index.vue
11.9 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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<template>
<div>
<a-card class="content">
<!-- 操作条 start-->
<a-row style="margin:16px 0;">
<a-col :span="12">
<a-button type="primary" @click="handleAdd">
<template #icon>
<icon-plus/>
</template>
{{ $t('menu.diagram.project.power.list.create') }}
</a-button>
</a-col>
</a-row>
<!-- 操作条 end-->
<!-- 卡片列表 -->
<!-- <a-row :gutter="[16,16]" :span="25">-->
<!-- <a-col :span="5" v-for="(item, index) in renderData">-->
<a-grid :cols="5" :colGap="12" :rowGap="12">
<a-grid-item v-for="(item,index) in renderData" :key="index">
<a-card class="card-demo" :title="item.projectName">
<a-typography-paragraph class="card-time">
{{ item.createTime }}
</a-typography-paragraph>
<a-typography-paragraph class="card-content">
{{ item.remark }}
</a-typography-paragraph>
<template #actions>
<a-button size="small" status="success" @click="handleDesign(item.id)">{{ $t('global.design') }}
</a-button>
<a-button size="small" status="warning" @click="handleEdit(item.id)">{{ $t('global.edit') }}</a-button>
<a-button size="small" status="danger" @click="handleDelete(item)">{{ $t('global.delete') }}</a-button>
</template>
</a-card>
</a-grid-item>
</a-grid>
<!-- </a-col>-->
<!-- </a-row>-->
<!-- 添加右弹层 start -->
<a-drawer :width="750" :visible="formDrawer.visible" :ok-loading="formDrawer.loading" :mask-closable="false"
@ok="handleSubmitForm"
@cancel="handleFormCancel">
<template #title>
{{
formDrawer.formModel.id ? $t('menu.diagram.project.power.list.editItem') : $t('menu.diagram.project.power.list.addItem')
}}
</template>
<a-spin style="width: 100%;height: auto;" :loading="formDrawer.loading">
<a-row :gutter="24" class="row-mp-30">
<a-col :span="24">
<a-form ref="formRef" :model="formDrawer.formModel" label-align="right" :rules="formDrawer.rules"
auto-label-width>
<!-- 站点类型 -->
<a-form-item field="stationType" :label="$t('menu.diagram.project.power.list.siteType')">
<a-select :disabled="formDrawer.formModel.id == 0 ? false : true"
v-model="formDrawer.formModel.stationType"
:placeholder="$t('menu.diagram.project.power.list.siteTypeSelect')" allow-clear>
<a-option v-for="dict in sys_station_type" :key="dict.value" :label="dict.label"
:value="Number(dict.value)"></a-option>
</a-select>
</a-form-item>
<!-- 项目名称 -->
<a-form-item field="projectName" :label="$t('menu.diagram.project.power.list.projectName')"
:validate-trigger="['blur']">
<a-input v-model="formDrawer.formModel.projectName" :max-length="20" allow-clear
:placeholder="$t('menu.diagram.project.power.list.projectNamePlaceholder')"/>
</a-form-item>
<!-- 状态 -->
<a-form-item field="stopFlag" :label="$t('menu.diagram.project.power.list.projectStatus')">
<a-switch v-model="formDrawer.formModel.stopFlag" :checked-value="0" :unchecked-value="1">
<template
#checked>{{ $t('global.normal') }}
</template>
<template #unchecked>{{ $t('global.outOfService') }}</template>
</a-switch>
</a-form-item>
<a-form-item field="remark" :label="$t('global.remarks')">
<a-textarea v-model="formDrawer.formModel.remark" allow-clear :max-length="200" :auto-size="true"
:show-word-limit="true"
:placeholder="$t('menu.diagram.project.power.list.remarksPlaceholder')"/>
</a-form-item>
</a-form>
</a-col>
</a-row>
</a-spin>
</a-drawer>
<!-- 添加右弹层 end -->
<!-- 操作弹框 start -->
<a-modal width="450px" v-model:visible="operateModalModel.visible" class="modal-box">
<template #title>
<icon-close-circle v-if="operateModalModel.type == 1" size="18"
style="color: rgb(var(--red-6)); margin-right: 5px"/>
<icon-exclamation-circle v-else size="18" style="color: rgb(var(--orange-6)); margin-right: 5px"/>
{{ $t('global.confirmTip') }}
</template>
<div style="text-align: center;">是否确认{{ operateModalModel.title }}名称为【{{
operateModalModel.name
}}】的数据项?
</div>
<template #footer>
<div style="text-align: center">
<a-space>
<a-button type="primary" status="danger" @click="handleOperateModelCancle">{{ $t('global.cancel') }}
</a-button>
<a-button type="primary" @click="handleOperateModelOk">{{ $t('global.confirm') }}</a-button>
</a-space>
</div>
</template>
</a-modal>
<!-- 操作弹框 end -->
</a-card>
</div>
</template>
<script lang="ts" setup>
import {computed, getCurrentInstance, onMounted, reactive, ref} from "vue";
import {BasePagination} from "@/api/common";
import useLoading from '@/hooks/loading';
import {
addWebtopoProject,
listWebtopoProject,
updateWebtopoProject,
getWebtopoProject,
delWebtopoProject
} from "@/api/system/webtopo";
import {FormInstance, TableColumnData, TableInstance} from "@arco-design/web-vue";
import {notification} from "@/hooks/my-design";
import {StationTypeEnum} from "@/api/system/device";
import {useRouter} from "vue-router";
//******* 这里编写动态获取下拉列表 start ******
const proxy = getCurrentInstance()?.appContext.config.globalProperties;
const {sys_station_type} = proxy?.useDict("sys_station_type");
//******* 这里编写动态获取下拉列表 end ******
/*************************** 变量区域 begin ***************************/
//路由
const router = useRouter();
//组件参数
const props = defineProps({
stationType: {
type: Number,
default: StationTypeEnum.power,
}
})
//生成查询条件
const generateFormModel = () => {
return {
projectName: "",
stationType: props.stationType,
};
};
//表格分页配置
const pagination: any = reactive({...BasePagination()});
//查询项
const searchParams = ref(generateFormModel());
//加载中
const {loading, setLoading} = useLoading(true);
//表格实例
const tableRef = ref<TableInstance>();
//表格数据
const renderData = ref<any[]>([]);
//设置表格列
const columns = computed<TableColumnData[]>(() => [
{
title: "项目名称",
dataIndex: 'projectName',
width: 300,
fixed: "left"
},
{
title: "电站类型",
dataIndex: 'stationType',
slotName: 'stationType',
align: 'center',
width: 150
}, {
title: "备注",
dataIndex: 'remark',
width: 270,
fixed: "left"
},
{
title: "创建时间",
dataIndex: 'createTime',
align: 'center',
width: 180
},
{
title: "启用状态",
dataIndex: 'stopFlag',
slotName: "stopFlag",
fixed: "right",
align: 'center',
width: 100
},
{
title: "操作",
dataIndex: 'operate',
slotName: 'operate',
align: "center",
width: 180,
fixed: "right"
}
])
const generateFormDrawerModel = () => {
return {
visible: false,
loading: false,
rules: {
stationType: [{required: true, message: "请选择站点类型"}],
projectName: [{required: true, message: "请输入项目名称"}],
},
formModel: {
id: 0,
projectName: "",
stationType: props.stationType,
stopFlag: 1,
remark: "",
},
};
};
//表单模型
const formDrawer = ref(generateFormDrawerModel());
//编辑表单实例
const formRef = ref<FormInstance>();
//操作弹框
const generateOperateModalModel = () => {
return {
//0 状态 1删除
type: 0,
visible: false,
title: "",
id: 0,
value: 0,
name: ""
};
};
//操作弹框模型
const operateModalModel = ref(generateOperateModalModel());
/*************************** 变量区域 end ***************************/
/*************************** 方法区域 begin ***************************/
/**
* 添加接线图
*/
const handleAdd = async () => {
formDrawer.value = generateFormDrawerModel();
formDrawer.value.visible = true;
}
//表格页码发生变化
const onPageChange = (val: number) => {
pagination.current = val;
fetchData();
}
//表格每页数量发生变化
const onPageSizeChange = (val: number) => {
console.log("pageSize", val);
pagination.pageSize = val;
fetchData();
}
/**
* 设计接线图
* @param id
*/
const handleDesign = async (id: any) => {
window.open(`/webtopo/diagram/design/${id}`, '_blank');
}
/**
* 编辑项目
*/
const handleEdit = async (id: any) => {
formDrawer.value = generateFormDrawerModel();
formDrawer.value.visible = true;
formDrawer.value.loading = true;
try {
let res: any = await getWebtopoProject(id);
if (res.code == 200) {
formDrawer.value.formModel = res.data;
}
} catch (err) {
} finally {
formDrawer.value.loading = false;
}
}
/**
* 提交表单
*/
const handleSubmitForm = async () => {
const validate = await formRef.value?.validate();
if (!validate) {
try {
formDrawer.value.loading = true;
let result: any = {};
if (formDrawer.value.formModel.id == 0) {
result = await addWebtopoProject(formDrawer.value.formModel);
} else {
result = await updateWebtopoProject(formDrawer.value.formModel);
}
notification(result);
if (result.code == 200) {
await fetchData();
formDrawer.value = generateFormDrawerModel();
}
} catch (e) {
console.error(e);
} finally {
formDrawer.value.loading = false;
}
}
}
/**
* 删除数据
* @param record 数据行
*/
const handleDelete = (record: any) => {
operateModalModel.value.visible = true;
operateModalModel.value.id = record.id;
operateModalModel.value.title = '删除';
operateModalModel.value.name = record.projectName;
operateModalModel.value.type = 1;
}
/**
* 取消
*/
const handleFormCancel = () => {
formRef.value?.resetFields();
formDrawer.value = generateFormDrawerModel();
}
/**
* 删除提示弹框取消
*/
const handleOperateModelCancle = () => {
operateModalModel.value = generateOperateModalModel();
}
/**
* 删除提示弹框确认
*/
const handleOperateModelOk = async () => {
let result = await delWebtopoProject(operateModalModel.value.id);
notification(result);
if (result.code == 200) {
handleOperateModelCancle();
await fetchData();
}
}
/**
* 获取数据
*/
const fetchData = async () => {
setLoading(true);
try {
let res = await listWebtopoProject({
...searchParams.value,
pageSize: pagination.pageSize,
pageNum: pagination.current,
});
if (res.code == 200) {
renderData.value = res.rows;
pagination.total = res.total;
}
} catch (err) {
} finally {
setLoading(false);
}
}
/*************************** 方法区域 end ***************************/
onMounted(async () => {
await fetchData();
})
</script>
<style lang="less" scoped>
.card-demo{
border-radius: 5px;
}
.card-demo :deep(.arco-card-header) {
border: none;
}
.card-time {
margin-bottom: 4px;
}
.card-content {
min-height: 70px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
:deep(.arco-card-size-medium .arco-card-body) {
padding-top: 0;
}
</style>