底部导航
|
|
@ -1,31 +1,24 @@
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function() {
|
onLaunch: function() {
|
||||||
// 检查本地登录凭证是否存在
|
// 检查本地登录凭证,过期则静默清除,不跳转登录页
|
||||||
const token = uni.getStorageSync('token')
|
const token = uni.getStorageSync('token')
|
||||||
if (!token) {
|
if (!token) return
|
||||||
// 未登录,跳转登录页
|
|
||||||
uni.reLaunch({ url: '/pages/login/login' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 简单检查 JWT 是否过期
|
|
||||||
try {
|
try {
|
||||||
const parts = token.split('.')
|
const parts = token.split('.')
|
||||||
if (parts.length === 3) {
|
if (parts.length === 3) {
|
||||||
const payload = JSON.parse(atob(parts[1]))
|
const payload = JSON.parse(atob(parts[1]))
|
||||||
if (payload.exp && payload.exp * 1000 < Date.now()) {
|
if (payload.exp && payload.exp * 1000 < Date.now()) {
|
||||||
// token 已过期,清除并跳转登录页
|
// token 已过期,静默清除
|
||||||
uni.removeStorageSync('token')
|
uni.removeStorageSync('token')
|
||||||
uni.removeStorageSync('userInfo')
|
uni.removeStorageSync('userInfo')
|
||||||
uni.reLaunch({ url: '/pages/login/login' })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// 解析失败,清除无效 token
|
// 解析失败,清除无效 token
|
||||||
uni.removeStorageSync('token')
|
uni.removeStorageSync('token')
|
||||||
uni.removeStorageSync('userInfo')
|
uni.removeStorageSync('userInfo')
|
||||||
uni.reLaunch({ url: '/pages/login/login' })
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onShow: function() {},
|
onShow: function() {},
|
||||||
|
|
|
||||||
|
|
@ -178,26 +178,26 @@
|
||||||
{
|
{
|
||||||
"pagePath": "pages/index/index",
|
"pagePath": "pages/index/index",
|
||||||
"text": "首页",
|
"text": "首页",
|
||||||
"iconPath": "static/tab/home.png",
|
"iconPath": "static/tab/ic_home.png",
|
||||||
"selectedIconPath": "static/tab/home-active.png"
|
"selectedIconPath": "static/tab/ic_home_s.png"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pagePath": "pages/order-hall/order-hall",
|
"pagePath": "pages/order-hall/order-hall",
|
||||||
"text": "订单大厅",
|
"text": "订单大厅",
|
||||||
"iconPath": "static/tab/hall.png",
|
"iconPath": "static/tab/ic_orders.png",
|
||||||
"selectedIconPath": "static/tab/hall-active.png"
|
"selectedIconPath": "static/tab/ic_orders_s.png"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pagePath": "pages/message/message",
|
"pagePath": "pages/message/message",
|
||||||
"text": "消息",
|
"text": "消息",
|
||||||
"iconPath": "static/tab/message.png",
|
"iconPath": "static/tab/ic_message.png",
|
||||||
"selectedIconPath": "static/tab/message-active.png"
|
"selectedIconPath": "static/tab/ic_message_s.png"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pagePath": "pages/mine/mine",
|
"pagePath": "pages/mine/mine",
|
||||||
"text": "我的",
|
"text": "我的",
|
||||||
"iconPath": "static/tab/mine.png",
|
"iconPath": "static/tab/ic_me.png",
|
||||||
"selectedIconPath": "static/tab/mine-active.png"
|
"selectedIconPath": "static/tab/ic_me_s.png"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
miniapp/static/tab/ic_home.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
miniapp/static/tab/ic_home_s.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
miniapp/static/tab/ic_me.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
miniapp/static/tab/ic_me_s.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
miniapp/static/tab/ic_message.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
miniapp/static/tab/ic_message_s.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
miniapp/static/tab/ic_orders.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
miniapp/static/tab/ic_orders_s.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
|
|
@ -38,15 +38,11 @@ export const useUserStore = defineStore('user', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查登录状态,未登录则跳转登录页
|
* 检查登录状态
|
||||||
* @returns {boolean} 是否已登录
|
* @returns {boolean} 是否已登录
|
||||||
*/
|
*/
|
||||||
function checkLogin() {
|
function checkLogin() {
|
||||||
if (!isLoggedIn.value) {
|
return isLoggedIn.value
|
||||||
uni.reLaunch({ url: '/pages/login/login' })
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -65,10 +65,10 @@ function request(options) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 未登录或 token 过期,跳转登录页
|
// 未登录或 token 过期,静默清除凭证,不自动跳转
|
||||||
if (statusCode === 401) {
|
if (statusCode === 401) {
|
||||||
redirectToLogin()
|
clearAuth()
|
||||||
reject(new Error('登录已过期,请重新登录'))
|
reject(new Error('未登录或登录已过期'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,8 +113,8 @@ function uploadFile(filePath, url = '/api/upload/image') {
|
||||||
header,
|
header,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.statusCode === 401) {
|
if (res.statusCode === 401) {
|
||||||
redirectToLogin()
|
clearAuth()
|
||||||
reject(new Error('登录已过期,请重新登录'))
|
reject(new Error('未登录或登录已过期'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const data = JSON.parse(res.data)
|
const data = JSON.parse(res.data)
|
||||||
|
|
|
||||||