初始化项目, 添加TDesign等包

This commit is contained in:
zhengw
2025-11-28 16:49:36 +08:00
commit 3e53beb7bb
980 changed files with 39201 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import { SuperComponent } from '../common/src/index';
export default class Dialog extends SuperComponent {
behaviors: string[];
options: {
multipleSlots: boolean;
};
externalClasses: string[];
properties: import("./type").TdDialogProps;
data: {
prefix: string;
classPrefix: string;
buttonVariant: string;
};
observers: {
'confirmBtn, cancelBtn'(confirm: any, cancel: any): void;
};
methods: {
onTplButtonTap(e: any): void;
onConfirm(): void;
onCancel(): void;
onClose(): void;
close(): void;
overlayClick(): void;
onActionTap(index: number): void;
openValueCBHandle(e: any): void;
openValueErrCBHandle(e: any): void;
};
}

View File

@@ -0,0 +1 @@
import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import config from"../common/config";import props from"./props";import{toCamel}from"../common/utils";import{isObject}from"../common/validator";import useCustomNavbar from"../mixins/using-custom-navbar";const{prefix:prefix}=config,name=`${prefix}-dialog`;let Dialog=class extends SuperComponent{constructor(){super(...arguments),this.behaviors=[useCustomNavbar],this.options={multipleSlots:!0},this.externalClasses=[`${prefix}-class`,`${prefix}-class-content`,`${prefix}-class-confirm`,`${prefix}-class-cancel`,`${prefix}-class-action`],this.properties=props,this.data={prefix:prefix,classPrefix:name,buttonVariant:"text"},this.observers={"confirmBtn, cancelBtn"(t,e){const{prefix:o,classPrefix:i,buttonLayout:n}=this.data,s={buttonVariant:"text"},r=[t,e].some(t=>isObject(t)&&t.variant&&"text"!==t.variant),a={confirm:t,cancel:e},c=[`${i}__button`],l=[];r?(s.buttonVariant="base",c.push(`${i}__button--${n}`)):(c.push(`${i}__button--text`),l.push(`${i}-button`)),Object.keys(a).forEach(t=>{const e=a[t],n={block:!0,rootClass:[...c,`${i}__button--${t}`],tClass:[...l,`${o}-class-${t}`],variant:s.buttonVariant,openType:""};"cancel"===t&&"base"===s.buttonVariant&&(n.theme="light"),s[`_${t}`]="string"==typeof e?Object.assign(Object.assign({},n),{content:e}):e&&"object"==typeof e?Object.assign(Object.assign({},n),e):null}),this.setData(Object.assign({},s))}},this.methods={onTplButtonTap(t){var e,o,i;const n=t.type,{type:s,extra:r}=t.target.dataset,a=this.data[`_${s}`],c=`bind${n}`;if("action"===s)return void this.onActionTap(r);if("function"==typeof a[c]){a[c](t)&&this.close()}if(!!!a.openType&&["confirm","cancel"].includes(s)&&(null===(e=this[toCamel(`on-${s}`)])||void 0===e||e.call(this,s)),"tap"!==n){const e=(null===(i=null===(o=t.detail)||void 0===o?void 0:o.errMsg)||void 0===i?void 0:i.indexOf("ok"))>-1;this.triggerEvent(e?"open-type-event":"open-type-error-event",t.detail)}},onConfirm(){this.triggerEvent("confirm"),this._onConfirm&&(this._onConfirm({trigger:"confirm"}),this.close())},onCancel(){const t={trigger:"cancel"};this.triggerEvent("cancel"),this.triggerEvent("close",t),this._onCancel&&(this._onCancel(t),this.close())},onClose(){var t;const e={trigger:"close-btn"};this.triggerEvent("close",e),null===(t=this._onCancel)||void 0===t||t.call(this,e),this.close()},close(){this.setData({visible:!1})},overlayClick(){var t;if(this.triggerEvent("overlay-click"),this.properties.closeOnOverlayClick){const e={trigger:"overlay"};this.triggerEvent("close",e),null===(t=this._onCancel)||void 0===t||t.call(this,e),this.close()}},onActionTap(t){this.triggerEvent("action",{index:t}),this._onAction&&(this._onAction({index:t}),this.close())},openValueCBHandle(t){this.triggerEvent("open-type-event",t.detail)},openValueErrCBHandle(t){this.triggerEvent("open-type-error-event",t.detail)}}}};Dialog=__decorate([wxComponent()],Dialog);export default Dialog;

View File

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

View File

@@ -0,0 +1 @@
<import src="../common/template/button.wxml"/><import src="../common/template/icon.wxml"/><wxs src="../common/utils.wxs" module="_"/><wxs src="./dialog.wxs" module="_this"/><t-popup name="dialog" style="{{_._style([style, customStyle])}}" class="class" t-class="{{classPrefix}}__wrapper" visible="{{visible}}" showOverlay="{{showOverlay}}" closeOnOverlayClick="{{closeOnOverlayClick}}" preventScrollThrough="{{preventScrollThrough}}" overlayProps="{{overlayProps}}" zIndex="{{zIndex}}" placement="center" usingCustomNavbar="{{usingCustomNavbar}}" bind:visible-change="overlayClick"><view slot="content" class="{{classPrefix}} {{prefix}}-class"><slot name="top"/><view wx:if="{{closeBtn}}" class="{{classPrefix}}__close-btn" bind:tap="onClose"><template wx:if="{{_.isObject(closeBtn)}}" is="icon" data="{{ name: 'close', size: 22, ...closeBtn }}"/><t-icon wx:else name="close" size="44rpx"/></view><view class="{{classPrefix}}__content {{prefix}}-class-content"><view wx:if="{{title}}" class="{{classPrefix}}__header">{{title}}</view><slot name="title"/><view wx:if="{{content}}" class="{{classPrefix}}__body"><text class="{{classPrefix}}__body-text">{{content}}</text></view><slot name="content"/></view><slot name="middle"/><view class="{{_.cls(classPrefix + '__footer', [['column', buttonLayout === 'vertical'], ['full', buttonVariant == 'text' && actions.length == 0]])}}"><block wx:if="{{actions}}"><block wx:for="{{actions}}" wx:key="index"><template is="button" data="{{block: true, type: 'action', extra: index, tClass: prefix + '-class-action', rootClass: _this.getActionClass(classPrefix, buttonLayout), ...item }}"/></block></block><slot name="actions"/><block wx:if="{{_cancel}}"><template is="button" data="{{type: 'cancel', ..._cancel }}"/></block><slot name="cancel-btn"/><block wx:if="{{_confirm}}"><template is="button" data="{{type: 'confirm', theme: 'primary', ..._confirm}}"/></block><slot name="confirm-btn"/></view></view></t-popup>

View File

@@ -0,0 +1,13 @@
module.exports.getTypeof = function (obj) {
return typeof obj;
};
module.exports.getActionClass = function (prefix, buttonLayout) {
var cls = [prefix + '__button', prefix + '__button--action'];
if (buttonLayout) {
cls.push(prefix + '__button--' + buttonLayout);
}
return cls.join(' ');
};

View File

@@ -0,0 +1,20 @@
@import '../common/style/index.wxss';.t-dialog{overflow:hidden;width:var(--td-dialog-width,622rpx);border-radius:var(--td-dialog-border-radius,var(--td-radius-extraLarge,24rpx));background-color:var(--td-bg-color-container,var(--td-font-white-1,#fff));}
.t-dialog__wrapper{--td-popup-border-radius:var(--td-dialog-border-radius, var(--td-radius-extraLarge, 24rpx));}
.t-dialog__close-btn{position:absolute;top:var(--td-spacer,16rpx);right:var(--td-spacer,16rpx);color:var(--td-dialog-close-color,var(--td-text-color-placeholder,var(--td-font-gray-3,rgba(0,0,0,.4))));z-index:1;}
.t-dialog__content{padding-top:var(--td-spacer-3,48rpx);padding-right:var(--td-spacer-3,48rpx);padding-bottom:0;padding-left:var(--td-spacer-3,48rpx);max-height:var(--td-dialog-body-max-height,912rpx);box-sizing:border-box;display:flex;flex-direction:column;justify-content:center;font-size:var(--td-font-size-m,32rpx);}
.t-dialog__content:empty{display:none;}
.t-dialog__header{text-align:center;font-weight:700;font-size:var(--td-dialog-title-font-size,36rpx);line-height:var(--td-dialog-title-line-height,52rpx);color:var(--td-dialog-title-color,var(--td-text-color-primary,var(--td-font-gray-1,rgba(0,0,0,.9))));}
.t-dialog__header+.t-dialog__body{margin-top:var(--td-spacer,16rpx);}
.t-dialog__body{overflow-y:scroll;text-align:center;-webkit-overflow-scrolling:touch;font-size:var(--td-dialog-content-font-size,32rpx);color:var(--td-dialog-content-color,var(--td-text-color-secondary,var(--td-font-gray-2,rgba(0,0,0,.6))));line-height:var(--td-dialog-content-line-height,48rpx);}
.t-dialog__body-text{word-wrap:break-word;}
.t-dialog__body--left{text-align:left;}
.t-dialog__body--right{text-align:right;}
.t-dialog__footer{display:flex;padding:var(--td-spacer-3,48rpx);}
.t-dialog__footer--column{flex-flow:column-reverse;}
.t-dialog__footer--column .t-dialog__button{width:100%;}
.t-dialog__footer--full{padding:var(--td-spacer-4,64rpx) 0 0;}
.t-dialog__button{position:relative;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.t-dialog__button--horizontal+.t-dialog__button--horizontal{margin-left:var(--td-spacer-1,24rpx);}
.t-dialog__button--vertical+.t-dialog__button--vertical{margin-bottom:var(--td-spacer-1,24rpx);}
.t-dialog__button--text{flex:1;--td-button-border-radius:0;--td-button-medium-height:112rpx;border-radius:0;}
.t-dialog__button--text:before{content:' ';position:absolute;box-sizing:border-box;top:0;left:0;border-top:1px solid var(--td-border-level-1-color,var(--td-gray-color-3,#e7e7e7));border-left:1px solid var(--td-border-level-1-color,var(--td-gray-color-3,#e7e7e7));transform:scale(.5);transform-origin:0 0;width:200%;height:200%;border-radius:0;}

View File

@@ -0,0 +1,44 @@
/// <reference types="miniprogram-api-typings" />
/// <reference types="miniprogram-api-typings" />
declare type Context = WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;
interface DialogAlertOptionsType {
context?: Context;
selector?: string;
title?: string;
content?: string;
zIndex?: number;
asyncClose?: boolean;
confirmButtonText?: string;
textAlign?: string;
cancelBtn?: string | object;
confirmBtn?: string | object;
showOverlay?: boolean;
closeOnOverlayClick?: boolean;
preventScrollThrough?: boolean;
}
interface DialogConfirmOptionsType extends DialogAlertOptionsType {
cancelButtonText?: string;
}
interface Action {
content: string;
theme?: 'default' | 'primary' | 'danger' | 'light';
}
interface DialogActionOptionsType {
context?: Context;
selector?: string;
title?: string;
content: string;
zIndex?: number;
asyncClose?: boolean;
actions?: Action[];
buttonLayout?: 'vertical' | 'horizontal';
}
declare const _default: {
alert(options: DialogAlertOptionsType): Promise<unknown>;
confirm(options: DialogConfirmOptionsType): Promise<unknown>;
close(options?: DialogConfirmOptionsType): Promise<void>;
action(options: DialogActionOptionsType): Promise<{
index: number;
}>;
};
export default _default;

View File

@@ -0,0 +1 @@
import{__rest}from"tslib";import props from"./props";import{getInstance}from"../common/utils";const defaultOptions={actions:[],buttonLayout:props.buttonLayout.value,cancelBtn:props.cancelBtn.value,closeOnOverlayClick:props.closeOnOverlayClick.value,confirmBtn:props.confirmBtn.value,content:"",preventScrollThrough:props.preventScrollThrough.value,showOverlay:props.showOverlay.value,title:"",visible:props.visible.value};export default{alert(t){const e=Object.assign({},t),{context:s,selector:o="#t-dialog"}=e,n=__rest(e,["context","selector"]),c=getInstance(s,o);return c?new Promise(t=>{const e=Object.assign(Object.assign(Object.assign({},defaultOptions),c.properties),n);c.setData(Object.assign(Object.assign({cancelBtn:""},e),{visible:!0})),c._onConfirm=t}):Promise.reject()},confirm(t){const e=Object.assign({},t),{context:s,selector:o="#t-dialog"}=e,n=__rest(e,["context","selector"]),c=getInstance(s,o);return c?new Promise((t,e)=>{const s=Object.assign(Object.assign(Object.assign({},defaultOptions),c.properties),n);c.setData(Object.assign(Object.assign({},s),{visible:!0})),c._onConfirm=t,c._onCancel=e}):Promise.reject()},close(t){const{context:e,selector:s="#t-dialog"}=Object.assign({},t),o=getInstance(e,s);return o?(o.close(),Promise.resolve()):Promise.reject()},action(t){const e=Object.assign({},t),{context:s,selector:o="#t-dialog"}=e,n=__rest(e,["context","selector"]),c=getInstance(s,o);if(!c)return Promise.reject();const{buttonLayout:r="vertical",actions:i=c.properties.actions}=t,a="vertical"===r?7:3;return(!i||"object"==typeof i&&(0===i.length||i.length>a))&&console.warn(`action 数量建议控制在1至${a}`),new Promise(t=>{const e=Object.assign(Object.assign(Object.assign({},defaultOptions),c.properties),n);c.setData(Object.assign(Object.assign({},e),{buttonLayout:r,visible:!0})),c._onAction=t})}};

View File

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

View File

@@ -0,0 +1 @@
const props={actions:{type:Array},buttonLayout:{type:String,value:"horizontal"},cancelBtn:{type:null},closeBtn:{type:null,value:!1},closeOnOverlayClick:{type:Boolean,value:!1},confirmBtn:{type:null},content:{type:String},overlayProps:{type:Object,value:{}},preventScrollThrough:{type:Boolean,value:!0},showOverlay:{type:Boolean,value:!0},title:{type:String},usingCustomNavbar:{type:Boolean,value:!1},visible:{type:Boolean},zIndex:{type:Number,value:11500}};export default props;

View File

@@ -0,0 +1,60 @@
import { ButtonProps } from '../button/index';
import { OverlayProps } from '../overlay/index';
export interface TdDialogProps {
actions?: {
type: ArrayConstructor;
value?: Array<ButtonProps>;
};
buttonLayout?: {
type: StringConstructor;
value?: 'horizontal' | 'vertical';
};
cancelBtn?: {
type: null;
value?: string | ButtonProps | null;
};
closeBtn?: {
type: null;
value?: boolean | ButtonProps | null;
};
closeOnOverlayClick?: {
type: BooleanConstructor;
value?: boolean;
};
confirmBtn?: {
type: null;
value?: string | ButtonProps | null;
};
content?: {
type: StringConstructor;
value?: string;
};
overlayProps?: {
type: ObjectConstructor;
value?: OverlayProps;
};
preventScrollThrough?: {
type: BooleanConstructor;
value?: boolean;
};
showOverlay?: {
type: BooleanConstructor;
value?: boolean;
};
title?: {
type: StringConstructor;
value?: string;
};
usingCustomNavbar?: {
type: BooleanConstructor;
value?: boolean;
};
visible?: {
type: BooleanConstructor;
value?: boolean;
};
zIndex?: {
type: NumberConstructor;
value?: number;
};
}

View File

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