mirror of
				https://gitee.com/vant-contrib/vant-weapp.git
				synced 2025-10-31 03:32:07 +08:00 
			
		
		
		
	feat(rate): support model value
This commit is contained in:
		
							parent
							
								
									c63e63d6e4
								
							
						
					
					
						commit
						ea1653657a
					
				| @ -7,13 +7,6 @@ Page({ | |||||||
|     value3: 3, |     value3: 3, | ||||||
|     value4: 2.5, |     value4: 2.5, | ||||||
|     value5: 4, |     value5: 4, | ||||||
|     value6: 3 |     value6: 3, | ||||||
|   }, |   }, | ||||||
| 
 |  | ||||||
|   onChange(event) { |  | ||||||
|     const { key } = event.currentTarget.dataset; |  | ||||||
|     this.setData({ |  | ||||||
|       [key]: event.detail |  | ||||||
|     }); |  | ||||||
|   } |  | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -1,8 +1,7 @@ | |||||||
| <demo-block title="基础用法"> | <demo-block title="基础用法"> | ||||||
|   <van-rate |   <van-rate | ||||||
|     custom-class="rate-position" |     custom-class="rate-position" | ||||||
|     data-key="value1" |     model:value="{{ value1 }}" | ||||||
|     value="{{ value1 }}" |  | ||||||
|   /> |   /> | ||||||
| </demo-block> | </demo-block> | ||||||
| 
 | 
 | ||||||
| @ -11,53 +10,45 @@ | |||||||
|     custom-class="rate-position" |     custom-class="rate-position" | ||||||
|     icon="like" |     icon="like" | ||||||
|     void-icon="like-o" |     void-icon="like-o" | ||||||
|     data-key="value2" |     model:value="{{ value2 }}" | ||||||
|     value="{{ value2 }}" |  | ||||||
|   /> |   /> | ||||||
| </demo-block> | </demo-block> | ||||||
| 
 | 
 | ||||||
| <demo-block title="自定义样式"> | <demo-block title="自定义样式"> | ||||||
|   <van-rate |   <van-rate | ||||||
|     custom-class="rate-position" |     custom-class="rate-position" | ||||||
|     data-key="value3" |     model:value="{{ value3 }}" | ||||||
|     value="{{ value3 }}" |  | ||||||
|     size="{{ 25 }}" |     size="{{ 25 }}" | ||||||
|     color="#ee0a24" |     color="#ee0a24" | ||||||
|     void-color="#eee" |     void-color="#eee" | ||||||
|     void-icon="star" |     void-icon="star" | ||||||
|     bind:change="onChange" |  | ||||||
|   /> |   /> | ||||||
| </demo-block> | </demo-block> | ||||||
| 
 | 
 | ||||||
| <demo-block title="半星"> | <demo-block title="半星"> | ||||||
|   <van-rate |   <van-rate | ||||||
|     custom-class="rate-position" |     custom-class="rate-position" | ||||||
|     data-key="value4" |     model:value="{{ value4 }}" | ||||||
|     value="{{ value4 }}" |  | ||||||
|     size="{{ 25 }}" |     size="{{ 25 }}" | ||||||
|     allow-half |     allow-half | ||||||
|     color="#ee0a24" |     color="#ee0a24" | ||||||
|     void-color="#eee" |     void-color="#eee" | ||||||
|     void-icon="star" |     void-icon="star" | ||||||
|     touchable="{{ false }}" |     touchable="{{ false }}" | ||||||
|     bind:change="onChange" |  | ||||||
|   /> |   /> | ||||||
| </demo-block> | </demo-block> | ||||||
| 
 | 
 | ||||||
| <demo-block title="自定义数量"> | <demo-block title="自定义数量"> | ||||||
|   <van-rate |   <van-rate | ||||||
|     custom-class="rate-position" |     custom-class="rate-position" | ||||||
|     data-key="value5" |     model:value="{{ value5 }}" | ||||||
|     value="{{ value5 }}" |  | ||||||
|     count="{{ 6 }}" |     count="{{ 6 }}" | ||||||
|     bind:change="onChange" |  | ||||||
|   /> |   /> | ||||||
| </demo-block> | </demo-block> | ||||||
| 
 | 
 | ||||||
| <demo-block title="禁用状态"> | <demo-block title="禁用状态"> | ||||||
|   <van-rate |   <van-rate | ||||||
|     custom-class="rate-position" |     custom-class="rate-position" | ||||||
|     data-key="value6" |  | ||||||
|     value="{{ value6 }}" |     value="{{ value6 }}" | ||||||
|     disabled |     disabled | ||||||
|   /> |   /> | ||||||
| @ -66,7 +57,6 @@ | |||||||
| <demo-block title="只读状态"> | <demo-block title="只读状态"> | ||||||
|   <van-rate |   <van-rate | ||||||
|     custom-class="rate-position" |     custom-class="rate-position" | ||||||
|     data-key="value6" |  | ||||||
|     value="{{ value6 }}" |     value="{{ value6 }}" | ||||||
|     readonly |     readonly | ||||||
|   /> |   /> | ||||||
|  | |||||||
| @ -13,7 +13,7 @@ | |||||||
| 	}, | 	}, | ||||||
| 	"compileType": "miniprogram", | 	"compileType": "miniprogram", | ||||||
| 	"cloudfunctionRoot": "functions/", | 	"cloudfunctionRoot": "functions/", | ||||||
| 	"libVersion": "2.3.0", | 	"libVersion": "2.9.3", | ||||||
| 	"appid": "wx1c01b35002d3ba14", | 	"appid": "wx1c01b35002d3ba14", | ||||||
| 	"projectname": "vant-weapp", | 	"projectname": "vant-weapp", | ||||||
| 	"debugOptions": { | 	"debugOptions": { | ||||||
|  | |||||||
							
								
								
									
										33
									
								
								packages/common/version.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								packages/common/version.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | |||||||
|  | import { getSystemInfoSync } from './utils'; | ||||||
|  | 
 | ||||||
|  | function compareVersion(v1, v2) { | ||||||
|  |   v1 = v1.split('.'); | ||||||
|  |   v2 = v2.split('.'); | ||||||
|  |   const len = Math.max(v1.length, v2.length); | ||||||
|  | 
 | ||||||
|  |   while (v1.length < len) { | ||||||
|  |     v1.push('0'); | ||||||
|  |   } | ||||||
|  |   while (v2.length < len) { | ||||||
|  |     v2.push('0'); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   for (let i = 0; i < len; i++) { | ||||||
|  |     const num1 = parseInt(v1[i], 10); | ||||||
|  |     const num2 = parseInt(v2[i], 10); | ||||||
|  | 
 | ||||||
|  |     if (num1 > num2) { | ||||||
|  |       return 1; | ||||||
|  |     } | ||||||
|  |     if (num1 < num2) { | ||||||
|  |       return -1; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export function canIUseModel() { | ||||||
|  |   const system = getSystemInfoSync(); | ||||||
|  |   return compareVersion(system.SDKVersion, '2.9.3') >= 0; | ||||||
|  | } | ||||||
| @ -1,6 +1,7 @@ | |||||||
| import { VantComponent } from '../common/component'; | import { VantComponent } from '../common/component'; | ||||||
| import { Weapp } from 'definitions/weapp'; | import { Weapp } from 'definitions/weapp'; | ||||||
| import { commonProps, inputProps, textareaProps } from './props'; | import { commonProps, inputProps, textareaProps } from './props'; | ||||||
|  | import { canIUseModel } from '../common/version'; | ||||||
| 
 | 
 | ||||||
| VantComponent({ | VantComponent({ | ||||||
|   field: true, |   field: true, | ||||||
| @ -121,7 +122,9 @@ VantComponent({ | |||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     emitChange() { |     emitChange() { | ||||||
|  |       if (canIUseModel()) { | ||||||
|         this.setData({ value: this.value }); |         this.setData({ value: this.value }); | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
|       wx.nextTick(() => { |       wx.nextTick(() => { | ||||||
|         this.$emit('input', this.value); |         this.$emit('input', this.value); | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| import { VantComponent } from '../common/component'; | import { VantComponent } from '../common/component'; | ||||||
| import { Weapp } from 'definitions/weapp'; | import { Weapp } from 'definitions/weapp'; | ||||||
|  | import { canIUseModel } from '../common/version'; | ||||||
| 
 | 
 | ||||||
| VantComponent({ | VantComponent({ | ||||||
|   field: true, |   field: true, | ||||||
| @ -64,8 +65,15 @@ VantComponent({ | |||||||
|       const { score } = event.currentTarget.dataset; |       const { score } = event.currentTarget.dataset; | ||||||
|       if (!data.disabled && !data.readonly) { |       if (!data.disabled && !data.readonly) { | ||||||
|         this.setData({ innerValue: score + 1 }); |         this.setData({ innerValue: score + 1 }); | ||||||
|  | 
 | ||||||
|  |         if (canIUseModel()) { | ||||||
|  |           this.setData({ value: score + 1 }); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         wx.nextTick(() => { | ||||||
|           this.$emit('input', score + 1); |           this.$emit('input', score + 1); | ||||||
|           this.$emit('change', score + 1); |           this.$emit('change', score + 1); | ||||||
|  |         }); | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user