wangrong
1 天以前 db685b04e52efd75213ef7540fdc0bed7dccfd9e
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
58
59
60
61
62
63
64
65
66
<script setup lang="ts">
import { useStore, storage } from "/@/cool";
import { miniAutoLogin, phoneAuthState } from "/@/cool/mini-login";
import { i18n } from "/@/locale";
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
 
let booted = false;
 
function boot() {
    if (booted) {
        return;
    }
    booted = true;
 
    const { dict, user } = useStore();
    const authState = phoneAuthState();
 
    try {
        const locale = uni.getLocale();
        if (locale) {
            i18n.global.locale = locale;
        }
    } catch (err) {
        console.error(err);
    }
 
    dict.refresh()?.catch(() => undefined);
 
    // #ifdef MP-WEIXIN
    miniAutoLogin()
        .catch(() => false)
        .finally(() => {
            authState.ready = true;
            if (user.token && !storage.isExpired("token")) {
                user.get()?.catch(() => undefined);
            }
        });
    // #endif
 
    // #ifndef MP-WEIXIN
    authState.ready = true;
    if (user.token) {
        user.get()?.catch(() => undefined);
    }
    // #endif
}
 
onLaunch(() => {
    console.log("App Launch");
});
 
onShow(() => {
    console.log("App Show");
    setTimeout(boot, 0);
});
 
onHide(() => {
    console.log("App Hide");
});
</script>
 
<style lang="scss">
@import "/static/css/iconfont/index.scss";
@import "/$/cool-ui/index.scss";
@import "/@/static/css/index.scss";
</style>