diff --git a/frontend/src/enums/routeEnum.ts b/frontend/src/enums/routeEnum.ts index c56c2750c8..0c1e7cec9f 100644 --- a/frontend/src/enums/routeEnum.ts +++ b/frontend/src/enums/routeEnum.ts @@ -108,6 +108,7 @@ export enum SettingRouteEnum { export enum ShareEnum { SHARE = 'share', SHARE_REPORT_SCENARIO = 'shareReportScenario', + SHARE_DEFINITION_API = 'shareDefinitionApi', SHARE_REPORT_CASE = 'shareReportCase', SHARE_REPORT_TEST_PLAN = 'shareReportTestPlan', } diff --git a/frontend/src/router/constants.ts b/frontend/src/router/constants.ts index b4914ee808..752e72543e 100644 --- a/frontend/src/router/constants.ts +++ b/frontend/src/router/constants.ts @@ -21,6 +21,11 @@ export const WHITE_LIST = [ path: '/shareReportTestPlan', children: [], }, + { + name: 'shareDefinitionApi', + path: '/shareDefinitionApi', + children: [], + }, ], }, { @@ -38,6 +43,11 @@ export const WHITE_LIST = [ path: '/shareReportTestPlan', children: [], }, + { + name: 'shareDefinitionApi', + path: '/shareDefinitionApi', + children: [], + }, ]; // 左侧菜单底部对齐的菜单数组,数组项为一级路由的name diff --git a/frontend/src/router/routes/modules/share.ts b/frontend/src/router/routes/modules/share.ts index 3183ec7f69..066fa36089 100644 --- a/frontend/src/router/routes/modules/share.ts +++ b/frontend/src/router/routes/modules/share.ts @@ -46,6 +46,17 @@ const ShareRoute: AppRouteRecordRaw = { isTopMenu: false, }, }, + // 接口文档分享 + { + path: 'shareDefinitionApi', + name: ShareEnum.SHARE_DEFINITION_API, + component: () => import('@/views/api-test/management/components/management/api/shareApiDocIndex.vue'), + meta: { + locale: '', + roles: ['*'], + isTopMenu: false, + }, + }, ], }; diff --git a/frontend/src/views/api-test/management/components/management/api/apiSharePreview.vue b/frontend/src/views/api-test/management/components/management/api/apiSharePreview.vue index e5dd52d7ef..06829e46de 100644 --- a/frontend/src/views/api-test/management/components/management/api/apiSharePreview.vue +++ b/frontend/src/views/api-test/management/components/management/api/apiSharePreview.vue @@ -1,5 +1,5 @@ + + + + diff --git a/frontend/src/views/api-test/management/components/management/api/shareButton.vue b/frontend/src/views/api-test/management/components/management/api/shareButton.vue index a8ccb57753..47dc392e6c 100644 --- a/frontend/src/views/api-test/management/components/management/api/shareButton.vue +++ b/frontend/src/views/api-test/management/components/management/api/shareButton.vue @@ -67,11 +67,11 @@ import { useAppStore } from '@/store'; import type { shareItem } from '@/models/apiTest/management'; + import { RouteEnum } from '@/enums/routeEnum'; const appStore = useAppStore(); const { copy, isSupported } = useClipboard({ legacy: true }); - const { t } = useI18n(); const emit = defineEmits<{ @@ -133,9 +133,9 @@ } if (isSupported) { // 判断路由中是不是有dId参数,有的话只是修改当前的值就可以了 - const url = window.location.href; - const dIdParam = `&docShareId=${item.id}`; - copy(`${url}${dIdParam}`); + const shareLinkUrl = `${origin}/#/${RouteEnum.SHARE}/${RouteEnum.SHARE_DEFINITION_API}`; + const dIdParam = `?orgId=${appStore.currentOrgId}&pId=${appStore.currentProjectId}&docShareId=${item.id}`; + copy(`${shareLinkUrl}${dIdParam}`); Message.success(t('apiTestManagement.shareUrlCopied')); } else { Message.error(t('common.copyNotSupport')); diff --git a/frontend/src/views/api-test/management/components/management/api/shareListDrawer.vue b/frontend/src/views/api-test/management/components/management/api/shareListDrawer.vue index 71471fe410..bc72d55740 100644 --- a/frontend/src/views/api-test/management/components/management/api/shareListDrawer.vue +++ b/frontend/src/views/api-test/management/components/management/api/shareListDrawer.vue @@ -78,7 +78,7 @@ import { hasAnyPermission } from '@/utils/permission'; import type { ShareDetail, shareItem } from '@/models/apiTest/management'; - import { ApiTestRouteEnum } from '@/enums/routeEnum'; + import { ShareEnum } from '@/enums/routeEnum'; import { TableKeyEnum } from '@/enums/tableEnum'; import { FilterRemoteMethodsEnum } from '@/enums/tableFilterEnum'; @@ -189,7 +189,7 @@ // 查看链接 function viewLink(record: shareItem) { - openNewPage(ApiTestRouteEnum.API_TEST_MANAGEMENT, { + openNewPage(ShareEnum.SHARE_DEFINITION_API, { docShareId: record.id, }); } diff --git a/frontend/src/views/api-test/management/components/moduleTree.vue b/frontend/src/views/api-test/management/components/moduleTree.vue index 86cef88ab0..471153c764 100644 --- a/frontend/src/views/api-test/management/components/moduleTree.vue +++ b/frontend/src/views/api-test/management/components/moduleTree.vue @@ -268,14 +268,14 @@ const virtualListProps = computed(() => { if (props.readOnly || props.isModal) { return { - height: props.docShareId ? 'calc(60vh - 150px)' : 'calc(60vh - 190px)', + height: 'calc(60vh - 190px)', threshold: 200, fixedSize: true, buffer: 15, // 缓冲区默认 10 的时候,虚拟滚动的底部 padding 计算有问题 }; } return { - height: props.docShareId ? 'calc(100vh - 233px)' : 'calc(100vh - 273px)', + height: props.docShareId ? 'calc(100vh - 150px)' : 'calc(100vh - 273px)', threshold: 200, fixedSize: true, buffer: 15, // 缓冲区默认 10 的时候,虚拟滚动的底部 padding 计算有问题 diff --git a/frontend/src/views/api-test/management/index.vue b/frontend/src/views/api-test/management/index.vue index c7dfba6e41..0a1f7d97e7 100644 --- a/frontend/src/views/api-test/management/index.vue +++ b/frontend/src/views/api-test/management/index.vue @@ -7,7 +7,6 @@
@@ -36,7 +33,6 @@ - - - @@ -126,28 +68,20 @@ */ import { provide } from 'vue'; import { useRoute, useRouter } from 'vue-router'; - import { FormInstance, Message } from '@arco-design/web-vue'; import MsCard from '@/components/pure/ms-card/index.vue'; import MsSplitBox from '@/components/pure/ms-split-box/index.vue'; - import type { BatchActionQueryParams } from '@/components/pure/ms-table/type'; import { RequestParam } from '../components/requestComposition/index.vue'; import importApi from './components/import.vue'; import importTaskDrawer from './components/importTaskDrawer.vue'; import management from './components/management/index.vue'; import moduleTree from './components/moduleTree.vue'; - import ApiExportModal from '@/views/api-test/management/components/management/api/apiExportModal.vue'; - import ApiSharePreview from '@/views/api-test/management/components/management/api/apiSharePreview.vue'; - import { getProtocolList } from '@/api/modules/api-test/common'; - import { checkSharePsd, getTrashModuleCount, shareDetail } from '@/api/modules/api-test/management'; + import { getTrashModuleCount } from '@/api/modules/api-test/management'; import { useI18n } from '@/hooks/useI18n'; - import { NOT_FOUND_RESOURCE } from '@/router/constants'; - import { useUserStore } from '@/store'; - import useDocShareCheckStore from '@/store/modules/api/docShareCheck'; import useAppStore from '@/store/modules/app'; - import { ApiDefinitionGetModuleParams, ShareDetailType } from '@/models/apiTest/management'; + import { ApiDefinitionGetModuleParams } from '@/models/apiTest/management'; import { ModuleTreeNode } from '@/models/common'; import { ApiTestRouteEnum } from '@/enums/routeEnum'; @@ -155,8 +89,6 @@ const route = useRoute(); const { t } = useI18n(); const router = useRouter(); - const docCheckStore = useDocShareCheckStore(); - const userStore = useUserStore(); const activeModule = ref('all'); const folderTree = ref([]); @@ -190,20 +122,6 @@ } } - const protocols = ref([]); - async function initProtocolList() { - try { - protocols.value = await getProtocolList(appStore.currentOrgId); - } catch (error) { - // eslint-disable-next-line no-console - console.log(error); - } - } - - onBeforeMount(() => { - initProtocolList(); - }); - function handleProtocolChange(val: string[]) { selectedProtocols.value = val; } @@ -284,153 +202,8 @@ moduleTreeRef.value?.setActiveFolder('all'); } - const checkLoading = ref(false); - const checkPsdModal = ref(false); - const checkForm = ref({ - docShareId: route.query.docShareId as string, - password: '', - }); - - const validatePassword = (value: string | undefined, callback: (error?: string) => void) => { - const sixDigitRegex = /^\d{6}$/; - - if (value === undefined || value === '') { - callback(t('apiTestManagement.enterPassword')); - } else if (!sixDigitRegex.test(value)) { - callback(t('apiTestManagement.enterPassword')); - } else { - callback(); - } - }; - - const rules = { - password: [ - { - required: true, - message: t('apiTestManagement.sharePasswordPlaceholder'), - }, - { - validator: validatePassword, - }, - ], - }; - - // 上一条|下一条 - function toggleDetail(type: string) { - if (type === 'prev') { - moduleTreeRef.value?.previousApi(); - } else { - moduleTreeRef.value?.nextApi(); - } - } - const formRef = ref(); - - // 关闭分享 - function closeShareHandler() { - checkPsdModal.value = false; - formRef.value?.resetFields(); - checkForm.value.password = ''; - } - const currentNode = ref(); - - const showExportModal = ref(false); - const batchParams = ref({ - selectedIds: [], - selectAll: false, - excludeIds: [], - }); - - // 导出全部|导出单个 - function handleExportShare(all: boolean) { - batchParams.value.selectAll = all; - batchParams.value.selectedIds = all ? [] : [currentNode.value?.id]; - showExportModal.value = true; - } - - function getConditionParams() { - return { - condition: { - keyword: '', - filter: {}, - viewId: '', - }, - projectId: appStore.currentProjectId, - protocols: selectedProtocols.value, - moduleIds: [], - shareId: docShareId.value, - }; - } - - const shareDetailInfo = ref({ - invalid: false, - allowExport: false, - isPrivate: false, - }); - - // 获取分享详情 - async function getShareDetail() { - try { - shareDetailInfo.value = await shareDetail(docShareId.value); - // 资源无效 - if (shareDetailInfo.value.invalid) { - router.push({ - name: NOT_FOUND_RESOURCE, - query: { - type: 'EXPIRED', - }, - }); - } - // 限制访问校验 - if (shareDetailInfo.value.isPrivate && !docCheckStore.isDocVerified(docShareId.value, userStore.id || '')) { - checkPsdModal.value = true; - } - } catch (error) { - // eslint-disable-next-line no-console - console.log(error); - } - } - - const previousNode = ref(); - const nextNode = ref(); - - // 设置当前预览节点 - function openCurrentNode(node: ModuleTreeNode, apiNodes: ModuleTreeNode[]) { - const index = apiNodes.indexOf(node); - currentNode.value = node; - previousNode.value = index > 0 ? apiNodes[index - 1] : null; - nextNode.value = index < apiNodes.length - 1 ? apiNodes[index + 1] : null; - } - - // 校验密码 - function handleCheckPsd() { - formRef.value?.validate(async (errors) => { - if (!errors) { - try { - checkLoading.value = true; - const res = await checkSharePsd(checkForm.value); - if (res) { - closeShareHandler(); - // 标记为已验证 - docCheckStore.markDocAsVerified(docShareId.value, userStore.id || ''); - checkPsdModal.value = false; - } else { - Message.error(t('apiTestManagement.apiSharePsdError')); - } - } catch (error) { - // eslint-disable-next-line no-console - console.log(error); - } finally { - checkLoading.value = false; - } - } - }); - } - const taskDrawerVisible = ref(false); onBeforeMount(() => { - if (docShareId.value) { - getShareDetail(); - } if (route.query.taskDrawer) { taskDrawerVisible.value = true; } @@ -441,8 +214,6 @@ provide('refreshModuleTree', refreshModuleTree); provide('refreshModuleTreeCount', refreshModuleTreeCount); provide('folderTreePathMap', folderTreePathMap.value); - provide('docShareId', docShareId.value); - provide('shareDetailInfo', shareDetailInfo);