operation.js 5.22 KB
import Vue from 'vue'
import axios from 'axios'
import request from '@/utils/request';
import { Message } from "element-ui";
/**
 * @description: removeTreeListItem
 * @param {*} treeList
 * @param {*} dictId
 * @param {*} idName
 * @author: renchao
 */
export function removeTreeListItem (treeList, dictId, idName = 'bsmDict') {
  if (!treeList || !treeList.length) {
    return
  }
  for (let i = 0; i < treeList.length; i++) {
    if (treeList[i][idName] === dictId) {
      treeList.splice(i, 1);
      break;
    }
    removeTreeListItem(treeList[i].children, dictId)
  }
}
/**
 * @description: 创造id
 * @param {*} len
 * @param {*} radix
 * @author: renchao
 */
export function getUuid (len, radix) {
  var chars = "0123456789abcdefghijklmnopqrstuvwxyz".split(
    ""
  );
  var uuid = [],
    i;
  radix = radix || chars.length;
  if (len) {
    for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
  } else {
    var r;
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
    uuid[14] = "4";
    for (i = 0; i < 36; i++) {
      if (!uuid[i]) {
        r = 0 | (Math.random() * 16);
        uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
      }
    }
  }
  return uuid.join("");
}
/**
 * @description: judgeSort
 * @param {*} arr
 * @author: renchao
 */
export function judgeSort (arr) {
  if (arr.length) {
    for (let i in arr) {
      arr[i]["isTop"] = false;
      arr[i]["isBottom"] = false;
      arr[i] == arr[0] && (arr[i].isTop = true);
      arr[i] == arr[arr.length - 1] && (arr[i].isBottom = true);
      arr[i].children && arr[i].children.length && judgeSort(arr[i].children)
    }
  }
  return arr
}
/**
 * @description: 上下移动
 * @param {*} bsmDict
 * @param {*} operate
 * @param {*} data
 * @author: renchao
 */
export function realMove (bsmDict, operate, data) {
  function changeSort (arr, bsmDict) {
    if (arr.length) {
      let flag = false;
      for (let i in arr) {
        if (arr[i].bsmDict == bsmDict) {
          if (operate === "UP") {
            arr[i] = arr.splice(i - 1, 1, arr[i])[0];
          } else if (operate === "DOWN") {
            let temp = arr.splice(i - 0 + 1, 1, arr[i])
            arr[i] = temp[0];
          }
          flag = true;
          break;
        }
        if (!flag && arr[i].children && arr[i].children.length) {
          arr[i].children = changeSort(arr[i].children, bsmDict);
        }
      }
    }
    return arr;
  }
  data = judgeSort(changeSort(data, bsmDict));
}
/**
 * @description: 获取所有父节点
 * @param {*} treeData
 * @param {*} bsmDict
 * @author: renchao
 */
export function findParents (treeData, bsmDict) {
  if (treeData.length == 0) return
  for (let i = 0; i < treeData.length; i++) {
    if (treeData[i].bsmDict == bsmDict) {
      return []
    } else {
      if (treeData[i].children) {
        let res = findParents(treeData[i].children, bsmDict)
        if (res !== undefined) {
          return res.concat(treeData[i].bsmDict)
        }
      }
    }
  }
}
// 上移下移
/**
 * @description: 上移下移
 * @param {*} index
 * @param {*} data
 * @author: renchao
 */
export function upward (index, data) {
  if (index > 0) {
    let upData = data[index - 1];
    data.splice(index - 1, 1);
    data.splice(index, 0, upData);
  } else {
    Message({
      message: '已经是第一条,上移失败'
    });
  }
}
/**
 * @description: down
 * @param {*} index
 * @param {*} data
 * @author: renchao
 */
export function down (index, data) {
  if ((index + 1) == data.length) {
    Message({
      message: '已经是最后一条,下移失败'
    });
  } else {
    let downData = data[index + 1];
    data.splice(index + 1, 1);
    data.splice(index, 0, downData);
  }
}

/**
 * @description: 身份证读卡器
 * @author: renchao
 */
export function getIdCardInfo (level) {
  var webSocket = new WebSocket('ws://localhost:1818');

  function start () {
    return new Promise((resolve, reject) => {
      webSocket.onopen = function (event) {
        webSocket.send('ReadCard(1001,d:\\)');
      }
      webSocket.onerror = function (error) {
        console.error('WebSocket发生错误:', error);
      }

      webSocket.onclose = function (event) {
        if (event.wasClean) {
          console.log(`WebSocket连接已关闭,代码: ${event.code}, 原因: ${event.reason}`);
        } else {
          console.error('WebSocket连接断开'); // 例如,服务器断电导致连接中断
        }
      }
      webSocket.onmessage = function (event) {
        if (event.data.indexOf('BeginReadCard') >= 0) {
          // 处理数据并返回结果
          const processedData = event.data.replace('BeginReadCard', '').replace('EndReadCard', '');
          // 返回处理后的数据
          resolve(processedData);
        }
      }
    })
  }
  const resultMap = {
    jy: start(),
    lt: axios.post(Vue.prototype.BASE_API.IDCARDURL),
    default: axios.post(Vue.prototype.BASE_API.IDCARDURL)
  }
  return resultMap[level] || resultMap.default
}
/**
 * @description: 高拍仪组件
 * @author: renchao
 */
export function getAltimeterInfo () {
  let data = {
    "filepath": "base64",
    "rotate": "0",
    "cutpage": "0",
    "camidx": "0",
    "ColorMode": "0",
    "quality": "3"
  }
  return axios.post("http://127.0.0.1:38088/video=grabimage", JSON.stringify(data))
}