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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<script setup lang="uts">
    import { clearSession, hasActiveSession, hasRefreshableSession } from './services/session.uts'
    import { refreshMerchantSession } from './services/session-refresh.uts'
    import { initializeDevelopmentApiBaseUrl } from './config/development-server.uts'
    // #ifdef APP-ANDROID || APP-HARMONY
    let firstBackTime = 0
    // #endif
 
    onLaunch(() => {
        console.log('App Launch')
        // 先把服务端地址解析好:开发环境探测本机局域网 IP,换网后不必改代码重新编译。
        initializeDevelopmentApiBaseUrl()
    })
 
    onAppShow(() => {
        console.log('App Show')
        if (!hasActiveSession() && hasRefreshableSession()) {
            refreshMerchantSession((success: boolean) => {
                if (!success) {
                    clearSession()
                    uni.reLaunch({ url: '/pages/login/login' })
                }
            })
        }
    })
 
    onAppHide(() => {
        console.log('App Hide')
    })
 
    // #ifdef APP-ANDROID || APP-HARMONY
    onLastPageBackPress(() => {
        console.log('App LastPageBackPress')
        if (firstBackTime == 0) {
            uni.showToast({
                title: '再按一次退出应用',
                position: 'bottom',
            })
            firstBackTime = Date.now()
            setTimeout(() => {
                firstBackTime = 0
            }, 2000)
        } else if (Date.now() - firstBackTime < 2000) {
            firstBackTime = Date.now()
            uni.exit()
        }
    })
 
    onExit(() => {
        console.log('App Exit')
    })
    // #endif
</script>
 
<style>
    /*每个页面公共css */
    .uni-row {
        flex-direction: row;
    }
 
    .uni-column {
        flex-direction: column;
    }
 
    .merchant-tabbar-host {
        display: flex;
        height: 138rpx;
        position: fixed;
        left: 42rpx;
        right: 42rpx;
        bottom: 24rpx;
        bottom: calc(24rpx + constant(safe-area-inset-bottom));
        bottom: calc(24rpx + env(safe-area-inset-bottom));
        z-index: 10;
        border-radius: 36rpx;
        background-color: rgba(255, 255, 255, 0.98);
        box-shadow: 0 10rpx 36rpx rgba(44, 53, 65, 0.14);
        box-sizing: border-box;
        overflow: visible;
    }
 
    /* 统一商户端自定义导航左上返回箭头,和人才端保持一致 */
    .navigation-bar .back-button,
    .hero-nav .hero-back,
    .page > .back-button {
        display: flex !important;
        width: 80rpx !important;
        height: 80rpx !important;
        left: 18rpx !important;
        top: 79rpx !important;
        margin-left: 0 !important;
        border-radius: 10rpx !important;
        background-color: transparent !important;
        box-shadow: none !important;
        justify-content: center !important;
        align-items: center !important;
    }
 
    .navigation-bar .back-icon,
    .hero-nav .hero-back-icon,
    .page > .back-button .back-icon {
        width: 44rpx !important;
        height: 44rpx !important;
        transform: none !important;
    }
 
    .navigation-bar,
    .hero-nav {
        padding-left: 18rpx !important;
    }
</style>