materialSelectorFolderMixin.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import crumbs from "@/components/crumbs";
  2. import { nodeIdList2nodeInfoListByNodeTree } from "@/utils/other.js";
  3. import {
  4. getFolderTree,
  5. } from "@/api";
  6. import {i18n} from "@/lang"
  7. export default {
  8. components: {
  9. crumbs,
  10. },
  11. data() {
  12. return {
  13. folderTree: null,
  14. folderPath: [],
  15. }
  16. },
  17. computed: {
  18. currentFolderId() {
  19. return this.folderPath[this.folderPath.length - 1]?.id
  20. },
  21. },
  22. methods: {
  23. onClickPath(idx) {
  24. this.searchKey = ''
  25. this.folderPath = this.folderPath.slice(0, idx + 1)
  26. },
  27. onClickFolder(folder) {
  28. getFolderTree({
  29. type: this.currentMaterialType,
  30. }).then((res) => {
  31. this.folderTree = res.data
  32. const targetPathIdList = folder.ancestors.split(',').map((item) => {
  33. return Number(item)
  34. })
  35. targetPathIdList.push(folder.id)
  36. this.folderPath = nodeIdList2nodeInfoListByNodeTree(targetPathIdList, this.folderTree)
  37. this.searchKey = ''
  38. })
  39. },
  40. },
  41. watch: {
  42. currentFolderId: {
  43. handler: function (v1, v2) {
  44. if (v2 !== undefined) {
  45. this.refreshMaterialList(this.currentMaterialType)
  46. }
  47. },
  48. },
  49. },
  50. created() {
  51. this.folderPath.push({
  52. name: i18n.t(`gather.${this.currentMaterialType}`),
  53. id: 1,
  54. })
  55. }
  56. }