first commit

This commit is contained in:
lingxiao865
2025-09-18 12:39:54 +08:00
parent b2e8461792
commit 6c6fe3d0d6
1898 changed files with 30918 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import { SuperComponent, RelationsOptions, ComponentsOptionsType } from '../common/src/index';
import { PickerItemOption } from './type';
export default class PickerItem extends SuperComponent {
relations: RelationsOptions;
options: ComponentsOptionsType;
externalClasses: string[];
properties: import("./type").TdPickerItemProps;
observers: {
'options, pickerKeys'(): void;
};
data: {
prefix: string;
classPrefix: string;
offset: number;
duration: number;
value: string;
curIndex: number;
columnIndex: number;
pickerKeys: {
value: string;
label: string;
};
formatOptions: PickerItemOption[];
};
lifetimes: {
created(): void;
};
methods: {
onClickItem(event: WechatMiniprogram.TouchEvent): void;
onTouchStart(event: any): void;
onTouchMove(event: any): void;
onTouchEnd(event: any): void;
formatOption(options: PickerItemOption[], columnIndex: number, format: any): any[];
updateSelected(index: number, trigger: boolean): void;
update(): void;
getCount(): any;
};
}

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";const{prefix:prefix}=config,name=`${prefix}-picker-item`,ANIMATION_DURATION=1e3,INERTIA_TIME=300,INERTIA_DISTANCE=15,range=function(t,e,i){return Math.min(Math.max(t,e),i)},momentum=(t,e)=>{let i=t;return i=Math.abs(i/e)/.005*(i<0?-1:1),i};let PickerItem=class extends SuperComponent{constructor(){super(...arguments),this.relations={"../picker/picker":{type:"parent",linked(t){if("keys"in t.data){const{keys:e}=t.data;if(null===e||JSON.stringify(this.data.pickerKeys)===JSON.stringify(e))return;this.setData({pickerKeys:e})}}}},this.options={multipleSlots:!0},this.externalClasses=[`${prefix}-class`],this.properties=props,this.observers={"options, pickerKeys"(){this.update()}},this.data={prefix:prefix,classPrefix:name,offset:0,duration:0,value:"",curIndex:0,columnIndex:0,pickerKeys:{value:"value",label:"label"},formatOptions:props.options.value},this.lifetimes={created(){this.StartY=0,this.StartOffset=0,this.startTime=0}},this.methods={onClickItem(t){const{index:e}=t.currentTarget.dataset,{pickItemHeight:i}=this.data,s=range(e,0,this.getCount()-1);s!==this._selectedIndex&&this.setData({offset:-s*i,curIndex:s,duration:200}),this.updateSelected(s,!0)},onTouchStart(t){this.StartY=t.touches[0].clientY,this.StartOffset=this.data.offset,this.startTime=Date.now(),this.setData({duration:0})},onTouchMove(t){const{StartY:e,StartOffset:i}=this,{pickItemHeight:s}=this.data,o=t.touches[0].clientY-e,n=range(i+o,-this.getCount()*s,0);this.setData({offset:n})},onTouchEnd(t){const{offset:e,pickItemHeight:i}=this.data,{startTime:s}=this;if(e===this.StartOffset)return;let o=0;const n=t.changedTouches[0].clientY-this.StartY,a=Date.now()-s;a<300&&Math.abs(n)>15&&(o=momentum(n,a));const r=range(e+o,-this.getCount()*i,0),c=range(Math.round(-r/i),0,this.getCount()-1);this.setData({offset:-c*i,duration:1e3,curIndex:c}),c!==this._selectedIndex&&this.updateSelected(c,!0)},formatOption:(t,e,i)=>"function"!=typeof i?t:t.map(t=>i(t,e)),updateSelected(t,e){var i,s,o;const{columnIndex:n,pickerKeys:a,formatOptions:r}=this.data;this._selectedIndex=t,this._selectedValue=null===(i=r[t])||void 0===i?void 0:i[null==a?void 0:a.value],this._selectedLabel=null===(s=r[t])||void 0===s?void 0:s[null==a?void 0:a.label],e&&(null===(o=this.$parent)||void 0===o||o.triggerColumnChange({index:t,column:n}))},update(){const{options:t,value:e,pickerKeys:i,pickItemHeight:s,format:o,columnIndex:n}=this.data,a=this.formatOption(t,n,o),r=a.findIndex(t=>t[null==i?void 0:i.value]===e),c=r>0?r:0;this.setData({formatOptions:a,offset:-c*s,curIndex:c},()=>{this.updateSelected(c,!1)})},getCount(){var t,e;return null===(e=null===(t=this.data)||void 0===t?void 0:t.options)||void 0===e?void 0:e.length}}}};PickerItem=__decorate([wxComponent()],PickerItem);export default PickerItem;

View File

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

View File

@@ -0,0 +1 @@
<wxs src="../common/utils.wxs" module="_"/><view style="{{_._style([style, customStyle])}}" class="{{_.cls(classPrefix + '__group', [])}} class {{prefix}}-class" bind:touchstart="onTouchStart" catch:touchmove="onTouchMove" bind:touchend="onTouchEnd" bind:touchcancel="onTouchEnd"><view class="{{classPrefix}}__wrapper" style="transition: transform {{ duration }}ms cubic-bezier(0.215, 0.61, 0.355, 1); transform: translate3d(0, {{ offset }}px, 0)"><view class="{{_.cls(classPrefix + '__item', [['active', curIndex == index]])}}" style="height: {{pickItemHeight}}px" wx:for="{{formatOptions}}" wx:key="index" wx:for-item="option" data-index="{{ index }}" bind:tap="onClickItem"><text class="{{classPrefix}}__item-label">{{option[pickerKeys.label]}}</text><slot name="label-suffix--{{index}}"></slot></view></view></view>

View File

@@ -0,0 +1,6 @@
@import '../common/style/index.wxss';:host{display:flex;}
.t-picker-item__group{height:var(--td-picker-group-height,400rpx);overflow:hidden;flex:1;z-index:1;}
.t-picker-item__wrapper{padding:144rpx 0;}
.t-picker-item__item{display:flex;justify-content:center;align-items:center;color:var(--td-picker-item-color,var(--td-text-color-secondary,var(--td-font-gray-2,rgba(0,0,0,.6))));font-size:var(--td-picker-item-font-size,var(--td-font-size-m,32rpx));}
.t-picker-item__item-label{white-space:nowrap;text-overflow:ellipsis;overflow:hidden;}
.t-picker-item__item--active{color:var(--td-picker-item-active-color,var(--td-text-color-primary,var(--td-font-gray-1,rgba(0,0,0,.9))));font-weight:600;}

View File

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

View File

@@ -0,0 +1 @@
const props={format:{type:null},options:{type:Array,value:[]}};export default props;

View File

@@ -0,0 +1,14 @@
export interface TdPickerItemProps {
format?: {
type: undefined;
value?: (option: PickerItemOption, columnIndex: number) => PickerItemOption;
};
options?: {
type: ArrayConstructor;
value?: PickerItemOption[];
};
}
export interface PickerItemOption {
label: string;
value: string | number;
}

View File

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