From b217ec6d467ef11448dbcfa56f236ebe94f4be65 Mon Sep 17 00:00:00 2001
From: cuiqian2004 <cuiqian2004@163.com>
Date: 星期四, 05 九月 2024 09:56:15 +0800
Subject: [PATCH] 去除 store

---
 pages/index/index.vue |  206 +++++++++++++++++++++++++++-----------------------
 1 files changed, 111 insertions(+), 95 deletions(-)

diff --git a/pages/index/index.vue b/pages/index/index.vue
index 3338b09..382eb2d 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -28,24 +28,19 @@
 <script>
 	import Base64 from '../../components/js-base64/base64.js'
 	import utils from "@/js/utils.js"
+	import {
+		areaFunc
+	} from "@/api/index.js"
+	import {
+		getFuncTree
+	} from "@/api/mobox.js"
+
 	export default {
 		modules: {
 			Base64,
 		},
 		onNavigationBarButtonTap(e) {
-			// console.log(e.text);
-			// console.log(e.fontSize);
-			this.$store.state.areaFunc = '';
-			this.$store.commit("classAttrList", null);
-			this.$store.commit("classGridStyleInfo", null);
-			this.$store.commit("dicValueInfo", null);
-			this.$store.commit("subClassAttrList", null);
-			this.$store.commit("subClassGridStyleInfo", null);
-			//鍒锋柊褰撳墠椤甸潰
-			// location.reload();
-			uni.redirectTo({
-				url: '../index/index?args=9999999999'
-			});
+			this.loadData()
 		},
 		data() {
 			return {
@@ -56,89 +51,110 @@
 		onLoad(options) {
 			console.log(options);
 			// 鑾峰彇鎵�湁AppType="MES",ClientType="2"(PDA)鐨勫紩鐢ㄩ鍩熷姛鑳界偣淇℃伅
-
-			if (this.$store.state.areaFunc)
-				this.data = this.$store.state.areaFunc.data;
-			else {
-				const appType = utils.session.getValue('app_type') || "MES";
-				this.$store.dispatch('areaFunc', {
-					app_type: appType,
-					need_ace:1,
-				}).then(success => {
-					// console.log(success);
-					if (success.code == '00000' || success.err_code == 0) {
-						this.data = success.data;
-						if (success.err_code != undefined) { //鍒ゆ柇鏄惁鏄疢obox3
-							success.result.forEach(async (area, index) => {
-								if (area.client_type == 2) { //鍒ゆ柇绫诲瀷鏄惁鏄疨DA绫诲瀷
-								area.app_type= appType
-									await this.GetFuncTree(index, area);
-								}
-							});
-						}
-					} else {
-						uni.showModal({
-							title: this.translateSys("error"),
-							content: success.msg,
-							showCancel: false,
-							confirmText: this.translateSys("cancel")
-						});
-					}
-				}).catch(ex => {
-					// console.log(ex);
-					uni.showModal({
-						title: this.translateSys("error"),
-						content: ex.errMsg,
-						showCancel: false,
-						confirmText: this.translateSys("cancel")
-					});
-				});
-			}
+			this.loadData()
 
 		},
 		methods: {
-			async GetFuncTree(index, area) { //Mobox3鑾峰彇搴旂敤棰嗗煙鐨勫姛鑳界偣
-				this.data = [];
-				var $this = this;
+			setData: function(obj) {
+				let that = this;
+				let keys = [];
+				let val, data;
 
-				var json = {
-					app_type: area.app_type,
-					area_id: area.id,
-					area_client_type: area.client_type,
-					need_ace:1,
-				};
-				this.$store.dispatch('GetFuncTree', json).then(success => {
-					// console.log(success);
-					if (success.err_code == 0) {
-						if ((success.result || []).length > 0) {
-							$this.data.push(success.result[0]);
-							console.log("onLoad", $this.data)
-							this.$store.commit("areaFunc", $this.data);
+				Object.keys(obj).forEach(function(key) {
+					keys = key.split(".");
+					val = obj[key];
+					data = that.$data;
+					keys.forEach(function(key2, index) {
+						if (index + 1 == keys.length) {
+							that.$set(data, key2, val);
+						} else {
+							if (!data[key2]) {
+								that.$set(data, key2, {});
+							}
 						}
-
-					} else {
-						uni.showModal({
-							title: this.translateSys("error"),
-							content: success.msg,
-							showCancel: false,
-							confirmText: this.translateSys("cancel")
-						});
-					}
-				}).catch(ex => {
-					// console.log(ex);
-					uni.showModal({
-						title: this.translateSys("error"),
-						content: ex.errMsg,
-						showCancel: false,
-						confirmText: this.translateSys("cancel")
+						data = data[key2];
 					});
 				});
 			},
-			appCreate(app) { //鐐瑰嚮鍔熻兘鐐硅烦杞〉闈�-				console.log(app);
-				var paramStr = this.$store.state.OIMoboxSAPI ? app.param : app.Param;
-				var appName = this.$store.state.OIMoboxSAPI ? (app.list_name || app.name) : app.Name;
-				var defCode = this.$store.state.OIMoboxSAPI ? app.def_code : app.DefCode;
+
+			async loadData() {
+				try {
+					this.setData({
+						data: []
+					})
+					const appType = utils.session.getValue('app_type') || "MES";
+					const list = await areaFunc(appType, 1) || []
+					const app = getApp()
+					if (app.globalData.isMobox3) {
+						const list2 = []
+						for (let i in list) {
+							const area = list[i]
+							area.app_type = appType
+							const areaApp = await this.GetFuncTree(i, area)
+							console.log(areaApp)
+							if (areaApp) {
+								list2.push(areaApp)
+							}
+						}
+						this.setData({
+							data: list2
+						})
+					} else {
+						this.setData({
+							data: list
+						})
+					}
+				} catch (ex) {
+					console.log(ex);
+					let exStr = JSON.stringify(ex)
+					if (exStr == "{}")
+						exStr = ex
+					let tip = typeof ex.errMsg == "string" ? ex.errMsg : exStr
+					uni.showModal({
+						title: this.translateSys("error"),
+						content: tip,
+						showCancel: false,
+						confirmText: this.translateSys("cancel")
+					});
+				}
+
+
+			},
+			async GetFuncTree(index, area) { //Mobox3鑾峰彇搴旂敤棰嗗煙鐨勫姛鑳界偣		
+				try {
+					var param = {
+						app_type: area.app_type,
+						area_id: area.id,
+						area_client_type: area.client_type,
+						need_ace: 1,
+					};
+					const res = await getFuncTree(param) || []
+					if (res.length > 0)
+						return res[0]
+					else
+						return undefined
+				} catch (ex) {
+					console.log(ex);
+					let exStr = JSON.stringify(ex)
+					if (exStr == "{}")
+						exStr = ex
+					let tip = typeof ex.errMsg == "string" ? ex.errMsg : exStr
+					uni.showModal({
+						title: this.translateSys("error"),
+						content: tip,
+						showCancel: false,
+						confirmText: this.translateSys("cancel")
+					});
+					return undefined
+				}
+			},
+			appCreate(appInfo) { //鐐瑰嚮鍔熻兘鐐硅烦杞〉闈�+				console.log(appInfo);
+				const app = getApp()
+
+				var paramStr = app.globalData.isMobox3 ? appInfo.param : appInfo.Param;
+				var appName = app.globalData.isMobox3 ? (appInfo.list_name || appInfo.name) : appInfo.Name;
+				var defCode = app.globalData.isMobox3 ? appInfo.def_code : appInfo.DefCode;
 				var param = "";
 				if (paramStr) {
 					//mobox2鐨刾aram鏄痡son瀛楃涓�@@ -157,7 +173,7 @@
 					return;
 				}
 				if (defCode == '3018') {
-					if (this.$store.state.OIMoboxSAPI) { //Mobox3
+					if (app.globalData.isMobox3) { //Mobox3
 						uni.navigateTo({
 							// url:'../modal/3018?param='+param+"&titlename="+appName
 							url: '../modal/3018_2?param=' + param + "&titlename=" + appName
@@ -168,7 +184,7 @@
 						});
 					}
 				} else if (defCode == '3037') {
-					if (this.$store.state.OIMoboxSAPI) { //Mobox3
+					if (app.globalData.isMobox3) { //Mobox3
 						uni.navigateTo({
 							// url:'../modal/3037?param='+param+"&titlename="+appName
 							url: '../modal/3037_2?param=' + param + "&titlename=" + appName
@@ -179,31 +195,31 @@
 						});
 					}
 				} else if (defCode == '3200') {
-					if (this.$store.state.OIMoboxSAPI) { //Mobox3
+					if (app.globalData.isMobox3) { //Mobox3
 						uni.navigateTo({
 							url: '../modal/3200?param=' + param + "&titlename=" + appName
 						});
 					}
 				} else if (defCode == '3201') {
-					if (this.$store.state.OIMoboxSAPI) { //Mobox3
+					if (app.globalData.isMobox3) { //Mobox3
 						uni.navigateTo({
 							url: '../modal/3201?param=' + param + "&titlename=" + appName
 						});
 					}
 				} else if (defCode == '5600') { //鐮佺洏
-					if (this.$store.state.OIMoboxSAPI) { //Mobox3
+					if (app.globalData.isMobox3) { //Mobox3
 						uni.navigateTo({
 							url: '../modal/5600?param=' + param + "&titlename=" + appName
 						});
 					}
 				} else if (defCode == '5601') { //鐮佺洏
-					if (this.$store.state.OIMoboxSAPI) { //Mobox3
+					if (app.globalData.isMobox3) { //Mobox3
 						uni.navigateTo({
 							url: '../modal/5601?param=' + param + "&titlename=" + appName
 						});
 					}
 				} else if (defCode == '5602') { //鍒嗘嫞
-					if (this.$store.state.OIMoboxSAPI) { //Mobox3
+					if (app.globalData.isMobox3) { //Mobox3
 						uni.navigateTo({
 							url: '../modal/5602?param=' + param + "&titlename=" + appName
 						});

--
Gitblit v1.9.1