From 35d6dfc8e565708492af695f4274aa8812b0603c Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期三, 05 三月 2025 09:45:58 +0800 Subject: [PATCH] 一些更改 --- src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue | 413 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 311 insertions(+), 102 deletions(-) diff --git a/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue b/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue index c3b5fd0..7f9a844 100644 --- a/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue +++ b/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue @@ -6,11 +6,29 @@ class="!mt-5" v-for="(item, index) in drawers" > - <BasicTable @register="useTables[item.name]"> + <BasicTable + @register="useTables[item.name]" + :beforeEditSubmit=" + ({ record, index, key, value }) => + beforeEditSubmit({ record, index, key, value }, item.name) + " + @edit-end=" + ({ record, index, key, value }) => handleEditEnd({ record, index, key, value }, item.name) + " + @edit-change="onEditChange" + > <template #toolbar> - <a-button type="primary" @click="handleCreate(index, item)" preIcon="add_02|svg"> - 鏂板 + <a-button + v-if="item.showTbButton" + type="primary" + v-for="d in buttons.filter((m) => m['BUTTON_TYPE'] == 0)" + @click="handleCreate(index, item, d)" + :preIcon="d['ICON_URL']" + :key="d" + > + {{ d['FUNC_NAME'] }} </a-button> + <!-- <a-button v-if="item.showTbButton" @click="openImg" type="primary"> 棰勮 </a-button> --> </template> <template #action="{ record }"> <TableAction :actions="createActions(record, index, item)" /> @@ -37,22 +55,28 @@ </div> </template> <script lang="ts" setup> - import { Ref, inject, onMounted, ref, watch } from 'vue'; - import { BasicTable, TableAction } from '/@/components/Table'; - import { useForm } from '/@/components/Form/index'; + import { Ref, inject, onMounted, ref, unref, watch } from 'vue'; + import { BasicTable, EditRecordRow, TableAction } from '/@/components/Table'; import GeneralModal from '/@/views/components/GeneralModal.vue'; import normalDrawer from '../../normalDrawer.vue'; import { isFunction, isNullOrEmpty, isNullOrUnDef } from '/@/utils/is'; import { useModal } from '/@/components/Modal'; import { useGo } from '/@/hooks/web/usePage'; - import { DeleteEntity, getEntity } from '/@/api/tigerapi/system'; + import { DeleteEntity, getEntity, SaveEntity } from '/@/api/tigerapi/system'; import { useI18n } from '/@/hooks/web/useI18n'; import { Card } from 'ant-design-vue'; import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel'; + import { useRouter } from 'vue-router'; + import { getRoleButtons } from '/@/api/sys/menu'; + import { CustModalParams } from '/@/api/tigerapi/model/systemModel'; + import { useWebSocketStore } from '/@/store/modules/websocket'; + import { useTabs } from '/@/hooks/web/useTabs'; + import { cloneDeep } from 'lodash-es'; + import { useMessage } from '/@/hooks/web/useMessage'; const { t } = useI18n(); const ACard = Card; - const emit = defineEmits(['search']); + const emit = defineEmits(['search', 'opencust', 'gettables']); const props = defineProps({ colSlots: { type: Array as PropType<any[]> }, useTableData: { type: Object as PropType<{}>, default: { table: [] } }, @@ -65,24 +89,29 @@ const _useTables = inject('useTables') as Ref<any>; const useFormData = inject('useFormData') as Ref<{}>; const keyFieldValues = inject('keyFieldValues') as Ref<Recordable[]>; + const others = ref({}); + const ctype = ref(''); + const { createMessage: msg } = useMessage(); const go = useGo(); + const { currentRoute } = useRouter(); const [registerItemAdd, { openModal: openItemModal }] = useModal(); - const cType = ref(''); - const dtlSlots = ref([] as any[]); - const useModalData = ref({}); //琛ㄥ崟涓彃妲芥覆鏌撴寜閽墦寮�妯℃�佹useModal鏂规硶 + const currentEditKeyRef = ref(''); const custImport = ref<any[]>([]); const EntityCustFunction = ref([ { - ActionItem(params, data, ...args) {}, - EditOperation(data, d, u, item) {}, - GetCrudForm(type: string | undefined, ...args) {}, - KeyFieldValues(val, id) {}, - GetTitle(type: string | undefined) {}, - GetUseTables(data: Ref<Recordable[]>, ...args) {}, + ActionItem() {}, + EditOperation() {}, + GetCrudForm() {}, + KeyFieldValues() {}, + GetTitle() {}, + GetUseTables() {}, GetUseDrawers() {}, - CustInitData(data: Ref<any[]>, keyFieldValues: Ref<{}>, type: string) {}, - } as EntityCustFunctionType, + CustInitData() {}, + GetNewRow() {}, + CreateAction() {}, + CustEditEnd() {}, + } as unknown as EntityCustFunctionType, ]); /* 鍔ㄦ�乮mport瀹炰綋鍚�.ts鐨勮嚜瀹氫箟鏂规硶 */ try { @@ -90,7 +119,6 @@ } catch (e) {} const [ { - ActionItem: nActionItem, EditOperation, GetCrudForm, KeyFieldValues, @@ -98,36 +126,54 @@ GetUseTables, GetUseDrawers, CustInitData, + CreateAction, + CustFunc, + GetNewRow, + CustEditEnd, }, ] = isNullOrUnDef(custImport.value['default']) ? EntityCustFunction.value : custImport.value['default'](); + const buttons = ref<[]>(await getRoleButtons(currentRoute.value.meta.menuCode as string)); keyFieldValues.value = KeyFieldValues(objParams.value['CODE'], objParams.value['ID']); //鑾峰彇涓�浜涘叾浠栨湁闇�瑕佹彁渚涚殑鍊硷紝杩欓噷鏄富椤甸潰璺宠浆杩囨潵鏃跺甫鐨勫叧閿瓧娈靛�� const drawers = ref<any[]>(objParams.value['drawers']); //鏄彸渚ц竟妗嗗垪琛紝閲岄潰鐨刵ame琛ㄧず鏄摢涓�涓疄浣擄紝涔熷氨鏄珮绾ц〃鍗曚腑琛ㄦ牸鐨勫悕瀛楋紝寰堝鏂规硶闇�瑕佷互杩欎釜鍚嶅瓧涓簁ey const useTables = GetUseTables(data, emit); //楂樼骇琛ㄥ崟涓悇涓〃鏍�(Table)鐨剈seTable鏂规硶瀹炵幇鍒楄〃 const useDrawers = GetUseDrawers(); //楂樼骇琛ㄥ崟涓悇涓〃鏍�(Table)鐨勫彸渚ц竟妗�(Drawer)鐨剈seDrawer鏂规硶瀹炵幇鍒楄〃 _useTables.value = useTables; //鎶妘seTable鐨勫垪琛ㄥ搷搴斿埌浠庝富椤甸潰娉ㄥ叆鐨刜useTables锛岃繖鏍蜂富椤甸潰鑳芥嬁鍒皍seTable鐨勭粨鏋滐紝浠庤�屽彲浠ヤ娇鐢ㄥ悇涓〃鏍肩殑鍐呯疆鏂规硶 - // watch( - // () => props.dataSource, - // (newVal, oldVal) => { - // nextTick(() => { - // setProps({ - // dataSource: [], - // }); - // data.value = newVal; - // setProps({ - // dataSource: data, - // }); - // }); - // }, - // { deep: true, immediate: true }, - // ); + const webSocketStore = useWebSocketStore(); + const { refreshPage } = useTabs(); + watch( + () => webSocketStore.socketMessage, + (newVal, oldVal) => { + console.log(oldVal, newVal); + /* 濡傛灉鐩戝惉鍒扮殑鍊间笉涓�鏍凤紝鍒欏埛鏂伴〉闈� */ + if ( + newVal != oldVal && + !isNullOrEmpty(oldVal) && + newVal['Data'] == 'Content' && + newVal['IsSuccessed'] + ) { + // init().then(() => { + // refreshPage(); + // }); + } + }, + { deep: true, immediate: true }, + ); /** * @description: 鎸傝浇缁勪欢瀹屾垚鏃� * @return {*} */ onMounted(async () => { + init(); + }); + + /** + * @description: 鍒濆鍖栨暟鎹� + * @return {*} + */ + async function init() { for (const i in drawers.value) { let sqlcmd = ' 1 =1 '; if (!isNullOrEmpty(keyFieldValues.value[drawers.value[i].code])) { @@ -152,7 +198,7 @@ data.value[drawers.value[i].name] = list.Data.Items; // 鑷畾涔夊垵濮嬪寲鏁版嵁 if (CustInitData && isFunction(CustInitData)) { - CustInitData(data, keyFieldValues, drawers.value[i].name); + CustInitData(data, keyFieldValues, drawers.value[i].name, useTables); } useTables[drawers.value[i].name][1].setProps({ dataSource: [], @@ -161,9 +207,12 @@ dataSource: data.value[drawers.value[i].name], }); useTables[drawers.value[i].name][1].reload(); + emit('gettables', useTables); } } - }); + } + + const imgList = ['http://localhost:8800/files/Template/10浣嶆壒娆℃潯鐮�.png']; /** * @description: 鐢熸垚鍒楄〃涓搷浣滈」鐨勬寜閽� @@ -171,75 +220,45 @@ * @return {*} */ function createActions(record, index, item) { - const params = { - record, - isUpdate: true, - ifSave: true, - entityName: props.entityName, - formJson: [], //getFormSchema(`${entityName.value}_Crud`), - cType, - dtlSlots, - useModalData, - useFormData, - crudColSlots: props.crudColSlots, - data, - name: item.name, //drawers鍒楄〃閲岄潰鐨刵ame锛岃〃绀烘槸鍝竴涓疄浣擄紝涔熷氨鏄珮绾ц〃鍗曚腑琛ㄦ牸鐨勫悕瀛� - keyName: item.keyName, - }; - const actionItem = [ + if (!record.editable) { + const values = useFormData.value['BaseForm'][1].getFieldsValue(); + const type = values['TEMP_TYPE']; + return [ + { + label: '缂栬緫', + disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false, + onClick: handleEdit.bind(null, record), + name: '', + }, + { + label: '鍒犻櫎', + color: 'error', + disabled: + type == 0 + ? true + : currentEditKeyRef.value + ? currentEditKeyRef.value !== record.key + : false, + onClick: handleDel.bind(null, record, index, item), + name: '', + }, + ]; + } + return [ { - icon: 'clarity:note-edit-line', - onClick: editRecord.bind(null, useDrawers[index][item.name][1].openDrawer, params), + label: '淇濆瓨', + onClick: handleSave.bind(null, record, index, item), + name: '', }, { - icon: 'ant-design:delete-outlined', - color: 'error', + label: '鍙栨秷', popConfirm: { - title: '鏄惁纭鍒犻櫎?', - placement: 'left', - confirm: deleteRecord.bind(null, useTables[item.name][1].reload, params), + title: '鏄惁鍙栨秷缂栬緫', + confirm: handleCancel.bind(null, record, index, item), }, + name: '', }, ]; - if (isNullOrUnDef(custImport.value)) { - return actionItem; - } - return nActionItem( - params, - actionItem, - useDrawers[index][item.name][1].openDrawer, - useTables, - null, - useForm, - useModal, - go, - ); - } - - /** - * @description: 鍏敤缂栬緫鏂规硶 - * @param {Fn} fn - * @param {*} params - * @return {*} - */ - function editRecord(fn: Fn, params: {}) { - fn(true, params); - } - - /** - * @description: 鍏敤鍒犻櫎鏂规硶 - * @param {Fn} fn - * @param {*} params - * @return {*} - */ - function deleteRecord(fn: Fn, params: {}) { - console.log(params['record']); - //鍒犻櫎 - DeleteEntity(params['record'], params['entityName']).then((action) => { - if (action.IsSuccessed) { - fn(); - } - }); } /** @@ -257,22 +276,23 @@ } /** - * @description: 鏂板鎸夐挳鏂规硶 + * @description: 鎵撳紑鎶藉眽鏂规硶 * @param {*} index * @param {*} item * @return {*} */ - function handleCreate(index, item) { + function CreateopenDrawer(index, item) { validate().then((res) => { const Keys = Object.getOwnPropertyNames(useFormData.value); for (const i in Keys) { keyFieldValues.value[item['code']] = objParams.value['IsID'] ? res[Keys[i]]['ID'] : res[Keys[i]][item['code']]; + console.log(i); } useDrawers[index][item['name']][1].openDrawer(true, { isUpdate: false, - ifSave: true, + ifSave: objParams.value['ifSave'], entityName: item['name'], //props.entityName, // formJson: GetCrudForm(item, data), //鑾峰彇澧炲垹鏀硅〃鍗曞瓧娈� crudColSlots: props.crudColSlots, @@ -282,6 +302,65 @@ keyName: item['keyName'], }); }); + } + + /** + * @description: 鏂板鎸夐挳鏂规硶 + * @param {*} index + * @param {*} item + * @return {*} + */ + function handleCreate(index, item, d) { + const _cruds = GetCrudForm(); + let isExistSql = ''; + for (const i in _cruds) { + if (_cruds[i].isexist == 'Y') { + isExistSql = _cruds[i].field; + } + } + + if (isNullOrUnDef(custImport.value['default'])) { + CreateopenDrawer(index, item); + } else { + const result = CreateAction(item.name); + /* 鏍规嵁涓婚〉闈㈣烦杞紶杩囨潵鐨勫弬鏁扮‘瀹氭柊澧炴寜閽殑鎵ц鏂规硶 */ + switch (result.action) { + case 'go': + sessionStorage.removeItem(`${result.params.Name}_update_params`); + // 灏嗗璞¤浆鎹负JSON瀛楃涓插苟淇濆瓨鍒皊essionStorage + sessionStorage.setItem( + `${result.params.Name}_update_params`, + encodeURI(JSON.stringify(result.params)), + ); + go( + `/${result.url}/${encodeURI(JSON.stringify({ sName: `${result.params.Name}_update`, Name: result.params.Name }))}`, + ); + break; + case 'drawer': + CreateopenDrawer(index, item); + break; + case 'edit': + const params: CustModalParams = { + mValues: {}, + others: keyFieldValues.value, + cType: item.name, + values: GetNewRow(item.name), + initFnName: '', + FnName: item.FnName, + data: data, + }; + /* 鑷畾涔夋柟娉� */ + CustFunc(params); + useTables[item.name][1].setProps({ + dataSource: [], + }); + useTables[item.name][1].setProps({ + dataSource: data.value[item.name], + }); + useTables[item.name][1].reload(); + break; + } + } } /** @@ -381,4 +460,134 @@ }); } catch (e) {} } + + /** + * @description: 鍗曞厓鏍肩紪杈戝畬鎴愬悗浜嬩欢 + * @param {*} record + * @param {*} index + * @param {*} key + * @param {*} value + * @param {*} name + * @return {*} + */ + function handleEditEnd({ record, index, key, value }: Recordable, name) { + console.log(record, index, key, value); + data.value[name][index] = record; + /* 鍗曞厓鏍肩紪杈戝畬鎴愬悗濡傛灉鏈夎嚜瀹氫箟鏂规硶锛屽氨璋冪敤 */ + if (CustEditEnd && isFunction(CustEditEnd)) { + CustEditEnd({ record, index, key, value }, name, useTables, data); + } + return false; + } + + /** + * @description: 鍗曞厓鏍兼彁浜や簨浠� + * @param {*} record + * @param {*} index + * @param {*} key + * @param {*} value + * @param {*} name + * @return {*} + */ + async function beforeEditSubmit({ record, index, key, value }, name) { + console.log('鍗曞厓鏍兼暟鎹鍦ㄥ噯澶囨彁浜�', { record, index, key, value }); + return true; + } + + /** + * @description: 缂栬緫鏀瑰彉鏃朵簨浠� + * @param {*} column + * @param {*} value + * @param {*} record + * @return {*} + */ + function onEditChange({ column, value, record }) { + // 鏈緥 + if (column.dataIndex === 'id') { + record.editValueRefs.name4.value = `${value}`; + } + console.log(column, value, record); + } + + /** + * @description: 缂栬緫琛� + * @param {*} record + * @return {*} + */ + function handleEdit(record: EditRecordRow) { + currentEditKeyRef.value = record.key; + record.onEdit?.(true); + } + + /** + * @description: 鍒犻櫎琛� + * @param {*} record + * @return {*} + */ + function handleDel(record: EditRecordRow, index, item) { + data.value[item.name] = data.value[item.name].filter((q) => q.ID != record.ID); + useTables[item.name][1].setProps({ + dataSource: [], + }); + useTables[item.name][1].setProps({ + dataSource: data.value[item.name], + }); + useTables[item.name][1].reload(); + // setData(); + } + + /** + * @description: 鍙栨秷缂栬緫 + * @param {*} record + * @return {*} + */ + function handleCancel(record: EditRecordRow, index, item) { + currentEditKeyRef.value = ''; + record.onEdit?.(false, false); + } + + /** + * @description: 淇濆瓨鎿嶄綔 + * @param {*} record + * @return {*} + */ + async function handleSave(record: EditRecordRow, index, item) { + // 鏍¢獙 + msg.loading({ content: '姝e湪淇濆瓨...', duration: 0, key: 'saving' }); + const valid = await record.onValid?.(); + if (valid) { + try { + const _data = cloneDeep(record.editValueRefs); + console.log(_data); + //TODO 姝ゅ灏嗘暟鎹彁浜ょ粰鏈嶅姟鍣ㄤ繚瀛� + if (CustFunc && isFunction(CustFunc)) { + CustFunc({ + others: others.value, + cType: item.name, + values: record, + data: data, + FnName: 'SaveRow', + }); + } else { + /* 榛樿淇濆瓨鏂规硶 */ + const action = await SaveEntity( + record, + true, + item.name, //瀹炰綋鍚� + // `${isExistSql.value}='${values[isExistSql.value]}'`, + ); + } + // 淇濆瓨涔嬪悗鎻愪氦缂栬緫鐘舵�� + const pass = await record.onEdit?.(false, true); + if (pass) { + currentEditKeyRef.value = ''; + } + msg.success({ content: t('鏁版嵁宸叉殏瀛橈紝瑕佹渶缁堜繚瀛樺埌鏁版嵁搴撹鎻愪氦'), key: 'saving' }); + } catch (error) { + msg.error({ content: t('淇濆瓨澶辫触'), key: 'saving' }); + } + } else { + msg.error({ content: t('璇峰~鍐欐纭殑鏁版嵁'), key: 'saving' }); + } + } </script> -- Gitblit v1.9.3