feat(系统设置): 资源池命名调整&穿梭框组件调整&请求携带本地语言

This commit is contained in:
baiqi 2023-08-25 15:55:17 +08:00 committed by 刘瑞斌
parent e1d62bf8c8
commit 896a58a5eb
8 changed files with 31 additions and 24 deletions

View File

@ -6,6 +6,7 @@ import { isString } from '@/utils/is';
import { getToken } from '@/utils/auth'; import { getToken } from '@/utils/auth';
import { setObjToUrlParams, deepMerge } from '@/utils'; import { setObjToUrlParams, deepMerge } from '@/utils';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useLocale from '@/locale/useLocale';
import { joinTimestamp } from './helper'; import { joinTimestamp } from './helper';
import type { AxiosResponse } from 'axios'; import type { AxiosResponse } from 'axios';
@ -110,10 +111,17 @@ const transform: AxiosTransform = {
*/ */
requestInterceptors: (config) => { requestInterceptors: (config) => {
// 请求之前处理config // 请求之前处理config
const { currentLocale } = useLocale();
const token = getToken(); const token = getToken();
if (token && (config as Recordable)?.requestOptions?.withToken !== false) { if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
const { sessionId, csrfToken } = token; const { sessionId, csrfToken } = token;
(config as Recordable).headers = { 'X-AUTH-TOKEN': sessionId, 'CSRF-TOKEN': csrfToken };
(config as Recordable).headers = {
...config.headers,
'X-AUTH-TOKEN': sessionId,
'CSRF-TOKEN': csrfToken,
'Accept-Language': currentLocale.value,
};
} }
return config; return config;
}, },

View File

@ -5,12 +5,12 @@
:data="transferData" :data="transferData"
show-search show-search
> >
<template #source="{ data: tData, selectedKeys, onSelect }"> <template #source="{ selectedKeys, onSelect }">
<a-tree <a-tree
:checkable="true" :checkable="true"
checked-strategy="child" checked-strategy="child"
:checked-keys="selectedKeys" :checked-keys="selectedKeys"
:data="getTreeData(tData)" :data="getTreeData()"
block-node block-node
@check="onSelect" @check="onSelect"
/> />
@ -96,9 +96,7 @@
/** /**
* 获取树结构数据根据穿梭框过滤的数据获取 * 获取树结构数据根据穿梭框过滤的数据获取
*/ */
const getTreeData = (data: TransferDataItem[]) => { const getTreeData = () => {
const values = data.map((item) => item[props.treeFiled.key]);
const travel = (_treeData: TreeDataItem[]) => { const travel = (_treeData: TreeDataItem[]) => {
const treeDataSource: TreeDataItem[] = []; const treeDataSource: TreeDataItem[] = [];
_treeData.forEach((item) => { _treeData.forEach((item) => {
@ -111,7 +109,7 @@
Array.isArray(itemChildren) && Array.isArray(itemChildren) &&
itemChildren.length > 0 && itemChildren.length > 0 &&
itemChildren?.every((child: TreeDataItem) => innerTarget.value.includes(child[props.treeFiled.key])); itemChildren?.every((child: TreeDataItem) => innerTarget.value.includes(child[props.treeFiled.key]));
if (!allSelected && !innerTarget.value.includes(itemKey) && (itemChildren || values.includes(itemKey))) { if (!allSelected && !innerTarget.value.includes(itemKey)) {
// //
treeDataSource.push({ treeDataSource.push({
title: itemTitle, title: itemTitle,

View File

@ -53,6 +53,7 @@ async function changeLocale(locale: LocaleType) {
loadLocalePool.push(locale); loadLocalePool.push(locale);
setI18nLanguage(locale); setI18nLanguage(locale);
window.location.reload();
return locale; return locale;
} }

View File

@ -19,7 +19,7 @@ export interface TestResourceDTO {
nodesList: NodesListItem[]; // node资源 nodesList: NodesListItem[]; // node资源
ip: string; // k8s ip ip: string; // k8s ip
token: string; // k8s token token: string; // k8s token
nameSpaces: string; // k8s 命名空间 namespace: string; // k8s 命名空间
concurrentNumber: number; // k8s 最大并发数 concurrentNumber: number; // k8s 最大并发数
podThreads: number; // k8s 单pod最大线程数 podThreads: number; // k8s 单pod最大线程数
jobDefinition: string; // k8s job自定义模板 jobDefinition: string; // k8s job自定义模板

View File

@ -235,14 +235,14 @@
/> />
</a-form-item> </a-form-item>
<a-form-item <a-form-item
:label="t('system.resourcePool.testResourceDTO.nameSpaces')" :label="t('system.resourcePool.testResourceDTO.namespace')"
field="testResourceDTO.nameSpaces" field="testResourceDTO.namespace"
class="form-item" class="form-item"
:rules="[{ required: true, message: t('system.resourcePool.testResourceDTO.nameSpacesRequired') }]" :rules="[{ required: true, message: t('system.resourcePool.testResourceDTO.nameSpacesRequired') }]"
asterisk-position="end" asterisk-position="end"
> >
<a-input <a-input
v-model:model-value="form.testResourceDTO.nameSpaces" v-model:model-value="form.testResourceDTO.namespace"
:placeholder="t('system.resourcePool.testResourceDTO.nameSpacesPlaceholder')" :placeholder="t('system.resourcePool.testResourceDTO.nameSpacesPlaceholder')"
:max-length="250" :max-length="250"
class="mr-[8px] flex-1" class="mr-[8px] flex-1"
@ -379,7 +379,7 @@
nodesList: [] as NodesListItem[], nodesList: [] as NodesListItem[],
ip: '', ip: '',
token: '', token: '',
nameSpaces: '', namespace: '',
jobDefinition: job, jobDefinition: job,
deployName: '', deployName: '',
orgIds: [] as string[], orgIds: [] as string[],
@ -483,7 +483,7 @@
// K8S // K8S
const isShowK8SResources = computed(() => form.value.type === 'Kubernetes' && isShowTypeItem.value); const isShowK8SResources = computed(() => form.value.type === 'Kubernetes' && isShowTypeItem.value);
// //
const isFillNameSpaces = computed(() => form.value.testResourceDTO.nameSpaces?.trim() !== ''); const isFillNameSpaces = computed(() => form.value.testResourceDTO.namespace?.trim() !== '');
// Deploy Name // Deploy Name
const isFillNameSpacesAndDeployName = computed( const isFillNameSpacesAndDeployName = computed(
() => isFillNameSpaces.value && form.value.testResourceDTO.deployName?.trim() !== '' () => isFillNameSpaces.value && form.value.testResourceDTO.deployName?.trim() !== ''
@ -630,7 +630,7 @@
function downloadYaml(type: YamlType) { function downloadYaml(type: YamlType) {
let name = ''; let name = '';
let yamlStr = ''; let yamlStr = '';
const { nameSpaces, deployName } = form.value.testResourceDTO; const { namespace, deployName } = form.value.testResourceDTO;
// -xxx // -xxx
const apiImage = `registry.cn-qingdao.aliyuncs.com/metersphere/task-runner:${appStore.version.substring( const apiImage = `registry.cn-qingdao.aliyuncs.com/metersphere/task-runner:${appStore.version.substring(
0, 0,
@ -639,15 +639,15 @@
switch (type) { switch (type) {
case 'role': case 'role':
name = 'Role.yml'; name = 'Role.yml';
yamlStr = getYaml('role', '', nameSpaces, ''); yamlStr = getYaml('role', '', namespace, '');
break; break;
case 'Deployment': case 'Deployment':
name = 'Deployment.yml'; name = 'Deployment.yml';
yamlStr = getYaml('Deployment', deployName, nameSpaces, apiImage); yamlStr = getYaml('Deployment', deployName, namespace, apiImage);
break; break;
case 'DaemonSet': case 'DaemonSet':
name = 'Daemonset.yml'; name = 'Daemonset.yml';
yamlStr = getYaml('DaemonSet', deployName, nameSpaces, apiImage); yamlStr = getYaml('DaemonSet', deployName, namespace, apiImage);
break; break;
default: default:
throw new Error('文件类型不在可选范围'); throw new Error('文件类型不在可选范围');
@ -673,7 +673,7 @@
const { const {
ip, ip,
token, // k8s token token, // k8s token
nameSpaces, // k8s namespace, // k8s
concurrentNumber, // k8s concurrentNumber, // k8s
podThreads, // k8s pod线 podThreads, // k8s pod线
jobDefinition, // k8s job jobDefinition, // k8s job
@ -694,7 +694,7 @@
? { ? {
ip, ip,
token, token,
nameSpaces, namespace,
concurrentNumber, concurrentNumber,
podThreads, podThreads,
deployName: isCheckedAPI.value ? deployName : null, // deployName: isCheckedAPI.value ? deployName : null, //

View File

@ -264,7 +264,7 @@
const { const {
ip, ip,
token, // k8s token token, // k8s token
nameSpaces, // k8s namespace, // k8s
concurrentNumber, // k8s concurrentNumber, // k8s
podThreads, // k8s pod线 podThreads, // k8s pod线
deployName, // k8s api deployName, // k8s api
@ -298,8 +298,8 @@
value: token, value: token,
}, },
{ {
label: t('system.resourcePool.testResourceDTO.nameSpaces'), label: t('system.resourcePool.testResourceDTO.namespace'),
value: nameSpaces, value: namespace,
}, },
{ {
label: t('system.resourcePool.testResourceDTO.deployName'), label: t('system.resourcePool.testResourceDTO.deployName'),

View File

@ -94,7 +94,7 @@ export default {
'system.resourcePool.testResourceDTO.token': 'Token', 'system.resourcePool.testResourceDTO.token': 'Token',
'system.resourcePool.testResourceDTO.tokenRequired': 'Please fill in the Token', 'system.resourcePool.testResourceDTO.tokenRequired': 'Please fill in the Token',
'system.resourcePool.testResourceDTO.tokenPlaceholder': 'Please fill in the Token', 'system.resourcePool.testResourceDTO.tokenPlaceholder': 'Please fill in the Token',
'system.resourcePool.testResourceDTO.nameSpaces': 'NameSpaces', 'system.resourcePool.testResourceDTO.namespace': 'NameSpaces',
'system.resourcePool.testResourceDTO.nameSpacesRequired': 'Please fill in the namespace', 'system.resourcePool.testResourceDTO.nameSpacesRequired': 'Please fill in the namespace',
'system.resourcePool.testResourceDTO.nameSpacesPlaceholder': 'system.resourcePool.testResourceDTO.nameSpacesPlaceholder':
'To use the K8S resource pool, you need to deploy the Role.yaml file', 'To use the K8S resource pool, you need to deploy the Role.yaml file',

View File

@ -91,7 +91,7 @@ export default {
'system.resourcePool.testResourceDTO.token': 'Token', 'system.resourcePool.testResourceDTO.token': 'Token',
'system.resourcePool.testResourceDTO.tokenRequired': 'Token 不能为空', 'system.resourcePool.testResourceDTO.tokenRequired': 'Token 不能为空',
'system.resourcePool.testResourceDTO.tokenPlaceholder': '请输入 Token', 'system.resourcePool.testResourceDTO.tokenPlaceholder': '请输入 Token',
'system.resourcePool.testResourceDTO.nameSpaces': '命名空间', 'system.resourcePool.testResourceDTO.namespace': '命名空间',
'system.resourcePool.testResourceDTO.nameSpacesRequired': '命名空间不能为空', 'system.resourcePool.testResourceDTO.nameSpacesRequired': '命名空间不能为空',
'system.resourcePool.testResourceDTO.nameSpacesPlaceholder': '使用K8S资源池需要部署Role.yaml文件', 'system.resourcePool.testResourceDTO.nameSpacesPlaceholder': '使用K8S资源池需要部署Role.yaml文件',
'system.resourcePool.testResourceDTO.deployName': 'Deploy Name', 'system.resourcePool.testResourceDTO.deployName': 'Deploy Name',