-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
167 lines (166 loc) · 3.58 KB
/
main.js
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
import Vue from 'vue'
import App from './App'
import uView from "uview-ui";
import moment from "moment";
// 引入uView对小程序分享的mixin封装
let mpShare = require('uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare);
Vue.use(uView);
Vue.config.productionTip = false
App.mpType = 'app'
/**
* 分享
*/
Vue.prototype.share = function(title = '', path = '', image = '') {
// 该对象已集成到this.$u中,内部属性如下
this.$u.mpShare = {
title: title == '' ? app.globalData.title : title, // 默认为小程序名称,可自定义
path: path, // 默认为当前页面路径,一般无需修改,QQ小程序不支持
// 分享图标,路径可以是本地文件路径、代码包文件路径或者网络图片路径。
// 支持PNG及JPG,默认为当前页面的截图
imageUrl: image
}
}
/**
* moment.js日期处理类
*/
Vue.prototype.$date = moment();
/**
* \n转成<br/>
*/
Vue.prototype.nl2br = function(str) {
if (str.match(/\\r\\n/ig)) {
str = str.replace(/\\r\\n/ig, '<br/>');
}
if (str.match(/\r\n/ig)) {
str = str.replace(/\r\n/ig, '<br/>');
}
if (str.match(/\\r/ig)) {
str = str.replace(/\\r/ig, '<br/>');
}
if (str.match(/\r/ig)) {
str = str.replace(/\r/ig, '<br/>');
}
if (str.match(/\\n/ig)) {
str = str.replace(/\\n/ig, '<br/>');
}
if (str.match(/\n/ig)) {
str = str.replace(/\n/ig, '<br/>');
}
return str;
}
/**
* 通用Post
*/
Vue.prototype.post = function(url, param = {}, callback, type = 'get') {
let that = this;
uni.showLoading({
title: "加载中"
});
if (type == 'get') {
that.$u.get(url, {
istest:1,
...param
}).then(res => {
if (callback) {
callback(res);
} else {
return res;
}
}).catch(err => {});
} else {
that.$u.post(url, {
istest:1,
...param
}).then(res => {
if (callback) {
callback(res);
} else {
return res;
}
}).catch(err => {});
}
}
Vue.prototype.getApi = function(name, url) {
let that = this;
that.post(url ? url : app.globalData.api_url + '/api/index/getapi', {
name: name
}, res => {
//功能描述
that.html = res.data.infocontent;
//分享
that.share(app.globalData.title + ' :' + name, '', app.globalData.api_url + res.data
.picimage);
}, 'post');
}
/**
* 通用提示
*/
Vue.prototype.showMsg = function(msg, status = 'none', callback, time = 1500) {
uni.showToast({
title: msg,
icon: status,
duration: time,
success: () => {
if (callback) {
setTimeout(function() {
callback();
}, time - 100);
}
}
});
return false;
}
/**
* 统一跳转
*/
Vue.prototype.jump = function(url = '', type = 'nt', def = '/') {
switch (type) {
case 'nt':
uni.navigateTo({
url: def + 'pages/' + url
});
break;
case 'rt':
uni.redirectTo({
url: def + 'pages/' + url
});
break;
case 'rl':
uni.reLaunch({
url: def + 'pages/' + url
});
break;
case 'nb':
uni.navigateBack({
delta: url
});
break;
case 'st':
uni.switchTab({
url: def + 'pages/' + url
});
break;
}
}
Vue.prototype.tabbar = [{
pagePath: '/pages/home/index',
iconPath: "home",
selectedIconPath: "home-fill",
text: '首页',
},
{
pagePath: '/pages/user/index',
iconPath: "account",
selectedIconPath: "account-fill",
text: '我的',
}
];
const app = new Vue({
...App
});
// http拦截器,此为需要加入的内容,如果不是写在common目录,请自行修改引入路径
import httpInterceptor from '@/common/http.interceptor.js';
// 这里需要写在最后,是为了等Vue创建对象完成,引入"app"对象(也即页面的"this"实例)
Vue.use(httpInterceptor, app);
app.$mount();