wzp
2022-11-21 f29dfb68a705ab9f37ed924fc82d6fd414c1c78c
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
<template>
    <view>
        <u-toast ref="uToast"></u-toast>
 
        <view class="" v-if="loginFlag">
            登陆异常:{{loginText}}
        </view>
        
        <view class="text-xl" v-if="workFlag">
            请使用企业微信客户端扫码打开!
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                loginFlag: false,
                loginText: "",
                workFlag:false,
                
                code: 0,
                state: 0,
                status: "0",
                flag: true,
                number: "",
                number2: ""
            }
        },
        async onLoad(options) {
            try {
                //http://asset.mengdong.icu/h5/?status=1&number=6688898
                this.status = options.status;
                console.log('status=' + this.status);
                if (this.status === "1") {
                    this.number = options.number;
                    this.flag = false
                    this.navToCode();
                }
            } catch (e) {
 
            }
 
            if (this.flag) {
                this.code = options.code;
                this.state = options.state;
 
                await this.login(this.code);
 
                if (!this.loginFlag) {
                    await this.getUserInfo();
                    let json = this.state.split("^");
 
                    if (json[0] === "share") {
                        this.number = json[1];
                        setTimeout(() => {
                            this.navToShare();
                        }, 0)
                    } else {
                        this.navTo();
                    }
                }
 
 
 
            }
 
        },
        methods: {
            navTo() {
                uni.switchTab({
                    url: "../index/index?state=" + this.state
                })
            },
            navToShare() {
                uni.reLaunch({
                    url: "../assets/repairInfo?number=" + this.number
                })
            },
 
            navToCode() {
                
                var ua = window.navigator.userAgent.toLowerCase();
                if ((ua.match(/MicroMessenger/i) == 'micromessenger') && (ua.match(/wxwork/i) == 'wxwork')) {
                    //生产
                    window.location.href =`http://open.weixin.qq.com/connect/oauth2/authorize?appid=ww9516eee214a997e5&redirect_uri=http://uat.zhongyishutong.xyz/h5/&response_type=code&state=share^${this.number}&scope=snsapi_userinfo@asset#wechat_redirect`;
                    
                    //测试
                    // window.location.href =`http://open.weixin.qq.com/connect/oauth2/authorize?appid=wwb3c45e4348576dc2&redirect_uri=http://asset.mengdong.icu/h5/&response_type=code&state=share^${this.number}&scope=snsapi_userinfo@asset#wechat_redirect`;
                } else if (ua.match(/micromessenger/i) == 'micromessenger') {
                    this.workFlag=true;
                }
 
            },
 
            //登陆
            async login(code) {
                await this.$http.get('/h5login', {
                        params: {
                            code: code
                        }
                    })
                    .then(res => {
                        // debugger;
                        console.log(res.data)
                        if (res.data.code === 0) {
                            // this.$refs.uToast.show({
                            //     type: 'success',
                            //     message: "登陆成功"
                            // });
 
                            this.token = res.data.token;
                            console.log('token=' + this.token);
                            this.value1 = this.token;
                            uni.setStorageSync('token', this.token);
                        } else {
                            this.loginFlag = true;
                            this.loginText = res.data.msg;
                        }
 
                    }).catch(err => {
                        this.loginFlag = true;
                        this.loginText = '异常' + err;
                        console.log('错误', err.data)
                    })
            },
 
            async getUserInfo() {
                await this.$http.get('/assets/approval/getUserDetail')
                    .then(res => {
                        // debugger;
                        if (res.data.code === 0) {
                            let data = res.data.data;
                            uni.setStorageSync('user', data);
                            console.log('姓名:' + data.userName)
                            console.log('user=', data)
                        }
                    }).catch(err => {
                        console.log('错误', err.data)
                    })
            },
        }
    }
</script>
 
<style>
 
</style>