2025-09-23 11:56:35 +08:00
|
|
|
import request from "@/utils/request.js";
|
2025-08-27 11:06:49 +08:00
|
|
|
export default {
|
|
|
|
|
|
2025-09-23 11:56:35 +08:00
|
|
|
guid: function generateUUID() {
|
|
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
|
|
|
const r = Math.random() * 16 | 0;
|
|
|
|
|
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
|
|
|
return v.toString(16);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
alert: function(title, content, callback) {
|
|
|
|
|
if (!title) {
|
|
|
|
|
title = '提示'
|
|
|
|
|
}
|
|
|
|
|
if (!content) {
|
|
|
|
|
content = title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: title,
|
|
|
|
|
content: content,
|
|
|
|
|
success: function(res) {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
console.log('用户点击确定');
|
|
|
|
|
} else if (res.cancel) {
|
|
|
|
|
console.log('用户点击取消');
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback(res);
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showLoading: function(title, mask) {
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: title,
|
|
|
|
|
mask: mask,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
hideLoading: function() {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
},
|
|
|
|
|
showToast: function(title, mask, duration, callback) {
|
|
|
|
|
if (!duration) {
|
|
|
|
|
duration = 1500;
|
|
|
|
|
}
|
|
|
|
|
if (mask == undefined) {
|
|
|
|
|
mask = false;
|
|
|
|
|
}
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: title,
|
|
|
|
|
mask: mask,
|
|
|
|
|
duration: duration,
|
|
|
|
|
callback: callback,
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
GetData: function(url, data, method, contentType, succ, err, complete) {
|
|
|
|
|
var these = this;
|
|
|
|
|
if (!url) {
|
|
|
|
|
console.error("url为空");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (url.toLowerCase().indexOf('http://') == -1 || url.toLowerCase().indexOf('https://') == -1) {
|
|
|
|
|
if (url.indexOf('/') == 0) {
|
|
|
|
|
url = url.substr(1, url.length - 1);
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
let ServerPath = these.DevApi;
|
|
|
|
|
if (these.Version === 'Dev') {
|
|
|
|
|
ServerPath = these.DevApi;
|
|
|
|
|
} else if (these.Version === 'Uat') {
|
|
|
|
|
ServerPath = these.UatApi;
|
|
|
|
|
} else if (these.Version === 'Relese') {
|
|
|
|
|
ServerPath = these.ReleseApi;
|
|
|
|
|
} else {
|
|
|
|
|
these.DevApi
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
url = ServerPath + url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var these = this;
|
|
|
|
|
if (!method) {
|
|
|
|
|
method = 'POST';
|
|
|
|
|
}
|
|
|
|
|
method = method.toUpperCase();
|
|
|
|
|
|
|
|
|
|
if (!contentType) {
|
|
|
|
|
contentType = 'application/json;charset=UTF-8';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
these.checkLAN(
|
|
|
|
|
|
|
|
|
|
function() {
|
|
|
|
|
these.showLoading('请稍候..', true);
|
|
|
|
|
setTimeout(function() {
|
2025-08-27 11:06:49 +08:00
|
|
|
uni.request({
|
2025-09-23 11:56:35 +08:00
|
|
|
url: url,
|
|
|
|
|
data: data,
|
|
|
|
|
header: {
|
|
|
|
|
"Content-Type": contentType
|
2025-08-27 11:06:49 +08:00
|
|
|
},
|
2025-09-23 11:56:35 +08:00
|
|
|
method: method,
|
|
|
|
|
timeout: 60000,
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
success: function(json) {
|
|
|
|
|
|
|
|
|
|
if (succ) {
|
2025-08-27 11:06:49 +08:00
|
|
|
succ(json);
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-09-23 11:56:35 +08:00
|
|
|
fail: function(ex) {
|
|
|
|
|
|
|
|
|
|
if (err) {
|
2025-08-27 11:06:49 +08:00
|
|
|
err(ex);
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-09-23 11:56:35 +08:00
|
|
|
complete: function() {
|
|
|
|
|
|
|
|
|
|
if (complete) {
|
2025-08-27 11:06:49 +08:00
|
|
|
complete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-09-23 11:56:35 +08:00
|
|
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
|
|
|
|
|
,
|
|
|
|
|
function() {
|
2025-08-27 11:06:49 +08:00
|
|
|
these.showToast('无网络连接');
|
|
|
|
|
});
|
2025-09-23 11:56:35 +08:00
|
|
|
},
|
|
|
|
|
checkLAN: function(succ, error) {
|
|
|
|
|
uni.getNetworkType({
|
|
|
|
|
success: (res) => {
|
|
|
|
|
const networkType = res.networkType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断网络是否连接
|
|
|
|
|
if (networkType === 'none') {
|
2025-08-27 11:06:49 +08:00
|
|
|
console.error('无网络连接')
|
2025-09-23 11:56:35 +08:00
|
|
|
if (error) {
|
|
|
|
|
error();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (succ) {
|
2025-08-27 11:06:49 +08:00
|
|
|
succ();
|
|
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
},
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
console.error('获取网络状态失败:', err);
|
|
|
|
|
if (error) {
|
2025-08-27 11:06:49 +08:00
|
|
|
error();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
DateFormat: function(date, format) {
|
|
|
|
|
if (!date) {
|
|
|
|
|
date = new Date();
|
|
|
|
|
}
|
|
|
|
|
if (!format) {
|
|
|
|
|
format = 'yyyy-MM-dd HH:mm:ss';
|
|
|
|
|
}
|
|
|
|
|
// 处理参数默认值
|
|
|
|
|
if (typeof date === 'string' || typeof date === 'number') {
|
|
|
|
|
date = new Date(date);
|
|
|
|
|
}
|
|
|
|
|
date = date instanceof Date ? date : new Date();
|
|
|
|
|
format = format || 'yyyy-MM-dd';
|
|
|
|
|
|
|
|
|
|
// 检查日期是否有效
|
|
|
|
|
if (isNaN(date.getTime())) {
|
|
|
|
|
return 'Invalid Date';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 定义格式化映射
|
|
|
|
|
const formatMap = {
|
|
|
|
|
'yyyy': date.getFullYear(),
|
|
|
|
|
'MM': String(date.getMonth() + 1).padStart(2, '0'),
|
|
|
|
|
'dd': String(date.getDate()).padStart(2, '0'),
|
|
|
|
|
'HH': String(date.getHours()).padStart(2, '0'),
|
|
|
|
|
'mm': String(date.getMinutes()).padStart(2, '0'),
|
|
|
|
|
'ss': String(date.getSeconds()).padStart(2, '0'),
|
|
|
|
|
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
|
|
|
|
|
'M': date.getMonth() + 1,
|
|
|
|
|
'd': date.getDate(),
|
|
|
|
|
'H': date.getHours(),
|
|
|
|
|
'm': date.getMinutes(),
|
|
|
|
|
's': date.getSeconds(),
|
|
|
|
|
'S': date.getMilliseconds()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 替换格式字符串中的占位符
|
|
|
|
|
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
|
|
|
|
|
return formatMap[match];
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
getdeviceShareId(id) {//获取设备分享信息
|
|
|
|
|
return request({
|
|
|
|
|
url: `/app/deviceShare/${id}`,
|
|
|
|
|
method: 'get',
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
getPermissions(type) {
|
|
|
|
|
if (!type) {
|
2025-09-23 13:54:38 +08:00
|
|
|
type='6170';
|
2025-09-23 11:56:35 +08:00
|
|
|
}
|
|
|
|
|
let array = [{
|
|
|
|
|
value: "1",
|
|
|
|
|
label: "灯光模式",
|
|
|
|
|
checked: false,
|
|
|
|
|
type: ['210', '6170', '670']
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "2",
|
|
|
|
|
label: "激光模式",
|
|
|
|
|
checked: false,
|
|
|
|
|
type: ['210', '6170']
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "3",
|
|
|
|
|
label: "开机画面",
|
|
|
|
|
checked: false,
|
|
|
|
|
type: ['210', '6170', '670']
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "4",
|
|
|
|
|
label: "人员信息登记",
|
|
|
|
|
checked: false,
|
|
|
|
|
type: ['210', '6170', '670']
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "5",
|
|
|
|
|
label: "发送信息",
|
|
|
|
|
checked: false,
|
|
|
|
|
type: ['210', '6170', '670']
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "6",
|
|
|
|
|
label: "产品信息",
|
|
|
|
|
checked: false,
|
|
|
|
|
type: ['210', '6170', '670']
|
|
|
|
|
}, {
|
|
|
|
|
value: "41",
|
|
|
|
|
label: "静电探测",
|
|
|
|
|
checked: false,
|
|
|
|
|
type: ['670']
|
|
|
|
|
}, {
|
|
|
|
|
value: "42",
|
|
|
|
|
label: "SOS",
|
|
|
|
|
checked: false,
|
|
|
|
|
type: ['210', '6170', '670']
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
let arr=[];
|
|
|
|
|
for (let i = 0; i < array.length; i++) {
|
|
|
|
|
let item = array[i];
|
|
|
|
|
if(!item){
|
|
|
|
|
continue;
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
if(!item.type){
|
|
|
|
|
continue;
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
let typeContais=item.type.find(v=>{
|
|
|
|
|
return v.includes(type);
|
2025-08-27 11:06:49 +08:00
|
|
|
});
|
2025-09-23 11:56:35 +08:00
|
|
|
if(typeContais){
|
|
|
|
|
let json={};
|
|
|
|
|
Object.assign(json,item);
|
|
|
|
|
arr.push(json);
|
|
|
|
|
}
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|
2025-09-23 11:56:35 +08:00
|
|
|
return arr;
|
|
|
|
|
}
|
2025-08-27 11:06:49 +08:00
|
|
|
}
|