Compare commits
10 Commits
48c25b9d71
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3dbdaba6f | ||
|
|
9ce4ed0c01 | ||
|
|
6d631af58a | ||
|
|
cac9120196 | ||
|
|
43a645ec87 | ||
|
|
527747259c | ||
|
|
ba4d59dc98 | ||
|
|
4be5f32066 | ||
|
|
0e520e4365 | ||
|
|
52bfe02beb |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 249 B After Width: | Height: | Size: 249 B |
|
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
@@ -12,8 +12,10 @@
|
|||||||
<!-- 遍历渲染业务图标 -->
|
<!-- 遍历渲染业务图标 -->
|
||||||
<view class="item u-flex-col" v-for="(item,index) in cardData" :key="index" @click="clickItem(item)">
|
<view class="item u-flex-col" v-for="(item,index) in cardData" :key="index" @click="clickItem(item)">
|
||||||
<view class="item-icon" :style="{ background: item.iconBackground || '#008cff' }">
|
<view class="item-icon" :style="{ background: item.iconBackground || '#008cff' }">
|
||||||
|
{{ console.log(imgId[item.id],'imgId[item.id]判断') }}
|
||||||
<image class="item-img" :src="`/static/image/${item.name}.png`"></image>
|
{{ console.log(imgId,'imgId') }}
|
||||||
|
{{ console.log(item.id,'item.id') }}
|
||||||
|
<image v-show="!!imgId[item.id]" class="item-img" :src="`/static/image/${item.id}.png`"></image>
|
||||||
<!-- 使用 iconify-icon 渲染 ep 系列图标 -->
|
<!-- 使用 iconify-icon 渲染 ep 系列图标 -->
|
||||||
<!-- <iconify-icon
|
<!-- <iconify-icon
|
||||||
:icon="item.icon"
|
:icon="item.icon"
|
||||||
@@ -45,10 +47,10 @@
|
|||||||
type: Array,
|
type: Array,
|
||||||
default: () => []
|
default: () => []
|
||||||
},
|
},
|
||||||
flowList: {
|
// flowList: {
|
||||||
type: Array,
|
// type: Array,
|
||||||
default: () => []
|
// default: () => []
|
||||||
},
|
// },
|
||||||
showAdd: {
|
showAdd: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
@@ -76,21 +78,35 @@
|
|||||||
computed: {
|
computed: {
|
||||||
tabType() {
|
tabType() {
|
||||||
return this.tabList[this.current].type
|
return this.tabList[this.current].type
|
||||||
|
},
|
||||||
|
imgId(){
|
||||||
|
return {
|
||||||
|
'1963446794006355970' : '动土作业',
|
||||||
|
'1963872316314165250' : '动火作业',
|
||||||
|
'1964898396173070337' : '有限空间',
|
||||||
|
'1964261054499336194' : '临时用电',
|
||||||
|
'1964253329070571521' : '高处作业',
|
||||||
|
'1964210049770401793' : '吊装作业'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
menuList: {
|
menuList: {
|
||||||
handler(val) {
|
handler(val) {
|
||||||
if (this.current != 0) this.cardData = this.flowList
|
console.log(this.current,'this.current---')
|
||||||
|
this.cardData = this.menuList
|
||||||
},
|
},
|
||||||
immediate: true
|
immediate: true
|
||||||
},
|
},
|
||||||
flowList: {
|
// flowList: {
|
||||||
handler(val) {
|
// handler(val) {
|
||||||
if (this.current == 0) this.cardData = this.menuList
|
// console.log(this.current,'this.current---')
|
||||||
},
|
// console.log(this.menuList,'this.menuList---')
|
||||||
immediate: true
|
// // if (this.current == 0) this.cardData = this.menuList
|
||||||
}
|
// this.cardData = this.menuList
|
||||||
|
// },
|
||||||
|
// immediate: true
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.userInfo = uni.getStorageSync('userInfo') || {}
|
this.userInfo = uni.getStorageSync('userInfo') || {}
|
||||||
@@ -107,8 +123,9 @@
|
|||||||
},
|
},
|
||||||
tabChange(index) {
|
tabChange(index) {
|
||||||
this.current = index;
|
this.current = index;
|
||||||
if (this.tabType === 'menu') this.cardData = this.menuList
|
// if (this.tabType === 'menu')
|
||||||
if (this.tabType === 'flow') this.cardData = this.flowList
|
this.cardData = this.menuList
|
||||||
|
// if (this.tabType === 'flow') this.cardData = this.flowList
|
||||||
},
|
},
|
||||||
clickItem(item) {
|
clickItem(item) {
|
||||||
this.$emit('launch', {
|
this.$emit('launch', {
|
||||||
|
|||||||
@@ -511,7 +511,13 @@
|
|||||||
modelId,
|
modelId,
|
||||||
isPreview = '0',
|
isPreview = '0',
|
||||||
id = '',
|
id = '',
|
||||||
|
current,
|
||||||
|
tabCurrent
|
||||||
} = config
|
} = config
|
||||||
|
console.log(tabCurrent !== undefined,'判断11111111')
|
||||||
|
if(tabCurrent !== undefined){
|
||||||
|
uni.setStorageSync('fromNonTabBar', tabCurrent);
|
||||||
|
}
|
||||||
const formPermissionList =[]
|
const formPermissionList =[]
|
||||||
Object.assign(this, {
|
Object.assign(this, {
|
||||||
userInfo: uni.getStorageSync('userInfo') || {},
|
userInfo: uni.getStorageSync('userInfo') || {},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
@click="handelClick(item)">
|
@click="handelClick(item)">
|
||||||
<!-- 渲染图标 -->
|
<!-- 渲染图标 -->
|
||||||
<view class="item-icon" :style="{ background: item.iconBackground || '#008cff' }">
|
<view class="item-icon" :style="{ background: item.iconBackground || '#008cff' }">
|
||||||
<image class="item-img" :src="`/static/image/${item.name}.png`"></image>
|
<image v-show="!!imgId[item.id]" class="item-img" :src="`/static/image/${item.id}.png`"></image>
|
||||||
<!-- 使用 iconify-icon 渲染 ep 系列图标 -->
|
<!-- 使用 iconify-icon 渲染 ep 系列图标 -->
|
||||||
<!-- <iconify-icon
|
<!-- <iconify-icon
|
||||||
:icon="item.icon"
|
:icon="item.icon"
|
||||||
@@ -86,6 +86,16 @@
|
|||||||
pcURL() {
|
pcURL() {
|
||||||
return this.define.pcURL;
|
return this.define.pcURL;
|
||||||
},
|
},
|
||||||
|
imgId(){
|
||||||
|
return {
|
||||||
|
'1963446794006355970' : '动土作业',
|
||||||
|
'1963872316314165250' : '动火作业',
|
||||||
|
'1964898396173070337' : '有限空间',
|
||||||
|
'1964261054499336194' : '临时用电',
|
||||||
|
'1964253329070571521' : '高处作业',
|
||||||
|
'1964210049770401793' : '吊装作业'
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.keyword = "";
|
this.keyword = "";
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
:menuList="homeData.commonUseMenuList || []" @launch="launch" v-if="homeData.commonUseEnable"
|
:menuList="homeData.commonUseMenuList || []" @launch="launch" v-if="homeData.commonUseEnable"
|
||||||
@openPage="openPage" :flowEnabled="homeData.flowEnabled" /> -->
|
@openPage="openPage" :flowEnabled="homeData.flowEnabled" /> -->
|
||||||
|
|
||||||
<CommonPaneSys title="应用功能" :flowList="[]" type="common"
|
<CommonPaneSys title="应用功能" type="common"
|
||||||
:menuList="homeData || []" @launch="launch" v-if="homeData"
|
:menuList="homeData || []" @launch="launch" v-if="homeData"
|
||||||
@openPage="openPage" />
|
@openPage="openPage" />
|
||||||
<view class="todo-list-wrap">
|
<view class="todo-list-wrap">
|
||||||
@@ -392,6 +392,7 @@
|
|||||||
getMenuData().then((res) => {
|
getMenuData().then((res) => {
|
||||||
const list = res?.data
|
const list = res?.data
|
||||||
this.homeData = list
|
this.homeData = list
|
||||||
|
console.log(this.homeData,'homeData----')
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -425,7 +426,7 @@
|
|||||||
//更多按钮
|
//更多按钮
|
||||||
openPage(path, type) {
|
openPage(path, type) {
|
||||||
if (type === 'approve') {
|
if (type === 'approve') {
|
||||||
let workFlowList = this.menuList.filter(o => o.enCode === 'workFlow')
|
let workFlowList =this.menuList && this.menuList.filter(o => o.enCode === 'workFlow')
|
||||||
console.log(this.menuList,'menuList---------')
|
console.log(this.menuList,'menuList---------')
|
||||||
if (!workFlowList[0]?.children?.length) return this.$u.toast('暂无权限')
|
if (!workFlowList[0]?.children?.length) return this.$u.toast('暂无权限')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ export default {
|
|||||||
// if (this.sysConfigInfo[config.key] === 1) return this.tabsList.unshift(config.tab);
|
// if (this.sysConfigInfo[config.key] === 1) return this.tabsList.unshift(config.tab);
|
||||||
// });
|
// });
|
||||||
this.menuList = uni.getStorageSync("menuList");
|
this.menuList = uni.getStorageSync("menuList");
|
||||||
let workFlowList = this.menuList.filter(o => o.enCode === 'workFlow')
|
let workFlowList = this.menuList && this.menuList.filter(o => o.enCode === 'workFlow')
|
||||||
if (!workFlowList.length) return
|
if (!workFlowList.length) return
|
||||||
let menuData = workFlowList[0]?.children
|
let menuData = workFlowList[0]?.children
|
||||||
this.tabsList = this.tabsList.filter(tab =>
|
this.tabsList = this.tabsList.filter(tab =>
|
||||||
|
|||||||
@@ -66,6 +66,10 @@
|
|||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
default: '0'
|
default: '0'
|
||||||
},
|
},
|
||||||
|
current: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: '0'
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -100,7 +104,8 @@
|
|||||||
id: businessId,
|
id: businessId,
|
||||||
name: name,
|
name: name,
|
||||||
btnType: 'btn_process',
|
btnType: 'btn_process',
|
||||||
current: this.category
|
current: this.category,
|
||||||
|
tabCurrent: this.current
|
||||||
}
|
}
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/apply/dynamicModelList/form?config=' +
|
url: '/pages/apply/dynamicModelList/form?config=' +
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
|
<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
|
||||||
:up="upOption" :top="mescrollTop">
|
:up="upOption" :top="mescrollTop">
|
||||||
<flowlist :list='list' :swipeAction='current != 3' :category='category' />
|
<flowlist :list='list' :swipeAction='current != 3' :category='category' :current='current' />
|
||||||
</mescroll-body>
|
</mescroll-body>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
@@ -76,12 +76,18 @@
|
|||||||
onShow() {
|
onShow() {
|
||||||
const fromNonTabBar = uni.getStorageSync('fromNonTabBar');
|
const fromNonTabBar = uni.getStorageSync('fromNonTabBar');
|
||||||
console.log(fromNonTabBar,'fromNonTabBar---')
|
console.log(fromNonTabBar,'fromNonTabBar---')
|
||||||
this.current = fromNonTabBar && Number(fromNonTabBar)
|
if(fromNonTabBar == ''){
|
||||||
// if(!fromNonTabBar){
|
this.current = 1
|
||||||
// this.current = 1
|
this.category = '2'
|
||||||
// }else {
|
}else {
|
||||||
// this.current = 0
|
this.current = Number(fromNonTabBar)
|
||||||
// }
|
this.category = Number(fromNonTabBar) + 1+''
|
||||||
|
}
|
||||||
|
const page = {
|
||||||
|
num : 1,
|
||||||
|
size: 20
|
||||||
|
}
|
||||||
|
this.upCallback(page)
|
||||||
uni.removeStorageSync('fromNonTabBar');
|
uni.removeStorageSync('fromNonTabBar');
|
||||||
uni.$off('operate')
|
uni.$off('operate')
|
||||||
uni.$on('refresh', () => {
|
uni.$on('refresh', () => {
|
||||||
@@ -91,6 +97,10 @@
|
|||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
uni.$off('refresh')
|
uni.$off('refresh')
|
||||||
|
uni.removeStorageSync('fromNonTabBar');
|
||||||
|
},
|
||||||
|
onHide() {
|
||||||
|
uni.removeStorageSync('fromNonTabBar');
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getFlowStatus(status) {
|
getFlowStatus(status) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
BIN
static/image/1964210049770401793.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
static/image/1964253329070571521.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
static/image/1964261054499336194.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 249 B |
207
utils/request.js
@@ -11,6 +11,45 @@ let requestQueue = []
|
|||||||
let isRefreshingToken = false
|
let isRefreshingToken = false
|
||||||
const isRelogin = { show: false }
|
const isRelogin = { show: false }
|
||||||
|
|
||||||
|
// 全局网络状态标记(防止多请求覆盖)
|
||||||
|
let GLOBAL_IS_NETWORK_ERROR = false;
|
||||||
|
|
||||||
|
// ========== 核心:全局拦截登录跳转 ==========
|
||||||
|
// 拦截所有跳登录页的操作,仅允许非断网场景跳转
|
||||||
|
function interceptLoginJump() {
|
||||||
|
// 拦截 reLaunch(最常用的跳登录方式)
|
||||||
|
const originalReLaunch = uni.reLaunch;
|
||||||
|
uni.reLaunch = function(options) {
|
||||||
|
// 如果是跳登录页 + 当前是网络错误 → 阻止跳转
|
||||||
|
if (options.url && options.url.includes('/pages/login/index') && GLOBAL_IS_NETWORK_ERROR) {
|
||||||
|
console.log('【拦截】断网时禁止跳登录页');
|
||||||
|
uni.showToast({
|
||||||
|
title: '网络已断开,请先连接网络',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 3000
|
||||||
|
});
|
||||||
|
return; // 终止跳转
|
||||||
|
}
|
||||||
|
// 非登录页/非断网场景 → 正常跳转
|
||||||
|
originalReLaunch.call(uni, options);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 拦截其他跳转方式(兜底)
|
||||||
|
const interceptors = ['navigateTo', 'redirectTo', 'switchTab'];
|
||||||
|
interceptors.forEach(method => {
|
||||||
|
const originalMethod = uni[method];
|
||||||
|
uni[method] = function(options) {
|
||||||
|
if (options.url && options.url.includes('/pages/login/index') && GLOBAL_IS_NETWORK_ERROR) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
originalMethod.call(uni, options);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化拦截器(页面加载时执行一次)
|
||||||
|
interceptLoginJump();
|
||||||
|
|
||||||
// ------------- 核心request方法 -------------
|
// ------------- 核心request方法 -------------
|
||||||
function request(config) {
|
function request(config) {
|
||||||
config.options = Object.assign(defaultOpt, config.options)
|
config.options = Object.assign(defaultOpt, config.options)
|
||||||
@@ -36,12 +75,13 @@ function request(config) {
|
|||||||
// let url = config.url.indexOf('http') > -1 ? config.url : host + config.url
|
// let url = config.url.indexOf('http') > -1 ? config.url : host + config.url
|
||||||
let url = host + config.url
|
let url = host + config.url
|
||||||
console.log(url,'url---')
|
console.log(url,'url---')
|
||||||
// 3. 显示加载中
|
|
||||||
|
// 显示加载中
|
||||||
if (config.options.load) {
|
if (config.options.load) {
|
||||||
uni.showLoading({ title: config.options.loadText || '正在加载' })
|
uni.showLoading({ title: config.options.loadText || '正在加载' })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 返回Promise,核心改造逻辑
|
// 返回Promise
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 封装核心请求逻辑
|
// 封装核心请求逻辑
|
||||||
const coreRequest = () => {
|
const coreRequest = () => {
|
||||||
@@ -53,6 +93,8 @@ function request(config) {
|
|||||||
timeout: define.timeout,
|
timeout: define.timeout,
|
||||||
success: async (res) => {
|
success: async (res) => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
|
GLOBAL_IS_NETWORK_ERROR = false; // 有响应 → 网络正常
|
||||||
|
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
if (res.data.code == 200 || res.data.code == 0) {
|
if (res.data.code == 200 || res.data.code == 0) {
|
||||||
resolve(res.data)
|
resolve(res.data)
|
||||||
@@ -60,74 +102,102 @@ function request(config) {
|
|||||||
// 白名单接口不处理
|
// 白名单接口不处理
|
||||||
const isWhiteList = whiteList.some(v => config.url.includes(v))
|
const isWhiteList = whiteList.some(v => config.url.includes(v))
|
||||||
if (isWhiteList) {
|
if (isWhiteList) {
|
||||||
ajaxError(res.data)
|
uni.showToast({ title: res.data.msg || '认证失败', icon: 'none' });
|
||||||
reject(res.data.msg)
|
reject(res.data.msg);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------- 刷新token请求改为问号拼接参数 -------------
|
// 无刷新token → 提示手动登录(不自动跳转)
|
||||||
if (!refreshToken) {
|
if (!refreshToken) {
|
||||||
await handleAuthorized()
|
uni.showModal({
|
||||||
reject(res.data.msg)
|
title: '登录过期',
|
||||||
return
|
content: '您的登录已过期,请重新登录',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmText: '去登录'
|
||||||
|
}).then(res => {
|
||||||
|
if (res.confirm) {
|
||||||
|
clearAuthStorage();
|
||||||
|
uni.reLaunch({ url: '/pages/login/index' }); // 这里会走拦截器,仅网络正常时跳转
|
||||||
|
}
|
||||||
|
});
|
||||||
|
reject('登录过期,无刷新Token');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRefreshingToken) {
|
if (isRefreshingToken) {
|
||||||
requestQueue.push(() => coreRequest())
|
requestQueue.push(() => coreRequest());
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isRefreshingToken = true
|
isRefreshingToken = true;
|
||||||
try {
|
try {
|
||||||
// 拼接URL参数
|
// 刷新token接口
|
||||||
const refreshUrl = `${host}/admin-api/system/auth/refresh-token?refreshToken=${encodeURIComponent(refreshToken)}`
|
const refreshUrl = `${host}/admin-api/system/auth/refresh-token?refreshToken=${encodeURIComponent(refreshToken)}`;
|
||||||
// 调用刷新token接口(POST方法 + URL参数,无请求体)
|
|
||||||
const refreshRes = await uni.request({
|
const refreshRes = await uni.request({
|
||||||
url: refreshUrl, // 带参数的URL
|
url: refreshUrl,
|
||||||
method: 'POST', // 保持POST方法
|
method: 'POST',
|
||||||
header: {
|
header: {
|
||||||
'tenant-id': tenantId, // 携带租户ID
|
'tenant-id': tenantId,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
data: {} // 无请求体,参数全在URL上
|
data: {}
|
||||||
})
|
});
|
||||||
// 刷新成功处理
|
|
||||||
if (refreshRes.data.code == 0) {
|
if (refreshRes.data && (refreshRes.data.code == 0 || refreshRes.data.code == 200)) {
|
||||||
const newTokenData = refreshRes.data.data
|
// 刷新成功
|
||||||
// 存储新token
|
const newTokenData = refreshRes.data.data;
|
||||||
uni.setStorageSync('token', newTokenData.accessToken)
|
uni.setStorageSync('token', newTokenData.accessToken);
|
||||||
uni.setStorageSync('refreshToken', newTokenData.refreshToken)
|
uni.setStorageSync('refreshToken', newTokenData.refreshToken);
|
||||||
// 更新请求头
|
header['Authorization'] = newTokenData.accessToken;
|
||||||
header['Authorization'] = newTokenData.accessToken
|
coreRequest();
|
||||||
// 重试当前请求
|
requestQueue.forEach(cb => cb());
|
||||||
coreRequest()
|
requestQueue = [];
|
||||||
// 执行队列请求
|
|
||||||
requestQueue.forEach(cb => cb())
|
|
||||||
requestQueue = []
|
|
||||||
} else {
|
} else {
|
||||||
await handleAuthorized()
|
// 刷新失败 → 提示手动登录
|
||||||
reject('刷新token失败:' + (refreshRes.data?.msg || '接口返回异常'))
|
uni.showModal({
|
||||||
|
title: '登录过期',
|
||||||
|
content: '刷新登录状态失败,请重新登录',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmText: '去登录'
|
||||||
|
}).then(res => {
|
||||||
|
if (res.confirm) {
|
||||||
|
clearAuthStorage();
|
||||||
|
uni.reLaunch({ url: '/pages/login/index' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
reject('刷新Token失败:' + (refreshRes.data?.msg || '接口返回异常'));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await handleAuthorized()
|
// 刷新token异常 → 判定为网络错误
|
||||||
reject('刷新token异常:' + err.errMsg)
|
GLOBAL_IS_NETWORK_ERROR = true;
|
||||||
|
uni.showToast({ title: '网络异常,无法刷新登录状态', icon: 'none', duration: 3000 });
|
||||||
|
reject('网络异常:' + (err.errMsg || err.message));
|
||||||
} finally {
|
} finally {
|
||||||
isRefreshingToken = false
|
isRefreshingToken = false;
|
||||||
requestQueue = []
|
requestQueue = [];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ajaxError(res.data)
|
// 普通业务错误
|
||||||
reject(res.data.msg)
|
uni.showToast({ title: res.data.msg || '请求出错,请重试', icon: 'none' });
|
||||||
|
reject(res.data.msg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ajaxError(res.data)
|
// HTTP状态码错误
|
||||||
reject(res.errMsg)
|
uni.showToast({ title: `请求失败[${res.statusCode}]`, icon: 'none' });
|
||||||
|
reject(res.errMsg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({ title: '连接服务器失败', icon: 'none' })
|
GLOBAL_IS_NETWORK_ERROR = true;
|
||||||
reject(err)
|
|
||||||
|
// 重置刷新状态,防止死锁
|
||||||
|
isRefreshingToken = false;
|
||||||
|
requestQueue = [];
|
||||||
|
|
||||||
|
// 仅提示网络错误,不跳转
|
||||||
|
uni.showToast({ title: '网络连接失败,请检查网络', icon: 'none', duration: 3000 });
|
||||||
|
reject({ isNetworkError: true, errMsg: err.errMsg });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -137,40 +207,17 @@ function request(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------- 辅助函数 -------------
|
// ------------- 辅助函数 -------------
|
||||||
function ajaxError(data) {
|
/**
|
||||||
uni.showToast({
|
* 清除登录缓存
|
||||||
title: data.msg || '请求出错,请重试',
|
*/
|
||||||
icon: 'none',
|
function clearAuthStorage() {
|
||||||
complete() {
|
uni.removeStorageSync('token');
|
||||||
if ([600, 601, 602, 401].includes(data.code) && !isRefreshingToken) {
|
uni.removeStorageSync('refreshToken');
|
||||||
setTimeout(() => handleAuthorized(), 1500)
|
uni.removeStorageSync('cid');
|
||||||
}
|
uni.removeStorageSync('userInfo');
|
||||||
}
|
uni.removeStorageSync('permissionList');
|
||||||
})
|
uni.removeStorageSync('sysVersion');
|
||||||
|
uni.removeStorageSync('dynamicModelExtra');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleAuthorized() {
|
export default request;
|
||||||
if (!isRelogin.show) {
|
|
||||||
isRelogin.show = true
|
|
||||||
const res = await uni.showModal({
|
|
||||||
title: '登录过期',
|
|
||||||
content: '您的登录已过期,请重新登录',
|
|
||||||
showCancelButton: false,
|
|
||||||
confirmText: '重新登录'
|
|
||||||
})
|
|
||||||
if (res.confirm) {
|
|
||||||
// 清除缓存(建议用项目封装的removeToken方法)
|
|
||||||
uni.removeStorageSync('token')
|
|
||||||
uni.removeStorageSync('refreshToken')
|
|
||||||
uni.removeStorageSync('cid')
|
|
||||||
uni.removeStorageSync('userInfo')
|
|
||||||
uni.removeStorageSync('permissionList')
|
|
||||||
uni.removeStorageSync('sysVersion')
|
|
||||||
uni.removeStorageSync('dynamicModelExtra')
|
|
||||||
uni.reLaunch({ url: '/pages/login/index' })
|
|
||||||
}
|
|
||||||
isRelogin.show = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default request
|
|
||||||