BaseModal1.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <BasicModal @register="register" :title="title" :width="800" :min-height="400" 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. // debugger
  55. // 初始打开有数据时候要查点表
  56. // await getDevicePointList(data.record['deviceId'])
  57. // devicePointList.value.forEach(item => {
  58. // if(item['id'] == pointData.value){
  59. // setPoint([item])
  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. </script>
  117. <style scoped lang="less"></style>