plm前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
10 months ago
2 years ago
  1. import Vue from 'vue'
  2. import router from '@/router'
  3. import store from '@/store'
  4. /**
  5. * 获取uuid
  6. */
  7. export function getUUID () {
  8. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
  9. return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
  10. })
  11. }
  12. /**
  13. * 是否有权限
  14. * @param {*} key
  15. */
  16. export function isAuth (key) {
  17. // console.log(key)
  18. // console.log(JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || false)
  19. return JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || false
  20. }
  21. export function accessField (key) {
  22. return JSON.parse(sessionStorage.getItem('accessField') || '[]').indexOf(key) !== -1 || false
  23. }
  24. /**
  25. * 树形数据转换
  26. * @param {*} data
  27. * @param {*} id
  28. * @param {*} pid
  29. */
  30. export function treeDataTranslate (data, id = 'id', pid = 'parentId') {
  31. var res = []
  32. var temp = {}
  33. for (var i = 0; i < data.length; i++) {
  34. temp[data[i][id]] = data[i]
  35. }
  36. for (var k = 0; k < data.length; k++) {
  37. if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) {
  38. if (!temp[data[k][pid]]['children']) {
  39. temp[data[k][pid]]['children'] = []
  40. }
  41. if (!temp[data[k][pid]]['_level']) {
  42. temp[data[k][pid]]['_level'] = 1
  43. }
  44. data[k]['_level'] = temp[data[k][pid]]._level + 1
  45. temp[data[k][pid]]['children'].push(data[k])
  46. } else {
  47. res.push(data[k])
  48. }
  49. }
  50. return res
  51. }
  52. /**
  53. * 清除登录信息
  54. */
  55. export function clearLoginInfo () {
  56. Vue.cookie.delete('token')
  57. store.commit('resetStore')
  58. // 加入清空权限信息
  59. sessionStorage.removeItem("dynamicMenuRoutes")
  60. sessionStorage.removeItem("accessField")
  61. sessionStorage.removeItem("menuList")
  62. sessionStorage.removeItem("permissions")
  63. router.options.isAddDynamicMenuRoutes = false
  64. }
  65. export function handleExport(data) {
  66. // 动态创建iframe下载文件
  67. let fileName = this.selectedTabelRow[0].dirName;
  68. if (!data) {
  69. return;
  70. }
  71. let blob = new Blob([data], { type: "application/octet-stream" });
  72. if ("download" in document.createElement("a")) {
  73. // 不是IE浏览器
  74. let url = window.URL.createObjectURL(blob);
  75. let link = document.createElement("a");
  76. link.style.display = "none";
  77. link.href = url;
  78. link.setAttribute("download", fileName);
  79. document.body.appendChild(link);
  80. link.click();
  81. document.body.removeChild(link); // 下载完成移除元素
  82. window.URL.revokeObjectURL(url); // 释放掉blob对象
  83. } else {
  84. // IE 10+
  85. window.navigator.msSaveBlob(blob, fileName);
  86. }
  87. }