绿满眶商城微信小程序-uniapp
xiangpei
6 天以前 70738d032bd80f5b13075f8a13045ff4de57c2c3
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
<script>
    /**
     * vuex管理登录状态,具体可以参考官方登录模板示例
     */
    import config from "@/config/config";
import {
    getClipboardData
} from "@/js_sdk/h5-copy/h5-copy.js";
import APPUpdate from "@/plugins/APPUpdate";
import storage from "@/utils/storage";
import {
    mapMutations
} from "vuex";
 
    
    
    /**
     * 路由监听并删除路由
     * https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html
     * */
    // #ifdef MP-WEIXIN
    wx.onAppRoute((res) => {
        
    })
    // #endif
 
    export default {
        data() {
            return {
                config,
            };
        },
 
 
        /**
         * 监听返回
         */
        onBackPress(e) {
            console.log("onBackPress-APP", e);
            if (e.from == "backbutton") {
                let routes = getCurrentPages();
                let curRoute = routes[routes.length - 1].options;
                routes.forEach((item) => {
                    if (
                        item.route == "pages/tabbar/cart/cartList" ||
                        item.route.indexOf("pages/product/goods") != -1
                    ) {
                        uni.redirectTo({
                            url: item.route,
                        });
                    }
                });
 
                if (curRoute.addId) {
                    uni.reLaunch({
                        url: "/pages/tabbar/cart/cartList",
                    });
                } else {
                    uni.navigateBack();
                }
                return true; //阻止默认返回行为
            }
        },
        methods: {
            ...mapMutations(["login"]),
        },
        onLaunch: function() {
            // #ifdef APP-PLUS
            this.checkArguments(); // 检测启动参数
            APPUpdate();
 
            // 重点是以下: 一定要监听后台恢复 !一定要
            plus.globalEvent.addEventListener("newintent", (e) => {
                this.checkArguments(); // 检测启动参数
            });
            // #endif
 
            // #ifdef MP-WEIXIN
            this.applyUpdateWeChat();
            // #endif
        },
 
        onShow() {
            // #ifndef H5
            if(this.config.enableGetClipboard){
                this.getClipboard();
            }
            // #endif
            // #ifdef APP-PLUS
 
            if (storage.getShow()) {
                if (uni.getSystemInfoSync().platform == 'ios') {
                    this.$u.route("/pages/tabbar/screen/fullScreen");
 
                }
            }
            // #endif
        },
        methods: {
            /**
             * 微信小程序版本提交更新版本 解决缓存问题
             */
            applyUpdateWeChat() {
                const updateManager = uni.getUpdateManager();
 
                updateManager.onCheckForUpdate(function(res) {
                    // 请求完新版本信息的回调
                });
 
                updateManager.onUpdateReady(function(res) {
                    uni.showModal({
                        title: "更新提示",
                        content: "发现新版本,是否重启应用?",
                        success(res) {
                            if (res.confirm) {
                                // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                                updateManager.applyUpdate();
                            }
                        },
                    });
                });
                updateManager.onUpdateFailed(function(res) {
                    // 新的版本下载失败
                });
            },
 
            //  TODO 开屏广告 后续优化添加
            launch() {
                try {
                    // 获取本地存储中launchFlag标识 开屏广告
                    const value = uni.getStorageSync("launchFlag");
                    if (!value) {
                        // this.$u.route("/pages/index/agreement");
                    } else {
                        //app启动时打开启动广告页
                        var w = plus.webview.open(
                            "/hybrid/html/advertise/advertise.html",
                            "本地地址", {
                                top: 0,
                                bottom: 0,
                                zindex: 999,
                            },
                            "fade-in",
                            500
                        );
                        //设置定时器,4s后关闭启动广告页
                        setTimeout(function() {
                            plus.webview.close(w);
                            APPUpdate();
                        }, 3000);
                    }
                } catch (e) {
                    // error
                    uni.setStorage({
                        key: "launchFlag",
                        data: true,
                        success: function() {
                            console.log("error时存储launchFlag");
                        },
                    });
                }
            },
 
            /**
             * 获取粘贴板数据
             */
            async getClipboard() {
                let res = await getClipboardData();
 
                /**
                 * 解析粘贴板数据
                 */
 
                if (res.indexOf(config.shareLink) != -1 && (res != this.$store.state.shareLink)) {
                    this.$store.state.shareLink = res
                    uni.showModal({
                        title: "提示",
                        content: "检测到一个分享链接是否跳转?",
                        confirmText: "跳转",
                        success: function(callback) {
                            if (callback.confirm) {
                                const path = res.split(config.shareLink)[1];
                                if (path.indexOf("tabbar") != -1) {
                                    uni.switchTab({
                                        url: path,
                                    });
                                } else {
                                    uni.navigateTo({
                                        url: path,
                                    });
                                }
                            }
                        },
                    });
                }
            },
 
            /**
             * h5中打开app获取跳转app的链接并跳转
             */
            checkArguments() {
                // #ifdef APP-PLUS
                setTimeout(() => {
                    const args = plus.runtime.arguments;
                    if (args) {
                        const argsStr = decodeURIComponent(args);
                        const path = argsStr.split("//")[1];
                        if (path.indexOf("tabbar") != -1) {
                            uni.switchTab({
                                url: `/${path}`,
                            });
                        } else {
                            uni.navigateTo({
                                url: `/${path}`,
                            });
                        }
                    }
                });
                // #endif
            },
        },
    };
</script>
 
<style lang="scss">
    @import '@/components/uview-components/uview-ui/index.scss';
 
    // -------适配底部安全区  苹果x系列刘海屏
 
    // #ifdef MP-WEIXIN
    .mp-iphonex-bottom {
        padding-bottom: constant(safe-area-inset-bottom);
        padding-bottom: env(safe-area-inset-bottom);
        box-sizing: content-box;
        height: auto !important;
        padding-top: 10rpx;
    }
 
    // #endif
 
    body {
        background-color: $bg-color;
    }
 
    /************************ */
    .w200 {
        width: 200rpx !important;
    }
 
    .flex1 {
        flex: 1; //必须父级设置flex
    }
    
    /* 在线链接服务仅供平台体验和调试使用,平台不承诺服务的稳定性,企业客户需下载字体包自行发布使用并做好备份。 */
    @font-face {
      font-family: 'iconfont';  /* Project id 4921691 */
      src: 
           url('//at.alicdn.com/t/c/font_4921691_3vdxatwdwe9.woff2?t=1750062394172') format('woff2'),
           url('//at.alicdn.com/t/c/font_4921691_3vdxatwdwe9.woff?t=1750062394172') format('woff'),
           url('//at.alicdn.com/t/c/font_4921691_3vdxatwdwe9.ttf?t=1750062394172') format('truetype');
    }
    .iconfont {
          /* font-family需要和自定义的相同 */
           font-family: "iconfont" !important;
           font-size: 2em;
           font-style: normal;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }
</style>