| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import { defineStore } from 'pinia'
- import { getStorage } from '@/api/myResource/file'
- import { checkUserLoginInfo } from '@/api/myResource/user'
- import { message } from 'ant-design-vue'
- export const useMyResourceStore = defineStore('myResource', {
- state: () => ({
- showUploadMask: false,
- // 表格中显示的列
- selectedColumnList: localStorage.getItem('qiwen_selected_column_list'),
- // 文件展示模式 0 列表模式 | 1 网格模式 | 2 时间线模式
- fileModel: localStorage.getItem('qiwen_file_model'),
- // 网格模式 & 时间线模式下 图标大小 单位px
- gridSize: localStorage.getItem('qiwen_grid_size') ? Number(localStorage.getItem('qiwen_grid_size')) : 80,
- // 批量模式下:被选中的文件列表
- selectedFiles: [],
- // 是否批量操作:true - 批量,false - 单文件
- isBatchOperation: false,
- isAdmin: -1,
- screenWidth: document.body.clientWidth, // 屏幕宽度
- storageValue: 0, // 文件已占用的存储空间大小
- totalStorageValue: 0,
- isLogin: localStorage.getItem('qiwen_isLogin') === 'true', // 用户登录状态
- userInfoObj: {}, // 用户信息
- query: {} //路径信息
- }),
- getters: {
- // 登录状态
- getIsLogin: (state) => state.isLogin,
- // 用户姓名
- getUsername: (state) => state.userInfoObj.username,
- // 用户ID
- getUserId: (state) => state.userInfoObj.userId,
- getIsAdmin: (state) => state.isAdmin,
- // 表格显示列
- getSelectedColumnList: (state) =>
- state.selectedColumnList === null
- ? [] // 假设 allColumnList 是一个空数组,如果它有其他来源,请您自行补充
- : state.selectedColumnList.split(','),
- // 文件查看模式
- getFileModel: (state) => (state.fileModel === null ? 0 : Number(state.fileModel)),
- // 网格模式 & 时间线模式下 文件图标大小
- getGridSize: (state) => state.gridSize,
- // 剩余存储空间
- getRemainderStorageValue: (state) => state.totalStorageValue - state.storageValue,
- getQuery: (state) => state.query
- },
- actions: {
- changeQuery(data) {
- this.query = data
- },
- toggleUploadMask() {
- this.showUploadMask = !this.showUploadMask
- },
- /**
- * 改变表格显示列
- * @description 表格显示列保存在 Pinia 和 cookie 中
- * @param {[]} data 表格需要显示的列数组
- */
- changeSelectedColumnList(data) {
- localStorage.setItem('qiwen_selected_column_list', data.toString())
- this.selectedColumnList = data.toString()
- },
- /**
- * 改变文件展示模式
- * @description 文件展示模式保存在 Pinia 和 cookie 中
- * @param {string} data 文件展示模式
- */
- changeFileModel(data) {
- localStorage.setItem('qiwen_file_model', data)
- this.fileModel = data
- },
- /**
- * 网格模式 & 时间线模式 改变文件图标大小
- * @description 文件图标大小保存在 Pinia 和 cookie 中
- * @param {string} data 文件图标大小
- */
- changeGridSize(data) {
- localStorage.setItem('qiwen_grid_size', data)
- this.gridSize = data
- },
- /**
- * 设置批量操作模式下被选中的文件列表
- * @param {array} data 批量操作模式下,被选中的文件列表
- */
- changeSelectedFiles(data) {
- this.selectedFiles = data
- },
- /**
- * 设置是否批量操作
- * @param {boolean} data 是否批量操作
- */
- changeIsBatchOperation(data) {
- this.isBatchOperation = data
- },
- changeIsAdmin(data) {
- this.isAdmin = data
- },
- /**
- * 改变屏幕宽度
- * @param {[]} data 屏幕宽度
- */
- changeScreenWidth(data) {
- this.screenWidth = data
- },
- /**
- * 获取文件已占用的存储空间
- */
- async showStorage() {
- try {
- const res = await getStorage()
- if (res.success) {
- this.storageValue = res.data ? (res.data.storageSize === null ? 0 : Number(res.data.storageSize)) : 0
- this.totalStorageValue = res.data
- ? res.data.totalStorageSize === null
- ? 0
- : Number(res.data.totalStorageSize)
- : 0
- } else {
- message.error(res.message)
- }
- } catch (error) {
- message.error('获取存储空间失败')
- }
- },
- /**
- * 获取用户信息
- */
- async getUserInfo() {
- this.isLogin = true
- localStorage.setItem('qiwen_isLogin', 'true')
- // try {
- // const res = await checkUserLoginInfo()
- // if (res.success) {
- // this.isLogin = true
- // this.userInfoObj = Object.assign({}, res.data.userInfoObj, data)
- // } else {
- // this.isLogin = false
- // this.userInfoObj = {}
- // }
- // } catch (error) {
- // this.isLogin = false
- // this.userInfoObj = {}
- // }
- }
- }
- })
|