指令管理任务管理
This commit is contained in:
50
utils/getData2.js
Normal file
50
utils/getData2.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import request from './request.js'
|
||||
|
||||
// 登录
|
||||
export const handLogin = (user, password) => request({
|
||||
url:'mobile/auth/login',
|
||||
data: {
|
||||
username: user,
|
||||
password: password
|
||||
}
|
||||
})
|
||||
/**
|
||||
* 指令管理
|
||||
*/
|
||||
// 1.1 查询未完成指令(生成任务号为-开头)
|
||||
export const handInsts = (key, scode, ncode) => request({
|
||||
url:'api/hand/insts',
|
||||
data: {
|
||||
keyword: key,
|
||||
start_devicecode: scode,
|
||||
next_devicecode: ncode
|
||||
}
|
||||
})
|
||||
// 1.2 指令操作
|
||||
export const handInst = (type, id) => request({
|
||||
url:'api/hand/inst',
|
||||
data: {
|
||||
type: type,
|
||||
inst_uuid: id
|
||||
}
|
||||
})
|
||||
/**
|
||||
* 任务管理
|
||||
*/
|
||||
// 1.1 1.1 查询无指令的任务(任务号为-开头)
|
||||
export const handTasks = (key, scode, ncode) => request({
|
||||
url:'api/hand/tasks',
|
||||
data: {
|
||||
keyword: key,
|
||||
start_devicecode: scode,
|
||||
next_devicecode: ncode
|
||||
}
|
||||
})
|
||||
// 1.2 任务操作
|
||||
export const handTaskoperation = (type, id) => request({
|
||||
url:'api/hand/taskoperation',
|
||||
data: {
|
||||
type: type,
|
||||
task_uuid: id
|
||||
}
|
||||
})
|
||||
12
utils/jsencrypt.js
Normal file
12
utils/jsencrypt.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import JSEncrypt from '../node_modules/jsencrypt/bin/jsencrypt.js'
|
||||
let publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD\n' +
|
||||
'2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ==';
|
||||
function RSAencrypt(pas){
|
||||
//实例化jsEncrypt对象
|
||||
let jse = new JSEncrypt();
|
||||
//设置公钥
|
||||
jse.setPublicKey(publicKey);
|
||||
return jse.encrypt(pas);
|
||||
}
|
||||
|
||||
export {RSAencrypt}
|
||||
251
utils/mork2.js
Normal file
251
utils/mork2.js
Normal file
@@ -0,0 +1,251 @@
|
||||
export const handTasks = (key, scode, ncode) => {
|
||||
let res = {
|
||||
"data": [
|
||||
{
|
||||
"task_no": "-087",
|
||||
"task_status": "2",
|
||||
"create_time": "2024-03-28 10:54:39",
|
||||
"carrier": '001',
|
||||
"task_uuid": "012bc5e653ce48949020f1147333aa7f",
|
||||
"inst_step": "7",
|
||||
"next_devicecode": "L1",
|
||||
"start_devicecode": "RKSSX2",
|
||||
"instruction_code": "163",
|
||||
"priority": "1"
|
||||
}
|
||||
],
|
||||
"message": "操作成功"
|
||||
}
|
||||
return res
|
||||
}
|
||||
// 1.2 任务操作
|
||||
export const handTaskoperation = (type, id) => {
|
||||
let res = {
|
||||
"message": "001"
|
||||
}
|
||||
return res
|
||||
}
|
||||
export const handInsts = () => {
|
||||
let res = {
|
||||
"data": [
|
||||
{
|
||||
"task_no": "-087",
|
||||
"inst_status": "2",
|
||||
"create_time": "2024-03-28 10:54:39",
|
||||
"carrier": '001',
|
||||
"carno": '1号车',
|
||||
"inst_uuid": "1",
|
||||
"inst_step": "3",
|
||||
"instruction_code": '11100',
|
||||
"next_devicecode": "L1",
|
||||
"start_devicecode": "RKSSX2",
|
||||
"instruction_code": "163",
|
||||
"priority": "1"
|
||||
},
|
||||
{
|
||||
"task_no": "-087",
|
||||
"inst_status": "2",
|
||||
"create_time": "2024-03-28 10:54:39 2024-03-28 10:54:39 2024-03-28 10:54:39 2024-03-28 10:54:39",
|
||||
"carrier": '001',
|
||||
"carno": '1号车',
|
||||
"inst_uuid": "2",
|
||||
"inst_step": "3",
|
||||
"instruction_code": '11100',
|
||||
"next_devicecode": "L1",
|
||||
"start_devicecode": "RKSSX2",
|
||||
"instruction_code": "163",
|
||||
"priority": "1"
|
||||
},
|
||||
{
|
||||
"task_no": "-087",
|
||||
"inst_status": "2",
|
||||
"create_time": "2024-03-28 10:54:39",
|
||||
"carrier": '001',
|
||||
"carno": '1号车',
|
||||
"inst_uuid": "3",
|
||||
"inst_step": "3",
|
||||
"instruction_code": '11100',
|
||||
"next_devicecode": "L1",
|
||||
"start_devicecode": "RKSSX2",
|
||||
"instruction_code": "163",
|
||||
"priority": "1"
|
||||
},
|
||||
{
|
||||
"task_no": "-087",
|
||||
"inst_status": "2",
|
||||
"create_time": "2024-03-28 10:54:39",
|
||||
"carrier": '001',
|
||||
"carno": '1号车',
|
||||
"inst_uuid": "4",
|
||||
"inst_step": "3",
|
||||
"instruction_code": '11100',
|
||||
"next_devicecode": "L1",
|
||||
"start_devicecode": "RKSSX2",
|
||||
"instruction_code": "163",
|
||||
"priority": "1"
|
||||
}
|
||||
],
|
||||
"message": "操作成功"
|
||||
}
|
||||
return res
|
||||
}
|
||||
export const handInst = (code) => {
|
||||
let res = {
|
||||
"message": "001"
|
||||
}
|
||||
return res
|
||||
}
|
||||
export const queryTask = (keyword, scode, ncode) => {
|
||||
let res = {
|
||||
"message": "ok",
|
||||
"data": [
|
||||
{
|
||||
"inst_uuid": "51",
|
||||
"task_no": "ADB001",
|
||||
"start_devicecode": "46",
|
||||
"next_devicecode": "2",
|
||||
"inst_status": "1",
|
||||
"priority": "一级",
|
||||
"create_time": "1976-04-07 02:36:18",
|
||||
"carrier": "890000008",
|
||||
"instruction_code": '0000',
|
||||
"carno": '1号车',
|
||||
"inst_step": '1'
|
||||
}
|
||||
]
|
||||
}
|
||||
return res
|
||||
}
|
||||
// 1.2 指令操作
|
||||
export const taskOperation = (uuid, type) => {
|
||||
let res = {
|
||||
"message": "001"
|
||||
}
|
||||
return res
|
||||
}
|
||||
export const queryArea = () => {
|
||||
let res = {
|
||||
data: [{region_code: '1', region_name: '一楼装箱区'}, {region_code: '2', region_name: 'A2'}, {region_code: '3', region_name: 'A2'}, {region_code: '4', region_name: 'A10'}]
|
||||
}
|
||||
return res
|
||||
}
|
||||
export const queryPointByArea = () => {
|
||||
let res = {
|
||||
data: [{
|
||||
device_code: 'B2_ED_1_1_K',
|
||||
device_name: 'B2_1_1_生箔机空轴',
|
||||
status: '1'
|
||||
}, {
|
||||
device_code: 'B2_ED_1_2_K',
|
||||
device_name: 'B2_1_2_生箔机空轴'
|
||||
}, {
|
||||
device_code: 'B2_ED_1_3_K',
|
||||
device_name: 'JLDFJLLJ3'
|
||||
}, {
|
||||
device_code: 'B2_ED_1_4_K',
|
||||
device_name: 'JLDFJLLJ4'
|
||||
}, {
|
||||
device_code: 'B2_ED_1_5_K',
|
||||
device_name: 'JLDFJLLJ5'
|
||||
}, {
|
||||
device_code: 'B2_ED_1_6_K',
|
||||
device_name: 'JLDFJLLJ6'
|
||||
}, {
|
||||
device_code: 'B2_ED_1_7_K',
|
||||
device_name: 'JLDFJLLJ7'
|
||||
}, {
|
||||
device_code: 'B3_ED_1_3_K',
|
||||
device_name: 'JLDFJLLJ3'
|
||||
}, {
|
||||
device_code: 'B3_ED_1_4_K',
|
||||
device_name: 'JLDFJLLJ4'
|
||||
}, {
|
||||
device_code: 'B3_ED_1_5_K',
|
||||
device_name: 'JLDFJLLJ5'
|
||||
}, {
|
||||
device_code: 'B3_ED_1_6_K',
|
||||
device_name: 'JLDFJLLJ6'
|
||||
}, {
|
||||
device_code: 'B3_ED_1_7_K',
|
||||
device_name: 'JLDFJLLJ7'
|
||||
}, {
|
||||
device_code: 'B4_ED_1_3_K',
|
||||
device_name: 'JLDFJLLJ3'
|
||||
}, {
|
||||
device_code: 'B4_ED_1_4_K',
|
||||
device_name: 'JLDFJLLJ4'
|
||||
}, {
|
||||
device_code: 'B4_ED_1_5_K',
|
||||
device_name: 'JLDFJLLJ5'
|
||||
}, {
|
||||
device_code: 'B4_ED_1_6_K',
|
||||
device_name: 'JLDFJLLJ6'
|
||||
}, {
|
||||
device_code: 'B4_ED_1_7_K',
|
||||
device_name: 'JLDFJLLJ7'
|
||||
}]
|
||||
}
|
||||
return res
|
||||
}
|
||||
export const queryDevices = () => {
|
||||
let res = {
|
||||
data: [{
|
||||
device_code: '1',
|
||||
device_name: 'JLDFJLLJ',
|
||||
seq_num: '1'
|
||||
}, {
|
||||
device_code: '12',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '13',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '14',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '15',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '16',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '17',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}]
|
||||
}
|
||||
return res
|
||||
}
|
||||
export const agvqueryArea = () => {
|
||||
let res = {
|
||||
data: [{region_code: '1', region_name: '一楼装箱区'}, {region_code: '2', region_name: 'A2'}, {region_code: '3', region_name: 'A2'}, {region_code: '4', region_name: 'A10'}]
|
||||
}
|
||||
return res
|
||||
}
|
||||
export const agvqueryPointByArea = (code) => {
|
||||
let res = {
|
||||
data: [{
|
||||
device_code: '1',
|
||||
device_name: 'JLDFJLLJ',
|
||||
seq_num: '1'
|
||||
}, {
|
||||
device_code: '12',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '13',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '14',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '15',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '16',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}, {
|
||||
device_code: '17',
|
||||
device_name: 'JLDFJLLJ'
|
||||
}]
|
||||
}
|
||||
return res
|
||||
}
|
||||
245
utils/permission.js
Normal file
245
utils/permission.js
Normal file
@@ -0,0 +1,245 @@
|
||||
/// null = 未请求,1 = 已允许,0 = 拒绝|受限, 2 = 系统未开启
|
||||
|
||||
var isIOS
|
||||
|
||||
function album() {
|
||||
var result = 0;
|
||||
var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary");
|
||||
var authStatus = PHPhotoLibrary.authorizationStatus();
|
||||
if (authStatus === 0) {
|
||||
result = null;
|
||||
} else if (authStatus == 3) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(PHPhotoLibrary);
|
||||
return result;
|
||||
}
|
||||
|
||||
function camera() {
|
||||
var result = 0;
|
||||
var AVCaptureDevice = plus.ios.import("AVCaptureDevice");
|
||||
var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
|
||||
if (authStatus === 0) {
|
||||
result = null;
|
||||
} else if (authStatus == 3) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(AVCaptureDevice);
|
||||
return result;
|
||||
}
|
||||
|
||||
function location() {
|
||||
var result = 0;
|
||||
var cllocationManger = plus.ios.import("CLLocationManager");
|
||||
var enable = cllocationManger.locationServicesEnabled();
|
||||
var status = cllocationManger.authorizationStatus();
|
||||
if (!enable) {
|
||||
result = 2;
|
||||
} else if (status === 0) {
|
||||
result = null;
|
||||
} else if (status === 3 || status === 4) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(cllocationManger);
|
||||
return result;
|
||||
}
|
||||
|
||||
function push() {
|
||||
var result = 0;
|
||||
var UIApplication = plus.ios.import("UIApplication");
|
||||
var app = UIApplication.sharedApplication();
|
||||
var enabledTypes = 0;
|
||||
if (app.currentUserNotificationSettings) {
|
||||
var settings = app.currentUserNotificationSettings();
|
||||
enabledTypes = settings.plusGetAttribute("types");
|
||||
if (enabledTypes == 0) {
|
||||
result = 0;
|
||||
console.log("推送权限没有开启");
|
||||
} else {
|
||||
result = 1;
|
||||
console.log("已经开启推送功能!")
|
||||
}
|
||||
plus.ios.deleteObject(settings);
|
||||
} else {
|
||||
enabledTypes = app.enabledRemoteNotificationTypes();
|
||||
if (enabledTypes == 0) {
|
||||
result = 3;
|
||||
console.log("推送权限没有开启!");
|
||||
} else {
|
||||
result = 4;
|
||||
console.log("已经开启推送功能!")
|
||||
}
|
||||
}
|
||||
plus.ios.deleteObject(app);
|
||||
plus.ios.deleteObject(UIApplication);
|
||||
return result;
|
||||
}
|
||||
|
||||
function contact() {
|
||||
var result = 0;
|
||||
var CNContactStore = plus.ios.import("CNContactStore");
|
||||
var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
|
||||
if (cnAuthStatus === 0) {
|
||||
result = null;
|
||||
} else if (cnAuthStatus == 3) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(CNContactStore);
|
||||
return result;
|
||||
}
|
||||
|
||||
function record() {
|
||||
var result = null;
|
||||
var avaudiosession = plus.ios.import("AVAudioSession");
|
||||
var avaudio = avaudiosession.sharedInstance();
|
||||
var status = avaudio.recordPermission();
|
||||
console.log("permissionStatus:" + status);
|
||||
if (status === 1970168948) {
|
||||
result = null;
|
||||
} else if (status === 1735552628) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(avaudiosession);
|
||||
return result;
|
||||
}
|
||||
|
||||
function calendar() {
|
||||
var result = null;
|
||||
var EKEventStore = plus.ios.import("EKEventStore");
|
||||
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
|
||||
if (ekAuthStatus == 3) {
|
||||
result = 1;
|
||||
console.log("日历权限已经开启");
|
||||
} else {
|
||||
console.log("日历权限没有开启");
|
||||
}
|
||||
plus.ios.deleteObject(EKEventStore);
|
||||
return result;
|
||||
}
|
||||
|
||||
function memo() {
|
||||
var result = null;
|
||||
var EKEventStore = plus.ios.import("EKEventStore");
|
||||
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
|
||||
if (ekAuthStatus == 3) {
|
||||
result = 1;
|
||||
console.log("备忘录权限已经开启");
|
||||
} else {
|
||||
console.log("备忘录权限没有开启");
|
||||
}
|
||||
plus.ios.deleteObject(EKEventStore);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function requestIOS(permissionID) {
|
||||
return new Promise((resolve, reject) => {
|
||||
switch (permissionID) {
|
||||
case "push":
|
||||
resolve(push());
|
||||
break;
|
||||
case "location":
|
||||
resolve(location());
|
||||
break;
|
||||
case "record":
|
||||
resolve(record());
|
||||
break;
|
||||
case "camera":
|
||||
resolve(camera());
|
||||
break;
|
||||
case "album":
|
||||
resolve(album());
|
||||
break;
|
||||
case "contact":
|
||||
resolve(contact());
|
||||
break;
|
||||
case "calendar":
|
||||
resolve(calendar());
|
||||
break;
|
||||
case "memo":
|
||||
resolve(memo());
|
||||
break;
|
||||
default:
|
||||
resolve(0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function requestAndroid(permissionID) {
|
||||
return new Promise((resolve, reject) => {
|
||||
plus.android.requestPermissions(
|
||||
[permissionID],
|
||||
function(resultObj) {
|
||||
var result = 0;
|
||||
for (var i = 0; i < resultObj.granted.length; i++) {
|
||||
var grantedPermission = resultObj.granted[i];
|
||||
console.log('已获取的权限:' + grantedPermission);
|
||||
result = 1
|
||||
}
|
||||
for (var i = 0; i < resultObj.deniedPresent.length; i++) {
|
||||
var deniedPresentPermission = resultObj.deniedPresent[i];
|
||||
console.log('拒绝本次申请的权限:' + deniedPresentPermission);
|
||||
result = 0
|
||||
}
|
||||
for (var i = 0; i < resultObj.deniedAlways.length; i++) {
|
||||
var deniedAlwaysPermission = resultObj.deniedAlways[i];
|
||||
console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
|
||||
result = -1
|
||||
}
|
||||
resolve(result);
|
||||
},
|
||||
function(error) {
|
||||
console.log('result error: ' + error.message)
|
||||
resolve({
|
||||
code: error.code,
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function gotoAppPermissionSetting() {
|
||||
if (permission.isIOS) {
|
||||
var UIApplication = plus.ios.import("UIApplication");
|
||||
var application2 = UIApplication.sharedApplication();
|
||||
var NSURL2 = plus.ios.import("NSURL");
|
||||
var setting2 = NSURL2.URLWithString("app-settings:");
|
||||
application2.openURL(setting2);
|
||||
plus.ios.deleteObject(setting2);
|
||||
plus.ios.deleteObject(NSURL2);
|
||||
plus.ios.deleteObject(application2);
|
||||
} else {
|
||||
var Intent = plus.android.importClass("android.content.Intent");
|
||||
var Settings = plus.android.importClass("android.provider.Settings");
|
||||
var Uri = plus.android.importClass("android.net.Uri");
|
||||
var mainActivity = plus.android.runtimeMainActivity();
|
||||
var intent = new Intent();
|
||||
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
mainActivity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
const permission = {
|
||||
get isIOS(){
|
||||
return typeof isIOS === 'boolean' ? isIOS : (isIOS = uni.getSystemInfoSync().platform === 'ios')
|
||||
},
|
||||
requestIOS: requestIOS,
|
||||
requestAndroid: requestAndroid,
|
||||
gotoAppSetting: gotoAppPermissionSetting
|
||||
}
|
||||
|
||||
export default permission
|
||||
95
utils/request.js
Normal file
95
utils/request.js
Normal file
@@ -0,0 +1,95 @@
|
||||
// import qs from 'qs' // 处理data
|
||||
import store from '@/vuex/store'
|
||||
const request = (params) => {
|
||||
let _self = this;
|
||||
let url = params.url;
|
||||
let method = params.method || 'POST';
|
||||
let data = params.data || {};
|
||||
let token = ''
|
||||
if (store.getters.saveToken !== '') {
|
||||
token = store.getters.saveToken
|
||||
}
|
||||
let defaultOpot = {
|
||||
// 'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Terminal-Type': 'innerH5',
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
}
|
||||
let header = {}
|
||||
method = method.toUpperCase()
|
||||
if (method == 'POST') {
|
||||
header = {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
'Authorization': token
|
||||
}
|
||||
// data = qs.stringify(data)
|
||||
}
|
||||
const requestUrl = `${store.getters.baseUrl}/` + url;
|
||||
let type = params.type
|
||||
if (type === 1) {
|
||||
uni.showLoading({
|
||||
mask: true,
|
||||
title: '正在推送,如未审核成功,请查看单据审核结果信息。'
|
||||
});
|
||||
} else {
|
||||
uni.showLoading({
|
||||
mask: true,
|
||||
title: '加载中...'
|
||||
});
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: requestUrl,
|
||||
method: method,
|
||||
header: Object.assign({}, defaultOpot, header),
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
})
|
||||
.then(res => { // 成功
|
||||
if (res.length === 1) {
|
||||
uni.hideLoading();
|
||||
uni.showModal({
|
||||
content: 'request:fail',
|
||||
showCancel: false
|
||||
})
|
||||
reject('request:fail')
|
||||
} else if (res[1] && res[1].statusCode === 400) {
|
||||
uni.hideLoading();
|
||||
uni.showModal({
|
||||
content: `${res[1].data.message}`,
|
||||
showCancel: false
|
||||
})
|
||||
reject(res[1].data.message)
|
||||
} else if (res[1] && res[1].statusCode === 401) {
|
||||
uni.hideLoading();
|
||||
uni.showModal({
|
||||
content: `${res[1].data.message}`,
|
||||
showCancel: false
|
||||
})
|
||||
// store.dispatch('delUserInfo', '')
|
||||
// uni.redirectTo({
|
||||
// url: '/pages/login/login'
|
||||
// })
|
||||
} else if (res[1] && res[1].statusCode === 200) {
|
||||
uni.hideLoading();
|
||||
let {
|
||||
data: dataType
|
||||
} = res[1]
|
||||
resolve(dataType)
|
||||
}else {
|
||||
uni.hideLoading();
|
||||
uni.showModal({
|
||||
content: `${res[1].data.message}`,
|
||||
showCancel: false
|
||||
})
|
||||
reject(res[1].data.message)
|
||||
}
|
||||
})
|
||||
.catch(err => { // 错误
|
||||
reject(err)
|
||||
})
|
||||
.finally(() => {
|
||||
// uni.hideLoading();
|
||||
})
|
||||
})
|
||||
}
|
||||
export default request
|
||||
39
utils/utils.js
Normal file
39
utils/utils.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* yy-mm-dd
|
||||
*/
|
||||
export const dateFtt = date => {
|
||||
if (date == null) {
|
||||
return ''
|
||||
}
|
||||
let year = date.getFullYear()
|
||||
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||||
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
/**
|
||||
* yy-mm-dd hh:mm:ss
|
||||
*/
|
||||
export const dateTimeFtt = date => {
|
||||
if (date == null) {
|
||||
return ''
|
||||
}
|
||||
let year = date.getFullYear()
|
||||
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||||
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
let hh = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
||||
let mm = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
||||
let ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
|
||||
return `${year}-${month}-${day} ${hh}:${mm}:${ss}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串形式的日期转换成日期对象
|
||||
*/
|
||||
export const dateNew = date => {
|
||||
if (date === undefined || date === 'undefined') {
|
||||
return new Date()
|
||||
}
|
||||
return new Date(Date.parse(date))
|
||||
}
|
||||
|
||||
99
utils/websocket.js
Normal file
99
utils/websocket.js
Normal file
@@ -0,0 +1,99 @@
|
||||
let websock = null
|
||||
let messageCallback = null
|
||||
let errorCallback = null
|
||||
let wsUrl = ''
|
||||
|
||||
// 接收ws后端返回的数据
|
||||
function websocketonmessage (e) {
|
||||
messageCallback(JSON.parse(e.data))
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起websocket连接
|
||||
* @param {Object} agentData 需要向后台传递的参数数据
|
||||
*/
|
||||
function websocketSend (agentData) {
|
||||
// 加延迟是为了尽量让ws连接状态变为OPEN
|
||||
setTimeout(() => {
|
||||
// 添加状态判断,当为OPEN时,发送消息
|
||||
if (websock.readyState === websock.OPEN) { // websock.OPEN = 1
|
||||
// 发给后端的数据需要字符串化
|
||||
websock.send(JSON.stringify(agentData))
|
||||
}
|
||||
if (websock.readyState === websock.CLOSED) { // websock.CLOSED = 3
|
||||
console.log('websock.readyState=3')
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 关闭ws连接
|
||||
function websocketclose (e) {
|
||||
// e.code === 1000 表示正常关闭。 无论为何目的而创建, 该链接都已成功完成任务。
|
||||
// e.code !== 1000 表示非正常关闭。
|
||||
if (e && e.code !== 1000) {
|
||||
uni.showToast({
|
||||
title: 'server error',
|
||||
icon: 'none'
|
||||
})
|
||||
errorCallback()
|
||||
}
|
||||
}
|
||||
// 建立ws连接
|
||||
function websocketOpen (e) {
|
||||
// console.log('ws连接成功')
|
||||
}
|
||||
|
||||
// 初始化weosocket
|
||||
function initWebSocket () {
|
||||
if (typeof (WebSocket) === 'undefined') {
|
||||
uni.showToast({
|
||||
title: '您的浏览器不支持WebSocket,无法获取数据',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
// ws请求完整地址
|
||||
const requstWsUrl = wsUrl
|
||||
websock = new WebSocket(requstWsUrl)
|
||||
|
||||
websock.onmessage = function (e) {
|
||||
websocketonmessage(e)
|
||||
}
|
||||
websock.onopen = function () {
|
||||
websocketOpen()
|
||||
}
|
||||
websock.onerror = function () {
|
||||
}
|
||||
websock.onclose = function (e) {
|
||||
websocketclose(e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起websocket请求函数
|
||||
* @param {string} url ws连接地址
|
||||
* @param {Object} agentData 传给后台的参数
|
||||
* @param {function} successCallback 接收到ws数据,对数据进行处理的回调函数
|
||||
* @param {function} errCallback ws连接错误的回调函数
|
||||
*/
|
||||
export function sendWebsocket (url, agentData, successCallback, errCallback) {
|
||||
wsUrl = url
|
||||
initWebSocket()
|
||||
messageCallback = successCallback
|
||||
errorCallback = errCallback
|
||||
websocketSend(agentData)
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭websocket函数
|
||||
*/
|
||||
export function closeWebsocket (flag) {
|
||||
if (flag) {
|
||||
websock.close()
|
||||
return
|
||||
}
|
||||
if (websock) {
|
||||
websock.close() // 关闭websocket
|
||||
websock.onclose() // 关闭websocket
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user