cuiqian2004
4 天以前 2af5f043b60c1f7ac38ecccc8f5bf44743134325
api/vehicle.js
@@ -4,10 +4,11 @@
} from "@/comm/utils.js"
const addLog = (item) => {
   const list = session.getValue("request_log") || []
   list.unshift(item)
   session.setValue("request_log", list)
   http.addLog(item)
}
// 判断ip是否可以连接上
export const checkIpLinkSuccess = (ip) => {
   var url = `http://${ip}:4405/api/mt/battery`;
@@ -73,6 +74,310 @@
      })
   })
}
/**
 * GET 4405/api/shell/version
 * 获取软件版本信息:
 * @param
 * @returns
 */
export const getShellVersion = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/shell/version`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 4405/api/shell/version
 * 更新软件版本
 * @param
 * @returns
 */
export const uploadShellVersion = async (ip, path) => {
   var header = {
      'Content-Type': 'application/octet-stream'
   };
   var url = `http://${ip}:4405/api/shell/version`;
   const buf = await FilePath.readArrayBuffer({
      path: filePath
   });
   const flag = 3
   const flagBuf = new ArrayBuffer(4);
   const view = new DataView(flagBuf);
   view.setUint32(0, flag, false); // 大端
   // 2.3 拼接 POST 体:flag(4B) + 压缩包
   const body = new ArrayBuffer(4 + buf.byteLength);
   const whole = new Uint8Array(body);
   whole.set(new Uint8Array(flagBuf), 0);
   whole.set(new Uint8Array(buf), 4);
   return http.request({
      method: "POST",
      url,
      header,
      dataType: 'arraybuffer', // 关键:让 data 按二进制走
      data: body,
   })
}
export const shellUpgrade = async (ip, filePath, cbSuccess, cbProgress, cbFail) => {
   var url = `http://${ip}:4405/api/shell/upgrade`;
   const uploadTask = uni.uploadFile({
      url,
      name: "upload",
      filePath: filePath,
      formData: {
         'upgrade_flag': 3
      },
      success: (result) => {
         console.log(result)
         const now = new Date()
         const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
         if (result.statusCode != 200) {
            http.addLog({
               date,
               method: "POST",
               url,
               param: {
                  upload: filePath,
                  upgrade_flag: 3
               },
               statusCode: result.statusCode,
               data: ""
            })
            if (result.statusCode == 404) {
               cbFail("地址不对,请检查该地址:" + url);
            } else
               cbFail("访问失败,状态码:" + result.statusCode);
         } else {
            var ret = result.data
            if (typeof ret == 'string') {
               try {
                  try {
                     try {
                        ret = JSON.parse(ret.replace(/\\"/g, '"'));
                     } catch (ex) {
                        ret = JSON.parse(ret.replace(/\\/g, '\\\\'))
                     }
                  } catch (ex) {
                     ret = JSON.parse(ret.replace(/\\"/g, "'").replace(
                        /[\r\n]/g,
                        '<br>').replace(/[\t]/g, '    '));
                  }
               } catch (ex) {
                  cbFail('将【json string】转换为【json object】失败');
               }
            }
            http.addLog({
               date,
               method: "POST",
               url,
               param: {
                  upload: filePath,
                  upgrade_flag: 3
               },
               statusCode: result.statusCode,
               data: JSON.stringify(ret)
            })
            if (ret.code == 0) {
               cbSuccess(ret.data);
            } else {
               cbFail(ret.msg || ret.message || "");
            }
         }
      },
      fail: (result) => {
         console.log(result)
         cbFail(result);
      },
   })
   uploadTask.onProgressUpdate((res) => {
      cbProgress(res, uploadTask)
   });
}
/**
 * GET 4405/api/error/list
 * 获取实时错误
 * @param
 * @returns
 */
export const getErrorList = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/error/list?_timestamp=${new Date().getTime()}`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 4405/api/mt/clear_fault
 * 清除实时错误
 * @param
 * @returns
 */
export const clearFault = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/mt/clear_fault`;
   return http.request({
      method: "POST",
      url,
      header,
   })
}
/**
 * GET 4405/api/error/history
 * 获取历史错误
 * @param
 * @returns
 */
export const getErrorHistory = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/error/history?_timestamp=${new Date().getTime()}`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 4405/api/error/download_error
 * 下载历史错误日志:
 * @param
 * @returns
 */
export const downloadError = (ip, path, cbSuccess, cbProgress, cbFail) => {
   var url = `http://${ip}:4405/api/error/download_error?path=${encodeURI(path)}`;
   console.log(url)
   // var header = {
   //    "Content-Type": "application/json;charset=UTF-8"
   // };
   // return http.request({
   //    method: "GET",
   //    url,
   //    header,
   // })
   // return
   const downloadTask = uni.downloadFile({
      url: url,
      header: {
         'content-type': 'application/octet-stream',
      },
      success: (result) => {
         console.log("downloadFile", result)
         const now = new Date()
         const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
         if (result.statusCode === 200) {
            http.addLog({
               date,
               method: `GET`,
               url: url,
               param: {},
               statusCode: result.statusCode,
               data: result
            })
            cbSuccess(result.tempFilePath)
         } else {
            http.addLog({
               date,
               method: `GET`,
               url: url,
               param: {},
               statusCode: result.statusCode,
               data: result.data
            })
            cbFail(result.data || '下载未知错误!');
         }
      },
      fail: (result) => {
         console.log("downloadTaskFile fail", result)
         const now = new Date()
         const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
         http.addLog({
            date,
            method: `GET`,
            url: url,
            param: {},
            statusCode: -1,
            data: result
         })
         cbFail('下载文件失败!');
      }
   })
   downloadTask.onProgressUpdate((res) => {
      cbProgress(res, downloadTask)
   });
   return downloadTask
}
/**
 * POST 4405/api/mt/error/tar_log
 * 打包下载日志
 * @param
 * @returns
 */
export const tarErrorLog = (ip, start_time, end_time) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:4405/api/error/tar_log`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         start_time,
         end_time
      }
   })
}
/**
 * GET 4405/api/error/query_task_status
 * 查询打包后的日志目录(查到后使用4405/api/error/download_error接口下载)
 * @param
 * @returns
 */
export const queryErrorTaskStatus = (ip, task_list) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url =
      `http://${ip}:4405/api/error/query_task_status?_timestamp=${new Date().getTime()}&task_list=${encodeURI(JSON.stringify(task_list))}`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 5000/api/get_agv_state
@@ -1000,10 +1305,50 @@
      method: "POST",
      url,
      header,
      data: {data}
      data: {
         data
      }
   })
}
/**
 * GET 5000/api/save_db_data_status
 * 获取DB数据保存状态:
 * @param
 * @returns  1保存中 2保存成功 3保存失败
 */
export const getSaveDBDataStatus = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/save_db_data_status/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * GET 5000/api/cancel_save_db_data
 * 取消保存DB数据:
 * @param
 * @returns
 */
export const cancelSaveDBData = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/cancel_save_db_data/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
@@ -1041,7 +1386,9 @@
      method: "POST",
      url,
      header,
      data: {status}
      data: {
         status
      }
   })
}
@@ -1085,3 +1432,46 @@
    })
 }
 
/**
 * GET 5000/api/get_pallet_size/
 * 获取托盘尺寸:
 * @param
 * @returns
 */
export const getPalletSize = (ip) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/get_pallet_size/`;
   return http.request({
      method: "GET",
      url,
      header,
   })
}
/**
 * POST 5000/api/save_pallet_size/
 * 设置托盘尺寸:
 * @param  length 2,#长度/单位m
 * @param  width 2,#长度/单位m
 * @returns
 */
export const savePalletSize = (ip, length, width) => {
   var header = {
      "Content-Type": "application/json;charset=UTF-8"
   };
   var url = `http://${ip}:5000/api/save_pallet_size/`;
   return http.request({
      method: "POST",
      url,
      header,
      data: {
         length,
         width
      }
   })
}