index.vue
4.52 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
<template>
<div class="p-4">
<BasicTable @register="registerTable">
<template #toolbar>
<a-button type="primary" @click="handleCreate"> 新增设备 </a-button>
</template>
<template #config="{ record }">
<a-button type="link" class="ml-2" @click="showData(record)"> 查看配置 </a-button>
</template>
<template #deviceProfile="{ record }">
<a-button type="link" class="ml-2" @click="goDeviceProfile">
{{ record.deviceProfile.name }}
</a-button>
</template>
<template #deviceType="{ record }">
<Tag color="success" class="ml-2">
{{
record.deviceType == DeviceTypeEnum.GATEWAY
? '网关设备'
: record.deviceType == DeviceTypeEnum.DIRECT_CONNECTION
? '直连设备'
: '网关子设备'
}}
</Tag>
</template>
<template #deviceState="{ record }">
<Tag
:color="
record.deviceState == DeviceState.INACTIVE
? 'warning'
: record.deviceState == DeviceState.ONLINE
? 'success'
: 'error'
"
class="ml-2"
>
{{
record.deviceState == DeviceState.INACTIVE
? '待激活'
: record.deviceState == DeviceState.ONLINE
? '在线'
: '离线'
}}
</Tag>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '编辑',
icon: 'clarity:note-edit-line',
onClick: handleEdit.bind(null, record),
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
color: 'error',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
},
},
]"
/>
</template>
</BasicTable>
<RuleEngineDrawer @register="registerDrawer" @success="handleSuccess" />
</div>
</template>
<script lang="ts">
import { defineComponent, h } from 'vue';
import { DeviceState, DeviceTypeEnum } from '/@/api/device/model/deviceModel';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useDrawer } from '/@/components/Drawer';
import RuleEngineDrawer from './RuleEngineDrawer.vue';
import { columns } from './config.data';
import { Modal, Tag } from 'ant-design-vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { deleteDevice, devicePage } from '/@/api/device/deviceManager';
import { PageEnum } from '/@/enums/pageEnum';
import { useGo } from '/@/hooks/web/usePage';
export default defineComponent({
name: 'DeviceManagement',
components: { BasicTable, RuleEngineDrawer, TableAction, Tag },
setup() {
const [registerDrawer, { openDrawer }] = useDrawer();
const { createMessage } = useMessage();
const go = useGo();
const [registerTable, { reload }] = useTable({
title: '设备列表',
api: devicePage,
columns,
useSearchForm: false,
showTableSetting: true,
bordered: true,
showIndexColumn: false,
actionColumn: {
width: 200,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: 'right',
},
});
function handleCreate() {
openDrawer(true, {
isUpdate: false,
});
}
function handleEdit(record: Recordable) {
openDrawer(true, {
record,
isUpdate: true,
});
}
function handleDelete(record: Recordable) {
let ids = [record.id];
deleteDevice(ids).then(() => {
createMessage.success('删除设备成功');
handleSuccess();
});
}
function handleSuccess() {
reload();
}
function showData(record: Recordable) {
Modal.info({
title: '当前配置',
width: 480,
content: h(JsonPreview, { data: JSON.parse(JSON.stringify(record.deviceInfo)) }),
});
}
function goDeviceProfile() {
go(PageEnum.DEVICE_PROFILE);
}
return {
registerTable,
registerDrawer,
showData,
handleCreate,
handleEdit,
handleDelete,
handleSuccess,
goDeviceProfile,
DeviceTypeEnum,
DeviceState,
};
},
});
</script>