myResource.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { defineStore } from 'pinia'
  2. import { getStorage } from '@/api/myResource/file'
  3. import { checkUserLoginInfo } from '@/api/myResource/user'
  4. import { message } from 'ant-design-vue'
  5. export const useMyResourceStore = defineStore('myResource', {
  6. state: () => ({
  7. showUploadMask: false,
  8. // 表格中显示的列
  9. selectedColumnList: localStorage.getItem('qiwen_selected_column_list'),
  10. // 文件展示模式 0 列表模式 | 1 网格模式 | 2 时间线模式
  11. fileModel: localStorage.getItem('qiwen_file_model'),
  12. // 网格模式 & 时间线模式下 图标大小 单位px
  13. gridSize: localStorage.getItem('qiwen_grid_size') ? Number(localStorage.getItem('qiwen_grid_size')) : 80,
  14. // 批量模式下:被选中的文件列表
  15. selectedFiles: [],
  16. // 是否批量操作:true - 批量,false - 单文件
  17. isBatchOperation: false,
  18. isAdmin: -1,
  19. screenWidth: document.body.clientWidth, // 屏幕宽度
  20. storageValue: 0, // 文件已占用的存储空间大小
  21. totalStorageValue: 0,
  22. isLogin: localStorage.getItem('qiwen_isLogin') === 'true', // 用户登录状态
  23. userInfoObj: {}, // 用户信息
  24. query: {} //路径信息
  25. }),
  26. getters: {
  27. // 登录状态
  28. getIsLogin: (state) => state.isLogin,
  29. // 用户姓名
  30. getUsername: (state) => state.userInfoObj.username,
  31. // 用户ID
  32. getUserId: (state) => state.userInfoObj.userId,
  33. getIsAdmin: (state) => state.isAdmin,
  34. // 表格显示列
  35. getSelectedColumnList: (state) =>
  36. state.selectedColumnList === null
  37. ? [] // 假设 allColumnList 是一个空数组,如果它有其他来源,请您自行补充
  38. : state.selectedColumnList.split(','),
  39. // 文件查看模式
  40. getFileModel: (state) => (state.fileModel === null ? 0 : Number(state.fileModel)),
  41. // 网格模式 & 时间线模式下 文件图标大小
  42. getGridSize: (state) => state.gridSize,
  43. // 剩余存储空间
  44. getRemainderStorageValue: (state) => state.totalStorageValue - state.storageValue,
  45. getQuery: (state) => state.query
  46. },
  47. actions: {
  48. changeQuery(data) {
  49. this.query = data
  50. },
  51. toggleUploadMask() {
  52. this.showUploadMask = !this.showUploadMask
  53. },
  54. /**
  55. * 改变表格显示列
  56. * @description 表格显示列保存在 Pinia 和 cookie 中
  57. * @param {[]} data 表格需要显示的列数组
  58. */
  59. changeSelectedColumnList(data) {
  60. localStorage.setItem('qiwen_selected_column_list', data.toString())
  61. this.selectedColumnList = data.toString()
  62. },
  63. /**
  64. * 改变文件展示模式
  65. * @description 文件展示模式保存在 Pinia 和 cookie 中
  66. * @param {string} data 文件展示模式
  67. */
  68. changeFileModel(data) {
  69. localStorage.setItem('qiwen_file_model', data)
  70. this.fileModel = data
  71. },
  72. /**
  73. * 网格模式 & 时间线模式 改变文件图标大小
  74. * @description 文件图标大小保存在 Pinia 和 cookie 中
  75. * @param {string} data 文件图标大小
  76. */
  77. changeGridSize(data) {
  78. localStorage.setItem('qiwen_grid_size', data)
  79. this.gridSize = data
  80. },
  81. /**
  82. * 设置批量操作模式下被选中的文件列表
  83. * @param {array} data 批量操作模式下,被选中的文件列表
  84. */
  85. changeSelectedFiles(data) {
  86. this.selectedFiles = data
  87. },
  88. /**
  89. * 设置是否批量操作
  90. * @param {boolean} data 是否批量操作
  91. */
  92. changeIsBatchOperation(data) {
  93. this.isBatchOperation = data
  94. },
  95. changeIsAdmin(data) {
  96. this.isAdmin = data
  97. },
  98. /**
  99. * 改变屏幕宽度
  100. * @param {[]} data 屏幕宽度
  101. */
  102. changeScreenWidth(data) {
  103. this.screenWidth = data
  104. },
  105. /**
  106. * 获取文件已占用的存储空间
  107. */
  108. async showStorage() {
  109. try {
  110. const res = await getStorage()
  111. if (res.success) {
  112. this.storageValue = res.data ? (res.data.storageSize === null ? 0 : Number(res.data.storageSize)) : 0
  113. this.totalStorageValue = res.data
  114. ? res.data.totalStorageSize === null
  115. ? 0
  116. : Number(res.data.totalStorageSize)
  117. : 0
  118. } else {
  119. message.error(res.message)
  120. }
  121. } catch (error) {
  122. message.error('获取存储空间失败')
  123. }
  124. },
  125. /**
  126. * 获取用户信息
  127. */
  128. async getUserInfo() {
  129. this.isLogin = true
  130. localStorage.setItem('qiwen_isLogin', 'true')
  131. // try {
  132. // const res = await checkUserLoginInfo()
  133. // if (res.success) {
  134. // this.isLogin = true
  135. // this.userInfoObj = Object.assign({}, res.data.userInfoObj, data)
  136. // } else {
  137. // this.isLogin = false
  138. // this.userInfoObj = {}
  139. // }
  140. // } catch (error) {
  141. // this.isLogin = false
  142. // this.userInfoObj = {}
  143. // }
  144. }
  145. }
  146. })