| | |
| | | * @version: |
| | | * @Date: 2024-06-18 15:09:48 |
| | | * @LastEditors: Ben Lin |
| | | * @LastEditTime: 2024-07-02 03:42:25 |
| | | * @LastEditTime: 2024-07-15 22:23:12 |
| | | --> |
| | | <!-- |
| | | * _oo0oo_ |
| | |
| | | @back="goBack" |
| | | > |
| | | <Suspense> |
| | | <baseForm /> |
| | | <baseForm :entityName="entityName" /> |
| | | </Suspense> |
| | | <!-- <a-card :title="titleInfo['baseTableTitle']" :bordered="false" class="!mt-5"> --> |
| | | <Suspense> |
| | | <dtl :entityName="entityName" /> |
| | | </Suspense> |
| | | <Suspense> |
| | | <dtl :entityName="entityName" @search="dtlFormSearch" /> |
| | | </Suspense> |
| | | <!-- </a-card> --> |
| | | <a-card |
| | | :title="item.title" |
| | |
| | | <a-button class="mr-4" type="info" @click="cancel"> 取消 </a-button> |
| | | <a-button type="primary" @click="submitAll"> 提交 </a-button> |
| | | </template> |
| | | <CustModal |
| | | @register="registerCust" |
| | | @success="custSuccess" |
| | | :type="cType" |
| | | :detailSlots="dtlSlots" |
| | | > |
| | | <!-- 用插槽自定义多表单 --> |
| | | <template #[item.name] v-for="item in dtlSlots" :key="item.name"> |
| | | <BasicForm @register="useFormData[item.name][0]" v-if="useFormData[item.name]"> |
| | | <!-- 用插槽自定义弹出选择框 --> |
| | | <template #[name]="{ field }" v-for="name in item.slots" :key="name"> |
| | | <a-button |
| | | class="mt-1 ml-1" |
| | | size="small" |
| | | @click="handleCustClick(field)" |
| | | :preIcon="item.preIcons[name]" |
| | | /> |
| | | <GeneralModal |
| | | @register="useModalData[name][0]" |
| | | @success="(d, u) => handleEntSuccess(d, u, item.name)" |
| | | /> |
| | | </template> |
| | | </BasicForm> |
| | | <!-- 自定义内容 --> |
| | | </template> |
| | | </CustModal> |
| | | <Suspense> |
| | | <CustModal |
| | | @register="registerCust" |
| | | @success="custSuccess" |
| | | :type="cType" |
| | | :detailSlots="dtlSlots" |
| | | :entityName="entityName" |
| | | > |
| | | <!-- 用插槽自定义多表单 --> |
| | | <template #[item.name] v-for="item in dtlSlots" :key="item.name"> |
| | | <BasicForm @register="useFormData[item.name][0]" v-if="useFormData[item.name]"> |
| | | <!-- 用插槽自定义弹出选择框 --> |
| | | <template #[name]="{ field }" v-for="name in item.slots" :key="name"> |
| | | <a-button |
| | | class="mt-1 ml-1" |
| | | size="small" |
| | | @click="handleCustClick(field)" |
| | | :preIcon="item.preIcons[name]" |
| | | /> |
| | | <GeneralModal |
| | | @register="useModalData[name][0]" |
| | | @success="(d, u) => handleEntSuccess(d, u, item.name)" |
| | | /> |
| | | </template> |
| | | </BasicForm> |
| | | <!-- 自定义内容 --> |
| | | </template> |
| | | </CustModal> |
| | | </Suspense> |
| | | </PageWrapper> |
| | | </template> |
| | | <script lang="ts" setup> |
| | |
| | | import dtl from './dtl.vue'; |
| | | import baseForm from './baseForm.vue'; |
| | | import GeneralModal from '/@/views/components/GeneralModal.vue'; |
| | | import { AddListEntity, DeleteWhere, SaveEntity, getEntity } from '/@/api/tigerapi/system'; |
| | | import { AddAfterDelete, SaveEntity } from '/@/api/tigerapi/system'; |
| | | import { useGlobSetting } from '/@/hooks/setting'; |
| | | import { useRoute, useRouter } from 'vue-router'; |
| | | import CustModal from '/@/views/components/CustModal.vue'; |
| | |
| | | import { buildUUID } from '/@/utils/uuid'; |
| | | import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is'; |
| | | import { useI18n } from '/@/hooks/web/useI18n'; |
| | | import { Reactified } from '@vueuse/core'; |
| | | import { isFunction } from 'xe-utils'; |
| | | |
| | | const { t } = useI18n(); |
| | | |
| | |
| | | return tabStore.getTabList.find((item) => item.fullPath === route.fullPath)!; |
| | | } |
| | | const currentTab = getCurrentTab(); |
| | | const objParams = ref(JSON.parse(decodeURI(route.params?.id as string))); |
| | | const routeParams = ref(JSON.parse(decodeURI(route.params?.id as string))); |
| | | const entityName = ref(routeParams.value.Name); |
| | | // 从sessionStorage中读取参数并转换回对象 |
| | | const savedParams = sessionStorage.getItem(`${routeParams.value.sName}_params`); |
| | | const objParams = savedParams ? ref(JSON.parse(decodeURI(savedParams))) : ref({}); |
| | | const titleInfo = ref({}); //getTitle(objParams.value.Name); |
| | | const entityName = ref(objParams.value.Name); |
| | | const isAllUpdate = ref(objParams.value.CODE != '0'); |
| | | const globSetting = useGlobSetting(); |
| | | const formSchemas = ref({}); //弹出框或高级页面多表单结构 |
| | |
| | | const otherCards = ref([] as any[]); |
| | | const isMounted = ref(false); |
| | | const custImport = ref<any[]>([]); |
| | | const others = ref<any>(null); |
| | | const keyFieldValues = ref<any>(null); |
| | | const data = ref<any>({}); |
| | | for(const i in objParams.value['drawers']){ |
| | | const useTables = ref<any>({}); |
| | | for (const i in objParams.value['drawers']) { |
| | | data.value[objParams.value['drawers'][i]['name']] = ref<Recordable[]>([]); |
| | | } |
| | | provide<Ref<any>>('objParams', objParams.value); |
| | | provide<Ref<any>>('objParams', objParams); |
| | | provide<Ref<any>>('data', data); |
| | | provide<Ref<any>>('others', others); |
| | | provide<Ref<any>>('keyFieldValues', keyFieldValues); |
| | | provide<Ref<{}>>('useFormData', useFormData); |
| | | provide<Ref<any>>('baseCards', baseCards); |
| | | provide<Ref<any>>('useTables', useTables); |
| | | |
| | | const [registerCust, { openModal: openCustomModal, closeModal }] = useModal(); |
| | | const { setTitle } = useTabs(); |
| | |
| | | /* 动态import实体名.ts的自定义方法 */ |
| | | try { |
| | | custImport.value = await import(`../entityts/${entityName.value}.ts`); |
| | | const [{GetTitle}] = custImport.value['default'](); |
| | | const [{ GetTitle }] = custImport.value['default'](); |
| | | titleInfo.value = GetTitle(); |
| | | } catch (e) {} |
| | | isMounted.value = true; |
| | |
| | | * @description: 异步全部提交方法 |
| | | * @return {*} |
| | | */ |
| | | function submitAll() { |
| | | async function submitAll() { |
| | | try { |
| | | validate().then((res) => { |
| | | const Keys = Object.getOwnPropertyNames(useFormData.value); |
| | | let i; |
| | | let p = [] as Promise<any>[]; |
| | | for (i = 0; i < Keys.length; i++) { |
| | | p.push(SaveEntity(res[Keys[i]], unref(isAllUpdate), baseCards.value[i]['entityName'])); |
| | | } |
| | | Promise.all(p).then((action) => { |
| | | DeleteWhere( |
| | | ` ${objParams.value.pCode} = '${others.value[objParams.value.pCode]}'`, |
| | | entityName.value, |
| | | ).then((res) => { |
| | | if (res.IsSuccessed) { |
| | | data.value.forEach((item) => { |
| | | item.ID = buildUUID(); |
| | | }); |
| | | AddListEntity(data.value, entityName.value).then((action) => { |
| | | if (action.IsSuccessed) { |
| | | cancel(); |
| | | } |
| | | }); |
| | | const validates = await validate(); |
| | | const Keys = Object.getOwnPropertyNames(useFormData.value); |
| | | let i; |
| | | let p = [] as Promise<any>[]; |
| | | for (i = 0; i < Keys.length; i++) { |
| | | p.push( |
| | | SaveEntity( |
| | | validates[Keys[i]], |
| | | unref(isAllUpdate), |
| | | baseCards.value[i]['entityName'], |
| | | `${objParams.value['IsExist']}='${validates[Keys[i]][objParams.value['IsExist']]}'`, |
| | | true, |
| | | ), |
| | | ); |
| | | } |
| | | await Promise.all(p); |
| | | if ( |
| | | !custImport.value['default']()[0].SubmitAll && |
| | | !isFunction(custImport.value['default']()[0].SubmitAll) |
| | | ) { |
| | | /* 默认提交 */ |
| | | objParams.value['drawers'].forEach((d) => { |
| | | let where = `${d['code']} = '${keyFieldValues.value[d['code']]}'`; |
| | | /* type: all-表示需要code的所有的值 */ |
| | | if (d['type'] == 'all' && data.value[d['keyName']].length > 0) { |
| | | where = `${d['code']} in (${data.value[d['keyName']].map((value) => `'${value[d['code']]}'`).join(',')})`; |
| | | } |
| | | /* 如果高级表单中关联的是ID(IsID == true),则不用初始化ID */ |
| | | if (!objParams.value['IsID']) { |
| | | data.value[d['name']].map((item) => { |
| | | item.ID = buildUUID(); |
| | | }); |
| | | } |
| | | AddAfterDelete(d['name'], data.value[d['name']], where).then((action) => { |
| | | if (action.IsSuccessed) { |
| | | cancel(); |
| | | } |
| | | }); |
| | | }); |
| | | }); |
| | | // values.ID = params.RULE_ID; |
| | | // const action = await SaveRule({ ...values, ...testValues }); |
| | | // if (action.IsSuccessed) { |
| | | // await DeleteRuleDtl(params.RULE_ID); |
| | | // const dtlAction = await SaveRuleDtl(data.value); |
| | | // if (dtlAction.IsSuccessed) { |
| | | // cancel(); |
| | | // } |
| | | // } |
| | | } else { |
| | | /* 如果自定义提交方法存在就用自定义提交 */ |
| | | custImport.value['default']()[0].SubmitAll(data, keyFieldValues, cancel); |
| | | } |
| | | } catch (error) {} |
| | | } |
| | | async function cancel() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description: 表格查询回调,根据对应子组件中表格的查询按钮提交事件转入动态调用的实体名方法去执行对应的查询逻辑,返回后刷新数据 |
| | | * @param {*} d |
| | | * @return {*} |
| | | */ |
| | | function dtlFormSearch(d) { |
| | | try { |
| | | var values = useTables.value[d.type][1].getForm().getFieldsValue(); |
| | | let data = custImport.value['default']()[0].FormSearch({ ...d, ...{ values: values } }); |
| | | useTables.value[d.type][1].setProps({ |
| | | dataSource: [], |
| | | }); |
| | | useTables.value[d.type][1].setProps({ |
| | | dataSource: data, |
| | | }); |
| | | useTables.value[d.type][1].reload(); |
| | | } catch (e) {} |
| | | } |
| | | |
| | | /** |
| | | * @description: Select 自定义onChange方法 |
| | | * @param {*} obj |
| | | * @return {*} |