index.vue
2.88 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
<script lang="ts" setup>
import { onMounted } from 'vue';
import { BasicModal, useModal } from '/@/components/Modal';
import { Spin } from 'ant-design-vue';
import { ref } from 'vue';
import { useRoute } from 'vue-router';
import { checkShareAccessToken, sharePageLogin, getShareContent } from '/@/api/sys/share';
import { ShareRouteParams } from '/@/api/sys/model/shareModel';
import { useUserStore } from '/@/store/modules/user';
import { BasicForm, useForm } from '/@/components/Form';
import { FieldsEnum } from '../../visual/board/config/share';
import BoardDetail from '/@/views/visual/board/detail/index.vue';
const loading = ref(true);
const ROUTE = useRoute();
const contentData = ref<any>();
const canLoadComponent = ref(false);
const [register, { openModal }] = useModal();
const [registerForm, { getFieldsValue }] = useForm({
schemas: [
{
field: FieldsEnum.ACCESS_CREDENTIALS,
component: 'Input',
label: '访问令牌',
},
],
showActionButtonGroup: false,
layout: 'inline',
labelWidth: 100,
});
const userStore = useUserStore();
const getShareToken = async () => {
const { params } = ROUTE;
const { publicId } = params as Partial<ShareRouteParams>;
const { token, refreshToken } = await sharePageLogin(publicId!);
userStore.storeToken(token, refreshToken);
};
const getCheckNeedAccessToken = async () => {
const { params } = ROUTE;
loading.value = true;
const { viewType, id } = params as Partial<ShareRouteParams>;
const { data } = await checkShareAccessToken(viewType!, id!);
data ? openModal(data) : await getContentData();
};
const getContentLoading = ref(false);
const getContentData = async () => {
try {
getContentLoading.value = true;
const { params } = ROUTE;
const { id } = params as unknown as ShareRouteParams;
const value = getFieldsValue() as Record<'accessCredentials', string>;
const result = await getShareContent({ id, ...value });
contentData.value = result;
loading.value = false;
canLoadComponent.value = true;
openModal(false);
} catch (error) {
} finally {
getContentLoading.value = false;
}
};
const handleSubmit = async () => {
await getContentData();
};
onMounted(async () => {
await getShareToken();
await getCheckNeedAccessToken();
});
</script>
<template>
<BasicModal
@register="register"
title="公开"
@ok="handleSubmit"
:showCancelBtn="false"
:okButtonProps="{ loading: getContentLoading }"
>
<BasicForm @register="registerForm" />
</BasicModal>
<Spin
:spinning="loading"
tip="正在加载中..."
size="large"
class="!flex justify-center items-center w-full h-full share-full-loading"
>
<BoardDetail v-if="canLoadComponent" :value="contentData" />
</Spin>
</template>
<style lang="less" scoped></style>