mirror of
https://github.com/YMFE/yapi.git
synced 2025-02-17 13:49:43 +08:00
opti: 优化代码结构添加错误统一提示
This commit is contained in:
parent
20f2ca0bf3
commit
39c0dd82da
17
.tags
17
.tags
@ -61,11 +61,6 @@ fetchMoreNews /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/news/news.js
|
||||
const.curUid /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/user/user.js /^const initialState = {$/;" property line:4
|
||||
switch /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/user/user.js /^ switch (action.type) {$/;" function line:9
|
||||
changeCurUid /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/user/user.js /^export function changeCurUid(curUid) {$/;" function line:23
|
||||
path /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^var path = require('path');$/;" variable line:1
|
||||
processOutput /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ processOutput: function (assets) {$/;" function line:5
|
||||
modifyQuery /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ modifyQuery: function (defaultQuery) { \/\/ 可查看和编辑 defaultQuery$/;" function line:13
|
||||
config /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ config: function (ykit) {$/;" function line:21
|
||||
modifyWebpackConfig /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ modifyWebpackConfig: function (baseConfig) {$/;" function line:43
|
||||
requireAuthentication /Users/qitmac000445/Desktop/YAPI/yapi/client/components/AuthenticatedComponent.js /^export function requireAuthentication(Component) {$/;" function line:16
|
||||
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/components/AuthenticatedComponent.js /^ constructor(props){$/;" function line:18
|
||||
static.isAuthenticated /Users/qitmac000445/Desktop/YAPI/yapi/client/components/AuthenticatedComponent.js /^ static propTypes ={$/;" property line:21
|
||||
@ -284,3 +279,15 @@ state.login /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ th
|
||||
static.checkLoginState /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ static propTypes = {$/;" property line:34
|
||||
componentDidMount /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ componentDidMount() {$/;" function line:39
|
||||
render /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ render() {$/;" function line:72
|
||||
path /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^var path = require('path');$/;" variable line:1
|
||||
processOutput /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ processOutput: function (assets) {$/;" function line:5
|
||||
modifyQuery /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ modifyQuery: function (defaultQuery) { \/\/ 可查看和编辑 defaultQuery$/;" function line:13
|
||||
config /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ config: function (ykit) {$/;" function line:21
|
||||
modifyWebpackConfig /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ modifyWebpackConfig: function (baseConfig) {$/;" function line:43
|
||||
switch /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ switch (this.env) {$/;" function line:45
|
||||
case.development /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ ENV_PARAMS = {development: true};$/;" property line:47
|
||||
case.development /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ ENV_PARAMS = {development: true};$/;" property line:50
|
||||
case.development /Users/qitmac000445/Desktop/YAPI/yapi/ykit.js /^ ENV_PARAMS = {development: false};$/;" property line:53
|
||||
createStore /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/create.js /^export default function createStore(initialState = {}) {$/;" function line:8
|
||||
module.exports.parser /Users/qitmac000445/Desktop/YAPI/yapi/client/.eslintrc.js /^module.exports = {$/;" property line:1
|
||||
module.exports.extends /Users/qitmac000445/Desktop/YAPI/yapi/client/.eslintrc.js /^ parser: 'babel-eslint',$/;" property line:2
|
||||
|
7
.tags1
7
.tags1
@ -4,8 +4,5 @@
|
||||
!_TAG_PROGRAM_NAME Exuberant Ctags //
|
||||
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
|
||||
!_TAG_PROGRAM_VERSION 5.8 //
|
||||
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ constructor(props) {$/;" function line:27
|
||||
state.login /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ this.state = {$/;" property line:29
|
||||
static.checkLoginState /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ static propTypes = {$/;" property line:34
|
||||
componentDidMount /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ componentDidMount() {$/;" function line:39
|
||||
render /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ render() {$/;" function line:72
|
||||
module.exports.parser /Users/qitmac000445/Desktop/YAPI/yapi/client/.eslintrc.js /^module.exports = {$/;" property line:1
|
||||
module.exports.extends /Users/qitmac000445/Desktop/YAPI/yapi/client/.eslintrc.js /^ parser: 'babel-eslint',$/;" property line:2
|
||||
|
@ -22,5 +22,8 @@ module.exports = {
|
||||
"comma-dangle": ["error", "never"],
|
||||
"no-console": ["off"],
|
||||
"import/no-unresolved": ["error"]
|
||||
},
|
||||
"globals": {
|
||||
"ENV_PARAMS": true
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,11 @@
|
||||
import React from 'react'
|
||||
import thunkMiddleware from 'redux-thunk'
|
||||
import promiseMiddleware from 'redux-promise';
|
||||
import ReactDOM from 'react-dom'
|
||||
import App from './Application'
|
||||
import { createStore, combineReducers, applyMiddleware, compose } from 'redux'
|
||||
import { Provider } from 'react-redux'
|
||||
import ReduxContainer from './reducer'
|
||||
import createStore from './reducer/create';
|
||||
import { DevTools } from './containers';
|
||||
|
||||
const enhancer = compose(
|
||||
// Middleware you want to use in development:
|
||||
applyMiddleware(
|
||||
thunkMiddleware,
|
||||
promiseMiddleware
|
||||
),
|
||||
// Required! Enable Redux DevTools with the monitors you chose
|
||||
DevTools.instrument()
|
||||
);
|
||||
|
||||
// 合并 redux 创建stroe
|
||||
const store = createStore(combineReducers( ReduxContainer ), {}, enhancer)
|
||||
const store = createStore();
|
||||
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
|
24
client/reducer/create.js
Normal file
24
client/reducer/create.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { createStore as _createStore, applyMiddleware, compose } from 'redux';
|
||||
import thunkMiddleware from 'redux-thunk';
|
||||
import promiseMiddleware from 'redux-promise';
|
||||
import messageMiddleware from './middleware/messageMiddleware';
|
||||
import DevTools from '../containers/DevTools/DevTools';
|
||||
import reducer from './modules/reducer';
|
||||
|
||||
export default function createStore(initialState = {}) {
|
||||
const middleware = [thunkMiddleware, promiseMiddleware, messageMiddleware];
|
||||
|
||||
let finalCreateStore;
|
||||
if (ENV_PARAMS.development) {
|
||||
finalCreateStore = compose(
|
||||
applyMiddleware(...middleware),
|
||||
window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument()
|
||||
)(_createStore);
|
||||
} else {
|
||||
finalCreateStore = applyMiddleware(...middleware)(_createStore);
|
||||
}
|
||||
|
||||
const store = finalCreateStore(reducer, initialState);
|
||||
|
||||
return store;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
import login from './modules/login.js'
|
||||
import group from './modules/group.js'
|
||||
import project from './modules/project.js'
|
||||
import Interface from './modules/interface.js'
|
||||
import news from './modules/news.js'
|
||||
import addInterface from './modules/addInterface.js'
|
||||
import user from './modules/user.js'
|
||||
import menu from './modules/menu.js'
|
||||
|
||||
export default {
|
||||
group,
|
||||
login,
|
||||
Interface,
|
||||
user,
|
||||
project,
|
||||
news,
|
||||
addInterface,
|
||||
menu
|
||||
}
|
12
client/reducer/middleware/messageMiddleware.js
Normal file
12
client/reducer/middleware/messageMiddleware.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { Message } from 'antd';
|
||||
|
||||
export default () => next => action => {
|
||||
if (action.error) {
|
||||
Message.error('服务器错误');
|
||||
} else if (action.payload && action.payload.res === false) {
|
||||
const hasChinese = /[\u4E00-\u9FFF]+/g.test(action.payload.message);
|
||||
const message = hasChinese ? action.payload.message : '服务器错误';
|
||||
Message.error(message);
|
||||
}
|
||||
return next(action);
|
||||
};
|
@ -1,16 +0,0 @@
|
||||
import process from 'process';
|
||||
import { Message } from 'antd';
|
||||
|
||||
export default () => next => action => {
|
||||
if (process.browser) {
|
||||
if (action.error) {
|
||||
Message.error('服务器错误');
|
||||
} else if (action.payload && action.payload.res === false) {
|
||||
const hasChinese = /[\u4E00-\u9FFF]+/g.test(action.payload.message);
|
||||
const message = hasChinese ? action.payload.message : '服务器错误';
|
||||
Message.error(message);
|
||||
}
|
||||
return next(action);
|
||||
}
|
||||
return next(action);
|
||||
};
|
20
client/reducer/modules/reducer.js
Normal file
20
client/reducer/modules/reducer.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import login from './login.js'
|
||||
import group from './group.js'
|
||||
import project from './project.js'
|
||||
import Interface from './interface.js'
|
||||
import news from './news.js'
|
||||
import addInterface from './addInterface.js'
|
||||
import user from './user.js'
|
||||
import menu from './menu.js'
|
||||
|
||||
export default combineReducers({
|
||||
group,
|
||||
login,
|
||||
Interface,
|
||||
user,
|
||||
project,
|
||||
news,
|
||||
addInterface,
|
||||
menu
|
||||
})
|
17
ykit.js
17
ykit.js
@ -41,7 +41,22 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
modifyWebpackConfig: function (baseConfig) {
|
||||
|
||||
var ENV_PARAMS = {};
|
||||
switch (this.env) {
|
||||
case 'local':
|
||||
ENV_PARAMS = {development: true};
|
||||
break;
|
||||
case 'dev':
|
||||
ENV_PARAMS = {development: true};
|
||||
break;
|
||||
case 'prd':
|
||||
ENV_PARAMS = {development: false};
|
||||
break;
|
||||
default:
|
||||
}
|
||||
baseConfig.plugins.push(new this.webpack.DefinePlugin({
|
||||
ENV_PARAMS: JSON.stringify(ENV_PARAMS)
|
||||
}))
|
||||
baseConfig.devtool = 'cheap-module-eval-source-map'
|
||||
baseConfig.context = path.resolve(__dirname, "client");
|
||||
baseConfig.output.prd.path = 'static/prd';
|
||||
|
Loading…
Reference in New Issue
Block a user