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 +1 -1
- package/src/bootstrap.ts +8 -0
- package/src/main.ts +12 -13
- package/src/stores/modules/setting.ts +16 -10
package/package.json
CHANGED
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
|
-
|
|
32
|
-
const
|
|
31
|
+
(async () => {
|
|
32
|
+
const app = createApp(App)
|
|
33
|
+
const head = createHead()
|
|
33
34
|
|
|
34
|
-
app.use(head)
|
|
35
|
-
app.use(
|
|
36
|
-
app.use(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if (res.setting) {
|
|
42
|
+
useStore.set(APP_WEB_CONFIG_KEY, res)
|
|
43
|
+
setSetting(res.setting)
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
|
-
}
|
|
43
46
|
|
|
44
|
-
|
|
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
|
|