From 39ab910fe59480a35ebca316cd66e3995e70d4ed Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 13 九月 2024 11:58:49 +0800
Subject: [PATCH] 支持刷新低代码,

---
 src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue |  166 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 97 insertions(+), 69 deletions(-)

diff --git a/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue b/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
index 801a80f..21e09d6 100644
--- a/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
+++ b/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
@@ -33,7 +33,7 @@
 				</el-table></Pane
 			>
 			<Pane :size="60">
-				<Splitpanes class="default-theme h100" :horizontal="true" v-if="currentSql">
+				<Splitpanes class="default-theme h100" :horizontal="true">
 					<Pane :size="35" class="flex-col flex">
 						<div class="flex-0 flex justify-between items-center mb-1 ml-1 h-[36px]">
 							<span class="font-bold">鍙傛暟</span>
@@ -50,6 +50,11 @@
 									<el-input v-model="scope.row.prompt" @input="argsInput"></el-input>
 								</template>
 							</el-table-column>
+							<el-table-column prop="check" label="缂虹渷鍊�" show-overflow-tooltip>
+								<template #default="scope">
+									<el-input v-model="scope.row.check" @input="argsInput"></el-input>
+								</template>
+							</el-table-column>
 							<el-table-column label="" width="55" fixed="right" show-overflow-tooltip>
 								<template #default="scope">
 									<el-tooltip effect="dark" content="鍒犻櫎" placement="top">
@@ -59,28 +64,37 @@
 							</el-table-column>
 						</el-table>
 					</Pane>
-					<Pane :size="65" class="flex-column">
-						<template v-if="currentSql">
-							<div class="flex-0 flex justify-between items-center my-1 ml-1 h-[36px]">
-								<span class="font-bold">SQL</span>
+					<Pane :size="65">
+						<div class="h-full">
+							<template v-if="currentDockConfig">
+								<div class="flex justify-between items-center my-1 ml-1 h-[36px]">
+									<el-select class="w-52 font-bold" v-model="currentDockConfig.type">
+										<el-option
+											v-for="item in Object.keys(amisDockTypeMap)"
+											:key="item"
+											:value="item"
+											:label="amisDockTypeMap[item]"
+										></el-option>
+									</el-select>
 
-								<el-select class="w-40" v-model="currentSql.database" @change="databaseSelectChange">
-									<el-option v-for="item in databaseList" :key="item.id" :value="item.id" :label="item.title"></el-option>
-								</el-select>
-							</div>
-							<codemirror
-								class="flex-auto overflow-auto"
-								v-model="currentSql.sql"
-								:style="{ height: '100%' }"
-								:autofocus="true"
-								:indent-with-tab="true"
-								:tab-size="2"
-								:extensions="sqlEditorExtensions"
-								@change="sqlCodeChange"
-								@focus="log('focus', $event)"
-								@blur="log('blur', $event)"
-							/>
-						</template>
+									<el-select class="w-40" v-model="currentDockConfig.database" @change="databaseSelectChange">
+										<el-option v-for="item in databaseList" :key="item.id" :value="item.id" :label="item.title"></el-option>
+									</el-select>
+								</div>
+								<codemirror
+									class="overflow-auto"
+									style="height: calc(100% - 36px)"
+									v-model="currentDockConfig.sql"
+									:autofocus="true"
+									:indent-with-tab="true"
+									:tab-size="2"
+									:extensions="sqlEditorExtensions"
+									@change="sqlCodeChange"
+									@focus="log('focus', $event)"
+									@blur="log('blur', $event)"
+								/>
+							</template>
+						</div>
 					</Pane>
 				</Splitpanes>
 			</Pane>
@@ -93,20 +107,21 @@
 import { sql } from '@codemirror/lang-sql';
 import { xml } from '@codemirror/lang-xml';
 import { vscodeDark } from '@uiw/codemirror-theme-vscode';
-import _, { debounce } from 'lodash';
-import { onMounted, ref } from 'vue';
-import { Codemirror } from 'vue-codemirror';
-import * as codeExample from './testData';
-import titleBox from '/@/components/titleBox.vue';
-import { Pane, Splitpanes } from 'splitpanes';
-import 'splitpanes/dist/splitpanes.css';
 import type { TableInstance } from 'element-plus';
 import { ElMessage } from 'element-plus';
+import _, { debounce } from 'lodash';
+import { Pane, Splitpanes } from 'splitpanes';
+import 'splitpanes/dist/splitpanes.css';
 import { v4 as uuid } from 'uuid';
+import { onMounted, ref } from 'vue';
+import { Codemirror } from 'vue-codemirror';
+import { SupervisorPublished } from '../types';
+import * as codeExample from './testData';
 import * as supervisorApi from '/@/api/supervisorAdmin';
 import { updateSqlApi } from '/@/api/supervisorAdmin';
+import titleBox from '/@/components/titleBox.vue';
 import { useCompRef } from '/@/utils/types';
-import { SupervisorPublished } from '../types';
+import { amisDockTypeMap } from './types';
 
 const props = defineProps(['supervisor']);
 const emit = defineEmits(['backLastPage', 'updatePublished']);
@@ -127,6 +142,10 @@
 let defaultSelectDatabase = null;
 const databaseSelectChange = (val) => {
 	defaultSelectDatabase = val;
+	if (currentDockConfig.value) {
+		currentDockConfig.value.database = val;
+	}
+	updateSqlAndRs(currentDockConfig.value.id, currentDockConfig.value);
 };
 const backLastPage = () => {
 	// setTimeout(() => {
@@ -137,13 +156,14 @@
 const currentRs = ref<AmisDockConfig>(null);
 const dockRowChange = (row) => {
 	currentRs.value = row;
-	currentSql.value = sqlList.value.find((item) => item.id === currentRs.value.recordId) ?? {
+	currentDockConfig.value = dockConfigList.value.find((item) => item.id === currentRs.value.recordId) ?? {
 		id: row.recordId,
+		type: AmisDockType.Sql,
 		sql: '',
 		database: defaultSelectDatabase ?? databaseList.value[0]?.id ?? null,
 	};
 };
-const currentSql = ref(null);
+const currentDockConfig = ref(null);
 /** @description 璺緞鍒嗛殧绗� */
 const PATH_SEPARATOR = '/';
 /** @description 1 閫�鍑烘墍鏈夊惊鐜� -1閫�鍑哄綋娆″惊鐜� 0鎴栧叾浠栧�肩户缁� */
@@ -203,7 +223,7 @@
 		if (key === 'api') {
 			// const url = value.url;
 			const urlPath = path + PATH_SEPARATOR + 'url';
-			const randomStr = 'query_' + uuid().slice(0, 12);
+			const randomStr = 'q_' + value.url + '_' + uuid().slice(0, 12);
 			const foundItem = apiDataList.find((item) => item.path === urlPath);
 			const asyncId = foundItem?.asyncId ?? randomStr;
 			const recordId = foundItem?.recordId ?? randomStr;
@@ -221,55 +241,60 @@
 };
 
 const checkValid = (showTip: boolean, tip?: string) => {
-	const foundWithNoDatabase = sqlList.value?.find((item) => !item.database);
+	if(!dockConfigList.value || dockConfigList.value.length===0) return true;
+	const foundWithNoDatabase = dockConfigList.value?.find((item) => !item.database);
 	if (foundWithNoDatabase && showTip) {
 		ElMessage.warning(tip ?? `銆�${foundWithNoDatabase.id}銆戞湭閫夋嫨鏁版嵁搴揱);
 	}
 	return !foundWithNoDatabase;
 };
 
-const updateSqlAndRs = (id?, sqlValue?: string) => {
+const updateSqlAndRs = (id?, sqlValue?: { database?: string; sql?: string; type?: AmisDockType }) => {
 	const apiConfig = configList.value.filter((item) => item.type === AmisDockType.Sql);
-	if (apiConfig.length === 0) return;
+
 	if (!checkValid(true)) {
 		return;
 	}
+
+	const recordIds = apiConfig?.map(item=>item.recordId)??[];
+	// 杩囨护鍑� apiConfig 涓湁鐨剅ecord;
+	dockConfigList.value = dockConfigList.value?.filter(item=>recordIds.includes(item.id))??[]
 	const asyncRsList = apiConfig.map((item) => ({
 		amis_path: item.path,
 		async_id: item.asyncId,
 		rec_id: item.recordId,
 	}));
 
-	if (id) {
-		const found = sqlList.value?.find((item) => item.id === id);
-		if (found) {
-			found.sql = sqlValue;
+	if (id && sqlValue) {
+		const foundIndex = dockConfigList.value?.findIndex((item) => item.id === id);
+		if (foundIndex > -1) {
+			dockConfigList.value[foundIndex] = {
+				...dockConfigList.value[foundIndex],
+				...sqlValue,
+			};
 		} else {
-			if (!sqlList.value || sqlList.value.length === 0) {
-				sqlList.value = [
-					{
-						id: id,
-						sql: sqlValue,
-					},
-				];
+			if (!sqlValue.database) {
+				ElMessage.warning('璇峰厛閫夋嫨鏁版嵁搴�');
+				return;
+			}
+			const newSqlValue = {
+				id: id,
+				database: sqlValue.database ?? null,
+				sql: sqlValue.sql ?? null,
+				type: sqlValue.type ?? AmisDockType.Sql,
+			};
+			if (!dockConfigList.value || dockConfigList.value.length === 0) {
+				dockConfigList.value = [newSqlValue];
 			} else {
-				sqlList.value.push({
-					id: id,
-					sql: sqlValue,
-				});
+				dockConfigList.value.push(newSqlValue);
 			}
 		}
 	}
 
-	const dockList = sqlList.value.map((item) => ({
-		type: AmisDockType.Sql,
-		...item,
-	}));
-
 	updateSqlApi(
 		{
 			id: props.supervisor.id,
-			def_rs_json: dockList.length === 0 ? null : JSON.stringify(dockList),
+			def_rs_json: dockConfigList.value.length === 0 ? null : JSON.stringify(dockConfigList.value),
 			async_rs_json: asyncRsList.length === 0 ? null : JSON.stringify(asyncRsList),
 			args: args.value.length === 0 ? null : JSON.stringify(args.value),
 		},
@@ -283,20 +308,21 @@
 
 const sqlCodeChange = debounce((val) => {
 	if (!currentRs.value.recordId) return;
-	if (currentSql.value) {
-		if (!currentSql.value.database) {
+	if (currentDockConfig.value) {
+		if (!currentDockConfig.value.database) {
 			ElMessage.warning('璇峰厛閫夋嫨鏁版嵁搴�');
 			return;
 		}
 	}
-	updateSqlAndRs(currentRs.value.recordId, val);
+	updateSqlAndRs(currentDockConfig.value.id, currentDockConfig.value);
 }, 1000);
-const sqlList = ref([]);
+const dockConfigList = ref([]);
 const rsTableRef = ref<TableInstance>(null);
 let xmlJson = null;
 
 // 妫�鏌ユ槸鍚﹂渶瑕佹洿鏂� rs
 const checkRsUpdate = (originData: AmisDockConfig[], currentData: AmisDockConfig[]) => {
+
 	// 閮戒负绌猴紝涓嶉渶瑕佹洿鏂�
 	if ((!originData || originData.length === 0) && (!currentData || currentData.length === 0)) {
 		return false;
@@ -337,6 +363,7 @@
 	const initData = {
 		name: '',
 		prompt: '',
+		check: '',
 	};
 	if (!args.value || args.value.length === 0) {
 		args.value = [initData];
@@ -359,10 +386,7 @@
 		id: props.supervisor.id,
 	});
 
-	if (!xmlJson?.amis_json) {
-		ElMessage.warning('鏆傛棤SQL閰嶇疆');
-		return;
-	}
+	
 	const originConfig =
 		xmlJson.async_rs?.map(
 			(item) =>
@@ -373,18 +397,22 @@
 					path: item.amis_path,
 				} as AmisDockConfig)
 		) ?? [];
-	sqlList.value = xmlJson.sql ?? null;
-	// args.value = xmlJson
+	dockConfigList.value = xmlJson.def_rs_json ?? null;
+	args.value = xmlJson.args ?? [];
 
 	configList.value = parseJSONData(xmlJson.amis_json, originConfig);
 	const res = await supervisorApi.getAmisDatabaseList();
 	databaseList.value = res.values ?? [];
 	if (configList.value.length > 0) {
 		rsTableRef.value.setCurrentRow(configList.value[0]);
-		// dockRowChange(configList.value[0]);
 	}
 
-	if (checkRsUpdate(originConfig, configList.value)) {
+	if(!configList || configList.value.length===0 ){
+		ElMessage.warning('鏆傛棤瀵规帴閰嶇疆');
+	}
+
+	const isRsUpdate = checkRsUpdate(originConfig, configList.value)
+	if (isRsUpdate) {
 		// 鑷姩鏇存柊Rs
 		updateSqlAndRs();
 	}

--
Gitblit v1.9.3