This commit is contained in:
Ling53666
2025-08-18 09:11:51 +08:00
commit 02554225da
2516 changed files with 133155 additions and 0 deletions

View File

@ -0,0 +1 @@
.ant-popover{position:relative}.ant-popover-children{z-index:999}.ant-popover-mask{z-index:998;background:0 0}.ant-popover-content{position:absolute;min-width:32px;max-width:calc(100vw - 48 * .5px);z-index:999}.ant-popover-inner{position:relative;border-radius:8px;overflow:hidden;font-size:15px;background-color:#404040;color:#fff;padding:8px 12px;width:max-content}.ant-popover-arrow{position:absolute;width:0;height:0;border-left:9px solid transparent;border-right:9px solid transparent;border-bottom:9px solid #404040}.ant-popover-top{transform:translate(-50%,-100%)}.ant-popover-top-arrow{bottom:1px;transform:translate(-50%,100%) rotate(180deg);left:50%}.ant-popover-bottom{transform:translate(-50%,100%)}.ant-popover-bottom-arrow{top:1px;transform:translate(-50%,-100%) rotate(0);left:50%}.ant-popover-left{transform:translate(-100%,-50%)}.ant-popover-left-arrow{right:1px;transform:translate(75%,-50%) rotate(90deg);top:50%}.ant-popover-right{transform:translate(100%,-50%)}.ant-popover-right-arrow{left:1px;transform:translate(-75%,-50%) rotate(-90deg);top:50%}.ant-popover-top-left{transform:translate(0,-100%)}.ant-popover-top-left-arrow{bottom:1px;transform:translate(0,100%) rotate(180deg);left:12px}.ant-popover-top-right{transform:translate(0,-100%)}.ant-popover-top-right-arrow{bottom:1px;transform:translate(0,100%) rotate(180deg);right:12px}.ant-popover-bottom-left{transform:translate(0,100%)}.ant-popover-bottom-left-arrow{top:1px;transform:translate(0,-100%) rotate(0);left:12px}.ant-popover-bottom-right{transform:translate(0,100%)}.ant-popover-bottom-right-arrow{top:1px;transform:translate(0,-100%) rotate(0);right:12px}.ant-popover-left-top{transform:translate(-100%,0)}.ant-popover-left-top-arrow{right:1px;transform:translate(75%,0) rotate(90deg);top:12px}.ant-popover-left-bottom{transform:translate(-100%,0)}.ant-popover-left-bottom-arrow{right:1px;transform:translate(75%,0) rotate(90deg);bottom:12px}.ant-popover-right-top{transform:translate(100%,0)}.ant-popover-right-top-arrow{left:1px;transform:translate(-75%,0) rotate(-90deg);top:12px}.ant-popover-right-bottom{transform:translate(100%,0)}.ant-popover-right-bottom-arrow{left:1px;transform:translate(-75%,0) rotate(-90deg);bottom:12px}

View File

@ -0,0 +1,36 @@
<view
class="ant-popover {{showMask && mixin.value ? 'ant-popover-children' : ''}} {{className ? className : ''}}"
style="{{style || ''}}"
>
<view
id="ant-popover-children{{$id ? '-' + $id : ''}}"
onTap="onVisibleChange"
>
<slot></slot>
</view>
<view
a:if="{{!destroyOnClose || mixin.value}}"
hidden="{{!mixin.value}}"
id="ant-popover-content{{$id ? '-' + $id : ''}}"
class="ant-popover-content ant-popover-{{adjustedPlacement}}"
style="{{popoverContentStyle}}; {{adjustedPlacement ? '' : 'opacity: 0'}}"
>
<view
class="ant-popover-arrow ant-popover-{{adjustedPlacement}}-arrow"
style="{{color ? 'border-bottom-color:' + color : ''}}"
></view>
<view
class="ant-popover-inner {{contentClassName || ''}}"
style="{{color ? 'background:' + color : ''}};{{contentStyle || ''}}"
>
<slot name="content">{{content}}</slot>
</view>
</view>
</view>
<mask
show="{{showMask && mixin.value}}"
id="ant-popover-mask{{$id ? '-' + $id : ''}}"
className="ant-popover-mask {{maskClassName || ''}}"
style="{{maskStyle}}"
onMaskTap="onVisibleChange"
></mask>

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,98 @@
import { __awaiter, __generator } from "tslib";
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { PopoverDefaultProps } from './props';
import mixinValue from '../mixins/value';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
import { getSystemInfo } from '../_util/jsapi/get-system-info';
import { getPopoverStyle } from './utils';
Component(PopoverDefaultProps, {
getInstance: function () {
if (this.$id) {
return my;
}
return this;
},
updatePopover: function () {
return __awaiter(this, void 0, void 0, function () {
var _a, placement, autoAdjustOverflow, _b, containerRect, childrenRect, contentRect, systemInfo, _c, popoverContentStyle, adjustedPlacement;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
_a = getValueFromProps(this, [
'placement',
'autoAdjustOverflow',
]), placement = _a[0], autoAdjustOverflow = _a[1];
return [4 /*yield*/, Promise.all([
getInstanceBoundingClientRect(this.getInstance(), "#ant-popover-children".concat(this.$id ? "-".concat(this.$id) : '')),
getInstanceBoundingClientRect(this.getInstance(), this.$id
? "#ant-popover-children-".concat(this.$id, " > *")
: "#ant-popover-children-container"),
getInstanceBoundingClientRect(this.getInstance(), this.$id
? "#ant-popover-content-".concat(this.$id)
: '#ant-popover-content'),
getSystemInfo(),
])];
case 1:
_b = _d.sent(), containerRect = _b[0], childrenRect = _b[1], contentRect = _b[2], systemInfo = _b[3];
_c = getPopoverStyle(placement, autoAdjustOverflow, {
containerRect: containerRect,
childrenRect: childrenRect,
contentRect: contentRect,
systemInfo: systemInfo,
}), popoverContentStyle = _c.popoverContentStyle, adjustedPlacement = _c.adjustedPlacement;
this.setData({
popoverContentStyle: popoverContentStyle,
adjustedPlacement: adjustedPlacement,
});
return [2 /*return*/];
}
});
});
},
onVisibleChange: function (e) {
if (!this.getValue() &&
e.target.id &&
e.target.id.indexOf('ant-popover-') === 0) {
return;
}
var value = !this.getValue();
if (!this.isControlled()) {
this.update(value);
}
triggerEvent(this, 'visibleChange', value, e);
},
}, {
adjustedPlacement: '',
popoverContentStyle: '',
}, [
mixinValue({
valueKey: 'visible',
defaultValueKey: 'defaultVisible',
transformValue: function (value) {
if (value) {
this.updatePopover();
}
else {
this.setData({
adjustedPlacement: '',
});
}
return {
needUpdate: true,
value: value,
};
},
}),
], {
didUpdate: function (prevProps) {
var _a = getValueFromProps(this, [
'placement',
'autoAdjustOverflow',
]), placement = _a[0], autoAdjustOverflow = _a[1];
if ((prevProps.placement !== placement ||
prevProps.autoAdjustOverflow !== autoAdjustOverflow) &&
this.getValue()) {
this.updatePopover();
}
},
});

View File

@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"mask": "../Mask/index"
}
}

View File

@ -0,0 +1,64 @@
import { IBaseProps } from '../_util/base';
/**
* @description 气泡,内部配合 PopoverItem 使用。
*/
export interface IPopoverProps extends IBaseProps {
/**
* @description 是否可见
* @default false
*/
visible: boolean;
/**
* @description 默认是否可见
* @default false
*/
defaultVisible: boolean;
/**
* @description 是否关闭后销毁内部元素
* @default false
*/
destroyOnClose: boolean;
/**
* @description 背景颜色
*/
color: string;
/**
* @description content区样式
*/
contentStyle: string;
/**
* @description content类名
*/
contentClassName: string;
/**
* @description content 内容
*/
content?: string;
/**
* @description 蒙层类名
*/
maskClassName: string;
/**
* @description 蒙层样式
*/
maskStyle: string;
/**
* @description visible 变更时回调
*/
onVisibleChange?: (visible: boolean, e: Record<string, any>) => void;
/**
* @description 气泡框位置
*/
placement: 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-left' | 'bottom-right' | 'left' | 'left-top' | 'left-bottom' | 'right' | 'right-top' | 'right-bottom';
/**
* @description 是否展示蒙层
* @default false
*/
showMask: boolean;
/**
* @description 气泡被遮挡时自动调整位置
* @default true
*/
autoAdjustOverflow: boolean;
}
export declare const PopoverDefaultProps: Partial<IPopoverProps>;

View File

@ -0,0 +1,15 @@
export var PopoverDefaultProps = {
visible: null,
defaultVisible: false,
destroyOnClose: false,
contentClassName: '',
color: '',
contentStyle: '',
showMask: true,
placement: 'top',
autoAdjustOverflow: true,
maskClassName: '',
maskStyle: '',
content: '',
onVisibleChange: function () { },
};

View File

@ -0,0 +1,22 @@
interface Rect {
left: number;
top: number;
right: number;
bottom: number;
width: number;
height: number;
}
interface SystemInfo {
windowHeight: number;
windowWidth: number;
}
export declare function getPopoverStyle(placement: string, autoAdjustOverflow: boolean, size: {
containerRect: Rect;
childrenRect: Rect;
contentRect: Rect;
systemInfo: SystemInfo;
}): {
popoverContentStyle: any;
adjustedPlacement: string;
};
export {};

View File

@ -0,0 +1,179 @@
export function getPopoverStyle(placement, autoAdjustOverflow, size) {
var containerRect = size.containerRect, childrenRect = size.childrenRect, contentRect = size.contentRect, systemInfo = size.systemInfo;
var left = childrenRect.left - containerRect.left;
var top = childrenRect.top - containerRect.top;
var bottom = containerRect.bottom - childrenRect.bottom;
var right = containerRect.right - childrenRect.right;
var adjustedPlacement = placement;
var arrowMargin = 12;
var contentRectWidth = contentRect.width + arrowMargin;
var contentRectHeight = contentRect.height + arrowMargin;
if (autoAdjustOverflow) {
if (adjustedPlacement === 'top') {
if (childrenRect.top - contentRectHeight < 0) {
adjustedPlacement = 'bottom';
}
}
else if (adjustedPlacement === 'bottom') {
if (childrenRect.bottom + contentRectHeight > systemInfo.windowHeight) {
adjustedPlacement = 'top';
}
}
else if (adjustedPlacement === 'left') {
if (childrenRect.left - contentRectWidth < 0) {
adjustedPlacement = 'right';
}
}
else if (adjustedPlacement === 'right') {
if (childrenRect.right + contentRectWidth > systemInfo.windowWidth) {
adjustedPlacement = 'left';
}
}
else if (adjustedPlacement === 'top-left') {
if (childrenRect.top - contentRectHeight < 0) {
adjustedPlacement = adjustedPlacement.replace('top', 'bottom');
}
if (childrenRect.left + contentRectWidth > systemInfo.windowWidth) {
adjustedPlacement = adjustedPlacement.replace('left', 'right');
}
}
else if (adjustedPlacement === 'top-right') {
if (childrenRect.top - contentRectHeight < 0) {
adjustedPlacement = adjustedPlacement.replace('top', 'bottom');
}
if (childrenRect.right - contentRectWidth < 0) {
adjustedPlacement = adjustedPlacement.replace('right', 'left');
}
}
else if (adjustedPlacement === 'bottom-left') {
if (childrenRect.bottom + contentRectHeight > systemInfo.windowHeight) {
adjustedPlacement = adjustedPlacement.replace('bottom', 'top');
}
if (childrenRect.left + contentRectWidth > systemInfo.windowWidth) {
adjustedPlacement = adjustedPlacement.replace('left', 'right');
}
}
else if (adjustedPlacement === 'bottom-right') {
if (childrenRect.bottom + contentRectHeight > systemInfo.windowHeight) {
adjustedPlacement = adjustedPlacement.replace('bottom', 'top');
}
if (childrenRect.right - contentRectWidth < 0) {
adjustedPlacement = adjustedPlacement.replace('right', 'left');
}
}
else if (adjustedPlacement === 'left-top') {
if (childrenRect.left - contentRectWidth < 0) {
adjustedPlacement = adjustedPlacement.replace('left', 'right');
}
if (childrenRect.top + contentRectHeight > systemInfo.windowHeight) {
adjustedPlacement = adjustedPlacement.replace('top', 'bottom');
}
}
else if (adjustedPlacement === 'left-bottom') {
if (childrenRect.left - contentRectWidth < 0) {
adjustedPlacement = adjustedPlacement.replace('left', 'right');
}
if (childrenRect.bottom - contentRectHeight < 0) {
adjustedPlacement = adjustedPlacement.replace('bottom', 'top');
}
}
else if (adjustedPlacement === 'right-top') {
if (childrenRect.right + contentRectWidth > systemInfo.windowWidth) {
adjustedPlacement = adjustedPlacement.replace('right', 'left');
}
if (childrenRect.top + contentRectHeight > systemInfo.windowHeight) {
adjustedPlacement = adjustedPlacement.replace('top', 'bottom');
}
}
else if (adjustedPlacement === 'right-bottom') {
if (childrenRect.right + contentRectWidth > systemInfo.windowWidth) {
adjustedPlacement = adjustedPlacement.replace('right', 'left');
}
if (childrenRect.bottom - contentRectHeight < 0) {
adjustedPlacement = adjustedPlacement.replace('bottom', 'top');
}
}
}
var popoverContentStyle;
if (adjustedPlacement === 'top') {
popoverContentStyle = getStyle({
left: left + childrenRect.width / 2,
top: top - arrowMargin,
});
}
else if (adjustedPlacement === 'bottom') {
popoverContentStyle = getStyle({
left: left + childrenRect.width / 2,
bottom: bottom - arrowMargin,
});
}
else if (adjustedPlacement === 'left') {
popoverContentStyle = getStyle({
left: left - arrowMargin,
top: top + childrenRect.height / 2,
});
}
else if (adjustedPlacement === 'right') {
popoverContentStyle = getStyle({
right: right - arrowMargin,
top: top + childrenRect.height / 2,
});
}
else if (adjustedPlacement === 'top-left') {
popoverContentStyle = getStyle({
left: left,
top: top - arrowMargin,
});
}
else if (adjustedPlacement === 'top-right') {
popoverContentStyle = getStyle({
right: right,
top: top - arrowMargin,
});
}
else if (adjustedPlacement === 'bottom-left') {
popoverContentStyle = getStyle({
left: left,
bottom: bottom - arrowMargin,
});
}
else if (adjustedPlacement === 'bottom-right') {
popoverContentStyle = getStyle({
right: right,
bottom: bottom - arrowMargin,
});
}
else if (adjustedPlacement === 'left-top') {
popoverContentStyle = getStyle({
left: left - arrowMargin,
top: top,
});
}
else if (adjustedPlacement === 'left-bottom') {
popoverContentStyle = getStyle({
left: left - arrowMargin,
bottom: bottom,
});
}
else if (adjustedPlacement === 'right-top') {
popoverContentStyle = getStyle({
right: right - arrowMargin,
top: top,
});
}
else if (adjustedPlacement === 'right-bottom') {
popoverContentStyle = getStyle({
right: right - arrowMargin,
bottom: bottom,
});
}
return {
popoverContentStyle: popoverContentStyle,
adjustedPlacement: adjustedPlacement,
};
}
function getStyle(obj) {
return Object.keys(obj)
.map(function (item) { return "".concat(item, ": ").concat(obj[item], "px"); })
.join(';');
}