UNPKG

2.16 kBJavaScriptView Raw
1import { Toast, Notification, Modal, Popconfirm, localeWrapper, Alert } from 'edf-component'
2import { fetch, environment } from 'edf-utils'
3import './mock.js'
4
5var _options = {}
6
7
8fetch.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
41function config(options) {
42 Object.assign(_options, options)
43
44 //对应用进行配置,key会被转换为'^<key>$'跟app名称正则匹配
45 _options.apps && _options.apps.config({
46 '*': {
47 //webapi,//正式网站应该有一个完整webapi对象,提供所有web请求函数
48 webProvider: fetch.mock,
49 //dbProvider: websql,
50 dbConfig: {
51 name: 'test'
52 },
53 },
54 'ttk-edf-app-root': {
55 startAppName: _options.apps['ttk-edf-app-login'] ? 'ttk-edf-app-login' : 'app-test',
56 }
57 })
58
59 require('./mock.js')
60 _options.targetDomId = 'app' //react render到目标dom
61 _options.startAppName = 'ttk-edf-app-root' //启动app名,需要根据实际情况配置
62
63 _options.toast = Toast //轻提示使用组件,edf-meta-engine使用
64 _options.notification = Notification //通知组件
65 _options.modal = Modal //模式弹窗组件
66 _options.popconfirm = Popconfirm //confirm提示组件
67 _options.alert = Alert //alert
68 _options.rootWrapper = (child) => localeWrapper('zh-CN', child) //国际化处理
69 return _options
70}
71
72config.current = _options
73
74export default config