Skip to content

Commit

Permalink
feat(frontend): 单据管理迭代_123 TencentBlueKing#7190
Browse files Browse the repository at this point in the history
  • Loading branch information
hLinx committed Dec 12, 2024
1 parent 01e4381 commit 6225f22
Show file tree
Hide file tree
Showing 32 changed files with 307 additions and 871 deletions.
8 changes: 1 addition & 7 deletions dbm-ui/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"@blueking/login-modal": "^1.0.5",
"@blueking/notice-component": "2.0.5",
"@blueking/sub-saas": "0.0.0-beta.6",
"@blueking/table": "^0.0.1-beta.19",
"@blueking/vxe-table": "^4.8.0-beta.7.8",
"@icon-cool/bk-icon-bk-biz-components": "0.0.4",
"@blueking/table": "^0.0.1-beta.20",
"@vueuse/core": "^12.0.0",
"axios": "^1.7.9",
"bkui-vue": "2.0.1-beta.78",
Expand Down Expand Up @@ -56,7 +54,6 @@
},
"devDependencies": {
"@commitlint/config-conventional": "^19.6.0",
"@jridgewell/gen-mapping":"0.3.5",
"@trivago/prettier-plugin-sort-imports": "^5.1.0",
"@tsconfig/node20": "20.1.4",
"@types/lodash": "^4.17.13",
Expand Down Expand Up @@ -111,9 +108,6 @@
"prettier --write"
]
},
"overrides":{
"@jridgewell/gen-mapping":"0.3.5"
},
"engines": {
"node": ">=16.0.1"
}
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/frontend/src/components/cluster-selector/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@
[tabKey]: tabSelectMap,
};
}, {} as SelectMapValueType<T>);

showTabTips.value = true;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
white-space: nowrap;

.content {
color: #313238;
// padding-bottom: 2px;
cursor: pointer;
color: #313238;
// border-bottom: 1px dotted #979ba5;
}
}
Expand All @@ -104,8 +104,8 @@
}

.visible-icon {
font-size: 16px;
color: #3a84ff;
cursor: pointer;
font-size: 16px;
}
</style>
231 changes: 231 additions & 0 deletions dbm-ui/frontend/src/components/tag-block/Index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
<template>
<div
ref="rootRef"
class="dbm-tag-block">
<template v-if="data && data.length">
<BkTag
v-for="item in renderData"
:key="item">
{{ item }}
</BkTag>
<BkTag
v-if="moreTagCount > 0"
key="more"
ref="moreRef">
+{{ moreTagCount }}
</BkTag>
<div
v-if="copyenable"
v-bk-tooltips="t('复制所有')"
class="copy-btn"
@click.stop="handleCopy">
<DbIcon type="copy" />
</div>
</template>
<span v-else>--</span>
<div
v-if="isCalcRenderTagNum"
ref="tagList"
style="position: absolute; word-break: keep-all; white-space: nowrap; visibility: hidden">
<BkTag
v-for="item in data"
:key="item">
{{ item }}
</BkTag>
</div>
<div style="display: none">
<div
ref="tipsPanel"
style="word-break: keep-all; white-space: nowrap">
<BkTag
v-for="item in data.slice(renderData.length)"
:key="item">
{{ item }}
</BkTag>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { throttle } from 'lodash';
import tippy, { type Instance, type SingleTarget } from 'tippy.js';
import { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { execCopy } from '@utils';
interface Props {
data: Array<string>;
copyenable?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
max: 0,
copyenable: false,
});
const { t } = useI18n();
const rootRef = ref();
const moreRef = ref();
const tagListRef = useTemplateRef('tagList');
const tipsPanelRef = useTemplateRef('tipsPanel');
const renderTagNum = ref(1);
const isCalcRenderTagNum = ref(false);
const renderData = computed(() => props.data.slice(0, renderTagNum.value));
const moreTagCount = computed(() => props.data.length - renderTagNum.value);
let tippyIns: Instance;
const calcRenderTagNum = () => {
// next 确保组件是 mounted 状态
nextTick(() => {
if (!rootRef.value || props.data.length < 1) {
return;
}
isCalcRenderTagNum.value = true;
// setTimeout 确保 isCalcRenderTagNum 已经生效
nextTick(() => {
const { width: maxWidth } = rootRef.value.getBoundingClientRect();
renderTagNum.value = 0;
let renderTagCount = 0;
const tipsTagPlaceholderWidth = 45;
const copyBtnWidth = props.copyenable ? 30 : 0;
const allTagEleList = Array.from(tagListRef.value!.querySelectorAll('.bk-tag'));
if (tagListRef.value!.getBoundingClientRect().width + copyBtnWidth <= maxWidth || props.data.length === 1) {
renderTagNum.value = props.data.length;
} else {
const tagMargin = 6;
let totalTagWidth = -tagMargin;
for (let i = 0; i < allTagEleList.length; i++) {
const { width: tagWidth } = allTagEleList[i].getBoundingClientRect();
totalTagWidth += tagWidth + tagMargin;
if (totalTagWidth + tipsTagPlaceholderWidth + copyBtnWidth <= maxWidth) {
renderTagCount = renderTagCount + 1;
} else {
break;
}
}
renderTagNum.value = Math.max(renderTagCount, 1);
}
isCalcRenderTagNum.value = false;
});
});
};
watch(
() => props.data,
() => {
calcRenderTagNum();
},
{
immediate: true,
},
);
watch(
moreTagCount,
() => {
if (moreTagCount.value < 1) {
if (tippyIns) {
tippyIns.hide();
tippyIns.disable();
}
return;
}
nextTick(() => {
if (tippyIns) {
tippyIns.enable();
return;
}
tippyIns = tippy(moreRef.value.$el as SingleTarget, {
content: tipsPanelRef.value as Element,
placement: 'top',
allowHTML: true,
appendTo: () => document.body,
theme: 'light',
interactive: true,
arrow: true,
offset: [0, 8],
zIndex: 999999,
hideOnClick: true,
trigger: 'mouseenter',
});
});
},
{
deep: true,
immediate: true,
},
);
const handleCopy = () => {
execCopy(props.data.join('\n'), t('复制成功'));
};
let resizeObserver: any;
onMounted(() => {
calcRenderTagNum();
const resizeObserver = new ResizeObserver(
throttle(() => {
calcRenderTagNum();
}),
);
resizeObserver.observe(rootRef.value);
});
onBeforeUnmount(() => {
if (tippyIns) {
tippyIns.hide();
tippyIns.unmount();
tippyIns.destroy();
}
resizeObserver?.disconnect();
});
</script>
<style lang="postcss">
.dbm-tag-block {
position: relative;
display: block;
word-break: keep-all;
white-space: nowrap;
.label-text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&:hover {
.copy-btn {
opacity: 100%;
}
}
.bk-tag {
margin-right: 0;
margin-left: 0;
& ~ .bk-tag {
margin-left: 6px;
}
}
.copy-btn {
display: inline-block;
padding-left: 8px;
cursor: pointer;
opacity: 0%;
&:hover {
color: #3a84ff;
}
}
}
</style>
1 change: 1 addition & 0 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3820,5 +3820,6 @@
"容灾要求:": "容灾要求:",
"Proxy起始端口:": "Proxy起始端口:",
"数量:": "数量:",
"源 DB 名": "源 DB 名",
"这行勿动!新增翻译请在上一行添加!": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import ClusterSelector from '@components/cluster-selector/Index.vue';
import RenderClusterStatus from '@components/cluster-status/Index.vue';



interface IClusterData {
id: number;
cluster_name: string;
Expand Down Expand Up @@ -158,7 +160,7 @@

const fetchClusterData = (clusterIds: number[]) => {
isLoading.value = true;
filterClusters<TendbhaModel>({
filterClusters<SelectorRowDataType>({
cluster_ids: clusterIds.join(','),
bk_biz_id: window.PROJECT_CONFIG.BIZ_ID,
})
Expand All @@ -167,14 +169,21 @@
clusterVersionList.value = _.uniq(data.map(item => item.major_version));
clusterSelectorValue.value = data.reduce((result, item) => {
if (item.cluster_type === ClusterTypes.TENDBHA) {
result[ClusterTypes.TENDBHA].push(item);
} else {
result[ClusterTypes.TENDBSINGLE].push(item);
result[ClusterTypes.TENDBHA].push(item as TendbhaModel);
} else if (item.cluster_type === ClusterTypes.TENDBSINGLE) {
result[ClusterTypes.TENDBSINGLE].push(item as TendbsingleModel);
} else if (item.cluster_type === ClusterTypes.TENDBCLUSTER) {
result[ClusterTypes.TENDBCLUSTER].push(item as TendbclusterModel);
} else if (item.cluster_type === ClusterTypes.SQLSERVER_HA) {
result[ClusterTypes.SQLSERVER_HA].push(item as SqlServerHaClusterModel);
} else if (item.cluster_type === ClusterTypes.SQLSERVER_SINGLE) {
result[ClusterTypes.SQLSERVER_SINGLE].push(item as SqlServerSingleClusterModel);
}
return result;
}, {
[ClusterTypes.TENDBHA]: [] as TendbhaModel[],
[ClusterTypes.TENDBSINGLE]: [] as TendbsingleModel[],
[ClusterTypes.TENDBCLUSTER]: [] as TendbclusterModel[],
[ClusterTypes.SQLSERVER_HA]: [] as SqlServerHaClusterModel[],
[ClusterTypes.SQLSERVER_SINGLE]: [] as SqlServerSingleClusterModel[],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,10 @@
watch(
filenameList,
() => {
if (filenameList.value.length) {
localList.value = filenameList.value.map((fileName) => ({
id: fileName,
name: fileName,
}));
}
localList.value = filenameList.value.map((fileName) => ({
id: fileName,
name: fileName,
}));
},
{
immediate: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
} else {
selectFileName.value = '';
}

triggerGramarCheckChange();
triggerChange();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@
.ticket-info-more {
display: flex;
& ~ .ticket-info-more {
margin-top: 8px;
}
margin-top: 8px;
.ticket-info-label {
flex-shrink: 0;
Expand Down
Loading

0 comments on commit 6225f22

Please sign in to comment.