sideMenu.js 905 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { getStorage } from '_r/file.js'
  2. export default {
  3. state: {
  4. storageValue: 0, // 文件已占用的存储空间大小
  5. totalStorageValue: 0
  6. },
  7. mutations: {
  8. /**
  9. * 保存文件已占用的存储空间大小
  10. * @param {object} state Vuex 的 state 对象
  11. * @param {number} data 存储大小
  12. */
  13. setStorageValue(state, data) {
  14. state.storageValue = data
  15. },
  16. setTotalStorageValue(state, data) {
  17. state.totalStorageValue = data
  18. }
  19. },
  20. actions: {
  21. /**
  22. * 获取文件已占用的存储空间
  23. */
  24. showStorage(context) {
  25. return getStorage().then((res) => {
  26. if (res.success) {
  27. context.commit(
  28. 'setStorageValue',
  29. res.data ? Number(res.data.storageSize) : 0
  30. )
  31. context.commit(
  32. 'setTotalStorageValue',
  33. res.data ? Number(res.data.totalStorageSize) : 0
  34. )
  35. } else {
  36. this.$message.error(res.message)
  37. }
  38. })
  39. }
  40. }
  41. }