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,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,69 @@
@import (reference) './variable.less';
@badgePrefix: ant-badge;
.@{badgePrefix} {
display: inline-block;
position: relative;
&-content {
position: absolute;
display: flex;
height: 28 * @rpx;
align-self: center;
align-items: center;
font-size: 18 * @rpx;
padding: 4 * @rpx 8 * @rpx;
box-sizing: border-box;
word-break: keep-all;
justify-content: center;
top: 0;
left: 100%;
transform: translate(-50%, -50%);
&-stroke {
border: 2 * @rpx solid @COLOR_WHITE;
}
&-text {
padding-left: 4 * @rpx;
&:empty {
display: none;
}
.ant-badge-icon-container:empty ~ & {
padding-left: 0;
}
}
.ant-icon {
font-size: 18 * @rpx;
color: @COLOR_WHITE;
}
&-not-dot {
min-width: 28 * @rpx;
height: 28 * @rpx;
border-radius: 28 * @rpx;
display: flex;
background-color: @badge-background-color;
}
}
&-dot {
width: 20 * @rpx;
height: 20 * @rpx;
border-radius: 50%;
background-color: @badge-background-color;
&-stroke {
border: 2 * @rpx solid @COLOR_WHITE;
}
}
&-number,
&-text,
&-bubble {
color: @COLOR_WHITE;
}
}

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: '',
};

View File

@ -0,0 +1,6 @@
@import (reference) '../style/themes/index.less';
// 字体颜色,同时作用于 stroke 边框
@badge-text-color: @COLOR_WHITE;
// 背景颜色
@badge-background-color: @COLOR_RED;