初始化项目, 添加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,39 @@
declare const _default: {
value: {
type: StringConstructor;
value: string;
};
icon: {
type: StringConstructor;
value: string;
};
size: {
type: NumberConstructor;
value: number;
};
iconSize: {
type: any;
value: null;
};
level: {
type: StringConstructor;
value: import("../../../common/shared/qrcode/types").ErrorCorrectionLevel;
};
bgColor: {
type: StringConstructor;
value: string;
};
color: {
type: StringConstructor;
value: string;
};
includeMargin: {
type: BooleanConstructor;
value: boolean;
};
marginSize: {
type: NumberConstructor;
value: number;
};
};
export default _default;

View File

@@ -0,0 +1 @@
import{DEFAULT_MARGIN_SIZE,DEFAULT_NEED_MARGIN,DEFAULT_BACKGROUND_COLOR,DEFAULT_FRONT_COLOR}from"../../../common/shared/qrcode/utils";export default{value:{type:String,value:""},icon:{type:String,value:""},size:{type:Number,value:160},iconSize:{type:null,value:40},level:{type:String,value:"M"},bgColor:{type:String,value:DEFAULT_BACKGROUND_COLOR},color:{type:String,value:DEFAULT_FRONT_COLOR},includeMargin:{type:Boolean,value:DEFAULT_NEED_MARGIN},marginSize:{type:Number,value:DEFAULT_MARGIN_SIZE}};

View File

@@ -0,0 +1,60 @@
import { SuperComponent } from '../../../common/src/index';
export default class QRCode extends SuperComponent {
properties: {
value: {
type: StringConstructor;
value: string;
};
icon: {
type: StringConstructor;
value: string;
};
size: {
type: NumberConstructor;
value: number;
};
iconSize: {
type: any;
value: null;
};
level: {
type: StringConstructor;
value: import("../../../common/shared/qrcode/types").ErrorCorrectionLevel;
};
bgColor: {
type: StringConstructor;
value: string;
};
color: {
type: StringConstructor;
value: string;
};
includeMargin: {
type: BooleanConstructor;
value: boolean;
};
marginSize: {
type: NumberConstructor;
value: number;
};
};
lifetimes: {
ready(): void;
};
observers: {
'**': () => void;
};
methods: {
initCanvas(): Promise<void>;
drawQrcode(canvas: WechatMiniprogram.Canvas, ctx: WechatMiniprogram.CanvasContext): Promise<void>;
getSizeProp(iconSize: number | {
width: number;
height: number;
} | null | undefined): {
width: number;
height: number;
};
checkDefaultValue(): void;
getCanvasNode(): Promise<unknown>;
};
}

View File

@@ -0,0 +1 @@
import{__awaiter,__decorate}from"tslib";import props from"./props";import useQRCode from"../../hooks/useQRCode";import{SuperComponent,wxComponent}from"../../../common/src/index";import{DEFAULT_MINVERSION,excavateModules}from"../../../common/shared/qrcode/utils";let QRCode=class extends SuperComponent{constructor(){super(...arguments),this.properties=props,this.lifetimes={ready(){this.checkDefaultValue(),this.initCanvas()}},this.observers={"**":function(){this.checkDefaultValue(),this.initCanvas()}},this.methods={initCanvas(){return __awaiter(this,void 0,void 0,function*(){wx.createSelectorQuery().in(this).select("#qrcodeCanvas").fields({node:!0,size:!0}).exec(e=>__awaiter(this,void 0,void 0,function*(){var t;if(!(null===(t=e[0])||void 0===t?void 0:t.node))return;const i=e[0].node,o=i.getContext("2d");yield this.drawQrcode(i,o)}))})},drawQrcode(e,t){var i;return __awaiter(this,void 0,void 0,function*(){if(!t)return;const{value:o,icon:r,size:a,iconSize:l,level:n,bgColor:s,color:c,includeMargin:d,marginSize:h}=this.properties,u=this.getSizeProp(l);try{const l=useQRCode({value:o,level:n,minVersion:DEFAULT_MINVERSION,includeMargin:d,marginSize:h,size:a,imageSettings:r?{src:r,width:u.width,height:u.height,excavate:!0}:void 0}),g=wx.getWindowInfo().pixelRatio||1;e.width=a*g,e.height=a*g;const m=a*g/l.numCells;t.scale(m,m),t.fillStyle=s,t.fillRect(0,0,l.numCells,l.numCells);let v=l.cells;if(r&&(null===(i=l.calculatedImageSettings)||void 0===i?void 0:i.excavation)&&(v=excavateModules(l.cells,l.calculatedImageSettings.excavation)),t.fillStyle=c,v.forEach((e,i)=>{e.forEach((e,o)=>{e&&t.fillRect(o+l.margin,i+l.margin,1.05,1.05)})}),r&&l.calculatedImageSettings){const i=e.createImage();yield new Promise((e,t)=>{i.onload=e,i.onerror=t,i.src=this.properties.icon}),t.drawImage(i,l.calculatedImageSettings.x+l.margin,l.calculatedImageSettings.y+l.margin,l.calculatedImageSettings.w,l.calculatedImageSettings.h)}this.triggerEvent("drawCompleted")}catch(e){this.triggerEvent("drawError",{error:e})}})},getSizeProp:e=>e?"number"==typeof e?{width:e,height:e}:{width:e.width,height:e.height}:{width:0,height:0},checkDefaultValue(){const e={bgColor:"",color:""};let t=!1;const{bgColor:i,color:o}=this.properties,{bgColor:r,color:a}=props;""===i&&r.value&&(e.bgColor=r.value,t=!0),""===o&&a.value&&(e.color=a.value,t=!0),t&&this.setData(e)},getCanvasNode(){return new Promise(e=>{wx.createSelectorQuery().in(this).select("#qrcodeCanvas").fields({node:!0,size:!0}).exec(t=>{var i;e(null===(i=t[0])||void 0===i?void 0:i.node)})})}}}};QRCode=__decorate([wxComponent()],QRCode);export default QRCode;

View File

@@ -0,0 +1 @@
<canvas type="2d" class="t-qrcode__canvas class" id="qrcodeCanvas"></canvas>

View File

@@ -0,0 +1 @@
@import '../../../common/style/index.wxss';canvas{width:100%;height:100%;align-self:stretch;min-width:0;flex:auto;}

View File

@@ -0,0 +1,12 @@
import { ErrorCorrectionLevel } from '../../../common/shared/qrcode/types';
export interface TdQRCodeProps {
value?: string;
icon?: string;
size?: number;
iconSize?: null;
level?: ErrorCorrectionLevel;
bgColor?: string;
color?: string;
includeMargin?: boolean;
marginSize?: number;
}

View File

@@ -0,0 +1,19 @@
declare const _default: {
status: {
type: StringConstructor;
value: "loading" | "active" | "expired" | "scanned";
};
locale: {
type: ObjectConstructor;
value: {
expiredText?: string;
refreshText?: string;
scannedText?: string;
};
};
statusRender: {
type: BooleanConstructor;
value: boolean;
};
};
export default _default;

View File

@@ -0,0 +1 @@
export default{status:{type:String,value:""},locale:{type:Object,value:{expiredText:"二维码过期",refreshText:"点击刷新",scannedText:"已扫描"}},statusRender:{type:Boolean,value:!1}};

View File

@@ -0,0 +1,35 @@
import { SuperComponent } from '../../../common/src/index';
export default class QRCode extends SuperComponent {
options: {
multipleSlots: boolean;
};
properties: {
statusRender: {
type: BooleanConstructor;
value: boolean;
};
status: {
type: StringConstructor;
value: "loading" | "active" | "expired" | "scanned";
};
locale: {
type: ObjectConstructor;
value: {
expiredText?: string;
refreshText?: string;
scannedText?: string;
};
};
};
data: {
prefix: string;
classPrefix: string;
isSkyline: boolean;
};
lifetimes: {
attached(): void;
};
methods: {
handleRefresh(): void;
};
}

View File

@@ -0,0 +1 @@
import{__decorate}from"tslib";import props from"./props";import config from"../../../common/config";import{SuperComponent,wxComponent}from"../../../common/src/index";const{prefix:prefix}=config,name=`${prefix}-qrcode`;let QRCode=class extends SuperComponent{constructor(){super(...arguments),this.options={multipleSlots:!0},this.properties=Object.assign(Object.assign({},props),{statusRender:{type:Boolean,value:!1}}),this.data={prefix:prefix,classPrefix:name,isSkyline:!1},this.lifetimes={attached(){this.setData({isSkyline:"skyline"===this.renderer})}},this.methods={handleRefresh(){this.triggerEvent("refresh")}}}};QRCode=__decorate([wxComponent()],QRCode);export default QRCode;

View File

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

View File

@@ -0,0 +1 @@
<block wx:if="{{statusRender}}"><slot name="statusRender"/></block><block wx:else><view wx:if="{{status === 'expired'}}" class="{{prefix}}-expired"><view class="{{prefix}}-expired__text">{{locale.expiredText}}<view class="{{prefix}}-expired__button" bindtap="handleRefresh"><t-icon name="refresh" size="36rpx"/>{{locale.refreshText}}</view></view></view><view wx:elif="{{status === 'loading'}}" class="{{prefix}}-loading-container"><t-loading size="64rpx" theme="{{isSkyline ? 'spinner' : 'circular'}}"/></view><view wx:elif="{{status === 'scanned'}}" class="{{prefix}}-scanned"><t-icon name="check-circle-filled" class="{{prefix}}-scanned__icon" size="44rpx"/>{{locale.scannedText}}</view></block>

View File

@@ -0,0 +1,5 @@
@import '../../../common/style/index.wxss';.t-expired__text{color:var(--td-text-color-primary,var(--td-font-gray-1,rgba(0,0,0,.9)));font-weight:600;}
.t-expired__button{display:flex;color:var(--td-brand-color,var(--td-primary-color-7,#0052d9));box-shadow:none;cursor:pointer;column-gap:8px;align-items:center;height:32px;transition:all .2s cubic-bezier(.215,.61,.355,1);}
.t-expired__button:hover{color:var(--td-brand-color-hover);}
.t-scanned{display:flex;column-gap:8px;align-items:center;}
.t-scanned__icon{color:var(--td-success-color);}

View File

@@ -0,0 +1,9 @@
export interface QRCodeStatusProps {
status?: 'active' | 'expired' | 'loading' | 'scanned';
locale?: {
expiredText?: string;
refreshText?: string;
scannedText?: string;
};
statusRender?: boolean;
}

View File

@@ -0,0 +1,27 @@
import { QrCode } from '../../common/shared/qrcode/qrcodegen';
import type { ErrorCorrectionLevel, Excavation, ImageSettings } from '../../common/shared/qrcode/types';
interface Options {
value: string;
level: ErrorCorrectionLevel;
minVersion: number;
includeMargin: boolean;
marginSize?: number;
imageSettings?: ImageSettings;
size: number;
}
interface QRCodeResult {
cells: boolean[][];
margin: number;
numCells: number;
calculatedImageSettings: {
x: number;
y: number;
h: number;
w: number;
excavation: Excavation | null;
opacity: number;
} | null;
qrcode: QrCode;
}
declare const useQRCode: (opt: Options) => QRCodeResult;
export default useQRCode;

View File

@@ -0,0 +1 @@
import{QrCode,QrSegment}from"../../common/shared/qrcode/qrcodegen";import{ERROR_LEVEL_MAP,getImageSettings,getMarginSize}from"../../common/shared/qrcode/utils";const useQRCode=e=>{const{value:t,level:n,minVersion:r,includeMargin:g,marginSize:o,imageSettings:m,size:i}=e,s=(()=>{const e=QrSegment.makeSegments(t);return QrCode.encodeSegments(e,ERROR_LEVEL_MAP[n],r)})(),a=s.getModules(),d=getMarginSize(g,o),c=getImageSettings(a,i,d,m);return{cells:a,margin:d,numCells:a.length+2*d,calculatedImageSettings:c,qrcode:s}};export default useQRCode;

View File

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

View File

@@ -0,0 +1 @@
const props={bgColor:{type:String,value:""},borderless:{type:Boolean,value:!1},color:{type:String,value:""},icon:{type:String,value:""},iconSize:{type:null,value:40},level:{type:String,value:"M"},size:{type:Number,value:160},status:{type:String,value:"active"},value:{type:String,value:""}};export default props;

View File

@@ -0,0 +1,80 @@
import { SuperComponent } from '../common/src/index';
export default class QRCode extends SuperComponent {
externalClasses: string[];
options: {
multipleSlots: boolean;
virtualHost: boolean;
};
properties: {
statusRender: {
type: BooleanConstructor;
value: boolean;
};
style: {
type: StringConstructor;
value: string;
};
customStyle: {
type: StringConstructor;
value: string;
};
bgColor?: {
type: StringConstructor;
value?: string;
};
borderless?: {
type: BooleanConstructor;
value?: boolean;
};
color?: {
type: StringConstructor;
value?: string;
};
icon?: {
type: StringConstructor;
value?: string;
};
iconSize?: {
type: null;
value?: number | {
width: number;
height: number;
};
};
level?: {
type: StringConstructor;
value?: "M" | "L" | "Q" | "H";
};
size?: {
type: NumberConstructor;
value?: number;
};
status?: {
type: StringConstructor;
value?: import("./type").QRStatus;
};
value?: {
type: StringConstructor;
value?: string;
};
};
data: {
prefix: string;
showMask: boolean;
classPrefix: string;
canvasReady: boolean;
};
lifetimes: {
ready(): Promise<void>;
attached(): void;
};
observers: {
status: (newVal: string) => void;
};
methods: {
handleDrawCompleted(): void;
handleDrawError(err: any): void;
handleRefresh(): void;
handleDownload(): Promise<void>;
};
}

View File

@@ -0,0 +1 @@
import{__awaiter,__decorate}from"tslib";import props from"./props";import config from"../common/config";import{SuperComponent,wxComponent}from"../common/src/index";const{prefix:prefix}=config,name=`${prefix}-qrcode`;let QRCode=class extends SuperComponent{constructor(){super(...arguments),this.externalClasses=[`${prefix}-class`,`${prefix}-class-canvas`],this.options={multipleSlots:!0,virtualHost:!0},this.properties=Object.assign(Object.assign({},props),{statusRender:{type:Boolean,value:!1},style:{type:String,value:""},customStyle:{type:String,value:""}}),this.data={prefix:prefix,showMask:!1,classPrefix:name,canvasReady:!1},this.lifetimes={ready(){return __awaiter(this,void 0,void 0,function*(){const e=this.selectComponent("#qrcodeCanvas"),t=yield e.getCanvasNode();this.setData({canvasNode:t})})},attached(){this.setData({showMask:"active"!==this.properties.status})}},this.observers={status:function(e){this.setData({showMask:"active"!==e})}},this.methods={handleDrawCompleted(){this.setData({canvasReady:!0})},handleDrawError(e){console.error("二维码绘制失败",e)},handleRefresh(){this.triggerEvent("refresh")},handleDownload(){return __awaiter(this,void 0,void 0,function*(){this.data.canvasNode?wx.canvasToTempFilePath({canvas:this.data.canvasNode,success:e=>{wx.saveImageToPhotosAlbum({filePath:e.tempFilePath})},fail:e=>{console.error("canvasToTempFilePath failed",e)}},this):console.error("未找到 canvas 节点")})}}}};QRCode=__decorate([wxComponent()],QRCode);export default QRCode;

View File

@@ -0,0 +1 @@
{"component":true,"styleIsolation":"apply-shared","usingComponents":{"qrcode-canvas":"./components/qrcode-canvas/qrcode-canvas","qrcode-status":"./components/qrcode-status/qrcode-status"}}

View File

@@ -0,0 +1 @@
<wxs src="../common/utils.wxs" module="_"/><view style="{{_._style([style, customStyle])}} width:{{size}}px; height: {{size}}px; background-color: {{bgColor}};" class="{{classPrefix}} {{borderless ? prefix+'-'+'borderless' : ''}} class {{prefix}}-class"><qrcode-canvas id="qrcodeCanvas" class="{{prefix}}-class-canvas" size="{{size}}" value="{{value}}" level="{{level}}" color="{{color}}" bg-color="{{bgColor}}" icon="{{icon}}" icon-size="{{iconSize}}" bind:drawError="handleDrawError" bind:drawCompleted="handleDrawCompleted"></qrcode-canvas><block wx:if="{{showMask && canvasReady}}"><view class="{{prefix}}-mask"><qrcode-status status="{{status}}" bind:refresh="handleRefresh" status-render="{{statusRender}}"><slot name="statusRender" slot="statusRender"></slot></qrcode-status></view></block></view>

View File

@@ -0,0 +1,3 @@
@import '../common/style/index.wxss';.t-qrcode{position:relative;display:flex;box-sizing:border-box;background-color:var(--td-bg-color-container,var(--td-font-white-1,#fff));padding:12px;border-radius:6px;border:1px solid var(--td-component-border,var(--td-gray-color-4,#dcdcdc));}
.t-qrcode.t-borderless{border-color:transparent;}
.t-qrcode .t-mask{left:0;top:0;position:absolute;inset-block-start:0;inset-inline-start:0;z-index:300;display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;height:100%;color:var(--td-text-color-primary,var(--td-font-gray-1,rgba(0,0,0,.9)));line-height:22px;background-color:var(--td-mask-background,rgba(255,255,255,.96));text-align:center;border-radius:6px;font-size:var(--td-font-size-title-small);}

View File

@@ -0,0 +1,46 @@
export interface TdQRCodeProps {
bgColor?: {
type: StringConstructor;
value?: string;
};
borderless?: {
type: BooleanConstructor;
value?: boolean;
};
color?: {
type: StringConstructor;
value?: string;
};
icon?: {
type: StringConstructor;
value?: string;
};
iconSize?: {
type: null;
value?: number | {
width: number;
height: number;
};
};
level?: {
type: StringConstructor;
value?: 'L' | 'M' | 'Q' | 'H';
};
size?: {
type: NumberConstructor;
value?: number;
};
status?: {
type: StringConstructor;
value?: QRStatus;
};
value?: {
type: StringConstructor;
value?: string;
};
}
export declare type QRStatus = 'active' | 'expired' | 'loading' | 'scanned';
export declare type StatusRenderInfo = {
status: QRStatus;
onRefresh?: () => void;
};

View File

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