From a40ec21a0585abe897fe9c02e4f7fa4c24e495d4 Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Fri, 17 Nov 2023 13:31:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=A1=A8=E4=BD=BF=E7=94=A8=E8=99=9A=E6=8B=9F=E8=A1=A8=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=EF=BC=8C=E6=8F=90=E5=8D=87=E6=95=B0=E6=8D=AE=E9=87=8F?= =?UTF-8?q?=E8=BE=83=E5=A4=A7=E6=97=B6=E7=9A=84=E6=B8=B2=E6=9F=93=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mayfly_go_web/src/views/ops/db/SqlExec.vue | 4 +- .../db/component/sqleditor/DbSqlEditor.vue | 27 +- .../ops/db/component/table/DbTableData.vue | 730 +++++++++++++----- .../ops/db/component/table/DbTableDataOp.vue | 59 +- mayfly_go_web/src/views/ops/db/db.ts | 38 +- 5 files changed, 552 insertions(+), 306 deletions(-) diff --git a/mayfly_go_web/src/views/ops/db/SqlExec.vue b/mayfly_go_web/src/views/ops/db/SqlExec.vue index be63e1bd..3cbd6243 100644 --- a/mayfly_go_web/src/views/ops/db/SqlExec.vue +++ b/mayfly_go_web/src/views/ops/db/SqlExec.vue @@ -366,7 +366,7 @@ const state = reactive({ activeName: '', reloadStatus: false, tabs, - dataTabsTableHeight: '600', + dataTabsTableHeight: 600, editorHeight: '600', tablesOpHeight: '600', }); @@ -388,7 +388,7 @@ onBeforeUnmount(() => { */ const setHeight = () => { state.editorHeight = window.innerHeight - 500 + 'px'; - state.dataTabsTableHeight = window.innerHeight - 255 + 'px'; + state.dataTabsTableHeight = window.innerHeight - 255; state.tablesOpHeight = window.innerHeight - 220 + 'px'; }; diff --git a/mayfly_go_web/src/views/ops/db/component/sqleditor/DbSqlEditor.vue b/mayfly_go_web/src/views/ops/db/component/sqleditor/DbSqlEditor.vue index 14879066..627cc888 100644 --- a/mayfly_go_web/src/views/ops/db/component/sqleditor/DbSqlEditor.vue +++ b/mayfly_go_web/src/views/ops/db/component/sqleditor/DbSqlEditor.vue @@ -50,10 +50,7 @@
- - - 导出 @@ -77,6 +74,7 @@ empty-text="tips: select *开头的单表查询或点击表名默认查询的数据,可双击数据在线修改" @selection-change="onDataSelectionChange" @change-updated-field="changeUpdatedField" + @data-delete="onDeleteData" >
@@ -149,7 +147,7 @@ const state = reactive({ hasUpdatedFileds: false, }); -const { tableDataHeight, execRes, table, loading, hasUpdatedFileds } = toRefs(state); +const { tableDataHeight, execRes, loading, hasUpdatedFileds } = toRefs(state); watch( () => props.editorHeight, @@ -529,27 +527,20 @@ const onDataSelectionChange = (datas: []) => { state.selectionDatas = datas; }; -const changeUpdatedField = (updatedFields: []) => { +const changeUpdatedField = (updatedFields: any) => { // 如果存在要更新字段,则显示提交和取消按钮 - state.hasUpdatedFileds = updatedFields && updatedFields.length > 0; + state.hasUpdatedFileds = updatedFields && updatedFields.size > 0; }; /** - * 执行删除数据事件 + * 数据删除事件 */ -const onDeleteData = async () => { - const deleteDatas = state.selectionDatas; - isTrue(deleteDatas && deleteDatas.length > 0, '请先选择要删除的数据'); +const onDeleteData = async (deleteDatas: any) => { const db = props.dbName; const dbInst = getNowDbInst(); const primaryKey = await dbInst.loadTableColumn(db, state.table); const primaryKeyColumnName = primaryKey.columnName; - dbInst.promptExeSql(db, dbInst.genDeleteByPrimaryKeysSql(db, state.table, deleteDatas), null, () => { - state.execRes.data = state.execRes.data.filter( - (d: any) => !(deleteDatas.findIndex((x: any) => x[primaryKeyColumnName] == d[primaryKeyColumnName]) != -1) - ); - state.selectionDatas = []; - }); + state.execRes.data = state.execRes.data.filter((d: any) => !(deleteDatas.findIndex((x: any) => x[primaryKeyColumnName] == d[primaryKeyColumnName]) != -1)); }; const submitUpdateFields = () => { @@ -572,10 +563,6 @@ const cancelUpdateFields = () => { text-decoration: none; } -.update_field_active { - background-color: var(--el-color-success); -} - .editor-move-resize { cursor: n-resize; height: 3px; diff --git a/mayfly_go_web/src/views/ops/db/component/table/DbTableData.vue b/mayfly_go_web/src/views/ops/db/component/table/DbTableData.vue index ec46f34d..3a1d3114 100644 --- a/mayfly_go_web/src/views/ops/db/component/table/DbTableData.vue +++ b/mayfly_go_web/src/views/ops/db/component/table/DbTableData.vue @@ -1,51 +1,122 @@ @@ -221,8 +210,8 @@ const props = defineProps({ required: true, }, tableHeight: { - type: [String], - default: '600', + type: [Number], + default: 600, }, }); @@ -258,11 +247,7 @@ const state = reactive({ placeholder: '', visible: false, }, - genSqlDialog: { - visible: false, - sql: '', - }, - tableHeight: '600', + tableHeight: 600, hasUpdatedFileds: false, }); @@ -446,11 +431,8 @@ const onSelectByCondition = async () => { * 表排序字段变更 */ const onTableSortChange = async (sort: any) => { - if (!sort.prop) { - return; - } - const sortType = sort.order == 'descending' ? 'DESC' : 'ASC'; - state.orderBy = `ORDER BY ${sort.prop} ${sortType}`; + const sortType = sort.order == 'desc' ? 'DESC' : 'ASC'; + state.orderBy = `ORDER BY ${sort.columnName} ${sortType}`; await onRefresh(); }; @@ -458,28 +440,9 @@ const onDataSelectionChange = (datas: []) => { state.selectionDatas = datas; }; -const changeUpdatedField = (updatedFields: []) => { +const changeUpdatedField = (updatedFields: any) => { // 如果存在要更新字段,则显示提交和取消按钮 - state.hasUpdatedFileds = updatedFields && updatedFields.length > 0; -}; - -/** - * 执行删除数据事件 - */ -const onDeleteData = async () => { - const deleteDatas = state.selectionDatas; - isTrue(deleteDatas && deleteDatas.length > 0, '请先选择要删除的数据'); - const db = props.dbName; - const dbInst = getNowDbInst(); - dbInst.promptExeSql(db, dbInst.genDeleteByPrimaryKeysSql(db, props.tableName, deleteDatas), null, () => { - onRefresh(); - }); -}; - -const onGenerateInsertSql = async () => { - isTrue(state.selectionDatas && state.selectionDatas.length > 0, '请先选择数据'); - state.genSqlDialog.sql = getNowDbInst().genInsertSql(props.dbName, props.tableName, state.selectionDatas); - state.genSqlDialog.visible = true; + state.hasUpdatedFileds = updatedFields && updatedFields.size > 0; }; const submitUpdateFields = () => { @@ -530,8 +493,4 @@ const addRow = async () => { }; - + diff --git a/mayfly_go_web/src/views/ops/db/db.ts b/mayfly_go_web/src/views/ops/db/db.ts index 24c39f88..8dbf66bd 100644 --- a/mayfly_go_web/src/views/ops/db/db.ts +++ b/mayfly_go_web/src/views/ops/db/db.ts @@ -232,11 +232,12 @@ export class DbInst { * @param table 表名 * @param datas 要生成的数据 */ - genInsertSql(dbName: string, table: string, datas: any[]): string { + async genInsertSql(dbName: string, table: string, datas: any[]) { if (!datas) { return ''; } - const columns = this.getDb(dbName).getColumns(table); + + const columns = await this.loadColumns(dbName, table); const sqls = []; for (let data of datas) { let colNames = []; @@ -256,8 +257,8 @@ export class DbInst { * @param table 表名 * @param datas 要删除的记录 */ - genDeleteByPrimaryKeysSql(db: string, table: string, datas: any[]) { - const primaryKey = this.getDb(db).getColumn(table); + async genDeleteByPrimaryKeysSql(db: string, table: string, datas: any[]) { + const primaryKey = await this.loadTableColumn(db, table); const primaryKeyColumnName = primaryKey.columnName; const ids = datas.map((d: any) => `${DbInst.wrapColumnValue(primaryKey.columnType, d[primaryKeyColumnName])}`).join(','); return `DELETE FROM ${this.wrapName(table)} WHERE ${this.wrapName(primaryKeyColumnName)} IN (${ids})`; @@ -389,7 +390,7 @@ export class DbInst { } // 获取列名称的长度 加上排序图标长度 - const columnWidth: number = getTextWidth(prop) + 40; + const columnWidth: number = getTextWidth(prop) + 23; // prop为该列的字段名(传字符串);tableData为该表格的数据源(传变量); if (!tableData || !tableData.length || tableData.length === 0 || tableData === undefined) { return columnWidth; @@ -531,33 +532,6 @@ export class TabInfo { } } -/** 修改表字段所需数据 */ -export type UpdateFieldsMeta = { - // 主键值 - primaryKey: string; - // 主键名 - primaryKeyName: string; - // 主键类型 - primaryKeyType: string; - // 新值 - fields: FieldsMeta[]; -}; - -export type FieldsMeta = { - // 字段所在div - div: HTMLElement; - // 字段名 - fieldName: string; - // 字段所在的表格行数据 - row: any; - // 字段类型 - fieldType: string; - // 原值 - oldValue: string; - // 新值 - newValue: string; -}; - /** * 注册数据库表、字段等信息提示 *