tool.js 2.5 KB

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