fix(公共脚本): 引用公共脚本每次更新最新脚本内容

--bug=1046248 --user=白奇 【项目设置】公共脚本修改,场景内引用脚步未同步更新 https://www.tapd.cn/55049933/s/1592511
This commit is contained in:
baiqi 2024-10-16 10:26:26 +08:00 committed by Craftsman
parent e7d4278079
commit 555c31b917
4 changed files with 35 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import {
GetCommonScriptDetailUrl,
GetCommonScriptPageUrl,
GetCommonScriptStatusUrl,
getCommonScriptUrl,
GetCustomFuncColumnsOptionUrl,
GetFormApiImportModuleCountUrl,
GetFormApiImportPageListUrl,
@ -17,6 +18,7 @@ import {
UpdateCommonScriptUrl,
} from '@/api/requrls/project-management/commonScript';
import type { CommonScriptInfo } from '@/models/apiTest/common';
import type { ModulesTreeType } from '@/models/caseManagement/featureCase';
import { CommonList, TableQueryParams } from '@/models/common';
import type {
@ -114,3 +116,8 @@ export const apiSocket = (url: string, host?: string) => {
export function getSocket(reportId: string | number, socketUrl?: string, host?: string) {
return apiSocket(`${socketUrl || ConnectionWebsocketUrl}/${reportId}`, host);
}
// 获取单个公共脚本详情
export function getCommonScript(scriptId: string) {
return MSR.get<CommonScriptInfo>({ url: `${getCommonScriptUrl}/${scriptId}` });
}

View File

@ -29,3 +29,5 @@ export const TestScriptUrl = '/api/test/custom/func/run';
export const ConnectionWebsocketUrl = '/ws/api';
// 公共脚本变更历史详情
export const getChangeHistoryUrl = '/project/custom/func/history/page';
// 获取单个公共脚本详情
export const getCommonScriptUrl = '/api/test/common-script';

View File

@ -194,19 +194,20 @@ export type ResponseRegexAssertionItem = Pick<ResponseAssertionItem, 'expression
// 断言-Xpath断言子项
export type ResponseXPathAssertionItem = Pick<ResponseAssertionItem, 'expression' | 'expectedValue'>;
// 脚本公共配置
export interface CommonScriptInfo {
id: string; // 公共脚本id
name: string; // 公共脚本名称
script: string; // 公共脚本内容
params: KeyValueParam[]; // 公共脚本参数
scriptLanguage: Language; // 脚本语言
}
export interface ScriptCommonConfig {
enableCommonScript: boolean; // 是否启用公共脚本
script: string; // 脚本内容
scriptId: string; // 脚本id
scriptName: string; // 脚本名称
scriptLanguage: Language; // 脚本语言
commonScriptInfo: {
id: string; // 公共脚本id
name: string; // 公共脚本名称
script: string; // 公共脚本内容
params: KeyValueParam[]; // 公共脚本参数
scriptLanguage: Language; // 脚本语言
}; // 公共脚本信息
commonScriptInfo: CommonScriptInfo; // 公共脚本信息
}
// 断言-响应体断言
export interface ResponseBodyAssertion {

View File

@ -495,6 +495,7 @@
import quoteSqlSourceDrawer from '../quoteSqlSourceDrawer.vue';
import { getProtocolList } from '@/api/modules/api-test/common';
import { getCommonScript } from '@/api/modules/project-management/commonScript';
import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal';
import useAppStore from '@/store/modules/app';
@ -580,6 +581,19 @@
}
}
async function getCommonScriptLatest() {
if (!condition.value.commonScriptInfo?.id) {
return;
}
try {
const res = await getCommonScript(condition.value.commonScriptInfo.id);
condition.value.commonScriptInfo = res;
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
}
watch(
() => appStore.currentEnvConfig?.id,
() => {
@ -595,6 +609,7 @@
() => condition.value.id,
() => {
filterDataSource();
getCommonScriptLatest();
}
);
@ -1016,6 +1031,9 @@
}
}
});
onMounted(() => {
getCommonScriptLatest();
});
watch(
() => condition.value.commonScriptInfo,
(info) => {