Commit 5ec48e6db9bb1b943011bcab952d436136a8fd08

Authored by fengtao
1 parent 2b197447

refractor:重新修改了报表配置部分代码

... ... @@ -18,23 +18,23 @@
18 18 mode="multiple"
19 19 labelInValue
20 20 allowClear
21   - @deselect="handleDeSelect"
22 21 notFoundContent="请选择设备"
23 22 />
24 23 <div style="margin-top: 1.5vh"></div>
25   - <DeviceAttrCpns
26   - ref="deviceAttrRef"
27   - @change="handleChange"
28   - :value="deviceList"
29   - :orgId="organizationId || orgId"
30   - :deSelectValue="deSelectValue"
31   - />
  24 + <div v-for="(item, index) in deviceList" :key="index">
  25 + <DeviceAttrCpns
  26 + ref="deviceAttrRef"
  27 + @change="handleChange"
  28 + :value="item"
  29 + :orgId="organizationId || orgId"
  30 + />
  31 + </div>
32 32 </template>
33 33 </BasicForm>
34 34 </BasicDrawer>
35 35 </template>
36 36 <script lang="ts" setup>
37   - import { ref, computed, unref, reactive, watch } from 'vue';
  37 + import { ref, computed, unref, reactive, watch, nextTick } from 'vue';
38 38 import { BasicForm, useForm } from '/@/components/Form';
39 39 import { formSchema, organizationId } from './config.data';
40 40 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
... ... @@ -50,10 +50,9 @@
50 50 const isUpdate = ref(true);
51 51 const editId = ref('');
52 52 const orgId = ref('');
53   - let deviceAttrData: any = ref([]);
54 53 const selectOptions: any = ref([]);
55 54 const selectDevice = ref([]);
56   - const deviceList = ref([]);
  55 + const deviceList: any = ref([]);
57 56 watch(organizationId, async (newValue: string) => {
58 57 if (!newValue) return;
59 58 //获取设备
... ... @@ -71,11 +70,6 @@
71 70 const handleDeviceChange = (e) => {
72 71 deviceList.value = e;
73 72 };
74   - const deSelectValue = ref('');
75   - const handleDeSelect = ({ key }) => {
76   - //取消选中的key
77   - deSelectValue.value = key;
78   - };
79 73 const [registerForm, { validate, setFieldsValue, resetFields }] = useForm({
80 74 labelWidth: 120,
81 75 schemas: formSchema,
... ... @@ -129,29 +123,29 @@
129 123 ];
130 124 selectDevice.value = deviceIds;
131 125 //回显设备属性 TODO 模拟的数据 待服务端返回
132   - deviceAttrData.value = [
  126 + deviceList.value = [
133 127 {
134   - device: '8943f0b0-f1f7-11ec-98ad-a9680487d1e0',
  128 + value: '8a4cc9a0-f201-11ec-98ad-a9680487d1e0',
135 129 attribute: 'CO2',
136   - name: '宝马默认设备',
  130 + label: '奥迪网关子设备',
137 131 },
138 132 {
139   - device: '8f5b4280-f29e-11ec-98ad-a9680487d1e0',
  133 + value: '8943f0b0-f1f7-11ec-98ad-a9680487d1e0',
140 134 attribute: 'co',
141   - name: '新增奥迪测试设备',
  135 + label: '宝马默认设备',
142 136 },
143 137 {
144   - device: '54e199d0-f1f7-11ec-98ad-a9680487d1e0',
  138 + value: '6d9043f0-f1f7-11ec-98ad-a9680487d1e0',
145 139 attribute: 'hot',
146   - name: '奥迪默认设备',
  140 + label: '奔驰默认设备',
147 141 },
148 142 {
149   - device: '6d9043f0-f1f7-11ec-98ad-a9680487d1e0',
  143 + value: '8f5b4280-f29e-11ec-98ad-a9680487d1e0',
150 144 attribute: 'wet',
151   - name: '奔驰默认设备',
  145 + label: '新增奥迪测试设备',
152 146 },
153 147 ];
154   - deviceAttrRef.value?.echoDynamicInputFunc(deviceAttrData.value);
  148 + nextTick(() => {});
155 149 } else {
156 150 editId.value = '';
157 151 orgId.value = '';
... ... @@ -162,7 +156,9 @@
162 156 });
163 157 const getAttrDevice: any = ref([]);
164 158 const getTitle = computed(() => (!unref(isUpdate) ? '新增报表配置' : '编辑报表配置'));
165   - const handleChange = (e) => (getAttrDevice.value = e);
  159 + const handleChange = (e) => {
  160 + getAttrDevice.value.push(e);
  161 + };
166 162 let postObj: any = reactive({});
167 163 let queryCondition: any = reactive({});
168 164 let executeContent: any = reactive({});
... ...
... ... @@ -38,14 +38,14 @@
38 38 device: string;
39 39 }
40 40 const props = defineProps({
41   - value: propTypes.array.def([]),
  41 + value: propTypes.object.def({}),
42 42 orgId: propTypes.string.def(''),
43 43 });
44 44 const emits = defineEmits(['change', 'update:value']);
45 45 const selectOptions = ref<SelectTypes['options']>([]);
46 46 //获取属性
47 47 const getAttr = async (orgId, deviceId) => {
48   - const res = await getAttribute(orgId, deviceId.join(','));
  48 + const res = await getAttribute(orgId, deviceId);
49 49 selectOptions.value = res.map((o) => {
50 50 return {
51 51 label: o,
... ... @@ -55,25 +55,20 @@
55 55 };
56 56 //动态数据
57 57 const dynamicInput: UnwrapRef<{ params: Params[] }> = reactive({ params: [] });
58   - //监听传入数据value
59   - watchEffect(() => {
  58 + const rEffect = watchEffect(() => {
60 59 initVal();
61 60 });
  61 + rEffect();
62 62 /**
63 63 * 初始化数值
64 64 */
65 65 async function initVal() {
66   - dynamicInput.params = [];
67   - if (props.value && props.orgId) {
68   - let jsonObj = props.value;
69   - const deviceId = jsonObj.map((m: any) => m.value);
70   - await getAttr(props.orgId, deviceId);
71   - jsonObj.forEach((item: any) => {
72   - dynamicInput.params.push({
73   - attribute: '',
74   - device: item.label,
75   - value: item.value,
76   - });
  66 + if (props.orgId && props.value.value) {
  67 + await getAttr(props.orgId, props.value.value);
  68 + dynamicInput.params.push({
  69 + device: props.value.label,
  70 + value: props.value.value,
  71 + attribute: props.value.attribute == '' ? '' : props.value.attribute,
77 72 });
78 73 }
79 74 }
... ... @@ -81,32 +76,12 @@
81 76 * 数值改变
82 77 */
83 78 function emitChange() {
84   - let obj: any = [];
85   - if (dynamicInput.params.length > 0) {
86   - dynamicInput.params.forEach((item: Params) => {
87   - obj.push({
88   - attribute: item.attribute,
89   - device: item.value,
90   - });
91   - });
92   - }
93   - console.log('emitChange', obj);
  79 + let obj: any = dynamicInput.params[0];
94 80 emits('change', obj);
95 81 emits('update:value', obj);
96 82 }
97   - //回显
98   - const echoDynamicInputFunc = (o) => {
99   - dynamicInput.params = [];
100   - o.forEach((m: any) => {
101   - dynamicInput.params.push({
102   - device: m.name,
103   - attribute: m.attribute,
104   - value: m.device,
105   - });
106   - });
107   - };
108 83 defineExpose({
109   - echoDynamicInputFunc,
  84 + getAttr,
110 85 });
111 86 </script>
112 87 <style scoped lang="css">
... ...
... ... @@ -4,13 +4,24 @@ import moment from 'moment';
4 4 import { h } from 'vue';
5 5 import { Tag } from 'ant-design-vue';
6 6
  7 +///任务组名Enum
  8 +export enum EJobGroup {
  9 + DEFAULT = 'DEFAULT',
  10 + SYSTEM = 'SYSTEM',
  11 + REPORT = 'REPORT',
  12 +}
  13 +
7 14 //任务详细配置
8 15 export const personSchema: DescItem[] = [
9 16 {
10 17 field: 'jobGroup',
11 18 label: '任务分组:',
12 19 render: (_, data) => {
13   - return data.jobGroup == 'Default' ? '默认' : data.jobGroup == 'System' ? '系统' : '报表';
  20 + return data.jobGroup == EJobGroup.DEFAULT
  21 + ? '默认'
  22 + : data.jobGroup == EJobGroup.SYSTEM
  23 + ? '系统'
  24 + : '报表';
14 25 },
15 26 },
16 27 {
... ... @@ -62,9 +73,9 @@ export const columnSchedue: BasicColumn[] = [
62 73 dataIndex: 'jobGroup',
63 74 width: 120,
64 75 format: (_text: string, record: Recordable) => {
65   - return record.jobGroup === 'Default'
  76 + return record.jobGroup === EJobGroup.DEFAULT
66 77 ? '默认'
67   - : record.jobGroup === 'System'
  78 + : record.jobGroup === EJobGroup.SYSTEM
68 79 ? '系统'
69 80 : '报表';
70 81 },
... ... @@ -121,15 +132,15 @@ export const searchSchedueFormSchema: FormSchema[] = [
121 132 options: [
122 133 {
123 134 label: '默认',
124   - value: 'Default',
  135 + value: EJobGroup.DEFAULT,
125 136 },
126 137 {
127 138 label: '系统',
128   - value: 'System',
  139 + value: EJobGroup.SYSTEM,
129 140 },
130 141 {
131 142 label: '报表',
132   - value: 'Report',
  143 + value: EJobGroup.REPORT,
133 144 },
134 145 ],
135 146 placeholder: '请选择任务组名',
... ... @@ -176,7 +187,11 @@ export const scheduleLogDetailSchema: DescItem[] = [
176 187 field: 'jobGroup',
177 188 label: '任务组名:',
178 189 render: (_, data) => {
179   - return data.jobGroup == 'Default' ? '默认' : data.jobGroup == 'System' ? '系统' : '报表';
  190 + return data.jobGroup == EJobGroup.DEFAULT
  191 + ? '默认'
  192 + : data.jobGroup == EJobGroup.SYSTEM
  193 + ? '系统'
  194 + : '报表';
180 195 },
181 196 },
182 197 {
... ...
1 1 import { BasicColumn, FormSchema } from '/@/components/Table';
2 2 import type { FormSchema as QFormSchema } from '/@/components/Form/index';
3 3 import { JCronValidator } from '/@/components/Form';
  4 +import { EJobGroup } from './config.data';
4 5
5 6 // 定时任务表格配置
6 7 export const columnSchedue: BasicColumn[] = [
... ... @@ -14,9 +15,9 @@ export const columnSchedue: BasicColumn[] = [
14 15 dataIndex: 'jobGroup',
15 16 width: 120,
16 17 format: (_text: string, record: Recordable) => {
17   - return record.jobGroup === 'Default'
  18 + return record.jobGroup === EJobGroup.DEFAULT
18 19 ? '默认'
19   - : record.jobGroup === 'System'
  20 + : record.jobGroup === EJobGroup.SYSTEM
20 21 ? '系统'
21 22 : '报表';
22 23 },
... ... @@ -60,15 +61,15 @@ export const searchSchedueFormSchema: FormSchema[] = [
60 61 options: [
61 62 {
62 63 label: '默认',
63   - value: 'Default',
  64 + value: EJobGroup.DEFAULT,
64 65 },
65 66 {
66 67 label: '系统',
67   - value: 'System',
  68 + value: EJobGroup.SYSTEM,
68 69 },
69 70 {
70 71 label: '报表',
71   - value: 'Report',
  72 + value: EJobGroup.REPORT,
72 73 },
73 74 ],
74 75 placeholder: '请选择任务组名',
... ... @@ -120,15 +121,15 @@ export const formSchema: QFormSchema[] = [
120 121 options: [
121 122 {
122 123 label: '默认',
123   - value: 'Default',
  124 + value: EJobGroup.DEFAULT,
124 125 },
125 126 {
126 127 label: '系统',
127   - value: 'System',
  128 + value: EJobGroup.SYSTEM,
128 129 },
129 130 {
130 131 label: '报表',
131   - value: 'Report',
  132 + value: EJobGroup.REPORT,
132 133 },
133 134 ],
134 135 },
... ...