cshenfu
2023-05-19 7bab338c7c5c147b794c7708f0b6755c10d310b0
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
282
283
284
<script>
    
    import {
        mapState,
        mapMutations
    } from 'vuex'
    import setting from "@/common/config";
    export default {
        data() {
            return {
                shar_openid:''
            }
        },
        created() {
            let code = ''
            let open_id2 = this.getURLParams()
            if(open_id2.indexOf("?") != -1){
                var str = open_id2.substr(1);
                var strs = str.split("=");  
                code = strs[1];
                uni.setStorageSync('openid',code);
            }
            this.shar_openid = uni.getStorageSync('openid')
        },
        methods: {
            getURLParams() {
                var url = window.location.href;
                var theRequest = '';
                if (url.indexOf("?") != -1) {
                    theRequest = url
                }else{
                    theRequest = null
                }
                return theRequest
            },
            gzhLogin() {
                // #ifdef H5
                if (/MicroMessenger/i.test(navigator.userAgent) && this.$store.state.config.wxGzhLogin == 1) {
                    const launchOptions = uni.getLaunchOptionsSync()
                    const query = launchOptions.query
                    const token = query.token
                    console.log('url中的token参数:', token)
                    if (token) {
                        this.$store.commit('wxH5SetToken', token);
                        this.$nextTick(() => {
                            // 通过token获取用户信息
                            this.$request('/api/Member/getUserInfo', 'POST').then(res => {
                                console.log(res)
                                if (res.status == 200) {
                                    let uInfo = res.data;
                                    uInfo.token = token;
                                    this.syncUserInfo(uInfo)
                                    uni.setStorageSync('userInfo', uInfo)
                                    uni.setStorageSync('token', token)
                                }
                            })
                        })
                    } else {
                        let rurl = setting.base_url + '/api/Member/wxH5Login?presenter='+this.shar_openid;
                        let url =
                            "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+setting.official_accounts_appid+"&redirect_uri=" +
                            rurl +
                            "&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect"
                        window.location.href = url;
                    }
                }
                // #endif
            },
            async init() {
                var userInfo = uni.getStorageSync('userInfo');
                if (userInfo) {
                    await this.login(userInfo);
                    this.$request('/api/Member/checkNum', 'POST').then(res => {
                        userInfo.num = res.data.num // 更新数量
                        this.syncUserInfo(userInfo)
                    })
                }
                this.$request('/api/Baseconfig/getInfo').then(res => {
                    console.log(res)
                    this.$store.commit('setConfig', res)
                    // #ifdef H5
                    if (!userInfo) {
                        this.gzhLogin()
                    }
                    // #endif
                }).catch(err => {
                    this.$request('/api/Baseconfig/getInfo').then(res => {
                        console.log(res)
                        this.$store.commit('setConfig', res)
                        // #ifdef H5
                        if (!userInfo) {
                            this.gzhLogin()
                        }
                        // #endif
                    })
                })
            },
            ...mapMutations(['login', 'syncUserInfo'])
        },
        onLaunch: function() {
            console.log('App Launch')
 
            this.init()
            /* #ifdef H5 */
            // 接入百度统计
            var bp = document.createElement('script');
            var curProtocol = window.location.protocol.split(':')[0];
            if (curProtocol === 'https') {
                bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
            } else {
                bp.src = 'http://push.zhanzhang.baidu.com/push.js';
            }
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(bp, s);
            /* #endif */
        },
        onShow: function() {
            console.log('App Show')
        },
        onHide: function() {
            console.log('App Hide')
        }
    }
</script>
 
<style>
    /*每个页面公共css */
    @import url("./static/style/icon.css");
</style>
 
<style lang="scss">
    /*每个页面公共css */
    @import "@/uni_modules/uview-ui/index.scss";
 
    .pix_box {
        width: 100vw;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 10000;
    }
 
    .one {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
 
    .two {
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
    }
 
    .pdg {
        width: fit-content;
    }
 
    .a {
        position: relative;
    }
 
    .a image {
        position: absolute;
        width: 100%;
        height: 100%;
    }
 
    .showt {
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.2);
        position: fixed;
        top: 0;
        left: 0;
        z-index: 100000;
        display: flex;
        align-items: center;
        justify-content: center;
    }
 
    .showt_box {
        width: 520rpx;
        background: #FFFFFF;
        border-radius: 24rpx;
        overflow: hidden;
    }
 
    .showt_title {
        font-size: 34rpx;
        font-weight: 500;
        color: #333333;
        padding: 60rpx 30rpx;
        text-align: center;
        margin: auto;
    }
 
    .showt_btn {
        width: 100%;
        height: 88rpx;
        border-top: 1rpx solid rgba(0, 0, 0, 0.12);
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
 
    .showt_btn view {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 30rpx;
        font-weight: 500;
    }
 
    .showt_btnl {
        color: #999999;
        border-right: 1rpx solid rgba(0, 0, 0, 0.12);
        margin-left: -1rpx;
    }
 
    .custom {
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 100000;
    }
 
    .custom_box {
        width: 520rpx;
        background: #FFFFFF;
        border-radius: 24rpx;
    }
 
    .custom_title {
        font-size: 34rpx;
        font-weight: 500;
        color: #333333;
        padding: 60rpx 30rpx;
        line-height: 42rpx;
        text-align: center;
    }
 
    .custom_btn {
        width: 100%;
        height: 88rpx;
        border-top: 1rpx solid rgba(0, 0, 0, 0.12);
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
 
    .custom_btn view {
        width: 50%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 30rpx;
        font-weight: 500;
    }
 
    .custom_btn_l {
        color: #999999;
        margin-left: -1rpx;
        border-right: 1rpx solid rgba(0, 0, 0, 0.12);
    }
 
    .custom_btn_r {
        color: #23A0F0;
    }
</style>