1 | import { Toast, Notification, Modal, Popconfirm, localeWrapper, Alert } from 'edf-component'
|
2 | import { fetch, environment } from 'edf-utils'
|
3 | import './mock.js'
|
4 |
|
5 | var _options = {}
|
6 |
|
7 |
|
8 | fetch.config({
|
9 | mock: true,
|
10 | after: (response, url, data, header) => {
|
11 | if (response.result) {
|
12 | if (response.token) {
|
13 | fetch.config({ token: response.token })
|
14 | }
|
15 | if (url === '/v1/edf/user/login' || url === '/v1/edf/user/create' || url === 'v1/edf/org/checkCanUpdatePeriod') {
|
16 | return response
|
17 | }
|
18 | return response.value
|
19 | }
|
20 | else {
|
21 | if (data && data.isReturnValue) {
|
22 | return response
|
23 | }
|
24 | else {
|
25 | let errorCode = ''
|
26 | if(response.error && response.error.code){
|
27 | errorCode = response.error.code
|
28 | }
|
29 | if (environment.isDevMode()) {
|
30 | Modal.error({ title: '错误:' + errorCode || '', okText: '关闭', width: 600, bodyStyle: 'height:300px;overflow:auto;', content: response.error.message })
|
31 | }
|
32 | else {
|
33 | Toast.error(response.error.message)
|
34 | }
|
35 | return
|
36 | }
|
37 | }
|
38 | }
|
39 | })
|
40 |
|
41 | function config(options) {
|
42 | Object.assign(_options, options)
|
43 |
|
44 |
|
45 | _options.apps && _options.apps.config({
|
46 | '*': {
|
47 |
|
48 | webProvider: fetch.mock,
|
49 |
|
50 | dbConfig: {
|
51 | name: 'test'
|
52 | },
|
53 | },
|
54 | 'ttk-edf-app-root': {
|
55 | startAppName: 'ttk-edf-app-login',
|
56 | }
|
57 | })
|
58 |
|
59 | require('./mock.js')
|
60 | _options.targetDomId = 'app'
|
61 | _options.startAppName = 'ttk-edf-app-root'
|
62 |
|
63 | _options.toast = Toast
|
64 | _options.notification = Notification
|
65 | _options.modal = Modal
|
66 | _options.popconfirm = Popconfirm
|
67 | _options.alert = Alert
|
68 | _options.rootWrapper = (child) => localeWrapper('zh-CN', child)
|
69 | return _options
|
70 | }
|
71 |
|
72 | config.current = _options
|
73 |
|
74 | export default config
|