index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <script setup lang="ts">
  2. import {
  3. deleteChildren,
  4. getNodeByUniqueId,
  5. appendFieldByUniqueId
  6. } from "@/utils/tree";
  7. import { useDetail } from "./hooks";
  8. import { ref, computed } from "vue";
  9. import { clone } from "@pureadmin/utils";
  10. import { transformI18n } from "@/plugins/i18n";
  11. import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
  12. import { usePermissionStoreHook } from "@/store/modules/permission";
  13. defineOptions({
  14. name: "Tabs"
  15. });
  16. const { toDetail, router } = useDetail();
  17. const menusTree = clone(usePermissionStoreHook().wholeMenus, true);
  18. const treeData = computed(() => {
  19. return appendFieldByUniqueId(deleteChildren(menusTree), 0, {
  20. disabled: true
  21. });
  22. });
  23. const currentValues = ref<string[]>([]);
  24. const multiTags = computed(() => {
  25. return useMultiTagsStoreHook()?.multiTags;
  26. });
  27. function onCloseTags() {
  28. if (currentValues.value.length === 0) return;
  29. currentValues.value.forEach(uniqueId => {
  30. const currentPath =
  31. getNodeByUniqueId(treeData.value, uniqueId).redirect ??
  32. getNodeByUniqueId(treeData.value, uniqueId).path;
  33. useMultiTagsStoreHook().handleTags("splice", currentPath);
  34. if (currentPath === "/tabs/index")
  35. router.push({
  36. path: multiTags.value[(multiTags as any).value.length - 1].path
  37. });
  38. });
  39. }
  40. </script>
  41. <template>
  42. <el-card shadow="never">
  43. <template #header>
  44. <div class="font-medium">标签页复用,超出限制自动关闭</div>
  45. <el-link
  46. class="mt-2"
  47. href="https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/tabs"
  48. target="_blank"
  49. >
  50. 代码位置 src/views/tabs
  51. </el-link>
  52. </template>
  53. <div class="flex flex-wrap items-center">
  54. <p>query传参模式:</p>
  55. <el-button
  56. v-for="index in 6"
  57. :key="index"
  58. class="m-2!"
  59. @click="toDetail({ id: index }, 'query')"
  60. >
  61. 打开{{ index }}详情页
  62. </el-button>
  63. <el-button
  64. @click="
  65. toDetail({ id: 666, name: '小明', age: 18, job: '工程师' }, 'query')
  66. "
  67. >
  68. 多个参数
  69. </el-button>
  70. </div>
  71. <el-divider />
  72. <div class="flex flex-wrap items-center">
  73. <p>params传参模式:</p>
  74. <el-button
  75. v-for="index in 6"
  76. :key="index"
  77. class="m-2!"
  78. @click="toDetail({ id: index }, 'params')"
  79. >
  80. 打开{{ index }}详情页
  81. </el-button>
  82. </div>
  83. <el-divider />
  84. <el-tree-select
  85. v-model="currentValues"
  86. class="w-[300px]!"
  87. node-key="uniqueId"
  88. placeholder="请选择要关闭的标签"
  89. clearable
  90. multiple
  91. filterable
  92. default-expand-all
  93. :props="{
  94. label: data => transformI18n(data.meta.title),
  95. value: 'uniqueId',
  96. children: 'children',
  97. disabled: 'disabled'
  98. }"
  99. :data="treeData"
  100. >
  101. <template #default="{ data }">
  102. <span>{{ transformI18n(data.meta.title) }}</span>
  103. </template>
  104. </el-tree-select>
  105. <el-button class="m-2!" @click="onCloseTags">关闭标签</el-button>
  106. <el-divider />
  107. <el-button @click="router.push({ name: 'Menu1-2-2' })">
  108. 跳转页内菜单(传name对象,优先推荐)
  109. </el-button>
  110. <el-button @click="router.push('/nested/menu1/menu1-2/menu1-2-2')">
  111. 跳转页内菜单(直接传要跳转的路径)
  112. </el-button>
  113. <el-button
  114. @click="router.push({ path: '/nested/menu1/menu1-2/menu1-2-2' })"
  115. >
  116. 跳转页内菜单(传path对象)
  117. </el-button>
  118. <el-divider />
  119. <el-button
  120. @click="
  121. router.push({
  122. name: 'Menu1-2-2',
  123. query: { text: '传name对象,优先推荐' }
  124. })
  125. "
  126. >
  127. 携参跳转页内菜单(传name对象,优先推荐)
  128. </el-button>
  129. <el-button
  130. @click="
  131. router.push({
  132. path: '/nested/menu1/menu1-2/menu1-2-2',
  133. query: { text: '传path对象' }
  134. })
  135. "
  136. >
  137. 携参跳转页内菜单(传path对象)
  138. </el-button>
  139. <el-link
  140. class="ml-4"
  141. href="https://router.vuejs.org/zh/guide/essentials/navigation.html#%E5%AF%BC%E8%88%AA%E5%88%B0%E4%B8%8D%E5%90%8C%E7%9A%84%E4%BD%8D%E7%BD%AE"
  142. target="_blank"
  143. >
  144. 点击查看更多跳转方式
  145. </el-link>
  146. <el-divider />
  147. <el-button @click="router.push({ name: 'Empty' })">
  148. 跳转无Layout的空白页面
  149. </el-button>
  150. </el-card>
  151. </template>