vporto.js
6.58 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
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
import Vue from "vue";
Vue.prototype.dev_unid = "2cb6e39adc5176b81879f6c22f1d9e1c";
/**
* @param {unid} 设备id
*/
Vue.prototype.setDevunid = function(devuid) {
Vue.prototype.dev_unid = devuid;
};
/**
* tar文件上传设置
*/
Vue.prototype.uploadFile = function(file, type, size) {
const isType = file.raw.type === type;
let isSize = true;
if (size) {
isSize = file.size / 1024 / 1024 < size;
}
if (!isType) {
this.$message.error(`上传头像文件只能${type}是格式!`);
}
if (size && !isSize) {
this.$message.error(`文件大小不能超过 ${size}MB!`);
}
return isType && isSize;
};
Vue.prototype.globalWs = null;
Vue.prototype.getCode = function(codeName, code) {
var name = window.localStorage.getItem(codeName + "-" + code);
name = name ? name : "";
return name;
};
/**
* @param {src} 图片路径
* 图片放大
*/
Vue.prototype.zoomImg = function(data) {
store.commit("setImgsrc", data);
};
Vue.filter("sexfn", function(value) {
if (!value) return;
var str = "";
if (value == 1) str = "男";
if (value == 2) str = "女";
return str;
});
Vue.filter("dbnamefn", function(value) {
let dbData = store.state.initinfo.facedbdata,
dbname = "";
dbData.forEach(ele => {
if (ele.code == value) {
dbname = ele.name;
}
});
return dbname;
});
Vue.filter("filterDeployType", function(value) {
let dbData = store.state.alarmtype,
dbname = "";
dbData.forEach(ele => {
if (ele.type == value) {
dbname = ele.name;
}
});
return dbname;
});
/**
* @param {provenceid} 省份id
* @param {cityid} 城市id
*/
Vue.prototype.showCity = function(provenceid, cityid) {
this.cData = this.$store.state.initinfo.province;
var province = provenceid;
var provinceNmae = "";
var cityName = "";
var curProvince = "";
var city = cityid;
if (province) {
this.cData.forEach(function(ele) {
if (ele.code == province) {
if (ele.cities) curProvince = ele.cities;
provinceNmae = ele.name;
}
}, this);
if (city) {
if (curProvince)
curProvince.list_data.forEach(function(ele) {
if (ele.code == city) {
cityName = ele.name;
}
});
}
} else {
provinceNmae = "--";
cityName = "--";
}
return provinceNmae + "-" + cityName;
};
/**
* @param {obj}
* 格式化时间
*/
Vue.prototype.timeForm = function(obj) {
var nowY = obj.getFullYear();
var nowM =
obj.getMonth() + 1 < 10 ? "0" + (obj.getMonth() + 1) : obj.getMonth() + 1;
var nowD = obj.getDate() < 10 ? "0" + obj.getDate() : obj.getDate();
var nowH = obj.getHours() < 10 ? "0" + obj.getHours() : obj.getHours();
var nowMi = obj.getMinutes() < 10 ? "0" + obj.getMinutes() : obj.getMinutes();
var nowS = obj.getSeconds() < 10 ? "0" + obj.getSeconds() : obj.getSeconds();
var timeNow =
nowY + "-" + nowM + "-" + nowD + " " + nowH + ":" + nowMi + ":" + nowS;
return timeNow;
};
/**
* @param {obj}
* UTC时间处理
*/
Vue.prototype.setUtcTime = function(obj) {
if (obj && obj != "") {
let num = new Date(obj).getTime();
let offset = Math.abs(new Date().getTimezoneOffset());
let time;
if (isNaN(num)) {
let ary = obj.split(":");
let h = parseInt(ary[0]) - offset / 60;
if (h < 0) {
h += 24;
}
if (h < 10) {
h = "0" + h;
}
time = h + ":" + ary[1] + ":" + ary[2];
} else {
time = this.timeForm(new Date(new Date(obj).getTime() - offset * 60000));
}
return time;
}
};
/**IE
* 检查浏览器
*/
function checkIE() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIE =
userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
var isIE11 =
userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1;
if (isIE || isEdge || isIE11) {
return true;
} else {
return false;
}
}
Vue.prototype.showLocalTime = function(obj) {
if (obj == undefined) return;
let dt = "",
ndt = "";
if (checkIE()) {
dt = obj.replace(/-/g, "/");
ndt = String(dt).split(".")[0];
} else {
ndt = obj;
}
let num = new Date(ndt).getTime();
let offset = Math.abs(new Date().getTimezoneOffset());
let time;
if (isNaN(num)) {
let ary = obj.split(":");
let h = Number(ary[0]) + offset / 60;
if (h >= 24) {
h -= 24;
}
if (h < 10) {
h = "0" + h;
}
time = h + ":" + ary[1] + ":" + ary[2];
} else {
time = this.timeForm(new Date(new Date(ndt).getTime() + offset * 60000));
}
return time;
};
/**
* 本地存储相机信息
*/
Vue.prototype.setCameralocalStor = function(key, val) {
if (window.localStorage) {
localStorage[key] = val;
} else {
alert("浏览器不支持本地存储");
}
};
/**
* @param {key}
* 获取本地存储相机信息
*/
Vue.prototype.getCameralocalStor = function(key) {
var val = "";
if (window.localStorage) {
val = localStorage[key];
} else {
alert("浏览器不支持本地存储");
}
return val;
};
/**
* 图片上传限制
*/
Vue.prototype.uploadImgCondition = function(file) {
const isJPG = file.type === "image/jpeg";
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isJPG) {
this.$message.error("上传头像图片只能是 JPG 格式!");
}
if (!isLt2M) {
this.$message.error("上传头像图片大小不能超过 2MB!");
}
return isJPG && isLt2M;
};
/**
* base64图片
*/
Vue.prototype.base64Img = function(file) {
// eslint-disable-next-line no-redeclare
var file = file.file;
return new Promise((resolve, reject) => {
var srcs = "";
var reader = new FileReader();
if (file) {
reader.readAsDataURL(file);
}
reader.onloadend = function(evt) {
srcs = reader.result.split(",")[1];
let data = {
pic_base64: srcs,
format: file.type.split("/")[1],
ofilename: file.name,
t_format: "jpg"
};
data.src = evt.target.result;
resolve(data);
};
});
};
/**
* code操作
*/
var codeNation = 1004; //民族
var codeCulture = 1005; //文化程度
var codeBlood = 1006; //血型
var codeRelationTOhead = 1009; //与户主关系
var codePersonType = 1012; //人员类别
var profession = 1013; //职业
var faith = 1020; //宗教信仰
var army = 1021; //服兵役情况
var personType = 1067; //关注人员类型
var marriage = 1007; //婚姻状况
// 获取code编码
Vue.prototype.getCode = (codeName, code) => {
var name = localStorage.getItem(codeName + "-" + code);
name = name ? name : "";
return name;
};