You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.3 KiB
79 lines
1.3 KiB
<script setup> |
|
|
|
import {nextTick, provide, ref, watch} from "vue"; |
|
|
|
const props = defineProps({ |
|
type:{ |
|
type:String, |
|
default:'form' |
|
}, |
|
model:{ |
|
type:Object, |
|
default:{} |
|
}, |
|
isRead:{ |
|
type:Boolean, |
|
default:false, |
|
}, |
|
disabled:{ |
|
type:Boolean, |
|
default:false, |
|
} |
|
}) |
|
|
|
watch(() => props.type,()=>{ |
|
uni.$emit('formType',props.type); |
|
}); |
|
|
|
|
|
const rule = ref([]); |
|
provide('form',{ |
|
rule:rule, |
|
props:props |
|
}); |
|
|
|
function verify(){ |
|
try { |
|
// nextTick(() => { |
|
return new Promise((resolve, reject) => { |
|
rule.value.some(item => { |
|
if(!props.model[item.value]){ |
|
uni.$m.error(item.label+'未填写') |
|
reject(item) |
|
return true; |
|
} |
|
}) |
|
resolve(true); |
|
}).catch(e => { |
|
console.log('e',e) |
|
}) |
|
// }) |
|
}catch (err) { |
|
console.log('err',err) |
|
} |
|
} |
|
|
|
defineExpose({ |
|
verify |
|
}) |
|
</script> |
|
|
|
<template> |
|
<view class="form border-box" style="position:relative;z-index:2;background-color:#fff;padding-top:0;"> |
|
<slot></slot> |
|
</view> |
|
</template> |
|
|
|
<style lang="scss"> |
|
.form-item { |
|
padding: 35rpx 0; |
|
|
|
&.bottom { |
|
padding-bottom: 10rpx; |
|
} |
|
} |
|
.vertical{ |
|
flex: 0 0 100%; |
|
padding-bottom:10rpx; |
|
} |
|
</style> |