dict.js 855 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const state = {
  2. dict: new Array()
  3. }
  4. const mutations = {
  5. SET_DICT: (state, { key, value }) => {
  6. if (key !== null && key !== "") {
  7. state.dict.push({
  8. key: key,
  9. value: value
  10. })
  11. }
  12. },
  13. REMOVE_DICT: (state, key) => {
  14. try {
  15. for (let i = 0; i < state.dict.length; i++) {
  16. if (state.dict[i].key == key) {
  17. state.dict.splice(i, i)
  18. return true
  19. }
  20. }
  21. } catch (e) {
  22. }
  23. },
  24. CLEAN_DICT: (state) => {
  25. state.dict = new Array()
  26. }
  27. }
  28. const actions = {
  29. // 设置字典
  30. setDict({ commit }, data) {
  31. commit('SET_DICT', data)
  32. },
  33. // 删除字典
  34. removeDict({ commit }, key) {
  35. commit('REMOVE_DICT', key)
  36. },
  37. // 清空字典
  38. cleanDict({ commit }) {
  39. commit('CLEAN_DICT')
  40. }
  41. }
  42. export default {
  43. namespaced: true,
  44. state,
  45. mutations,
  46. actions
  47. }