shinnosuke
5 天以前 e52934f6527027bd6008c2ade61c3083159efd4a
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<script setup lang="uts">
    import { developmentLoginBypassEnabled, isApiConfigured } from './config/api.uts'
    import { initializeDevelopmentApiBaseUrl } from './config/development-server.uts'
    import { loginWithDevelopmentSession } from './services/auth.uts'
    import { resolveApiUrl } from './services/http.uts'
 
    /**
     * 行楷字体(古典艺术行楷简,5.1MB)放在服务器 `/uploads/fonts/gudian-xingkai.ttf`:
     * 包体主包上限 2MB,完整字体不能进包,所以启动时动态加载;加载失败时页面仍用包内子集/系统字体。
     * `global: true` 只在 app.uvue 里调用才全局生效(微信小程序基础库 2.10+)。
     */
    const loadCalligraphyFont = () => {
        if (!isApiConfigured()) return
        uni.loadFontFace({
            family: 'FoodCalligraphyFull',
            source: 'url("' + resolveApiUrl('/uploads/fonts/gudian-xingkai.ttf') + '")',
            global: true,
            success: () => { console.log('Calligraphy font loaded') },
            fail: (error: any) => { console.warn('Calligraphy font load failed: ' + JSON.stringify(error)) }
        })
    }
 
    // #ifdef APP-ANDROID || APP-HARMONY
    let firstBackTime = 0
    // #endif
 
    onLaunch(() => {
        console.log('App Launch')
        // 先把服务端地址解析好:开发环境探测本机局域网 IP,换网后不必改代码重新编译。
        initializeDevelopmentApiBaseUrl()
        loadCalligraphyFont()
        if (developmentLoginBypassEnabled) {
            loginWithDevelopmentSession(() => {}, (error) => {
                console.warn('Development session initialization failed: ' + error.code)
            })
        }
    })
 
    onAppShow(() => {
        console.log('App Show')
    })
 
    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>
    page {
        background-color: #F6F7FB;
        color: #1E293B;
        font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    }
 
    /* 每个页面公共布局 */
    .uni-row {
        flex-direction: row;
    }
 
    .uni-column {
        flex-direction: column;
    }
 
    /* 全局统一人才端自定义导航左上返回箭头,位置按登录页原型 */
    .nav-row .back-button,
    .nav-row .back {
        display: flex !important;
        width: 80rpx !important;
        height: 80rpx !important;
        margin-left: 0 !important;
        position: relative !important;
        left: auto !important;
        top: auto !important;
        border-radius: 10rpx !important;
        background-color: transparent !important;
        box-shadow: none !important;
        justify-content: center !important;
        align-items: center !important;
    }
 
    .custom-nav .nav-row,
    .page-header .nav-row {
        padding-left: 18rpx !important;
    }
 
    .nav-row .back-button image,
    .nav-row .back image {
        width: 44rpx !important;
        height: 44rpx !important;
    }
 
    .custom-nav.is-solid .back-button {
        background-color: transparent !important;
    }
 
    /*
     * 专题页的大标题/菜名用行楷:优先用 App.uvue 动态加载的服务器字体(FoodCalligraphyFull),
     * 没加载出来或缺少字符时回退到包内子集(FoodCalligraphy)与系统字体。
     */
    .dish-name,
    .scene-name {
        font-family: 'FoodCalligraphyFull', 'FoodCalligraphy' !important;
    }
 
    .nav-row .back-button-active {
        opacity: .55;
    }
</style>