cshenfu
2024-06-27 58aa6e282bb343503be3cb198948328ea3ed7b79
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
285
286
287
<script>
    import config from '@/app.config.js'
    import util from '@/utils/util.js'
    import checkUpdate from "./uni_modules/uni-upgrade-center-app/utils/check-update"
    var that
    export default {
        methods: {
            //微信网页登录
            mpLogin() {
                //存在openid了 就不再走下面流程
                if (getApp().globalData.openid)
                    return
                uni.removeStorageSync("openid")
                //是微信网页打开 且 未登录
                let mpConfig = getApp().globalData.mpWeixinConfig
                if (util.isWechat() && mpConfig.enabled) {
                    //参数中不带code 不是回调 拦截 准备登录
                    if (window.location.href.indexOf('?code=') == -1 && window.location.href.indexOf('&code=') == -1) {
                        window.location.href =
                            'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
                            mpConfig.appid +
                            '&redirect_uri=' +
                            window.location.href.split('#')[0] +
                            '&response_type=code&scope=snsapi_base#wechat_redirect';
                    } else {
                        let code;
                        if (window.location.href.indexOf('?code=') !== -1) {
                            code = window.location.href.split('?code=')[1].split('&')[0];
                        } else {
                            code = window.location.href.split('&code=')[1].split('&')[0];
                        }
                        if (!uni.vk.callFunctionUtil.checkToken()) {
                            //处理code 自动登录
                            uni.vk.callFunction({
                                url: "user/pub/loginByWeixin",
                                data: {
                                    code: code
                                },
                                success(data) {
                                    uni.setStorageSync("openid", data.userInfo.wx_openid.h5)
                                    that.globalData.openid = data.userInfo.wx_openid.h5
                                    uni.switchTab({
                                        url: "/pages/index/homePage"
                                    })
                                }
                            })
                        } else {
                            //存储openid 用于登录
                            vkUtil.getH5Openid(code).then((res) => {
                                uni.setStorageSync("openid", res.openid)
                                that.globalData.openid = res.openid
                            });
                        }
                    }
                }
            }
        },
        // 监听 - 页面404
        onPageNotFound: function(e) {
            uni.redirectTo({ url: config.error.url })
        },
        onLaunch: function(e) {
            that = this;
 
            uni.vk.callFunctionUtil.updateRequestGlobalParam({
                "platform": {
                    regExp: "^client/",
                    data: {
                        platform: "h5",
                        runtime: util.platform(),
                        is_ios: util.isIosApp
                    }
                }
            });
 
            //用户中微信心登录时受此影响 需要单独配置
            uni.vk.callFunctionUtil.updateRequestGlobalParam({
                "platform": {
                    regExp: "^user/",
                    data: {
                        platform: util.getWeiXinLoginPlatfo(),
                        runtime: util.platform(),
                        is_ios: util.isIosApp
                    }
                }
            });
 
            //获取系统配置
            uni.vk.callFunction({
                url: 'client/app/pub/init',
                success(data) {
                    getApp().globalData.appConfig = data.data.appConfig
                    getApp().globalData.mpWeixinConfig = data.data.mpWeixinConfig
                    uni.vk.setVuex('$app.vipRole', data.data.vipRole);
                    that.mpLogin()
                }
            });
 
            //获取个人资料
            if (uni.vk.callFunctionUtil.checkToken()) {
                uni.vk.callFunction({
                    url: 'user/kh/getMyUserInfo',
                    success(data) {
                        getApp().globalData.userInfo = data.userInfo
                    }
                });
            }
 
            // #ifdef APP-PLUS
            //检查版本更新
            checkUpdate()
            //idfa有需要的用户在应用首次启动时自己获取存储到storage中
            //https://ask.dcloud.net.cn/article/36107
            /*if(~plus.storage.getItem('idfa')){
                plus.device.getInfo({//需要勾选IDFA
                    success:function(e){  
                        console.log('idfa =  '+JSON.stringify(e.idfa));  
                    },
                    fail:function(e){
                        console.log('getDeviceInfo failed: '+JSON.stringify(e));  
                    }  
                });
            }*/
            // #endif
            // #ifdef APP-PLUS
            uni.$on("upDataClientId", res => {
                console.log(plus.push.getClientInfo().clientid);
                this.vk.userCenter.updateUser({
                    data: {
                        clientid: plus.push.getClientInfo().clientid
                    },
                    success: function(data) {}
                });
            })
 
            //监听push推送通知
            plus.push.addEventListener('receive', ({
                type,
                title,
                content,
                payload
            }) => {
                // 点赞时我的显示角标
                if (payload.type == 'like' || payload.type == 'talk') {
                    uni.showTabBarRedDot({ index: 3 })
                    // 通知
                }
                //如果type!='receive'是自己本地插件的push消息栏,“拦截”避免死循环',安卓系统没有这个问题
                if (type == 'receive' || uni.getSystemInfoSync().platform != "ios") {
                    plus.push.createMessage(content, JSON.stringify(payload), {
                        title: payload.title,
                        subtitle: payload.content
                    });
                }
            });
            //监听点击通知栏
            plus.push.addEventListener('click', (e) => {
                if (typeof e.payload != 'object') e.payload = JSON.parse(e.payload);
                console.log(e.payload)
                // 点赞信息
                if (e.payload.type == 'like' || e.payload.type == 'talk') {
                    uni.switchTab({ url: '/pages/mine/index' })
                    return
                }
            });
            // #endif
        },
        globalData: {
            openid: undefined,
            appConfig: {},
            userInfo: {},
            userVipRole: []
        }
    }
</script>
 
<style lang="scss">
    /* #ifndef APP-NVUE */
    /*每个页面公共css */
    @import "uview-ui/index.scss";
 
    .nav-slot-wrap-title {
        font-size: 44rpx;
        font-weight: 500;
        color: #FFFFFF;
        font-family: PingFangSC-Medium, PingFang SC;
        margin-left: 24rpx;
        letter-spacing: 7rpx;
    }
 
    .nav-slot-wrap-title-black {
        color: #333333;
    }
 
    .loadmore {
        width: 100%;
        height: auto;
        padding-top: 15px;
        padding-bottom: 15px;
    }
 
    /************************************************************
    ** 请将全局样式拷贝到项目的全局 CSS 文件或者当前页面的顶部 **
    ** 否则页面将无法正常显示                                  **
    ************************************************************/
 
    html {
        font-size: 16px;
    }
 
    body {
        margin: 0;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
            'Droid Sans', 'Helvetica Neue', 'Microsoft Yahei', sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
 
    view,
    image,
    text {
        box-sizing: border-box;
        flex-shrink: 0;
    }
 
    #app {
        width: 100vw;
        height: 100vh;
    }
 
    .flex-row {
        display: flex;
        flex-direction: row;
    }
 
    .flex-col {
        display: flex;
        flex-direction: column;
    }
 
    .justify-start {
        display: flex;
        justify-content: flex-start;
    }
 
    .justify-center {
        display: flex;
        justify-content: center;
    }
 
    .justify-end {
        display: flex;
        justify-content: flex-end;
    }
 
    .justify-evenly {
        display: flex;
        justify-content: space-evenly;
    }
 
    .justify-around {
        display: flex;
        justify-content: space-around;
    }
 
    .justify-between {
        display: flex;
        justify-content: space-between;
    }
 
    .items-start {
        display: flex;
        align-items: flex-start;
    }
 
    .items-center {
        display: flex;
        align-items: center;
    }
 
    .items-end {
        display: flex;
        align-items: flex-end;
    }
 
    /* #endif */
</style>