Commit 0169a6819a4e9f73bcb6425f847b0c38ea5ed2f0
Merge branch 'local_dev_ft' into 'main'
fix:DEFECT-1016 租户配置新增后就不允许编辑了 See merge request huang/yun-teng-iot-front!470
Showing
1 changed file
with
133 additions
and
108 deletions
| 1 | <template> | 1 | <template> |
| 2 | <div class="drawer-class"> | 2 | <div class="drawer-class"> |
| 3 | - <BasicDrawer v-bind="$attrs" @register="registerDrawer" showFooter :title="getTitle" width="700px" | ||
| 4 | - @ok="handleSubmit"> | 3 | + <BasicDrawer |
| 4 | + v-bind="$attrs" | ||
| 5 | + @register="registerDrawer" | ||
| 6 | + showFooter | ||
| 7 | + :title="getTitle" | ||
| 8 | + width="700px" | ||
| 9 | + @ok="handleSubmit" | ||
| 10 | + > | ||
| 5 | <BasicForm @register="registerForm" /> | 11 | <BasicForm @register="registerForm" /> |
| 6 | <CpnsTenantSet ref="getChildData" :parentData="parentSetData" /> | 12 | <CpnsTenantSet ref="getChildData" :parentData="parentSetData" /> |
| 7 | </BasicDrawer> | 13 | </BasicDrawer> |
| 8 | </div> | 14 | </div> |
| 9 | </template> | 15 | </template> |
| 10 | <script lang="ts"> | 16 | <script lang="ts"> |
| 11 | -import { defineComponent, ref, computed, unref, getCurrentInstance, reactive } from 'vue'; | ||
| 12 | -import { BasicForm, useForm } from '/@/components/Form'; | ||
| 13 | -import { formSchema } from './config'; | ||
| 14 | -import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; | ||
| 15 | -import CpnsTenantSet from './cpns/index.vue'; | ||
| 16 | -import { saveTenantProfileApi } from '/@/api/tenant/tenantApi'; | ||
| 17 | -import { useMessage } from '/@/hooks/web/useMessage'; | 17 | + import { defineComponent, ref, computed, unref, getCurrentInstance, reactive } from 'vue'; |
| 18 | + import { BasicForm, useForm } from '/@/components/Form'; | ||
| 19 | + import { formSchema } from './config'; | ||
| 20 | + import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; | ||
| 21 | + import CpnsTenantSet from './cpns/index.vue'; | ||
| 22 | + import { saveTenantProfileApi } from '/@/api/tenant/tenantApi'; | ||
| 23 | + import { useMessage } from '/@/hooks/web/useMessage'; | ||
| 18 | 24 | ||
| 19 | -export default defineComponent({ | ||
| 20 | - name: 'ConfigDrawer', | ||
| 21 | - components: { BasicDrawer, BasicForm, CpnsTenantSet }, | ||
| 22 | - emits: ['success', 'register'], | ||
| 23 | - setup(_, { emit }) { | ||
| 24 | - const { createMessage } = useMessage(); | ||
| 25 | - const isUpdate = ref(true); | ||
| 26 | - let postAllData: any = reactive({}); | ||
| 27 | - const parentSetData: any = ref(null); | ||
| 28 | - let getValuesFormData: any = reactive({}); | ||
| 29 | - const { proxy } = getCurrentInstance() as any; | ||
| 30 | - const getChildData = ref(null); | ||
| 31 | - const editGetId: any = ref(''); | ||
| 32 | - const [registerForm, { validate, resetFields, setFieldsValue }] = useForm({ | ||
| 33 | - schemas: formSchema, | ||
| 34 | - showActionButtonGroup: false, | ||
| 35 | - }); | ||
| 36 | - const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { | ||
| 37 | - //清除表单值 | ||
| 38 | - proxy.$refs.getChildData.funcResetFields(); | ||
| 39 | - await resetFields(); | ||
| 40 | - setDrawerProps({ confirmLoading: false }); | ||
| 41 | - isUpdate.value = !!data?.isUpdate; | ||
| 42 | - if (!unref(isUpdate)) { | ||
| 43 | - editGetId.value = ''; | ||
| 44 | - } | ||
| 45 | - //编辑 | ||
| 46 | - if (unref(isUpdate)) { | ||
| 47 | - parentSetData.value = { ...data.record.profileData.configuration }; | ||
| 48 | - proxy.$refs.getChildData.setFieldsValueFunc(parentSetData.value); | ||
| 49 | - editGetId.value = data.record.id; | ||
| 50 | - await setFieldsValue({ | ||
| 51 | - ...data.record, | ||
| 52 | - }); | ||
| 53 | - } | ||
| 54 | - }); | ||
| 55 | - const getTitle = computed(() => (!unref(isUpdate) ? '新增租户配置' : '编辑租户配置')); | 25 | + export default defineComponent({ |
| 26 | + name: 'ConfigDrawer', | ||
| 27 | + components: { BasicDrawer, BasicForm, CpnsTenantSet }, | ||
| 28 | + emits: ['success', 'register'], | ||
| 29 | + setup(_, { emit }) { | ||
| 30 | + const { createMessage } = useMessage(); | ||
| 31 | + const isUpdate = ref(true); | ||
| 32 | + let postAllData: any = reactive({}); | ||
| 33 | + const parentSetData: any = ref(null); | ||
| 34 | + let getValuesFormData: any = reactive({}); | ||
| 35 | + const { proxy } = getCurrentInstance() as any; | ||
| 36 | + const getChildData = ref(null); | ||
| 37 | + const editGetId: any = ref(''); | ||
| 38 | + const [registerForm, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({ | ||
| 39 | + schemas: formSchema, | ||
| 40 | + showActionButtonGroup: false, | ||
| 41 | + }); | ||
| 42 | + const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { | ||
| 43 | + //清除表单值 | ||
| 44 | + proxy.$refs.getChildData.funcResetFields(); | ||
| 45 | + await resetFields(); | ||
| 46 | + setDrawerProps({ confirmLoading: false }); | ||
| 47 | + isUpdate.value = !!data?.isUpdate; | ||
| 48 | + if (!unref(isUpdate)) { | ||
| 49 | + editGetId.value = ''; | ||
| 50 | + updateStatusSchema(false); | ||
| 51 | + } | ||
| 52 | + //编辑 | ||
| 53 | + if (unref(isUpdate)) { | ||
| 54 | + parentSetData.value = { ...data.record.profileData.configuration }; | ||
| 55 | + proxy.$refs.getChildData.setFieldsValueFunc(parentSetData.value); | ||
| 56 | + editGetId.value = data.record.id; | ||
| 57 | + await setFieldsValue({ | ||
| 58 | + ...data.record, | ||
| 59 | + }); | ||
| 60 | + updateStatusSchema(true); | ||
| 61 | + } | ||
| 62 | + }); | ||
| 63 | + const getTitle = computed(() => (!unref(isUpdate) ? '新增租户配置' : '编辑租户配置')); | ||
| 56 | 64 | ||
| 57 | - const getAllFieldsFunc = async () => { | ||
| 58 | - getValuesFormData = await validate(); | ||
| 59 | - if (!getValuesFormData) return; | ||
| 60 | - let getChildValues = proxy.$refs.getChildData.getAllFields(); | ||
| 61 | - let profileData1 = { | ||
| 62 | - configuration: getChildValues, | ||
| 63 | - }; | ||
| 64 | - const id: any = { | ||
| 65 | - id: unref(isUpdate) ? editGetId.value : '', | 65 | + const updateStatusSchema = (status) => { |
| 66 | + updateSchema([ | ||
| 67 | + { | ||
| 68 | + field: 'isolatedTbRuleEngine', | ||
| 69 | + componentProps: { | ||
| 70 | + disabled: status, | ||
| 71 | + }, | ||
| 72 | + }, | ||
| 73 | + { | ||
| 74 | + field: 'isolatedTbCore', | ||
| 75 | + componentProps: { | ||
| 76 | + disabled: status, | ||
| 77 | + }, | ||
| 78 | + }, | ||
| 79 | + ]); | ||
| 66 | }; | 80 | }; |
| 67 | 81 | ||
| 68 | - const createTime = { | ||
| 69 | - createdTime: Date.now(), | ||
| 70 | - }; | 82 | + const getAllFieldsFunc = async () => { |
| 83 | + getValuesFormData = await validate(); | ||
| 84 | + if (!getValuesFormData) return; | ||
| 85 | + let getChildValues = proxy.$refs.getChildData.getAllFields(); | ||
| 86 | + let profileData1 = { | ||
| 87 | + configuration: getChildValues, | ||
| 88 | + }; | ||
| 89 | + const id: any = { | ||
| 90 | + id: unref(isUpdate) ? editGetId.value : '', | ||
| 91 | + }; | ||
| 71 | 92 | ||
| 72 | - Object.assign( | ||
| 73 | - postAllData, | ||
| 74 | - { | ||
| 75 | - profileData: profileData1, | ||
| 76 | - }, | ||
| 77 | - getValuesFormData, | ||
| 78 | - id, | ||
| 79 | - createTime | ||
| 80 | - ); | ||
| 81 | - if (!unref(isUpdate)) { | ||
| 82 | - delete postAllData.id; | ||
| 83 | - } | ||
| 84 | - }; | 93 | + const createTime = { |
| 94 | + createdTime: Date.now(), | ||
| 95 | + }; | ||
| 85 | 96 | ||
| 86 | - async function handleSubmit() { | ||
| 87 | - setDrawerProps({ confirmLoading: true }); | ||
| 88 | - try { | 97 | + Object.assign( |
| 98 | + postAllData, | ||
| 99 | + { | ||
| 100 | + profileData: profileData1, | ||
| 101 | + }, | ||
| 102 | + getValuesFormData, | ||
| 103 | + id, | ||
| 104 | + createTime | ||
| 105 | + ); | ||
| 89 | if (!unref(isUpdate)) { | 106 | if (!unref(isUpdate)) { |
| 90 | - await getAllFieldsFunc(); | ||
| 91 | - await saveTenantProfileApi(postAllData); | ||
| 92 | - createMessage.success('租户配置新增成功'); | ||
| 93 | - closeDrawer(); | ||
| 94 | - emit('success'); | ||
| 95 | - resetFields(); | ||
| 96 | - } else { | ||
| 97 | - await getAllFieldsFunc(); | ||
| 98 | - await saveTenantProfileApi(postAllData); | ||
| 99 | - createMessage.success('租户配置编辑成功'); | ||
| 100 | - closeDrawer(); | ||
| 101 | - emit('success'); | 107 | + delete postAllData.id; |
| 108 | + } | ||
| 109 | + }; | ||
| 110 | + | ||
| 111 | + async function handleSubmit() { | ||
| 112 | + setDrawerProps({ confirmLoading: true }); | ||
| 113 | + try { | ||
| 114 | + if (!unref(isUpdate)) { | ||
| 115 | + await getAllFieldsFunc(); | ||
| 116 | + await saveTenantProfileApi(postAllData); | ||
| 117 | + createMessage.success('租户配置新增成功'); | ||
| 118 | + closeDrawer(); | ||
| 119 | + emit('success'); | ||
| 120 | + resetFields(); | ||
| 121 | + } else { | ||
| 122 | + await getAllFieldsFunc(); | ||
| 123 | + await saveTenantProfileApi(postAllData); | ||
| 124 | + createMessage.success('租户配置编辑成功'); | ||
| 125 | + closeDrawer(); | ||
| 126 | + emit('success'); | ||
| 127 | + } | ||
| 128 | + } catch (e) { | ||
| 129 | + } finally { | ||
| 130 | + setTimeout(() => { | ||
| 131 | + setDrawerProps({ confirmLoading: false }); | ||
| 132 | + }, 300); | ||
| 102 | } | 133 | } |
| 103 | - } catch (e) { | ||
| 104 | - } finally { | ||
| 105 | - setTimeout(() => { | ||
| 106 | - setDrawerProps({ confirmLoading: false }); | ||
| 107 | - }, 300); | ||
| 108 | } | 134 | } |
| 109 | - } | ||
| 110 | - return { | ||
| 111 | - parentSetData, | ||
| 112 | - getChildData, | ||
| 113 | - registerDrawer, | ||
| 114 | - registerForm, | ||
| 115 | - getTitle, | ||
| 116 | - handleSubmit, | ||
| 117 | - }; | ||
| 118 | - }, | ||
| 119 | -}); | 135 | + return { |
| 136 | + parentSetData, | ||
| 137 | + getChildData, | ||
| 138 | + registerDrawer, | ||
| 139 | + registerForm, | ||
| 140 | + getTitle, | ||
| 141 | + handleSubmit, | ||
| 142 | + }; | ||
| 143 | + }, | ||
| 144 | + }); | ||
| 120 | </script> | 145 | </script> |
| 121 | 146 | ||
| 122 | <style lang="less"> | 147 | <style lang="less"> |
| 123 | -.drawer-class { | ||
| 124 | - .ant-row { | ||
| 125 | - .ant-col { | ||
| 126 | - :deep .ant-input-number { | ||
| 127 | - width: 34vw !important; | 148 | + .drawer-class { |
| 149 | + .ant-row { | ||
| 150 | + .ant-col { | ||
| 151 | + :deep .ant-input-number { | ||
| 152 | + width: 34vw !important; | ||
| 153 | + } | ||
| 128 | } | 154 | } |
| 129 | } | 155 | } |
| 130 | } | 156 | } |
| 131 | -} | ||
| 132 | </style> | 157 | </style> |