diff --git a/example/app.json b/example/app.json index f005f5530..265f38b2d 100644 --- a/example/app.json +++ b/example/app.json @@ -76,8 +76,6 @@ "t-button-group": "tdesign-miniprogram/button-group/button-group", "t-icon": "tdesign-miniprogram/icon/icon", "t-rate": "tdesign-miniprogram/rate/rate", - "t-picker": "tdesign-miniprogram/picker/picker", - "t-picker-item": "tdesign-miniprogram/picker/picker-item", "t-progress": "tdesign-miniprogram/progress/progress", "t-input": "tdesign-miniprogram/input/input", "t-textarea": "tdesign-miniprogram/textarea/textarea", diff --git a/src/picker/README.md b/src/picker/README.md index a1ce1cf4b..e881dd0ea 100644 --- a/src/picker/README.md +++ b/src/picker/README.md @@ -20,44 +20,7 @@ isComponent: true ### 基础选择器 - - -```html - - - -``` - -```js -Page({ - data: { - selectedCityValue: [], - citys: [ - { label: '广州市', value: '广州市' }, - { label: '韶关市', value: '韶关市' }, - { label: '深圳市', value: '深圳市' }, - { label: '珠海市', value: '珠海市' }, - { label: '汕头市', value: '汕头市' }, - ], - }, - onPickerConfirm(e) { - console.log('picker confirm:', e.detail); - this.setData({ - selectedCityValue: e.detail.value, - }); - }, - onColumnChange(e) { - console.log('picker pick:', e); - }, -}); -``` +{{ base }} ## API ### Picker Props diff --git a/src/picker/_example/base/index.js b/src/picker/_example/base/index.js new file mode 100644 index 000000000..0081b4d77 --- /dev/null +++ b/src/picker/_example/base/index.js @@ -0,0 +1,80 @@ +const PICKER_KEY = { + CITY: 'city', + YEAR_SEASONS: 'yearSeasons', + DATE: 'date', +}; + +Component({ + data: { + PICKER_KEY, + + [`${PICKER_KEY.CITY}Visible`]: false, + [`${PICKER_KEY.YEAR_SEASONS}Visible`]: false, + [`${PICKER_KEY.DATE}Visible`]: false, + + pickerTitle: '', + citys: [ + { label: '北京', value: '北京' }, + { label: '上海', value: '上海' }, + { label: '广州', value: '广州' }, + { label: '深圳', value: '深圳' }, + { label: '成都', value: '成都' }, + ], + years: [ + { label: '2021年', value: '2021' }, + { label: '2020年', value: '2020' }, + { label: '2019年', value: '2019' }, + ], + months: Array.from(new Array(12), (_, index) => ({ + label: `${index + 1}月`, + value: index + 1, + })), + days: Array.from(new Array(31), (_, index) => ({ label: `${index + 1}日`, value: index + 1 })), + seasons: [ + { label: '春', value: '春' }, + { label: '夏', value: '夏' }, + { label: '秋', value: '秋' }, + { label: '冬', value: '冬' }, + ], + + [`${PICKER_KEY.CITY}Value`]: [], + [`${PICKER_KEY.YEAR_SEASONS}Value`]: [], + [`${PICKER_KEY.DATE}Value`]: [], + }, + + methods: { + joinArray(array) { + return array.join('-'); + }, + + onClickPicker(e) { + const { key } = e?.currentTarget?.dataset; + + this.setData({ + [`${key}Visible`]: true, + }); + }, + + onColumnChange(e) { + console.log('picker pick:', e); + }, + + onPickerChange(e) { + const { key } = e?.currentTarget?.dataset; + console.log('picker change:', e.detail); + this.setData({ + [`${key}Visible`]: false, + [`${key}Value`]: e.detail.value, + [`${key}CurrentValue`]: this.joinArray(e.detail.value), + }); + }, + onPickerCancel(e) { + const { key } = e?.currentTarget?.dataset; + console.log(e, '取消'); + console.log('picker1 cancel:'); + this.setData({ + [`${key}Visible`]: false, + }); + }, + }, +}); diff --git a/src/picker/_example/base/index.json b/src/picker/_example/base/index.json new file mode 100644 index 000000000..2798fd54a --- /dev/null +++ b/src/picker/_example/base/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "t-picker": "tdesign-miniprogram/picker/picker", + "t-picker-item": "tdesign-miniprogram/picker/picker-item" + } +} diff --git a/src/picker/_example/base/index.wxml b/src/picker/_example/base/index.wxml new file mode 100644 index 000000000..81f358427 --- /dev/null +++ b/src/picker/_example/base/index.wxml @@ -0,0 +1,67 @@ + + + 城市 + {{cityCurrentValue || '选择城市'}} + + + + 年份和季节 + + {{yearSeasonsCurrentValue || '选择年份和季节' }} + + + + 日期 + {{dateCurrentValue || '选择日期' }} + + + + + + + + + + + + + + + + + + + + + diff --git a/src/picker/_example/base/index.wxss b/src/picker/_example/base/index.wxss new file mode 100644 index 000000000..4ce6c4b03 --- /dev/null +++ b/src/picker/_example/base/index.wxss @@ -0,0 +1,26 @@ +.pannel-item { + display: flex; + align-items: center; + height: 96rpx; + padding: 0 32rpx; + font-size: 32rpx; + margin-bottom: 32rpx; + background-color: #fff; +} + +.pannel-item .last { + margin-bottom: -13rpx; +} +.pannel-label { + width: 160rpx; + margin-right: 32rpx; +} + +.pannel-text { + flex: 1; + color: #000; + opacity: 0.9; +} +.pannel-text.empty { + opacity: 0.26; +} diff --git a/src/picker/_example/picker.json b/src/picker/_example/picker.json index f294ad3be..85547c2b0 100644 --- a/src/picker/_example/picker.json +++ b/src/picker/_example/picker.json @@ -1,6 +1,9 @@ { "navigationBarTitleText": "Picker 选择器", "usingComponents": { - "t-demo": "../../components/demo-block/index" + "t-demo": "../../components/demo-block/index", + "t-picker": "tdesign-miniprogram/picker/picker", + "t-picker-item": "tdesign-miniprogram/picker/picker-item", + "base": "./base" } } diff --git a/src/picker/_example/picker.ts b/src/picker/_example/picker.ts index 664ed7683..456e2bd0e 100644 --- a/src/picker/_example/picker.ts +++ b/src/picker/_example/picker.ts @@ -1,7 +1,4 @@ const PICKER_KEY = { - CITY: 'city', - YEAR_SEASONS: 'yearSeasons', - DATE: 'date', CITY_TITLE: 'cityTitle', YEAR_SEASONS_TITLE: 'yearSeasonsTitle', DATE_TITLE: 'dateTitle', @@ -10,15 +7,10 @@ const PICKER_KEY = { Page({ data: { PICKER_KEY, - - [`${PICKER_KEY.CITY}Visible`]: false, - [`${PICKER_KEY.YEAR_SEASONS}Visible`]: false, - [`${PICKER_KEY.DATE}Visible`]: false, [`${PICKER_KEY.CITY_TITLE}Visible`]: false, [`${PICKER_KEY.YEAR_SEASONS_TITLE}Visible`]: false, [`${PICKER_KEY.DATE_TITLE}Visible`]: false, - pickerTitle: '', citys: [ { label: '北京', value: '北京' }, { label: '上海', value: '上海' }, @@ -42,33 +34,31 @@ Page({ { label: '秋', value: '秋' }, { label: '冬', value: '冬' }, ], - - [`${PICKER_KEY.CITY}Value`]: [], - [`${PICKER_KEY.YEAR_SEASONS}Value`]: [], - [`${PICKER_KEY.DATE}Value`]: [], [`${PICKER_KEY.CITY_TITLE}Value`]: [], [`${PICKER_KEY.YEAR_SEASONS_TITLE}Value`]: [], [`${PICKER_KEY.DATE_TITLE}Value`]: [], }, + joinArray(array) { + return array.join('-'); + }, + onClickPicker(e) { const { key } = e?.currentTarget?.dataset; - this.setData({ [`${key}Visible`]: true, }); }, - onColumnChange(e) { console.log('picker pick:', e); }, - onPickerChange(e) { const { key } = e?.currentTarget?.dataset; console.log('picker change:', e.detail); this.setData({ [`${key}Visible`]: false, [`${key}Value`]: e.detail.value, + [`${key}CurrentValue`]: this.joinArray(e.detail.value), }); }, onPickerCancel(e) { diff --git a/src/picker/_example/picker.wxml b/src/picker/_example/picker.wxml index 16308c3b6..6994b3e30 100644 --- a/src/picker/_example/picker.wxml +++ b/src/picker/_example/picker.wxml @@ -1,33 +1,14 @@ - - var joinArray = function (array) { return array.join('-') } ;module.exports = { joinArray: joinArray } - Picker 选择器 用于一组预设数据中的选择。 - - 城市 - {{util.joinArray(cityValue) || '选择城市'}} - - - - 年份和季节 - - {{util.joinArray(yearSeasonsValue) || '选择年份和季节' }} - - - - 日期 - {{util.joinArray(dateValue) || '选择日期' }} - - + 城市 {{util.joinArray(cityTitleValue) || '选择城市'}}{{ cityTitleCurrentValue || '选择城市' }} @@ -39,67 +20,19 @@ > 年份和季节 - {{ util.joinArray(yearSeasonsTitleValue) || '选择年份和季节' }} 日期 - {{util.joinArray(dateTitleValue) || '选择日期'}} - - - - - - - - - - - - - - - - - -