diff --git a/dist/calendar/index.js b/dist/calendar/index.js index 08dad0be..7fa6a5d0 100644 --- a/dist/calendar/index.js +++ b/dist/calendar/index.js @@ -1,7 +1,9 @@ import { VantComponent } from '../common/component'; import { ROW_HEIGHT, + getPrevDay, getNextDay, + getToday, compareDay, copyDates, calcDateNum, @@ -12,6 +14,15 @@ import { } from './utils'; import Toast from '../toast/toast'; import { requestAnimationFrame } from '../common/utils'; +const initialMinDate = getToday().getTime(); +const initialMaxDate = (() => { + const now = getToday(); + return new Date( + now.getFullYear(), + now.getMonth() + 6, + now.getDate() + ).getTime(); +})(); VantComponent({ props: { title: { @@ -54,15 +65,11 @@ VantComponent({ }, minDate: { type: null, - value: Date.now(), + value: initialMinDate, }, maxDate: { type: null, - value: new Date( - new Date().getFullYear(), - new Date().getMonth() + 6, - new Date().getDate() - ).getTime(), + value: initialMaxDate, }, position: { type: String, @@ -151,19 +158,46 @@ VantComponent({ } }); }, - getInitialDate() { - const { type, defaultDate, minDate } = this.data; + limitDateRange(date, minDate = null, maxDate = null) { + minDate = minDate || this.data.minDate; + maxDate = maxDate || this.data.maxDate; + if (compareDay(date, minDate) === -1) { + return minDate; + } + if (compareDay(date, maxDate) === 1) { + return maxDate; + } + return date; + }, + getInitialDate(defaultDate = null) { + const { type, minDate, maxDate } = this.data; + const now = getToday().getTime(); if (type === 'range') { + if (!Array.isArray(defaultDate)) { + defaultDate = []; + } const [startDay, endDay] = defaultDate || []; - return [ - startDay || minDate, - endDay || getNextDay(new Date(minDate)).getTime(), - ]; + const start = this.limitDateRange( + startDay || now, + minDate, + getPrevDay(maxDate).getTime() + ); + const end = this.limitDateRange( + endDay || now, + getNextDay(minDate).getTime() + ); + return [start, end]; } if (type === 'multiple') { - return defaultDate || [minDate]; + if (Array.isArray(defaultDate)) { + return defaultDate.map((date) => this.limitDateRange(date)); + } + return [this.limitDateRange(now)]; } - return defaultDate || minDate; + if (!defaultDate || Array.isArray(defaultDate)) { + defaultDate = now; + } + return this.limitDateRange(defaultDate); }, scrollIntoView() { requestAnimationFrame(() => { diff --git a/dist/calendar/utils.d.ts b/dist/calendar/utils.d.ts index 17fc0779..ec7cf3f4 100644 --- a/dist/calendar/utils.d.ts +++ b/dist/calendar/utils.d.ts @@ -11,6 +11,7 @@ export declare function compareDay( export declare function getDayByOffset(date: Date, offset: number): Date; export declare function getPrevDay(date: Date): Date; export declare function getNextDay(date: Date): Date; +export declare function getToday(): Date; export declare function calcDateNum(date: [Date, Date]): number; export declare function copyDates(dates: Date | Date[]): Date | Date[]; export declare function getMonthEndDay(year: number, month: number): number; diff --git a/dist/calendar/utils.js b/dist/calendar/utils.js index 281a35c9..f773e7f5 100644 --- a/dist/calendar/utils.js +++ b/dist/calendar/utils.js @@ -47,6 +47,11 @@ export function getPrevDay(date) { export function getNextDay(date) { return getDayByOffset(date, 1); } +export function getToday() { + const today = new Date(); + today.setHours(0, 0, 0, 0); + return today; +} export function calcDateNum(date) { const day1 = new Date(date[0]).getTime(); const day2 = new Date(date[1]).getTime(); diff --git a/dist/cell-group/index.js b/dist/cell-group/index.js index 99bcdb9e..5f76bb55 100644 --- a/dist/cell-group/index.js +++ b/dist/cell-group/index.js @@ -6,5 +6,6 @@ VantComponent({ type: Boolean, value: true, }, + inset: Boolean, }, }); diff --git a/dist/cell-group/index.wxml b/dist/cell-group/index.wxml index 6e0b471d..311e064a 100644 --- a/dist/cell-group/index.wxml +++ b/dist/cell-group/index.wxml @@ -1,9 +1,11 @@ + + {{ title }} - + diff --git a/dist/cell-group/index.wxss b/dist/cell-group/index.wxss index edbccd59..5bc5d0f4 100644 --- a/dist/cell-group/index.wxss +++ b/dist/cell-group/index.wxss @@ -1 +1 @@ -@import '../common/index.wxss';.van-cell-group__title{padding:16px 16px 8px;padding:var(--cell-group-title-padding,16px 16px 8px);font-size:14px;font-size:var(--cell-group-title-font-size,14px);line-height:16px;line-height:var(--cell-group-title-line-height,16px);color:#969799;color:var(--cell-group-title-color,#969799)} \ No newline at end of file +@import '../common/index.wxss';.van-cell-group--inset{margin:0 16px;margin:var(--cell-group-inset-padding,0 16px);border-radius:8px;border-radius:var(--cell-group-inset-border-radius,8px);overflow:hidden}.van-cell-group__title{padding:16px 16px 8px;padding:var(--cell-group-title-padding,16px 16px 8px);font-size:14px;font-size:var(--cell-group-title-font-size,14px);line-height:16px;line-height:var(--cell-group-title-line-height,16px);color:#969799;color:var(--cell-group-title-color,#969799)}.van-cell-group__title--inset{padding:16px 16px 8px 32px;padding:var(--cell-group-inset-title-padding,16px 16px 8px 32px)} \ No newline at end of file diff --git a/docs/markdown/changelog.md b/docs/markdown/changelog.md index 23cf5925..54414354 100644 --- a/docs/markdown/changelog.md +++ b/docs/markdown/changelog.md @@ -1,5 +1,19 @@ # 更新日志 + +### [1.7.2](https://github.com/youzan/vant-weapp/tree/v1.7.2) + +`2021-07-19` + +**Bug Fixes** + + - Calendar: 初始日期设置为当前日期 [#4339](https://github.com/youzan/vant-weapp/issues/4339) + +**Features** + + - Cell: CellGroup 新增 inset 属性 [#4341](https://github.com/youzan/vant-weapp/issues/4341) + - Search: 新增click-input 事件 [#4337](https://github.com/youzan/vant-weapp/issues/4337) + ### [1.7.1](https://github.com/youzan/vant-weapp/tree/v1.7.1) `2021-07-06` diff --git a/example/pages/cell/index.wxml b/example/pages/cell/index.wxml index ebf0bdd7..72130cb3 100644 --- a/example/pages/cell/index.wxml +++ b/example/pages/cell/index.wxml @@ -10,6 +10,13 @@ + + + + + + + + {{ title }} - + diff --git a/lib/cell-group/index.wxss b/lib/cell-group/index.wxss index edbccd59..5bc5d0f4 100644 --- a/lib/cell-group/index.wxss +++ b/lib/cell-group/index.wxss @@ -1 +1 @@ -@import '../common/index.wxss';.van-cell-group__title{padding:16px 16px 8px;padding:var(--cell-group-title-padding,16px 16px 8px);font-size:14px;font-size:var(--cell-group-title-font-size,14px);line-height:16px;line-height:var(--cell-group-title-line-height,16px);color:#969799;color:var(--cell-group-title-color,#969799)} \ No newline at end of file +@import '../common/index.wxss';.van-cell-group--inset{margin:0 16px;margin:var(--cell-group-inset-padding,0 16px);border-radius:8px;border-radius:var(--cell-group-inset-border-radius,8px);overflow:hidden}.van-cell-group__title{padding:16px 16px 8px;padding:var(--cell-group-title-padding,16px 16px 8px);font-size:14px;font-size:var(--cell-group-title-font-size,14px);line-height:16px;line-height:var(--cell-group-title-line-height,16px);color:#969799;color:var(--cell-group-title-color,#969799)}.van-cell-group__title--inset{padding:16px 16px 8px 32px;padding:var(--cell-group-inset-title-padding,16px 16px 8px 32px)} \ No newline at end of file diff --git a/package.json b/package.json index 1f32bd5f..007d3772 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vant/weapp", - "version": "1.7.1", + "version": "1.7.2", "author": "youzan", "license": "MIT", "miniprogram": "lib", diff --git a/packages/calendar/index.ts b/packages/calendar/index.ts index 5a325bdd..8151588c 100644 --- a/packages/calendar/index.ts +++ b/packages/calendar/index.ts @@ -1,7 +1,9 @@ import { VantComponent } from '../common/component'; import { ROW_HEIGHT, + getPrevDay, getNextDay, + getToday, compareDay, copyDates, calcDateNum, @@ -14,6 +16,16 @@ import { import Toast from '../toast/toast'; import { requestAnimationFrame } from '../common/utils'; +const initialMinDate = getToday().getTime(); +const initialMaxDate = (() => { + const now = getToday(); + return new Date( + now.getFullYear(), + now.getMonth() + 6, + now.getDate() + ).getTime(); +})(); + VantComponent({ props: { title: { @@ -56,15 +68,11 @@ VantComponent({ }, minDate: { type: Number, - value: Date.now(), + value: initialMinDate, }, maxDate: { type: Number, - value: new Date( - new Date().getFullYear(), - new Date().getMonth() + 6, - new Date().getDate() - ).getTime(), + value: initialMaxDate, }, position: { type: String, @@ -162,22 +170,58 @@ VantComponent({ }); }, - getInitialDate() { - const { type, defaultDate, minDate } = this.data; + limitDateRange( + date: number, + minDate: number | null = null, + maxDate: number | null = null + ) { + minDate = minDate || (this.data.minDate as number); + maxDate = maxDate || (this.data.maxDate as number); + if (compareDay(date, minDate) === -1) { + return minDate; + } + if (compareDay(date, maxDate) === 1) { + return maxDate; + } + return date; + }, + + getInitialDate(defaultDate: number | number[] | null = null) { + const { type, minDate, maxDate } = this.data; + + const now = getToday().getTime(); if (type === 'range') { + if (!Array.isArray(defaultDate)) { + defaultDate = []; + } + const [startDay, endDay] = defaultDate || []; - return [ - startDay || minDate, - endDay || getNextDay(new Date(minDate)).getTime(), - ]; + + const start = this.limitDateRange( + startDay || now, + minDate, + getPrevDay(maxDate).getTime() + ); + const end = this.limitDateRange( + endDay || now, + getNextDay(minDate).getTime() + ); + return [start, end]; } if (type === 'multiple') { - return defaultDate || [minDate]; + if (Array.isArray(defaultDate)) { + return defaultDate.map((date) => this.limitDateRange(date)); + } + + return [this.limitDateRange(now)]; } - return defaultDate || minDate; + if (!defaultDate || Array.isArray(defaultDate)) { + defaultDate = now; + } + return this.limitDateRange(defaultDate); }, scrollIntoView() { diff --git a/packages/calendar/utils.ts b/packages/calendar/utils.ts index 0b43e24b..a19a0559 100644 --- a/packages/calendar/utils.ts +++ b/packages/calendar/utils.ts @@ -64,6 +64,12 @@ export function getNextDay(date: Date) { return getDayByOffset(date, 1); } +export function getToday() { + const today = new Date(); + today.setHours(0, 0, 0, 0); + return today; +} + export function calcDateNum(date: [Date, Date]) { const day1 = new Date(date[0]).getTime(); const day2 = new Date(date[1]).getTime(); diff --git a/packages/cell-group/index.less b/packages/cell-group/index.less index a2bdf0cb..1b6dab4d 100644 --- a/packages/cell-group/index.less +++ b/packages/cell-group/index.less @@ -2,10 +2,21 @@ @import '../common/style/theme.less'; .van-cell-group { + &--inset { + .theme(margin, '@cell-group-inset-padding'); + .theme(border-radius, '@cell-group-inset-border-radius'); + + overflow: hidden; + } + &__title { .theme(padding, '@cell-group-title-padding'); .theme(font-size, '@cell-group-title-font-size'); .theme(line-height, '@cell-group-title-line-height'); .theme(color, '@cell-group-title-color'); + + &--inset { + .theme(padding, '@cell-group-inset-title-padding'); + } } } diff --git a/packages/cell-group/index.ts b/packages/cell-group/index.ts index 954cbd29..7891f58d 100644 --- a/packages/cell-group/index.ts +++ b/packages/cell-group/index.ts @@ -7,5 +7,6 @@ VantComponent({ type: Boolean, value: true, }, + inset: Boolean, }, }); diff --git a/packages/cell-group/index.wxml b/packages/cell-group/index.wxml index 6e0b471d..311e064a 100644 --- a/packages/cell-group/index.wxml +++ b/packages/cell-group/index.wxml @@ -1,9 +1,11 @@ + + {{ title }} - + diff --git a/packages/cell/README.md b/packages/cell/README.md index 60172908..db8290fd 100644 --- a/packages/cell/README.md +++ b/packages/cell/README.md @@ -28,6 +28,17 @@ ``` +### 卡片风格 + +通过 `CellGroup` 的 `inset` 属性,可以将单元格转换为圆角卡片风格(从 1.7.2 版本开始支持)。 + +```html + + + + +``` + ### 单元格大小 通过`size`属性可以控制单元格的大小。 @@ -109,10 +120,11 @@ ### CellGroup Props -| 参数 | 说明 | 类型 | 默认值 | 版本 | -| ------ | -------------- | --------- | ------ | ---- | -| title | 分组标题 | _string_ | `-` | - | -| border | 是否显示外边框 | _boolean_ | `true` | - | +| 参数 | 说明 | 类型 | 默认值 | +| -------------- | ---------------------- | --------- | ------- | +| title | 分组标题 | _string_ | `-` | +| inset `v1.7.2` | 是否展示为圆角卡片风格 | _boolean_ | `false` | +| border | 是否显示外边框 | _boolean_ | `true` | ### CellGroup 外部样式类 @@ -122,24 +134,24 @@ ### Cell Props -| 参数 | 说明 | 类型 | 默认值 | 版本 | -| --- | --- | --- | --- | --- | -| icon | 左侧图标名称或图片链接,可选值见 [Icon 组件](#/icon) | _string_ | - | - | -| title | 左侧标题 | _string \| number_ | - | -| title-width | 标题宽度,须包含单位 | _string_ | - | - | -| value | 右侧内容 | _string \| number_ | - | - | -| label | 标题下方的描述信息 | _string_ | - | - | -| size | 单元格大小,可选值为 `large` | _string_ | - | - | -| border | 是否显示下边框 | _boolean_ | `true` | - | -| center | 是否使内容垂直居中 | _boolean_ | `false` | - | -| url | 点击后跳转的链接地址 | _string_ | - | - | -| link-type | 链接跳转类型,可选值为 `redirectTo` `switchTab` `reLaunch` | _string_ | `navigateTo` | - | -| clickable | 是否开启点击反馈 | _boolean_ | `false` | - | -| is-link | 是否展示右侧箭头并开启点击反馈 | _boolean_ | `false` | - | -| required | 是否显示表单必填星号 | _boolean_ | `false` | - | -| arrow-direction | 箭头方向,可选值为 `left` `up` `down` | _string_ | - | - | -| use-label-slot | 是否使用 label slot | _boolean_ | `false` | - | -| title-style | 标题样式 | _string_ | - | 1.4.0 | +| 参数 | 说明 | 类型 | 默认值 | +| -------------------- | ---------------------------------------------------------- | ------------------ | ------------ | +| icon | 左侧图标名称或图片链接,可选值见 [Icon 组件](#/icon) | _string_ | - | +| title | 左侧标题 | _string \| number_ | - | +| title-width | 标题宽度,须包含单位 | _string_ | - | +| value | 右侧内容 | _string \| number_ | - | +| label | 标题下方的描述信息 | _string_ | - | +| size | 单元格大小,可选值为 `large` | _string_ | - | +| border | 是否显示下边框 | _boolean_ | `true` | +| center | 是否使内容垂直居中 | _boolean_ | `false` | +| url | 点击后跳转的链接地址 | _string_ | - | +| link-type | 链接跳转类型,可选值为 `redirectTo` `switchTab` `reLaunch` | _string_ | `navigateTo` | +| clickable | 是否开启点击反馈 | _boolean_ | `false` | +| is-link | 是否展示右侧箭头并开启点击反馈 | _boolean_ | `false` | +| required | 是否显示表单必填星号 | _boolean_ | `false` | +| arrow-direction | 箭头方向,可选值为 `left` `up` `down` | _string_ | - | +| use-label-slot | 是否使用 label slot | _boolean_ | `false` | +| title-style `v1.4.0` | 标题样式 | _string_ | - | ### Cell Event diff --git a/packages/common/style/var.less b/packages/common/style/var.less index 601334ee..c66eb8f8 100644 --- a/packages/common/style/var.less +++ b/packages/common/style/var.less @@ -193,6 +193,9 @@ @cell-group-title-padding: @padding-md @padding-md @padding-xs; @cell-group-title-font-size: @font-size-md; @cell-group-title-line-height: 16px; +@cell-group-inset-padding: 0 @padding-md; +@cell-group-inset-border-radius: @border-radius-lg; +@cell-group-inset-title-padding: @padding-md @padding-md @padding-xs @padding-xl; // Checkbox @checkbox-size: 20px; diff --git a/packages/search/README.md b/packages/search/README.md index 9439f865..2aa1293c 100644 --- a/packages/search/README.md +++ b/packages/search/README.md @@ -145,6 +145,7 @@ Page({ | bind:focus | 输入框聚焦时触发 | - | | bind:blur | 输入框失焦时触发 | - | | bind:clear | 点击清空控件时触发 | - | +| bind:click-input | 点击搜索区域时触发 | - | ### Slot diff --git a/packages/search/index.ts b/packages/search/index.ts index cd44e391..31243802 100644 --- a/packages/search/index.ts +++ b/packages/search/index.ts @@ -83,5 +83,9 @@ VantComponent({ onClear(event: WechatMiniprogram.CustomEvent) { this.$emit('clear', event.detail); }, + + onClickInput: function (event) { + this.$emit('click-input', event.detail); + }, }, }); diff --git a/packages/search/index.wxml b/packages/search/index.wxml index 1d0e6f1f..5d77fca8 100644 --- a/packages/search/index.wxml +++ b/packages/search/index.wxml @@ -32,6 +32,7 @@ bind:change="onChange" bind:confirm="onSearch" bind:clear="onClear" + bind:click-input="onClickInput" > diff --git a/packages/uploader/README.md b/packages/uploader/README.md index 374dfa71..05b3edce 100644 --- a/packages/uploader/README.md +++ b/packages/uploader/README.md @@ -190,7 +190,7 @@ Page({ ```js // 上传图片 -uploadToCloud() { +uploadToCloud() { wx.cloud.init(); const { fileList } = this.data; if (!fileList.length) { @@ -200,7 +200,7 @@ uploadToCloud() { Promise.all(uploadTasks) .then(data => { wx.showToast({ title: '上传成功', icon: 'none' }); - const newFileList = data.map(item => { url: item.fileID }); + const newFileList = data.map(item => ({ url: item.fileID })); this.setData({ cloudPath: data, fileList: newFileList }); }) .catch(e => { diff --git a/yarn.lock b/yarn.lock index a47d5b89..53ecc0f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3215,9 +3215,9 @@ eslint-visitor-keys "^2.0.0" "@vant/cli@^3.10.3": - version "3.11.0" - resolved "https://registry.yarnpkg.com/@vant/cli/-/cli-3.11.0.tgz#95812fd72f15c844b2a81f974e85901219a599ec" - integrity sha512-MERBUKZlJvbQT8JJVKkoxL0z532uXHnT5lfs9puszi9uvxLV042PuTm2eF/CAz5mwV5jEZyTapMTZBpmOfLuUA== + version "3.11.2" + resolved "https://registry.yarnpkg.com/@vant/cli/-/cli-3.11.2.tgz#d6a91160b6d64a8a302bebff1858ef8ea3671b0c" + integrity sha512-8sd61UqKHBsCkc3K1wrymuo9f6JxRFfKbX6nq5rlexygZLmoydKgXL8fpB9w3uhriiJJLt3JKNm6Q8k49IjyeA== dependencies: "@babel/core" "^7.14.5" "@babel/preset-env" "^7.14.5" @@ -3292,9 +3292,9 @@ eslint-plugin-vue "^7.1.0" "@vant/icons@^1.6.0": - version "1.6.0" - resolved "https://registry.npmjs.org/@vant/icons/-/icons-1.6.0.tgz#3db7eb7f963f51a2a08676720d5af9c4c3512feb" - integrity sha512-4Hvq4tl4grCOJLZ0e8ZaivBV8xOcmTPmTT8BDkTrEIKqnDowRFDdsXxcHECzWmbmMx+CYGdngvd2Cq8YR9DfKA== + version "1.7.0" + resolved "https://registry.yarnpkg.com/@vant/icons/-/icons-1.7.0.tgz#02d427532a8142c35db159da9c364fe6890c3ac9" + integrity sha512-sqKvtYcSgSd6+AU1nBPaZARn2Nzf8hi0ErLhfXVR6f+Y7R0gojGZVoxuB83yUI6+0LwbitW5IfN3E6qzEsu21Q== "@vant/markdown-loader@^4.1.0": version "4.1.0" @@ -11065,9 +11065,9 @@ minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.5: integrity sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI= miniprogram-api-typings@^3.1.6: - version "3.3.1" - resolved "https://registry.yarnpkg.com/miniprogram-api-typings/-/miniprogram-api-typings-3.3.1.tgz#1cc58437873fe01c1b4f382aa7630bd73d848c42" - integrity sha512-3MTHaLgcuaLlMiEIVn3OdzJjLKgZfkpV/KrwxUYIL/+4b4BM6TAFYcwsXmQH7edOG9AUwU7pkQESpzE0ZjpPUQ== + version "3.4.1" + resolved "https://registry.yarnpkg.com/miniprogram-api-typings/-/miniprogram-api-typings-3.4.1.tgz#17cef4c184d32b2e12e2deb5559d1c01c84fa891" + integrity sha512-kGUJ4zLgwzGyhtCOR2DTz8LTPkKJVek9OqspzGoMVcrmAKV76WqJ6sEOwJoQ1kO/VlTuXEKCu9+ZXB7hFKLcmw== miniprogram-ci@^1.0.27: version "1.2.3"