初始化项目, 添加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,15 @@
declare type ControlInstance = {
controlled: boolean;
initValue: any;
set(newVal: any, extObj?: Object, fn?: any): void;
get(): any;
change(newVal: any, customChangeData?: any, customUpdateFn?: any): void;
};
declare type ControlOption = {
valueKey?: string;
defaultValueKey?: string;
changeEventName?: string;
strict?: boolean;
};
declare function useControl(this: any, option?: ControlOption): ControlInstance;
export { ControlOption, ControlInstance, useControl };

View File

@@ -0,0 +1 @@
const defaultOption={valueKey:"value",defaultValueKey:"defaultValue",changeEventName:"change",strict:!0};function useControl(e={}){const{valueKey:t,defaultValueKey:a,changeEventName:n,strict:s}=Object.assign(Object.assign({},defaultOption),e),l=this.properties||{},i=l[t],u=l[s?a:t];let o=!1;s&&null!=i&&(o=!0);const c=(e,a,n)=>{this.setData(Object.assign({[`_${t}`]:e},a),n)};return{controlled:o,initValue:o?i:u,set:c,get:()=>this.data[`_${t}`],change:(e,t,a)=>{this.triggerEvent(n,void 0!==t?t:e),o||("function"==typeof a?a():c(e))}}}export{useControl};

View File

@@ -0,0 +1,13 @@
export declare const getPrototypeOf: (obj: any) => any;
export declare const iterateInheritedPrototype: (callback: (proto: Record<string, any>) => boolean | void, fromCtor: any, toCtor: any, includeToCtor?: boolean) => void;
export interface ClassInstanceToObjectOptions {
bindTo?: any;
excludes?: string[];
till?: any;
enumerable?: 0 | boolean;
configurable?: 0 | boolean;
writable?: 0 | boolean;
}
export declare const toObject: (something: any, options?: ClassInstanceToObjectOptions) => {
[key: string]: any;
};

View File

@@ -0,0 +1 @@
import{isObject}from"../../common/validator";export const getPrototypeOf=function(t){return Object.getPrototypeOf?Object.getPrototypeOf(t):t.__proto__};export const iterateInheritedPrototype=function(t,e,o,r=!0){let n=e.prototype||e;const c=o.prototype||o;for(;n&&(r||n!==c)&&!1!==t(n)&&n!==c;)n=getPrototypeOf(n)};export const toObject=function(t,e={}){const o={};if(!isObject(t))return o;const r=e.excludes||["constructor"],{enumerable:n=!0,configurable:c=0,writable:i=0}=e,p={};return 0!==n&&(p.enumerable=n),0!==c&&(p.configurable=c),0!==i&&(p.writable=i),iterateInheritedPrototype(t=>{Object.getOwnPropertyNames(t).forEach(n=>{if(r.indexOf(n)>=0)return;if(Object.prototype.hasOwnProperty.call(o,n))return;const c=Object.getOwnPropertyDescriptor(t,n);["get","set","value"].forEach(t=>{if("function"==typeof c[t]){const o=c[t];c[t]=function(...t){return o.apply(Object.prototype.hasOwnProperty.call(e,"bindTo")?e.bindTo:this,t)}}}),Object.defineProperty(o,n,Object.assign(Object.assign({},c),p))})},t,e.till||Object,!1),o};

View File

@@ -0,0 +1,4 @@
export * from './superComponent';
export * from './flatTool';
export * from './instantiationDecorator';
export * from './control';

View File

@@ -0,0 +1 @@
export*from"./superComponent";export*from"./flatTool";export*from"./instantiationDecorator";export*from"./control";

View File

@@ -0,0 +1,3 @@
import { SuperComponent } from './superComponent';
export declare const toComponent: (options: Record<string, any>) => Record<string, any>;
export declare const wxComponent: () => (constructor: new () => SuperComponent) => void;

View File

@@ -0,0 +1 @@
import{toObject}from"./flatTool";import{isPlainObject}from"../validator";import{canUseVirtualHost}from"../version";const RawLifeCycles=["Created","Attached","Ready","Moved","Detached","Error"],NativeLifeCycles=RawLifeCycles.map(e=>e.toLowerCase()),ComponentNativeProps=["properties","data","observers","methods","behaviors",...NativeLifeCycles,"relations","externalClasses","options","lifetimes","pageLifeTimes","definitionFilter"];export const toComponent=function(e){const{relations:t,behaviors:o=[],externalClasses:i=[]}=e;if(e.properties){Object.keys(e.properties).forEach(t=>{let o=e.properties[t];isPlainObject(o)||(o={type:o}),e.properties[t]=o});[{key:"ariaHidden",type:Boolean},{key:"ariaRole",type:String},{key:"ariaLabel",type:String},{key:"ariaLabelledby",type:String},{key:"ariaDescribedby",type:String},{key:"ariaBusy",type:Boolean}].forEach(({key:t,type:o})=>{e.properties[t]={type:o}}),e.properties.style={type:String,value:""},e.properties.customStyle={type:String,value:""}}e.methods||(e.methods={}),e.lifetimes||(e.lifetimes={});const s={};if(t){const e=(e,t)=>Behavior({created(){Object.defineProperty(this,`$${e}`,{get:()=>{const o=this.getRelationNodes(t)||[];return"parent"===e?o[0]:o}})}}),i={};Object.keys(t).forEach(o=>{const s=t[o],r=["parent","ancestor"].includes(s.type)?"parent":"children",n=e(r,o);i[r]=n}),o.push(...Object.keys(i).map(e=>i[e]))}if(e.behaviors=[...o],e.externalClasses=["class",...i],Object.getOwnPropertyNames(e).forEach(t=>{const o=Object.getOwnPropertyDescriptor(e,t);o&&(NativeLifeCycles.indexOf(t)<0&&"function"==typeof o.value?(Object.defineProperty(e.methods,t,o),delete e[t]):ComponentNativeProps.indexOf(t)<0?s[t]=o:NativeLifeCycles.indexOf(t)>=0&&(e.lifetimes[t]=e[t]))}),Object.keys(s).length){const t=e.lifetimes.created,o=e.lifetimes.attached,{controlledProps:i=[]}=e;e.lifetimes.created=function(...e){Object.defineProperties(this,s),t&&t.apply(this,e)},e.lifetimes.attached=function(...e){o&&o.apply(this,e),i.forEach(({key:e})=>{const t=`default${e.replace(/^(\w)/,(e,t)=>t.toUpperCase())}`,o=this.properties;null==o[e]&&(this._selfControlled=!0),null==o[e]&&null!=o[t]&&this.setData({[e]:o[t]})})},e.methods._trigger=function(e,t,o){const s=i.find(t=>t.event===e);if(s){const{key:e}=s;this._selfControlled&&this.setData({[e]:t[e]})}this.triggerEvent(e,t,o)}}return e};export const wxComponent=function(){return function(e){const t=new class extends e{};t.options=t.options||{},canUseVirtualHost()&&(t.options.virtualHost=!0);const o=toComponent(toObject(t));Component(o)}};

View File

@@ -0,0 +1,19 @@
/// <reference types="miniprogram-api-typings" />
export interface ComponentsOptionsType extends WechatMiniprogram.Component.ComponentOptions {
styleIsolation?: 'isolated' | 'apply-shared' | 'shared' | 'page-isolated' | 'page-apply-shared' | 'page-shared';
}
export interface RelationsOptions {
[componentName: string]: WechatMiniprogram.Component.RelationOption;
}
export interface SuperComponent<D = {}, P = {}, M = {}> extends WechatMiniprogram.Component.Lifetimes, WechatMiniprogram.Component.OtherOption, WechatMiniprogram.Component.InstanceMethods<D> {
properties: P;
data: D;
options: ComponentsOptionsType;
methods: M | Record<string, (...args: any[]) => any>;
$global: Function;
[x: string]: any;
}
export declare class SuperComponent<D = {}, P = {}, M = {}> {
readonly app: any;
constructor();
}

View File

@@ -0,0 +1 @@
export class SuperComponent{constructor(){this.app=getApp()}}