Skip to content

Commit

Permalink
(feature)使用ts重构
Browse files Browse the repository at this point in the history
  • Loading branch information
jingchenxu committed Aug 8, 2019
1 parent 293e2bb commit d270670
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 196 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/myview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Empty file removed src/router/route.js
Empty file.
67 changes: 0 additions & 67 deletions src/store/app.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/store/index.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/store/index.js → src/store/index.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
71 changes: 71 additions & 0 deletions src/store/newapp/index.ts
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions src/store/newapp/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Menu } from '../newuser/interface'

export interface State {
currentPage: Menu | null,
cachePages: Array<Menu>,
expandMisMenu: boolean,
loading: boolean
}
48 changes: 20 additions & 28 deletions src/store/user.js → src/store/newuser/index.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
24 changes: 24 additions & 0 deletions src/store/newuser/interface.ts
Original file line number Diff line number Diff line change
@@ -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<Menu>
}

export interface CurrentUser {
user: any,
menu: Array<Menu>,
dept: any
}

export interface State {
currentUser: CurrentUser,
isLogin: boolean
}
21 changes: 19 additions & 2 deletions src/views/mis/MisContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</el-popover>
</el-header>
<el-main element-loading-spinner="iconfont mvloading loading-animation" v-loading="getLoading">
<mis-tab-navi />
<mis-tab-navi :navi-list="getCachePages" :active-navi="getCurrentPage" />
<router-view v-if="getLogin" />
<copy-right />
</el-main>
Expand All @@ -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 () {
Expand Down
46 changes: 20 additions & 26 deletions src/views/mis/components/MisMenu/MisMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,27 @@
</div>
</template>

<script>
import { mapGetters } from 'vuex'
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { State, Mutation, Getter } from 'vuex-class'
export default {
name: 'MisMenu',
data () {
return {
}
},
computed: {
...mapGetters([
'getExpandMisMenu',
'getMenuTree'
])
},
methods: {
handleOpen (key, keyPath) {
console.log(key, keyPath)
},
handleClose (key, keyPath) {
console.log(key, keyPath)
},
handleSelect (index, indexPath, item) {
this.$router.push({
name: index
})
}
@Component({
name: 'MisMenu'
})
export default class MisMenu extends Vue {
@Getter private getExpandMisMenu: Boolean
@Getter private getMenuTree: Boolean
private handleOpen (key: String, keyPath: String) {
console.log(key, keyPath)
}
private handleClose (key: String, keyPath: String) {
console.log(key, keyPath)
}
private handleSelect (index: any, indexPath: String, item: any) {
this.$router.push({
name: index
})
}
}
</script>
Expand Down
Loading

0 comments on commit d270670

Please sign in to comment.