operation.js 1.42 KB
import { Message } from "element-ui";
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)
  }
}
// 创造id
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("");
}

// 上移下移
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: '已经是第一条,上移失败',
    });
  }
}
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);
  }
}