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-badge{display:inline-block;position:relative}.ant-badge-content{position:absolute;display:flex;height:14px;align-self:center;align-items:center;font-size:9px;padding:2px 4px;box-sizing:border-box;word-break:keep-all;justify-content:center;top:0;left:100%;transform:translate(-50%,-50%)}.ant-badge-content-stroke{border:1px solid #fff}.ant-badge-content-text{padding-left:2px}.ant-badge-content-text:empty{display:none}.ant-badge-icon-container:empty~.ant-badge-content-text{padding-left:0}.ant-badge-content .ant-icon{font-size:9px;color:#fff}.ant-badge-content-not-dot{min-width:14px;height:14px;border-radius:14px;display:flex;background-color:#ff3141}.ant-badge-dot{width:10px;height:10px;border-radius:50%;background-color:#ff3141}.ant-badge-dot-stroke{border:1px solid #fff}.ant-badge-bubble,.ant-badge-number,.ant-badge-text{color:#fff}

View File

@ -0,0 +1,56 @@
<import-sjs
from="./index.sjs"
name="_sjs"
></import-sjs>
<view
class="ant-badge {{className || ''}}"
style="{{style}}"
>
<view class="ant-badge-body">
<slot></slot>
</view>
<view
a:if="{{type === 'dot'}}"
class="ant-badge-content"
style="{{_sjs.setPositionStyle(position, offsetX, offsetY)}}"
>
<view
class="ant-badge-dot {{stroke ? 'ant-badge-dot-stroke' : ''}}"
style="{{bgColor ? 'background-color: ' + bgColor + ';' : ''}}"
></view>
</view>
<view
a:else
class="ant-badge-content ant-badge-content-not-dot {{type === 'bubble' ? 'ant-badge-content-' + position + '-bubble' : ''}} {{stroke ? 'ant-badge-content-stroke' : ''}}"
style="{{bgColor ? 'background-color: ' + bgColor + ';' : ''}} {{_sjs.setBubbleStyle(type, position)}};{{_sjs.setPositionStyle(position, offsetX, offsetY)}}"
>
<view class="ant-badge-icon-container"></view>
<view class="ant-badge-content-text">
<slot name="text">
<block a:if="{{text}}">
<view
a:if="{{type === 'number'}}"
class="ant-badge-number"
>
<!--display: inline-->
<text a:if="{{_sjs.getOverCount(text)}}">99+</text>
<!--display: inline-->
<text a:else>{{text}}</text>
</view>
<view
a:if="{{type === 'text'}}"
class="ant-badge-text"
>
{{text}}
</view>
<view
a:if="{{type === 'bubble'}}"
class="ant-badge-bubble"
>
{{text}}
</view>
</block>
</slot>
</view>
</view>
</view>

View File

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

View File

@ -0,0 +1,3 @@
import { Component } from '../_util/simply';
import { BadgeFunctionalProps } from './props';
Component(BadgeFunctionalProps);

View File

@ -0,0 +1,3 @@
{
"component": true
}

View File

@ -0,0 +1,54 @@
function setPositionStyle(position) {
var offsetX = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '-50%';
var offsetY = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '-50%';
var transformStyle = "transform: translate(calc(".concat(offsetX, "), calc(").concat(offsetY, "));");
switch (position) {
case 'top-left':
return "top: 0; left: 0; ".concat(transformStyle);
case 'top-center':
return "top: 0; left: 50%; ".concat(transformStyle);
case 'top-right':
return "top: 0; left: 100%; ".concat(transformStyle);
case 'left':
return "top: 50%; left: 0; ".concat(transformStyle);
case 'right':
return "top: 50%; left: 100%; ".concat(transformStyle);
case 'bottom-left':
return "top: 100%; left: 0; ".concat(transformStyle);
case 'bottom-center':
return "top: 100%; left: 50%; ".concat(transformStyle);
case 'bottom-right':
return "top: 100%; left: 100%; ".concat(transformStyle);
default:
return "top: 0; left: 0; ".concat(transformStyle);
}
}
function setBubbleStyle(type, position) {
if (type !== 'bubble') return '';
switch (position) {
case 'top-left':
return 'border-bottom-right-radius: 0;';
case 'top-right':
return 'border-bottom-left-radius: 0;';
case 'bottom-left':
return 'border-top-right-radius: 0;';
case 'bottom-right':
return 'border-top-left-radius: 0;';
default:
return '';
}
}
function getOverCount(text) {
var overCount = false;
if (typeof text === 'number') {
if (text >= 100) {
overCount = true;
}
}
return overCount;
}
export default {
setPositionStyle: setPositionStyle,
setBubbleStyle: setBubbleStyle,
getOverCount: getOverCount
};

View File

@ -0,0 +1,41 @@
import { IBaseProps } from '../_util/base';
/**
* @description 徽标,红点、数字或文字。用于告诉用户待处理的事物或更新数。
*/
export interface IBadgeProps extends IBaseProps {
/**
* @description badge 类型
* @default dot
*/
type: 'dot' | 'number' | 'text' | 'bubble';
/**
* @description 红点内容,为空时表示只显示红点;可以是数字,也可以是文字;如果是数字,超过 99 会自动变成 ...
*/
text: string | number;
/**
* @description 相对于 children 所在访问left-top(左上角) top-right(右上角)
* @default "top-right"
*/
position: 'top-left' | 'top-center' | 'top-right' | 'left' | 'right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
/**
* @description 水平方向偏移量(字符串类型,需要带上像素单位)
* @default "-50%"
*/
offsetX: string;
/**
* @description 垂直方向偏移量(字符串类型,需要带上像素单位)
* @default "-50%"
*/
offsetY: number | string;
/**
* @description 是否有描边
* @default false
*/
stroke: boolean;
/**
* @description 背景色
*/
bgColor: string;
}
export declare const BadgeDefaultProps: Partial<IBadgeProps>;
export declare const BadgeFunctionalProps: Partial<IBadgeProps>;

View File

@ -0,0 +1,15 @@
export var BadgeDefaultProps = {
position: 'top-right',
stroke: false,
type: 'dot',
bgColor: '',
};
export var BadgeFunctionalProps = {
type: 'dot',
text: null,
position: 'top-right',
offsetX: null,
offsetY: null,
stroke: false,
bgColor: '',
};