BreadCrumb.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="breadcrumb-wrapper">
  3. <div class="title">当前位置:</div>
  4. <a-input
  5. class="file-path-input"
  6. ref="filePathInputRef"
  7. placeholder="请输入路径"
  8. v-model:value="inputFilePath"
  9. size="small"
  10. :autoFocus="true"
  11. v-if="isShowInput"
  12. @blur="handleInputBlurEnter"
  13. @change="handleInputBlurEnter"
  14. ></a-input>
  15. <div
  16. class="breadcrumb-box"
  17. :class="{ 'able-input': fileType === 0 }"
  18. v-if="!isShowInput"
  19. @click.self="handleClickBreadCrumbSelf"
  20. >
  21. <a-breadcrumb v-if="![0, 8].includes(fileType) && !['Share'].includes(route.name)">
  22. <a-breadcrumb-item>{{ fileTypeMap[fileType] }}</a-breadcrumb-item>
  23. </a-breadcrumb>
  24. <a-breadcrumb v-else>
  25. <a-breadcrumb-item v-for="(item, index) in breadCrumbList" :key="index">
  26. <!-- <router-link :to="getRouteQuery(item)">{{ item.name }}</router-link> -->
  27. <span style="cursor: pointer" @click="setRouteQuery(item)">{{ item.name }}</span>
  28. </a-breadcrumb-item>
  29. </a-breadcrumb>
  30. </div>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { ref, computed, nextTick } from 'vue'
  35. import { useRoute, useRouter } from 'vue-router'
  36. import { useMyResourceStore } from '@/store/myResource'
  37. const myResourceStore = useMyResourceStore()
  38. const props = defineProps({
  39. // 文件类型
  40. fileType: {
  41. required: true,
  42. type: Number
  43. },
  44. // 文件路径
  45. filePath: {
  46. require: true,
  47. type: String
  48. }
  49. })
  50. const route = useRoute()
  51. const router = useRouter()
  52. const fileTypeMap = {
  53. 1: '全部图片',
  54. 2: '全部文档',
  55. 3: '全部视频',
  56. 4: '全部音乐',
  57. 5: '其他',
  58. 6: '回收站',
  59. // 7: '群文件',
  60. // 9: '团队文件',
  61. 10: '正在传输',
  62. 11: '传输完成',
  63. 12: '敏感词',
  64. 13: '敏感词过滤记录',
  65. 14: '跨文件传输记录',
  66. 15: '企业云盘'
  67. }
  68. const isShowInput = ref(false) // 是否展示路径输入框
  69. const inputFilePath = ref('') // 路径输入
  70. const filePathInputRef = ref(null)
  71. /**
  72. * 面包屑导航栏数组
  73. */
  74. const breadCrumbList = computed(() => {
  75. // let filePath = route.query.filePath
  76. let filePath = myResourceStore.getQuery.filePath ? myResourceStore.getQuery.filePath : '/'
  77. let filePathList = filePath ? filePath.split('/') : []
  78. let res = [] // 返回结果数组
  79. let _path = [] // 存放祖先路径
  80. for (let i = 0; i < filePathList.length; i++) {
  81. if (filePathList[i]) {
  82. _path.push(filePathList[i])
  83. res.push({
  84. path: _path.join('/'),
  85. name: filePathList[i]
  86. })
  87. } else if (i === 0) {
  88. // 根目录
  89. filePathList[i] = ''
  90. _path.push(filePathList[i])
  91. res.push({
  92. path: '/',
  93. name:
  94. props.fileType === 0
  95. ? '全部文件'
  96. : props.fileType === 8
  97. ? '我的分享'
  98. : route.name === 'Share'
  99. ? '全部分享'
  100. : ''
  101. })
  102. }
  103. }
  104. return res
  105. })
  106. /**
  107. * 点击面包屑导航栏空白处
  108. */
  109. const handleClickBreadCrumbSelf = () => {
  110. if (props.fileType === 0) {
  111. inputFilePath.value = props.filePath
  112. isShowInput.value = true
  113. nextTick(() => {
  114. filePathInputRef.value?.focus()
  115. })
  116. }
  117. }
  118. /**
  119. * 路径输入框失去焦点或用户按下回车时触发
  120. */
  121. const handleInputBlurEnter = () => {
  122. isShowInput.value = false
  123. if (inputFilePath.value !== props.filePath) {
  124. const fixInputFilePath = inputFilePath.value.endsWith('/')
  125. ? inputFilePath.value.slice(0, -1)
  126. : inputFilePath.value
  127. // router.push({
  128. // query: { filePath: `${fixInputFilePath}`, fileType: 0 }
  129. // })
  130. myResourceStore.changeQuery({ filePath: fixInputFilePath, fileType: 0 })
  131. }
  132. }
  133. // 获取文件参数
  134. const getRouteQuery = (item) => {
  135. let routeName = route.name
  136. if (routeName === 'Share') {
  137. // 当前是查看他人分享列表的页面
  138. return { query: { filePath: item.path } }
  139. } else if (props.fileType === 8) {
  140. // 当前是我的已分享列表页面
  141. return {
  142. query: {
  143. fileType: 8,
  144. filePath: item.path,
  145. shareBatchNum: item.path === '/' ? undefined : route.query.shareBatchNum // 当查看的是根目录,批次号置空
  146. }
  147. }
  148. } else {
  149. // 网盘页面
  150. return { query: { filePath: item.path, fileType: 0 } }
  151. }
  152. }
  153. const setRouteQuery = (item) => {
  154. let data = getRouteQuery(item)
  155. myResourceStore.changeQuery(data.query)
  156. }
  157. </script>
  158. <style lang="less" scoped>
  159. @import '@/style/myResource/varibles.less';
  160. .breadcrumb-wrapper {
  161. padding: 0;
  162. height: 30px;
  163. line-height: 30px;
  164. display: flex;
  165. .title,
  166. :deep(.ant-breadcrumb) {
  167. height: 30px;
  168. line-height: 30px;
  169. }
  170. .file-path-input {
  171. flex: 1;
  172. font-size: 14px;
  173. }
  174. .breadcrumb-box {
  175. padding: 0 8px;
  176. flex: 1;
  177. display: flex;
  178. &.able-input {
  179. cursor: pointer;
  180. &:hover {
  181. // background: @tabBackColor; // 假设 $tabBackColor 转换为 @tabBackColor
  182. }
  183. }
  184. }
  185. }
  186. </style>