BaseModal.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <BasicModal @register="register" :title="title" :width="800" :min-height="600" v-bind="$attrs" @ok="onSubmit">
  3. <BasicForm @register="registerForm">
  4. <template #monitor="{ model, field }">
  5. <div class="vent-flex-row-between">
  6. <Select ref="selectRef" disabled v-model:value="pointData" :options="option"
  7. style="width: calc(100% - 65px);" />
  8. <a-button class="vent-margin-b-5" type="primary" @click="selectPoint(model['strtype'])"
  9. style="position: absolute; right: 0; top: 1px;">选择</a-button>
  10. </div>
  11. </template>
  12. </BasicForm>
  13. </BasicModal>
  14. <DevicePointTable @register="registerModal" :data-source="devicePointList" :selection-row-keys="pointData"
  15. @reload="setPoint" />
  16. </template>
  17. <script lang="ts" setup>
  18. import { onMounted, ref, defineEmits, unref, nextTick } from 'vue';
  19. import { BasicForm, useForm } from '/@/components/Form/index';
  20. import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
  21. import type { FormSchema } from '/@/components/Form/src/types/form';
  22. import { Select, message } from 'ant-design-vue';
  23. import DevicePointTable from './DevicePointTable.vue';
  24. import { workFacePointList } from './warning.api'
  25. const props = defineProps({
  26. formSchemas: {
  27. type: Array as PropType<FormSchema[]>,
  28. default: () => ([]),
  29. },
  30. deviceId: { type: String },
  31. monitorType: {
  32. type: String,
  33. default: '2'
  34. }
  35. })
  36. const emit = defineEmits(['add', 'update', 'register'])
  37. const option = ref<any[]>([])
  38. const devicePointList = ref<any[]>([])
  39. const pointData = ref<String[]>([])
  40. const title = ref('')
  41. const isUpdate = ref(false)
  42. // 注册 form
  43. const [registerForm, { resetFields, setFieldsValue, validate, getFieldsValue }] = useForm({
  44. schemas: props.formSchemas,
  45. showActionButtonGroup: false,
  46. });
  47. // 注册 modal
  48. const [register, { setModalProps }] = useModalInner(async (data) => {
  49. isUpdate.value = unref(data.isUpdate);
  50. title.value = unref(data.title);
  51. await resetFields();
  52. if (data.isUpdate) {
  53. await setFieldsValue({ ...data.record });
  54. pointData.value = [data.record['monitorId']]
  55. debugger
  56. await getDevicePointList(data.record['deviceId'])
  57. devicePointList.value.forEach(item => {
  58. if (item['id'] == pointData.value) {
  59. setPoint([item])
  60. }
  61. })
  62. // 初始打开有数据时候要查点表
  63. } else if (data.record) {
  64. await setFieldsValue({ relId: data.record['relId'] || data.record['id'], monitorId: '' });
  65. }
  66. });
  67. const [registerModal, { openModal }] = useModal();
  68. async function getDevicePointList(strtype) {
  69. try {
  70. const result = await workFacePointList({ deviceType: strtype, valueType: props.monitorType });
  71. devicePointList.value = result
  72. } catch (error) {
  73. devicePointList.value = []
  74. }
  75. };
  76. async function onSubmit() {
  77. try {
  78. const data = await getFieldsValue()
  79. await setFieldsValue({ ...data, monitorId: pointData.value[0] })
  80. const values = await validate();
  81. setModalProps({ confirmLoading: true });
  82. debugger
  83. // 提交表单
  84. if (!isUpdate.value) {
  85. emit('add', 'add', values)
  86. } else {
  87. emit('update', 'update', values)
  88. }
  89. // //关闭弹窗
  90. // closeModal();
  91. // //刷新列表
  92. // reload()
  93. } finally {
  94. setModalProps({ confirmLoading: false });
  95. }
  96. }
  97. async function selectPoint(strtype) {
  98. if (strtype) {
  99. await getDevicePointList(strtype)
  100. openModal()
  101. } else {
  102. message.info('请先选择设备!')
  103. }
  104. }
  105. function setPoint(value) {
  106. const data = value[0]
  107. option.value = [
  108. {
  109. value: data.id,
  110. label: data.valuename
  111. }
  112. ]
  113. nextTick(() => {
  114. pointData.value = [data.id]
  115. })
  116. }
  117. onMounted(async () => {
  118. });
  119. </script>
  120. <style scoped lang="less"></style>