import Vue from 'vue'
|
import ElBusiness from 'el-business'
|
import cacheUtil from 'el-business-cache-utils'
|
import zhCNLocale from 'el-business/src/locale/lang/zh-CN'
|
import enLocale from 'el-business/src/locale/lang/en'
|
import enHttpLocale from './httpLang/en'
|
|
export default (ctx) => {
|
const enableCache = ctx.$config.enableCache
|
const locale = {
|
'zh-CN': zhCNLocale,
|
en: enLocale,
|
}
|
const currentLocale = ctx.i18n.getLocaleCookie() || ctx.i18n.defaultLocale
|
Vue.use(ElBusiness, {
|
httpBaseUri: ctx.$config.httpBaseUri,
|
dictInterfaceUri: 'flower/api/code/value',
|
uploadInterfaceUri: 'flower/api/upload/oss/file',
|
downloadInterfaceUri: 'flower/api/download/file',
|
areaInterfaceUri: 'flower/api/pub/china/area/json',
|
smsInterfaceUri: 'flower/api/sms/send/code',
|
crudDialogAttrs: {
|
closeOnClickModal: false,
|
},
|
enableCache,
|
locale: locale[currentLocale],
|
})
|
ctx.$elBusHttp.options.beforeRequest = (config) => {
|
config.headers['Accept-Language'] = currentLocale
|
}
|
const httpLocale = {
|
en: enHttpLocale,
|
}
|
ctx.$elBusHttp.options.locale = httpLocale[currentLocale] || null
|
if (process.client) {
|
// if (!ctx.store.state.app.platformInfo) {
|
// await ctx.store.dispatch('app/getPlatformInfo')
|
// const logo = ctx.store?.state?.app?.platformInfo?.logo
|
// if (logo) {
|
// const link =
|
// document.querySelector("link[rel*='icon']") ||
|
// document.createElement('link')
|
// link.type = 'image/x-icon'
|
// link.rel = 'shortcut icon'
|
// link.href = logo
|
// document.getElementsByTagName('head')[0].appendChild(link)
|
// }
|
// }
|
// 缓存
|
if (enableCache) {
|
const cacheVersion = ctx.store?.state?.app?.platformInfo?.cache_version
|
if (cacheVersion) {
|
cacheUtil.init(cacheVersion)
|
}
|
}
|
}
|
}
|