quanyawei
2024-11-15 f752f50a484f63fc3786ab1c7ad563f3b17cce77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const state = {
  // 文件下载进度
  progressList: [],
  progressError: ''
}
const mutations = {
  SET_PROGRESS: (state, progressObj) => {
    // 修改进度列表
    console.log('Vuex', progressObj)
    if (state.progressList.length) {
      // 如果进度列表存在
      if (state.progressList.find(item => item.path == progressObj.path)) {
        // 前面说的path时间戳是唯一存在的,所以如果在进度列表中找到当前的进度对象
        state.progressList.find(
          item => item.path == progressObj.path
        ).progress = progressObj.progress
        // 改变当前进度对象的progress
      }
    } else {
      // 当前进度列表为空,没有下载任务,直接将该进度对象添加到进度数组内
      state.progressList.push(progressObj)
    }
  },
  DEL_PROGRESS: (state, props) => {
    state.progressList.splice(
      state.progressList.findIndex(item => item.path == props),
      1
    ) // 删除进度列表中的进度对象
  },
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  }
}
 
const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}
 
export default {
  namespaced: true,
  state,
  mutations,
  actions
}