You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
import store from '@/store'
|
|
import { setLanguage } from '@/lang/index'
|
|
import { getOrDefault, setItem } from '@/utils/localStorage'
|
|
import AbpConfigurationService, { IAbpConfiguration, AbpConfiguration as AbpConfig } from '@/api/abpconfiguration'
|
|
import { VuexModule, Module, Mutation, Action, getModule } from 'vuex-module-decorators'
|
|
|
|
export interface IAbpState {
|
|
configuration: IAbpConfiguration
|
|
}
|
|
|
|
const abpConfigurationKey = 'vue_admin_abp_configuration'
|
|
|
|
@Module({ dynamic: true, store, name: 'abp' })
|
|
class AbpConfiguration extends VuexModule implements IAbpState {
|
|
configuration = getOrDefault(abpConfigurationKey, new AbpConfig())
|
|
|
|
@Mutation
|
|
private SET_ABPCONFIGURATION(configuration: IAbpConfiguration) {
|
|
this.configuration = configuration
|
|
setItem(abpConfigurationKey, JSON.stringify(configuration))
|
|
}
|
|
|
|
@Mutation
|
|
private SET_ABPLOCALIZER(configuration: IAbpConfiguration) {
|
|
const { currentCulture, values } = configuration.localization
|
|
setLanguage(currentCulture.cultureName, values)
|
|
}
|
|
|
|
@Action({ rawError: true })
|
|
public LoadAbpConfiguration() {
|
|
return new Promise<AbpConfig>((resolve, reject) => {
|
|
AbpConfigurationService.getAbpConfiguration().then(config => {
|
|
this.SET_ABPCONFIGURATION(config)
|
|
this.SET_ABPLOCALIZER(config)
|
|
return resolve(config)
|
|
}).catch(error => {
|
|
return reject(error)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
export const AbpModule = getModule(AbpConfiguration)
|
|
|