demo.vue
8.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<template>
<div class="container">
<a-card class="general-card" title="动态表头">
<a-radio-group v-model="position" type="button" @change="positionChange">
<a-radio value="day">天</a-radio>
<a-radio value="hour">小时</a-radio>
</a-radio-group>
<a-table :data="data">
<template #columns>
<a-table-column v-for="item in customColumnsValue" :title="item.title"
:data-index="item.dataIndex"></a-table-column>
<a-table-column title="操作">
<template #cell="{ record }">
<a-button>查看</a-button>
</template>
</a-table-column>
</template>
</a-table>
</a-card>
<a-row>
<a-col :flex="6">
<a-card title="用电能耗统计 在头部" class="energy-box">
<template #extra>
<time-bar @change="timeChange" :pickType="0" />
</template>
<electricity-chart />
</a-card>
</a-col>
<a-col :flex="6">
<a-card title="用电能耗统计 在内容里" class="energy-box">
<time-bar @change="timeChange" :pickType="1" />
<electricity-chart />
</a-card>
</a-col>
</a-row>
<a-divider style="margin-top: 0" />
<a-card title="曹晓桐的自定义图标">
<custom-icon type="icon-ykite-dianli"></custom-icon>
</a-card>
<a-divider style="margin-top: 0" />
<a-card title="十七的自定义图标">
<custom-icon type="复制的代码"></custom-icon>
</a-card>
<a-divider style="margin-top: 0" />
<a-card title="张怡静的自定义图标">
<custom-icon type="复制的代码"></custom-icon>
</a-card>
<a-divider style="margin-top: 0" />
<a-card title="杨季鸿的自定义图标">
<custom-icon type="复制的代码"></custom-icon>
</a-card>
<a-divider style="margin-top: 0" />
<a-card title="周孟琦的自定义图标">
<custom-icon type="icon-ykite-add-copy"></custom-icon>
<custom-icon type="icon-ykite-wj-jlb"></custom-icon>
</a-card>
<a-divider style="margin-top: 0" />
<a-card class="general-card" title="查询表格">
<!-- 查询条件 start-->
<a-row>
<a-col :flex="1" style="margin-top: 4px;">
<a-col :flex="1">
<a-form :model="formModel" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }"
label-align="left">
<a-row :gutter="16">
<a-col :span="8">
<a-form-item field="trueName" label="用户姓名">
<a-input v-model="formModel.trueName" placeholder="请输入用户姓名" allow-clear />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="phone" label="用户电话">
<a-input v-model="formModel.phone" placeholder="请输入用户电话" allow-clear />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="phone" label="用户电话">
<a-input v-model="formModel.phone" placeholder="请输入用户电话" allow-clear />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="phone" label="用户电话">
<a-input v-model="formModel.phone" placeholder="请输入用户电话" allow-clear />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="phone" label="用户电话">
<a-input v-model="formModel.phone" placeholder="请输入用户电话" allow-clear />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="phone" label="用户电话">
<a-input v-model="formModel.phone" placeholder="请输入用户电话" allow-clear />
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-col>
</a-col>
<a-divider style="height: 84px" direction="vertical" />
<a-col :flex="'86px'" style="text-align: right">
<a-space direction="vertical" :size="18">
<a-button type="primary" @click="search">
<template #icon>
<icon-search />
</template>
查询
</a-button>
<a-button @click="reset">
<template #icon>
<icon-refresh />
</template>
重置
</a-button>
</a-space>
</a-col>
</a-row>
<!-- 查询条件 end-->
<a-divider style="margin-top: 0" />
<!-- 表格 start -->
<a-table row-key="id" :loading="loading" :pagination="pagination" :columns="columns"
:data="renderData" :bordered="false" @page-change="onPageChange" @page-size-change="pageSizeChange"></a-table>
<!-- 表格 end-->
</a-card>
</div>
</template>
<script lang="ts" setup>
import { computed, reactive, ref } from 'vue';
import useLoading from '@/hooks/loading';
import { BasePagination } from '@/api/common';
import { UserEntity, UserQueryParams, queryUserList } from '@/api/pv/demo';
const position = ref<string>("day");
const customColumnsOne = [{
title: '设备',
dataIndex: 'device',
}, {
title: '参数',
dataIndex: 'params',
}, {
title: '1天',
dataIndex: '1',
}, {
title: '2天',
dataIndex: '2',
}, {
title: '3天',
dataIndex: '3'
}, {
title: '4天',
dataIndex: '4'
}, {
title: '5天',
dataIndex: '5'
}, {
title: '6天',
dataIndex: '6'
}, {
title: '最大值',
dataIndex: 'maxValue'
}];
const customColumnsTwo = [{
title: '设备',
dataIndex: 'device',
}, {
title: '参数',
dataIndex: 'params',
}, {
title: '1时',
dataIndex: '1时',
}, {
title: '2时',
dataIndex: '2时',
}, {
title: '3时',
dataIndex: '3时'
}, {
title: '4时',
dataIndex: '4时'
}, {
title: '5时',
dataIndex: '5时'
}, {
title: '6时',
dataIndex: '6时'
}, {
title: '7时',
dataIndex: '7时'
}, {
title: '最大值',
dataIndex: 'maxValue'
}];
const dataOne = [{
device: '1#350KVA-1变压器-按天',
params: "用电量",
1: "10",
2: "20",
3: "30",
4: "40",
5: "50",
6: "60",
maxValue: 60
}];
const dataTwo = [{
device: '1#350KVA-2变压器-按小时',
params: "用电量",
"1时": "10",
"2时": "20",
"3时": "30",
"4时": "40",
"5时": "50",
"6时": "60",
"7时": "70",
maxValue: 70
}];
let customColumnsValue = customColumnsOne;
let data = dataOne;
const positionChange = (value: string | number | boolean, ev: Event) => {
if(value == "day"){
customColumnsValue = customColumnsOne;
data = dataOne;
}else{
customColumnsValue = customColumnsTwo;
data = dataTwo;
}
}
//生成查询条件
const generateFormModel = () => {
return {
trueName: '',
phone: '',
};
};
const formModel = ref(generateFormModel());
//加载中
const { loading, setLoading } = useLoading(true);
//设置表格列
const columns = computed<any[]>(() => [
{
title: "编号",
dataIndex: 'id',
},
{
title: "昵称",
dataIndex: 'nickName',
},
{
title: "姓名",
dataIndex: 'trueName',
},
{
title: "手机号",
dataIndex: 'phone',
},
{
title: "注册时间",
dataIndex: 'registerTime',
},
{
title: "状态",
dataIndex: 'status',
slotName: 'status',
},
{
title: "用户地址",
dataIndex: 'address',
},
{
title: "操作",
dataIndex: 'operations',
slotName: 'operations',
}
]);
const timeChange = (time: any) => {
console.log(time);
}
//表格数据
const renderData = ref<UserEntity[]>([]);
//设置表格分页
const pagination: any = reactive({ ...BasePagination()});
//查询方法
const search = () => {
fetchData({
...pagination,
...formModel.value,
} as unknown as UserQueryParams);
};
//重置查询
const reset = () => {
formModel.value = generateFormModel();
};
//分页变化
const onPageChange = (current: number) => {
fetchData({ ...pagination, current });
};
const pageSizeChange = (val: number) => {
console.log('pageSizeChange', val)
pagination.pageSize = val;
console.log(pagination)
}
const fetchData = async (
params: UserQueryParams = { current: 1, pageSize: 20 }
) => {
setLoading(true);
try {
const { data } = await queryUserList(params);
renderData.value = data.list;
pagination.current = params.current;
pagination.total = data.total;
} catch (err) {
// you can report use errorHandler or other
} finally {
setLoading(false);
}
};
fetchData();
</script>
<style scoped lang="less">
:deep(.arco-table-th) {
&:last-child {
.arco-table-th-item-title {
margin-left: 16px;
}
}
}
.action-icon {
margin-left: 12px;
cursor: pointer;
}
.active {
color: #0960bd;
background-color: #e3f4fc;
}
.setting {
display: flex;
align-items: center;
width: 200px;
.title {
margin-left: 12px;
cursor: pointer;
}
}
</style>