mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 17:54:30 +08:00
code refactor
This commit is contained in:
+36
-33
@@ -44,6 +44,7 @@ const i18n = new VueI18n(getI18nOptions());
|
|||||||
|
|
||||||
Vue.prototype.$version = version.getVersion;
|
Vue.prototype.$version = version.getVersion;
|
||||||
Vue.prototype.$buildTime = version.getBuildTime;
|
Vue.prototype.$buildTime = version.getBuildTime;
|
||||||
|
|
||||||
Vue.prototype.$licenses = licenses;
|
Vue.prototype.$licenses = licenses;
|
||||||
Vue.prototype.$constants = {
|
Vue.prototype.$constants = {
|
||||||
currency: currency,
|
currency: currency,
|
||||||
@@ -51,44 +52,46 @@ Vue.prototype.$constants = {
|
|||||||
icons: icons,
|
icons: icons,
|
||||||
account: account,
|
account: account,
|
||||||
};
|
};
|
||||||
|
|
||||||
Vue.prototype.$utilities = utils;
|
Vue.prototype.$utilities = utils;
|
||||||
Vue.prototype.$logger = logger;
|
Vue.prototype.$logger = logger;
|
||||||
Vue.prototype.$webauthn = webauthn;
|
Vue.prototype.$webauthn = webauthn;
|
||||||
Vue.prototype.$settings = settings;
|
Vue.prototype.$settings = settings;
|
||||||
Vue.prototype.$getDefaultLanguage = getDefaultLanguage;
|
Vue.prototype.$locale = {
|
||||||
Vue.prototype.$getAllLanguages = getAllLanguages;
|
getDefaultLanguage: getDefaultLanguage,
|
||||||
Vue.prototype.$getLanguage = getLanguage;
|
getAllLanguages: getAllLanguages,
|
||||||
Vue.prototype.$setLanguage = function (locale) {
|
getLanguage: getLanguage,
|
||||||
if (settings.getLanguage() !== locale) {
|
setLanguage: function (locale) {
|
||||||
settings.setLanguage(locale);
|
if (settings.getLanguage() !== locale) {
|
||||||
|
settings.setLanguage(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
i18n.locale = locale;
|
||||||
|
moment.locale(locale);
|
||||||
|
services.setLocale(locale);
|
||||||
|
document.querySelector('html').setAttribute('lang', locale);
|
||||||
|
return locale;
|
||||||
|
},
|
||||||
|
getAllCurrencies: function () {
|
||||||
|
const allCurrencyCodes = currency.all;
|
||||||
|
const allCurrencies = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < allCurrencyCodes.length; i++) {
|
||||||
|
const code = allCurrencyCodes[i];
|
||||||
|
|
||||||
|
allCurrencies.push({
|
||||||
|
code: code,
|
||||||
|
displayName: i18n.t(`currency.${code}`)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
allCurrencies.sort(function(c1, c2){
|
||||||
|
return c1.displayName.localeCompare(c2.displayName);
|
||||||
|
})
|
||||||
|
|
||||||
|
return allCurrencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
i18n.locale = locale;
|
|
||||||
moment.locale(locale);
|
|
||||||
services.setLocale(locale);
|
|
||||||
document.querySelector('html').setAttribute('lang', locale);
|
|
||||||
return locale;
|
|
||||||
};
|
};
|
||||||
Vue.prototype.$getAllCurrencies = function () {
|
|
||||||
const allCurrencyCodes = currency.all;
|
|
||||||
const allCurrencies = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < allCurrencyCodes.length; i++) {
|
|
||||||
const code = allCurrencyCodes[i];
|
|
||||||
|
|
||||||
allCurrencies.push({
|
|
||||||
code: code,
|
|
||||||
displayName: i18n.t(`currency.${code}`)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
allCurrencies.sort(function(c1, c2){
|
|
||||||
return c1.displayName.localeCompare(c2.displayName);
|
|
||||||
})
|
|
||||||
|
|
||||||
return allCurrencies;
|
|
||||||
};
|
|
||||||
Vue.prototype.$isUserRegistrationEnabled = settings.isUserRegistrationEnabled;
|
|
||||||
|
|
||||||
Vue.prototype.$alert = function (message, confirmCallback) {
|
Vue.prototype.$alert = function (message, confirmCallback) {
|
||||||
let parameters = {};
|
let parameters = {};
|
||||||
@@ -171,7 +174,7 @@ if (settings.getLanguage()) {
|
|||||||
logger.info(`No language is set, use browser default ${getDefaultLanguage()}`);
|
logger.info(`No language is set, use browser default ${getDefaultLanguage()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vue.prototype.$setLanguage(settings.getLanguage() || getDefaultLanguage());
|
Vue.prototype.$locale.setLanguage(settings.getLanguage() || getDefaultLanguage());
|
||||||
|
|
||||||
if (userstate.isUserLogined()) {
|
if (userstate.isUserLogined()) {
|
||||||
if (!settings.isEnableApplicationLock()) {
|
if (!settings.isEnableApplicationLock()) {
|
||||||
|
|||||||
@@ -110,10 +110,10 @@ export default {
|
|||||||
return 'v' + this.$version();
|
return 'v' + this.$version();
|
||||||
},
|
},
|
||||||
allLanguages() {
|
allLanguages() {
|
||||||
return this.$getAllLanguages();
|
return this.$locale.getAllLanguages();
|
||||||
},
|
},
|
||||||
isUserRegistrationEnabled() {
|
isUserRegistrationEnabled() {
|
||||||
return this.$isUserRegistrationEnabled();
|
return this.$settings.isUserRegistrationEnabled();
|
||||||
},
|
},
|
||||||
inputIsEmpty() {
|
inputIsEmpty() {
|
||||||
return !this.username || !this.password;
|
return !this.username || !this.password;
|
||||||
@@ -134,10 +134,10 @@ export default {
|
|||||||
},
|
},
|
||||||
currentLanguageName() {
|
currentLanguageName() {
|
||||||
const currentLocale = this.$i18n.locale;
|
const currentLocale = this.$i18n.locale;
|
||||||
let lang = this.$getLanguage(currentLocale);
|
let lang = this.$locale.getLanguage(currentLocale);
|
||||||
|
|
||||||
if (!lang) {
|
if (!lang) {
|
||||||
lang = this.$getLanguage(this.$getDefaultLanguage());
|
lang = this.$locale.getLanguage(this.$locale.getDefaultLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return lang.displayName;
|
return lang.displayName;
|
||||||
@@ -289,7 +289,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
changeLanguage(locale) {
|
changeLanguage(locale) {
|
||||||
this.$setLanguage(locale);
|
this.$locale.setLanguage(locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -92,14 +92,14 @@ export default {
|
|||||||
return userInfo.nickname || userInfo.username || this.$t('User');
|
return userInfo.nickname || userInfo.username || this.$t('User');
|
||||||
},
|
},
|
||||||
allLanguages() {
|
allLanguages() {
|
||||||
return this.$getAllLanguages();
|
return this.$locale.getAllLanguages();
|
||||||
},
|
},
|
||||||
currentLocale: {
|
currentLocale: {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.$i18n.locale;
|
return this.$i18n.locale;
|
||||||
},
|
},
|
||||||
set: function (value) {
|
set: function (value) {
|
||||||
this.$setLanguage(value);
|
this.$locale.setLanguage(value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isEnableApplicationLock() {
|
isEnableApplicationLock() {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
allCurrencies() {
|
allCurrencies() {
|
||||||
return this.$getAllCurrencies();
|
return this.$locale.getAllCurrencies();
|
||||||
},
|
},
|
||||||
inputIsEmpty() {
|
inputIsEmpty() {
|
||||||
return !!this.inputEmptyProblemMessage;
|
return !!this.inputEmptyProblemMessage;
|
||||||
@@ -161,6 +161,10 @@ export default {
|
|||||||
|
|
||||||
if (self.$utilities.isString(data.result.token)) {
|
if (self.$utilities.isString(data.result.token)) {
|
||||||
self.$user.updateTokenAndUserInfo(data.result);
|
self.$user.updateTokenAndUserInfo(data.result);
|
||||||
|
|
||||||
|
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
||||||
|
self.$services.autoRefreshLatestExchangeRates();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.$toast('You have been successfully registered');
|
self.$toast('You have been successfully registered');
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ export default {
|
|||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
allCurrencies() {
|
allCurrencies() {
|
||||||
return this.$getAllCurrencies();
|
return this.$locale.getAllCurrencies();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
allCurrencies() {
|
allCurrencies() {
|
||||||
return this.$getAllCurrencies();
|
return this.$locale.getAllCurrencies();
|
||||||
},
|
},
|
||||||
inputIsNotChanged() {
|
inputIsNotChanged() {
|
||||||
return !!this.inputIsNotChangedProblemMessage;
|
return !!this.inputIsNotChangedProblemMessage;
|
||||||
|
|||||||
Reference in New Issue
Block a user