Commit 04c4d5efc9e3dbe3e82e1b08696574acf1867a70

Authored by 黄 x
1 parent 20bdaf98

fix(front): 添加设备配置分步操作

@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 width="500px" 7 width="500px"
8 @ok="handleSubmit" 8 @ok="handleSubmit"
9 > 9 >
10 - <BasicForm @register="registerForm" /> 10 + <BasicForm @register="registerForm"/>
11 </BasicDrawer> 11 </BasicDrawer>
12 </template> 12 </template>
13 <script lang="ts"> 13 <script lang="ts">
@@ -15,8 +15,8 @@ @@ -15,8 +15,8 @@
15 import { BasicForm, useForm } from '/@/components/Form'; 15 import { BasicForm, useForm } from '/@/components/Form';
16 import { formSchema } from './device.profile.data'; 16 import { formSchema } from './device.profile.data';
17 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; 17 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
18 - import { saveOrEditMessageConfig } from '/@/api/message/config';  
19 - import { useMessage } from '/@/hooks/web/useMessage'; 18 + import { saveOrEditMessageConfig } from "/@/api/message/config";
  19 + import { useMessage } from "/@/hooks/web/useMessage";
20 20
21 export default defineComponent({ 21 export default defineComponent({
22 name: 'DeviceProfileDrawer', 22 name: 'DeviceProfileDrawer',
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 setup(_, { emit }) { 25 setup(_, { emit }) {
26 const isUpdate = ref(true); 26 const isUpdate = ref(true);
27 27
28 - const [registerForm, { validate, setFieldsValue, resetFields }] = useForm({ 28 + const [registerForm, { validate,setFieldsValue,resetFields }] = useForm({
29 labelWidth: 120, 29 labelWidth: 120,
30 schemas: formSchema, 30 schemas: formSchema,
31 showActionButtonGroup: false, 31 showActionButtonGroup: false,
@@ -37,8 +37,8 @@ @@ -37,8 +37,8 @@
37 isUpdate.value = !!data?.isUpdate; 37 isUpdate.value = !!data?.isUpdate;
38 if (unref(isUpdate)) { 38 if (unref(isUpdate)) {
39 const config = data.record.config; 39 const config = data.record.config;
40 - for (const key in config) {  
41 - Reflect.set(data.record, key + '', config[key]); 40 + for (const key in config){
  41 + Reflect.set(data.record, key+'', config[key]);
42 } 42 }
43 await setFieldsValue({ 43 await setFieldsValue({
44 ...data.record, 44 ...data.record,
@@ -53,27 +53,27 @@ @@ -53,27 +53,27 @@
53 const values = await validate(); 53 const values = await validate();
54 const { createMessage } = useMessage(); 54 const { createMessage } = useMessage();
55 setDrawerProps({ confirmLoading: true }); 55 setDrawerProps({ confirmLoading: true });
56 - let config = {};  
57 - if (values.messageType === 'PHONE_MESSAGE') {  
58 - config = {  
59 - accessKeyId: values.accessKeyId,  
60 - accessKeySecret: values.accessKeySecret,  
61 - };  
62 - } else if (values.messageType === 'EMAIL_MESSAGE') {  
63 - config = {  
64 - host: values.host,  
65 - port: values.port,  
66 - username: values.username,  
67 - password: values.password,  
68 - }; 56 + let config={};
  57 + if(values.messageType === 'PHONE_MESSAGE'){
  58 + config ={
  59 + "accessKeyId":values.accessKeyId,
  60 + "accessKeySecret":values.accessKeySecret,
  61 + }
  62 + }else if(values.messageType === 'EMAIL_MESSAGE'){
  63 + config ={
  64 + "host":values.host,
  65 + "port":values.port,
  66 + "username":values.username,
  67 + "password":values.password,
  68 + }
69 } 69 }
70 Reflect.set(values, 'config', config); 70 Reflect.set(values, 'config', config);
71 - let saveMessage = '添加成功';  
72 - let updateMessage = '修改成功'; 71 + let saveMessage = "添加成功";
  72 + let updateMessage = "修改成功";
73 await saveOrEditMessageConfig(values, unref(isUpdate)); 73 await saveOrEditMessageConfig(values, unref(isUpdate));
74 closeDrawer(); 74 closeDrawer();
75 emit('success'); 75 emit('success');
76 - createMessage.success(unref(isUpdate) ? updateMessage : saveMessage); 76 + createMessage.success(unref(isUpdate)?updateMessage:saveMessage);
77 } finally { 77 } finally {
78 setDrawerProps({ confirmLoading: false }); 78 setDrawerProps({ confirmLoading: false });
79 } 79 }
  1 +<template>
  2 + <BasicModal
  3 + v-bind="$attrs"
  4 + width="55rem"
  5 + @register="register"
  6 + :title=getTitle
  7 + @visible-change="handleVisibleChange"
  8 + >
  9 + <div class="step-form-form">
  10 + <a-steps :current="current">
  11 + <a-step title="设备配置" />
  12 + <a-step title="传输配置" />
  13 + <a-step title="告警配置" />
  14 + </a-steps>
  15 + </div>
  16 + <div class="mt-5">
  17 + <DeviceProfileStep1 @next="handleStep1Next" v-show="current === 0" />
  18 + <DeviceProfileStep2
  19 + @prev="handleStepPrev"
  20 + @next="handleStep2Next"
  21 + v-show="current === 1"
  22 + v-if="initStep2"
  23 + />
  24 + <DeviceProfileStep3 v-show="current === 2" @redo="handleRedo" v-if="initStep3" />
  25 + </div>
  26 + </BasicModal>
  27 +</template>
  28 +<script lang="ts">
  29 + import { defineComponent, ref, nextTick, computed, unref, reactive, toRefs} from 'vue';
  30 + import { BasicModal, useModalInner } from '/@/components/Modal';
  31 + import { BasicForm, FormSchema, useForm } from '/@/components/Form';
  32 + import DeviceProfileStep1 from "/@/views/device/profile/step/DeviceProfileStep1.vue";
  33 + import DeviceProfileStep2 from "/@/views/device/profile/step/DeviceProfileStep2.vue";
  34 + import DeviceProfileStep3 from "/@/views/device/profile/step/DeviceProfileStep3.vue";
  35 + import { Steps } from "ant-design-vue";
  36 + const schemas: FormSchema[] = [
  37 + {
  38 + field: 'field1',
  39 + component: 'Input',
  40 + label: '字段1',
  41 + colProps: {
  42 + span: 24,
  43 + },
  44 + defaultValue: '111',
  45 + },
  46 + {
  47 + field: 'field2',
  48 + component: 'Input',
  49 + label: '字段2',
  50 + colProps: {
  51 + span: 24,
  52 + },
  53 + },
  54 + ];
  55 + export default defineComponent({
  56 + name:'DeviceModal',
  57 + components: { BasicModal, BasicForm, DeviceProfileStep1, DeviceProfileStep2, DeviceProfileStep3,
  58 + [Steps.name]: Steps,
  59 + [Steps.Step.name]: Steps.Step, },
  60 + props: {
  61 + userData: { type: Object },
  62 + },
  63 + setup(props) {
  64 + const state = reactive({
  65 + initStep2: false,
  66 + initStep3: false,
  67 + });
  68 + const current = ref(0);
  69 + const isUpdate = ref(true);
  70 + const modelRef = ref({});
  71 + const getTitle = computed(() => (!unref(isUpdate) ? '新增设备配置' : '编辑设备配置'));
  72 + const [
  73 + registerForm,
  74 + {
  75 + // setFieldsValue,
  76 + // setProps
  77 + },
  78 + ] = useForm({
  79 + labelWidth: 120,
  80 + schemas,
  81 + showActionButtonGroup: false,
  82 + actionColOptions: {
  83 + span: 24,
  84 + },
  85 + });
  86 +
  87 + const [register] = useModalInner((data) => {
  88 + isUpdate.value = !!data?.isUpdate;
  89 + data && onDataReceive(data);
  90 + });
  91 +
  92 + function handleStepPrev() {
  93 + current.value--;
  94 + }
  95 + function handleStep1Next(step1Values: any) {
  96 + current.value++;
  97 + state.initStep2 = true;
  98 + console.log(step1Values);
  99 + }
  100 + function handleStep2Next(step2Values: any) {
  101 + current.value++;
  102 + state.initStep3 = true;
  103 + console.log(step2Values);
  104 + }
  105 + function handleRedo() {
  106 + current.value = 0;
  107 + state.initStep2 = false;
  108 + state.initStep3 = false;
  109 + }
  110 +
  111 +
  112 + function onDataReceive(data) {
  113 + console.log('Data Received', data);
  114 + // 方式1;
  115 + // setFieldsValue({
  116 + // field2: data.data,
  117 + // field1: data.info,
  118 + // });
  119 +
  120 + // // 方式2
  121 + modelRef.value = { field2: data.data, field1: data.info };
  122 +
  123 + // setProps({
  124 + // model:{ field2: data.data, field1: data.info }
  125 + // })
  126 + }
  127 +
  128 + function handleVisibleChange(v) {
  129 + v && props.userData && nextTick(() => onDataReceive(props.userData));
  130 + }
  131 +
  132 + return { register, schemas, registerForm, model: modelRef, getTitle,handleVisibleChange,
  133 + current, ...toRefs(state), handleStepPrev, handleStep1Next, handleStep2Next, handleRedo};
  134 + },
  135 + });
  136 +</script>
@@ -8,40 +8,40 @@ @@ -8,40 +8,40 @@
8 <TableAction 8 <TableAction
9 :actions="[ 9 :actions="[
10 { 10 {
11 - label: '编辑', 11 + label:'编辑',
12 icon: 'clarity:note-edit-line', 12 icon: 'clarity:note-edit-line',
13 onClick: handleEdit.bind(null, record), 13 onClick: handleEdit.bind(null, record),
14 }, 14 },
15 { 15 {
16 - label: '删除', 16 + label:'删除',
17 icon: 'ant-design:delete-outlined', 17 icon: 'ant-design:delete-outlined',
18 color: 'error', 18 color: 'error',
19 popConfirm: { 19 popConfirm: {
20 title: '是否确认删除', 20 title: '是否确认删除',
21 confirm: handleDelete.bind(null, record), 21 confirm: handleDelete.bind(null, record),
22 - }, 22 + }
23 }, 23 },
24 ]" 24 ]"
25 /> 25 />
26 </template> 26 </template>
27 </BasicTable> 27 </BasicTable>
28 - <DeviceProfileDrawer @register="registerDrawer" @success="handleSuccess" /> 28 + <DeviceProfileModal @register="registerModal" @success="handleSuccess"/>
29 </div> 29 </div>
30 </template> 30 </template>
31 <script lang="ts"> 31 <script lang="ts">
32 import { defineComponent } from 'vue'; 32 import { defineComponent } from 'vue';
33 import { BasicTable, useTable, TableAction } from '/@/components/Table'; 33 import { BasicTable, useTable, TableAction } from '/@/components/Table';
34 - import { useDrawer } from '/@/components/Drawer';  
35 - import DeviceProfileDrawer from './DeviceProfile.vue';  
36 import { columns, searchFormSchema } from './device.profile.data'; 34 import { columns, searchFormSchema } from './device.profile.data';
37 - import { useMessage } from '/@/hooks/web/useMessage';  
38 - import { deviceProfilePage, deleteDeviceProfile } from '/@/api/device/deviceManager'; 35 + import { useMessage } from "/@/hooks/web/useMessage";
  36 + import { deviceProfilePage, deleteDeviceProfile } from "/@/api/device/deviceManager";
  37 + import { useModal } from "/@/components/Modal";
  38 + import DeviceProfileModal from "/@/views/device/profile/DeviceProfileModal.vue";
39 export default defineComponent({ 39 export default defineComponent({
40 name: 'DeviceProfileManagement', 40 name: 'DeviceProfileManagement',
41 - components: { BasicTable, DeviceProfileDrawer, TableAction }, 41 + components: { BasicTable, DeviceProfileModal, TableAction},
42 setup() { 42 setup() {
43 - const [registerDrawer, { openDrawer }] = useDrawer();  
44 - const { createMessage } = useMessage(); 43 + const {createMessage} = useMessage();
  44 + const [registerModal, { openModal }] = useModal();
45 const [registerTable, { reload }] = useTable({ 45 const [registerTable, { reload }] = useTable({
46 title: '设备配置列表', 46 title: '设备配置列表',
47 api: deviceProfilePage, 47 api: deviceProfilePage,
@@ -63,13 +63,13 @@ @@ -63,13 +63,13 @@
63 }); 63 });
64 64
65 function handleCreate() { 65 function handleCreate() {
66 - openDrawer(true, { 66 + openModal(true, {
67 isUpdate: false, 67 isUpdate: false,
68 }); 68 });
69 } 69 }
70 70
71 function handleEdit(record: Recordable) { 71 function handleEdit(record: Recordable) {
72 - openDrawer(true, { 72 + openModal(true, {
73 record, 73 record,
74 isUpdate: true, 74 isUpdate: true,
75 }); 75 });
@@ -77,9 +77,9 @@ @@ -77,9 +77,9 @@
77 77
78 function handleDelete(record: Recordable) { 78 function handleDelete(record: Recordable) {
79 let ids = [record.id]; 79 let ids = [record.id];
80 - deleteDeviceProfile(ids).then(() => {  
81 - createMessage.success('删除设备配置成功');  
82 - handleSuccess(); 80 + deleteDeviceProfile(ids).then(()=>{
  81 + createMessage.success("删除设备配置成功")
  82 + handleSuccess()
83 }); 83 });
84 } 84 }
85 85
@@ -88,11 +88,11 @@ @@ -88,11 +88,11 @@
88 } 88 }
89 return { 89 return {
90 registerTable, 90 registerTable,
91 - registerDrawer,  
92 handleCreate, 91 handleCreate,
93 handleEdit, 92 handleEdit,
94 handleDelete, 93 handleDelete,
95 handleSuccess, 94 handleSuccess,
  95 + registerModal,
96 }; 96 };
97 }, 97 },
98 }); 98 });
  1 +<template>
  2 + <div class="step1">
  3 + <div class="step1-form">
  4 + <BasicForm @register="register"> </BasicForm>
  5 + </div>
  6 + </div>
  7 +</template>
  8 +<script lang="ts">
  9 + import { defineComponent, ref } from 'vue';
  10 + import { BasicForm, useForm } from '/@/components/Form';
  11 + import { step1Schemas } from './data';
  12 + import { Select, Input, Divider } from 'ant-design-vue';
  13 + export default defineComponent({
  14 + components: {
  15 + BasicForm,
  16 + [Select.name]: Select,
  17 + ASelectOption: Select.Option,
  18 + [Input.name]: Input,
  19 + [Input.Group.name]: Input.Group,
  20 + [Divider.name]: Divider,
  21 + },
  22 + emits: ['next'],
  23 + setup(_, { emit }) {
  24 + const devicePic = ref('');
  25 + const [register, { validate }] = useForm({
  26 + labelWidth: 100,
  27 + schemas: step1Schemas,
  28 + actionColOptions: {
  29 + span: 14,
  30 + },
  31 + showResetButton: false,
  32 + submitButtonOptions: {
  33 + text: '下一步',
  34 + },
  35 + submitFunc: customSubmitFunc,
  36 + });
  37 +
  38 + async function customSubmitFunc() {
  39 + try {
  40 + const values = await validate();
  41 + emit('next', values);
  42 + } catch (error) {}
  43 + }
  44 + return { register, devicePic };
  45 + },
  46 + });
  47 +</script>
  48 +<style lang="less" scoped>
  49 + .step1 {
  50 + &-form {
  51 + width: 450px;
  52 + margin: 0 auto;
  53 + }
  54 +
  55 + h3 {
  56 + margin: 0 0 12px;
  57 + font-size: 16px;
  58 + line-height: 32px;
  59 + color: @text-color;
  60 + }
  61 +
  62 + h4 {
  63 + margin: 0 0 4px;
  64 + font-size: 14px;
  65 + line-height: 22px;
  66 + color: @text-color;
  67 + }
  68 +
  69 + p {
  70 + color: @text-color;
  71 + }
  72 + }
  73 +
  74 + .pay-select {
  75 + width: 20%;
  76 + }
  77 +
  78 + .pay-input {
  79 + width: 70%;
  80 + }
  81 +</style>
  1 +<template>
  2 + <div class="step2">
  3 + <BasicForm @register="register" />
  4 + </div>
  5 +</template>
  6 +<script lang="ts">
  7 + import { defineComponent } from 'vue';
  8 + import { BasicForm, useForm } from '/@/components/Form';
  9 + import { step2Schemas } from './data';
  10 + import { Alert, Divider, Descriptions } from 'ant-design-vue';
  11 +
  12 + export default defineComponent({
  13 + components: {
  14 + BasicForm,
  15 + [Alert.name]: Alert,
  16 + [Divider.name]: Divider,
  17 + [Descriptions.name]: Descriptions,
  18 + [Descriptions.Item.name]: Descriptions.Item,
  19 + },
  20 + emits: ['next', 'prev'],
  21 + setup(_, { emit }) {
  22 + const [register, { validate}] = useForm({
  23 + labelWidth: 80,
  24 + schemas: step2Schemas,
  25 + actionColOptions: {
  26 + span: 14,
  27 + },
  28 + resetButtonOptions: {
  29 + text: '上一步',
  30 + },
  31 + submitButtonOptions: {
  32 + text: '下一步',
  33 + },
  34 + resetFunc: customResetFunc,
  35 + submitFunc: customSubmitFunc,
  36 + });
  37 +
  38 + async function customResetFunc() {
  39 + emit('prev');
  40 + }
  41 +
  42 + async function customSubmitFunc() {
  43 + try {
  44 + const values = await validate();
  45 + emit('next', values);
  46 + } catch (error) {}
  47 + }
  48 +
  49 + return { register };
  50 + },
  51 + });
  52 +</script>
  53 +<style lang="less" scoped>
  54 + .step2 {
  55 + width: 450px;
  56 + margin: 0 auto;
  57 + }
  58 +</style>
  1 +<template>
  2 + <div class="step2">
  3 + <BasicForm @register="register" />
  4 + </div>
  5 +</template>
  6 +<script lang="ts">
  7 +import { defineComponent } from 'vue';
  8 +import { BasicForm, useForm } from '/@/components/Form';
  9 +import { step3Schemas } from './data';
  10 +import { Alert, Divider, Descriptions } from 'ant-design-vue';
  11 +
  12 +export default defineComponent({
  13 + components: {
  14 + BasicForm,
  15 + [Alert.name]: Alert,
  16 + [Divider.name]: Divider,
  17 + [Descriptions.name]: Descriptions,
  18 + [Descriptions.Item.name]: Descriptions.Item,
  19 + },
  20 + emits: ['next', 'prev'],
  21 + setup(_, { emit }) {
  22 + const [register, { validate, setProps }] = useForm({
  23 + labelWidth: 80,
  24 + schemas: step3Schemas,
  25 + actionColOptions: {
  26 + span: 14,
  27 + },
  28 + resetButtonOptions: {
  29 + text: '上一步',
  30 + },
  31 + submitButtonOptions: {
  32 + text: '提交',
  33 + },
  34 + resetFunc: customResetFunc,
  35 + submitFunc: customSubmitFunc,
  36 + });
  37 +
  38 + async function customResetFunc() {
  39 + emit('prev');
  40 + }
  41 +
  42 + async function customSubmitFunc() {
  43 + try {
  44 + const values = await validate();
  45 + setProps({
  46 + submitButtonOptions: {
  47 + loading: true,
  48 + },
  49 + });
  50 + setTimeout(() => {
  51 + setProps({
  52 + submitButtonOptions: {
  53 + loading: false,
  54 + },
  55 + });
  56 + emit('next', values);
  57 + }, 1500);
  58 + } catch (error) {}
  59 + }
  60 +
  61 + return { register };
  62 + },
  63 +});
  64 +</script>
  65 +<style lang="less" scoped>
  66 +.step2 {
  67 + width: 450px;
  68 + margin: 0 auto;
  69 +}
  70 +</style>
  1 +import { FormSchema } from '/@/components/Form';
  2 +import {findDictItemByCode} from "/@/api/system/dict";
  3 +
  4 +export const step1Schemas: FormSchema[] = [
  5 + {
  6 + field: 'name',
  7 + label: '配置名称',
  8 + required: true,
  9 + component:'Input',
  10 + componentProps:{
  11 + maxLength:30
  12 + }
  13 + },
  14 + {
  15 + field: 'deviceType',
  16 + label: '队列优先级',
  17 + component: 'ApiSelect',
  18 + componentProps: {
  19 + api:findDictItemByCode,
  20 + params:{
  21 + dictCode:"queen_execute_sequence"
  22 + },
  23 + labelField:'itemText',
  24 + valueField:'itemValue',
  25 + },
  26 + },
  27 + {
  28 + label: '备注',
  29 + field: 'remark',
  30 + component: 'InputTextArea',
  31 + }
  32 +];
  33 +
  34 +export const step2Schemas: FormSchema[] = [
  35 + {
  36 + field: 'transportType',
  37 + component: 'Select',
  38 + label: '传输方式',
  39 + defaultValue: 'DEFAULT',
  40 + componentProps:{
  41 + options: [
  42 + {label: '默认', value: "DEFAULT"},
  43 + ],
  44 + }
  45 + },
  46 +];
  47 +
  48 +export const step3Schemas: FormSchema[] = [
  49 + {
  50 + field: 'transportType',
  51 + component: 'Select',
  52 + label: '报警规则',
  53 + defaultValue: 'DEFAULT',
  54 + componentProps:{
  55 + options: [
  56 + {label: '默认', value: "DEFAULT"},
  57 + ],
  58 + }
  59 + },
  60 +];