From 9ab6b38c098f857f2ce0772693142c930e4f9b6d Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期六, 30 三月 2024 10:44:03 +0800
Subject: [PATCH] #

---
 pages/LoginDemo/LoginDemo.vue |  160 ++++++++++++++++++++++++----------------------------
 1 files changed, 74 insertions(+), 86 deletions(-)

diff --git a/pages/LoginDemo/LoginDemo.vue b/pages/LoginDemo/LoginDemo.vue
index 53318bc..788e345 100644
--- a/pages/LoginDemo/LoginDemo.vue
+++ b/pages/LoginDemo/LoginDemo.vue
@@ -19,9 +19,6 @@
 					<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>
 		</view>
 		<!-- 璁剧疆寮圭獥鍖哄煙 -->
@@ -30,14 +27,14 @@
 				<!-- 鏍囬 -->
 				<view class="title">缃� 缁� 閰� 缃�</view>
 				<scroll-view scroll-y="true" class="settings-scroll">
-					<view class="scroll-item" v-for="net in network">
-						<view class="item-title" style="">{{net.name}}</view>
+					<view class="scroll-item">
+						<view class="item-title" style="">{{network.name}}</view>
 						<view style="display: flex;align-items: center;">
-							<input class="settings-input1" type="text" v-model="net.ip">
+							<input class="settings-input1" type="text" v-model="network.ip">
 							<text style="font-weight: 900;">:</text>
-							<input class="settings-input2" type="text" v-model="net.port">
+							<input class="settings-input2" type="text" v-model="network.port">
 							<text style="font-weight: 900;">/</text>
-							<input class="settings-input3" type="text" v-model="net.address">
+							<input class="settings-input3" type="text" v-model="network.address">
 						</view>
 					</view>
 				</scroll-view>
@@ -63,32 +60,26 @@
 
 <script>
 	// import { data } from 'jquery'
-	import {
-		mapState
-	} from 'vuex' //寮曞叆mapState
+	import { mapState } from 'vuex' //寮曞叆mapState
+	import store from '@/store/index.js';
 	import md5 from '../../static/js/md5.js'
+	import common from '../api/common/common.js'
+	import login from '../api/login/login.js'
 	export default {
 		data() {
 			return {
 				version: '',
 				remberPassword: true,
 				user: {
-					username: '1',
-					password: '2'
+					username: '',
+					password: ''
 				},
-				network: [{
-						name: 'wms',
-						ip: '192.168.1.1',
-						port: '8080',
-						address: 'pswms'
-					},
-					{
-						name: 'wcs',
-						ip: '192.168.1.1',
-						port: '9090',
-						address: 'pswcs'
-					}
-				],
+				network: {
+					name: 'wms',
+					ip: '192.168.1.1',
+					port: '8080',
+					address: 'pswms'
+				},
 				load: {
 					loading: false,
 					btnText: '鐧诲綍'
@@ -96,94 +87,91 @@
 			}
 		},
 		computed: mapState({
-			project: state => state.project
+			project: state => state.project,
+			
 		}),
 		onShow() {
-
 		},
 		mounted() {
-			uni.getSystemInfo({
-				success(res) {
-					// console.log(res);
-				}
-			})
-			if (uni.getStorageSync('user')) {
-				this.user = uni.getStorageSync('user')
-			}
+			// 浠� state 鑾峰彇缃戠粶淇℃伅
+			// 浠� state 鑾峰彇璐﹀彿淇℃伅
+			console.log(store.state);
+			this.user = store.state.userInfo
+			this.network = store.state.network
 			// 鎵嬫満绔増鏈彿
 			// #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')) {
 					this.network = uni.getStorageSync('Network')
 				}
 				this.$refs.settings.open()
+				
 			},
 			cancel() {
 				this.$refs.settings.close()
 			},
 			confirm() {
-				uni.setStorageSync('Network', this.network);
+				let baseUrl = `http://${this.network.ip}:${this.network.port}/${this.network.address}`
+				this.$store.commit("setNetwork", this.network);
+				this.$store.commit("setBaseUrl", baseUrl);
 				this.$refs.settings.close()
 			},
-			onLogin() {
-				let _this = this,
-					path = 'demo',
-					network = uni.getStorageSync('Network');
-				if (!network) {
+			async onLogin() {
+				// 楠岃瘉ip淇℃伅
+				// 楠岃瘉璐﹀彿淇℃伅
+				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 login.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);
+						this.$store.commit("setUserInfo", this.user);
+					}, 700)
+				} else if (res.code === 0) {
+					this.load.loading = false;
+					this.load.btnText = '鐧诲綍';
 					uni.showToast({
-						icon: 'error',
-						title: '璇烽厤缃綉缁滀俊鎭�'
+						icon: 'none',
+						title: '杩炴帴澶辫触锛岃妫�鏌ヨ澶囩綉缁�/IP鍦板潃鏄惁姝g‘锛�'
+					})
+				} 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}椤圭洰,璇疯仈绯荤鐞嗗厓`);
-						// 	}
-
-						// })
-					}
-				})
-			}
+			},
 		}
 	}
 </script>

--
Gitblit v1.9.1