| | |
| | | <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"> |
| | | <!-- <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'" |
| | | :data="displayTableData" |
| | | highlight-current-row |
| | | > |
| | | <el-table-column prop="title" label="标题" width="300" fixed="left" show-overflow-tooltip> </el-table-column> |
| | | <el-table-column prop="prompt" label="提示词" show-overflow-tooltip> </el-table-column> |
| | | <el-table-column prop="published" label="状态" width="80" show-overflow-tooltip> |
| | | <template #default="scope"> |
| | | {{ supervisorPublishedMap[scope.row.published] }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="创建人" prop="creator" width="100" show-overflow-tooltip> </el-table-column> |
| | | <el-table-column label="创建时间" prop="create_time" width="105" show-overflow-tooltip> </el-table-column> |
| | | <el-table-column label="更新时间" prop="update_time" width="105" show-overflow-tooltip> </el-table-column> |
| | | <el-table-column label="备注" prop="note" 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="120" fixed="right" show-overflow-tooltip> |
| | | <template #default="scope"> |
| | | <div class="space-x-2.5"> |
| | | <el-tooltip effect="dark" content="SQL编辑" placement="top"> |
| | | <i class="ywifont ywicon-sql !text-[14px] text-blue-400 cursor-pointer" @click="editSqlClick(scope.row)"></i> |
| | | </el-tooltip> |
| | | <el-tooltip effect="dark" content="编辑" placement="top"> |
| | | <i class="ywifont ywicon-bianji !text-[14px] text-blue-400 cursor-pointer" @click="openOperateDialog(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="openOperateDialog(scope.row)"></i> |
| | | </el-tooltip> |
| | | </div> |
| | | </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" |
| | | :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 { defineComponent, ref, shallowRef } from 'vue'; |
| | | import { Codemirror } from 'vue-codemirror'; |
| | | import { json } from '@codemirror/lang-json'; |
| | | import { vscodeDark, vscodeLight, vscodeLightInit } from '@uiw/codemirror-theme-vscode'; |
| | | import * as codeExample from './testData'; |
| | | import { sql } from '@codemirror/lang-sql'; |
| | | import { xml } from '@codemirror/lang-xml'; |
| | | const log = console.log; |
| | | const jsonCode = ref(codeExample.jsonCode); |
| | | const dockCode = ref(codeExample.dockCode); |
| | | const sqlCode = ref(codeExample.sqlCode); |
| | | import type { FormInstance, FormRules } from 'element-plus'; |
| | | import { ElMessage } from 'element-plus'; |
| | | |
| | | const jsonEditorExtensions = [json(), vscodeDark]; |
| | | const sqlEditorExtensions = [sql(), vscodeDark]; |
| | | const dockEditorExtensions = [xml(), vscodeDark]; |
| | | 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 { supervisorPublishedMap } from './types'; |
| | | import * as supervisorAdminApi from '/@/api/supervisorAdmin'; |
| | | import { convertListToTree, tableCellCenterExceptColumn } from '/@/utils/util'; |
| | | import { gotoRoute } from '/@/utils/route'; |
| | | 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 || []).map((item) => { |
| | | item.create_time = item.create_time.slice(0, 10); |
| | | item.update_time = item.create_time.slice(0, 10); |
| | | |
| | | return item; |
| | | }); |
| | | }; |
| | | //#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: '' }; |
| | | } |
| | | dialogIsShow.value = true; |
| | | }; |
| | | const closeDialog = () => { |
| | | dialogIsShow.value = false; |
| | | dialogFormRef.value.clearValidate(); |
| | | }; |
| | | |
| | | const submitFormValue = async () => { |
| | | const valid = await dialogFormRef.value.validate().catch(() => {}); |
| | | if (!valid) return; |
| | | |
| | | 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('添加分组成功'); |
| | | } |
| | | }; |
| | | |
| | | //#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 |
| | | |
| | | |
| | | //#region ====================== sql ====================== |
| | | const editSqlClick = () => { |
| | | gotoRoute({ |
| | | name:'SqlAmisEdit' |
| | | }) |
| | | }; |
| | | //#endregion |
| | | onMounted(() => { |
| | | getTableData(); |
| | | }); |
| | | </script> |
| | | <style scoped lang="scss"></style> |