Skip to content

Commit

Permalink
[add] Common.reloadMenu action
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Nov 28, 2023
1 parent 6f372d5 commit 2e28039
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/xgen/actions/Common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export { default as historyBack } from './historyBack'
export { default as confirm } from './confirm'
export { default as refetch } from './refetch'
export { default as reload } from './reload'
export { default as reloadMenu } from './reloadMenu'
export { default as showMessage } from './showMessage'
export { default as emitEvent } from './emitEvent'
5 changes: 5 additions & 0 deletions packages/xgen/actions/Common/reloadMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Action } from '@/types'

export default () => {
return () => window.$app.Event.emit(`app/getUserMenu`)
}
6 changes: 6 additions & 0 deletions packages/xgen/actions/utils/handleActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
openModal,
refetch,
reload,
reloadMenu,
showMessage,
emitEvent
} from '../Common'
Expand Down Expand Up @@ -44,6 +45,11 @@ export default ({ namespace, primary, data_item, it, extra }: OnAction) => {
case 'Common.reload':
total.push({ task: reload(), ...flow_info })
break

case 'Common.reloadMenu':
total.push({ task: reloadMenu(), ...flow_info })
break

case 'Common.showMessage':
total.push({ task: showMessage(), ...flow_info })
break
Expand Down
14 changes: 14 additions & 0 deletions packages/xgen/context/app/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export default class GlobalModel {
return Promise.resolve()
}

async getUserMenu() {
const { res, err } = await this.service.getUserMenu<App.Menus>()
if (err) return Promise.reject()

this.menus = res
this.menu = res?.items || []

local.menus = this.menus
local.menu = this.menu
return Promise.resolve()
}

setAvatar(avatar?: AvatarFullConfig) {
this.avatar = avatar || genConfig()

Expand Down Expand Up @@ -113,11 +125,13 @@ export default class GlobalModel {

on() {
window.$app.Event.on('app/getAppInfo', this.getAppInfo)
window.$app.Event.on('app/getUserMenu', this.getUserMenu)
window.$app.Event.on('app/updateMenuStatus', this.updateMenuStatus)
}

off() {
window.$app.Event.off('app/getAppInfo', this.getAppInfo)
window.$app.Event.off('app/getUserMenu', this.getUserMenu)
window.$app.Event.off('app/updateMenuStatus', this.updateMenuStatus)
}
}
1 change: 1 addition & 0 deletions packages/xgen/types/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export declare namespace Action {
'Common.confirm': Confirm
'Common.refetch': {}
'Common.reload': Reload
'Common.reloadMenu': {}
'Common.showMessage': ShowMessage
'Common.emitEvent': EmitEvent
'Table.search': {}
Expand Down

0 comments on commit 2e28039

Please sign in to comment.