fix(接口测试): 修复修改本地执行但case页面的执行方式未更新的缺陷

This commit is contained in:
teukkk 2024-04-01 14:13:16 +08:00 committed by Craftsman
parent 4db6d5a4c6
commit 7927527502
5 changed files with 51 additions and 30 deletions

View File

@ -122,6 +122,7 @@
}
const { height } = useWindowSize();
appStore.innerHeight = height.value;
await userStore.initLocalConfig(); //
});
/** 屏幕大小改变时重新赋值innerHeight */
useEventListener(window, 'resize', () => {

View File

@ -126,10 +126,13 @@
validLocalConfig,
} from '@/api/modules/user/index';
import { useI18n } from '@/hooks/useI18n';
import { useUserStore } from '@/store';
import { UserState } from '@/store/modules/user/types';
import { LocalConfig } from '@/models/user';
const { t } = useI18n();
const userStore = useUserStore();
type Status = 0 | 1 | 2 | 'none'; // 0 1 2
interface TagMapItem {
@ -167,6 +170,10 @@
status: 0,
});
function updateLocalConfigStore(partial: Partial<UserState>) {
userStore.updateLocalConfig(partial);
}
function clearApi() {
apiConfig.value.userUrl = '';
if (apiConfig.value.id) {
@ -177,6 +184,11 @@
});
disableLocalConfig(apiConfig.value.id);
apiConfig.value.enable = false;
updateLocalConfigStore({
hasLocalExec: false,
isPriorityLocalExec: false,
localExecuteUrl: apiConfig.value.userUrl.trim(),
});
Message.success(t('common.updateSuccess'));
}
}
@ -204,6 +216,7 @@
});
apiConfig.value.id = result.id;
}
updateLocalConfigStore({ hasLocalExec: true, localExecuteUrl: apiConfig.value.userUrl.trim() });
Message.success(t('ms.personal.testPass'));
} else {
Message.error(t('ms.personal.testFail'));
@ -223,6 +236,7 @@
} else {
await disableLocalConfig(apiConfig.value.id);
}
updateLocalConfigStore({ isPriorityLocalExec: val as boolean });
Message.success(val ? t('ms.personal.apiLocalExecutionOpen') : t('ms.personal.apiLocalExecutionClose'));
return true;
} catch (error) {

View File

@ -2,6 +2,7 @@ import { defineStore } from 'pinia';
import {
getAuthenticationList,
getLocalConfig,
isLogin as userIsLogin,
login as userLogin,
logout as userLogout,
@ -42,6 +43,9 @@ const useUserStore = defineStore('user', {
userRoles: [],
userRoleRelations: [],
loginType: [],
hasLocalExec: false, // 是否配置了api本地执行
isPriorityLocalExec: false, // 是否优先本地执行
localExecuteUrl: '',
}),
getters: {
@ -160,6 +164,25 @@ const useUserStore = defineStore('user', {
return false;
}
},
// 更新本地设置
updateLocalConfig(partial: Partial<UserState>) {
this.$patch(partial);
},
// 获取本地执行配置
async initLocalConfig() {
try {
const res = await getLocalConfig();
const apiLocalExec = res.find((e) => e.type === 'API');
if (apiLocalExec) {
this.hasLocalExec = true;
this.isPriorityLocalExec = apiLocalExec.enable || false;
this.localExecuteUrl = apiLocalExec.userUrl || '';
}
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
},
},
});

View File

@ -12,6 +12,11 @@ export interface UserRole {
type: SystemScopeType;
}
export interface permissionsItem {
id: string;
permissionId: string;
roleId: string;
}
export interface UserRoleRelation {
id: string;
userId: string;
@ -24,11 +29,6 @@ export interface UserRoleRelation {
userRole: UserRole;
}
export interface permissionsItem {
id: string;
permissionId: string;
roleId: string;
}
export interface UserRolePermissions {
userRole: UserRole;
userRolePermissions: permissionsItem[];
@ -56,4 +56,7 @@ export interface UserState {
userRoles?: UserRole[];
userRoleRelations?: UserRoleRelation[];
loginType: string[];
hasLocalExec?: boolean; // 是否配置了api本地执行
isPriorityLocalExec?: boolean; // 是否优先本地执行
localExecuteUrl?: string;
}

View File

@ -26,7 +26,7 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { getLocalConfig } from '@/api/modules/user/index';
import { useUserStore } from '@/store';
const props = defineProps<{
executeLoading?: boolean;
@ -38,31 +38,11 @@
}>();
const { t } = useI18n();
const userStore = useUserStore();
const hasLocalExec = ref(false); // api
const isPriorityLocalExec = ref(false); //
const localExecuteUrl = ref('');
async function initLocalConfig() {
if (hasLocalExec.value) {
return;
}
try {
const res = await getLocalConfig();
const apiLocalExec = res.find((e) => e.type === 'API');
if (apiLocalExec) {
hasLocalExec.value = true;
isPriorityLocalExec.value = apiLocalExec.enable || false;
localExecuteUrl.value = apiLocalExec.userUrl || '';
}
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
}
onBeforeMount(() => {
initLocalConfig();
});
const hasLocalExec = computed(() => userStore.hasLocalExec); // api
const isPriorityLocalExec = computed(() => userStore.isPriorityLocalExec); //
const localExecuteUrl = computed(() => userStore.localExecuteUrl);
async function execute(executeType?: 'localExec' | 'serverExec') {
emit('execute', executeType, localExecuteUrl.value);