123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <template>
- <view class="tn-form-class tn-form">
- <slot></slot>
- </view>
- </template>
- <script>
- export default {
- name: 'tn-form',
- props: {
-
- model: {
- type: Object,
- default() {
- return {}
- }
- },
-
-
-
-
-
-
- errorType: {
- type: Array,
- default() {
- return ['message', 'toast']
- }
- },
-
- borderBottom: {
- type:Boolean,
- default: true
- },
-
-
-
- labelPosition: {
- type: String,
- default: 'left'
- },
-
- labelWidth: {
- type: Number,
- default: 90
- },
-
-
-
-
- labelAlign: {
- type: String,
- default: 'left'
- },
-
- labelStyle: {
- type: Object,
- default() {
- return {}
- }
- }
- },
-
- provide() {
- return {
- tnForm: this
- }
- },
- data() {
- return {
- rules: {}
- }
- },
- created() {
-
-
- this.fields = []
- },
- methods: {
-
- setRules(rules) {
- this.rules = rules
- },
-
- resetFields() {
- this.fields.map(field => {
- field.resetField()
- })
- },
-
- validate(callback) {
- return new Promise(resolve => {
-
- let valid = true
-
- let count = 0
-
- let errors = []
-
-
- this.fields.map(field => {
-
- field.validation('', error => {
-
- if (error) {
- valid = false
- errors.push(error)
- }
-
- if (++count === this.fields.length) {
- resolve(valid)
-
- if (this.errorType.indexOf('none') === -1 &&
- this.errorType.indexOf('toast') >= 0 &&
- errors.length > 0) {
- this.$t.message.toast(errors[0])
- }
-
- if (typeof callback == 'function') callback(valid)
- }
- })
- })
- })
- }
- }
- }
- </script>
- <style>
- </style>
|