From 09a4dffa44acc386ab66b4e01af473068586e4fb Mon Sep 17 00:00:00 2001
From: Mr.Shi <1878285526@qq.com>
Date: 星期一, 04 九月 2023 10:38:55 +0800
Subject: [PATCH] 小程序

---
 minipro_standard/pages/login/login.vue |   57 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/minipro_standard/pages/login/login.vue b/minipro_standard/pages/login/login.vue
index 1632dbc..8446015 100644
--- a/minipro_standard/pages/login/login.vue
+++ b/minipro_standard/pages/login/login.vue
@@ -7,50 +7,77 @@
 		</view>
 		<view class="bg_w rd8 ptb30 pl40 bbox com-input flex input-height">
 			<image src="@/static/login_ic_code@2x.png" mode="" class="img40 mr25"></image>
-			<u--input placeholder="浼佷笟浠g爜" border="none" v-model="loginForm.companyId"></u--input>
+			<u--input placeholder="浼佷笟浠g爜" border="none" v-model="from.companyId"></u--input>
 		</view>
 		<view class="bg_w rd8 ptb30 pl40 bbox mt40 flex input-height">
 			<image src="@/static/login_ic_phone@2x.png" mode="" class="img40 mr25"></image>
-			<u--input placeholder="鎵嬫満鍙�" border="none" v-model="loginForm.username"></u--input>
+			<u--input placeholder="鎵嬫満鍙�" border="none" v-model="from.username"></u--input>
 		</view>
 		<view class="bg_w rd8 ptb30 pl40 bbox mt40 flex input-height">
 			<image src="@/static/login_ic_password@2x.png" mode="" class="img40 mr25"></image>
-			<u--input placeholder="瀵嗙爜" border="none" v-model="loginForm.password"></u--input>
+			<u--input placeholder="瀵嗙爜" border="none" v-model="from.password"></u--input>
 		</view>
 		<view class="login-btn mt80" @click="loginAction">绔嬪嵆鐧诲綍</view>
 	</view>
 </template>
 
 <script>
-	import { wxAccountLogin, getUserInfo } from '@/util/api/index.js'
+	import { wxLogin, wxAccountLogin, getUserInfo, wxProgramLogin } from '@/util/api/index.js';
 	export default {
 		data() {
 			return {
-				loginForm: {
+				from: {
+					openid: '',
+					unionid: '',
 					companyId: '',
 					username: '',
 					password: ''
 				}
 			};
 		},
+		onLoad() {
+			var that = this
+			uni.login({
+				provider: 'weixin',
+				success: function (loginRes) {
+					wxProgramLogin({ code: loginRes.code })
+						.then(async (res) => {
+							if (res.code === 200) {
+								// 鍏嶇櫥褰曪紝鐩存帴璺抽椤�
+								if (res.data.loginStatus == 0) {
+									that.$store.commit('SETSESSION', res.data.session)
+									let info = await getUserInfo()
+									if (info.code === 200) {
+										await that.$store.commit('setEntrance', 'WX')
+										await that.$store.commit('setUserInfo', info.data)
+										await that.$store.dispatch('getMenuList', 2)
+										uni.switchTab({
+											url: '/pages/workbench/workbench'
+										});
+									}
+								} else {
+									that.from.openid = res.data.openid
+									that.from.unionid = res.data.unionid
+								}
+							}
+						})
+				}
+			});
+		},
 		methods: {
 			async loginAction() {
-				if (!this.loginForm.companyId) return uni.showToast({ title: '浼佷笟浠g爜涓嶈兘涓虹┖', icon:"error", duration: 2000 });
-				if (!this.loginForm.username) return uni.showToast({ title: '鎵嬫満鍙蜂笉鑳戒负绌�', icon:"error", duration: 2000 });
-				if (!this.loginForm.password) return uni.showToast({ title: '瀵嗙爜涓嶈兘涓虹┖', icon:"error", duration: 2000 });
-				let res = await wxAccountLogin({
-					companyId: this.loginForm.companyId,
-					username: this.loginForm.username,
-					password: this.loginForm.password
-				})
+				if (!this.from.companyId) return uni.showToast({ title: '浼佷笟浠g爜涓嶈兘涓虹┖', icon:"error", duration: 2000 });
+				if (!this.from.username) return uni.showToast({ title: '鎵嬫満鍙蜂笉鑳戒负绌�', icon:"error", duration: 2000 });
+				if (!this.from.password) return uni.showToast({ title: '瀵嗙爜涓嶈兘涓虹┖', icon:"error", duration: 2000 });
+				let res = await wxAccountLogin(this.from)
 				if (res.code === 200) {
 					let user = await getUserInfo({})
 					if (user.code === 200) {
 						await this.$store.commit('SETUSERINFO', user.data)
 						await this.$store.dispatch('getMenuList', 2)
-						uni.reLaunch({
+						uni.switchTab({
 							url: '/pages/workbench/workbench'
-						})
+						});
 					}
 				}
 			}

--
Gitblit v1.9.3