mirror of
				https://gitee.com/vant-contrib/vant-weapp.git
				synced 2025-10-27 01:42:08 +08:00 
			
		
		
		
	[improvement] SubmitBar: price & tip 支持动态更新
fix 1676
This commit is contained in:
		
							parent
							
								
									1d54331a4f
								
							
						
					
					
						commit
						55ad8418fc
					
				| @ -132,6 +132,23 @@ | ||||
| @stepper-input-disabled-color: @active-color; | ||||
| @stepper-border-radius: 4px; | ||||
| 
 | ||||
| // SubmitBar | ||||
| @submit-bar-height: 50px; | ||||
| @submit-bar-z-index: 100; | ||||
| @submit-bar-background-color: @white; | ||||
| @submit-bar-button-width: 110px; | ||||
| @submit-bar-price-color: @red; | ||||
| @submit-bar-price-font-size: 18px; | ||||
| @submit-bar-currency-font-size: 14px; | ||||
| @submit-bar-text-color: @text-color; | ||||
| @submit-bar-text-font-size: 14px; | ||||
| @submit-bar-tip-padding: 10px; | ||||
| @submit-bar-tip-font-size: 12px; | ||||
| @submit-bar-tip-line-height: 1.5; | ||||
| @submit-bar-tip-color: #f56723; | ||||
| @submit-bar-tip-background-color: #fff7cc; | ||||
| @submit-bar-tip-icon-size: 12px; | ||||
| 
 | ||||
| // NavBar | ||||
| @nav-bar-height: 44px; | ||||
| 
 | ||||
|  | ||||
| @ -78,6 +78,7 @@ es5 | ||||
| |-----------|-----------|-----------|-------------| | ||||
| | price | 价格(单位分) |  `Number` | - | | ||||
| | label | 价格文案 |  `String` | `合计:` | | ||||
| | suffix-label | 价格右侧文案 | `String` | - | | ||||
| | button-text | 按钮文字 | `String` | - | | ||||
| | button-type | 按钮类型 |  `String` | `danger` | | ||||
| | tip | 提示文案 |  `String` / `Boolean` | - | | ||||
| @ -100,7 +101,7 @@ es5 | ||||
| |-----------|-----------| | ||||
| | - | 自定义订单栏左侧内容 | | ||||
| | top | 自定义订单栏上方内容 | | ||||
| | tip | 提示文案中的额外操作和说明,`tip` 不为空时才显示 | | ||||
| | tip | 提示文案中的额外操作和说明 | | ||||
| 
 | ||||
| ### 外部样式类 | ||||
| 
 | ||||
|  | ||||
| @ -1,25 +1,29 @@ | ||||
| @import '../common/style/var.less'; | ||||
| 
 | ||||
| .van-submit-bar { | ||||
|   z-index: 100; | ||||
|   position: fixed; | ||||
|   bottom: 0; | ||||
|   left: 0; | ||||
|   z-index: @submit-bar-z-index; | ||||
|   width: 100%; | ||||
|   user-select: none; | ||||
| 
 | ||||
|   &__tip { | ||||
|     padding: 10px; | ||||
|     color: #f56723; | ||||
|     font-size: 12px; | ||||
|     line-height: 18px; | ||||
|     background-color: #fff7cc; | ||||
|     padding: @submit-bar-tip-padding; | ||||
|     font-size: @submit-bar-tip-font-size; | ||||
|     line-height: @submit-bar-tip-line-height; | ||||
|     color: @submit-bar-tip-color; | ||||
|     background-color: @submit-bar-tip-background-color; | ||||
| 
 | ||||
|     &:empty { | ||||
|       display: none; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   &__tip-icon { | ||||
|     width:12px; | ||||
|     height:12px; | ||||
|     margin-right:4px; | ||||
|     width: 12px; | ||||
|     height: 12px; | ||||
|     margin-right: 4px; | ||||
|     vertical-align: middle; | ||||
|   } | ||||
| 
 | ||||
| @ -30,10 +34,11 @@ | ||||
| 
 | ||||
|   &__bar { | ||||
|     display: flex; | ||||
|     height: @submit-bar-height; | ||||
|     font-size: @submit-bar-text-font-size; | ||||
|     background-color: @submit-bar-background-color; | ||||
|     align-items: center; | ||||
|     height: 50px; | ||||
|     background-color: @white; | ||||
|     font-size: 14px; | ||||
|     justify-content: flex-end; | ||||
| 
 | ||||
|     &--safe { | ||||
|       padding-bottom: @safe-area-inset-bottom; | ||||
| @ -41,23 +46,27 @@ | ||||
|   } | ||||
| 
 | ||||
|   &__text { | ||||
|     flex: 1; | ||||
|     color: @text-color; | ||||
|     padding-right: 12px; | ||||
|     font-weight: 500; | ||||
|     color: @submit-bar-text-color; | ||||
|     flex: 1; | ||||
|     text-align: right; | ||||
|   } | ||||
| 
 | ||||
|   &__price { | ||||
|     color: @red; | ||||
|     font-size: 18px; | ||||
|     padding-right: 12px; | ||||
|     font-size: @submit-bar-price-font-size; | ||||
|     color: @submit-bar-price-color; | ||||
|   } | ||||
| 
 | ||||
|   &__currency { | ||||
|     font-size: 14px; | ||||
|     font-size: @submit-bar-currency-font-size; | ||||
|   } | ||||
| 
 | ||||
|   &__suffix-label { | ||||
|     margin-left: 5px; | ||||
|   } | ||||
| 
 | ||||
|   &__button { | ||||
|     width: 110px; | ||||
|     width: @submit-bar-button-width; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -11,10 +11,16 @@ VantComponent({ | ||||
|   ], | ||||
| 
 | ||||
|   props: { | ||||
|     tip: null, | ||||
|     tip: { | ||||
|       type: null, | ||||
|       observer: 'updateTip' | ||||
|     }, | ||||
|     tipIcon: String, | ||||
|     type: Number, | ||||
|     price: null, | ||||
|     price: { | ||||
|       type: null, | ||||
|       observer: 'updatePrice' | ||||
|     }, | ||||
|     label: String, | ||||
|     loading: Boolean, | ||||
|     disabled: Boolean, | ||||
| @ -29,26 +35,25 @@ VantComponent({ | ||||
|     }, | ||||
|     decimalLength: { | ||||
|       type: Number, | ||||
|       value: 2 | ||||
|     } | ||||
|       value: 2, | ||||
|       observer: 'updatePrice' | ||||
|     }, | ||||
| 
 | ||||
|   computed: { | ||||
|     hasPrice() { | ||||
|       return typeof this.data.price === 'number'; | ||||
|     }, | ||||
| 
 | ||||
|     priceStr() { | ||||
|       return (this.data.price / 100).toFixed(this.data.decimalLength); | ||||
|     }, | ||||
| 
 | ||||
|     tipStr() { | ||||
|       const { tip } = this.data; | ||||
|       return typeof tip === 'string' ? tip : ''; | ||||
|     } | ||||
|     suffixLabel: String | ||||
|   }, | ||||
| 
 | ||||
|   methods: { | ||||
|     updatePrice() { | ||||
|       const { price, decimalLength } = this.data; | ||||
|       this.set({ | ||||
|         hasPrice: typeof price === 'number', | ||||
|         priceStr: (price / 100).toFixed(decimalLength) | ||||
|       }); | ||||
|     }, | ||||
| 
 | ||||
|     updateTip() { | ||||
|       this.set({ hasTip: typeof this.data.tip === 'string' }); | ||||
|     }, | ||||
| 
 | ||||
|     onSubmit(event: Weapp.Event) { | ||||
|       this.$emit('submit', event.detail); | ||||
|     } | ||||
|  | ||||
| @ -3,28 +3,28 @@ | ||||
| <view class="van-submit-bar custom-class"> | ||||
|   <slot name="top" /> | ||||
| 
 | ||||
|   <view wx:if="{{ tip }}" class="van-submit-bar__tip"> | ||||
|   <view class="van-submit-bar__tip"> | ||||
|     <van-icon | ||||
|       wx:if="{{ tipIcon }}" | ||||
|       size="12px" | ||||
|       name="{{ tipIcon }}" | ||||
|       custom-class="van-submit-bar__tip-icon" | ||||
|     /> | ||||
|     <view wx:if="{{ tipStr }}" class="van-submit-bar__tip-text"> | ||||
|       {{ tipStr }} | ||||
|     <view wx:if="{{ hasTip }}" class="van-submit-bar__tip-text"> | ||||
|       {{ tip }} | ||||
|     </view> | ||||
|     <slot name="tip" /> | ||||
|   </view> | ||||
| 
 | ||||
|   <view class="bar-class {{ utils.bem('submit-bar__bar', { safe: safeAreaInsetBottom && isIPhoneX }) }}"> | ||||
|     <slot /> | ||||
|     <view class="van-submit-bar__text"> | ||||
|       <block wx:if="{{ hasPrice }}"> | ||||
|     <view wx:if="{{ hasPrice }}" class="van-submit-bar__text"> | ||||
|       <text>{{ label || '合计:' }}</text> | ||||
|       <text class="van-submit-bar__price price-class"> | ||||
|           <text class="van-submit-bar__currency">{{ currency }}</text> {{ priceStr }} | ||||
|         <text class="van-submit-bar__currency">{{ currency }} </text> | ||||
|         <text>{{ priceStr }}</text> | ||||
|       </text> | ||||
|       </block> | ||||
|       <text class="van-submit-bar__suffix-label">{{ suffixLabel }}</text> | ||||
|     </view> | ||||
|     <van-button | ||||
|       square | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user