index.vue
8.58 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
<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 } 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';
const ListItem = List.Item;
const router = useRouter();
const { createMessage, createConfirm } = useMessage();
const listEL = ref();
const loading = ref(false);
const dataBoardList = ref<DataBoardRecord[]>([]);
//分页相关
const page = ref(1);
const pageSize = ref(10);
const total = ref(0);
const paginationProp = ref({
showSizeChanger: false,
showQuickJumper: true,
pageSize,
current: page,
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 = (boardId: string, tenantId: string, name: string) => {
const { origin } = location;
return `${origin}${DATA_BOARD_SHARE_URL(encode(boardId), encode(tenantId), encode(name))}`;
};
const { clipboardRef } = useCopyToClipboard();
const handleCopyShareUrl = (record: DataBoardRecord) => {
clipboardRef.value = createShareUrl(record.id, record.tenantId, record.name);
unref(clipboardRef) ? createMessage.success('复制成功') : createMessage.error('未找到分享链接');
};
const { hasPermission } = usePermission();
const dropMenuList = computed<DropMenu[]>(() => {
const hasUpdatePermission = hasPermission('api:yt:data_board:update:update');
const hasDeletePermission = hasPermission('api:yt:data_board:delete');
const basicMenu: DropMenu[] = [];
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 () => {
try {
loading.value = true;
const { total, items } = await getDataBoardList({
page: unref(paginationProp).current,
pageSize: unref(paginationProp).pageSize,
});
dataBoardList.value = items;
paginationProp.value.total = total;
} catch (error) {
} finally {
loading.value = false;
}
};
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),
});
}
};
const handleEdit = (record: DataBoardRecord) => {
openModal(true, {
isEdit: true,
...record,
});
};
const handleOpenDetailModal = () => {
openModal();
};
const handleRemove = async (record: DataBoardRecord) => {
// TODO 删除确认
try {
await deleteDataBoard([record.id]);
createMessage.success('删除成功');
await getDatasource();
} catch (error) {
// createMessage.error('删除失败');
}
};
const [registerModal, { openModal }] = useModal();
const handleViewBoard = (record: DataBoardRecord) => {
const hasDetailPermission = hasPermission('api:yt:data_component:list');
if (hasDetailPermission)
router.push(`/data/board/detail/${encode(record.id)}/${encode(record.name)}`);
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.minHeight = listContainerHeight + 'px') &&
// (listContainerEl.style.maxHeight = listContainerHeight + 'px') &&
(listContainerEl.style.height = listContainerHeight + 'px') &&
(listContainerEl.style.overflowY = 'auto') &&
(listContainerEl.style.overflowX = 'hidden');
};
onMounted(() => {
getDatasource();
handlePagenationPosition();
});
</script>
<template>
<PageWrapper>
<div class="flex mb-6 items-center bg-light-100 h-78px">
<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>
<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 }"
>
<template #renderItem="{ item }">
<ListItem>
<Card class="data-card cursor-pointer">
<template #title>
<div>{{ 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>
<!-- <template #cover>title</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: #999999">
<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>
<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: #666666;
&::before {
content: '';
width: 54px;
height: 54px;
margin-right: 16px;
background-image: url('/@/assets/svg/component.svg');
}
}
</style>