From d84283821bb08d81d887f20a7118caf25b8b2714 Mon Sep 17 00:00:00 2001
From: cuiqian2004 <cuiqian2004@163.com>
Date: 星期二, 27 八月 2024 18:29:10 +0800
Subject: [PATCH] 判断接口返回值是否是字符串,然后解析

---
 pages/modal/5601.vue |  428 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 259 insertions(+), 169 deletions(-)

diff --git a/pages/modal/5601.vue b/pages/modal/5601.vue
index 503c7dc..50ace94 100644
--- a/pages/modal/5601.vue
+++ b/pages/modal/5601.vue
@@ -296,25 +296,24 @@
 				}
 			},
 			async Head_UIStyleGetInfo(class_id, style_id) { //鑾峰彇鑷畾涔夎〃鍗曟牱寮�-				var $this = this;
-				var dataInfo = {
-					class_id: class_id,
-					ui_style_id: style_id,
-				};
-				this.$store.dispatch('UIStyleGetInfo', dataInfo).then(async (ret) => {
-					// console.log(ret);
-					if (ret.err_code == 0) {
-						var styledef = "";
-						if (ret.result.style_def) {
-							//mobox2鐨剆tyle_def鏄痡son瀛楃涓�-							styledef = ret.result.style_def.replace(/\\/g, "");
-							//mobox3鐨剆tyle_def鏄痓ase64瀛楃涓�-							if (!ret.result.style_def.includes('"')) styledef = Base64.decode(
-								ret.result
-								.style_def);
-						}
-						const styledefHead = styledef ? JSON.parse(styledef) : {};
-
+				try {
+					var $this = this;
+					var dataInfo = {
+						class_id: class_id,
+						ui_style_id: style_id,
+					};
+					const ret = await this.getUIStyleInfo(dataInfo)
+					var styledef = "";
+					if (ret.result.style_def) {
+						//mobox2鐨剆tyle_def鏄痡son瀛楃涓�+						styledef = ret.result.style_def.replace(/\\/g, "");
+						//mobox3鐨剆tyle_def鏄痓ase64瀛楃涓�+						if (!ret.result.style_def.includes('"')) styledef = Base64.decode(
+							ret.result
+							.style_def);
+					}
+					const styledefHead = styledef ? JSON.parse(styledef) : {};
+					if (styledefHead?.form?.items) {
 						for (let i in styledefHead.form.items) {
 							const ele = styledefHead.form.items[i]
 							if (ele.name != "Layout") {
@@ -355,26 +354,95 @@
 								}
 							}
 						}
-						this.setData({
-							head_styledef: styledefHead
-						})
-					} else {
-						uni.showModal({
-							title: this.translateSys("error") + "1",
-							content: ret.err_msg,
-							showCancel: false,
-							confirmText: this.translateSys("cancel")
-						});
+
 					}
-				}).catch(ex => {
+					this.setData({
+						head_styledef: styledefHead
+					})
+				} catch (ex) {
 					// console.log(ex);
 					uni.showModal({
-						title: this.translateSys("error") + "1.1",
+						title: this.translateSys("error") + "1",
 						content: ex.errMsg,
 						showCancel: false,
 						confirmText: this.translateSys("cancel")
 					});
-				});
+					return {}
+				}
+				// this.$store.dispatch('UIStyleGetInfo', dataInfo).then(async (ret) => {
+				// 	// console.log(ret);
+				// 	if (ret.err_code == 0) {
+				// 		var styledef = "";
+				// 		if (ret.result.style_def) {
+				// 			//mobox2鐨剆tyle_def鏄痡son瀛楃涓�+				// 			styledef = ret.result.style_def.replace(/\\/g, "");
+				// 			//mobox3鐨剆tyle_def鏄痓ase64瀛楃涓�+				// 			if (!ret.result.style_def.includes('"')) styledef = Base64.decode(
+				// 				ret.result
+				// 				.style_def);
+				// 		}
+				// 		const styledefHead = styledef ? JSON.parse(styledef) : {};
+
+				// 		for (let i in styledefHead.form.items) {
+				// 			const ele = styledefHead.form.items[i]
+				// 			if (ele.name != "Layout") {
+				// 				if (ele?.useDict) {
+				// 					//鍒ゆ柇useDict鏄惁浣跨敤瀛楀吀
+				// 					await this.DictGetInfo(ele.bind.dict,
+				// 						styledefHead.form.model,
+				// 						ele);
+				// 				}
+				// 				if ($this.focusFieldId == "") {
+				// 					if (ele.name == 'Input' || ele.name ==
+				// 						'InputNumber') {
+				// 						$this.setData({
+				// 							focusFieldId: ele.fieldId
+				// 						})
+				// 					}
+				// 				}
+				// 			} else {
+				// 				for (let j in ele.setting.colList) {
+				// 					const col = ele.setting.colList[j]
+				// 					if (col?.useDict) {
+				// 						//鍒ゆ柇useDict鏄惁浣跨敤瀛楀吀
+				// 						await this.DictGetInfo(col.bind
+				// 							.dict,
+				// 							styledefHead.form
+				// 							.model, col);
+				// 					}
+				// 					if ($this.focusFieldId == "") {
+				// 						if (col.name == 'Input' || col
+				// 							.name ==
+				// 							'InputNumber') {
+				// 							$this.setData({
+				// 								focusFieldId: col
+				// 									.fieldId
+				// 							})
+				// 						}
+				// 					}
+				// 				}
+				// 			}
+				// 		}
+				// 		this.setData({
+				// 			head_styledef: styledefHead
+				// 		})
+				// 	} else {
+				// 		uni.showModal({
+				// 			title: this.translateSys("error") + "1",
+				// 			content: ret.err_msg,
+				// 			showCancel: false,
+				// 			confirmText: this.translateSys("cancel")
+				// 		});
+				// 	}
+				// }).catch(ex => {
+				// 	// console.log(ex);
+				// 	uni.showModal({
+				// 		title: this.translateSys("error") + "1.1",
+				// 		content: ex.errMsg,
+				// 		showCancel: false,
+				// 		confirmText: this.translateSys("cancel")
+				// 	});
+				// });
 
 			},
 			async Detail_UIstyleGetInfo(class_id, style_id) { //鑾峰彇鑷畾涔夎〃鍗曟牱寮�@@ -398,26 +466,29 @@
 					const detailstyledef = ret.result.style_def ? JSON.parse(
 						styledef) : {};
 					detailstyledef.SelBut_Checked = true;
-					for (let index in detailstyledef.form.items) {
-						const ele = detailstyledef.form.items[index]
+					if (detailstyledef?.form?.items) {
+						for (let index in detailstyledef.form.items) {
+							const ele = detailstyledef.form.items[index]
 
-						if (ele.name != "Layout") {
-							if (ele.useDict == true) { //鍒ゆ柇useDict鏄惁浣跨敤瀛楀吀
-								await this.DictGetInfo(ele.bind.dict,
-									detailstyledef.form
-									.model, ele);
-							}
-						} else {
-							for (let j in ele.setting.colList) {
-								const col = ele.setting.colList[j]
-								if (col?.useDict == true) {
-									await this.DictGetInfo(col
-										.bind.dict,
+							if (ele.name != "Layout") {
+								if (ele.useDict == true) { //鍒ゆ柇useDict鏄惁浣跨敤瀛楀吀
+									await this.DictGetInfo(ele.bind.dict,
 										detailstyledef.form
-										.model, col);
+										.model, ele);
+								}
+							} else {
+								for (let j in ele.setting.colList) {
+									const col = ele.setting.colList[j]
+									if (col?.useDict == true) {
+										await this.DictGetInfo(col
+											.bind.dict,
+											detailstyledef.form
+											.model, col);
+									}
 								}
 							}
 						}
+
 					}
 					console.log("Detail_UIstyleGetInfo", detailstyledef);
 					return detailstyledef
@@ -572,12 +643,29 @@
 						dataType: "json",
 						success: (_res) => {
 							// console.log(_res);
-							const ret = _res.data
+							var ret = _res.data
+							if (typeof ret == 'string') {
+								try {
+									try {
+										try {
+											ret = JSON.parse(ret.replace(/\\"/g, '"'));
+										} catch (ex) {
+											ret = JSON.parse(ret.replace(/\\/g, '\\\\'))
+										}
+									} catch (ex) {
+										ret = JSON.parse(ret.replace(/\\"/g, "'").replace(/[\r\n]/g,
+											'<br>').replace(/[\t]/g, '    '));
+									}
+								} catch (ex) {
+									console.log(ret)
+									return reject('灏唃etUIStyleInfo銆恓son string銆戣浆鎹负銆恓son object銆戝け璐�)
+								}
+							}
 							if (ret.err_code == 0) {
 								resolve(ret);
 							} else {
 								reject({
-									"errMsg": ret.err_msg
+									"errMsg": ret.err_msg || ret.errMsg
 								});
 							}
 						},
@@ -1278,9 +1366,10 @@
 							}
 						}).catch(ex => {
 							// console.log(ex);
+							let tip = typeof ex.errMsg == "string" ? ex.errMsg : ex
 							uni.showModal({
 								title: this.translateSys("error") + "4.1",
-								content: ex.errMsg,
+								content: tip,
 								showCancel: false,
 								confirmText: this.translateSys("cancel")
 							});
@@ -1398,40 +1487,43 @@
 				});
 				if (!pageData)
 					return
-				data.row.forEach(row => {
-					var styleStr = JSON.stringify(pageData.StyleDef);
+				var styleStr = JSON.stringify(pageData.StyleDef);
 
-					var detailStyle = JSON.parse(styleStr);
-					detailStyle.form.objId = row.id;
-					detailStyle.form.htmlobjId = row.id ? row.id.replace(/-/g, '')
-						.replace(
-							'{', '').replace('}',
-							'') : 'null';
-					detailStyle.form.attrs = row.attrs;
-					row.attrs.forEach(attr => {
-						detailStyle.form.items.forEach(ele => {
-							if (ele.name != 'Layout') {
-								if (ele.fieldId == attr.attr) ele
-									.value =
-									attr.value;
-							} else if (ele.name == 'Layout') {
-								ele.setting.colList.forEach(
-									col => {
-										if (col) {
-											if (col.fieldId ==
-												attr
-												.attr) col
-												.value = attr
-												.value;
-										}
-									});
-							}
+				var detailStyle = JSON.parse(styleStr);
+				if (detailStyle.form) {
+					data.row.forEach(row => {
+						detailStyle = JSON.parse(styleStr);
+						detailStyle.form.objId = row.id;
+						detailStyle.form.htmlobjId = row.id ? row.id.replace(/-/g, '')
+							.replace(
+								'{', '').replace('}',
+								'') : 'null';
+						detailStyle.form.attrs = row.attrs;
+						row.attrs.forEach(attr => {
+							detailStyle.form.items.forEach(ele => {
+								if (ele.name != 'Layout') {
+									if (ele.fieldId == attr.attr) ele
+										.value =
+										attr.value;
+								} else if (ele.name == 'Layout') {
+									ele.setting.colList.forEach(
+										col => {
+											if (col) {
+												if (col.fieldId ==
+													attr
+													.attr) col
+													.value = attr
+													.value;
+											}
+										});
+								}
+							});
 						});
+
+						pageData.DefList.push(detailStyle);
+
 					});
-
-					pageData.DefList.push(detailStyle);
-
-				});
+				}
 			},
 			//鍔犺浇宸茬爜鐩樺唴瀹� 			viewAceionContent(data) {
@@ -1441,96 +1533,97 @@
 				});
 				if (!pageData)
 					return
-				console.log("viewAceionContent", pageData)
 				pageData.ExtData = data.ext_data || {}
 
 				if (JSON.stringify(data.content) == '{}') {
 					return;
 				}
-				data.content.forEach(cont => {
-					var styleStr = JSON.stringify(pageData.StyleDef);
-					console.log("viewAceionContent2", pageData)
-					var detailStyle = JSON.parse(styleStr);
-					detailStyle.SelBut_Checked = data.checkbox ?? true;
-					detailStyle.form.objId = cont.id;
-					detailStyle.form.htmlobjId = cont.id ? cont.id.replace(/-/g,
-							'')
-						.replace('{', '').replace('}',
-							'') : 'null';
-					detailStyle.form.attrs = cont.attrs;
-					cont.attrs.forEach(attr => {
-						detailStyle.form.items.forEach(ele => {
-							if (ele.name != 'Layout') {
-								if (ele.fieldId == attr.attr) ele
-									.value =
-									attr.value;
-							} else if (ele.name == 'Layout') {
-								ele.setting.colList.forEach(
-									col => {
-										if (col) {
-											if (col.fieldId ==
-												attr
-												.attr) col
-												.value = attr
-												.value;
-										}
-									});
-							}
-						});
-					});
-					//濡傛灉 clear = false 鍒欎笉闇�娓呴櫎锛屾牴鎹甶d鍒ゆ柇鏄惁瀛樺湪锛屼笉瀛樺湪鎻掑叆鍒伴〉闈紝濡傛灉瀛樺湪鐢ㄦ柊鐨勫睘鎬ц鐩�-					if (data.clear == false) {
-						var isflag = true;
-						pageData.DefList.forEach((style, index) => {
-							if (style.form.objId == detailStyle.form
-								.objId) {
-								cont.attrs.forEach(attr => {
-									style.form.items.forEach(
-										ele => {
-											if (ele.name !=
-												'Layout') {
-												if (ele
-													.fieldId ==
-													attr.attr)
-													ele
-													.value =
-													attr.value;
-											} else if (ele
-												.name ==
-												'Layout') {
-												ele.setting
-													.colList
-													.forEach(
-														col => {
-															if (
-																col
-															) {
-																if (col
-																	.fieldId ==
-																	attr
-																	.attr
-																)
-																	col
-																	.value =
-																	attr
-																	.value;
-															}
-														});
+				var styleStr = JSON.stringify(pageData.StyleDef);
+				var detailStyle = JSON.parse(styleStr);
+				if (detailStyle.form) {
+					data.content.forEach(cont => {
+						detailStyle = JSON.parse(styleStr);
+						detailStyle.SelBut_Checked = data.checkbox ?? true;
+
+						detailStyle.form.objId = cont.id;
+						detailStyle.form.htmlobjId = cont.id ? cont.id.replace(/-/g,
+								'')
+							.replace('{', '').replace('}',
+								'') : 'null';
+						detailStyle.form.attrs = cont.attrs;
+						cont.attrs.forEach(attr => {
+							detailStyle.form.items.forEach(ele => {
+								if (ele.name != 'Layout') {
+									if (ele.fieldId == attr.attr) ele
+										.value =
+										attr.value;
+								} else if (ele.name == 'Layout') {
+									ele.setting.colList.forEach(
+										col => {
+											if (col) {
+												if (col.fieldId ==
+													attr
+													.attr) col
+													.value = attr
+													.value;
 											}
 										});
-								});
-								isflag = false;
-							}
+								}
+							});
 						});
-						if (isflag) pageData.DefList.push(detailStyle); //寰呭垎鎷�-					} else {
-						pageData.DefList.push(detailStyle); //寰呭垎鎷�-					}
-					$this.activelist.push({
-						active: false
+						//濡傛灉 clear = false 鍒欎笉闇�娓呴櫎锛屾牴鎹甶d鍒ゆ柇鏄惁瀛樺湪锛屼笉瀛樺湪鎻掑叆鍒伴〉闈紝濡傛灉瀛樺湪鐢ㄦ柊鐨勫睘鎬ц鐩�+						if (data.clear == false) {
+							var isflag = true;
+							pageData.DefList.forEach((style, index) => {
+								if (style.form.objId == detailStyle.form
+									.objId) {
+									cont.attrs.forEach(attr => {
+										style.form.items.forEach(
+											ele => {
+												if (ele.name !=
+													'Layout') {
+													if (ele
+														.fieldId ==
+														attr.attr)
+														ele
+														.value =
+														attr.value;
+												} else if (ele
+													.name ==
+													'Layout') {
+													ele.setting
+														.colList
+														.forEach(
+															col => {
+																if (
+																	col
+																) {
+																	if (col
+																		.fieldId ==
+																		attr
+																		.attr
+																	)
+																		col
+																		.value =
+																		attr
+																		.value;
+																}
+															});
+												}
+											});
+									});
+									isflag = false;
+								}
+							});
+							if (isflag) pageData.DefList.push(detailStyle); //寰呭垎鎷�+						} else {
+							pageData.DefList.push(detailStyle); //寰呭垎鎷�+						}
+						$this.activelist.push({
+							active: false
+						});
 					});
-
-				});
+				}
 
 			},
 			onClickItem(e) { //閫夋嫨椤电
@@ -2059,7 +2152,7 @@
 					pageParam.okLoading = false
 				}).catch(ex => {
 					pageParam.okLoading = false
-					var tip = typeof ex == "string" ? ex : ex.errMsg;
+					let tip = typeof ex.errMsg == "string" ? ex.errMsg : ex
 					uni.showModal({
 						title: this.translateSys("error") + "8.1",
 						content: this.translate(
@@ -2108,8 +2201,8 @@
 		.v-head-style {
 			width: 98%;
 
-			.uni-form-item {
-				margin-bottom: 15rpx;
+			.uni-forms-item {
+				margin-bottom: 11rpx;
 			}
 
 			.input-wrapper {
@@ -2121,6 +2214,7 @@
 				.uni-input {
 					flex: 1;
 					padding: 12rpx 8rpx;
+					color: #2d8cf0;
 					// height: 40rpx;
 					// line-height: 40rpx;
 				}
@@ -2186,10 +2280,6 @@
 			position: relative;
 			border: 0 solid #000;
 			box-sizing: border-box;
-		}
-
-		.uni-input {
-			/* border: none; */
 		}
 
 		.uni-icon {

--
Gitblit v1.9.1