index.vue
10.2 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
<script lang="ts" setup>
import { List, Card, Statistic, Button, Tooltip, Spin } from 'ant-design-vue';
import { onMounted, ref, unref } from 'vue';
import { PageWrapper } from '/@/components/Page';
import { MoreOutlined, ShareAltOutlined } from '@ant-design/icons-vue';
import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
import { useMessage } from '/@/hooks/web/useMessage';
import Dropdown from '/@/components/Dropdown/src/Dropdown.vue';
import { DropMenu } from '/@/components/Dropdown';
import { DATA_BOARD_SHARE_URL, MoreActionEvent, VisualBoardPermission } from './config/config';
import { useModal } from '/@/components/Modal';
import PanelDetailModal from './components/PanelDetailModal.vue';
import { getDataBoardList, deleteDataBoard } from '/@/api/dataBoard';
import { DataBoardRecord } from '/@/api/dataBoard/model';
import { ViewType } from './config/panelDetail';
import { useRouter } from 'vue-router';
import { getBoundingClientRect } from '/@/utils/domUtils';
import Authority from '/@/components/Authority/src/Authority.vue';
import { computed } from '@vue/reactivity';
import { usePermission } from '/@/hooks/web/usePermission';
import { encode } from './config/config';
import { useForm, BasicForm } from '/@/components/Form';
import { formSchema } from './config/searchForm';
import ShareModal from './components/ShareModal.vue';
const ListItem = List.Item;
const router = useRouter();
const { createMessage, createConfirm } = useMessage();
const listEL = ref();
const loading = ref(false);
const dataBoardList = ref<DataBoardRecord[]>([]);
const [searchFormRegister, searchFormMethod] = useForm({
schemas: formSchema,
labelWidth: 80,
layout: 'inline',
submitButtonOptions: {
loading: loading as unknown as boolean,
},
submitFunc: async () => {
try {
const params = searchFormMethod.getFieldsValue();
await getDatasource(params);
} catch (error) {}
},
resetFunc: async () => {
try {
await getDatasource();
} catch (error) {}
},
});
// about pagination
const page = ref(1);
const pageSize = ref(10);
const total = ref(0);
const paginationProp = ref({
showSizeChanger: false,
showQuickJumper: true,
pageSize,
current: page,
size: 'small',
total,
showTotal: (total) => `总 ${total} 条`,
onChange: pageChange,
onShowSizeChange: pageSizeChange,
});
function pageChange(p, pz) {
page.value = p;
pageSize.value = pz;
getDatasource();
}
function pageSizeChange(_current, size) {
pageSize.value = size;
getDatasource();
}
const createShareUrl = (record: DataBoardRecord) => {
const { origin } = location;
const { id, publicId } = record;
return `${origin}${DATA_BOARD_SHARE_URL(id, publicId)}`;
};
const { clipboardRef } = useCopyToClipboard();
const handleCopyShareUrl = (record: DataBoardRecord) => {
clipboardRef.value = createShareUrl(record);
unref(clipboardRef) ? createMessage.success('复制成功') : createMessage.error('未找到分享链接');
};
const { hasPermission } = usePermission();
const dropMenuList = computed<DropMenu[]>(() => {
const hasUpdatePermission = hasPermission(VisualBoardPermission.UPDATE);
const hasDeletePermission = hasPermission(VisualBoardPermission.DELETE);
const basicMenu: DropMenu[] = [
{
text: '分享',
event: MoreActionEvent.SHARE,
icon: 'ant-design:share-alt-outlined',
},
];
if (hasUpdatePermission)
basicMenu.push({
text: '编辑',
event: MoreActionEvent.EDIT,
icon: 'ant-design:edit-outlined',
});
if (hasDeletePermission)
basicMenu.push({
text: '删除',
event: MoreActionEvent.DELETE,
icon: 'ant-design:delete-outlined',
});
return basicMenu;
});
const getDatasource = async (params: Recordable = {}) => {
try {
loading.value = true;
const { total, items } = await getDataBoardList({
page: unref(paginationProp).current,
pageSize: unref(paginationProp).pageSize,
...params,
});
dataBoardList.value = items;
paginationProp.value.total = total;
} catch (error) {
} finally {
loading.value = false;
}
};
const handleOpenShareModal = (record: DataBoardRecord) => {
openShareModal(true, record);
};
const handleMenuEvent = (event: DropMenu, record: DataBoardRecord) => {
if (event.event === MoreActionEvent.EDIT) handleEdit(record);
if (event.event === MoreActionEvent.DELETE) {
createConfirm({
iconType: 'warning',
content: '是否确认删除操作?',
onOk: () => handleRemove(record),
});
}
if (event.event === MoreActionEvent.SHARE) handleOpenShareModal(record);
};
const handleEdit = (record: DataBoardRecord) => {
openModal(true, {
isEdit: true,
...record,
});
};
const handleOpenDetailModal = () => {
openModal(true, { isEdit: false });
};
const handleRemove = async (record: DataBoardRecord) => {
try {
await deleteDataBoard([record.id]);
createMessage.success('删除成功');
await getDatasource();
} catch (error) {}
};
const [registerModal, { openModal }] = useModal();
const [registerShareModal, { openModal: openShareModal }] = useModal();
const handleViewBoard = (record: DataBoardRecord) => {
const hasDetailPermission = hasPermission(VisualBoardPermission.DETAIL);
if (hasDetailPermission) {
const boardId = encode(record.id);
const boardName = encode(record.name);
router.push(`/visual/board/detail/${boardId}/${boardName}`);
} else createMessage.warning('没有权限');
};
const handlePagenationPosition = () => {
const clientHeight = document.documentElement.clientHeight;
const rect = getBoundingClientRect(unref(listEL).$el!) as DOMRect;
const paginationHeight = 32 + 24 + 16;
const listContainerMarginBottom = 16;
const listContainerHeight =
clientHeight - rect.top - paginationHeight - listContainerMarginBottom;
const listContainerEl = (unref(listEL).$el as HTMLElement).querySelector(
'.ant-spin-container'
) as HTMLElement;
listContainerEl &&
(listContainerEl.style.height = listContainerHeight + 'px') &&
(listContainerEl.style.overflowY = 'auto') &&
(listContainerEl.style.overflowX = 'hidden');
};
onMounted(() => {
getDatasource();
handlePagenationPosition();
});
</script>
<template>
<PageWrapper>
<div class="flex items-center mb-3 bg-light-100 h-78px dark:text-gray-300 dark:bg-dark-900">
<div class="text-lg ml-30px mr-9px font-bold">自定义看板</div>
<Authority value="api:yt:data_board:add:post">
<Button type="primary" @click="handleOpenDetailModal">创建看板</Button>
</Authority>
</div>
<div class="bg-light-100 mb-6 w-full p-3 search-form dark:text-gray-300 dark:bg-dark-900">
<BasicForm class="flex-auto w-full" @register="searchFormRegister" />
</div>
<Spin :spinning="loading">
<List
ref="listEL"
:pagination="paginationProp"
:data-source="dataBoardList"
:grid="{ gutter: 20, column: 4, xs: 1, sm: 2, md: 2, lg: 3, xl: 3, xxl: 3 }"
class="data-board-list"
>
<template #renderItem="{ item }">
<ListItem>
<Card class="data-card cursor-pointer">
<template #title>
<div class="font-bold">{{ item.name }}</div>
</template>
<template #extra>
<Dropdown
v-if="dropMenuList.length"
:trigger="['click']"
@menu-event="(event) => handleMenuEvent(event, item)"
:drop-menu-list="dropMenuList"
>
<MoreOutlined class="rotate-90 transform cursor-pointer" />
</Dropdown>
</template>
<section @click="handleViewBoard(item)">
<div class="flex data-card__info">
<div>
<div>组件数量</div>
<Statistic style="font-size: 22px" :value="item.componentNum">
<template #suffix>
<span class="text-sm">个</span>
</template>
</Statistic>
</div>
</div>
<div class="flex justify-between mt-4 text-sm" style="color: #999">
<div>
<span>
{{ item.viewType === ViewType.PRIVATE_VIEW ? '私有看板' : '公共看板' }}
</span>
<span v-if="item.viewType === ViewType.PUBLIC_VIEW">
<Tooltip title="点击复制分享链接">
<ShareAltOutlined class="ml-2" @click.stop="handleCopyShareUrl(item)" />
</Tooltip>
</span>
</div>
<div>{{ item.createTime }}</div>
</div>
</section>
</Card>
</ListItem>
</template>
</List>
</Spin>
<ShareModal @register="registerShareModal" @success="getDatasource" />
<PanelDetailModal @register="registerModal" @change="getDatasource" />
</PageWrapper>
</template>
<style scoped lang="less">
.data-card:deep(.ant-card-head) {
padding: 20px;
}
.data-card:deep(.ant-card-head-title) {
padding: 0;
}
.data-card:deep(.ant-card-extra) {
padding: 0;
}
.data-card:deep(.ant-card-body) {
padding: 20px;
}
.data-card__info {
color: #666;
&::before {
content: '';
width: 54px;
height: 54px;
margin-right: 16px;
background-image: url('/@/assets/svg/component.svg');
}
}
.search-form {
width: 100%;
form {
width: 100%;
:deep(.ant-row) {
width: 100%;
}
:deep(.ant-row > div:last-child) {
flex: 1;
max-width: 100%;
}
}
}
.data-board-list:deep(.ant-list-pagination) {
padding: 10px;
background-color: #fff;
}
[data-theme='dark'] .data-board-list:deep(.ant-list-pagination) {
padding: 10px;
background-color: #000;
}
</style>