| | |
| | | <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" v-if="supervisorMgrShow"> |
| | | <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> |
| | | <!-- <div class="h-screen"> |
| | | <p>vue-json-editor</p> |
| | | <JsonEditorVue v-model="jsonMsg"></JsonEditorVue> |
| | | </div> --> |
| | | <el-table |
| | | v-loading="tableLoading" |
| | | ref="draggableTableRef" |
| | | class="h100" |
| | | border |
| | | :row-class-name="isDragStatus ? 'cursor-move' : 'cursor-pointer'" |
| | | :data="displayTableData" |
| | | highlight-current-row |
| | | > |
| | | <el-table-column type="expand" fixed="left"> |
| | | <template #default="scope"> |
| | | <div class="px-4"> |
| | | <h3 class="mb-2">页面参数</h3> |
| | | <JsonEditor currentMode="view" :modelValue="scope.row.args" /> |
| | | </div> |
| | | </template> |
| | | </el-table-column> |
| | | |
| | | <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 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=" |
| | | () => { |
| | | deleteCurrentRow(scope.row, '页面', supervisorAdminApi.DeleteAAssetsEquipmentCostCategory, () => { |
| | | const foundIndex = tableData.findIndex((item) => item === scope.row); |
| | | foundIndex > -1 && tableData.splice(foundIndex, 1); |
| | | }); |
| | | } |
| | | " |
| | | ></i> |
| | | </el-tooltip> |
| | | </div> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </template> |
| | | <ywDialog |
| | | v-model="dialogIsShow" |
| | | :headerIcon="dialogHeaderIcon" |
| | | :title="dialogTitle" |
| | | width="680" |
| | | @dlgClosed="closeDialog" |
| | | @submit="submitFormValue" |
| | | > |
| | | <el-form :model="dialogFormValue" ref="dialogFormRef" :rules="dialogFormRules" label-width="78"> |
| | | <el-form-item label="标题" prop="title"> |
| | | <el-input v-model="dialogFormValue.title"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="提示词" prop="prompt"> |
| | | <el-input v-model="dialogFormValue.prompt"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="状态" prop="published"> |
| | | <el-select v-model="dialogFormValue.published"> |
| | | <el-option |
| | | v-for="item in Object.keys(supervisorPublishedMap)" |
| | | :key="item" |
| | | :value="item" |
| | | :label="supervisorPublishedMap[item]" |
| | | ></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="备注" prop="note"> |
| | | <el-input v-model="dialogFormValue.note" type="textarea" :rows="3"></el-input> |
| | | </el-form-item> |
| | | <div class="flex"> |
| | | <span class="flex-0 ml-2.5">页面参数</span> |
| | | <JsonEditor class="ml-3 h-80" :showToolbar="true" currentMode="form" v-model="dialogFormValue.args" /> |
| | | </div> |
| | | </el-form> |
| | | </ywDialog> |
| | | </HMContainer> |
| | | <SqlAmisEdit v-else :supervisor="sqlEditMapSupervisor" @backLastPage="backLastPage"></SqlAmisEdit> |
| | | </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'; |
| | | import { deleteCurrentRow } from '/@/utils/util'; |
| | | |
| | | 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'; |
| | | |
| | | 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 SqlAmisEdit from './edit/SqlAmisEdit.vue'; |
| | | import { SupervisorPublished, supervisorPublishedMap } from './types'; |
| | | import * as supervisorAdminApi from '/@/api/supervisorAdmin'; |
| | | import JsonEditor from '/@/components/form/jsonEditor/JsonEditor.vue'; |
| | | |
| | | //#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>({ |
| | | title: [{ required: true, message: '请输入标题', trigger: 'change' }], |
| | | // prompt: [{ required: true, message: '输入提示词', trigger: 'blur' }], |
| | | }); |
| | | const openOperateDialog = (row?) => { |
| | | if (row) { |
| | | isEditDialog.value = true; |
| | | const { id, note, prompt, published, title, args } = row; |
| | | |
| | | dialogFormValue.value = deepClone({ id, note, prompt, published, title, args }); |
| | | } else { |
| | | isEditDialog.value = false; |
| | | |
| | | dialogFormValue.value = { title: null, prompt: null, published: SupervisorPublished.Y, note: null }; |
| | | } |
| | | 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) { |
| | | const foundIndex = tableData.value.find((item) => item.id === dialogFormValue.value.id); |
| | | if (foundIndex > -1) { |
| | | tableData.value[foundIndex] = { |
| | | ...tableData.value[foundIndex], |
| | | ...dialogFormValue.value, |
| | | }; |
| | | } |
| | | closeDialog(); |
| | | ElMessage.success('修改页面成功'); |
| | | } else { |
| | | ElMessage.error('修改页面失败'); |
| | | } |
| | | ); |
| | | } else { |
| | | const res = await supervisorAdminApi.InsertADictGroup(dialogFormValue.value); |
| | | const resData = res.Data; |
| | | if (resData === '0') { |
| | | ElMessage.error('添加页面失败'); |
| | | return; |
| | | } |
| | | const newData = { |
| | | id: resData, |
| | | ...dialogFormValue.value, |
| | | }; |
| | | tableData.value.push(newData); |
| | | 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 ====================== sql ====================== |
| | | |
| | | const supervisorMgrShow = ref(true); |
| | | const sqlEditMapSupervisor = ref(null); |
| | | const editSqlClick = (item) => { |
| | | sqlEditMapSupervisor.value = item; |
| | | supervisorMgrShow.value = false; |
| | | }; |
| | | |
| | | const backLastPage = () => { |
| | | supervisorMgrShow.value = true; |
| | | }; |
| | | //#endregion |
| | | |
| | | onMounted(() => { |
| | | getTableData(); |
| | | }); |
| | | </script> |
| | | <style scoped lang="scss"></style> |