diff --git a/src/main.js b/src/main.js index 9dede23..8b84ae3 100644 --- a/src/main.js +++ b/src/main.js @@ -24,5 +24,8 @@ new Vue({ router, store, i18n, - render: h => h(App) + render: h => h(App), + mounted() { + this.$store.dispatch('acrou/view/load') + } }).$mount('#app') diff --git a/src/store/modules/acrou/modules/view.js b/src/store/modules/acrou/modules/view.js new file mode 100644 index 0000000..55c6402 --- /dev/null +++ b/src/store/modules/acrou/modules/view.js @@ -0,0 +1,69 @@ +export default { + namespaced: true, + state: { + // 视图模式 + mode: "list", + }, + actions: { + /** + * @description 从持久化数据读取视图模式设置 + * @param {Object} context + */ + load({ state, dispatch, commit }) { + // eslint-disable-next-line no-async-promise-executor + return new Promise(async (resolve) => { + // store 赋值 + state.mode = await dispatch( + "acrou/db/get", + { + dbName: "sys", + path: "view.mode.value", + defaultValue: "list", + user: true, + }, + { root: true } + ); + // 应用 + commit("set", state.mode); + // end + resolve(); + }); + }, + /** + * @description 切换视图模式 + * @param {Object} context + */ + toggle({ state, dispatch, commit }, mode) { + // eslint-disable-next-line no-async-promise-executor + return new Promise(async (resolve) => { + // store 赋值 + state.mode = mode || "list"; + // 持久化 + await dispatch( + "acrou/db/set", + { + dbName: "sys", + path: "view.mode.value", + value: state.mode, + user: true, + }, + { root: true } + ); + // 应用 + commit("set", state.mode); + // end + resolve(); + }); + }, + }, + mutations: { + /** + * @description 设置 store 里的视图模式 + * @param {Object} state state + * @param {Boolean} mode mode + */ + set(state, mode) { + state.mode = mode; + }, + }, +}; diff --git a/src/views/common/BreadCrumb.vue b/src/views/common/BreadCrumb.vue index a0bcecc..44d3b40 100644 --- a/src/views/common/BreadCrumb.vue +++ b/src/views/common/BreadCrumb.vue @@ -8,15 +8,21 @@