BaseModal.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. await getDevicePointList(data.record['deviceId'])
  56. devicePointList.value.forEach(item => {
  57. if (item['id'] == pointData.value) {
  58. setPoint([item])
  59. }
  60. })
  61. // 初始打开有数据时候要查点表
  62. } else if (data.record) {
  63. await setFieldsValue({ relId: data.record['relId'] || data.record['id'], monitorId: '' });
  64. }
  65. });
  66. const [registerModal, { openModal }] = useModal();
  67. async function getDevicePointList(strtype) {
  68. try {
  69. const result = await workFacePointList({ deviceType: strtype, valueType: props.monitorType });
  70. devicePointList.value = result
  71. } catch (error) {
  72. devicePointList.value = []
  73. }
  74. };
  75. async function onSubmit() {
  76. try {
  77. const data = await getFieldsValue()
  78. await setFieldsValue({ ...data, monitorId: pointData.value[0] })
  79. const values = await validate();
  80. setModalProps({ confirmLoading: true });
  81. // 提交表单
  82. if (!isUpdate.value) {
  83. emit('add', 'add', values)
  84. } else {
  85. emit('update', 'update', values)
  86. }
  87. // //关闭弹窗
  88. // closeModal();
  89. // //刷新列表
  90. // reload()
  91. } finally {
  92. setModalProps({ confirmLoading: false });
  93. }
  94. }
  95. async function selectPoint(strtype) {
  96. if (strtype) {
  97. await getDevicePointList(strtype)
  98. openModal()
  99. } else {
  100. message.info('请先选择设备!')
  101. }
  102. }
  103. function setPoint(value) {
  104. const data = value[0]
  105. option.value = [
  106. {
  107. value: data.id,
  108. label: data.valuename
  109. }
  110. ]
  111. nextTick(() => {
  112. pointData.value = [data.id]
  113. })
  114. }
  115. onMounted(async () => {
  116. });
  117. </script>
  118. <style scoped lang="less"></style>