tool.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { Notification } from 'element-ui';
  2. import router from '@/router';
  3. export default {
  4. // 获取应用权限
  5. checkAuth (appname,auth) {
  6. try {
  7. // 获取应用数据
  8. let apps = JSON.parse(sessionStorage.getItem('active_modules'))
  9. let module_list = apps.apps
  10. // 获取当前应用数据
  11. let active_modules = module_list.filter(item => {
  12. return item.name === appname
  13. })
  14. console.log(active_modules);
  15. // 获取当前应用权限
  16. let auth_list = active_modules[0].meta.auth
  17. // 判断是否拥有权限
  18. let _haveAuth = auth_list.some(item=>item.option === auth)
  19. return _haveAuth
  20. } catch (error) {
  21. console.log(error);
  22. router.replace('/home')
  23. }
  24. },
  25. // 获取应用表格
  26. tabelCol (appname) {
  27. // 获取应用数据
  28. let apps = JSON.parse(sessionStorage.getItem('active_modules'))
  29. let module_list = apps.apps
  30. // 获取当前应用数据
  31. let active_modules = module_list.filter(item => {
  32. return item.name === appname
  33. })
  34. // 获取当前应用表格数据
  35. let tablecols = active_modules[0].meta.tables
  36. return tablecols
  37. },
  38. // 操作响应提示
  39. showMessage (res,success) {
  40. if (res.code === 0) return Notification({
  41. title: '失败',
  42. message: res.msg,
  43. type: 'error'
  44. });
  45. Notification({
  46. title: '成功',
  47. message: '操作成功',
  48. type: 'success'
  49. });
  50. success?success():''
  51. },
  52. // 处理省市县数据结构
  53. createMenu (node) {
  54. var that = this
  55. let obj = Object.keys(node).map((key,index,item)=>{
  56. var elNode = {
  57. label: key,
  58. value: key,
  59. item:node[key],
  60. }
  61. return elNode;
  62. })
  63. obj.forEach(e=>{
  64. if ((e.item) instanceof Array) {
  65. e.children = []
  66. e.item.forEach(c=>{
  67. e.children.push({
  68. label:c,
  69. value:c
  70. })
  71. })
  72. } else {
  73. if (Object.keys(e.item).length !== 0) {
  74. e.children = that.createMenu(e.item)
  75. }
  76. }
  77. })
  78. return obj
  79. },
  80. // 导出excel
  81. exportExcel(a,b,c,d) {
  82. let formatJson = function(filterVal, jsonData) {
  83. return jsonData.map(v => filterVal.map(j => v[j]))
  84. }
  85. require.ensure([], () => {
  86. const { export_json_to_excel } = require('./excel/Export2Excel');
  87. const tHeader = a; // 设置Excel的表格第一行的标题
  88. const filterVal = b; // index、nickName、name是tableData里对象的属性
  89. const list = c; //把data里的tableData存到list
  90. const data = formatJson(filterVal, list);
  91. export_json_to_excel(tHeader, data, d); //导出Excel 文件名
  92. })
  93. }
  94. }