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
/*
*工具 公用方法 全局方法
*
*
*
*/
import { BASE_CONFIG } from '@/config/config'
import axios from 'axios'
import Clipboard from 'clipboard';
import { MessageBox, Toast } from 'mint-ui';
export default {
install(Vue, options) {
//公共弹框
function CommonAlert(msg) {
return Toast({
message: msg,
duration: BASE_CONFIG.MESSAGE_DURATION
})
}
// 不需要登录就能访问
Vue.prototype.$normalPage = function () {
return [sessionStorage.getItem('normalPage')] || [];
}
Vue.prototype.$isIphonex = function () {
// X XS, XS Max, XR
const xSeriesConfig = [
{
devicePixelRatio: 3,
width: 375,
height: 812,
},
{
devicePixelRatio: 3,
width: 414,
height: 896,
},
{
devicePixelRatio: 2,
width: 414,
height: 896,
},
{
devicePixelRatio: 3,
width: 390,
height: 844,
},
{
devicePixelRatio: 3,
width: 428,
height: 926,
}
];
// h5
if (typeof window !== 'undefined' && window) {
const isIOS = /iphone/gi.test(window.navigator.userAgent);
if (!isIOS) return false;
const { devicePixelRatio, screen } = window;
const { width, height } = screen;
return xSeriesConfig.some(item => item.devicePixelRatio === devicePixelRatio && item.width === width && item.height === height);
}
return false;
}
Vue.prototype.$message = function (msg) {
return Toast({
message: msg,
duration: BASE_CONFIG.MESSAGE_DURATION
})
}
//获取全局公共配置
Vue.prototype.$getConfig = function () {
return BASE_CONFIG
}
//清除全局缓存
Vue.prototype.$removeRootScope = function (key) {
if (sessionStorage.getItem(key)) {
sessionStorage.removeItem(key);
}
}
//新增缓存字段
Vue.prototype.$setRootScope = function (key, value) {
if (sessionStorage.getItem(key)) {
sessionStorage.removeItem(key);
}
sessionStorage.setItem(key, value)
//sessionStorage.setItem(key, value);
}
//获取缓存
Vue.prototype.$getRootScope = function (key) {
let res = sessionStorage.getItem(key)
return res
}
//cookie
Vue.prototype.$getCookie = function (c_name) {
if (document.cookie.length > 0) {
let c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1
let c_end = document.cookie.indexOf(";", c_start)
if (c_end == -1)
c_end = document.cookie.length
//console.log(document.cookie.substring(c_start, c_end))
//console.log(decodeURIComponent(document.cookie.substring(c_start, c_end)) )
//return decodeURIComponent(document.cookie.substring(c_start, c_end))
return unescape(document.cookie.substring(c_start, c_end))
}
}
return ""
}
Vue.prototype.$setCookie = function (name, value, expires) {
//console.log(value)
//console.log(encodeURIComponent(value))
var exp = new Date();
exp.setTime(exp.getTime() + expires * 24 * 60 * 60 * 1000); //3天过期
//document.cookie = name + "=" + encodeURIComponent(value)
document.cookie = name + "=" + escape(value)
+ ";expires=" + exp.toGMTString() + ";path=/";
return true;
}
//复制
Vue.prototype.$copy = function (className) {
var clipboard = new Clipboard('.' + className)
clipboard.on('success', e => {
// console.log('复制成功')
CommonAlert('复制成功');
// 释放内存
clipboard.destroy()
})
clipboard.on('error', e => {
// 不支持复制
// console.log('该浏览器不支持自动复制')
CommonAlert('该浏览器不支持自动复制');
// 释放内存
clipboard.destroy()
})
}
//正则 从url里获取字段值
Vue.prototype.$getvl = function (reqUrl, name) {
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test(reqUrl)) return unescape(RegExp.$2.replace(/\//g, " "));
return "";
}
const commonExp = {
mobile: /^[1][0-9][0-9]{9}$/,
email: /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-zA-Z0-9]+[-a-z0-9]*[a-zA-Z0-9]+.){1,63}[a-zA-Z0-9]+$/,
account: /^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]{2,200}$/, // 2-位数 汉字、字母、数字、下划线
pwdStongMilddle: /^(?=.*[A-Z])(?=.*\d)[^]{6,18}$/,//6-18位数 数字和字母的组合
pwdStong: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{6,18}$/,//至少1个大写字母,1个小写字母和1个数字,
certNo: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
}
// 正则匹配 表达式 统一维护
Vue.prototype.$commonExpression = function (key) {
return commonExp[key]
}
//当日时间格式转换
Vue.prototype.$TimesStr = function () {
let date = new Date();
let month = (date.getMonth() + 1).toString();
let strDate = date.getDate().toString();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
let currentdate = date.getFullYear() + "-" + month + "-" + strDate;
this.$store.state.date = currentdate; //转换格式为yyyy-mm-dd
this.$store.state.dateDot = date.toLocaleDateString().replace(/\//g, ".");
this.$store.state.monthStr = date.getFullYear() + "-" + month
return currentdate;
}
}
}