• vue 项目内vue指令常用


    1. refs使用

    ref 写在标签上时:this.$refs.名字 获取的是标签对应的dom元素
    ref 写在组件上时:这时候获取到的是 子组件(比如counter)的引用

    获取组件上ref

    this.$refs.personalAuthForm[0]
    
    • 1

    获取标签上ref

    this.$refs.personalAuthForm[0].$refs.form
    
    • 1

    代码是工程组件化

    <template>
      <div class="personal-auth" :class="themeCode === '2' ? 'gold' : ''">
        <component
          v-for="(item, index) in personalAuth"
          :ref="item.surveyQuestionTypeId"
          :key="index"
          :is="item.surveyQuestionTypeId"
          :relationshipList="item"
          :currentIndex="index"
          :themeCode="themeCode"
          :imageBack="imageBack"
          :imageFront="imageFront"
          :title="title"
          :buttonInfos="buttonInfos"
          @clickButton="clickButton"
          @checkForm="checkForm"
          @handleOcr="handleOcr"
          :btnStatus="btnStatus"
          @switchCompentsFn="switchCompentsFn"
        />
      div>
    template>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    import { personalAuth } from '../config/components-config';
    import personalAuthUpload from './personal-auth/components/personal-auth-upload.vue';
    import personalAuthForm from './personal-auth/components/personal-auth-form.vue';
    
    export default {
    	data() {
        	return {
        		personalAuth: [],
        	}
        },
        props: {},
        components: {
        	personalAuthForm ,
        },
        computed: {},
        watch: {},
        mounted() {
    	    this.personalAuth = personalAuth;
    	    this.$set(this.buttonInfos[0], 'disabled', true);
    	    this.$set(this.buttonInfos[0], 'buttonText', '请上传身份证件信息');
      	},
      	methods: {
      		clickButton() {
    	      this.$refs.personalAuthForm[0].$refs.form
    	        .validate()
    	        .then((res) => {
    	          let val = this.$refs.personalAuthForm[0].personInfo;
    	          let idCardInfoParams = {
    	            productId: this.$route.query.productId,
    	            custNo: this.$store.getters['user/getUserInfo'].custNo,
    	            idCardInfo: { idcard: val.idCard },
    	            nextComponentName: '/authenSuccessSave',
    	            idCardInfo: {
    	              name: val.fullName,
    	              sex: val.gender,
    	              nation: val.nationality,
    	              address: val.address,
    	              idcard: val.idCard,
    	              birth: val.idCard.substr(6, 8),
    	              authority: val.issuingAuthority,
    	              validDate: val.validDate.replace(/\./g, '')
    	            }
    	          };
    	          this.$store.commit('user/setOtherJSON', idCardInfoParams);
    	          // sessionStorage.setItem("idCardInfo", JSON.stringify(idCardInfoParams))
    	          const params = {
    	            ...val,
    	            imageBack: this.imageBack,
    	            imageFront: this.imageFront
    	          };
    	          sessionStorage.setItem('nextComponentName', '/authenSuccessSave');
    	          this.$router.push({
    	            path: globalConfig['faceController'].pathName,
    	            query: {
    	              partyId: params.partyId,
    	              idcard: params.idCard,
    	              name: params.fullName,
    	              frontFileNo: params.imageBack,
    	              comeFrom: this.comeFrom,
    	              partyGroupId: this.partyGroupId,
    	              data: this.data
    	            }
    	          });
    	        })
    	        .catch((err) => {
    	          //验证失败
    	          console.log('失败!!', err);
    	          return false;
    	        });
    	    }
      	},
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

    components-config.js

    // 个人认证
    export const personalAuth = [{
      "surveyQuestionTypeId": "pageHeader",
      "question": "pageHeader",
      "surveyQuestionCategoryName": "页面元素",
      "description": "页面头部",
      "surveyQuestionTypeName": "页面头部",
      "orders": 0,
      "surveyQuestionValue": "{\"label\":\"页面头部\",\"isShow\":true,\"textTip\":\"页面头部\"}"
    }, {
      "surveyQuestionTypeId": "personalAuthUpload",
      "question": "personalAuthUpload",
      "surveyQuestionCategoryName": "页面元素",
      "description": "个人认证上传图片",
      "surveyQuestionTypeName": "个人认证上传图片",
      "orders": 1,
      "surveyQuestionValue": "{\"label\":\"个人认证上传图片\",\"isShow\":true,\"textTip\":\"个人认证上传图片\"}"
    }, {
      "surveyQuestionTypeId": "personalAuthForm",
      "question": "personalAuthForm",
      "surveyQuestionCategoryName": "页面元素",
      "description": "个人认证表单",
      "surveyQuestionTypeName": "个人认证表单",
      "orders": 2,
      "surveyQuestionValue": "{\"label\":\"个人认证表单\",\"isShow\":true,\"textTip\":\"个人认证表单\"}",
    }, 
    {
      "surveyQuestionTypeId": "pageFooterButton",
      "question": "pageFooterButton",
      "surveyQuestionCategoryName": "页面元素",
      "description": "页面底部按钮",
      "surveyQuestionTypeName": "页面底部按钮",
      "orders": 2,
      "surveyQuestionValue": "{\"label\":\"页面底部按钮\",\"isShow\":true,\"textTip\":\"页面底部按钮\"}",
    },
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    personal-auth-form.vue

    <template>
      <maskOpt :isEdit="isEdit" @goItemEdit="goEdit" v-bind="$attrs" v-on="$listeners">
        <div class="personal-auth-form">
          <div class="identCardContainer">
            <div class="tips">身份信息div>
            <van-button size="small" color="linear-gradient(to right, #ccc, #ccc)" v-if="btnStatus==0"
              @click="switchBtn('1')">
              手动输入van-button>
            <van-button size="small" color="linear-gradient(to right, #ccc, #ccc)" v-else @click="switchBtn('0')">
              自动识别
            van-button>
          div>
          <div class="formContainer">
            <van-form  ref="form" class="">
              <van-field class="top-radius" v-model="personInfo.fullName" name="fullName" input-align="left" label="姓名"
                :readonly="btnStatus==1?false:true" :rules="[{ required: true ,message: '请填写姓名' }]" />
              <van-field class="top-radius" v-model="personInfo.idCard" name="idCard" input-align="left" label="身份证号"
                :readonly="btnStatus==1?false:true" :rules="[{ required: true ,message: '请填写身份证号'}]" />
              <van-field class="top-radius" v-model="personInfo.issuingAuthority" name="issuingAuthority" input-align="left"
                :readonly="btnStatus==1?false:true" label="签发机关" :rules="[{ required: true ,message: '请填写签发机关'}]" />
              <van-field clickable input-align="left" name="validDate" :value="personInfo.validDate" label="有效日期"
                :readonly="btnStatus==1?false:true" @click="choiceDateRange"
                :rules="[{ required: true,message: '请填写有效日期' }]" />
              <van-field class="top-radius" v-model="personInfo.gender" name="gender" input-align="left" label="性别"
                :readonly="btnStatus==1?false:true" clickable @click="choiceGender"
                :rules="[{ required: true,message: '请填写性别' }]" />
              <van-field class="top-radius" v-model="personInfo.nationality" name="nationality" input-align="left"
                label="民族" :readonly="btnStatus==1?false:true" clickable @click="choiceNation"
                :rules="[{ required: true,message: '请填写民族' }]" />
              <van-field class="top-radius" v-model="personInfo.address" name="address" type="textarea" autosize rows="1"
                :readonly="btnStatus==1?false:true" input-align="left" label="住址" maxlength="100"
                :rules="[{ required: true,message: '请填写住址' }]" />
              
            van-form>
          div>
          <pickerPopup ref="PickerPopup" :dataList="columns" :themeCode="themeCode" :value="personInfo.gender" :title="'性别'"
            @checkedOneItem="onConfirmGender" />
          <pickerPopup ref="PickerPopupNation" :dataList="columnsNation" :themeCode="themeCode"
            :value="personInfo.nationality" :title="'民族'" @checkedOneItem="onConfirmNation" />
          <calendarRange :isShow="showDateRange" :isPastTime="false" @onCancel="onCancel" v-model="calendar"
            @onSubmit="onSubmitcalendarRang" />
        div>
      maskOpt>
    template>
    
    <script>
    import { stringify } from 'querystring';
    
    
    export default {
      name: 'personalAuthForm',
      data() {
        return {
          btnStatusText: "手动输入",
          buttonText: [{
            text: "自动识别",
            value: "personalAuthUpload",
            status: false
          }, {
            text: "手动输入",
            value: null,
            status: true
          }],
          isEdit: false,
          showDateRange: false,
          calendar: {
            startTime: '',
            endTime: '',
            focusFlag: true,
          },
          personInfo: {
            fullName: '', // 身份证姓名
            idCard: '', // 身份证号码
            issuingAuthority: '', // 签发机关
            address: '',
            gender: '', // 1/男,2/女
            nationality: '',
            validDate: '',
          },
          endDate: '', // 到期时间
          startDate: '',
          readonly: true,
          showPicker: false,
          showPickerNation: false,
          columns: ['男', '女'],
          columnsNation: [
            '汉',
            '壮',
            '满',
            '回',
            '苗',
            '维吾尔',
            '土家',
            '彝',
            '蒙古',
            '藏',
            '布依',
            '侗',
            '瑶',
            '朝鲜',
            '白',
            '哈尼',
            '哈萨克',
            '黎',
            '傣',
            '畲',
            '傈僳',
            '仡佬',
            '东乡',
            '高山',
            '拉祜',
            '水',
            '佤',
            '纳西',
            '羌',
            '土',
            '仫佬',
            '锡伯',
            '柯尔克孜',
            '达斡尔',
            '景颇',
            '毛南',
            '撒拉',
            '布朗',
            '塔吉克',
            '阿昌',
            '普米',
            '鄂温克',
            '怒',
            '京',
            '基诺',
            '德昂',
            '保安',
            '俄罗斯',
            '裕固',
            '乌孜别克',
            '门巴',
            '鄂伦春',
            '独龙',
            '塔塔尔',
            '赫哲',
            '珞巴'
          ],
        };
      },
      props: {
        themeCode: {
          type: String,
          default: '',
        },
        btnStatus: {
          type: String,
          default: 0
        }
      },
      watch: {
        personInfo: {
          handler() {
            this.checkForm()
          },
          deep: true,
        }
      },
      components: {
      },
      created() {
      },
    
      methods: {
        switchBtn(val) {
          this.$emit("switchCompentsFn", val)
        },
        goEdit() { },
        choiceDateRange() {
          if (this.readonly) {
            this.showDateRange = true
          }
        },
        choiceGender() {
          if (this.readonly) {
            this.$refs.PickerPopup.showPicker = true
          }
        },
        choiceNation() {
          if (this.readonly) {
            this.$refs.PickerPopupNation.showPicker = true
          }
        },
        onConfirmGender(value) {
          this.personInfo.gender = value;
        },
        onConfirmNation(value) {
          this.personInfo.nationality = value;
        },
        checkForm() {
          let disabled = false
          for (let key in this.personInfo) {
            if (!this.personInfo[key]) {
              disabled = true
              break
            }
          }
          this.$emit('checkForm', disabled)
        },
        onCancel() {
          this.showDateRange = false
        },
        onSubmitcalendarRang() {
          this.startDate = this.calendar.startTime
          this.endDate = this.calendar.endTime
          this.personInfo.validDate = this.calendar.startTime.replace(/\//g, '.') + '-' + this.calendar.endTime.replace(/\//g, '.')
          this.showDateRange = false
        },
      }
    };
    script>
    
    <style scoped lang="scss">
    .formContainer {
      padding-bottom: 60px;
    }
    
    .footer-button {
      width: 93%;
      background-color: #fff;
      text-align: center;
      position: fixed;
      bottom: 0;
    }
    
    .identCardContainer {
      display: flex;
      padding-right: 10px;
    
      button {
        margin-top: 10px;
        margin-left: auto;
      }
    }
    
    .personal-auth-form {
      margin: 12px;
      background-color: #fff;
      overflow: hidden;
      border-radius: 4px;
    
      .tips {
        font-size: 16px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #333333;
        line-height: 22px;
        margin: 13px 12px;
      }
    
      .hiddenInp {
        display: none;
      }
    
      /deep/ .van-cell {
        font-size: 14px;
        padding: 14px 12px;
        line-height: 20px;
      }
    
      /deep/ .van-field__label {
        color: #666666;
      }
    
      /deep/ .van-field__value {
        color: #333333;
      }
    
      /deep/ .van-cell::after {
        border-bottom: 1px solid #F4F5F6;
      }
    }
    style>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
  • 相关阅读:
    Java生成World,Java操作world,Java导出world文档
    云原生之DevOps
    APICloud前端框架
    搞定面试官 - 可以介绍一下在 MySQL 中你平时是怎么使用 COUNT() 的嘛?
    List分页插件
    SpringBoot试题及答案(第一章)
    【Python百日进阶-WEB开发-冲進Flask】Day182 - Flask蓝图与模板继承
    minikube部署K8s命令
    兼顾省钱与性能的存储资源盘活系统
    STL 中给 vector 去重的三种方法
  • 原文地址:https://blog.csdn.net/qq_41820930/article/details/127441386