From f29900986f01cf5d39b5755cec674825cef27961 Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期二, 19 十一月 2024 19:25:41 +0800
Subject: [PATCH] update

---
 src/views/login/components/passwordForm.vue |  281 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 160 insertions(+), 121 deletions(-)

diff --git a/src/views/login/components/passwordForm.vue b/src/views/login/components/passwordForm.vue
index b0eb9cb..32d5b14 100644
--- a/src/views/login/components/passwordForm.vue
+++ b/src/views/login/components/passwordForm.vue
@@ -1,148 +1,187 @@
 <template>
-	<el-form ref="loginForm" :model="form" :rules="rules" label-width="0" size="large" @keyup.enter="login" class="login-form">
+	<el-form ref="loginForm" :model="form" :rules="rules" label-width="0" size="large" @keyup.enter="login"
+		class="login-form">
 		<el-form-item prop="user">
-			<el-input v-model="form.user" prefix-icon="el-icon-user" clearable :placeholder="$t('login.userPlaceholder')" class="inputHeight">
+			<el-input v-model="form.user" prefix-icon="el-icon-user" clearable
+				:placeholder="$t('login.userPlaceholder')" class="inputHeight">
 			</el-input>
 		</el-form-item>
 		<el-form-item prop="password">
-			<el-input v-model="form.password" prefix-icon="el-icon-lock" clearable show-password :placeholder="$t('login.PWPlaceholder')" class="inputHeight"></el-input>
+			<el-input v-model="form.password" prefix-icon="el-icon-lock" clearable show-password
+				:placeholder="$t('login.PWPlaceholder')" class="inputHeight"></el-input>
 		</el-form-item>
 		<el-form-item>
-			<el-button type="primary" style="width: 100%;" :loading="islogin" @click="login">{{ $t('login.signIn') }}</el-button>
+			<el-button type="primary" style="width: 100%;" :loading="islogin" @click="login">{{ $t('login.signIn')
+				}}</el-button>
 		</el-form-item>
 	</el-form>
 </template>
 
 <script>
-	export default {
-		data() {
-			return {
-				userType: 'admin',
-				form: {
-					user: "admin",
-					password: "123456",
-					autologin: false
-				},
-				rules: {
-					user: [
-						{required: true, message: this.$t('login.userError'), trigger: 'blur'}
-					],
-					password: [
-						{required: true, message: this.$t('login.PWError'), trigger: 'blur'}
-					]
-				},
-				islogin: false,
+//import io from 'socket.io-client';
+export default {
+	data() {
+		return {
+			socket: null,
+			userType: 'admin',
+			form: {
+				user: "",
+				password: "",
+				autologin: false
+			},
+			rules: {
+				user: [
+					{ required: true, message: this.$t('login.userError'), trigger: 'blur' }
+				],
+				password: [
+					{ required: true, message: this.$t('login.PWError'), trigger: 'blur' }
+				]
+			},
+			islogin: false,
+		}
+	},
+	watch: {
+		userType(val) {
+			if (val == 'admin') {
+				this.form.user = 'admin'
+				this.form.password = 'admin'
+			} else if (val == 'user') {
+				this.form.user = 'user'
+				this.form.password = 'user'
 			}
-		},
-		watch:{
-			userType(val){
-				if(val == 'admin'){
-					this.form.user = 'admin'
-					this.form.password = 'admin'
-				}else if(val == 'user'){
-					this.form.user = 'user'
-					this.form.password = 'user'
-				}
+		}
+	},
+	mounted() {
+		//this.$HTTP.get('/api/blade-sync/outer-app-config/appStatus')
+	},
+	methods: {
+		async login() {
+			var validate = await this.$refs.loginForm.validate().catch(() => { })
+			if (!validate) { return false }
+			this.islogin = true
+			var data = {
+				username: this.form.user,
+				//password: this.$TOOL.crypto.MD5(this.form.password)
+				password: this.form.password,
+				tenantId: "000000",
+				grant_type: "password",
+				scope: "all"
 			}
-		},
-		mounted() {
-			//this.$HTTP.get('/api/blade-sync/outer-app-config/appStatus')
-		},
-		methods: {
-			async login(){
-				var validate = await this.$refs.loginForm.validate().catch(()=>{})
-				if(!validate){ return false }
-				this.islogin = true
-				var data = {
-					username: this.form.user,
-					//password: this.$TOOL.crypto.MD5(this.form.password)
-					password: this.form.password,
-					tenantId: "000000",
-					grant_type: "password",
-					scope: "all"
+			var isToken = false;
+			await this.$HTTP.postJ("/api/blade-auth/oauth/token?" + this.$TOOL.qsStringify(data)).then(res => {
+				this.islogin = false;
+				if (res.user_id) {
+					isToken = true;
+					//鑾峰彇token
+					this.$TOOL.cookie.set("TOKEN", res.access_token, {
+						expires: this.form.autologin ? 24 * 60 * 60 : 0
+					})
+					res.userName = res.user_name;
+					res.role = ["SA", "admin", "Auditor"];
+					res.dashboard = "0";
+					res.userId = "1";
+					this.$TOOL.data.set("USER_INFO", res);
+				} else {
+					this.$message({
+						showClose: true,
+						message: res.msg || res.error_description,
+						type: 'error'
+					});
 				}
-				//鑾峰彇鑿滃崟
-				// var menu = null
-				// if(this.form.user == 'admin'){
-				// 	menu = await this.$API.system.menu.myMenus.get()
-				// }else{
-				// 	menu = await this.$API.demo.menu.get()
-				// }
-				// if(menu.code == 200){
-				// 	if(menu.data.menu.length==0){
-				// 		this.islogin = false
-				// 		this.$alert("褰撳墠鐢ㄦ埛鏃犱换浣曡彍鍗曟潈闄愶紝璇疯仈绯荤郴缁熺鐞嗗憳", "鏃犳潈闄愯闂�", {
-				// 			type: 'error',
-				// 			center: true
-				// 		})
-				// 		return false
-				// 	}
-				// 	this.$TOOL.data.set("MENU", menu.data.menu)
-				// 	this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
-				// 	this.$TOOL.data.set("DASHBOARDGRID", menu.data.dashboardGrid)
-				// }else{
-				// 	this.islogin = false
-				// 	this.$message.warning(menu.message)
-				// 	return false
-				// }
+			})
+			if (!isToken) return;
+			//鑾峰彇鑿滃崟
+			await this.$HTTP.get("/api/blade-system/menu/routes?" + this.$TOOL.qsStringify({ "appCode": "CPS" })).then(res => {
+				if (res.data.length == 0) {
+					this.islogin = false
+					this.$alert("褰撳墠鐢ㄦ埛鏃犱换浣曡彍鍗曟潈闄愶紝璇疯仈绯荤郴缁熺鐞嗗憳", "鏃犳潈闄愯闂�", {
+						type: 'error',
+						center: true
+					})
+					return false
+				}
+				//寮�濮�
+				function addComponentToLastLevel(items) {
+					return items.map((item) => {
+						// 澶嶅埗褰撳墠椤癸紝閬垮厤鐩存帴淇敼鍘熷瀵硅薄  
+						const clonedItem = { ...item };
 
-				// this.$router.replace({
-				// 	path: '/'
-				// })
-				// this.$message.success("Login Success 鐧诲綍鎴愬姛")
-				// this.islogin = false
-
-
-
-				await this.$HTTP.postJ("/api/blade-auth/oauth/token",data).then(res=> {
-					if(res.user_id) {
-						//鑾峰彇token
-						this.$TOOL.cookie.set("TOKEN", res.access_token, {
-							expires: this.form.autologin? 24*60*60 : 0
-						})
-						res.userName = res.user_name;
-						res.role = ["SA", "admin", "Auditor"];
-						res.dashboard = "0";
-						res.userId =  "1";
-						this.$TOOL.data.set("USER_INFO", res);
-						//鑾峰彇鑿滃崟
-						
-						
-					}else {
-						this.islogin = false;
-						this.$message({
-				          showClose: true,
-				          message: res.error_description,
-				          type: 'error'
-				        });
-					}
-				})
-				await this.$API.system.menu.myMenus.get().then(resp=> {
-							console.log('>>>>>>')
-							if(resp.data.menu.length==0){
-								this.islogin = false
-								this.$alert("褰撳墠鐢ㄦ埛鏃犱换浣曡彍鍗曟潈闄愶紝璇疯仈绯荤郴缁熺鐞嗗憳", "鏃犳潈闄愯闂�", {
-									type: 'error',
-									center: true
-								})
-								return false
+						// 妫�鏌ュ綋鍓嶉」鏄惁鏈� children 灞炴��  
+						if (clonedItem.children) {
+							// 閫掑綊澶勭悊 children  
+							clonedItem.children = addComponentToLastLevel(clonedItem.children);
+						} else {
+							// 濡傛灉娌℃湁 children 灞炴�э紝璇存槑鏄渶鍚庝竴绾э紝娣诲姞 component 瀵硅薄  
+							var len = clonedItem.path.length;
+							if (item.name == "浠诲姟璋冨害") {
+								clonedItem.origin = item.path;
+								clonedItem.component = "myiframe/urlPath";   //鏈塩omponent涓嶅彲浠ヤ娇鐢╥frame
+								clonedItem.path = "/myiframe/urlPath";
+							} else {
+								clonedItem.component = clonedItem.path.substring(1, len);
 							}
-							this.$TOOL.data.set("MENU", resp.data.menu)
-							this.$TOOL.data.set("PERMISSIONS", resp.data.permissions)
-							this.$TOOL.data.set("DASHBOARDGRID", resp.data.dashboardGrid)
-
+						}
+						clonedItem.meta = { title: clonedItem.name, icon: "el-icon-takeaway-box", type: "menu" }
+						return clonedItem;
+					});
+				}
+				var transformedArray = addComponentToLastLevel(res.data);
+				//鑾峰彇澶氫釜宸ヤ綔鍙�
+				this.$HTTP.get("/api/blade-system/workbench/list?status=1").then(resp => {
+					if (resp.data.length) {
+						resp.data.forEach((item, index) => {
+							item.component = "home";
+							item.meta = { title: item.name, icon: 'el-icon-menu', affix: true };
+							item.path = "/dashboard";
+							item.parentId = item.id;
+						})
+						transformedArray.unshift({
+							children: resp.data,
+							code: "desk",
+							component: "console/desk",
+							id: "001",
+							meta: {title:聽'棣栭〉',聽icon:聽'el-icon-takeaway-box',聽type:聽'menu'},
+							name: "棣栭〉",
+							path: "/home"
 						});
+						transformedArray.forEach((item,index)=>{
+							if(item.name == "浠〃鏉�") {
+								transformedArray.splice(1,index);
+							}
+						})
+						var obj = {
+							dashboardGrid: ["Access", "deskNotice", "Entrance"],
+							menu: transformedArray,
+							permissions: ["list.add", "list.edit", "list.delete", "user.add", "user.edit", "user.delete"]
+						}
+						this.$TOOL.data.set("MENU", obj.menu);
+						console.log(obj.menu, 'menu')
+						this.$TOOL.data.set("PERMISSIONS", obj.permissions)
+						this.$TOOL.data.set("DASHBOARDGRID", obj.dashboardGrid)
+
 						this.$router.replace({
 							path: '/'
 						})
-						this.$message.success("Login Success 鐧诲綍鎴愬姛")
-						this.islogin = false
-			},
+						// this.$message.success("Login Success 鐧诲綍鎴愬姛")
+						this.islogin = false;
+					}
+				})
+			})
+
 		}
 	}
+}
 </script>
 
 <style>
-.login-form {margin: 0 auto;margin-top: 46px;width: 354px;}
-.inputHeight {height: 60px;line-height: 60px;}
+.login-form {
+	margin: 0 auto;
+	margin-top: 46px;
+	width: 294px;
+}
+
+.inputHeight {
+	height: 40px;
+	line-height: 40px;
+}
 </style>

--
Gitblit v1.9.3