From e8be9acee7c787349745677eb9e2a7feb2d34d67 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 09 九月 2024 17:46:26 +0800
Subject: [PATCH] sql 编辑修改

---
 src/api/supervisorAdmin/index.ts                          |   12 +++
 scripts/helper.js                                         |    4 
 src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue          |    4 
 src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue |  171 ++++++++++++++++++++++++++++++++----------
 4 files changed, 147 insertions(+), 44 deletions(-)

diff --git a/scripts/helper.js b/scripts/helper.js
index 62fda81..281ab87 100644
--- a/scripts/helper.js
+++ b/scripts/helper.js
@@ -18,8 +18,8 @@
 const commonDir = path.join(customerListDir, 'common');
 
  const item = customerList[0];
-const customerSplit = item.split(':');
-const deployEnv = customerSplit[1];
+const customerSplit = item?.split(':');
+const deployEnv = customerSplit?.[1];
 // 鏄惁涓虹敓浜х幆澧�
 const isPro = deployEnv==='pro';
 // const deployEnv = process.argv[3];
diff --git a/src/api/supervisorAdmin/index.ts b/src/api/supervisorAdmin/index.ts
index b8673be..b1f482f 100644
--- a/src/api/supervisorAdmin/index.ts
+++ b/src/api/supervisorAdmin/index.ts
@@ -101,4 +101,16 @@
 		data: params,
 		...extraData
 	});
+};
+
+
+/**
+ * @summary description
+ */
+export const getAmisDatabaseList = async (extraData: ExtraConfig = {}, req: any = request) => {
+	return req({
+		url: '/admin/supervisor/get_amis_database_list',
+		method: 'POST',
+		...extraData
+	});
 };
\ No newline at end of file
diff --git a/src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue b/src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue
index af9e4ad..a7f0e6c 100644
--- a/src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue
+++ b/src/views/project/yw/lowCode/sqlAmis/SqlAmis.vue
@@ -279,7 +279,7 @@
 		const foundIndex = listData.value.findIndex((item) => row.id === item.id);
 		listData.value.splice(foundIndex, 1);
 		if (listData.value.length > 0) {
-			currentNode.value = listData.value[foundIndex];
+			handleClickNode(listData.value[foundIndex]);
 		}
 	});
 };
@@ -359,7 +359,7 @@
 		};
 		Reflect.deleteProperty(newNode, 'parent_id');
 		listData.value.push(newNode);
-		currentNode.value = newNode;
+		handleClickNode(newNode);
 		moduleDialogIsShow.value = false;
 		ElMessage.success('娣诲姞椤甸潰鍒嗙粍鎴愬姛');
 	}
diff --git a/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue b/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
index c1aa22e..801a80f 100644
--- a/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
+++ b/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
@@ -13,50 +13,78 @@
 			</template>
 		</titleBox>
 
-		<div class="grid grid-cols-2 gap-2 h-full flex-auto">
-			<div class="h-full overflow-auto">
+		<Splitpanes class="default-theme flex-auto" :horizontal="false">
+			<Pane :size="40" class="flex-column">
+				<div class="flex-0 flex justify-between items-center mb-1 ml-1 h-[36px]">
+					<span class="font-bold">閰嶇疆椤�</span>
+				</div>
 				<el-table
 					ref="rsTableRef"
 					:data="configList"
 					row-class-name="cursor-pointer"
-					class="h-full"
+					class="flex-auto"
 					highlight-current-row
 					@current-change="dockRowChange"
 				>
 					<el-table-column prop="asyncId" label="鏌ヨ id" />
-
 					<el-table-column prop="path" label="閰嶇疆璺緞" />
-
 					<el-table-column prop="recordId" label="SQL id" />
 					<!-- <el-table-column prop="url" label="璇锋眰鍦板潃" /> -->
-				</el-table>
-				<!-- <codemirror
-					v-model="dockCode"
-					:style="{ height: '100%' }"
-					:autofocus="true"
-					:indent-with-tab="true"
-					:tab-size="2"
-					:extensions="dockEditorExtensions"
-					@change="log('change', $event)"
-					@focus="log('focus', $event)"
-					@blur="log('blur', $event)"
-				/> -->
-			</div>
-			<div class="h-full overflow-auto" v-if="currentSql">
-				<codemirror
-					class="h-full 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)"
-				/>
-			</div>
-		</div>
+				</el-table></Pane
+			>
+			<Pane :size="60">
+				<Splitpanes class="default-theme h100" :horizontal="true" v-if="currentSql">
+					<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>
+							<el-button type="primary" @click="addArg">娣诲姞</el-button>
+						</div>
+						<el-table class="flex-auto" :data="args" border>
+							<el-table-column prop="name" label="鍚嶇О" show-overflow-tooltip>
+								<template #default="scope">
+									<el-input v-model="scope.row.name" @input="argsInput"></el-input>
+								</template>
+							</el-table-column>
+							<el-table-column prop="prompt" label="鎻愮ず璇�" show-overflow-tooltip>
+								<template #default="scope">
+									<el-input v-model="scope.row.prompt" @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">
+										<i class="ywifont ywicon-shanchu !text-[17px] text-red-400 cursor-pointer" @click="deleteArg(scope.$index)"></i>
+									</el-tooltip>
+								</template>
+							</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>
+
+								<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>
+					</Pane>
+				</Splitpanes>
+			</Pane>
+		</Splitpanes>
 	</div>
 </template>
 
@@ -70,7 +98,8 @@
 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 { v4 as uuid } from 'uuid';
@@ -94,6 +123,11 @@
 	configList.value = [];
 	sqlCode.value = '';
 };
+
+let defaultSelectDatabase = null;
+const databaseSelectChange = (val) => {
+	defaultSelectDatabase = val;
+};
 const backLastPage = () => {
 	// setTimeout(() => {
 	// 	resetStatus();
@@ -106,6 +140,7 @@
 	currentSql.value = sqlList.value.find((item) => item.id === currentRs.value.recordId) ?? {
 		id: row.recordId,
 		sql: '',
+		database: defaultSelectDatabase ?? databaseList.value[0]?.id ?? null,
 	};
 };
 const currentSql = ref(null);
@@ -148,7 +183,7 @@
 };
 
 const enum AmisDockType {
-	Api,
+	Sql = 'SQL',
 }
 type AmisDockApi = string;
 type AmisDockValue = AmisDockApi;
@@ -176,7 +211,7 @@
 			jsonConfigList.push({
 				asyncId: asyncId,
 				recordId: recordId,
-				type: AmisDockType.Api,
+				type: AmisDockType.Sql,
 				path: urlPath,
 			});
 		}
@@ -185,9 +220,20 @@
 	return jsonConfigList;
 };
 
+const checkValid = (showTip: boolean, tip?: string) => {
+	const foundWithNoDatabase = sqlList.value?.find((item) => !item.database);
+	if (foundWithNoDatabase && showTip) {
+		ElMessage.warning(tip ?? `銆�${foundWithNoDatabase.id}銆戞湭閫夋嫨鏁版嵁搴揱);
+	}
+	return !foundWithNoDatabase;
+};
+
 const updateSqlAndRs = (id?, sqlValue?: string) => {
-	const apiConfig = configList.value.filter((item) => item.type === AmisDockType.Api);
+	const apiConfig = configList.value.filter((item) => item.type === AmisDockType.Sql);
 	if (apiConfig.length === 0) return;
+	if (!checkValid(true)) {
+		return;
+	}
 	const asyncRsList = apiConfig.map((item) => ({
 		amis_path: item.path,
 		async_id: item.asyncId,
@@ -215,11 +261,17 @@
 		}
 	}
 
+	const dockList = sqlList.value.map((item) => ({
+		type: AmisDockType.Sql,
+		...item,
+	}));
+
 	updateSqlApi(
 		{
 			id: props.supervisor.id,
-			sql_json: sqlList.value.length === 0 ? null : JSON.stringify(sqlList.value),
+			def_rs_json: dockList.length === 0 ? null : JSON.stringify(dockList),
 			async_rs_json: asyncRsList.length === 0 ? null : JSON.stringify(asyncRsList),
+			args: args.value.length === 0 ? null : JSON.stringify(args.value),
 		},
 		{
 			loading: false,
@@ -231,6 +283,12 @@
 
 const sqlCodeChange = debounce((val) => {
 	if (!currentRs.value.recordId) return;
+	if (currentSql.value) {
+		if (!currentSql.value.database) {
+			ElMessage.warning('璇峰厛閫夋嫨鏁版嵁搴�');
+			return;
+		}
+	}
 	updateSqlAndRs(currentRs.value.recordId, val);
 }, 1000);
 const sqlList = ref([]);
@@ -266,10 +324,41 @@
 		return Object.keys(currentItem).some((item) => originItem[item] !== currentItem[item]);
 	});
 };
+
+//#region ====================== 鍙紪杈戣〃鏍� ======================
+const args = ref([]);
+const debounceUpdateInput = debounce(() => {
+	updateSqlAndRs();
+}, 400);
+const argsInput = (val) => {
+	debounceUpdateInput();
+};
+const addArg = () => {
+	const initData = {
+		name: '',
+		prompt: '',
+	};
+	if (!args.value || args.value.length === 0) {
+		args.value = [initData];
+	} else {
+		args.value.push(initData);
+	}
+
+	updateSqlAndRs();
+};
+
+const deleteArg = (index) => {
+	args.value.splice(index, 1);
+	updateSqlAndRs();
+};
+
+const databaseList = ref([]);
+//#endregion
 onMounted(async () => {
 	xmlJson = await supervisorApi.getLowCodeJson({
 		id: props.supervisor.id,
 	});
+
 	if (!xmlJson?.amis_json) {
 		ElMessage.warning('鏆傛棤SQL閰嶇疆');
 		return;
@@ -278,16 +367,18 @@
 		xmlJson.async_rs?.map(
 			(item) =>
 				({
-					type: AmisDockType.Api,
+					type: AmisDockType.Sql,
 					asyncId: item.async_id,
 					recordId: item.rec_id,
 					path: item.amis_path,
 				} as AmisDockConfig)
 		) ?? [];
 	sqlList.value = xmlJson.sql ?? null;
+	// args.value = xmlJson
 
 	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]);

--
Gitblit v1.9.3