From 8099042b51891d1e58d6066f0247ba423f4457bd Mon Sep 17 00:00:00 2001 From: yyg1378265336 <1378265336@qq.com> Date: 星期四, 27 二月 2025 09:27:17 +0800 Subject: [PATCH] Merge branch 'master' of http://47.115.28.255:8110/r/TigerClouds-Tech/BS/TigerAdmin_2024 --- src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue | 307 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 237 insertions(+), 70 deletions(-) diff --git a/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue b/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue index 1109204..7f9a844 100644 --- a/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue +++ b/src/views/tigerprojects/system/lowcode/high/edit/editdtl.vue @@ -6,7 +6,17 @@ 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 v-if="item.showTbButton" @@ -18,6 +28,7 @@ > {{ 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)" /> @@ -44,22 +55,24 @@ </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 { GenerateActionButton } from '../../data'; 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; @@ -76,26 +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) {}, - GetNewRow(type: string) {}, - } as EntityCustFunctionType, + CustInitData() {}, + GetNewRow() {}, + CreateAction() {}, + CustEditEnd() {}, + } as unknown as EntityCustFunctionType, ]); /* 鍔ㄦ�乮mport瀹炰綋鍚�.ts鐨勮嚜瀹氫箟鏂规硶 */ try { @@ -103,7 +119,6 @@ } catch (e) {} const [ { - ActionItem: nActionItem, EditOperation, GetCrudForm, KeyFieldValues, @@ -114,6 +129,7 @@ CreateAction, CustFunc, GetNewRow, + CustEditEnd, }, ] = isNullOrUnDef(custImport.value['default']) ? EntityCustFunction.value @@ -124,27 +140,40 @@ 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])) { @@ -169,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: [], @@ -181,7 +210,9 @@ emit('gettables', useTables); } } - }); + } + + const imgList = ['http://localhost:8800/files/Template/10浣嶆壒娆℃潯鐮�.png']; /** * @description: 鐢熸垚鍒楄〃涓搷浣滈」鐨勬寜閽� @@ -189,40 +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 = GenerateActionButton( - params, - buttons, - useDrawers[index][item.name][1].openDrawer, - useTables[item.name][1].reload(), - ); - if (isNullOrUnDef(custImport.value)) { - return 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 nActionItem( - params, - actionItem, - useDrawers[index][item.name][1].openDrawer, - useTables, - null, - useForm, - useModal, - go, - ); + return [ + { + label: '淇濆瓨', + onClick: handleSave.bind(null, record, index, item), + name: '', + }, + { + label: '鍙栨秷', + popConfirm: { + title: '鏄惁鍙栨秷缂栬緫', + confirm: handleCancel.bind(null, record, index, item), + }, + name: '', + }, + ]; } /** @@ -256,7 +292,7 @@ } 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, @@ -313,6 +349,7 @@ FnName: item.FnName, data: data, }; + /* 鑷畾涔夋柟娉� */ CustFunc(params); useTables[item.name][1].setProps({ dataSource: [], @@ -423,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