App.vue
2.95 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
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
<script setup>
import { onLaunch, onShow } from '@dcloudio/uni-app';
// 应用启动时初始化
onLaunch(() => {
console.log('App Launch');
// 清空登录重定向残留(可选)
uni.removeStorageSync('loginRedirectPath');
});
// 监听所有页面显示(核心:检测登录状态)
onShow(() => {
checkLoginStatus();
});
// 登录检测核心函数
const checkLoginStatus = () => {
// 1. 获取当前页面信息(避免登录页循环跳转)
const pages = getCurrentPages();
if (pages.length === 0) return; // 无页面时跳过
const currentPage = pages[pages.length - 1];
const currentPath = currentPage.route; // 当前页面路径(如:pages/plan/index)
// // 2. 白名单:无需登录的页面(登录页必须加,其他按需加)
// const whiteList = ['pages/login/index', 'pages/register/index']; // 可追加首页等
// if (whiteList.includes(currentPath)) return;
// 3. 检测登录状态(仅判断token是否存在,极简版)
const token = uni.getStorageSync('jcss_token'); // 登录成功后需存token
if (!token) {
// 记录当前页面(登录后可返回)
uni.setStorageSync('loginRedirectPath', currentPath);
// 跳转到登录页(用redirectTo避免返回栈残留)
uni.redirectTo({
url: '/pages/login/index'
});
}
};
</script>
<style lang="scss">
/* 注意要写在第一行,注意不能引入至uni.scss,同时给style标签加入lang="scss"属性 */
@import "@/uni_modules/uview-plus/index.scss";
/* 你的全局样式 */
page {
background-color: #f8f8f8;
height: 100%;
}
// 卡片列表样式
.common-card-list {
.card-header{
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
.common-name{
flex: 1; // 占满剩余空间,挤压标签到右侧
font-size: 28rpx;
font-weight: 500;
color: #333;
// 关键:单行文本溢出省略
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
// 与标签保持间距
margin-right: 16rpx;
}
// 已失效标签样式
.common-invalid-tag {
color: #f56c6c;
font-size: 24rpx;
flex-shrink: 0; // 禁止标签被压缩
}
.common-finish-tag{
color: #5ac725;
font-size: 24rpx;
flex-shrink: 0; // 禁止标签被压缩
}
}
.common-card-title {
}
.u-body-item {
margin-bottom: 16rpx;
&:last-child {
margin-bottom: 0;
}
}
.u-body-value {
flex: 1
}
}
// 通用样式
.common-item-center {
align-items: center;
}
.common-justify-between {
justify-content: space-between;
}
// 底部按钮样式
.fixed-bottom-btn-wrap {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 999;
padding: 0;
/* #ifdef MP-WEIXIN */
//padding-bottom: constant(safe-area-inset-bottom);
//padding-bottom: env(safe-area-inset-bottom);
/* #endif */
}
.commonPageLRpadding{
padding-left: 15px;
padding-right: 15px;
}
</style>