New Huajishe Check ChaoXing

This commit is contained in:
e2hang
2025-10-01 10:01:52 +08:00
parent 240b884eac
commit 80be8ae3cf
1094 changed files with 61709 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
:: BASE_DOC ::
## API
### Stepper Props
name | type | default | description | required
-- | -- | -- | -- | --
style | Object | - | CSS(Cascading Style Sheets) | N
custom-style | Object | - | CSS(Cascading Style Sheets)used to set style on virtual component | N
disable-input | Boolean | false | \- | N
disabled | Boolean | undefined | \- | N
input-width | Number | - | \- | N
integer | Boolean | true | \- | N
max | Number | 100 | \- | N
min | Number | 0 | \- | N
size | String | medium | options: small/medium/large。Typescript`SizeEnum`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
step | Number | 1 | \- | N
theme | String | normal | stylish。options: normal/filled/outline | N
value | String / Number | 0 | \- | N
default-value | String / Number | undefined | uncontrolled property | N
### Stepper Events
name | params | description
-- | -- | --
blur | `({ type: string \| number })` | \-
change | `({ value: string \| number })` | \-
focus | `({ value: string \| number }))` | \-
overlimit | `({type: 'minus' \| 'plus'})` | \-
### Stepper External Classes
className | Description
-- | --
t-class | \-
t-class-input | \-
t-class-minus | \-
t-class-plus | \-
### CSS Variables
The component provides the following CSS variables, which can be used to customize styles.
Name | Default Value | Description
-- | -- | --
--td-stepper-border-color | @component-border | -
--td-stepper-border-radius | @radius-small | -
--td-stepper-input-color | @font-gray-1 | -
--td-stepper-input-disabled-color | @font-gray-4 | -

View File

@@ -0,0 +1,100 @@
---
title: Stepper 步进器
description: 用于数量的增减。
spline: form
isComponent: true
---
<span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20lines-90%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20functions-82%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20statements-90%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20branches-94%25-blue" /></span>
## 引入
全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。
```json
"usingComponents": {
"t-stepper": "tdesign-miniprogram/stepper/stepper"
}
```
## 代码演示
<a href="https://developers.weixin.qq.com/s/Ot604imU7ESt" title="在开发者工具中预览效果" target="_blank" rel="noopener noreferrer"> 在开发者工具中预览效果 </a>
<blockquote style="background-color: #d9e1ff; font-size: 15px; line-height: 26px;margin: 16px 0 0;padding: 16px; border-radius: 6px; color: #0052d9" >
<p>Tips: 请确保开发者工具为打开状态。导入开发者工具后依次执行npm i > 构建npm包 > 勾选 "将JS编译成ES5"</p>
</blockquote>
### 组件类型
基础步进器
{{ base }}
### 组件状态
最大最小状态
{{ min-max }}
禁用状态
{{ status }}
### 组件样式
步进器样式
{{ theme }}
步进器尺寸
{{ size }}
## API
### Stepper Props
名称 | 类型 | 默认值 | 描述 | 必传
-- | -- | -- | -- | --
style | Object | - | 样式 | N
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
disable-input | Boolean | false | 禁用输入框 | N
disabled | Boolean | undefined | 禁用全部操作 | N
input-width | Number | - | 输入框宽度,默认单位 `px` | N
integer | Boolean | true | 是否整型 | N
max | Number | 100 | 最大值 | N
min | Number | 0 | 最小值 | N
size | String | medium | 组件尺寸。可选项small/medium/large。TS 类型:`SizeEnum`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
step | Number | 1 | 步长 | N
theme | String | normal | 组件风格。可选项normal/filled/outline | N
value | String / Number | 0 | 值 | N
default-value | String / Number | undefined | 值。非受控属性 | N
### Stepper Events
名称 | 参数 | 描述
-- | -- | --
blur | `({ type: string \| number })` | 输入框失去焦点时触发
change | `({ value: string \| number })` | 数值发生变更时触发
focus | `({ value: string \| number }))` | 输入框聚焦时触发
overlimit | `({type: 'minus' \| 'plus'})` | 数值超出限制时触发
### Stepper External Classes
类名 | 描述
-- | --
t-class | 根节点样式类
t-class-input | 输入框样式类
t-class-minus | 左侧递减号样式类
t-class-plus | 右侧递增号样式类
### CSS Variables
组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--td-stepper-border-color | @component-border | -
--td-stepper-border-radius | @radius-small | -
--td-stepper-input-color | @font-gray-1 | -
--td-stepper-input-disabled-color | @font-gray-4 | -

View File

@@ -0,0 +1,3 @@
import { TdStepperProps } from './type';
declare const props: TdStepperProps;
export default props;

View File

@@ -0,0 +1,46 @@
const props = {
disableInput: {
type: Boolean,
value: false,
},
disabled: {
type: null,
value: undefined,
},
inputWidth: {
type: Number,
},
integer: {
type: Boolean,
value: true,
},
max: {
type: Number,
value: 100,
},
min: {
type: Number,
value: 0,
},
size: {
type: String,
value: 'medium',
},
step: {
type: Number,
value: 1,
},
theme: {
type: String,
value: 'normal',
},
value: {
type: null,
value: null,
},
defaultValue: {
type: null,
value: 0,
},
};
export default props;

View File

@@ -0,0 +1,78 @@
import { SuperComponent } from '../common/src/index';
export default class Stepper extends SuperComponent {
externalClasses: string[];
properties: {
disableInput?: {
type: BooleanConstructor;
value?: boolean;
};
disabled?: {
type: BooleanConstructor;
value?: boolean;
};
inputWidth?: {
type: NumberConstructor;
value?: number;
};
integer?: {
type: BooleanConstructor;
value?: boolean;
};
max?: {
type: NumberConstructor;
value?: number;
};
min?: {
type: NumberConstructor;
value?: number;
};
size?: {
type: StringConstructor;
value?: import("../common/common").SizeEnum;
};
step?: {
type: NumberConstructor;
value?: number;
};
theme?: {
type: StringConstructor;
value?: "outline" | "filled" | "normal";
};
value?: {
type: null;
value?: string | number;
};
defaultValue?: {
type: null;
value?: string | number;
};
};
controlledProps: {
key: string;
event: string;
}[];
observers: {
value(v: any): void;
};
data: {
currentValue: number;
classPrefix: string;
prefix: string;
};
lifetimes: {
attached(): void;
};
methods: {
isDisabled(type: any): boolean;
getLen(num: number): number;
add(a: number, b: number): number;
format(value: any): string;
setValue(value: any): void;
minusValue(): boolean;
plusValue(): boolean;
filterIllegalChar(value: string | number): string;
handleFocus(e: any): void;
handleInput(e: any): void;
handleBlur(e: any): void;
};
}

View File

@@ -0,0 +1,134 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import props from './props';
const { prefix } = config;
const name = `${prefix}-stepper`;
let Stepper = class Stepper extends SuperComponent {
constructor() {
super(...arguments);
this.externalClasses = [`${prefix}-class`, `${prefix}-class-input`, `${prefix}-class-minus`, `${prefix}-class-plus`];
this.properties = Object.assign({}, props);
this.controlledProps = [
{
key: 'value',
event: 'change',
},
];
this.observers = {
value(v) {
this.preValue = Number(v);
this.setData({
currentValue: this.format(Number(v)),
});
},
};
this.data = {
currentValue: 0,
classPrefix: name,
prefix,
};
this.lifetimes = {
attached() {
const { value, min } = this.properties;
this.setData({
currentValue: value ? Number(value) : min,
});
},
};
this.methods = {
isDisabled(type) {
const { min, max, disabled } = this.properties;
const { currentValue } = this.data;
if (disabled) {
return true;
}
if (type === 'minus' && currentValue <= min) {
return true;
}
if (type === 'plus' && currentValue >= max) {
return true;
}
return false;
},
getLen(num) {
const numStr = num.toString();
return numStr.indexOf('.') === -1 ? 0 : numStr.split('.')[1].length;
},
add(a, b) {
const maxLen = Math.max(this.getLen(a), this.getLen(b));
const base = Math.pow(10, maxLen);
return Math.round(a * base + b * base) / base;
},
format(value) {
const { min, max, step } = this.properties;
const len = Math.max(this.getLen(step), this.getLen(value));
return Math.max(Math.min(max, value, Number.MAX_SAFE_INTEGER), min, Number.MIN_SAFE_INTEGER).toFixed(len);
},
setValue(value) {
value = this.format(value);
if (this.preValue === value)
return;
this.preValue = value;
this._trigger('change', { value: Number(value) });
},
minusValue() {
if (this.isDisabled('minus')) {
this.triggerEvent('overlimit', { type: 'minus' });
return false;
}
const { currentValue, step } = this.data;
this.setValue(this.add(currentValue, -step));
},
plusValue() {
if (this.isDisabled('plus')) {
this.triggerEvent('overlimit', { type: 'plus' });
return false;
}
const { currentValue, step } = this.data;
this.setValue(this.add(currentValue, step));
},
filterIllegalChar(value) {
const v = String(value).replace(/[^0-9.]/g, '');
const indexOfDot = v.indexOf('.');
if (this.properties.integer && indexOfDot !== -1) {
return v.split('.')[0];
}
if (!this.properties.integer && indexOfDot !== -1 && indexOfDot !== v.lastIndexOf('.')) {
return v.split('.', 2).join('.');
}
return v;
},
handleFocus(e) {
const { value } = e.detail;
this.triggerEvent('focus', { value });
},
handleInput(e) {
const { value } = e.detail;
if (value === '') {
return;
}
const formatted = this.filterIllegalChar(value);
this.setData({
currentValue: formatted,
});
this.triggerEvent('input', { value: formatted });
},
handleBlur(e) {
const { value: rawValue } = e.detail;
const value = this.format(rawValue);
this.setValue(value);
this.triggerEvent('blur', { value });
},
};
}
};
Stepper = __decorate([
wxComponent()
], Stepper);
export default Stepper;

View File

@@ -0,0 +1,8 @@
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {
"t-cell": "../cell/cell",
"t-icon": "../icon/icon"
}
}

View File

@@ -0,0 +1,39 @@
<wxs src="../common/utils.wxs" module="_" />
<view
style="{{_._style([style, customStyle])}}"
class="{{classPrefix}} {{classPrefix}}--{{size}} class {{prefix}}-class"
>
<view
class="{{classPrefix}}__minus {{classPrefix}}__minus--{{theme}} {{classPrefix}}__icon--{{size}} {{ disabled || disableMinus || currentValue <= min ? classPrefix + '--' + theme + '-disabled': ''}} {{prefix}}-class-minus"
catchtap="minusValue"
aria-label="{{'减少' + step}}"
aria-role="button"
aria-disabled="{{disabled || disableMinus || currentValue <= min}}"
>
<t-icon name="remove" />
</view>
<view
class="{{classPrefix}}__input--{{theme}} {{ disabled || disableInput ? classPrefix + '--' + theme + '-disabled': ''}}"
>
<input
style="{{inputWidth? 'width:' + inputWidth + 'px;': ''}}"
class="{{classPrefix}}__input {{classPrefix}}__input--{{size}} {{prefix}}-class-input"
disabled="{{ disabled || disableInput }}"
type="{{ integer ? 'number' : 'digit' }}"
value="{{ currentValue }}"
catchinput="handleInput"
catchfocus="handleFocus"
catchblur="handleBlur"
/>
</view>
<view
class="{{classPrefix}}__plus {{classPrefix}}__plus--{{theme}} {{classPrefix}}__icon--{{size}} {{ disabled || disablePlus|| currentValue >= max ? classPrefix + '--' + theme + '-disabled': ''}} {{prefix}}-class-plus"
catchtap="plusValue"
aria-label="{{'增加' + step}}"
aria-role="button"
aria-disabled="{{disabled || disablePlus|| currentValue >= max}}"
>
<t-icon name="add" />
</view>
</view>

View File

@@ -0,0 +1,132 @@
.t-float-left {
float: left;
}
.t-float-right {
float: right;
}
@keyframes tdesign-fade-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
.hotspot-expanded.relative {
position: relative;
}
.hotspot-expanded::after {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
transform: scale(1.5);
}
.t-stepper {
display: flex;
align-items: center;
color: var(--td-stepper-input-color, var(--td-text-color-primary, var(--td-font-gray-1, rgba(0, 0, 0, 0.9))));
}
.t-stepper__input {
margin: 0 8rpx;
text-align: center;
vertical-align: top;
height: inherit;
min-height: inherit;
}
.t-stepper__minus,
.t-stepper__plus {
padding: 8rpx;
box-sizing: border-box;
}
.t-stepper__input,
.t-stepper__minus-icon,
.t-stepper__plus-icon {
color: inherit;
}
.t-stepper__input--normal,
.t-stepper__input--filled,
.t-stepper__input--outline {
height: inherit;
box-sizing: border-box;
}
.t-stepper--small {
height: 40rpx;
font-size: 20rpx;
}
.t-stepper--medium {
height: 48rpx;
font-size: 24rpx;
}
.t-stepper--large {
height: 56rpx;
font-size: 32rpx;
}
.t-stepper__input--small {
width: 68rpx;
}
.t-stepper__input--medium {
height: 48rpx;
width: 76rpx;
}
.t-stepper__input--large {
width: 90rpx;
}
.t-stepper__icon--small {
width: 40rpx;
height: 40rpx;
font-size: 24rpx;
}
.t-stepper__icon--medium {
width: 48rpx;
height: 48rpx;
font-size: 32rpx;
}
.t-stepper__icon--large {
width: 56rpx;
height: 56rpx;
font-size: 40rpx;
}
.t-stepper__minus--outline,
.t-stepper__plus--outline {
border: 2rpx solid var(--td-stepper-border-color, var(--td-component-border, var(--td-gray-color-4, #dcdcdc)));
}
.t-stepper__input--outline {
border: none;
border-top: 2rpx solid var(--td-stepper-border-color, var(--td-component-border, var(--td-gray-color-4, #dcdcdc)));
border-bottom: 2rpx solid var(--td-stepper-border-color, var(--td-component-border, var(--td-gray-color-4, #dcdcdc)));
}
.t-stepper__minus--outline,
.t-stepper__minus--filled {
border-radius: 0;
border-top-left-radius: var(--td-stepper-border-radius, var(--td-radius-small, 6rpx));
border-bottom-left-radius: var(--td-stepper-border-radius, var(--td-radius-small, 6rpx));
}
.t-stepper__plus--outline,
.t-stepper__plus--filled {
border-radius: 0;
border-top-right-radius: var(--td-stepper-border-radius, var(--td-radius-small, 6rpx));
border-bottom-right-radius: var(--td-stepper-border-radius, var(--td-radius-small, 6rpx));
}
.t-stepper__minus--filled,
.t-stepper__plus--filled {
background-color: var(--td-bg-color-secondarycontainer, var(--td-gray-color-1, #f3f3f3));
}
.t-stepper__input--filled {
background-color: var(--td-bg-color-secondarycontainer, var(--td-gray-color-1, #f3f3f3));
margin: 0 8rpx;
}
.t-stepper__input--filled .t-stepper__input {
margin: 0;
}
.t-stepper--normal-disabled {
color: var(--td-stepper-input-disabled-color, var(--td-text-color-disabled, var(--td-font-gray-4, rgba(0, 0, 0, 0.26))));
}
.t-stepper--filled-disabled,
.t-stepper--outline-disabled {
color: var(--td-stepper-input-disabled-color, var(--td-text-color-disabled, var(--td-font-gray-4, rgba(0, 0, 0, 0.26))));
background-color: var(--td-stepper-input-disabled-bg, var(--td-bg-color-component-disabled, var(--td-gray-color-2, #eeeeee)));
}

View File

@@ -0,0 +1,47 @@
import { SizeEnum } from '../common/common';
export interface TdStepperProps {
disableInput?: {
type: BooleanConstructor;
value?: boolean;
};
disabled?: {
type: BooleanConstructor;
value?: boolean;
};
inputWidth?: {
type: NumberConstructor;
value?: number;
};
integer?: {
type: BooleanConstructor;
value?: boolean;
};
max?: {
type: NumberConstructor;
value?: number;
};
min?: {
type: NumberConstructor;
value?: number;
};
size?: {
type: StringConstructor;
value?: SizeEnum;
};
step?: {
type: NumberConstructor;
value?: number;
};
theme?: {
type: StringConstructor;
value?: 'normal' | 'filled' | 'outline';
};
value?: {
type: null;
value?: string | number;
};
defaultValue?: {
type: null;
value?: string | number;
};
}

View File

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