-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
44 lines (36 loc) · 1.24 KB
/
action.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from 'react'
import { action as MetaAction, AppLoader } from 'mk-meta-engine'
import config from './config'
class action {
constructor(option) {
this.metaAction = option.metaAction
}
onInit = ({ component, injections }) => {
this.component = component
this.injections = injections
injections.reduce('init')
}
getLogo = () => config.getCurrent().logo
login = async () =>{
const cfg = config.getCurrent()
const user = this.metaAction.gf('data.form.user')
const password = this.metaAction.gf('data.form.password')
const ret = await config.getCurrent().loginApi(user, password)
if(ret.result && ret.value){
if( this.component.props.onRedirect && cfg.rediectInfo){
this.metaAction.context.set('user',ret.value.user)
this.component.props.onRedirect(cfg.rediectInfo)
}
}
else{
this.metaAction.toast('error','error')
}
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
o = new action({ ...option, metaAction }),
ret = { ...metaAction, ...o }
metaAction.config({ metaHandlers: ret })
return ret
}