diff --git a/web/src/views/backend/crud/design.vue b/web/src/views/backend/crud/design.vue index 4f9a1e54..8df2fe33 100644 --- a/web/src/views/backend/crud/design.vue +++ b/web/src/views/backend/crud/design.vue @@ -154,23 +154,23 @@ -
-
- {{ field.title }} +
+
+ {{ field.title }}
-
-
- {{ field.title }} +
+
+ {{ field.title }}
-
-
- {{ field.title }} +
+
+ {{ field.title }}
@@ -1381,9 +1381,62 @@ const autoRenameRepeatField = (fieldName: string) => { } } +const tableFieldAdd = (field?: FieldItem, position?: number) => { + const data = handleFieldAttr(cloneDeep(field!)) + + // 主键重复检测 + if (data.primaryKey) { + if (primaryKeyRepeatCheck(data)) { + // 设置为默认排序字段、快速搜索字段 + state.table.defaultSortField = data.name + state.table.quickSearchField.push(data.name) + } else { + return false; + } + } + + // 出现权重字段则以其排序 + if (data.designType == 'weigh') { + state.table.defaultSortField = data.name + } + + // name 重复时,自动重命名 + data.name = autoRenameRepeatField(data.name) + + // 插入字段 + state.fields.splice(position!, 0, data) + + logTableDesignChange({ + type: 'add-field', + index: position!, + newName: data.name, + oldName: '', + after: position === 0 ? 'FIRST FIELD' : state.fields[position! - 1].name, + }) + + // 远程下拉参数预填 + if (['remoteSelect', 'remoteSelects'].includes(data.designType)) { + showRemoteSelectPre(position!, true) + } + + // 表单表格字段预定义 + if (!data.formBuildExclude) { + state.table.formFields.push(data.name) + } + if (!data.tableBuildExclude) { + state.table.columnFields.push(data.name) + } + + nextTick(() => { + sortable.sort(range(state.fields.length).map((value) => value.toString())) + }) + + return true +} +let sortable: Sortable onMounted(() => { loadData() - const sortable = Sortable.create(designWindowRef.value, { + sortable = Sortable.create(designWindowRef.value, { group: 'design-field', animation: 200, filter: '.design-field-empty', @@ -1393,47 +1446,8 @@ onMounted(() => { if (field && field[evt.oldIndex!]) { const data = handleFieldAttr(cloneDeep(field[evt.oldIndex!])) - // 主键重复检测 - if (data.primaryKey) { - if (primaryKeyRepeatCheck(data)) { - // 设置为默认排序字段、快速搜索字段 - state.table.defaultSortField = data.name - state.table.quickSearchField.push(data.name) - } else { - return evt.item.remove() - } - } - - // 出现权重字段则以其排序 - if (data.designType == 'weigh') { - state.table.defaultSortField = data.name - } - - // name 重复时,自动重命名 - data.name = autoRenameRepeatField(data.name) - - // 插入字段 - state.fields.splice(evt.newIndex!, 0, data) - - logTableDesignChange({ - type: 'add-field', - index: evt.newIndex!, - newName: data.name, - oldName: '', - after: evt.newIndex === 0 ? 'FIRST FIELD' : state.fields[evt.newIndex! - 1].name, - }) - - // 远程下拉参数预填 - if (['remoteSelect', 'remoteSelects'].includes(data.designType)) { - showRemoteSelectPre(evt.newIndex!, true) - } - - // 表单表格字段预定义 - if (!data.formBuildExclude) { - state.table.formFields.push(data.name) - } - if (!data.tableBuildExclude) { - state.table.columnFields.push(data.name) + if ( !tableFieldAdd(data, evt.newIndex) ){ + evt.item.remove() } } evt.item.remove() @@ -1482,6 +1496,15 @@ onMounted(() => { }) }) +const clickAddSortable = (eve: Event, name: string) => { + const field = fieldItem[name as keyof typeof fieldItem] + + if (field && field[eve.target!.dataset!.index!]) { + const data = handleFieldAttr(cloneDeep(field[eve.target!.dataset!.index!])) + tableFieldAdd(data, state.fields.length) + } +} + /** * 修改表名 * @param val 新表名