康巴易测肤/伤疤uniapp小程序类
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.

преди 1 месец
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <uvForm
  3. ref="uForm"
  4. :model="model"
  5. :rules="rules"
  6. :errorType="errorType"
  7. :borderBottom="borderBottom"
  8. :labelPosition="labelPosition"
  9. :labelWidth="labelWidth"
  10. :labelAlign="labelAlign"
  11. :labelStyle="labelStyle"
  12. :customStyle="customStyle"
  13. >
  14. <slot />
  15. </uvForm>
  16. </template>
  17. <script>
  18. /**
  19. * 此组件存在的理由是,在nvue下,u-form被uni-app官方占用了,u-form在nvue中相当于form组件
  20. * 所以在nvue下,取名为u--form,内部其实还是u-form.vue,只不过做一层中转
  21. */
  22. import uvForm from '../u-form/u-form.vue';
  23. import props from '../u-form/props.js'
  24. /**
  25. * Form 表单
  26. * @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
  27. * @tutorial https://www.uviewui.com/components/form.html
  28. * @property {Object} model 当前form的需要验证字段的集合
  29. * @property {Object | Function | Array} rules 验证规则
  30. * @property {String} errorType 错误的提示方式,见上方说明 ( 默认 message )
  31. * @property {Boolean} borderBottom 是否显示表单域的下划线边框 ( 默认 true )
  32. * @property {String} labelPosition 表单域提示文字的位置,left-左侧,top-上方 ( 默认 'left' )
  33. * @property {String | Number} labelWidth 提示文字的宽度,单位px ( 默认 45 )
  34. * @property {String} labelAlign lable字体的对齐方式 ( 默认 ‘left' )
  35. * @property {Object} labelStyle lable的样式,对象形式
  36. * @example <u--formlabelPosition="left" :model="model1" :rules="rules" ref="form1"></u--form>
  37. */
  38. export default {
  39. // #ifdef MP-WEIXIN
  40. name: 'u-form',
  41. // #endif
  42. // #ifndef MP-WEIXIN
  43. name: 'u--form',
  44. // #endif
  45. mixins: [uni.$u.mpMixin, props, uni.$u.mixin],
  46. components: {
  47. uvForm
  48. },
  49. created() {
  50. this.children = []
  51. },
  52. methods: {
  53. // 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
  54. setRules(rules) {
  55. this.$refs.uForm.setRules(rules)
  56. },
  57. validate() {
  58. /**
  59. * 在微信小程序中,通过this.$parent拿到的父组件是u--form,而不是其内嵌的u-form
  60. * 导致在u-form组件中,拿不到对应的children数组,从而校验无效,所以这里每次调用u-form组件中的
  61. * 对应方法的时候,在小程序中都先将u--form的children赋值给u-form中的children
  62. */
  63. // #ifdef MP-WEIXIN
  64. this.setMpData()
  65. // #endif
  66. return this.$refs.uForm.validate()
  67. },
  68. validateField(value, callback, event) {
  69. // #ifdef MP-WEIXIN
  70. this.setMpData()
  71. // #endif
  72. return this.$refs.uForm.validateField(value, callback, event)
  73. },
  74. resetFields() {
  75. // #ifdef MP-WEIXIN
  76. this.setMpData()
  77. // #endif
  78. return this.$refs.uForm.resetFields()
  79. },
  80. clearValidate(props) {
  81. // #ifdef MP-WEIXIN
  82. this.setMpData()
  83. // #endif
  84. return this.$refs.uForm.clearValidate(props)
  85. },
  86. setMpData() {
  87. this.$refs.uForm.children = this.children
  88. }
  89. },
  90. }
  91. </script>