From 1efd7d5350b8ce4a5c0ff5849e2635c2e32cb380 Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Fri, 28 May 2021 08:40:11 +0800
Subject: [PATCH] 对接登入接口

---
 pages/loging/loging.vue |    8 +-
 pages/myself/myself.vue |   19 +-----
 store/mutations.js      |   10 ++-
 store/actions.js        |   98 +++++++++++++++++---------------
 4 files changed, 66 insertions(+), 69 deletions(-)

diff --git a/pages/loging/loging.vue b/pages/loging/loging.vue
index bc49ee8..f6e46dd 100644
--- a/pages/loging/loging.vue
+++ b/pages/loging/loging.vue
@@ -33,8 +33,8 @@
 		data() {
 			return {
 				icons: '',
-				names: '1',
-				passwords: '111111',
+				names: 'test',
+				passwords: '123456',
 				msg: '',
 				colors: '#123456'
 			}
@@ -52,11 +52,11 @@
 				if (login == "true" && name != '') {
 					//获取用户信息
 					var data = {
-						name: name
+						userName: name
 					}
 					this.$store.commit('getUse', data)
 					wx.reLaunch({
-						url: '/pages/workbench/workbench?login=' + data.name
+						url: '/pages/workbench/workbench?login=' + data.userName
 					})
 				}
 			},
diff --git a/pages/myself/myself.vue b/pages/myself/myself.vue
index f752b4e..6065a9e 100644
--- a/pages/myself/myself.vue
+++ b/pages/myself/myself.vue
@@ -7,7 +7,7 @@
 					<img class="img" :src="useimg" alt="">
 				</view>
 				<view class="usermsg">
-					<view>{{userMsg.useName}}</view>
+					<view>{{userName}}</view>
 					<view></view>
 				</view>
 			</view>
@@ -83,19 +83,6 @@
 			<uniPopup :textmsg="textmsg" @cancel='operation(1)' @confirm='operation(2)' v-show="showTextmsg">
 			</uniPopup>
 		</view>
-		<!-- <view class="m-body">
-			<!-- <card :h="17">
-				<floats :w="17" :h="17" :img="'../../static/img/out.png'" :msg="$store.state.loging == true? '登出': '登入'"
-					@onck="outIn"></floats>
-			</card> -->
-			<!-- <view class="m-b-top">
-				<view class="m-b-t-once" @click="outIn">
-					<image class="img" src="../../static/img/out.png" mode=""></image>
-					<span>{{butTitle}}</span>
-				</view>
-			</view> -->
-			
-		<!-- </view> -->
 	</view>
 </template>
 
@@ -119,8 +106,8 @@
 			uniPopup
 		},
 		computed: {
-			userMsg() {
-				return this.$store.state.message;
+			userName() {
+				return this.$store.state.puserName;
 			},
 			butTitle(){
 				return this.$store.state.loging == true? '登出': '登入'
diff --git a/store/actions.js b/store/actions.js
index 4deeaab..18674a7 100644
--- a/store/actions.js
+++ b/store/actions.js
@@ -16,53 +16,59 @@
 				},
 			],
 			pasw = md5(data.pass),
-			url = 'http://web.byisf.com/api/blade-auth/oauth/token?tenantId=000000&username=' + data.name +' &password=' + pasw + '&grant_type=password&scope=all&type=account';
-			// url ='http://192.168.0.109:82/blade-auth/oauth/token';
-			// url ='http://192.168.0.109:82/blade-auth/oauth/token?tenantId=000000&username=admin&password=93369e86dc5fa854a0eaf75558c4039d&grant_type=password';
-			// url ='http://web.byisf.com/api/blade-auth/oauth/token?tenantId=000000&username=admin&password=93369e86dc5fa854a0eaf75558c4039d&grant_type=password&scope=all';
-		// wx.request({ //uniapp 自带axios
-		// 	url: url, //仅为示例,并非真实接口地址。
-		// 	// data: d,
-		// 	// data: {
-		// 	// 	tenantId: '000000',
-		// 	// 	username: data.name,
-		// 	// 	password: pasw,
-		// 	// 	grant_type: 'password',
-		// 	// 	scope: 'all',
-		// 	// 	type: "account"
-		// 	// },
-		// 	header: {
-		// 		// "Content-Type":"",
-		// 		'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
-		// 		"Tenant-Id": "000000",
-		// 		"Captcha-Key": "14c53622c5a0d633d10318fcea86acc2",
-		// 		"Captcha-Code": '',
-		// 		// "Cookie": "JSESSIONID=maOJY05vT2jj4nHwsQGSPgWWVFH1mY-TGWOLYCSh"
-		// 	},
-		// 	method: "post",
-		// 	// dataType: 'JSON',
-		// 	success: (res) => {
-		// 		console.log(res)
-		// 	},
-		// 	fail: (res) => {
-		// 		console.log('失去连接 请稍等');
-		// 		console.log(res);
-		// 	}
-		// });
-		var time = setTimeout(() => { //模拟请求时间
-			var ud = user,
-				isit = false;
-			for (var key in ud) {
-				if (ud[key].name == data.name && ud[key].password == data.pass) {
-					isit = true;
-					break;
-				} else {
-					isit = false;
-				}
+			url = 'https://web.byisf.com/api/blade-auth/oauth/token?tenantId=000000&username=' + data.name +
+			' &password=' + pasw + '&grant_type=password&scope=all&type=account';
+		// url ='http://192.168.0.109:82/blade-auth/oauth/token';
+		// url ='http://192.168.0.109:82/blade-auth/oauth/token?tenantId=000000&username=admin&password=93369e86dc5fa854a0eaf75558c4039d&grant_type=password';
+		// url ='http://web.byisf.com/api/blade-auth/oauth/token?tenantId=000000&username=admin&password=93369e86dc5fa854a0eaf75558c4039d&grant_type=password&scope=all';
+		// console.log(url);
+		wx.request({ //uniapp 自带axios
+			url: url, //仅为示例,并非真实接口地址。
+			// data: d,
+			// data: {
+			// 	tenantId: '000000',
+			// 	username: data.name,
+			// 	password: pasw,
+			// 	grant_type: 'password',
+			// 	scope: 'all',
+			// 	type: "account"
+			// },
+			header: {
+				// "Content-Type":"",
+				"Authorization": "Basic c2FiZXI6c2FiZXJfc2VjcmV0",
+				"Tenant-Id": "000000"
+
+				// "Cookie": "JSESSIONID=maOJY05vT2jj4nHwsQGSPgWWVFH1mY-TGWOLYCSh"
+			},
+			method: "post",
+			// 	// dataType: 'JSON',
+			success: (res) => {
+				data.isit = true;
+				data.userName = res.data.real_name;//警袁姓名
+				data.userID = res.data.user_id;//警袁id
+				// data.userPhon = res.user_id;
+				store.commit('login', data);
+				// console.log(res)
+			},
+			fail: (res) => {
+				console.log('失去连接 请稍等');
+				// console.log(res);
 			}
-			data.isit = isit;
-			store.commit('login', data);
-		}, 2000)
+		});
+		// var time = setTimeout(() => { //模拟请求时间
+		// 	var ud = user,
+		// 		isit = false;
+		// 	for (var key in ud) {
+		// 		if (ud[key].name == data.name && ud[key].password == data.pass) {
+		// 			isit = true;
+		// 			break;
+		// 		} else {
+		// 			isit = false;
+		// 		}
+		// 	}
+		// 	data.isit = isit;
+		// 	store.commit('login', data);
+		// }, 2000)
 
 	}
 }
diff --git a/store/mutations.js b/store/mutations.js
index 595ce97..db8ee9e 100644
--- a/store/mutations.js
+++ b/store/mutations.js
@@ -2,13 +2,16 @@
 
 const mutations = {
 	login(state, data) {
+		console.log(data);
 		state.loging = data.isit; //登入状态
 		if (data.isit) { //写入用户数据
-			state.message.useName = data.name;
+			state.message.useName = data.userName;
+			state.puserName = data.userName;
+			state.puserID = data.userID;
 		}
 		//储存用户
 		WxStorage.set("init", "true");
-		WxStorage.set("name", data.name);
+		WxStorage.set("name", data.userName);
 	},
 	loginReset(state) { //重置
 		state.loging = false;
@@ -16,7 +19,8 @@
 		WxStorage.clear();
 	},
 	getUse(state,data){
-		state.message.useName = data.name;
+		state.puserName = data.userName;
+		// console.log(state.puserName)
 	}
 }
 

--
Gitblit v1.9.3