quanwei
13 hours ago 408c463c5b66bba2aa1c81d8dca23e04c1608e24
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
import Vue from 'vue'
 
import App from './App'
import directive from './common/directive.js'
import utils from './common/utils.js'
import config from './config.js'
import onfire from './common/onfire.js'
import {
    gotopage
} from '@/common/gotopage.js'
 
/* Vuex */
import store from "./store/index.js"
Vue.prototype.$store = store;
 
// 公共组件
import headerBar from './components/header.vue'
Vue.component('header-bar', headerBar)
 
/* 从服务器获取的图片(减少小程序端体积) by lyzflash */
import {
    remoteimg
} from '@/common/remoteimg.js'
 
//请求加载组件
import requestLoading from './components/jjjloading.vue';
 
//组件挂载到全局,方便每个页面使用
Vue.component('request-loading', requestLoading);
 
/*底部数据*/
import tabBar from "@/components/tabbar/footTabbar.vue"
Vue.component('tabBar', tabBar)
Vue.prototype.footTabberData = {
    active: 'home'
};
 
/*底部数据*/
import shopTabBar from "@/components/shoptabbar/footTabbar.vue"
Vue.component('shopTabBar', shopTabBar)
Vue.prototype.shopFootTabberData = {
    active: 'home'
};
Vue.prototype.$fire = new onfire()
 
Vue.config.productionTip = false
 
App.mpType = 'app'
 
Vue.prototype.config = config
 
const app = new Vue({
    ...App
})
app.$mount()
 
 
 
Vue.prototype.websiteUrl = config.app_url;
Vue.prototype.app_id = config.app_id;
//h5发布路径
Vue.prototype.h5_addr = config.h5_addr;
/*页面跳转*/
Vue.prototype.gotoPage = gotopage;
Vue.prototype.font_url = config.font_url;
/* 从服务器获取的图片(减少小程序端体积) by lyzflash */
Vue.prototype.remoteImg = remoteimg;
 
Vue.prototype.points_name = function(e) {
    if(!e){
        return store.state.points_name;
    }else{
        let re = new RegExp("积分","g"); 
        return e.replace(re, store.state.points_name);
    }
    
}
Vue.prototype.consumption_name = function(e) {
    if(!e){
        return store.state.consumption_name;
    }else{
        let re = new RegExp("消费券","g"); 
        return e.replace(re, store.state.consumption_name);
    }
    
}
//#ifdef H5
app.$router.afterEach((to, from) => {
    const u = navigator.userAgent.toLowerCase();
    if (u.indexOf("like mac os x") < 0 || u.match(/MicroMessenger/i) != 'micromessenger') return;
    if (to.path !== global.location.pathname) {
        location.assign(config.app_url + config.h5_addr + to.fullPath);
    }
})
//#endif
 
 
//是否是ios
Vue.prototype.ios = function() {
    const u = navigator.userAgent.toLowerCase();
    if (u.indexOf("like mac os x") < 0 || u.match(/MicroMessenger/i) != 'micromessenger') {
        return false;
    }
    return true;
};
 
//get请求
Vue.prototype._get = function(path, data, success, fail, complete) {
    data = data || {};
    data.token = uni.getStorageSync('token') || '';
    data.app_id = this.getAppId();
    uni.request({
        url: this.websiteUrl + '/index.php/api/' + path,
        data: data,
        dataType: 'json',
        method: 'GET',
        success: (res) => {
            if (res.statusCode !== 200 || typeof res.data !== 'object') {
                return false;
            }
            if (res.data.code === -2) {
                this.showError(res.data.msg, function() {
                    uni.removeStorageSync('token');
                    this.gotoPage('/pages/index/index', 'reLaunch');
                })
            } else if (res.data.code === -1) {
                // 登录态失效, 重新登录
                console.log('登录态失效, 重新登录');
                this.doLogin();
            } else if (res.data.code === 0) {
                this.showError(res.data.msg, function() {
                    fail && fail(res);
                });
                return false;
            } else {
                success && success(res.data);
            }
        },
        fail: (res) => {
            fail && fail(res);
        },
        complete: (res) => {
            uni.hideLoading();
            complete && complete(res);
        },
    });
};
 
//get请求
Vue.prototype._post = function(path, data, success, fail, complete) {
    data = data || {};
    data.token = uni.getStorageSync('token') || '';
    data.app_id = this.getAppId();
    uni.request({
        url: this.websiteUrl + '/index.php/api/' + path,
        data: data,
        dataType: 'json',
        method: 'POST',
        header: {
            'content-type': 'application/x-www-form-urlencoded',
        },
        success: (res) => {
            if (res.statusCode !== 200 || typeof res.data !== 'object') {
                return false;
            }
            if (res.data.code === -1) {
                // 登录态失效, 重新登录
                console.log('登录态失效, 重新登录');
                this.doLogin();
            } else if (res.data.code === 0) {
                this.showError(res.data.msg, function() {
                    fail && fail(res);
                });
                return false;
            } else {
                success && success(res.data);
            }
        },
        fail: (res) => {
            fail && fail(res);
        },
        complete: (res) => {
            uni.hideLoading();
            complete && complete(res);
        },
    });
};
 
Vue.prototype.doLogin = function() {
    let pages = getCurrentPages();
    if (pages.length) {
        let currentPage = pages[pages.length - 1];
        if ("pages/login/login" != currentPage.route &&
            "pages/login/weblogin" != currentPage.route &&
            "pages/login/openlogin" != currentPage.route) {
            uni.setStorageSync("currentPage", currentPage.route);
            uni.setStorageSync("currentPageOptions", currentPage.options);
        }
    }
    console.log('app_ID=' + this.getAppId())
    //公众号
    // #ifdef  H5
    console.log(this)
    if (this.isWeixin()) {
        window.location.href = this.websiteUrl + '/index.php/api/user.usermp/login?app_id=' + this.getAppId() +
            '&referee_id=' + uni.getStorageSync('referee_id');
    } else {
        this.gotoPage("/pages/login/weblogin");
    }
    // #endif
    // #ifdef APP-PLUS
    this.gotoPage("/pages/login/openlogin", 'redirect');
    return;
    // #endif
    // 非公众号,跳转授权页面
    // #ifndef  H5
    this.gotoPage("/pages/login/login");
    // #endif
};
 
 
/**
 * 显示失败提示框
 */
Vue.prototype.showError = function(msg, callback) {
    uni.showModal({
        title: '友情提示',
        content: msg,
        showCancel: false,
        success: function(res) {
            callback && callback();
        }
    });
};
 
/**
 * 显示失败提示框
 */
Vue.prototype.showSuccess = function(msg, callback) {
    uni.showModal({
        title: '友情提示',
        content: msg,
        showCancel: false,
        success: function(res) {
            callback && callback();
        }
    });
};
 
/**
 * 获取应用ID
 */
Vue.prototype.getAppId = function() {
    return this.app_id || 10001;
};
 
Vue.prototype.compareVersion = function(v1, v2) {
    v1 = v1.split('.')
    v2 = v2.split('.')
    const len = Math.max(v1.length, v2.length)
 
    while (v1.length < len) {
        v1.push('0')
    }
    while (v2.length < len) {
        v2.push('0')
    }
 
    for (let i = 0; i < len; i++) {
        const num1 = parseInt(v1[i])
        const num2 = parseInt(v2[i])
 
        if (num1 > num2) {
            return 1
        } else if (num1 < num2) {
            return -1
        }
    }
 
    return 0
};
 
 
/**
 * 生成转发的url参数
 */
Vue.prototype.getShareUrlParams = function(params) {
    let self = this;
    return utils.urlEncode(Object.assign({
        referee_id: self.getUserId(),
        app_id: self.getAppId()
    }, params));
};
 
/**
 * 当前用户id
 */
Vue.prototype.getUserId = function() {
    return uni.getStorageSync('user_id');
};
 
//#ifdef H5
var jweixin = require('jweixin-module');
 
Vue.prototype.configWx = function(signPackage, shareParams, params) {
    if (signPackage == '') {
        return;
    }
    let self = this;
    jweixin.config(JSON.parse(signPackage));
 
    let url_params = self.getShareUrlParams(params);
 
    jweixin.ready(function(res) {
        jweixin.updateAppMessageShareData({
            title: shareParams.title,
            desc: shareParams.desc,
            link: self.websiteUrl + self.h5_addr + shareParams.link + '?' + url_params,
            imgUrl: shareParams.imgUrl,
            success: function() {
 
            }
        });
        jweixin.updateTimelineShareData({
            title: shareParams.title,
            desc: shareParams.desc,
            link: self.websiteUrl + self.h5_addr + shareParams.link + '?' + url_params,
            imgUrl: shareParams.imgUrl,
            success: function() {
 
            }
        });
    });
};
 
Vue.prototype.configWxScan = function(signPackage) {
    if (signPackage == '') {
        return;
    }
    jweixin.config(JSON.parse(signPackage));
    return jweixin;
};
//#endif
 
/**
 * 获取当前平台
 */
Vue.prototype.getPlatform = function(params) {
    let platform = 'wx';
    // #ifdef  APP-PLUS
    if (uni.getSystemInfoSync().platform == 'android') {
        platform = 'android';
    } else {
        platform = 'ios';
    }
    // #endif
    // #ifdef  H5
    if (this.isWeixin()) {
        platform = 'mp';
    } else {
        platform = 'h5';
    }
    // #endif
    return platform;
};
 
/**
 * 订阅通知,目前仅小程序
 */
Vue.prototype.subMessage = function(temlIds, callback) {
    let self = this;
    // #ifdef  MP-WEIXIN
    //小程序订阅消息
    const version = wx.getSystemInfoSync().SDKVersion;
    if (temlIds && temlIds.length != 0 && self.compareVersion(version, '2.8.2') >= 0) {
        wx.requestSubscribeMessage({
            tmplIds: temlIds,
            success(res) {},
            fail(res) {},
            complete(res) {
                callback();
            },
        });
    } else {
        callback();
    }
    // #endif
    // #ifndef MP-WEIXIN
    callback();
    // #endif
};
 
Vue.prototype.isWeixin = function() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
};
 
/**
 * 获取访客
 */
Vue.prototype.getVisitcode = function() {
    let visitcode = uni.getStorageSync('visitcode');
    if (!visitcode) {
        visitcode = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            var r = Math.random() * 16 | 0,
                v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
        visitcode = visitcode.replace(/-/g, "");
        uni.setStorageSync('visitcode', visitcode);
    }
 
    return visitcode;
};
 
Vue.prototype.topBarTop = function() {
    // #ifdef MP-WEIXIN
    return uni.getMenuButtonBoundingClientRect().top;
    // #endif
    // #ifndef MP-WEIXIN
    const SystemInfo = uni.getSystemInfoSync();
    return SystemInfo.statusBarHeight;
    // #endif
};
Vue.prototype.topBarHeight = function() {
    // #ifdef MP-WEIXIN
    return uni.getMenuButtonBoundingClientRect().height;
    // #endif
    // #ifndef MP-WEIXIN
    return 0
    // #endif
};
Vue.prototype.yulan = function(e, i) {
    let image_path_arr = [];
    if (!Array.isArray(e)) {
        image_path_arr = [e];
    } else {
        if (e[0].file_path) {
            e.forEach((item, index) => {
                image_path_arr.push(item.file_path)
            })
        } else {
            image_path_arr = e
        }
    }
    let picnum = i * 1;
    uni.previewImage({
        urls: image_path_arr,
        current: picnum,
        indicator: 'default',
    });
}
Vue.prototype.theme = function() {
    return 'theme' + this.$store.state.theme || ''
}
Vue.prototype.footTab = function() {
    return this.$store.state.footTab || ''
}
/* 小数点截取 */
Vue.prototype.subPrice = function(str, val) {
    let strs = String(str);
    if (val == 1) {
        return strs.substring(0, strs.indexOf("."));
    } else if (val == 2) {
        let indof = strs.indexOf(".");
        return strs.slice(indof + 1, indof + 3);
    }
}
/*转两位数*/
Vue.prototype.convertTwo = function(n) {
    let str = '';
    if (n < 10) {
        str = '0' + n;
    } else {
        str = n;
    }
    return str;
}
Vue.prototype.getTabBarLinks = function() {
    let vars = uni.getStorageSync('TabBar');
    let theme = this.$store.state.theme;
    if (vars.is_auto == '0') {
        uni.showTabBar();
        vars.list = [];
        let color = ['#ff5704', '#19ad57', '#ffcc00', '#1774ff', '#e4e4e4', '#c8ba97',
            '#623ceb'
        ]
        uni.setTabBarStyle({
            color: '#333333',
            selectedColor: color[theme],
        })
        uni.setTabBarItem({
            index: 0,
            text: '首页',
            iconPath: 'static/tabbar/home.png',
            selectedIconPath: 'static/tabbar/home_' + theme + '.png'
        })
        uni.setTabBarItem({
            index: 1,
            text: '分类',
            iconPath: 'static/tabbar/category.png',
            selectedIconPath: 'static/tabbar/category_' + theme + '.png'
        })
        uni.setTabBarItem({
            index: 2,
            text: '店铺',
            iconPath: 'static/tabbar/shop.png',
            selectedIconPath: 'static/tabbar/shop_' + theme + '.png'
        })
        uni.setTabBarItem({
            index: 3,
            text: '购物车',
            iconPath: 'static/tabbar/cart.png',
            selectedIconPath: 'static/tabbar/cart_' + theme + '.png'
        })
        uni.setTabBarItem({
            index: 4,
            text: '我的',
            iconPath: 'static/tabbar/user.png',
            selectedIconPath: 'static/tabbar/user_' + theme + '.png'
        })
    } else {
        uni.hideTabBar();
    }
}
Vue.prototype.getThemeColor = function() {
    let theme = this.$store.state.theme;
    let color = ['#ff5704', '#19ad57', '#ffcc00', '#1774ff', '#e4e4e4', '#c8ba97', '#623ceb'];
    return color[theme]
}