Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 【产品功能】策略里面的指标是否可以提供复制的功能 --Story=120927927 #4140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default class MetricPopover extends tsc<MetricPopoverProps, MetricPopover
@Ref() metricSelectorPopover: HTMLElement;
/* 宽度 */
@Prop({ type: Number, default: 558 }) width: number;
/** 用于匹配 外部点击后不想触发该 popover 隐藏的 dom 元素 的有效的 CSS 选择器字符串 */
@Prop({ type: String, default: () => null }) coexistDomSelectors: string;

/** 弹层实例 */
popoverInstance = null;
Expand All @@ -64,7 +66,7 @@ export default class MetricPopover extends tsc<MetricPopoverProps, MetricPopover
placement: 'bottom-start',
theme: 'light common-monitor',
arrow: false,
// hideOnClick: false,
hideOnClick: false,
interactive: true,
boundary: 'window',
// offset: -1,
Expand All @@ -75,10 +77,24 @@ export default class MetricPopover extends tsc<MetricPopoverProps, MetricPopover
onHidden: () => {
this.destroyPopoverInstance();
this.handleShowChange(false);
document.body.removeEventListener('mousedown', this.handleClickHide, true);
},
});
// this.curTarget = target;
}
handleClickHide(e) {
if (this.popoverInstance?.popper?.contains(e.target)) {
return;
}

if (typeof this.coexistDomSelectors === 'string' && this.coexistDomSelectors) {
const target = document.querySelector(`${this.coexistDomSelectors}`);
if (target?.contains(e.target)) {
return;
}
}
this.handleDropDownHide();
}
/**
* @description: 显示添加条件弹层
* @param {HTMLElement} target 出发弹层的目标元素
Expand All @@ -89,6 +105,7 @@ export default class MetricPopover extends tsc<MetricPopoverProps, MetricPopover
this.registerDropDown();
await this.$nextTick();
this.popoverInstance?.show();
document.body.addEventListener('mousedown', this.handleClickHide, true);
}

// 清除popover实例
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,21 +477,31 @@ class MetricSelector extends Mixins(metricTipsContentMixin) {
* @return {*}
*/
handleMetricNameEnter(e: Event, item: MetricDetail) {
const target = Array.from(e.target.childNodes).find(c => c.className === 'tip-dom');
this.hoverTimer && window.clearTimeout(this.hoverTimer);
if (!this.show) return;
// @ts-ignore
const target = e.target.parentNode;
if (this.popoverInstance?.reference === target && this.popoverInstance?.state?.isShown) {
return;
}
this.handleTipsLeave();
this.hoverTimer = setTimeout(() => {
this.popoverInstance = this.$bkPopover(target, {
content: this.handleGetMetricTipsContent(item),
trigger: 'manual',
theme: 'tippy-metric',
arrow: true,
placement: 'right',
boundary: 'window',
allowHTML: true,
interactive: true,
interactiveBorder: 6,
});
this.popoverInstance?.show();
}, 1000);
}
handleMouseLeave() {
this.hoverTimer && window.clearTimeout(this.hoverTimer);
}

// 移出指标
handleMetricNameLeave() {
this.handleTipsLeave();
Expand All @@ -500,8 +510,8 @@ class MetricSelector extends Mixins(metricTipsContentMixin) {
// 去除指标tip
handleTipsLeave() {
if (this.popoverInstance) {
this.popoverInstance.hide(0);
this.popoverInstance.destroy();
this.popoverInstance?.hide(0);
this.popoverInstance?.destroy();
this.popoverInstance = null;
}
}
Expand Down Expand Up @@ -601,9 +611,7 @@ class MetricSelector extends Mixins(metricTipsContentMixin) {
}

/** 更新鼠标的hover状态 */
handleMousemove() {
this.isHoverItem = true;
}
handleMousemove() {}

/** 更新hover的索引 */
handleHoverItem(index: number) {
Expand Down Expand Up @@ -820,7 +828,7 @@ class MetricSelector extends Mixins(metricTipsContentMixin) {
<div
class={['metric-item-common', { 'multiple-style': this.multiple }]}
on-mouseenter={event => this.handleMetricNameEnter(event, item)}
on-mouseleave={this.handleMetricNameLeave}
on-mouseleave={this.handleMouseLeave}
>
<div class='top'>
<span class='title'>
Expand Down Expand Up @@ -952,6 +960,7 @@ class MetricSelector extends Mixins(metricTipsContentMixin) {
return (
<MetricPopover
width={this.type === MetricType.TimeSeries ? 718 : 558}
coexistDomSelectors='.tippy-metric-theme'
show={this.show}
targetId={this.targetId}
onShowChange={this.handleShowChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {

export type TGetMetricData = (
params: Record<string, any>
) => { metricList: IMetricDetail[] } | Promise<{ metricList: IMetricDetail[] }> | any;
) => { metricList: IMetricDetail[] } | any | Promise<{ metricList: IMetricDetail[] }>;

export type MetricSelectorProps = {
type?: MetricType;
Expand All @@ -55,6 +55,7 @@ export interface MetricPopoverProps {
targetId: string;
show?: boolean;
width?: number;
coexistDomSelectors?: string;
}
export interface MetricPopoverEvents {
onShowChange: boolean;
Expand Down