初始化项目, 添加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,36 @@
import { SuperComponent } from '../common/src/index';
export default class Navbar extends SuperComponent {
externalClasses: string[];
timer: any;
options: {
multipleSlots: boolean;
};
properties: import("./type").TdNavbarProps;
observers: {
visible(this: Navbar, visible: any): void;
'title,titleMaxLength'(this: any): void;
};
data: {
prefix: string;
classPrefix: string;
boxStyle: string;
showTitle: string;
hideLeft: boolean;
hideCenter: boolean;
_menuRect: any;
_leftRect: any;
_boxStyle: {};
};
attached(): void;
detached(): void;
methods: {
initStyle(): void;
calcCenterStyle(leftRect: WechatMiniprogram.BoundingClientRectResult, menuRect: WechatMiniprogram.BoundingClientRectResult, defaultStyle: object): void;
getLeftRect(): void;
getMenuRect(): void;
onMenuButtonBoundingClientRectWeightChange(): void;
offMenuButtonBoundingClientRectWeightChange(): void;
queryElements(capsuleRect: WechatMiniprogram.OnMenuButtonBoundingClientRectWeightChangeListenerResult): void;
goBack(): void;
};
}

View File

@@ -0,0 +1 @@
import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import{getRect,systemInfo}from"../common/utils";import config from"../common/config";import props from"./props";const{prefix:prefix}=config,name=`${prefix}-navbar`;let Navbar=class extends SuperComponent{constructor(){super(...arguments),this.externalClasses=[`${prefix}-class`,`${prefix}-class-placeholder`,`${prefix}-class-content`,`${prefix}-class-title`,`${prefix}-class-left`,`${prefix}-class-center`,`${prefix}-class-left-icon`,`${prefix}-class-home-icon`,`${prefix}-class-capsule`,`${prefix}-class-nav-btn`],this.timer=null,this.options={multipleSlots:!0},this.properties=props,this.observers={visible(t){const{animation:e}=this.properties,i=`${name}${t?"--visible":"--hide"}`;this.setData({visibleClass:`${i}${e?"-animation":""}`}),this.timer&&clearTimeout(this.timer),e&&(this.timer=setTimeout(()=>{this.setData({visibleClass:i})},300))},"title,titleMaxLength"(){const{title:t}=this.properties,e=this.properties.titleMaxLength||Number.MAX_SAFE_INTEGER;let i=t.slice(0,e);e<t.length&&(i+="..."),this.setData({showTitle:i})}},this.data={prefix:prefix,classPrefix:name,boxStyle:"",showTitle:"",hideLeft:!1,hideCenter:!1,_menuRect:null,_leftRect:null,_boxStyle:{}},this.methods={initStyle(){this.getMenuRect();const{_menuRect:t,_leftRect:e}=this.data;if(!t||!e||!systemInfo)return;const i={"--td-navbar-padding-top":`${systemInfo.statusBarHeight}px`,"--td-navbar-right":systemInfo.windowWidth-t.left+"px","--td-navbar-left-max-width":`${t.left}px`,"--td-navbar-capsule-height":`${t.height}px`,"--td-navbar-capsule-width":`${t.width}px`,"--td-navbar-height":`${2*(t.top-systemInfo.statusBarHeight)+t.height}px`};this.calcCenterStyle(e,t,i)},calcCenterStyle(t,e,i){const n=Math.max(t.right,systemInfo.windowWidth-e.left),s=Object.assign(Object.assign({},i),{"--td-navbar-center-left":`${n}px`,"--td-navbar-center-width":`${Math.max(e.left-n,0)}px`}),a=Object.entries(s).map(([t,e])=>`${t}: ${e}`).join("; ");this.setData({boxStyle:a,_boxStyle:s})},getLeftRect(){getRect(this,`.${name}__left`).then(t=>{t.right>this.data._leftRect.right&&this.calcCenterStyle(t,this.data._menuRect,this.data._boxStyle)})},getMenuRect(){if(wx.getMenuButtonBoundingClientRect){const t=wx.getMenuButtonBoundingClientRect();this.setData({_menuRect:t,_leftRect:{right:systemInfo.windowWidth-t.left}})}},onMenuButtonBoundingClientRectWeightChange(){wx.onMenuButtonBoundingClientRectWeightChange&&(this.onMenuButtonBoundingClientRectWeightChangeCallback=t=>this.queryElements(t),wx.onMenuButtonBoundingClientRectWeightChange(this.onMenuButtonBoundingClientRectWeightChangeCallback))},offMenuButtonBoundingClientRectWeightChange(){this.onMenuButtonBoundingClientRectWeightChangeCallback&&wx.offMenuButtonBoundingClientRectWeightChange(this.onMenuButtonBoundingClientRectWeightChangeCallback)},queryElements(t){Promise.all([getRect(this,`.${this.data.classPrefix}__left`),getRect(this,`.${this.data.classPrefix}__center`)]).then(([e,i])=>{const n=Math.round(e.right),s=Math.round(i.right),a=t.left;this.setData({hideLeft:n>a,hideCenter:n>a||s>a})})},goBack(){const{delta:t}=this.data,e=this;this.triggerEvent("go-back"),t>0&&wx.navigateBack({delta:t,fail(t){e.triggerEvent("fail",t)},complete(t){e.triggerEvent("complete",t)},success(t){e.triggerEvent("success",t)}})}}}attached(){this.initStyle(),this.getLeftRect(),this.onMenuButtonBoundingClientRectWeightChange()}detached(){this.offMenuButtonBoundingClientRectWeightChange()}};Navbar=__decorate([wxComponent()],Navbar);export default Navbar;

View File

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

View File

@@ -0,0 +1 @@
<wxs src="../common/utils.wxs" module="_"/><view class="{{_.cls(classPrefix, [['fixed', fixed]])}} {{visibleClass}} class {{prefix}}-class" style="{{_._style([boxStyle, style, customStyle])}}"><view wx:if="{{fixed}}" class="{{classPrefix}}__placeholder {{prefix}}-class-placeholder"/><view class="{{classPrefix}}__content {{prefix}}-class-content"><view class="{{classPrefix}}__left {{hideLeft ? classPrefix + '__left--hide' : ''}} {{prefix}}-class-left"><view wx:if="{{leftArrow}}" class="{{classPrefix}}__btn" bind:tap="goBack" aria-role="button" aria-label="返回"><t-icon name="chevron-left" class="{{classPrefix}}__left-arrow"/></view><slot name="left"/><view class="{{classPrefix}}__capsule {{prefix}}-class-capsule"><slot name="capsule"/></view></view><view class="{{classPrefix}}__center {{hideCenter ? classPrefix + '__center--hide' : ''}} {{prefix}}-class-center"><slot name="title"/><text wx:if="{{title}}" class="{{classPrefix}}__center-title {{prefix}}-class-title">{{showTitle}}</text></view></view></view>

View File

@@ -0,0 +1,17 @@
@import '../common/style/index.wxss';.t-navbar--fixed .t-navbar__content{position:fixed;top:0;left:0;z-index:5001;}
.t-navbar--visible{display:'';}
.t-navbar--visible-animation{opacity:1;transition:opacity .3s cubic-bezier(.645,.045,.355,1);}
.t-navbar--hide-animation{opacity:0;transition:opacity .3s cubic-bezier(.645,.045,.355,1);}
.t-navbar--hide{display:none;}
.t-navbar__placeholder{height:var(--td-navbar-height,48px);padding-top:var(--td-navbar-padding-top,20px);position:relative;visibility:hidden;box-sizing:content-box;}
.t-navbar__content{position:relative;z-index:1;height:var(--td-navbar-height,48px);width:calc(100% - var(--td-navbar-right,95px));padding-right:var(--td-navbar-right,95px);padding-top:var(--td-navbar-padding-top,20px);color:var(--td-navbar-color,var(--td-text-color-primary,var(--td-font-gray-1,rgba(0,0,0,.9))));background:var(--td-navbar-background,var(--td-navbar-bg-color,var(--td-bg-color-container,var(--td-font-white-1,#fff))));display:flex;align-items:center;box-sizing:content-box;}
.t-navbar__left{position:relative;box-sizing:border-box;max-width:var(--td-navbar-left-max-width);overflow:hidden;display:flex;align-items:center;margin-left:var(--td-spacer-1,24rpx);transition:opacity .3s cubic-bezier(.645,.045,.355,1);}
.t-navbar__left-arrow{font-size:var(--td-navbar-left-arrow-size,24px);}
.t-navbar__left--hide{opacity:0;}
.t-navbar__capsule{box-sizing:border-box;width:var(--td-navbar-capsule-width,88px);height:var(--td-navbar-capsule-height,32px);display:flex;align-items:center;}
.t-navbar__capsule::before{content:'';position:absolute;z-index:-1;top:0;left:0;width:200%;height:200%;transform:scale(.5);transform-origin:0 0;box-sizing:border-box;border-radius:calc(var(--td-navbar-capsule-border-radius,16px) * 2);border:2rpx solid var(--td-navbar-capsule-border-color,var(--td-border-level-1-color,var(--td-gray-color-3,#e7e7e7)));}
.t-navbar__capsule:empty{display:none;}
.t-navbar__center{font-size:18px;text-align:center;position:absolute;bottom:0;left:var(--td-navbar-center-left,var(--td-navbar-right,95px));width:var(--td-navbar-center-width,187px);height:var(--td-navbar-height,48px);line-height:var(--td-navbar-height,48px);flex:1;display:flex;align-items:center;justify-content:center;overflow:hidden;transition:opacity .3s cubic-bezier(.645,.045,.355,1);}
.t-navbar__center:empty{display:none;}
.t-navbar__center-title{font-size:var(--td-navbar-title-font-size,18px);text-overflow:ellipsis;white-space:nowrap;overflow:hidden;font-weight:var(--td-navbar-title-font-weight,600);}
.t-navbar__center--hide{opacity:0;}

View File

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

View File

@@ -0,0 +1 @@
const props={animation:{type:Boolean,value:!0},delta:{type:Number,value:1},fixed:{type:Boolean,value:!0},leftArrow:{type:Boolean,value:!1},safeAreaInsetTop:{type:Boolean,value:!0},title:{type:String},titleMaxLength:{type:Number},visible:{type:Boolean,value:!0}};export default props;

View File

@@ -0,0 +1,34 @@
export interface TdNavbarProps {
animation?: {
type: BooleanConstructor;
value?: boolean;
};
delta?: {
type: NumberConstructor;
value?: number;
};
fixed?: {
type: BooleanConstructor;
value?: boolean;
};
leftArrow?: {
type: BooleanConstructor;
value?: boolean;
};
safeAreaInsetTop?: {
type: BooleanConstructor;
value?: boolean;
};
title?: {
type: StringConstructor;
value?: string;
};
titleMaxLength?: {
type: NumberConstructor;
value?: number;
};
visible?: {
type: BooleanConstructor;
value?: boolean;
};
}

View File

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