BaseModal.vue 3.9 KB

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