refactor: upload vuex module
This commit is contained in:
@@ -5,12 +5,12 @@ const getters = {
|
||||
isEditor: (state, getters) => getters.isFiles && (state.req.type === 'text' || state.req.type === 'textImmutable'),
|
||||
selectedCount: state => state.selected.length,
|
||||
progress : state => {
|
||||
if (state.uploading.progress.length == 0) {
|
||||
if (state.upload.progress.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let sum = state.uploading.progress.reduce((acc, val) => acc + val)
|
||||
return Math.ceil(sum / state.uploading.size * 100);
|
||||
let sum = state.upload.progress.reduce((acc, val) => acc + val)
|
||||
return Math.ceil(sum / state.upload.size * 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import mutations from './mutations'
|
||||
import getters from './getters'
|
||||
import upload from './modules/upload'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
@@ -22,18 +23,13 @@ const state = {
|
||||
show: null,
|
||||
showShell: false,
|
||||
showMessage: null,
|
||||
showConfirm: null,
|
||||
uploading: {
|
||||
id: 0,
|
||||
count: 0,
|
||||
size: 0,
|
||||
progress: []
|
||||
}
|
||||
showConfirm: null
|
||||
}
|
||||
|
||||
export default new Vuex.Store({
|
||||
strict: true,
|
||||
state,
|
||||
getters,
|
||||
mutations
|
||||
mutations,
|
||||
modules: { upload }
|
||||
})
|
||||
|
||||
34
frontend/src/store/modules/upload.js
Normal file
34
frontend/src/store/modules/upload.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const state = {
|
||||
id: 0,
|
||||
count: 0,
|
||||
size: 0,
|
||||
progress: []
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
incrementId: (state) => {
|
||||
state.id = state.id + 1
|
||||
},
|
||||
incrementSize: (state, value) => {
|
||||
state.size = state.size + value
|
||||
},
|
||||
incrementCount: (state) => {
|
||||
state.count = state.count + 1
|
||||
},
|
||||
decreaseCount: (state) => {
|
||||
state.count = state.count - 1
|
||||
},
|
||||
setProgress(state, { id, loaded }) {
|
||||
Vue.set(state.progress, id, loaded)
|
||||
},
|
||||
reset: (state) => {
|
||||
state.id = 0
|
||||
state.size = 0
|
||||
state.count = 0
|
||||
state.progress = []
|
||||
}
|
||||
}
|
||||
|
||||
export default { state, mutations, namespaced: true }
|
||||
@@ -1,4 +1,3 @@
|
||||
import Vue from 'vue'
|
||||
import * as i18n from '@/i18n'
|
||||
import moment from 'moment'
|
||||
|
||||
@@ -83,28 +82,6 @@ const mutations = {
|
||||
resetClipboard: (state) => {
|
||||
state.clipboard.key = ''
|
||||
state.clipboard.items = []
|
||||
},
|
||||
|
||||
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