From 924f3850b1295e5f699bea843fcee83ae860feb6 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 20 九月 2024 17:17:38 +0800
Subject: [PATCH] \\s*

---
 src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue |  165 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 138 insertions(+), 27 deletions(-)

diff --git a/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue b/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
index 08b1351..236e7b0 100644
--- a/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
+++ b/src/views/project/yw/lowCode/sqlAmis/edit/SqlAmisEdit.vue
@@ -81,24 +81,74 @@
 										<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)"
-								/>
+								<el-tabs v-model="sqlActiveTab" class="overflow-auto" style="height: calc(100% - 36px)">
+									<el-tab-pane :label="sqlTabMap[SqlTabType.LinkSql]" :name="SqlTabType.LinkSql" class="h-full">
+										<codemirror
+											class="overflow-auto"
+											style="height: 100%"
+											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)"
+										/>
+									</el-tab-pane>
+									<el-tab-pane :label="sqlTabMap[SqlTabType.Others]" :name="SqlTabType.Others">
+										<div class="flex-column">
+											<div class="flex-0 flex mb-3.5">
+												<el-button class="ml-auto" type="danger" @click="deleteUnLinkSql">鍒犻櫎鎵�鏈夋湭浣跨敤</el-button>
+											</div>
+											<el-table
+												ref="draggableTableRef"
+												class="flex-auto"
+												border
+												row-class-name="cursor-pointer"
+												:data="otherSqlList"
+												highlight-current-row
+											>
+												
+												<el-table-column prop="id" label="id" width="220" fixed="left" show-overflow-tooltip> </el-table-column>
+												<el-table-column label="鏁版嵁搴�" prop="database" show-overflow-tooltip>
+													
+														<template #default="scope">
+															{{ getMapDatabase(scope.row.database)?.title }}
+														</template>
+													
+												</el-table-column>
+
+												<el-table-column label="鎿嶄綔" width="120" fixed="right" show-overflow-tooltip>
+													<template #default="scope">
+														<div class="space-x-3 items-center flex">
+															<el-tooltip effect="dark" content="鏌ョ湅SQL" placement="top">
+																<i
+																	class="ywifont ywicon-didaima !text-[21px] text-blue-400 cursor-pointer"
+																	@click="openShowSqlDlg(scope.row)"
+																></i>
+															</el-tooltip>
+															<el-tooltip effect="dark" content="鍒犻櫎" placement="top">
+																<i
+																	class="ywifont ywicon-shanchu !text-[17px] text-red-400 cursor-pointer"
+																	@click="deleteCurrentSql(scope.row)"
+																></i>
+															</el-tooltip>
+														</div>
+													</template>
+												</el-table-column>
+											</el-table>
+										</div>
+									</el-tab-pane>
+								</el-tabs>
 							</template>
 						</div>
 					</Pane>
 				</Splitpanes>
 			</Pane>
 		</Splitpanes>
+
+		<SqlCodeViewDlg v-model="optDlgIsShow" :item="optDlgMapRow"></SqlCodeViewDlg>
 	</div>
 </template>
 
@@ -108,7 +158,7 @@
 import { xml } from '@codemirror/lang-xml';
 import { vscodeDark } from '@uiw/codemirror-theme-vscode';
 import type { TableInstance } from 'element-plus';
-import { ElMessage } from 'element-plus';
+import { ElMessage, ElMessageBox } from 'element-plus';
 import _, { debounce } from 'lodash';
 import { Pane, Splitpanes } from 'splitpanes';
 import 'splitpanes/dist/splitpanes.css';
@@ -122,6 +172,8 @@
 import { updateSqlApi } from '/@/api/supervisorAdmin';
 import titleBox from '/@/components/titleBox.vue';
 import { useCompRef } from '/@/utils/types';
+import { computed } from 'vue';
+import SqlCodeViewDlg from './optDlg/SqlCodeViewDlg.vue';
 
 const props = defineProps(['supervisor']);
 const emit = defineEmits(['backLastPage', 'updatePublished']);
@@ -145,6 +197,7 @@
 	if (currentDockConfig.value) {
 		currentDockConfig.value.database = val;
 	}
+	sqlActiveTab.value = SqlTabType.LinkSql;
 	updateSqlAndRs(currentDockConfig.value.id, currentDockConfig.value);
 };
 const backLastPage = () => {
@@ -154,37 +207,49 @@
 	emit('backLastPage');
 };
 const currentRs = ref<AmisDockConfig>(null);
-
+const otherSqlList = computed(() => {
+	const sqlConfig = dockConfigList.value.filter((item) => {
+		return item.type === AmisDockType.Sql;
+	});
+	if (!currentDockConfig.value) {
+		return sqlConfig;
+	}
+	// 鎺掗櫎褰撳墠
+	return sqlConfig.filter((item) => {
+		return currentDockConfig.value.id !== item.id;
+	});
+});
 const getWithTemplateDataCommentSql = (sql: string, data: any) => {
+	const reg = new RegExp(`^\\s*(\\s*--\\s*".*"\\s*:.*\\n)+\\s*`);
+	const isMatchReg = reg.test(sql);
 	if (!Array.isArray(data)) {
-		return sql;
+		return isMatchReg ? sql.replace(reg, '') : sql;
 	}
 	const first = data[0];
 	if (!_.isObjectLike(first)) {
-		return sql;
+		return isMatchReg ? sql.replace(reg, '') : sql;
 	}
 	const firstKeyList = Object.keys(first);
 	// 鍊间负瀵硅薄
 	if (_.isObjectLike(first[firstKeyList[0]])) {
-		return sql;
+		return isMatchReg ? sql.replace(reg, '') : sql;
 	}
-
-	
 
 	let comment = '';
 	firstKeyList.map((key, index, array) => {
 		const value = JSON.stringify(first[key]);
 		comment += `-- "${key}": ${value}\n`;
+		// 鏈�鍚庝竴涓啀鎹㈣
+		comment += index === array.length - 1 ? '\n' : '';
 	});
 
-	const reg = new RegExp(`^\\s*(\\s*--\\s*".*"\\s*:.*\\n)+`)
 	// 宸茬粡瀛樺湪锛屼竴瀹氳鏇挎崲鎴愭渶鏂扮殑
-	if (reg.test(sql)) {
-		const replaceStr =  sql.replace(reg,comment);
+	if (isMatchReg) {
+		const replaceStr = sql.replace(reg, comment);
 		return replaceStr;
 	}
 
-	const result = comment+sql;
+	const result = comment + sql;
 	return result;
 };
 const dockRowChange = (row) => {
@@ -197,7 +262,7 @@
 	};
 	const templateData = extraInfoMap.value.get(row.recordId).templateData;
 
-	currentDockConfig.value.sql =  getWithTemplateDataCommentSql(currentDockConfig.value.sql,templateData)
+	currentDockConfig.value.sql = getWithTemplateDataCommentSql(currentDockConfig.value.sql, templateData);
 };
 const currentDockConfig = ref(null);
 /** @description 璺緞鍒嗛殧绗� */
@@ -320,9 +385,6 @@
 		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,
@@ -443,6 +505,11 @@
 };
 
 const databaseList = ref([]);
+
+const getMapDatabase = (id:string)=>{
+	const foundItem = databaseList.value.find(item=>item.id===id);
+	return foundItem;
+}
 //#endregion
 onMounted(async () => {
 	xmlJson = await supervisorApi.getLowCodeJson({
@@ -479,7 +546,51 @@
 		updateSqlAndRs();
 	}
 });
+//#region ====================== sql 淇濆瓨鍘嗗彶 ======================
+const enum SqlTabType {
+	LinkSql = 'link-sql',
+	Others = 'sql-list',
+}
+const sqlTabMap = {
+	[SqlTabType.LinkSql]: '鍏宠仈SQL',
+	[SqlTabType.Others]: '鍏跺畠',
+};
+const sqlActiveTab = ref<SqlTabType>(SqlTabType.LinkSql);
 
+// 鍒犻櫎褰撳墠
+const deleteCurrentSql = (row) => {
+	ElMessageBox.confirm('纭畾瑕佸垹闄ゅ綋鍓峉QL鍚楋紵', '鎻愮ず', {
+		confirmButtonText: '纭畾',
+		cancelButtonText: '鍙栨秷',
+		type: 'warning',
+	}).then(async () => {
+		dockConfigList.value = dockConfigList.value.filter((item) => item.id !== row.id);
+		updateSqlAndRs();
+	});
+};
+// 鍒犻櫎鏈繛鎺�
+const deleteUnLinkSql = () => {
+	ElMessageBox.confirm('纭畾瑕佸垹闄ゆ墍鏈夋湭浣跨敤鐨凷QL鍚楋紵', '鎻愮ず', {
+		confirmButtonText: '纭畾',
+		cancelButtonText: '鍙栨秷',
+		type: 'warning',
+	}).then(async () => {
+		const apiConfig = configList.value.filter((item) => item.type === AmisDockType.Sql);
+		const recordIds = apiConfig?.map((item) => item.recordId) ?? [];
+		// 杩囨护鍑� apiConfig 涓湁鐨剅ecord;
+		dockConfigList.value = dockConfigList.value?.filter((item) => recordIds.includes(item.id)) ?? [];
+		updateSqlAndRs();
+	});
+};
+
+const optDlgIsShow = ref(false);
+const optDlgMapRow = ref(null);
+const openShowSqlDlg = (row?: any) => {
+	optDlgMapRow.value = row;
+	optDlgIsShow.value = true;
+};
+
+//#endregion
 // watch(() => sqlCodemirrorRef.value, (codeMirrorRef) => {
 // 	codeMirrorRef.
 // })

--
Gitblit v1.9.3