cloudroam
2025-01-09 04be125365bfd254166072f75da87e406f633ba3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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/web/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)
      }
    }
  }
}