tool.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. // 获取当前应用权限
  15. let auth_list = active_modules[0].meta.auth
  16. // 判断是否拥有权限
  17. let _haveAuth = auth_list.some(item=>item.option === auth)
  18. return _haveAuth
  19. } catch (error) {
  20. router.replace('/home')
  21. }
  22. },
  23. // 获取应用表格
  24. tabelCol (appname) {
  25. // 获取应用数据
  26. let apps = JSON.parse(sessionStorage.getItem('active_modules'))
  27. let module_list = apps.apps
  28. // 获取当前应用数据
  29. let active_modules = module_list.filter(item => {
  30. return item.name === appname
  31. })
  32. // 获取当前应用表格数据
  33. let tablecols = active_modules[0].meta.tables
  34. return tablecols
  35. },
  36. // 操作响应提示
  37. showMessage (res,success) {
  38. if (res.code === 0) return Notification({
  39. title: '失败',
  40. message: res.msg,
  41. type: 'error'
  42. });
  43. Notification({
  44. title: '成功',
  45. message: '操作成功',
  46. type: 'success'
  47. });
  48. success?success():''
  49. },
  50. // 处理省市县数据结构
  51. createMenu (node) {
  52. var that = this
  53. let obj = Object.keys(node).map((key,index,item)=>{
  54. var elNode = {
  55. label: key,
  56. value: key,
  57. item:node[key],
  58. }
  59. return elNode;
  60. })
  61. obj.forEach(e=>{
  62. if ((e.item) instanceof Array) {
  63. e.children = []
  64. e.item.forEach(c=>{
  65. e.children.push({
  66. label:c,
  67. value:c
  68. })
  69. })
  70. } else {
  71. if (Object.keys(e.item).length !== 0) {
  72. e.children = that.createMenu(e.item)
  73. }
  74. }
  75. })
  76. return obj
  77. },
  78. // 导出excel
  79. exportExcel(a,b,c,d) {
  80. let formatJson = function(filterVal, jsonData) {
  81. return jsonData.map(v => filterVal.map(j => v[j]))
  82. }
  83. require.ensure([], () => {
  84. const { export_json_to_excel } = require('./excel/Export2Excel');
  85. const tHeader = a; // 设置Excel的表格第一行的标题
  86. const filterVal = b; // index、nickName、name是tableData里对象的属性
  87. const list = c; //把data里的tableData存到list
  88. const data = formatJson(filterVal, list);
  89. export_json_to_excel(tHeader, data, d); //导出Excel 文件名
  90. })
  91. },
  92. // 数组去重
  93. unique(arr, uniId){
  94. const res = new Map();
  95. return arr.filter((item) => !res.has(item[uniId]) && res.set(item[uniId], 1));
  96. },
  97. // 金额格式化
  98. formatAmount(amount, decimalDigits = 0) {
  99. const amountStr = String(Number(amount).toFixed(decimalDigits))
  100. const reg = /\B(?=(?:\d{3})+$)/g
  101. // 是否是小数
  102. const isDecimal = amountStr.indexOf('.') > -1
  103. if (isDecimal) {
  104. // 整数部分
  105. const integerPart = amountStr.substring(0, amountStr.indexOf('.'))
  106. // 小数部分
  107. const decimalPart = amountStr.substring(amountStr.length, amountStr.indexOf('.'))
  108. return `${integerPart.replace(reg, ',')}${decimalPart}`
  109. } else {
  110. return amountStr.replace(reg, ',')
  111. }
  112. }
  113. }