Blame view

src/utils/operation.js 4.25 KB
1 2
import Vue from 'vue'
import axios from 'axios'
3
import request from '@/utils/request';
任超 committed
4
import { Message } from "element-ui";
yuanbo committed
5 6 7 8 9 10 11
/**
 * @description: removeTreeListItem
 * @param {*} treeList
 * @param {*} dictId
 * @param {*} idName
 * @author: renchao
 */
任超 committed
12 13 14 15 16 17 18 19 20 21 22 23
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)
  }
}
任超 committed
24
// 创造id
yuanbo committed
25 26 27 28 29 30
/**
 * @description: 创造id
 * @param {*} len
 * @param {*} radix
 * @author: renchao
 */
任超 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
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("");
}
yuanbo committed
53 54 55 56 57
/**
 * @description: judgeSort
 * @param {*} arr
 * @author: renchao
 */
任超 committed
58 59 60 61 62 63 64 65 66 67 68 69 70
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
}
// 上下移动
yuanbo committed
71 72 73 74 75 76 77
/**
 * @description: 上下移动
 * @param {*} bsmDict
 * @param {*} operate
 * @param {*} data
 * @author: renchao
 */
任超 committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
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));
}
// 获取所有父节点
yuanbo committed
103 104 105 106 107 108
/**
 * @description: 获取所有父节点
 * @param {*} treeData
 * @param {*} bsmDict
 * @author: renchao
 */
任超 committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
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)
        }
      }
    }
  }
}
任超 committed
124
// 上移下移
yuanbo committed
125 126 127 128 129 130
/**
 * @description: 上移下移
 * @param {*} index
 * @param {*} data
 * @author: renchao
 */
任超 committed
131 132 133 134 135 136 137
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({
138
      message: '已经是第一条,上移失败'
任超 committed
139 140 141
    });
  }
}
yuanbo committed
142 143 144 145 146 147
/**
 * @description: down
 * @param {*} index
 * @param {*} data
 * @author: renchao
 */
任超 committed
148 149 150
export function down (index, data) {
  if ((index + 1) == data.length) {
    Message({
151
      message: '已经是最后一条,下移失败'
任超 committed
152 153 154 155 156 157
    });
  } else {
    let downData = data[index + 1];
    data.splice(index + 1, 1);
    data.splice(index, 0, downData);
  }
158
}
renchao@pashanhoo.com committed
159

160
/**
161
 * @description: 身份证读卡器
162 163
 * @author: renchao
 */
164 165
export function getIdCardInfo (level) {
  const resultMap = {
166
    A: '设备',
167
    default: axios.post(Vue.prototype.BASE_API.IDCARDURL),
168
  }
169
  return resultMap[level] || resultMap.default
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
}
/**
 * @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))
yuanbo committed
185
}