| | |
| | | // "Content-Type": "application/json;charset=UTF-8" |
| | | // }, |
| | | method: "GET", |
| | | dataType: "json" |
| | | dataType: "json", |
| | | |
| | | }, |
| | | apiCount: { |
| | | agv_state: 0, |
| | | laser_data: 0, |
| | | }, |
| | | addLog(item) { |
| | | if (!getApp().globalData.withLog) { |
| | | return |
| | | } |
| | | if (item.statusCode == 200) { |
| | | const ret = JSON.parse(item.data) |
| | | if (ret.code == 0) { |
| | | if (item.url.indexOf("get_agv_state") > 0) { |
| | | |
| | | if (this.apiCount.agv_state % 20 != 0) { |
| | | this.apiCount.agv_state++; |
| | | return |
| | | } |
| | | this.apiCount.agv_state = 1; |
| | | } |
| | | if (item.url.indexOf("laser_data") > 0) { |
| | | |
| | | if (ret.data?.base_map?.image_base64) { |
| | | this.apiCount.laser_data++; |
| | | } else { |
| | | if (this.apiCount.laser_data % 20 != 0) { |
| | | this.apiCount.laser_data++; |
| | | return |
| | | } |
| | | this.apiCount.laser_data = 1; |
| | | } |
| | | } |
| | | const res = ret.data |
| | | if (res) { |
| | | if (item.url.indexOf("getMapUrl") > 0) { |
| | | if (res.filedata) { |
| | | res.data_length = res.filedata.length |
| | | res.filedata = "..." |
| | | item.data = JSON.stringify(ret) |
| | | } |
| | | } else if (item.url.indexOf("laser_data") > 0) { |
| | | if (res?.base_map?.image_base64) { |
| | | res.base_map.image_length = res.base_map.image_base64.length |
| | | res.base_map.image_base64 = "..." |
| | | item.data = JSON.stringify(ret) |
| | | } |
| | | |
| | | } |
| | | if (JSON.stringify(res).length > 100 * 1024) { |
| | | // const maxData = session.getValue("request_log_max_data") || {} |
| | | // const key = `data${new Date().getTime()}` |
| | | // maxData[key] = item.data |
| | | // item.data_key = key |
| | | // session.setValue("request_log_max_data", maxData) |
| | | ret.data = "..." |
| | | ret.data_length = JSON.stringify(res).length |
| | | item.data = JSON.stringify(ret) |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | const list = session.getValue("request_log") || [] |
| | | |
| | | const res = typeof item.data == 'string' ? item.data : JSON.stringify(item.data) |
| | | if (res.length > 100 * 1024) { |
| | | const maxData = session.getValue("request_log_max_data") || {} |
| | | const key = `data${new Date().getTime()}` |
| | | maxData[key] = item.data |
| | | item.data_key = key |
| | | delete item.data |
| | | session.setValue("request_log_max_data", maxData) |
| | | } |
| | | list.unshift(item) |
| | | if (list.length > 1000) { |
| | | const oldItem = list.shift() |
| | | |
| | | if (list.length > 512) { |
| | | const oldItem = list.pop() |
| | | if (oldItem.data_key) { |
| | | const maxData = session.getValue("request_log_max_data") || {} |
| | | delete maxData[oldItem.data_key] |
| | |
| | | }; |
| | | options.method = options.method || this.common.method; |
| | | options.dataType = options.dataType || this.common.dataType; |
| | | console.log("url", options.url, options.data) |
| | | |
| | | if (options.url.indexOf("get_agv_state") < 0 && options.url.indexOf("laser_data") < 0 && options.url.indexOf( |
| | | "taskGroupStatus") < 0) { |
| | | console.log("url", options.url, options.data) |
| | | } |
| | | return new Promise((resolve, reject) => { |
| | | const app = getApp() |
| | | uni.request({ |
| | |
| | | method: options.method, |
| | | dataType: options.dataType, |
| | | success: (result) => { |
| | | console.log("result", result) |
| | | if (options.url.indexOf("get_agv_state") < 0 && options.url.indexOf( |
| | | "laser_data") < 0) { // |
| | | console.log("result", result) |
| | | } |
| | | |
| | | const now = new Date() |
| | | const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}` |
| | | if (result.statusCode != 200) { |
| | |
| | | msg: "访问失败,状态码:" + result.statusCode |
| | | }) |
| | | } |
| | | this.addLog({ |
| | | date, |
| | | method: `${options.method || ""}`, |
| | | url: options.url, |
| | | param: options.data, |
| | | statusCode: result.statusCode, |
| | | data: result.data |
| | | }) |
| | | |
| | | var ret = result.data |
| | | if (typeof ret == 'string') { |
| | | try { |
| | |
| | | }) |
| | | } |
| | | } |
| | | this.addLog({ |
| | | date, |
| | | method: `${options.method || ""}`, |
| | | url: options.url, |
| | | param: options.data, |
| | | statusCode: result.statusCode, |
| | | data: JSON.stringify(ret) |
| | | }) |
| | | if (ret.code == 0) { |
| | | |
| | | resolve(ret.data); |
| | | } else { |
| | | |
| | | reject({ |
| | | msg: ret.msg || "" |
| | | msg: ret.msg || ret.message || "" |
| | | }); |
| | | } |
| | | }, |