spotCheck.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import Layout from '@/layout/index'
  2. import ParentView from '@/components/ParentView';
  3. import InnerLink from '@/layout/components/InnerLink'
  4. import router from '@/router'
  5. import store from '@/store'
  6. import { constantRoutes } from '@/router'
  7. export var loadView = (view) => {
  8. return (resolve) => require([`@/views/${view}`], resolve)
  9. }
  10. let spotRouter = [{
  11. "menuId": 11220,
  12. "name": "SecondJian",
  13. "path": "/secondJian",
  14. "hidden": false,
  15. "redirect": "noRedirect",
  16. "component": "Layout",
  17. "alwaysShow": true,
  18. "meta": {
  19. "title": "二建监管平台",
  20. "icon": "date-range",
  21. "noCache": false
  22. },
  23. "children": [
  24. {
  25. "menuId": 11219,
  26. "name": "CourseListJian",
  27. "path": "courseListJian",
  28. "hidden": false,
  29. "component": "secondJian/courseList",
  30. "meta": {
  31. "title": "课程列表",
  32. "icon": "#",
  33. "noCache": false
  34. }
  35. },
  36. {
  37. "menuId": 11222,
  38. "name": "CompletionListJian",
  39. "path": "completionListJian",
  40. "hidden": false,
  41. "component": "secondJian/completionList",
  42. "meta": {
  43. "title": "完成列表",
  44. "icon": "#",
  45. "noCache": false
  46. }
  47. }, {
  48. "menuId": 11223,
  49. "name": "LearningListJian",
  50. "path": "learningListJian",
  51. "hidden": false,
  52. "component": "secondJian/learningList",
  53. "meta": {
  54. "title": "学习列表",
  55. "icon": "#",
  56. "noCache": false
  57. }
  58. }]
  59. }, {
  60. "menuId": 11221,
  61. "name": "SecondZao",
  62. "path": "/secondZao",
  63. "hidden": false,
  64. "redirect": "noRedirect",
  65. "component": "Layout",
  66. "alwaysShow": true,
  67. "meta": {
  68. "title": "二造监管平台",
  69. "icon": "druid",
  70. "noCache": false
  71. },
  72. "children": [
  73. {
  74. "menuId": 11224,
  75. "name": "CourseListZao",
  76. "path": "courseListZao",
  77. "hidden": false,
  78. "component": "secondZao/courseList",
  79. "meta": {
  80. "title": "课程列表",
  81. "icon": "#",
  82. "noCache": false
  83. }
  84. },
  85. {
  86. "menuId": 11225,
  87. "name": "CompletionListZao",
  88. "path": "completionListZao",
  89. "hidden": false,
  90. "component": "secondZao/completionList",
  91. "meta": {
  92. "title": "完成列表",
  93. "icon": "#",
  94. "noCache": false
  95. }
  96. }, {
  97. "menuId": 11226,
  98. "name": "LearningListZao",
  99. "path": "learningListZao",
  100. "hidden": false,
  101. "component": "secondZao/learningList",
  102. "meta": {
  103. "title": "学习列表",
  104. "icon": "#",
  105. "noCache": false
  106. }
  107. }]
  108. }, {
  109. "menuId": 11227,
  110. "path": "/",
  111. "hidden": true,
  112. "component": "Layout",
  113. "children": [{
  114. "name": "ClassHoursReviews",
  115. "path": "classHoursReviews",
  116. "hidden": false,
  117. "component": "classHoursReview",
  118. "meta": {
  119. "title": "学时审核",
  120. "icon": "#",
  121. "noCache": false
  122. }
  123. }]
  124. }]
  125. export function spotCheckFunc(li) {
  126. ///根据缓存数据筛选分类二建二造菜单
  127. const path = li.type == 1 ? '/secondJian' : li.type == 2 ? '/secondZao' : null
  128. const mapSpotRouter = spotRouter.filter(i => i.path === path || i.path === '/')
  129. const sidebarRoutes = filterAsyncRouter(JSON.parse(JSON.stringify(mapSpotRouter)))
  130. const rewriteRoutes = filterAsyncRouter(JSON.parse(JSON.stringify(mapSpotRouter)), false, true)
  131. rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
  132. store.commit('SET_ROUTES', rewriteRoutes)
  133. store.commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
  134. store.commit('SET_DEFAULT_ROUTES', sidebarRoutes)
  135. store.commit('SET_TOPBAR_ROUTES', sidebarRoutes)
  136. router.addRoutes(rewriteRoutes) // 动态添加可访问路由表
  137. }
  138. export function checkSession(row) {
  139. return new Promise((resolve, reject) => {
  140. const SESSION = sessionStorage.getItem("hoursAudit");
  141. try {
  142. if (SESSION) {
  143. let parseSession = JSON.parse(SESSION);
  144. const STATUS = parseSession.options.some((item) => {
  145. return (
  146. item.userId == row.userId &&
  147. item.goodsId == row.goodsId &&
  148. item.id == row.id &&
  149. item.orderGoodsId == row.orderGoodsId
  150. );
  151. });
  152. if (!STATUS) {
  153. parseSession.options.push(row);
  154. }
  155. parseSession.activeData = `${row.userId}-${row.goodsId}-${row.id}-${row.orderGoodsId}`;
  156. sessionStorage.setItem("hoursAudit", JSON.stringify(parseSession));
  157. } else {
  158. let data = {
  159. activeData: `${row.userId}-${row.goodsId}-${row.id}-${row.orderGoodsId}`,
  160. options: [row],
  161. };
  162. sessionStorage.setItem("hoursAudit", JSON.stringify(data));
  163. }
  164. resolve();
  165. } catch (error) {
  166. reject();
  167. }
  168. });
  169. }
  170. // 遍历后台传来的路由字符串,转换为组件对象
  171. function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
  172. return asyncRouterMap.filter(route => {
  173. if (type && route.children) {
  174. route.children = filterChildren(route.children)
  175. }
  176. if (route.component) {
  177. // Layout ParentView 组件特殊处理
  178. if (route.component === 'Layout') {
  179. route.component = Layout
  180. } else if (route.component === 'ParentView') {
  181. route.component = ParentView
  182. } else if (route.component === 'InnerLink') {
  183. route.component = InnerLink
  184. } else {
  185. route.component = loadView(route.component)
  186. }
  187. }
  188. if (route.children != null && route.children && route.children.length) {
  189. route.children = filterAsyncRouter(route.children, route, type)
  190. } else {
  191. delete route['children']
  192. delete route['redirect']
  193. }
  194. return true
  195. })
  196. }
  197. function filterChildren(childrenMap, lastRouter = false) {
  198. var children = []
  199. childrenMap.forEach((el, index) => {
  200. if (el.children && el.children.length) {
  201. if (el.component === 'ParentView' && !lastRouter) {
  202. el.children.forEach(c => {
  203. c.path = el.path + '/' + c.path
  204. if (c.children && c.children.length) {
  205. children = children.concat(filterChildren(c.children, c))
  206. return
  207. }
  208. children.push(c)
  209. })
  210. return
  211. }
  212. }
  213. if (lastRouter) {
  214. el.path = lastRouter.path + '/' + el.path
  215. }
  216. children = children.concat(el)
  217. })
  218. return children
  219. }