main.js
3.74 KB
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
import Vue from 'vue'
import App from './App'
import store from './store'
// +----------------------------------------------------------------------
// | 组件引入
// +----------------------------------------------------------------------
// 引入全局TuniaoUI
import TuniaoUI from 'tuniao-ui'
Vue.use(TuniaoUI)
// 底部导航栏组件
import tabbar from '@/components/tabbar/tabbar.vue';
Vue.component('tabbar', tabbar);
// 登录框组件
import login from '@/components/login/login.vue';
Vue.component('login', login);
// |______________________________________________________________________
// +----------------------------------------------------------------------
// | 函数引入
// +----------------------------------------------------------------------
// 工具函数
import utils from './common/js/utils';
Vue.prototype.utils = utils;
// 广告函数
import adUtils from './common/js/ad';
Vue.prototype.adUtils = adUtils;
// 应用配置
const app_info = require("@/static/appInfo.js");
Vue.prototype.appInfo = app_info
Vue.config.productionTip = false
// 全局登录事件
Vue.prototype.login = function() {
if (!this.utils.getData('token')) {
this.$refs.login.modal = true
return;
}
}
let api_host = app_info.api_host;
Vue.prototype.imgUrl = api_host
// 统一请求函数
Vue.prototype.http = function(path, data, method = 'post', showLoading = true) {
return utils.http(this, path, data, method, showLoading)
}
// 获取当前页面路径
Vue.prototype.currentPage = function () {
var pages = getCurrentPages() // 获取栈实例
let currentRoute = pages[pages.length-1].route; // 获取当前页面路由
let currentPage = pages[pages.length-1]['$page']['fullPath'] //当前页面路径(带参数)
return currentPage
}
// 正常格式的日期时间
Vue.filter('format_date', function(time) {
const dateTime = new Date(time * 1000);
const YY = dateTime.getFullYear();
const MM =
dateTime.getMonth() + 1 < 10 ?
'0' + (dateTime.getMonth() + 1) :
dateTime.getMonth() + 1;
const D =
dateTime.getDate() < 10 ? '0' + dateTime.getDate() : dateTime.getDate();
const hh =
dateTime.getHours() < 10 ?
'0' + dateTime.getHours() :
dateTime.getHours();
const mm =
dateTime.getMinutes() < 10 ?
'0' + dateTime.getMinutes() :
dateTime.getMinutes();
const ss =
dateTime.getSeconds() < 10 ?
'0' + dateTime.getSeconds() :
dateTime.getSeconds();
return `${YY}-${MM}-${D} ${hh}:${mm}`
});
// 秒转时分秒格式
Vue.filter('format_second', function(second, tips = '不限时') {
if (second == undefined) return ''
if (second == 0) return tips
let result = parseInt(second)
let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
let res = '';
if(h !== '00') res += `${h}时`;
if(m !== '00') res += `${m}分`;
res += `${s}秒`;
return res;
});
// |______________________________________________________________________
// +----------------------------------------------------------------------
// | 全局变量及函数
// +----------------------------------------------------------------------
// 引入TuniaoUI提供的vuex简写方法
let vuexStore = require('@/store/$t.mixin.js')
Vue.mixin(vuexStore)
// 导入并挂载全局的分享方法
import wxShare from '@/common/mixins/share.js'
Vue.mixin(wxShare)
// |______________________________________________________________________
App.mpType = 'app'
const app = new Vue({
store,
...App
})
app.$mount()