-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.vue
More file actions
92 lines (77 loc) · 1.72 KB
/
Copy pathApp.vue
File metadata and controls
92 lines (77 loc) · 1.72 KB
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
<template>
<view class="app">
<view class="app-content">
<!-- 自定义导航栏占位 -->
<view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
<!-- 页面内容 -->
<router-view />
</view>
</view>
</template>
<script setup lang="uts">
import { ref } from 'vue'
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { useUserStore } from '@/stores/user'
// 状态栏高度
const statusBarHeight = ref(0)
const userStore = useUserStore()
// 应用生命周期
onLaunch(() => {
console.log('App Launch')
// 获取系统信息
const systemInfo = uni.getSystemInfoSync()
statusBarHeight.value = systemInfo.statusBarHeight || 0
// 检查登录状态
userStore.checkLoginStatus()
// 初始化uni-id
initUniId()
})
onShow(() => {
console.log('App Show')
})
onHide(() => {
console.log('App Hide')
})
// 初始化uni-id
function initUniId() {
// 在微信小程序中自动登录
// #ifdef MP-WEIXIN
try {
uni.login({
provider: 'weixin',
success: (loginRes) => {
console.log('微信登录成功', loginRes)
// 登录成功后可以调用云函数进行后续处理
},
fail: (err) => {
console.error('微信登录失败', err)
}
})
} catch (e) {
console.error('初始化登录失败:', e)
}
// #endif
}
</script>
<style lang="scss">
/* 全局样式 */
page {
height: 100%;
background-color: #f5f5f5;
}
.app {
height: 100%;
.app-content {
height: 100%;
display: flex;
flex-direction: column;
}
}
/* 定义CSS变量 */
page {
--uni-color-primary: #4CAF50;
--uni-color-success: #4CAF50;
--uni-color-warning: #FF9800;
--uni-color-error: #F44336;
}
</style>