From 0f5bd3db43a7ea07d3373b38bd24126544de5e2f Mon Sep 17 00:00:00 2001 From: zhuguifei <zhuguifei@zhuguifeideiMac.local> Date: 星期一, 21 四月 2025 18:32:39 +0800 Subject: [PATCH] 完成设备点检 --- eims-ui-mobile/src/utils/http.ts | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/eims-ui-mobile/src/utils/http.ts b/eims-ui-mobile/src/utils/http.ts index 4106b0b..f1d74ce 100644 --- a/eims-ui-mobile/src/utils/http.ts +++ b/eims-ui-mobile/src/utils/http.ts @@ -2,6 +2,9 @@ import { useUserStore, useAccessStore } from '@/store' export const http = <T>(options: CustomRequestOptions) => { + uni.showLoading({ + title: '鍔犺浇涓�', + }) // 1. 杩斿洖 Promise 瀵硅薄 return new Promise<IResData<T>>((resolve, reject) => { uni.request({ @@ -12,11 +15,26 @@ // #endif // 鍝嶅簲鎴愬姛 success(res) { + uni.hideLoading() // 鐘舵�佺爜 2xx锛屽弬鑰� axios 鐨勮璁� if (res.statusCode >= 200 && res.statusCode < 300) { // 2.1 鎻愬彇鏍稿績鏁版嵁 res.data if ((res.data as IResData<T>).code === 200) { resolve(((res.data as IResData<T>).data || res.data) as IResData<T>) + } else if ((res.data as IResData<T>).code === 401) { + uni.showToast({ + icon: 'none', + title: '鐧诲綍瓒呮椂锛岃閲嶆柊鐧诲綍锛�', + }) + // 401閿欒 -> 娓呯悊鐢ㄦ埛淇℃伅锛岃烦杞埌鐧诲綍椤� + useAccessStore().clearAccessInfo() + useUserStore().clearUserInfo() + const loginRoute = '/pages/login/index' + // 閲嶆柊鐧诲綍鍚庤繑鍥為〉闈� + const url = '/pages/home/index' + const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}` + uni.navigateTo({ url: redirectRoute }) + reject(res) } else { uni.showToast({ icon: 'none', @@ -46,6 +64,7 @@ title: '缃戠粶閿欒锛屾崲涓綉缁滆瘯璇�', }) reject(err) + uni.hideLoading() }, }) }) @@ -85,5 +104,19 @@ }) } +export const httpPut = <T>( + url: string, + data?: Record<string, any>, + query?: Record<string, any>, +) => { + return http<T>({ + url, + query, + data, + method: 'PUT', + }) +} + http.get = httpGet http.post = httpPost +http.put = httpPut -- Gitblit v1.9.3