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,44 @@
:: BASE_DOC ::
## API
### Toast 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
direction | String | row | options: row/column | N
duration | Number | 2000 | \- | N
icon | String / Object / Slot | - | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
message | String / Slot | - | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
overlay-props | Object | - | Typescript`OverlayProps `[Overlay API Documents](./overlay?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/toast/type.ts) | N
placement | String | middle | options: top/middle/bottom | N
prevent-scroll-through | Boolean | false | \- | N
show-overlay | Boolean | false | \- | N
theme | String | - | options: loading/success/error | N
using-custom-navbar | Boolean | false | \- | N
### Toast Events
name | params | description
-- | -- | --
close | \- | \-
destroy | \- | \-
### Toast External Classes
className | Description
-- | --
t-class | \-
### CSS Variables
The component provides the following CSS variables, which can be used to customize styles.
Name | Default Value | Description
-- | -- | --
--td-toast-bg-color | @font-gray-2 | -
--td-toast-color | @font-white-1 | -
--td-toast-column-icon-size | 64rpx | -
--td-toast-max-width | 374rpx | -
--td-toast-radius | 8rpx | -
--td-toast-row-icon-size | 48rpx | -

View File

@@ -0,0 +1,81 @@
---
title: Toast 轻提示
description: 用于轻量级反馈或提示,不会打断用户操作。
spline: message
isComponent: true
---
<span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20lines-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20functions-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20statements-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20branches-83%25-blue" /></span>
## 引入
全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。
```json
"usingComponents": {
"t-toast": "tdesign-miniprogram/toast/toast"
}
```
## 代码演示
<a href="https://developers.weixin.qq.com/s/l0azMimf7CSu" 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 }}
### 组件状态
{{ theme }}
### 显示遮罩
{{ cover }}
### 手动关闭
{{ close }}
## API
### Toast Props
名称 | 类型 | 默认值 | 描述 | 必传
-- | -- | -- | -- | --
style | Object | - | 样式 | N
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
direction | String | row | 图标排列方式。可选项row/column | N
duration | Number | 2000 | 弹窗显示毫秒数 | N
icon | String / Object / Slot | - | 自定义图标。传入对象则透传至 Icon 组件。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
message | String / Slot | - | 弹窗显示文字。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
overlay-props | Object | - | 遮罩层属性,透传至 Overlay。TS 类型:`OverlayProps `[Overlay API Documents](./overlay?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/toast/type.ts) | N
placement | String | middle | 弹窗展示位置。可选项: top/middle/bottom | N
prevent-scroll-through | Boolean | false | 防止滚动穿透,即不允许点击和滚动 | N
show-overlay | Boolean | false | 是否显示遮罩层 | N
theme | String | - | 提示类型。可选项loading/success/error | N
using-custom-navbar | Boolean | false | 是否使用了自定义导航栏 | N
### Toast Events
名称 | 参数 | 描述
-- | -- | --
close | \- | 轻提示隐藏的时候触发
destroy | \- | 轻提示销毁的时候触发
### Toast External Classes
类名 | 描述
-- | --
t-class | 根节点样式类
### CSS Variables
组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--td-toast-bg-color | @font-gray-2 | -
--td-toast-color | @font-white-1 | -
--td-toast-column-icon-size | 64rpx | -
--td-toast-max-width | 374rpx | -
--td-toast-radius | 8rpx | -
--td-toast-row-icon-size | 48rpx | -

View File

@@ -0,0 +1,22 @@
/// <reference types="miniprogram-api-typings" />
/// <reference types="miniprogram-api-typings" />
declare type Context = WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;
declare type ToastType = 'loading' | 'success' | 'error';
declare type ToastPositionType = 'top' | 'middle' | 'bottom';
declare type ToastDirectionType = 'row' | 'column';
export declare type ToastOptionsType = {
context?: Context;
selector?: string;
icon?: string;
message?: string;
duration?: number;
theme?: ToastType;
placement?: ToastPositionType;
preventScrollThrough?: boolean;
direction?: ToastDirectionType;
close?: () => void;
};
declare function Toast(options: ToastOptionsType): void;
declare function showToast(options?: ToastOptionsType): void;
declare function hideToast(options?: ToastOptionsType): void;
export { Toast as default, showToast, hideToast };

View File

@@ -0,0 +1,31 @@
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { getInstance } from '../common/utils';
function Toast(options) {
var _a;
const { context, selector = '#t-toast' } = options, Options = __rest(options, ["context", "selector"]);
const instance = getInstance(context, selector);
if (instance) {
instance.show(Object.assign(Object.assign({}, Options), { duration: (_a = Options.duration) !== null && _a !== void 0 ? _a : 2000 }));
}
}
function showToast(options = {}) {
Toast(options);
}
function hideToast(options = {}) {
const { context, selector = '#t-toast' } = options;
const instance = getInstance(context, selector);
if (instance) {
instance.hide();
}
}
export { Toast as default, showToast, hideToast };

View File

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

View File

@@ -0,0 +1,39 @@
const props = {
direction: {
type: String,
value: 'row',
},
duration: {
type: Number,
value: 2000,
},
icon: {
type: null,
},
message: {
type: String,
},
overlayProps: {
type: Object,
},
placement: {
type: String,
value: 'middle',
},
preventScrollThrough: {
type: Boolean,
value: false,
},
showOverlay: {
type: Boolean,
value: false,
},
theme: {
type: String,
},
usingCustomNavbar: {
type: Boolean,
value: false,
},
};
export default props;

View File

@@ -0,0 +1,31 @@
/// <reference types="node" />
import { SuperComponent } from '../common/src/index';
import { ToastOptionsType } from './index';
declare type Timer = NodeJS.Timeout | null;
export default class Toast extends SuperComponent {
externalClasses: string[];
options: {
multipleSlots: boolean;
};
behaviors: string[];
hideTimer: Timer;
data: {
prefix: string;
classPrefix: string;
typeMapIcon: string;
};
properties: import("./type").TdToastProps;
lifetimes: {
detached(): void;
};
pageLifetimes: {
hide(): void;
};
methods: {
show(options: ToastOptionsType): void;
hide(): void;
destroyed(): void;
loop(): void;
};
}
export {};

View File

@@ -0,0 +1,91 @@
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';
import transition from '../mixins/transition';
import { calcIcon } from '../common/utils';
import useCustomNavbar from '../mixins/using-custom-navbar';
const { prefix } = config;
const name = `${prefix}-toast`;
let Toast = class Toast extends SuperComponent {
constructor() {
super(...arguments);
this.externalClasses = [`${prefix}-class`];
this.options = {
multipleSlots: true,
};
this.behaviors = [transition(), useCustomNavbar];
this.hideTimer = null;
this.data = {
prefix,
classPrefix: name,
typeMapIcon: '',
};
this.properties = props;
this.lifetimes = {
detached() {
this.destroyed();
},
};
this.pageLifetimes = {
hide() {
this.hide();
},
};
this.methods = {
show(options) {
if (this.hideTimer)
clearTimeout(this.hideTimer);
const iconMap = {
loading: 'loading',
success: 'check-circle',
warning: 'error-circle',
error: 'close-circle',
};
const typeMapIcon = iconMap[options === null || options === void 0 ? void 0 : options.theme];
const defaultOptions = {
direction: props.direction.value,
duration: props.duration.value,
icon: props.icon.value,
message: props.message.value,
placement: props.placement.value,
preventScrollThrough: props.preventScrollThrough.value,
theme: props.theme.value,
};
const data = Object.assign(Object.assign(Object.assign({}, defaultOptions), options), { visible: true, isLoading: (options === null || options === void 0 ? void 0 : options.theme) === 'loading', _icon: calcIcon(typeMapIcon !== null && typeMapIcon !== void 0 ? typeMapIcon : options.icon) });
const { duration } = data;
this.setData(data);
if (duration > 0) {
this.hideTimer = setTimeout(() => {
this.hide();
}, duration);
}
},
hide() {
var _a, _b;
if (!this.data.visible)
return;
this.setData({ visible: false });
(_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a);
this.triggerEvent('close');
},
destroyed() {
if (this.hideTimer) {
clearTimeout(this.hideTimer);
this.hideTimer = null;
}
this.triggerEvent('destory');
},
loop() { },
};
}
};
Toast = __decorate([
wxComponent()
], Toast);
export default Toast;

View File

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

View File

@@ -0,0 +1,38 @@
<import src="../common/template/icon.wxml" />
<wxs src="../common/utils.wxs" module="_" />
<view
wx:if="{{realVisible}}"
class="{{_.cls(classPrefix, [direction, theme, ['with-text', message]])}} class {{prefix}}-class {{transitionClass}}"
style="{{_._style([ 'top:' + (placement === 'top' ? '25%' : placement === 'bottom' ? '75%': '45%'), style, customStyle])}}"
bind:transitionend="onTransitionEnd"
catch:touchstart="loop"
>
<view class="{{classPrefix}}__content {{classPrefix}}__content--{{direction}}">
<t-loading
wx:if="{{isLoading}}"
theme="circular"
size="{{direction === 'row' ? '48rpx' : '64rpx'}}"
loading
inherit-color
layout="vertical"
/>
<template
wx:elif="{{_icon}}"
is="icon"
data="{{ ariaHidden: true, tClass: classPrefix + '__icon ' + classPrefix + '__icon--' + direction, ..._icon }}"
/>
<slot name="icon" />
<view aria-role="alert" class="{{classPrefix}}__text {{classPrefix}}__text--{{direction}}">{{message}}</view>
<slot name="message" />
</view>
</view>
<t-overlay
style="{{ overlayProps && overlayProps.style || ''}}"
visible="{{realVisible && (showOverlay || preventScrollThrough)}}"
z-index="{{overlayProps && overlayProps.zIndex || 11000}}"
duration="{{overlayProps && overlayProps.duration || 300}}"
usingCustomNavbar="{{overlayProps && overlayProps.usingCustomNavbar || usingCustomNavbar}}"
backgroundColor="{{preventScrollThrough ? 'transparent' : overlayProps && overlayProps.backgroundColor || ''}}"
preventScrollThrough="{{preventScrollThrough || overlayProps && overlayProps.preventScrollThrough}}"
/>

View File

@@ -0,0 +1,98 @@
.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-toast {
position: fixed;
right: -50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 12001;
opacity: 1;
transition: opacity 300ms ease;
background-color: var(--td-toast-bg-color, var(--td-font-gray-2, rgba(0, 0, 0, 0.6)));
border-radius: var(--td-toast-radius, 8rpx);
font-size: 28rpx;
color: var(--td-toast-color, var(--td-text-color-anti, var(--td-font-white-1, #ffffff)));
max-width: var(--td-toast-max-width, 374rpx);
width: fit-content;
box-sizing: border-box;
}
.t-toast--column {
padding: 48rpx;
min-width: 160rpx;
min-height: 160rpx;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
}
.t-toast--loading.t-toast--with-text {
min-width: 204rpx;
min-height: 204rpx;
padding-top: 0;
padding-bottom: 0;
}
.t-toast__content {
align-items: center;
line-height: 44rpx;
}
.t-toast__content--row {
display: flex;
text-align: left;
padding: 28rpx 44rpx;
}
.t-toast__content--column {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.t-toast__icon--row {
display: flex;
font-size: var(--td-toast-row-icon-size, 48rpx);
}
.t-toast__icon--column {
font-size: var(--td-toast-column-icon-size, 64rpx);
}
.t-toast__text {
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
display: -webkit-box;
-webkit-box-orient: vertical;
white-space: pre-line;
}
.t-toast__text--column:not(:empty):not(:only-child) {
margin-top: 16rpx;
}
.t-toast__text--row:not(:empty):not(:only-child) {
margin-left: 16rpx;
}
.t-toast.t-fade-enter,
.t-toast.t-fade-leave-to {
opacity: 0;
}

View File

@@ -0,0 +1,43 @@
import { OverlayProps } from '../overlay/index';
export interface TdToastProps {
direction?: {
type: StringConstructor;
value?: 'row' | 'column';
};
duration?: {
type: NumberConstructor;
value?: number;
};
icon?: {
type: null;
value?: string | object;
};
message?: {
type: StringConstructor;
value?: string;
};
overlayProps?: {
type: ObjectConstructor;
value?: OverlayProps;
};
placement?: {
type: StringConstructor;
value?: 'top' | 'middle' | 'bottom';
};
preventScrollThrough?: {
type: BooleanConstructor;
value?: boolean;
};
showOverlay?: {
type: BooleanConstructor;
value?: boolean;
};
theme?: {
type: StringConstructor;
value?: 'loading' | 'success' | 'error';
};
usingCustomNavbar?: {
type: BooleanConstructor;
value?: boolean;
};
}

View File

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