wzp
2022-02-22 46083a2914a62c1835612fb0872d7fdc76d7bb9d
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
<!-- 资产报修 -->
<template>
    <view>
        <view class="">
            <cu-custom bgColor="bg-gradual-blue" :isBack="true">
                <block slot="backText">返回</block>
                <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> -->
        
        <view class="btnBox">
            <button type="primary" @click="getWxConfig">点击扫一扫</button>
        </view>
    </view>
</template>
 
<script>
    import permision from "@/common/permission.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);
                            wx.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接口列表,凡是要调用的接口都需要传进来
                            });
                            
                            wx.ready(function(){
                                // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,
                                //config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
                                wx.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 => {
                        console.log(err.data)
                    })
            },
            
        }
    }
</script>
 
<style lang="scss">
    .btnBox{
        height: 50vh;
        display: flex;
        align-items: center;
        justify-content: center;
    }
</style>