fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

94 lines
2.5 KiB

import { VerticalLayout, shortcut, extend, createWidget, map, pixFormat } from "@/core";
import { Label } from "../label";
import { Tip } from "./0.tip";
/**
* title提示
*
* Created by GUY on 2015/9/7.
* @class Tooltip
* @extends Tip
*/
@shortcut()
export class Tooltip extends Tip {
_const = {
hgap: 8,
vgap: 4,
};
static xtype = "bi.tooltip";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
extraCls: "bi-tooltip",
text: "",
level: "success", // success或warning
stopEvent: false,
stopPropagation: false,
textAlign: "left",
});
}
render() {
const { level, stopPropagation, stopEvent, text, textAlign } = this.options;
this.element.addClass(`tooltip-${level}`);
function fn(e) {
stopPropagation && e.stopPropagation();
stopEvent && e.stopEvent();
}
this.element.bind({
click: fn,
mousedown: fn,
mouseup: fn,
mouseover: fn,
mouseenter: fn,
mouseleave: fn,
mousemove: fn,
});
const texts = `${text}`.split("\n");
if (texts.length > 1) {
createWidget({
type: VerticalLayout.xtype,
element: this,
hgap: this._const.hgap,
innerVgap: this._const.vgap,
items: map(texts, (i, text) => {
return {
type: Label.xtype,
textAlign,
whiteSpace: "normal",
text,
textHeight: 18,
title: null,
};
}),
});
} else {
this.text = createWidget({
type: Label.xtype,
element: this,
textAlign,
whiteSpace: "normal",
text,
title: null,
textHeight: 18,
hgap: this._const.hgap,
vgap: this._const.vgap,
});
}
}
setWidth(width) {
this.element.width(pixFormat(width - 2 * this._const.hgap));
}
setText(text) {
this.text && this.text.setText(text);
}
setLevel(level) {
this.element.removeClass("tooltip-success").removeClass("tooltip-warning");
this.element.addClass(`tooltip-${level}`);
}
}