middle.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="hc-project-collect-middle hc-h-full">
  3. <div class="menu hc-h-full inline-block w-[180px]">
  4. <hc-card>
  5. <HcMenuBar :cur="menuKey" :datas="menuData" @change="menuChange" />
  6. </hc-card>
  7. </div>
  8. <div class="content hc-h-full inline-block">
  9. <AdminCreate v-if="menuKey === 'project-collect-admin-create'" :form="adminFormInfo" @back="adminCreateBack" />
  10. <AdminListe v-else-if="menuKey === 'project-collect-admin-list'" @edit="adminListeEdit" />
  11. <GistCreate v-else-if="menuKey === 'project-collect-gist-create'" :form="gistFormInfo" @back="gistCreateBack" />
  12. <GistListe v-else-if="menuKey === 'project-collect-gist-list'" @edit="gistListeEdit" />
  13. <hc-empty v-else />
  14. </div>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { onMounted, ref, watch } from 'vue'
  19. import { useAppStore } from '~src/store'
  20. import { useRoute, useRouter } from 'vue-router'
  21. import { isArray, isNullES } from 'js-fast-way'
  22. //子组件
  23. import HcMenuBar from '~src/layout/modules/MenuBar.vue'
  24. import AdminCreate from './admin/create.vue'
  25. import AdminListe from './admin/list.vue'
  26. import GistCreate from './gist/create.vue'
  27. import GistListe from './gist/list.vue'
  28. //初始化
  29. const router = useRouter()
  30. const useRoutes = useRoute()
  31. const store = useAppStore()
  32. //渲染完成
  33. onMounted(() => {
  34. getMenuDataKey(store.projectMenu)
  35. })
  36. //监听菜单变化
  37. watch(() => store.projectMenu, (menu) => {
  38. getMenuDataKey(menu)
  39. })
  40. //左侧菜单
  41. const menuKey = ref('')
  42. const menuData = ref([])
  43. const menuChange = ({ code }) => {
  44. adminFormInfo.value = {}
  45. gistFormInfo.value = {}
  46. menuKey.value = code
  47. router.push({
  48. path: useRoutes.path,
  49. query: { code },
  50. })
  51. }
  52. //获取菜单数据
  53. const getMenuDataKey = async (menu) => {
  54. if (!isArray(menu)) return
  55. //获取当前左侧菜单
  56. menuData.value = menu
  57. if (menu.length <= 0) return
  58. //获取当前页面key
  59. const df_key = await getMenuDefaultKey(menu)
  60. const { code } = useRoutes.query
  61. menuKey.value = code || df_key
  62. }
  63. //获取菜单默认key
  64. const getMenuDefaultKey = async (data) => {
  65. const children = data[0].children
  66. if (!isNullES(children) && children.length > 0) {
  67. return await getMenuDefaultKey(children)
  68. } else {
  69. return data[0].code
  70. }
  71. }
  72. //项目列表编辑
  73. const adminFormInfo = ref({})
  74. const adminListeEdit = (row) => {
  75. toCollectAdmin('project-collect-admin-create', row)
  76. }
  77. //返回
  78. const adminCreateBack = () => {
  79. toCollectAdmin('project-collect-admin-list')
  80. }
  81. //跳转到项目管理相关页面
  82. const toCollectAdmin = (code, row = {}) => {
  83. adminFormInfo.value = row
  84. menuKey.value = code
  85. router.push({
  86. path: useRoutes.path,
  87. query: { code },
  88. })
  89. }
  90. //工作要点列表编辑
  91. const gistFormInfo = ref({})
  92. const gistListeEdit = (row) => {
  93. toCollectGist('project-collect-gist-create', row)
  94. }
  95. //返回
  96. const gistCreateBack = () => {
  97. toCollectGist('project-collect-gist-list')
  98. }
  99. //跳转到工作要点相关页面
  100. const toCollectGist = (code, row = {}) => {
  101. gistFormInfo.value = row
  102. menuKey.value = code
  103. router.push({
  104. path: useRoutes.path,
  105. query: { code },
  106. })
  107. }
  108. </script>
  109. <style lang="scss">
  110. @import '~src/styles/project/middle';
  111. </style>