From b5c0993eb8043882eae85ce9ab1d860ff8bebf17 Mon Sep 17 00:00:00 2001
From: whycq <10027870+whycq@user.noreply.gitee.com>
Date: 星期四, 28 三月 2024 13:52:56 +0800
Subject: [PATCH] #

---
 pages/LoginDemo/LoginDemo.vue |  108 ++++++++++++++++++++++++++---------------------------
 1 files changed, 53 insertions(+), 55 deletions(-)

diff --git a/pages/LoginDemo/LoginDemo.vue b/pages/LoginDemo/LoginDemo.vue
index 53318bc..e399630 100644
--- a/pages/LoginDemo/LoginDemo.vue
+++ b/pages/LoginDemo/LoginDemo.vue
@@ -19,10 +19,7 @@
 					<switch :checked='remberPassword' color="#FFCC33" style="zoom:.5" @change="remberChange" />
 				</view>
 			</view>
-			<!-- <view class="button" @click="login" :loading="load.loading">
-				{{load.btnText}} 
-			</view> -->
-			<button class="button" @click="onLogin()" :loading="load.loading">{{load.btnText}}</button>
+			<button class="button" @click="login()" :loading="load.loading">{{load.btnText}}</button>
 		</view>
 		<!-- 璁剧疆寮圭獥鍖哄煙 -->
 		<uni-popup ref="settings" type="dialog">
@@ -67,14 +64,15 @@
 		mapState
 	} from 'vuex' //寮曞叆mapState
 	import md5 from '../../static/js/md5.js'
+	import common from '../api/common/common.js'
 	export default {
 		data() {
 			return {
 				version: '',
 				remberPassword: true,
 				user: {
-					username: '1',
-					password: '2'
+					username: '',
+					password: ''
 				},
 				network: [{
 						name: 'wms',
@@ -112,15 +110,16 @@
 			}
 			// 鎵嬫満绔増鏈彿
 			// #ifdef APP-PLUS
-			var that = this
+			var _this = this
 			plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
-				that.version = wgtinfo.version
+				_this.version = wgtinfo.version
 			});
 			// #endif
 		},
 		methods: {
 			remberChange() {
-
+				this.remberPassword = !this.remberPassword
+				
 			},
 			settings() {
 				if (uni.getStorageSync('Network')) {
@@ -135,55 +134,54 @@
 				uni.setStorageSync('Network', this.network);
 				this.$refs.settings.close()
 			},
-			onLogin() {
-				let _this = this,
-					path = 'demo',
-					network = uni.getStorageSync('Network');
-				if (!network) {
+			async login() {
+				if (!uni.getStorageSync('Network')) {
+					uni.showToast({ icon: 'error', title: '璇烽厤缃綉缁滀俊鎭�' }) 
+					return
+				}
+				if (!this.user.username ) {
+					uni.showToast({ icon: 'none', title: '璇疯緭鍏ヨ处鍙�' }) 
+					return
+				}
+				if (!this.user.password ) {
+					uni.showToast({ icon: 'none', title: '璇疯緭鍏ュ瘑鐮�' }) 
+					return
+				}
+				this.load.loading = true;
+				this.load.btnText = '鐧诲綍涓�';
+				let res = await common.onLogin(this.user)
+				if (res.code === 200) {
+					setTimeout(() => {
+						uni.showToast({
+							title: '鐧诲綍鎴愬姛'
+						})
+						setTimeout(() => {
+							uni.reLaunch({
+								url: `/pages/home/home`,
+							});
+						}, 300)
+						if (!this.remberPassword) {
+							this.user.password = ''
+						}
+						uni.setStorageSync('user', this.user);
+					}, 700)
+				} else if (res.code === 0) {
+					this.load.loading = false;
+					this.load.btnText = '鐧诲綍';
 					uni.showToast({
-						icon: 'error',
-						title: '璇烽厤缃綉缁滀俊鎭�'
+						icon: 'none',
+						title: '杩炴帴澶辫触锛岃妫�鏌ョ綉缁�'
+					})
+				} else {
+					this.load.loading = false;
+					this.load.btnText = '鐧诲綍';
+					uni.showToast({
+						icon: 'none',
+						title: `${this.user.username} ${res.msg}`
 					})
 				}
-				// path = network[0].address
-				// path = path.substring(0, path.length - 3);
-				path = _this.project.name
-				let baseUrl = `http://${network[0].ip}:${network[0].port}/${network[0].address}`
-				_this.load.loading = true;
-				_this.load.btnText = '鐧诲綍涓�';
-				uni.setStorageSync('user', _this.user);
-				uni.request({
-					url: `${baseUrl}/login.action`,
-					data: {
-						username: _this.user.username,
-						password: md5.hex_md5(_this.user.password)
-					},
-					success(res) {
-						res = res.data
-						if (res.code === 200) {
-							uni.setStorageSync('token', res.data.token);
-							_this.load.btnText = '鐧诲綍涓�';
-							setTimeout(() => {
-								uni.showToast({
-									title: '鐧诲綍鎴愬姛'
-								})
-								setTimeout(() => {
-									uni.reLaunch({
-										url: `/pages/home/home`,
-									});
-								}, 300)
-							}, 700)
-						}
-						// uni.navigateTo({
-						// 	url: `/pages/project/${path}/home/home`,
-						// 	fail(res) {
-						// 		console.log(`娌℃湁${path}椤圭洰,璇疯仈绯荤鐞嗗厓`);
-						// 	}
-
-						// })
-					}
-				})
-			}
+			},
+			// end
 		}
 	}
 </script>

--
Gitblit v1.9.1