wzp
2022-03-08 1f478b4b033d518f6de21f931d828d2a175b2a3e
assetMgtH5/pages/assets/repair.vue
@@ -7,22 +7,105 @@
             <block slot="content">资产报修</block>
         </cu-custom>
      </view>
      <!-- <view class="uni-padding-wrap uni-common-mt">
         <view class="uni-title">扫码结果:</view>
         <view class="uni-list" v-if="result">
            <view class="uni-cell">
               <view class="scan-result">
                  {{result}}
               </view>
            </view>
         </view>
      </view> -->
      <!-- <view>
         url:{{url}}
      </view>
      <view class="">
         <u--textarea v-model="value1" placeholder="请输入内容" ></u--textarea>
      </view> -->
      <u-toast ref="uToast"></u-toast>
      <view class="btnBox">
         <button type="primary" @click="getWxConfig">点击扫一扫</button>
      </view>
   </view>
</template>
<script>
   import permision from "@/common/permission.js"
   const jsWx = require('@/api/jweixin-1.2.0.js')
   export default {
      data() {
         return {
            result:'',
            
         }
      },
      methods: {
         getWxConfig() {
            let wPath = window.document.location.href.split('#')[0];
            // this.url = wPath;
            // let urlStr ="http://localhost:8085/h5/pages/assets/repair";
            console.log(wPath);
             this.$http.get('/assets/approval/getWxConfig',{params:{url:wPath}})
               .then(res => {
                  // debugger;
                  if(res.data.code===0){
                     let data = res.data.data;
                     this.value1 = JSON.stringify(data);
                     jsWx.config({
                         beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
                         debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                         appId: data.appId, // 必填,企业微信的corpID
                         timestamp: data.timestamp, // 必填,生成签名的时间戳
                         nonceStr: data.nonceStr, // 必填,生成签名的随机串
                         signature: data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
                         jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
                     });
                     jsWx.ready(function(){
                         // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,
                        //config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
                        jsWx.scanQRCode({
                            desc: 'scanQRCode desc',
                            needResult: 0, // 默认为0,扫描结果由企业微信处理,1则直接返回扫描结果,
                            scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是条形码(一维码),默认二者都有
                            success: function(res) {
                                // 回调
                              this.result = res.resultStr;//当needResult为1时返回处理结果
                              console.log('结果',this.result)
                            },
                            error: function(res) {
                                if (res.errMsg.indexOf('function_not_exist') > 0) {
                                    alert('版本过低请升级')
                                }
                            }
                        });
                     });
                  }
               }).catch(err => {
                  this.$refs.uToast.show({
                     type: 'error',
                     message: '错误:'+err
                  });
                  console.log(err.data)
               })
         },
         
      }
   }
</script>
<style>
<style lang="scss">
   .btnBox{
      height: 50vh;
      display: flex;
      align-items: center;
      justify-content: center;
   }
</style>