Commit dcd325058583c6ada1b3ddfee8eb96e54aecb4da

Authored by ww
1 parent 00889916

feat: basic implement share data borad page

... ... @@ -27,6 +27,10 @@ enum DataComponentUrl {
27 27 UPDATE_DATA_COMPONENT = '/data_component',
28 28 }
29 29
  30 +enum DataBoardShareUrl {
  31 + GET_DATA_COMPONENT = '/noauth/share/dataBoard',
  32 +}
  33 +
30 34 enum DeviceUrl {
31 35 GET_DEVICE = '/device/list/master',
32 36 GET_SLAVE_DEVICE = '/device/list/slave',
... ... @@ -141,6 +145,18 @@ export const updateDataComponent = (params: UpdateDataComponentParams) => {
141 145 };
142 146
143 147 /**
  148 + * @description 分享组件信息
  149 + * @param params
  150 + * @returns
  151 + */
  152 +export const getShareBoardComponentInfo = (params: { boardId: string; tenantId: string }) => {
  153 + const { boardId, tenantId } = params;
  154 + return defHttp.get({
  155 + url: `${DataBoardShareUrl.GET_DATA_COMPONENT}/${boardId}/${tenantId}`,
  156 + });
  157 +};
  158 +
  159 +/**
144 160 * @description 获取所有主设备
145 161 * @param params
146 162 * @returns
... ...
... ... @@ -6,6 +6,7 @@ import {
6 6 EXCEPTION_COMPONENT,
7 7 PAGE_NOT_FOUND_NAME,
8 8 } from '/@/router/constant';
  9 +import { DATA_BOARD_SHARE_URL } from '/@/views/data/board/config/config';
9 10
10 11 // 404 on a page
11 12 export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
... ... @@ -76,3 +77,13 @@ export const ERROR_LOG_ROUTE: AppRouteRecordRaw = {
76 77 },
77 78 ],
78 79 };
  80 +
  81 +export const DATA_BOARD_SHARE: AppRouteRecordRaw = {
  82 + path: DATA_BOARD_SHARE_URL(),
  83 + name: 'dataBoardSharePage',
  84 + component: () => import('/@/views/data/board/detail/index.vue'),
  85 + meta: {
  86 + ignoreAuth: true,
  87 + title: '分享看板',
  88 + },
  89 +};
... ...
1 1 import type { AppRouteRecordRaw, AppRouteModule } from '/@/router/types';
2   -import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/routes/basic';
  2 +import { DATA_BOARD_SHARE, PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/routes/basic';
3 3 import { mainOutRoutes } from './mainOut';
4 4 import { PageEnum } from '/@/enums/pageEnum';
5 5 import { t } from '/@/hooks/web/useI18n';
... ... @@ -85,4 +85,5 @@ export const basicRoutes = [
85 85 ...mainOutRoutes,
86 86 REDIRECT_ROUTE,
87 87 PAGE_NOT_FOUND_ROUTE,
  88 + DATA_BOARD_SHARE,
88 89 ];
... ...
... ... @@ -8,3 +8,11 @@ export enum MoreActionEvent {
8 8
9 9 export const DEFAULT_WIDGET_WIDTH = 6;
10 10 export const DEFAULT_WIDGET_HEIGHT = 6;
  11 +
  12 +export const DATA_BOARD_SHARE_URL = (boardId = ':boardId', tenantId = ':tenantId') =>
  13 + `/data/board/share/${boardId}/${tenantId}`;
  14 +
  15 +export const isBataBoardSharePage = (url: string) => {
  16 + const reg = /^\/data\/board\/share/g;
  17 + return reg.test(url);
  18 +};
... ...
1 1 <script lang="ts" setup>
2 2 import { Button, PageHeader, Empty, Spin, Tooltip } from 'ant-design-vue';
3   - import { LineChartOutlined } from '@ant-design/icons-vue';
  3 + import { LineChartOutlined, RollbackOutlined } from '@ant-design/icons-vue';
4 4 import { GridItem, GridLayout } from 'vue3-grid-layout';
5 5 import { nextTick, onMounted, ref } from 'vue';
6 6 import WidgetWrapper from '../components/WidgetWrapper/WidgetWrapper.vue';
... ... @@ -8,11 +8,17 @@
8 8 import { DropMenu } from '/@/components/Dropdown';
9 9 import DataBindModal from './components/DataBindModal.vue';
10 10 import { useModal } from '/@/components/Modal';
11   - import { DEFAULT_WIDGET_HEIGHT, DEFAULT_WIDGET_WIDTH, MoreActionEvent } from '../config/config';
  11 + import {
  12 + DEFAULT_WIDGET_HEIGHT,
  13 + DEFAULT_WIDGET_WIDTH,
  14 + isBataBoardSharePage,
  15 + MoreActionEvent,
  16 + } from '../config/config';
12 17 import {
13 18 addDataComponent,
14 19 deleteDataComponent,
15 20 getDataComponent,
  21 + getShareBoardComponentInfo,
16 22 updateDataBoardLayout,
17 23 } from '/@/api/dataBoard';
18 24 import { useRoute, useRouter } from 'vue-router';
... ... @@ -33,21 +39,32 @@
33 39 const ROUTER = useRouter();
34 40
35 41 const { createMessage, createConfirm } = useMessage();
  42 +
36 43 const getBoardId = computed(() => {
37 44 return (ROUTE.params as { id: string }).id;
38 45 });
39 46
  47 + const getSharePageParams = computed(() => {
  48 + const { boardId, tenantId } = ROUTE.params as { boardId: string; tenantId: string };
  49 + return { boardId, tenantId };
  50 + });
  51 +
  52 + const getIsSharePage = computed(() => {
  53 + return isBataBoardSharePage(ROUTE.path);
  54 + });
  55 +
40 56 const widgetEl = new Map<string, Fn>();
41 57
42 58 const dataBoardList = ref<DataBoardLayoutInfo[]>([]);
43 59
44   - const draggable = ref(true);
45   - const resizable = ref(true);
  60 + const draggable = ref(!unref(getIsSharePage));
  61 + const resizable = ref(!unref(getIsSharePage));
46 62
47 63 const GirdLayoutColNum = 24;
48 64 const GridLayoutMargin = 10;
49 65
50 66 const handleBack = () => {
  67 + if (unref(getIsSharePage)) return;
51 68 ROUTER.go(-1);
52 69 };
53 70
... ... @@ -168,12 +185,36 @@
168 185
169 186 const { beginSendMessage } = useSocketConnect(dataBoardList);
170 187
  188 + const getBasePageComponentData = async () => {
  189 + try {
  190 + return await getDataComponent(unref(getBoardId));
  191 + } catch (error) {}
  192 + return [];
  193 + };
  194 +
  195 + const getSharePageComponentData = async () => {
  196 + try {
  197 + const params = unref(getSharePageParams);
  198 + return await getShareBoardComponentInfo(params);
  199 + } catch (error) {}
  200 + return [];
  201 + };
  202 +
  203 + const getDataBoradDetail = async () => {
  204 + try {
  205 + return unref(getIsSharePage)
  206 + ? await getSharePageComponentData()
  207 + : await getBasePageComponentData();
  208 + } catch (error) {}
  209 + return [];
  210 + };
  211 +
171 212 const loading = ref(false);
172 213 const getDataBoardComponent = async () => {
173 214 try {
174 215 // dataBoardList.value = [];
175 216 loading.value = true;
176   - const data = await getDataComponent(unref(getBoardId));
  217 + const data = await getDataBoradDetail();
177 218 dataBoardList.value = data.data.componentData.map((item) => {
178 219 const index = data.data.componentLayout.findIndex((each) => item.id === each.id);
179 220 let layout;
... ... @@ -258,10 +299,18 @@
258 299
259 300 <template>
260 301 <section class="bg-light-50 flex flex-col overflow-hidden h-full w-full">
261   - <PageHeader title="水电表看板" @back="handleBack">
  302 + <PageHeader>
  303 + <template #title>
  304 + <div class="flex items-center">
  305 + <RollbackOutlined v-if="!getIsSharePage" class="mr-3" @click="handleBack" />
  306 + <span>看板名称</span>
  307 + </div>
  308 + </template>
262 309 <template #extra>
263 310 <Authority value="api:yt:dataBoardDetail:post">
264   - <Button type="primary" @click="handleOpenCreatePanel">创建组件</Button>
  311 + <Button v-if="!getIsSharePage" type="primary" @click="handleOpenCreatePanel"
  312 + >创建组件</Button
  313 + >
265 314 </Authority>
266 315 </template>
267 316 <div>
... ... @@ -313,6 +362,7 @@
313 362 <template #moreAction>
314 363 <Tooltip title="趋势">
315 364 <LineChartOutlined
  365 + v-if="!getIsSharePage"
316 366 class="cursor-pointer mx-1"
317 367 @click="handleOpenHistroyDataModal(item.record.dataSource)"
318 368 />
... ...
... ... @@ -100,7 +100,6 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) {
100 100 const transformSocketMessageItem = () => {
101 101 const messageList: SocketMessageItem[] = [];
102 102 let index = 0;
103   - console.log(unref(dataSourceRef));
104 103 unref(dataSourceRef).forEach((record, recordIndex) => {
105 104 const componentId = record.record.id;
106 105 record.record.dataSource.forEach((dataSource, dataSourceIndex) => {
... ...
... ... @@ -7,7 +7,7 @@
7 7 import { useMessage } from '/@/hooks/web/useMessage';
8 8 import Dropdown from '/@/components/Dropdown/src/Dropdown.vue';
9 9 import { DropMenu } from '/@/components/Dropdown';
10   - import { MoreActionEvent } from './config/config';
  10 + import { DATA_BOARD_SHARE_URL, MoreActionEvent } from './config/config';
11 11 import { useModal } from '/@/components/Modal';
12 12 import PanelDetailModal from './components/PanelDetailModal.vue';
13 13 import { getDataBoardList, deleteDataBoard } from '/@/api/dataBoard';
... ... @@ -50,9 +50,14 @@
50 50 pageSize.value = size;
51 51 }
52 52
  53 + const createShareUrl = (boardId: string, tenantId: string) => {
  54 + const { origin } = location;
  55 + return `${origin}${DATA_BOARD_SHARE_URL(boardId, tenantId)}`;
  56 + };
  57 +
53 58 const { clipboardRef } = useCopyToClipboard();
54 59 const handleCopyShareUrl = (record: DataBoardRecord) => {
55   - clipboardRef.value = record.openUrl;
  60 + clipboardRef.value = createShareUrl(record.id, record.tenantId);
56 61 unref(clipboardRef) ? createMessage.success('复制成功') : createMessage.error('未找到分享链接');
57 62 };
58 63
... ...