refactor: uploading counters vuex state
This commit is contained in:
@@ -3,7 +3,15 @@ const getters = {
|
||||
isFiles: state => !state.loading && state.route.name === 'Files',
|
||||
isListing: (state, getters) => getters.isFiles && state.req.isDir,
|
||||
isEditor: (state, getters) => getters.isFiles && (state.req.type === 'text' || state.req.type === 'textImmutable'),
|
||||
selectedCount: state => state.selected.length
|
||||
selectedCount: state => state.selected.length,
|
||||
progress : state => {
|
||||
if (state.uploading.progress.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let sum = state.uploading.progress.reduce((acc, val) => acc + val)
|
||||
return Math.ceil(sum / state.uploading.size * 100);
|
||||
}
|
||||
}
|
||||
|
||||
export default getters
|
||||
|
||||
@@ -22,7 +22,13 @@ const state = {
|
||||
show: null,
|
||||
showShell: false,
|
||||
showMessage: null,
|
||||
showConfirm: null
|
||||
showConfirm: null,
|
||||
uploading: {
|
||||
id: 0,
|
||||
count: 0,
|
||||
size: 0,
|
||||
progress: []
|
||||
}
|
||||
}
|
||||
|
||||
export default new Vuex.Store({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import Vue from 'vue'
|
||||
import * as i18n from '@/i18n'
|
||||
import moment from 'moment'
|
||||
|
||||
@@ -83,8 +84,27 @@ const mutations = {
|
||||
state.clipboard.key = ''
|
||||
state.clipboard.items = []
|
||||
},
|
||||
setProgress: (state, value) => {
|
||||
state.progress = value
|
||||
|
||||
uploadingIncrementId: (state) => {
|
||||
state.uploading.id = state.uploading.id + 1
|
||||
},
|
||||
uploadingIncrementSize: (state, value) => {
|
||||
state.uploading.size = state.uploading.size + value
|
||||
},
|
||||
uploadingIncrementCount: (state) => {
|
||||
state.uploading.count = state.uploading.count + 1
|
||||
},
|
||||
uploadingDecreaseCount: (state) => {
|
||||
state.uploading.count = state.uploading.count - 1
|
||||
},
|
||||
uploadigSetProgress(state, { id, loaded }) {
|
||||
Vue.set(state.uploading.progress, id, loaded)
|
||||
},
|
||||
uploadingReset: (state) => {
|
||||
state.uploading.id = 0
|
||||
state.uploading.size = 0
|
||||
state.uploading.count = 0
|
||||
state.uploading.progress = []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user