| | |
| | | <template> |
| | | <div class="h-full flex flex-col"> |
| | | <div class="grid grid-cols-2 gap-2 h-2/3 flex-0"> |
| | | <div class="h-full overflow-auto"> |
| | | <el-table |
| | | :data="tableData" |
| | | row-class-name="cursor-pointer" |
| | | class="h-full" |
| | | highlight-current-row |
| | | @current-change="dockRowChange" |
| | | > |
| | | <el-table-column prop="date" label="Date" width="180" /> |
| | | <el-table-column prop="name" label="Name" width="180" /> |
| | | <el-table-column prop="address" label="Address" /> |
| | | </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"> |
| | | <codemirror |
| | | class="h-full overflow-auto" |
| | | v-model="sqlCode" |
| | | :style="{ height: '100%' }" |
| | | :autofocus="true" |
| | | :indent-with-tab="true" |
| | | :tab-size="2" |
| | | :extensions="sqlEditorExtensions" |
| | | @change="log('change', $event)" |
| | | @focus="log('focus', $event)" |
| | | @blur="log('blur', $event)" |
| | | /> |
| | | </div> |
| | | </div> |
| | | <div class="flex-auto overflow-auto mt-3"> |
| | | <codemirror |
| | | disabled |
| | | class="h-full overflow-auto" |
| | | v-model="jsonCode" |
| | | :style="{ height: '100%' }" |
| | | :autofocus="true" |
| | | :indent-with-tab="true" |
| | | :tab-size="2" |
| | | :extensions="jsonEditorExtensions" |
| | | @change="log('change', $event)" |
| | | @focus="log('focus', $event)" |
| | | @blur="log('blur', $event)" |
| | | /> |
| | | </div> |
| | | </div> |
| | | <HMContainer type="card"> |
| | | <template #header> |
| | | <el-form ref="queryFormRef" :inline="true" :model="queryParams"> |
| | | <el-form-item label="名称" prop="title"> |
| | | <el-input v-model="queryParams.title" style="width: 226.4px" placeholder="名称" clearable /> |
| | | </el-form-item> |
| | | |
| | | <el-form-item> |
| | | <el-button type="primary" icon="ele-Search" @click="handleQueryTable"> 查询 </el-button> |
| | | <el-button icon="ele-Refresh" @click="resetQuery">重置 </el-button> |
| | | <el-button icon="ele-Plus" @click="openOperateDialog()"> 增加 </el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | </template> |
| | | <template #main> |
| | | <el-table |
| | | v-loading="tableLoading" |
| | | ref="draggableTableRef" |
| | | class="h100" |
| | | border |
| | | row-key="ID" |
| | | :tree-props="{ children: 'Children', hasChildren: 'hasChildren' }" |
| | | :expand-row-keys="treeTableExpandKeys" |
| | | @expand-change="tableExpandChange" |
| | | :row-class-name="isDragStatus ? 'cursor-move' : 'cursor-pointer'" |
| | | :cell-style="tableCellCenterExceptColumn()" |
| | | :header-cell-style="{ textAlign: 'center' }" |
| | | :data="displayTableData" |
| | | highlight-current-row |
| | | > |
| | | <el-table-column prop="id" label="id" width="220" fixed="left" show-overflow-tooltip> </el-table-column> |
| | | <el-table-column prop="title" label="名称" width="220" fixed="left" show-overflow-tooltip> </el-table-column> |
| | | |
| | | <!-- <el-table-column prop="Code" label="编码" show-overflow-tooltip> </el-table-column> |
| | | <el-table-column prop="Description" label="说明" width="550" show-overflow-tooltip> </el-table-column> --> |
| | | <el-table-column label="操作" width="150" fixed="right" show-overflow-tooltip> |
| | | <template #default="scope"> |
| | | <el-button icon="ele-Edit" size="small" text type="primary" @click="openOperateDialog(scope.row)"> </el-button> |
| | | <el-button |
| | | icon="ele-Delete" |
| | | size="small" |
| | | text |
| | | type="danger" |
| | | |
| | | > |
| | | |
| | | </el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </template> |
| | | <ywDialog |
| | | v-model="dialogIsShow" |
| | | :headerIcon="dialogHeaderIcon" |
| | | :title="dialogTitle" |
| | | width="400" |
| | | @dlgClosed="closeDialog" |
| | | @submit="submitFormValue" |
| | | > |
| | | <el-form :model="dialogFormValue" ref="dialogFormRef" :rules="dialogFormRules" label-width="55"> |
| | | <el-form-item label="父级" prop="ParentID" v-if="!isEditDialog"> |
| | | <el-tree-select |
| | | filterable |
| | | style="width: 100%" |
| | | v-model="dialogFormValue.ParentID" |
| | | :props="{ |
| | | id: 'ID', |
| | | label: 'Name', |
| | | children: 'Children', |
| | | }" |
| | | :data="tableTreeData" |
| | | node-key="ID" |
| | | :clearable="true" |
| | | :accordion="true" |
| | | :expandNode="false" |
| | | :check-strictly="true" |
| | | > |
| | | </el-tree-select> |
| | | </el-form-item> |
| | | <el-form-item label="undefined" prop="ParentID"> |
| | | <el-input v-model="dialogFormValue.ParentID"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="名称" prop="Name"> |
| | | <el-input v-model="dialogFormValue.Name"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="编码" prop="Code"> |
| | | <el-input v-model="dialogFormValue.Code"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="说明" prop="Description"> |
| | | <el-input v-model="dialogFormValue.Description" type="textarea" :rows="3"></el-input> |
| | | </el-form-item> |
| | | </el-form> |
| | | </ywDialog> |
| | | </HMContainer> |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import { json } from '@codemirror/lang-json'; |
| | | import { sql } from '@codemirror/lang-sql'; |
| | | import { xml } from '@codemirror/lang-xml'; |
| | | import { vscodeDark } from '@uiw/codemirror-theme-vscode'; |
| | | import { ref } from 'vue'; |
| | | import { Codemirror } from 'vue-codemirror'; |
| | | import * as codeExample from './testData'; |
| | | import _ from 'lodash'; |
| | | const log = console.log; |
| | | const jsonCode = ref(codeExample.jsonCode); |
| | | const dockCode = ref(codeExample.dockCode); |
| | | const sqlCode = ref(codeExample.sqlCode); |
| | | const tableData = [ |
| | | { |
| | | date: '2016-05-03', |
| | | name: 'Tom', |
| | | address: 'No. 189, Grove St, Los Angeles', |
| | | }, |
| | | { |
| | | date: '2016-05-02', |
| | | name: 'Tom', |
| | | address: 'No. 189, Grove St, Los Angeles', |
| | | }, |
| | | { |
| | | date: '2016-05-04', |
| | | name: 'Tom', |
| | | address: 'No. 189, Grove St, Los Angeles', |
| | | }, |
| | | { |
| | | date: '2016-05-01', |
| | | name: 'Tom', |
| | | address: 'No. 189, Grove St, Los Angeles', |
| | | }, |
| | | ]; |
| | | const jsonEditorExtensions = [json(), vscodeDark]; |
| | | const sqlEditorExtensions = [sql(), vscodeDark]; |
| | | const dockEditorExtensions = [xml(), vscodeDark]; |
| | | import type { FormInstance, FormRules } from 'element-plus'; |
| | | import { ElMessage } from 'element-plus'; |
| | | |
| | | const dockRowChange = (row) => {}; |
| | | /** @description 路径分隔符 */ |
| | | const PATH_SEPARATOR = '/'; |
| | | /** @description 1 退出所有循环 -1退出当次循环 0或其他值继续 */ |
| | | const travelObj = (obj, callBack?: (key?: string, value?: any, path?: string) => 1 | -1 | undefined | void | 0, path = '') => { |
| | | let entry = Object.entries(obj); |
| | | // if (entry[0] && !entry[0]['isRoot']) { |
| | | // entry = entry.map((item) => { |
| | | // item['isRoot'] = true; |
| | | // item['path'] = ''; |
| | | // return item; |
| | | // }); |
| | | // } |
| | | let res = null; |
| | | import { computed, onMounted, ref } from 'vue'; |
| | | import ywDialog from '/@/components/dialog/yw-dialog.vue'; |
| | | import HMContainer from '/@/components/layout/HMContainer.vue'; |
| | | import { usePageDisplay } from '/@/hooks/usePageDisplay'; |
| | | import { useQueryTable } from '/@/hooks/useQueryTable'; |
| | | // import { useTableSort } from '/@/hooks/useTableSort'; |
| | | // import { useValidateUniqueness } from '/@/hooks/useValidateUniqueness'; |
| | | import { deepClone } from '/@/utils/other'; |
| | | import { deleteCurrentRow } from '/@/utils/util'; |
| | | |
| | | iterate: for (const item of entry) { |
| | | const [key, value] = item; |
| | | const currentPath = path + key; |
| | | res = callBack?.(key, value, currentPath); |
| | | switch (res) { |
| | | case 1: |
| | | break iterate; |
| | | case -1: |
| | | continue iterate; |
| | | default: |
| | | break; |
| | | } |
| | | if (!value) { |
| | | continue; |
| | | } |
| | | if (_.isObjectLike(value)) { |
| | | res = travelObj(value, callBack, currentPath); |
| | | switch (res) { |
| | | case 1: |
| | | break iterate; |
| | | case -1: |
| | | continue iterate; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | import * as supervisorAdminApi from '/@/api/supervisorAdmin'; |
| | | import { convertListToTree, tableCellCenterExceptColumn } from '/@/utils/util'; |
| | | const tableTreeData = computed(() => convertListToTree(tableData.value)); |
| | | |
| | | //#region ====================== 表格数据,table init ====================== |
| | | const tableLoading = ref(false); |
| | | const tableData = ref([]); |
| | | const isDragStatus = ref(false); |
| | | const getTableData = async () => { |
| | | tableLoading.value = true; |
| | | const res = await supervisorAdminApi.getSupervisorList().finally(() => { |
| | | tableLoading.value = false; |
| | | }); |
| | | tableData.value = res.values||[]; |
| | | }; |
| | | //#endregion |
| | | |
| | | //#region ====================== 表格查询、排序,search form init ====================== |
| | | |
| | | const queryParams = ref({ |
| | | title: '', |
| | | }); |
| | | const { resetQuery, handleQueryTable, displayTableData } = useQueryTable(tableData, queryParams, ()=>{ |
| | | displayTableData.value = tableData.value; |
| | | }); |
| | | |
| | | |
| | | |
| | | //#endregion |
| | | |
| | | //#region ====================== 增加、修改记录操作, dialog init====================== |
| | | const isEditDialog = ref(false); |
| | | const dialogTitle = computed(() => { |
| | | return isEditDialog.value ? '修改分组' : '添加分组'; |
| | | }); |
| | | const dialogHeaderIcon = computed(() => { |
| | | return isEditDialog.value ? 'ele-Edit' : 'ele-Plus'; |
| | | }); |
| | | const dialogFormValue = ref(null); |
| | | const dialogIsShow = ref(false); |
| | | const dialogFormRef = ref<FormInstance>(null); |
| | | |
| | | |
| | | |
| | | const dialogFormRules = ref<FormRules>({ |
| | | ParentID: [{ required: true, message: '请选择undefined', trigger: 'change' }], |
| | | Name: [{ required: true, message: '请输入名称', trigger: 'blur' }], |
| | | }); |
| | | const openOperateDialog = (row?) => { |
| | | if (row) { |
| | | isEditDialog.value = true; |
| | | const { ID, ParentID, Name, Code, Description } = row; |
| | | |
| | | dialogFormValue.value = deepClone({ ID, ParentID, Name, Code, Description }); |
| | | } else { |
| | | isEditDialog.value = false; |
| | | |
| | | dialogFormValue.value = { ParentID: '', Name: '', Code: '', Description: '' }; |
| | | } |
| | | return res; |
| | | dialogIsShow.value = true; |
| | | }; |
| | | const closeDialog = () => { |
| | | dialogIsShow.value = false; |
| | | dialogFormRef.value.clearValidate(); |
| | | }; |
| | | |
| | | const enum AmisDockType { |
| | | Api, |
| | | } |
| | | type AmisDockApi = string; |
| | | type AmisDockValue = AmisDockApi; |
| | | type AmisDockConfig = { |
| | | type: AmisDockType; |
| | | value: AmisDockValue; |
| | | }; |
| | | const parseJSONData = (json: string) => { |
| | | if (!json) return; |
| | | const obj = JSON.parse(json); |
| | | const configList: AmisDockConfig[] = []; |
| | | travelObj( |
| | | { |
| | | id: 'u:7d4e7d100425', |
| | | body: [ |
| | | { |
| | | id: 'u:3e0a8e524d99', |
| | | }, |
| | | ], |
| | | }, |
| | | (key, value, path) => { |
| | | console.log('🚀 ~ key:', key); |
| | | console.log('🚀 ~ value:', value); |
| | | console.log('🚀 ~ path:', path); |
| | | const submitFormValue = async () => { |
| | | const valid = await dialogFormRef.value.validate().catch(() => {}); |
| | | if (!valid) return; |
| | | |
| | | // if (key === 'api') { |
| | | // configList.push({ |
| | | // type: AmisDockType.Api, |
| | | // value: value.url, |
| | | // }); |
| | | // } |
| | | if (isEditDialog.value) { |
| | | const res = await supervisorAdminApi.UpdateADictGroup(dialogFormValue.value); |
| | | const resData = res.Data; |
| | | if (resData) { |
| | | getTableData(); |
| | | closeDialog(); |
| | | ElMessage.success('修改分组成功'); |
| | | } else { |
| | | ElMessage.error('修改分组失败'); |
| | | } |
| | | ); |
| | | } else { |
| | | const res = await supervisorAdminApi.InsertADictGroup(dialogFormValue.value); |
| | | const resData = res.Data; |
| | | if (resData === '0') { |
| | | ElMessage.error('添加分组失败'); |
| | | return; |
| | | } |
| | | getTableData(); |
| | | closeDialog(); |
| | | ElMessage.success('添加分组成功'); |
| | | } |
| | | }; |
| | | |
| | | parseJSONData(codeExample.jsonCode); |
| | | //#endregion |
| | | //#region ====================== 查询快捷键 ====================== |
| | | const queryFormRef = ref(null); |
| | | const pressEnterSearch = (ev: KeyboardEvent) => { |
| | | if (ev.key === 'Enter') { |
| | | handleQueryTable(); |
| | | } |
| | | }; |
| | | usePageDisplay( |
| | | () => { |
| | | queryFormRef.value.$el.addEventListener('keypress', pressEnterSearch); |
| | | }, |
| | | () => { |
| | | queryFormRef.value?.$el.removeEventListener('keypress', pressEnterSearch); |
| | | } |
| | | ); |
| | | //#endregion |
| | | //#region ====================== 解决拖拽展开状态失效问题 ====================== |
| | | const treeTableExpandKeys = ref([]); |
| | | const tableExpandChange = (row, expanded) => { |
| | | if (expanded) { |
| | | treeTableExpandKeys.value.push(row.ID); |
| | | } else { |
| | | const idx = treeTableExpandKeys.value.indexOf(row.ID); |
| | | treeTableExpandKeys.value.splice(idx, 1); |
| | | } |
| | | }; //#endregion |
| | | onMounted(() => { |
| | | getTableData(); |
| | | }); |
| | | </script> |
| | | <style scoped lang="scss"></style> |