From 11936dee44933bf5f58d9483db0916cf8dce09a6 Mon Sep 17 00:00:00 2001
From: YunaiV <zhijiantianya@gmail.com>
Date: Thu, 25 Nov 2021 22:33:28 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=20request=20=E8=AF=B7?=
 =?UTF-8?q?=E6=B1=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 yudao-vue-ui/common/js/request.js  | 43 ++++++++++++++++++++++++++++++
 yudao-vue-ui/pages/tabbar/user.vue |  6 ++---
 2 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100644 yudao-vue-ui/common/js/request.js

diff --git a/yudao-vue-ui/common/js/request.js b/yudao-vue-ui/common/js/request.js
new file mode 100644
index 000000000..45ec89d11
--- /dev/null
+++ b/yudao-vue-ui/common/js/request.js
@@ -0,0 +1,43 @@
+const BASE_URL = 'http://127.0.0.1:28080/api/';
+import { msg } from './util'
+
+export const request = (options) => {
+	return new Promise((resolve, reject) => {
+		// 发起请求
+		uni.request({
+			url: BASE_URL + options.url,
+			method: options.method || 'GET',
+			data: options.data || {},
+			header: {
+				'Authorization': '' // TODO 芋艿:带 token
+			}
+		}).then(res => {
+			debugger
+			res = res[1];
+			const statusCode = res.statusCode;
+			if (statusCode !== 200) {
+				msg('请求失败,请重试');
+				return;
+			}
+			
+			const code = res.data.code;
+			const message = res.data.msg;
+			// Token 过期,引导重新登陆
+			if (code === 401) {
+				msg('登录信息已过期,请重新登录');
+				store.commit('logout');
+				reject('无效的登录信息');
+				return;
+			}
+			// 其它失败情况
+			if (code > 0) {
+				msg(message);
+				reject(message);
+				return;
+			}
+			resolve(res.data.data);
+		}).catch((err) => {
+			reject(err);
+		})
+	})
+}
diff --git a/yudao-vue-ui/pages/tabbar/user.vue b/yudao-vue-ui/pages/tabbar/user.vue
index 8e72213bc..24e702fcc 100644
--- a/yudao-vue-ui/pages/tabbar/user.vue
+++ b/yudao-vue-ui/pages/tabbar/user.vue
@@ -19,7 +19,7 @@
 			<!-- 下面的圆弧 -->
 			<image class="user-background-arc-line" src="/static/icon/arc.png" mode="aspectFill"></image>
 		</view>
-		
+
 		<!-- 订单信息 -->
 		<view class="order-wrap">
 			<view class="order-header row" @click="navTo('/pages/order/list?current=0', {login: true})">
@@ -50,7 +50,7 @@
 				</view>
 			</view>
 		</view>
-		
+
 		<!-- 功能入口 -->
 		<view class="option-wrap">
 			<!-- <mix-list-cell icon="icon-iconfontweixin" iconColor="#fa436a" title="我的钱包" @onClick="navTo('/pages/wallet/index', {login: true})"></mix-list-cell> -->
@@ -95,7 +95,7 @@
 	.user-wrapper {
 		position: relative;
 		overflow: hidden;
-		padding-top: calc(var(--status-bar-height) + 52rpx);	
+		padding-top: calc(var(--status-bar-height) + 52rpx);
 		padding-bottom: 6rpx;
 		.user {
 			display: flex;