DeviceModal.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="registerModal"
  5. :title="title"
  6. width="1000px"
  7. :showCancelBtn="false"
  8. :showOkBtn="false"
  9. :footer="null"
  10. destroyOnClose
  11. >
  12. <a-tabs v-if="isEditParent" v-model:activeKey="activeKey" @change="changeTab">
  13. <a-tab-pane key="1" tab="基本信息" force-render>
  14. <FormModal v-if="activeKey == '1'" :record="record" :formSchema="formSchema" @saveOrUpdate="saveOrUpdate" />
  15. </a-tab-pane>
  16. <a-tab-pane key="2" tab="密码设置" force-render>
  17. <FormModal v-if="activeKey == '2'" :record="passwordRecord" :formSchema="passwordFormSchema" @saveOrUpdate="savePassword" />
  18. </a-tab-pane>
  19. </a-tabs>
  20. <FormModal v-else :record="record" :formSchema="formSchema" @saveOrUpdate="saveOrUpdate" />
  21. </BasicModal>
  22. </template>
  23. <script lang="ts" setup>
  24. import { ref, onMounted, reactive } from 'vue';
  25. import { BasicModal, useModalInner } from '/@/components/Modal';
  26. import FormModal from './FormModal.vue';
  27. import { formSchema, passwordFormSchema } from '../equip.data.ts';
  28. import { passwordList, editPassword } from '../equip.api.ts'
  29. // 声明Emits
  30. const emit = defineEmits(['saveOrUpdate', 'register']);
  31. const title = ref('')
  32. const record = ref({})
  33. const passwordRecord = ref({})
  34. const isEditParent = ref(false)
  35. const activeKey = ref('1')
  36. //表单赋值
  37. const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  38. //重置表单
  39. setModalProps({ confirmLoading: true });
  40. if(data.record){
  41. title.value = '编辑'
  42. record.value = data.record
  43. if(data.record['itemValue'].split('_')[1]){
  44. isEditParent.value = false
  45. }else{
  46. isEditParent.value = true
  47. // 查询密码record
  48. const result = await passwordList({ devicekind: data.record['itemValue']})
  49. passwordRecord.value = Object.assign(result, { itemText: data.record['itemText'], devicekind: data.record['itemValue'] })
  50. }
  51. }else{
  52. title.value = '新增'
  53. record.value = {}
  54. isEditParent.value = false
  55. }
  56. setModalProps({ confirmLoading: false });
  57. });
  58. function changeTab(key) {
  59. if(key == '2' && !record.value['itemValue']){
  60. activeKey.value = '1'
  61. }
  62. }
  63. function saveOrUpdate(record) {
  64. emit('saveOrUpdate', record)
  65. }
  66. function savePassword(data) {
  67. editPassword(data)
  68. }
  69. </script>
  70. <style scoped lang="less">
  71. ::v-deep .suffix {
  72. height: 32px;
  73. line-height: 32px;
  74. margin-left: 5px;
  75. color: #fff;
  76. }
  77. </style>