index.vue
8.77 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
<script lang="ts" setup>
import { Button, Tooltip, Card, Popconfirm } from 'ant-design-vue';
import { AuthIcon, EnumTableCardMode } from '/@/components/Widget';
import { useMessage } from '/@/hooks/web/useMessage';
import { BasicCardList, useCardList } from '/@/components/CardList';
import { useRoute } from 'vue-router';
import { ref } from 'vue';
import { HandleOperationEnum, HandleOperationNameEnum } from '../../config';
import { searchFormSchema } from '../EdgeInstance/config';
import { deleteEdgeInstance, edgeInstancePage } from '/@/api/edgeManage/edgeInstance';
import { EdgeInstanceItemType } from '/@/api/edgeManage/model/edgeInstance';
import { EdgeInstanceFormDrawer } from '../EdgeInstance';
import { useDrawer } from '/@/components/Drawer';
import moment from 'moment';
import { isArray } from '/@/utils/is';
import AuthDropDown from '/@/components/Widget/AuthDropDown.vue';
import edgeStatusIsOnlinePng from '/@/assets/images/edgeStatusIsOnline.png';
import edgeStatusIsOfflinePng from '/@/assets/images/edgeStatusIsOffline.png';
import { Image } from 'ant-design-vue';
import { useGo } from '/@/hooks/web/usePage';
defineProps<{
mode: EnumTableCardMode;
}>();
defineEmits(['register']);
enum DropMenuEvent {
DELETE = 'delete',
}
const { createMessage } = useMessage();
const go = useGo();
const { query } = useRoute();
const disabledDeleteFlag = ref(true);
const [registerCardList, { reload, getSelectedRecords, clearSelectedKeys }] = useCardList({
api: async ({ page, pageSize, textSearch }) => {
const res = await edgeInstancePage({
page: page === 1 ? 0 : page,
pageSize,
textSearch,
});
return {
total: res?.totalElements,
items: res?.data,
};
},
useSearchForm: true,
gutter: 4,
rowKey: 'routingKey', //id是对象
formConfig: {
schemas: searchFormSchema,
labelWidth: 100,
model: {
name: (query as Recordable)?.name ? decodeURIComponent((query as Recordable)?.name) : null,
},
},
selections: {
beforeSelectValidate: () => {
return true;
},
onSelect: (_record, _flag, allSelecteds) => {
disabledDeleteFlag.value = !allSelecteds.length;
},
onSelectAll: () => {
// 全选事件
disabledDeleteFlag.value = false;
},
onUnSelectAll: () => {
// 反选事件
disabledDeleteFlag.value = true;
},
onSelectToggle: (status: boolean) => {
// 全选是false,反选是true
if (!status) disabledDeleteFlag.value = false;
else disabledDeleteFlag.value = true;
},
},
});
const [registerEdgeInstanceFormDrawer, { openDrawer: openEdgeInstanceFormDrawer }] = useDrawer();
const handleEventIsSuccess = () => reload();
const handleGoDetail = (record: EdgeInstanceItemType | null) => {
go('/edge/edge_detail/' + record?.id?.id);
};
const handleOperationEvent = (
event: HandleOperationEnum,
record: EdgeInstanceItemType | null
) => {
const isUpdate = event === HandleOperationEnum.CREATE ? false : true;
const isUpdateText =
event === HandleOperationEnum.CREATE
? HandleOperationNameEnum.CREATE
: event === HandleOperationEnum.UPDATE
? HandleOperationNameEnum.UPDATE
: HandleOperationNameEnum.VIEW;
if (event === HandleOperationEnum.VIEW) {
} else {
openEdgeInstanceFormDrawer(true, { isUpdate, record, isUpdateText, event });
}
};
const handleDelete = async (event: HandleOperationEnum, id?: string | null) => {
try {
if (event === HandleOperationEnum.BATCH_DELETE) {
const batchDeleteIds = getSelectedRecords().map(
(rowRecord: EdgeInstanceItemType) => rowRecord?.id?.id
);
if (isArray(batchDeleteIds) && batchDeleteIds.length === 0) return;
for (let item of batchDeleteIds) await deleteEdgeInstance(item!);
} else {
await deleteEdgeInstance(id!);
}
createMessage.success('删除成功');
clearSelectedKeys();
disabledDeleteFlag.value = true;
await reload();
} catch (error) {
throw error;
}
};
</script>
<template>
<section>
<BasicCardList @register="registerCardList">
<template #toolbar>
<Button type="primary" @click="handleOperationEvent(HandleOperationEnum.CREATE, null)"
>新增实例</Button
>
<Popconfirm
title="您确定要批量删除数据"
ok-text="确定"
cancel-text="取消"
@confirm="handleDelete(HandleOperationEnum.BATCH_DELETE, null)"
:disabled="disabledDeleteFlag"
>
<Button type="primary" danger :disabled="disabledDeleteFlag"> 批量删除 </Button>
</Popconfirm>
</template>
<template #renderItem="{ item }: BasicCardListRenderItem<EdgeInstanceItemType>">
<Card hoverable>
<template #cover>
<div class="w-full h-full !flex flex-col justify-between m-3">
<div class="!flex justify-between align-center text-center">
<span class="truncate font-bold fill-dark-900 text-sm"> {{ item.name }} </span>
<div class="mr-6">
<a-tag class="!flex items-center" :color="item.active ? '#E8FFEA' : '#FFECE8'">
<template #icon>
<template v-if="item.active">
<Image :width="12" :height="12" :src="edgeStatusIsOnlinePng" />
</template>
<template v-else>
<Image :width="12" :height="12" :src="edgeStatusIsOfflinePng" />
</template>
</template>
<span class="ml-1" :style="{ color: item.active ? '#00B42A' : '#F53F3F' }">{{
item.active ? '在线' : '离线'
}}</span>
</a-tag>
</div>
</div>
<div class="!flex justify-between align-center text-center">
<span class="truncate text-xs" style="color: #86909c">
{{ moment(item.createdTime).format('YYYY-MM-DD HH:mm:ss') }}
</span>
</div>
</div>
</template>
<template class="ant-card-actions" #actions>
<Tooltip title="详情">
<AuthIcon
class="!text-lg"
icon="ant-design:eye-outlined"
@click.stop="handleGoDetail(item)"
/>
</Tooltip>
<Tooltip title="编辑">
<AuthIcon
class="!text-lg"
icon="ant-design:form-outlined"
@click.stop="handleOperationEvent(HandleOperationEnum.UPDATE, item)"
/>
</Tooltip>
<AuthDropDown
@click.stop
:trigger="['hover']"
:drop-menu-list="[
{
text: '删除',
event: DropMenuEvent.DELETE,
icon: 'ant-design:delete-outlined',
popconfirm: {
title: '是否确认删除操作?',
onConfirm: handleDelete.bind(null, HandleOperationEnum.DELETE, item?.id?.id),
},
},
]"
/>
</template>
<Card.Meta>
<template #description>
<div class="truncate h-17 !flex justify-between flex-col">
<div class="truncate !flex">
<span class="text-xs" style="color: #86909c">标签</span>
<span class="truncate ml-7.5 text-xs" style="color: #00b42a">{{
item.label
}}</span>
</div>
<div class="truncate !flex">
<span class="text-xs" style="color: #86909c">边缘类型</span>
<span style="color: #4e5969" class="truncate ml-7.5 text-xs">{{
item.type
}}</span>
</div>
<div class="truncate !flex">
<span class="text-xs" style="color: #86909c">描述</span>
<span style="color: #4e5969" class="truncate ml-7.5 text-xs">
{{ item?.additionalInfo?.description }}
</span>
</div>
</div>
</template>
</Card.Meta>
</Card>
</template>
</BasicCardList>
<EdgeInstanceFormDrawer
@register="registerEdgeInstanceFormDrawer"
@success="handleEventIsSuccess"
/>
</section>
</template>
<style lang="less" scoped>
.profile-list:deep(.ant-image-img) {
@apply !w-full !h-full;
}
.profile-list:deep(.ant-card-body) {
@apply !p-4;
}
:deep(.ant-card-body) {
padding: 12px;
}
</style>