af-mobile-client-vue3 1.1.29 → 1.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "af-mobile-client-vue3",
3
3
  "type": "module",
4
- "version": "1.1.29",
4
+ "version": "1.1.30",
5
5
  "description": "Vue + Vite component lib",
6
6
  "license": "MIT",
7
7
  "engines": {
package/src/bootstrap.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Router } from 'vue-router'
2
2
  import guards from '@af-mobile-client-vue3/router/guards'
3
+ import { useSettingStore } from '@af-mobile-client-vue3/stores/modules/setting'
3
4
  import { loadGuards, loadRoutes } from '@af-mobile-client-vue3/utils/routerUtil'
4
5
 
5
6
  type GuardFunction = (to: any, from: any, next?: any) => void
@@ -13,6 +14,13 @@ async function bootstrap(router: Router, customGuard: Guards = {}) {
13
14
  loadRoutes()
14
15
  // 加载路由守卫
15
16
  loadGuards({ ...guards, ...customGuard }, router)
17
+ // 初始化时先加载webMobileConfig,防止登录页拿不到配置信息
18
+ try {
19
+ await useSettingStore().init()
20
+ }
21
+ catch (e) {
22
+ console.error(e)
23
+ }
16
24
  }
17
25
 
18
26
  export default bootstrap
package/src/main.ts CHANGED
@@ -28,21 +28,20 @@ import 'vant/es/dialog/style'
28
28
  import 'vant/es/notify/style'
29
29
  import 'vant/es/image-preview/style'
30
30
 
31
- const app = createApp(App)
32
- const head = createHead()
31
+ (async () => {
32
+ const app = createApp(App)
33
+ const head = createHead()
33
34
 
34
- app.use(head)
35
- app.use(router)
36
- app.use(pinia)
37
- app.use(Plugins)
35
+ app.use(head)
36
+ app.use(pinia)
37
+ app.use(router)
38
+ app.use(Plugins)
38
39
 
39
- async function main() {
40
40
  await bootstrap(router)
41
41
  app.mount('#system-app')
42
- }
43
- main().then((_r) => {})
44
42
 
45
- // 👇 将卸载操作放入 unmount 函数,就是上面步骤2中的卸载函数
46
- window.unmount = () => {
47
- app.unmount()
48
- }
43
+ // 👇 将卸载操作放入 unmount 函数,就是上面步骤2中的卸载函数
44
+ window.unmount = () => {
45
+ app.unmount()
46
+ }
47
+ })()
@@ -16,36 +16,42 @@ export interface WebConfig {
16
16
  // 存放 webConfig 中的 setting 配置
17
17
  export const useSettingStore = defineStore('setting', () => {
18
18
  const setting = ref<WebConfig>(undefined)
19
+ const isInitialized = ref(false)
20
+
19
21
  const setSetting = (newSetting: WebConfig) => {
20
22
  setting.value = newSetting
21
23
  }
24
+
22
25
  const getSetting = () => {
23
26
  return setting.value
24
27
  }
25
28
 
26
- const useStore = createStorage()
27
-
28
- const store = useSettingStore()
29
-
29
+ // init 作为 store 的方法导出
30
30
  const init = async () => {
31
+ if (isInitialized.value)
32
+ return
33
+
34
+ const useStore = createStorage()
31
35
  const catchWebConfig = useStore.get(APP_WEB_CONFIG_KEY)
32
36
  if (catchWebConfig) {
33
37
  setSetting(catchWebConfig)
34
38
  }
35
39
  else {
36
40
  const res = await getConfigByNameAsync('webMobileConfig')
37
- useStore.set(APP_WEB_CONFIG_KEY, res)
38
- const setting: WebConfig = res.setting
39
- if (setting)
40
- store.setSetting(setting)
41
+ if (res.setting) {
42
+ useStore.set(APP_WEB_CONFIG_KEY, res)
43
+ setSetting(res.setting)
44
+ }
41
45
  }
42
- }
43
46
 
44
- init().then(() => {})
47
+ isInitialized.value = true
48
+ }
45
49
 
46
50
  return {
47
51
  setSetting,
48
52
  getSetting,
53
+ init, // 导出 init 方法
54
+ isInitialized,
49
55
  }
50
56
  })
51
57