From 69a1b3bf45738f048361ee4ccb6bdc64fce35720 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期三, 12 三月 2025 11:31:46 +0800
Subject: [PATCH] 更新

---
 pda/utils/service.js |   70 +++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/pda/utils/service.js b/pda/utils/service.js
new file mode 100644
index 0000000..26992f6
--- /dev/null
+++ b/pda/utils/service.js
@@ -0,0 +1,70 @@
+import { baseUrl } from "./config.js"
+export const http = function (options) {
+	{
+		return new Promise((resolve, reject) => {
+			let token = uni.getStorageSync('token') || null
+			// 鍦ㄧ櫥褰曠殑鏃跺�欓渶瑕佸偍瀛� token uni.setStorageSync("authorization","杩欓噷鏄櫥褰曡幏鍙栫殑token鍊�")
+
+			uni.showLoading({
+				title: '鍔犺浇涓�',
+				mask: true
+			})
+			uni.request({
+				url: baseUrl + options.url,
+				data: options.data || {},
+				method: options.method || 'GET',
+				header: options.header || {
+					// 鏍规嵁瀹為檯鎺ュ彛璁捐 key 鍙� token 鎴栬�� authorization
+					dm_user_token: token,
+					"content-type": 'application/json;charset=UTF-8'
+				},
+				success: (res) => {
+					let data = res.data
+					// 鎺у埗鍙版樉绀烘暟鎹俊鎭�
+					uni.hideLoading()
+					// 鐧诲綍杩囨湡
+					if (data.code === 5112 || data.code === 5111) {
+						setTimeout(() => {
+							uni.showToast({
+								title: data.message,
+								icon: "none",
+								duration: 2000
+							})
+						})
+						uni.navigateTo({
+							url: '/pages/index/login'
+						})
+						return
+					}
+					if (data.code !== 200) {
+						setTimeout(() => {
+							uni.showToast({
+								title: data.message,
+								icon: "none",
+								duration: 2000
+							})
+						})
+						return
+					}
+					resolve(data)
+					// return response.data
+				},
+				fail: (err) => {
+					// 椤甸潰涓脊妗嗘樉绀哄け璐�
+					uni.showToast({
+						title: '璇锋眰鎺ュ彛澶辫触',
+						icon: "none",
+					})
+					console.log('err', err)
+					console.log('msg', baseUrl + options.url)
+					// 杩斿洖閿欒娑堟伅
+					reject(err)
+					uni.hideLoading()
+				},
+				catch: (e) => {
+					console.log(e)
+				}
+			})
+		})
+	}
+}
\ No newline at end of file

--
Gitblit v1.9.3