tmp
This commit is contained in:
41
miniprogram_npm/tdesign-miniprogram/form/form.d.ts
vendored
Normal file
41
miniprogram_npm/tdesign-miniprogram/form/form.d.ts
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { SuperComponent, RelationsOptions } from '../common/src/index';
|
||||
export default class Form extends SuperComponent {
|
||||
behaviors: string[];
|
||||
externalClasses: string[];
|
||||
properties: import("./type").TdFormProps<import("./type").Data>;
|
||||
options: {
|
||||
multipleSlots: boolean;
|
||||
};
|
||||
relations: RelationsOptions;
|
||||
data: {
|
||||
prefix: string;
|
||||
classPrefix: string;
|
||||
children: any[];
|
||||
initialData: {};
|
||||
fields: any[];
|
||||
};
|
||||
lifetimes: {
|
||||
ready(): void;
|
||||
};
|
||||
methods: {
|
||||
initFormData(): void;
|
||||
registerChild(child: any): void;
|
||||
unregisterChild(childName: any): void;
|
||||
validate(): Promise<any>;
|
||||
scrollToError(validateResult: any): void;
|
||||
validateOnly(params: any): Promise<any>;
|
||||
formatValidateResult(validateResultList: any): {};
|
||||
getFirstError(validateResult: any): any;
|
||||
submit(): Promise<any>;
|
||||
getValidate(): Promise<false | {
|
||||
validateResult: any;
|
||||
firstError: any;
|
||||
}>;
|
||||
getEmptyValue(name: any): {};
|
||||
reset(): void;
|
||||
clearValidate(fields: any): void;
|
||||
setValidateMessage(validateMessage: any): void;
|
||||
onSubmit(): void;
|
||||
onReset(): void;
|
||||
};
|
||||
}
|
||||
1
miniprogram_npm/tdesign-miniprogram/form/form.js
Normal file
1
miniprogram_npm/tdesign-miniprogram/form/form.js
Normal 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";import useCustomNavbar from"../mixins/using-custom-navbar";const{prefix:prefix}=config,name=`${prefix}-form`;let Form=class extends SuperComponent{constructor(){super(...arguments),this.behaviors=["wx://component-export",useCustomNavbar],this.externalClasses=[`${prefix}-class`,`${prefix}-class-label`,`${prefix}-class-controls`,`${prefix}-class-help`,`${prefix}-class-extra`],this.properties=props,this.options={multipleSlots:!0},this.relations={"../form-item/form-item":{type:"child",linked(){}}},this.data={prefix:prefix,classPrefix:name,children:[],initialData:{},fields:[]},this.lifetimes={ready(){this.initFormData()}},this.methods={initFormData(){const{data:t}=this.properties,e=t||{},r=Object.assign({},e),i=Object.keys(e);this.setData({initialData:r,fields:i})},registerChild(t){const{children:e}=this.data;e.find(e=>e.data.name===t.data.name)||(e.push(t),this.setData({children:e}))},unregisterChild(t){const{children:e}=this.data,r=e.findIndex(e=>e.data.name===t);r>-1&&(e.splice(r,1),this.setData({children:e}))},validate(){return __awaiter(this,void 0,void 0,function*(){const{children:t}=this.data,{data:e}=this.properties,r=t.map(t=>t.validate(e,"all",this.properties.showErrorMessage));try{const t=yield Promise.all(r),e=this.formatValidateResult(t);return!0!==e&&this.scrollToError(e),this.triggerEvent("validate",{validateResult:e}),e}catch(t){return!1}})},scrollToError(t){const{distanceTop:e}=this.data,{scrollToFirstError:r}=this.properties;if(!r)return;const i=Object.keys(t)[0];if(!i)return;const{children:a}=this.data,s=a.find(t=>t.properties.name===i);s&&s.scrollIntoView(r,e)},validateOnly(t){return __awaiter(this,void 0,void 0,function*(){const{fields:e,trigger:r="all"}=t,{children:i}=this.data,a=i.filter(t=>!(e&&e.length>0)||e.includes(t.data.name)).map(t=>t.validateOnly(r));try{const t=yield Promise.all(a);return this.formatValidateResult(t)}catch(t){return!1}})},formatValidateResult(t){const e={};let r=!1;return t.forEach(t=>{t&&"object"==typeof t&&Object.keys(t).forEach(i=>{!0!==t[i]&&(e[i]=t[i],r=!0)})}),!r||e},getFirstError(t){if(!0===t)return"";const e=Object.keys(t)[0];if(!e)return"";const r=t[e];return Array.isArray(r)&&r.length>0&&r[0].message||""},submit(){return __awaiter(this,void 0,void 0,function*(){try{const t=yield this.validate(),e=this.getFirstError(t);return this.triggerEvent("submit",{validateResult:t,firstError:e}),t}catch(t){return!1}})},getValidate(){return __awaiter(this,void 0,void 0,function*(){try{const t=yield this.validate();return{validateResult:t,firstError:this.getFirstError(t)}}catch(t){return!1}})},getEmptyValue(t){const e=this.properties.data[t];return Array.isArray(e)?[]:"object"==typeof e&&null!==e?{}:"number"==typeof e?0:""},reset(){const{children:t,initialData:e,fields:r}=this.data,i={};t.forEach(t=>{r&&r.includes(t.data.name)&&("empty"===this.properties.resetType?i[t.data.name]=this.getEmptyValue(t.data.name):"initial"===this.properties.resetType&&(i[t.data.name]=e[t.data.name]),t.resetField())}),this.triggerEvent("reset",{formData:i})},clearValidate(t){const{children:e}=this.data;e.forEach(e=>{t&&!t.includes(e.data.name)||e.clearValidate()})},setValidateMessage(t){const{children:e}=this.data;e.forEach(e=>{t[e.data.name]&&e.setValidateMessage(t[e.data.name])})},onSubmit(){this.submit()},onReset(){this.reset()}}}};Form=__decorate([wxComponent()],Form);export default Form;
|
||||
1
miniprogram_npm/tdesign-miniprogram/form/form.json
Normal file
1
miniprogram_npm/tdesign-miniprogram/form/form.json
Normal file
@@ -0,0 +1 @@
|
||||
{"component":true,"styleIsolation":"apply-shared","usingComponents":{}}
|
||||
1
miniprogram_npm/tdesign-miniprogram/form/form.wxml
Normal file
1
miniprogram_npm/tdesign-miniprogram/form/form.wxml
Normal file
@@ -0,0 +1 @@
|
||||
<wxs src="../common/utils.wxs" module="_"/><form class="{{classPrefix}} {{prefix}}-class" style="{{_._style([style, customStyle])}}"><slot/></form>
|
||||
1
miniprogram_npm/tdesign-miniprogram/form/form.wxss
Normal file
1
miniprogram_npm/tdesign-miniprogram/form/form.wxss
Normal file
@@ -0,0 +1 @@
|
||||
@import '../common/style/index.wxss';.t-form{display:block;background-color:var(--td-form-bg-color,var(--td-bg-color-container,var(--td-font-white-1,#fff)));}
|
||||
3
miniprogram_npm/tdesign-miniprogram/form/index.d.ts
vendored
Normal file
3
miniprogram_npm/tdesign-miniprogram/form/index.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './props';
|
||||
export * from './type';
|
||||
export * from './form';
|
||||
1
miniprogram_npm/tdesign-miniprogram/form/index.js
Normal file
1
miniprogram_npm/tdesign-miniprogram/form/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export*from"./props";export*from"./type";export*from"./form";
|
||||
3
miniprogram_npm/tdesign-miniprogram/form/props.d.ts
vendored
Normal file
3
miniprogram_npm/tdesign-miniprogram/form/props.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { TdFormProps } from './type';
|
||||
declare const props: TdFormProps;
|
||||
export default props;
|
||||
1
miniprogram_npm/tdesign-miniprogram/form/props.js
Normal file
1
miniprogram_npm/tdesign-miniprogram/form/props.js
Normal file
@@ -0,0 +1 @@
|
||||
const props={colon:{type:Boolean,value:!1},data:{type:Object,value:{}},errorMessage:{type:Object},labelAlign:{type:String,value:"right"},labelWidth:{type:null,value:"81px"},requiredMark:{type:null,value:void 0},requiredMarkPosition:{type:String},resetType:{type:String,value:"empty"},rules:{type:Object},scrollToFirstError:{type:String},showErrorMessage:{type:Boolean,value:!0},submitWithWarningMessage:{type:Boolean,value:!1}};export default props;
|
||||
165
miniprogram_npm/tdesign-miniprogram/form/type.d.ts
vendored
Normal file
165
miniprogram_npm/tdesign-miniprogram/form/type.d.ts
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
import { IsEmailOptions } from 'validator/es/lib/isEmail';
|
||||
import { IsURLOptions } from 'validator/es/lib/isURL';
|
||||
export interface TdFormProps<FormData extends Data = Data> {
|
||||
colon?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
data?: {
|
||||
type: ObjectConstructor;
|
||||
value?: FormData;
|
||||
};
|
||||
errorMessage?: {
|
||||
type: ObjectConstructor;
|
||||
value?: FormErrorMessage;
|
||||
};
|
||||
labelAlign?: {
|
||||
type: StringConstructor;
|
||||
value?: 'left' | 'right' | 'top';
|
||||
};
|
||||
labelWidth?: {
|
||||
type: null;
|
||||
value?: string | number;
|
||||
};
|
||||
requiredMark?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
requiredMarkPosition?: {
|
||||
type: StringConstructor;
|
||||
value?: 'left' | 'right';
|
||||
};
|
||||
resetType?: {
|
||||
type: StringConstructor;
|
||||
value?: 'empty' | 'initial';
|
||||
};
|
||||
rules?: {
|
||||
type: ObjectConstructor;
|
||||
value?: FormRules<FormData>;
|
||||
};
|
||||
scrollToFirstError?: {
|
||||
type: StringConstructor;
|
||||
value?: '' | 'smooth' | 'auto';
|
||||
};
|
||||
showErrorMessage?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
submitWithWarningMessage?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
}
|
||||
export interface FormInstanceFunctions<FormData extends Data = Data> {
|
||||
clearValidate: {
|
||||
type: undefined;
|
||||
value?: (fields?: Array<keyof FormData>) => void;
|
||||
required?: boolean;
|
||||
};
|
||||
reset: {
|
||||
type: undefined;
|
||||
value?: (params?: FormResetParams<FormData>) => void;
|
||||
required?: boolean;
|
||||
};
|
||||
setValidateMessage: {
|
||||
type: undefined;
|
||||
value?: (message: FormValidateMessage<FormData>) => void;
|
||||
required?: boolean;
|
||||
};
|
||||
submit: {
|
||||
type: undefined;
|
||||
value?: (params?: {
|
||||
showErrorMessage?: boolean;
|
||||
}) => void;
|
||||
required?: boolean;
|
||||
};
|
||||
validate: {
|
||||
type: undefined;
|
||||
value?: (params?: FormValidateParams) => Promise<FormValidateResult<FormData>>;
|
||||
required?: boolean;
|
||||
};
|
||||
}
|
||||
export interface FormRule {
|
||||
boolean?: boolean;
|
||||
date?: boolean | IsDateOptions;
|
||||
email?: boolean | IsEmailOptions;
|
||||
enum?: Array<string>;
|
||||
idcard?: boolean;
|
||||
len?: number | boolean;
|
||||
max?: number | boolean;
|
||||
message?: string;
|
||||
min?: number | boolean;
|
||||
number?: boolean;
|
||||
pattern?: RegExp | string;
|
||||
required?: boolean;
|
||||
telnumber?: boolean;
|
||||
trigger?: ValidateTriggerType;
|
||||
type?: 'error' | 'warning';
|
||||
url?: boolean | IsURLOptions;
|
||||
validator?: CustomValidator;
|
||||
whitespace?: boolean;
|
||||
}
|
||||
export interface FormErrorMessage {
|
||||
boolean?: string;
|
||||
date?: string;
|
||||
enum?: string;
|
||||
idcard?: string;
|
||||
len?: string;
|
||||
max?: string;
|
||||
min?: string;
|
||||
number?: string;
|
||||
pattern?: string;
|
||||
required?: string;
|
||||
telnumber?: string;
|
||||
url?: string;
|
||||
validator?: string;
|
||||
whitespace?: string;
|
||||
}
|
||||
export declare type FormRules<T extends Data = any> = {
|
||||
[field in keyof T]?: Array<FormRule>;
|
||||
};
|
||||
export interface FormResetParams<FormData> {
|
||||
type?: 'initial' | 'empty';
|
||||
fields?: Array<keyof FormData>;
|
||||
}
|
||||
export declare type FormValidateMessage<FormData> = {
|
||||
[field in keyof FormData]: FormItemValidateMessage[];
|
||||
};
|
||||
export interface FormItemValidateMessage {
|
||||
type: 'warning' | 'error';
|
||||
message: string;
|
||||
}
|
||||
export interface FormValidateParams {
|
||||
fields?: Array<string>;
|
||||
showErrorMessage?: boolean;
|
||||
trigger?: ValidateTriggerType;
|
||||
}
|
||||
export declare type ValidateTriggerType = 'blur' | 'change' | 'submit' | 'all';
|
||||
export declare type FormValidateResult<T> = boolean | ValidateResultObj<T>;
|
||||
export declare type ValidateResultObj<T> = {
|
||||
[key in keyof T]: boolean | ValidateResultList;
|
||||
};
|
||||
export declare type ValidateResultList = Array<AllValidateResult>;
|
||||
export declare type AllValidateResult = CustomValidateObj | ValidateResultType;
|
||||
export interface ValidateResultType extends FormRule {
|
||||
result: boolean;
|
||||
}
|
||||
export declare type Data = {
|
||||
[key: string]: any;
|
||||
};
|
||||
export interface IsDateOptions {
|
||||
format: string;
|
||||
strictMode: boolean;
|
||||
delimiters: string[];
|
||||
}
|
||||
export declare type CustomValidator = (val: ValueType, context?: {
|
||||
formData: Data;
|
||||
name: string;
|
||||
}) => CustomValidateResolveType | Promise<CustomValidateResolveType>;
|
||||
export declare type CustomValidateResolveType = boolean | CustomValidateObj;
|
||||
export interface CustomValidateObj {
|
||||
result: boolean;
|
||||
message: string;
|
||||
type?: 'error' | 'warning' | 'success';
|
||||
}
|
||||
export declare type ValueType = any;
|
||||
1
miniprogram_npm/tdesign-miniprogram/form/type.js
Normal file
1
miniprogram_npm/tdesign-miniprogram/form/type.js
Normal file
@@ -0,0 +1 @@
|
||||
export{};
|
||||
Reference in New Issue
Block a user