DeviceModal.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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="true"
  11. :mask-closable="false"
  12. @cancel="closeModalFn"
  13. >
  14. <FormModal :record="record" @saveOrUpdate="(values) => emit('saveOrUpdate', values)" />
  15. </BasicModal>
  16. </template>
  17. <script lang="ts" setup>
  18. import { computed, unref, inject, reactive, ref, watch } from 'vue';
  19. import { BasicModal, useModalInner } from '/@/components/Modal';
  20. import FormModal from './FormModal.vue';
  21. const props = defineProps({
  22. showTab: { type: Boolean, required: true },
  23. });
  24. // 声明Emits
  25. const emit = defineEmits(['saveOrUpdate', 'register', 'closeModal']);
  26. const isUpdate = inject('isUpdate');
  27. const deviceData = inject('formData') as any;
  28. const record = reactive({});
  29. const activeKey = ref('1');
  30. //表单赋值
  31. const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  32. //重置表单
  33. setModalProps({ confirmLoading: false });
  34. Object.assign(deviceData, data.record);
  35. // 判断是否是关键阻力路线
  36. });
  37. //设置标题
  38. const title = computed(() => {
  39. if (!unref(isUpdate)) {
  40. if (deviceData.strname || deviceData.systemname) {
  41. return `新增(${deviceData.strname || deviceData.systemname})`;
  42. }
  43. return `新增`;
  44. } else {
  45. return `编辑`;
  46. }
  47. });
  48. const closeModalFn = () => {
  49. activeKey.value = '1';
  50. closeModal();
  51. emit('closeModal');
  52. };
  53. </script>
  54. <style scoped lang="less">
  55. ::v-deep .suffix {
  56. height: 32px;
  57. line-height: 32px;
  58. margin-left: 5px;
  59. color: #fff;
  60. }
  61. </style>