diff --git a/package.json b/package.json index d519e1a..bc958bb 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ }, "dependencies": { "@riophae/vue-treeselect": "^0.0.38", - "D": "^1.0.0", "animate.css": "^3.7.2", "axios": "^0.19.0", "core-js": "^2.6.5", diff --git a/src/myview/index.js b/src/myview/index.js index 23ba20c..6dc3164 100644 --- a/src/myview/index.js +++ b/src/myview/index.js @@ -2,7 +2,7 @@ import CopyRight from './components/CopyRight' import WhiteSpace from './components/WhiteSpace' import Label from './components/Label' import LabelGroup from './components/LabelGroup' -import Card from '..component/Card' +import Card from './components/Card' const components = { CopyRight, diff --git a/src/router/route.js b/src/router/route.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/store/app.js b/src/store/app.js deleted file mode 100644 index 642e211..0000000 --- a/src/store/app.js +++ /dev/null @@ -1,67 +0,0 @@ -import Vue from 'vue' -import Vuex from 'vuex' - -Vue.use(Vuex) - -const state = { - currentPage: {}, - cachePages: [], - expandMisMenu: false, - loading: false -} - -const getters = { - getCurrentPage (state) { - return state.currentPage - }, - getCachePages (state) { - return state.cachePages - }, - getCachePagesKeys (state) { - // TODO 用于页面缓存 - }, - getExpandMisMenu (state) { - return state.expandMisMenu - }, - getLoading (state) { - return state.loading - } -} - -const mutations = { - changeExpandMisMenu (state) { - let { expandMisMenu } = { ...state } - state.expandMisMenu = !expandMisMenu - }, - loadingStart (state) { - state.loading = true - }, - loadingFinish (state) { - state.loading = false - } -} - -/** - * @description actions 当中包含异步操作 - * @type {{UPDATECACHEPAGES(*, *=): void}} - */ -const actions = { - CHANGEEXPANDMISMENU (context) { - context.commit('changeExpandMisMenu') - }, - LOADINGSTART (context) { - context.commit('loadingStart') - }, - LOADINGFINISHED (context) { - context.commit('loadingFinish') - } -} - -const appnew = { - state, - getters, - mutations, - actions -} - -export default appnew diff --git a/src/store/index.d.ts b/src/store/index.d.ts deleted file mode 100644 index 5d18f42..0000000 --- a/src/store/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import Vuex from 'vuex-class' -// FIXME 稍后使用typescript进行重构 -declare var store: any diff --git a/src/store/index.js b/src/store/index.ts similarity index 79% rename from src/store/index.js rename to src/store/index.ts index 54c3a02..db26676 100644 --- a/src/store/index.js +++ b/src/store/index.ts @@ -1,8 +1,8 @@ import Vue from 'vue' import Vuex from 'vuex' -import app from './app' -import user from './user' +import app from './newapp' +import user from './newuser' Vue.use(Vuex) diff --git a/src/store/newapp/index.ts b/src/store/newapp/index.ts new file mode 100644 index 0000000..d83411f --- /dev/null +++ b/src/store/newapp/index.ts @@ -0,0 +1,71 @@ +import { State } from './interface' +import { Menu } from '../newuser/interface' +import { Commit } from 'vuex' + +const state: State = { + currentPage: null, + cachePages: [], + expandMisMenu: false, + loading: false +} + +const getters = { + getCurrentPage: (state: State) => state.currentPage, + getCachePages: (state: State) => state.cachePages, + getCachePagesKeys: (state: State) => state.cachePages, + getExpandMisMenu: (state: State) => state.expandMisMenu, + getLoading: (state: State) => state.loading +} + +const mutations = { + updateCurrentPage: (state: State, menu: Menu) => { + state.currentPage = menu + }, + updateCachePages: (state: State, menu: Menu) => { + let isHave: Boolean = false + let { cachePages } = { ...state } + cachePages.forEach((item: Menu) => { + if (item.mid === menu.mid) { + isHave = true + } + }) + if (!isHave) { + state.cachePages.push(menu) + } + }, + changeExpandMisMenu: (state: State) => { + let { expandMisMenu } = { ...state } + state.expandMisMenu = !expandMisMenu + }, + loadingStart: (state: State) => { + state.loading = true + }, + loadingFinish: (state: State) => { + state.loading = false + } +} + +const actions = { + UPDATECURRENTPAGE: (context: { commit: Commit }, menu: Menu) => { + context.commit('updateCurrentPage', menu) + context.commit('updateCachePages', menu) + }, + CHANGEEXPANDMISMENU: (context: { commit: Commit }) => { + context.commit('changeExpandMisMenu') + }, + LOADINGSTART: (context: { commit: Commit }) => { + context.commit('loadingStart') + }, + LOADINGFINISHED: (context: { commit: Commit }) => { + context.commit('loadingFinish') + } +} + +const newapp = { + state, + getters, + mutations, + actions +} + +export default newapp diff --git a/src/store/newapp/interface.ts b/src/store/newapp/interface.ts new file mode 100644 index 0000000..f69c3bf --- /dev/null +++ b/src/store/newapp/interface.ts @@ -0,0 +1,8 @@ +import { Menu } from '../newuser/interface' + +export interface State { + currentPage: Menu | null, + cachePages: Array, + expandMisMenu: boolean, + loading: boolean +} diff --git a/src/store/user.js b/src/store/newuser/index.ts similarity index 51% rename from src/store/user.js rename to src/store/newuser/index.ts index 692ae6f..e634e7b 100644 --- a/src/store/user.js +++ b/src/store/newuser/index.ts @@ -1,25 +1,21 @@ -import Vue from 'vue' -import Vuex from 'vuex' +import { State, CurrentUser } from './interface' +import { Commit } from 'vuex' -Vue.use(Vuex) +const currentUser: CurrentUser = { + user: {}, + menu: [], + dept: {} +} -const state = { - currentUser: { - user: {}, - menu: [], - dept: {} - }, +const state: State = { + currentUser, isLogin: false } const getters = { - getUser (state) { - return state.currentUser.user - }, - getMenu (state) { - return state.currentUser.menu - }, - getMenuTree (state) { + getUser: (state: State) => state.currentUser.user, + getMenu: (state: State) => state.currentUser.menu, + getMenuTree: (state: State) => { let { menu } = { ...state.currentUser } // 找到一级菜单 let menuTree = menu.filter(_menu => _menu.mlevel === 1) @@ -29,39 +25,35 @@ const getters = { } return menuTree }, - getDept (state) { - return state.currentUser.dept - }, - getLogin (state) { - return state.isLogin - } + getDept: (state: State) => state.currentUser.dept, + getLogin: (state: State) => state.isLogin } const mutations = { - updateCurrentUser (state, currentUser) { + updateCurrentUser: (state: State, currentUser: CurrentUser) => { state.currentUser = currentUser }, - changeLogin (state) { + changeLogin: (state: State) => { const { isLogin } = { ...state } state.isLogin = !isLogin } } const actions = { - UPDATECURRENTUSER (context, currentUser) { + UPDATECURRENTUSER (context: {commit: Commit}, currentUser: CurrentUser) { context.commit('updateCurrentUser', currentUser) context.commit('changeLogin', currentUser) }, - CHANGELOGIN (context) { + CHANGELOGIN (context: {commit: Commit}) { context.commit('changeLogin') } } -const usernew = { +const newuser = { state, getters, mutations, actions } -export default usernew +export default newuser diff --git a/src/store/newuser/interface.ts b/src/store/newuser/interface.ts new file mode 100644 index 0000000..70df0f8 --- /dev/null +++ b/src/store/newuser/interface.ts @@ -0,0 +1,24 @@ +export interface Menu { + mid: number, + mkey: String, + mname: String, + micon: String, + mpath: String, + mtip: String, + mrender: String, + mpid: number, + mlevel: Number, + mstatus: Number, + child?: Array +} + +export interface CurrentUser { + user: any, + menu: Array, + dept: any +} + +export interface State { + currentUser: CurrentUser, + isLogin: boolean +} diff --git a/src/views/mis/MisContainer.vue b/src/views/mis/MisContainer.vue index ad2606d..32b50c3 100644 --- a/src/views/mis/MisContainer.vue +++ b/src/views/mis/MisContainer.vue @@ -29,7 +29,7 @@ - + @@ -56,8 +56,25 @@ export default { showSetting: false } }, + watch: { + $route: { + handler (to, from) { + let getMenu = this.getMenu + let menu = false + for (let _menu of getMenu) { + if (_menu.mkey === to.name) { + menu = _menu + } + } + if (menu) { + this.$store.dispatch('UPDATECURRENTPAGE', menu) + } + }, + immediate: true + } + }, computed: { - ...mapGetters(['getLogin', 'getExpandMisMenu', 'getLoading']) + ...mapGetters(['getLogin', 'getExpandMisMenu', 'getLoading', 'getMenu', 'getCurrentPage', 'getCachePages']) }, methods: { handleSiderTrigger () { diff --git a/src/views/mis/components/MisMenu/MisMenu.vue b/src/views/mis/components/MisMenu/MisMenu.vue index 3831fdb..e03affa 100644 --- a/src/views/mis/components/MisMenu/MisMenu.vue +++ b/src/views/mis/components/MisMenu/MisMenu.vue @@ -33,33 +33,27 @@ - diff --git a/src/views/mis/components/MisTab/MisTab.vue b/src/views/mis/components/MisTab/MisTab.vue index 5fe87d4..1e21b8c 100644 --- a/src/views/mis/components/MisTab/MisTab.vue +++ b/src/views/mis/components/MisTab/MisTab.vue @@ -13,15 +13,12 @@ - diff --git a/src/views/mis/components/MisTabNavi/MisTabNavi.vue b/src/views/mis/components/MisTabNavi/MisTabNavi.vue index 0933886..59b3956 100644 --- a/src/views/mis/components/MisTabNavi/MisTabNavi.vue +++ b/src/views/mis/components/MisTabNavi/MisTabNavi.vue @@ -7,16 +7,15 @@
-
测试菜单1
-
测试菜单1
-
测试菜单1
-
测试菜单1
+
{{menu.mname}}
+
@@ -30,12 +29,25 @@