BaseModal.vue 3.5 KB

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