fix(datetime-picker): 修复日期选择器格式化问题并添加中文显示
修改datetime-picker组件,强制使用中文格式显示年月日时分 更新项目文档说明此组件的自定义修改注意事项
Showing
2 changed files
with
47 additions
and
2 deletions
| ... | @@ -97,7 +97,30 @@ VantComponent({ | ... | @@ -97,7 +97,30 @@ VantComponent({ |
| 97 | return this.picker; | 97 | return this.picker; |
| 98 | }, | 98 | }, |
| 99 | updateColumns() { | 99 | updateColumns() { |
| 100 | - const { formatter = defaultFormatter } = this.data; | 100 | + // const { formatter = defaultFormatter } = this.data; |
| 101 | + let { formatter } = this.data; | ||
| 102 | + if (defaultFormatter) { | ||
| 103 | + formatter = defaultFormatter; | ||
| 104 | + } | ||
| 105 | + // 默认写死配置 | ||
| 106 | + formatter = (type, value) => { | ||
| 107 | + if (type === 'year') { | ||
| 108 | + return `${value}年`; | ||
| 109 | + } | ||
| 110 | + if (type === 'month') { | ||
| 111 | + return `${value}月`; | ||
| 112 | + } | ||
| 113 | + if (type === 'day') { | ||
| 114 | + return `${value}日`; | ||
| 115 | + } | ||
| 116 | + if (type === 'hour') { | ||
| 117 | + return `${value}时`; | ||
| 118 | + } | ||
| 119 | + if (type === 'minute') { | ||
| 120 | + return `${value}分`; | ||
| 121 | + } | ||
| 122 | + return value; | ||
| 123 | + } | ||
| 101 | const results = this.getOriginColumns().map((column) => ({ | 124 | const results = this.getOriginColumns().map((column) => ({ |
| 102 | values: column.values.map((value) => formatter(column.type, value)), | 125 | values: column.values.map((value) => formatter(column.type, value)), |
| 103 | })); | 126 | })); |
| ... | @@ -262,7 +285,27 @@ VantComponent({ | ... | @@ -262,7 +285,27 @@ VantComponent({ |
| 262 | updateColumnValue(value) { | 285 | updateColumnValue(value) { |
| 263 | let values = []; | 286 | let values = []; |
| 264 | const { type } = this.data; | 287 | const { type } = this.data; |
| 265 | - const formatter = this.data.formatter || defaultFormatter; | 288 | + let formatter = this.data.formatter || defaultFormatter; |
| 289 | + // 默认写死配置 | ||
| 290 | + formatter = (type, value) => { | ||
| 291 | + if (type === 'year') { | ||
| 292 | + return `${value}年`; | ||
| 293 | + } | ||
| 294 | + if (type === 'month') { | ||
| 295 | + return `${value}月`; | ||
| 296 | + } | ||
| 297 | + if (type === 'day') { | ||
| 298 | + return `${value}日`; | ||
| 299 | + } | ||
| 300 | + if (type === 'hour') { | ||
| 301 | + return `${value}时`; | ||
| 302 | + } | ||
| 303 | + if (type === 'minute') { | ||
| 304 | + return `${value}分`; | ||
| 305 | + } | ||
| 306 | + return value; | ||
| 307 | + } | ||
| 308 | + | ||
| 266 | const picker = this.getPicker(); | 309 | const picker = this.getPicker(); |
| 267 | if (type === 'time') { | 310 | if (type === 'time') { |
| 268 | const pair = value.split(':'); | 311 | const pair = value.split(':'); | ... | ... |
-
Please register or login to post a comment