fix(接口管理):修复接口定义调试另存为用例标题显示错误问题以及项目管理用户名称超长显示错乱问题

--bug=1038231 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001038231
--bug=1037880 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001037880
This commit is contained in:
guoyuqi 2024-04-07 15:05:27 +08:00 committed by 刘瑞斌
parent ccfb4e1d19
commit bfe9fc9902
4 changed files with 22 additions and 13 deletions

View File

@ -16,3 +16,16 @@ export function translatePxToNumber(str: string): number {
const result = Number(str.replace('px', '')); const result = Number(str.replace('px', ''));
return Number.isNaN(result) ? 0 : result; return Number.isNaN(result) ? 0 : result;
} }
export function translateTextToPX(text?: string) {
if (!text) {
return 0;
}
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
if (context != null) {
const metrics = context.measureText(text);
return metrics.width;
}
return 0;
}

View File

@ -487,7 +487,7 @@
<a-modal <a-modal
v-if="!isCase" v-if="!isCase"
v-model:visible="saveCaseModalVisible" v-model:visible="saveCaseModalVisible"
:title="t('common.save')" :title="t('apiTestManagement.saveAsCase')"
:ok-loading="saveCaseLoading" :ok-loading="saveCaseLoading"
class="ms-modal-form" class="ms-modal-form"
title-align="start" title-align="start"
@ -1591,6 +1591,7 @@
} }
isUrlError.value = false; isUrlError.value = false;
activeApiTabFormRef.value?.validate(async (errors) => { activeApiTabFormRef.value?.validate(async (errors) => {
console.log('validate');
if (errors) { if (errors) {
horizontalSplitBoxRef.value?.expand(); horizontalSplitBoxRef.value?.expand();
} else { } else {

View File

@ -11,7 +11,7 @@
<div class="response-tab"> <div class="response-tab">
<div v-if="tab.defaultFlag" class="response-tab-default-icon"></div> <div v-if="tab.defaultFlag" class="response-tab-default-icon"></div>
<a-tooltip <a-tooltip
v-if="getTextWidth(t(tab.name || tab.label)) > 200" v-if="translateTextToPX(t(tab.name || tab.label)) > 200"
:content="t(tab.name || tab.label) + '(' + tab.statusCode + ')'" :content="t(tab.name || tab.label) + '(' + tab.statusCode + ')'"
> >
<span class="one-line-text" style="max-width: 200px" <span class="one-line-text" style="max-width: 200px"
@ -189,6 +189,7 @@
import { responseHeaderOption } from '@/config/apiTest'; import { responseHeaderOption } from '@/config/apiTest';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useAppStore from '@/store/modules/app'; import useAppStore from '@/store/modules/app';
import { translateTextToPX } from '@/utils/css';
import { ResponseDefinition } from '@/models/apiTest/common'; import { ResponseDefinition } from '@/models/apiTest/common';
import { ResponseBodyFormat, ResponseComposition } from '@/enums/apiEnum'; import { ResponseBodyFormat, ResponseComposition } from '@/enums/apiEnum';
@ -317,16 +318,6 @@
emit('change'); emit('change');
} }
function getTextWidth(text: string) {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
if (context != null) {
const metrics = context.measureText(text);
return metrics.width;
}
return 0;
}
// const jsonSchemaColumns: FormTableColumn[] = [ // const jsonSchemaColumns: FormTableColumn[] = [
// { // {
// title: 'apiTestManagement.paramName', // title: 'apiTestManagement.paramName',

View File

@ -31,7 +31,10 @@
<div class="ml-1 flex flex-col"> <div class="ml-1 flex flex-col">
<div class="label-item"> <div class="label-item">
<span class="label">{{ t('project.basicInfo.createBy') }}</span> <span class="label">{{ t('project.basicInfo.createBy') }}</span>
<span>{{ projectDetail?.createUser }}</span> <a-tooltip v-if="translateTextToPX(projectDetail?.createUser) > 300" :content="projectDetail?.createUser">
<span class="one-line-text" style="max-width: 300px">{{ projectDetail?.createUser }}</span>
</a-tooltip>
<span v-else>{{ projectDetail?.createUser }}</span>
</div> </div>
<div class="label-item"> <div class="label-item">
<span class="label">{{ t('project.basicInfo.organization') }}</span> <span class="label">{{ t('project.basicInfo.organization') }}</span>
@ -62,6 +65,7 @@
import { getProjectInfo } from '@/api/modules/project-management/basicInfo'; import { getProjectInfo } from '@/api/modules/project-management/basicInfo';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import { useAppStore } from '@/store'; import { useAppStore } from '@/store';
import { translateTextToPX } from '@/utils/css';
import type { ProjectBasicInfoModel } from '@/models/projectManagement/basicInfo'; import type { ProjectBasicInfoModel } from '@/models/projectManagement/basicInfo';