ui库和web端产品库合并版本(还需修复细节)
This commit is contained in:
		
							
								
								
									
										58
									
								
								ui/packages/basic/AiNumber.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								ui/packages/basic/AiNumber.vue
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| <template> | ||||
|   <section class="AiNumber"> | ||||
|     <el-input v-model="num" :size="size" @input.native="validate" @focus="$emit('focus')" @blur="format" clearable | ||||
|              @change="$emit('change')" :validate-event="isRule"></el-input> | ||||
|   </section> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
|   export default { | ||||
|     name: "AiNumber", | ||||
|     model: { | ||||
|       prop: "value", | ||||
|       event: "change" | ||||
|     }, | ||||
|     props: { | ||||
|       value: String, | ||||
|       size: String, | ||||
|       decimal: {type: [String, Number], default: 2}, | ||||
|       isRule: {type: Boolean, default: true} | ||||
|     }, | ||||
|     computed: { | ||||
|       validRegex() { | ||||
|         let dec = Number(this.decimal || 0), | ||||
|             regex = `^(\\d*\\.?\\d{0,${dec}}).*` | ||||
|         return new RegExp(regex) | ||||
|       } | ||||
|  | ||||
|     }, | ||||
|     data() { | ||||
|       return { | ||||
|         num: "" | ||||
|       } | ||||
|     }, | ||||
|     methods: { | ||||
|       validate() { | ||||
|         let num = JSON.parse(JSON.stringify(this.num)) | ||||
|         this.num = num.replace(this.validRegex, '$1') | ||||
|       }, | ||||
|       format() { | ||||
|         this.num = Number(this.num||0).toString() | ||||
|         this.$emit("blur") | ||||
|       } | ||||
|     }, | ||||
|     watch: { | ||||
|       num(v) { | ||||
|         this.$emit("change", v) | ||||
|       } | ||||
|     }, | ||||
|     mounted() { | ||||
|       this.num = this.value | ||||
|     } | ||||
|   } | ||||
| </script> | ||||
|  | ||||
| <style lang="scss" scoped> | ||||
|   .AiNumber { | ||||
|   } | ||||
| </style> | ||||
		Reference in New Issue
	
	Block a user