mirror of
https://github.com/zuiidea/antd-admin.git
synced 2024-04-21 12:32:14 +00:00
Added eslint rule 'no-conole', Fixed request page and post page,Replace utils/enums.js to utils/contant.js
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "react-app",
|
||||
"rules": {
|
||||
"jsx-a11y/href-no-hash": "off"
|
||||
"jsx-a11y/href-no-hash": "off",
|
||||
"no-console": "warn"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
coverage
|
||||
dist
|
||||
node_modules
|
||||
yarn-error.log
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
|
||||
# ide
|
||||
.idea
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
"lint-staged": {
|
||||
"src/**/*.js": [
|
||||
"eslint --ext .js --fix",
|
||||
"umi test",
|
||||
"npm run prettier",
|
||||
"git add"
|
||||
],
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@
|
||||
import { routerRedux } from 'dva/router'
|
||||
import { parse, stringify } from 'qs'
|
||||
import config from 'config'
|
||||
import { EnumRoleType } from 'enums'
|
||||
import { RoleType } from 'utils/constant'
|
||||
import { queryMenuList, userLogout, queryUserInfo } from 'api'
|
||||
|
||||
const { prefix } = config
|
||||
@@ -68,8 +68,8 @@ export default {
|
||||
const { permissions } = user
|
||||
let menu = list
|
||||
if (
|
||||
permissions.role === EnumRoleType.ADMIN ||
|
||||
permissions.role === EnumRoleType.DEVELOPER
|
||||
permissions.role === RoleType.ADMIN ||
|
||||
permissions.role === RoleType.DEVELOPER
|
||||
) {
|
||||
permissions.visit = list.map(item => item.id)
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,7 @@ import ReactEcharts from 'echarts-for-react'
|
||||
|
||||
const ChartWithEventComponent = () => {
|
||||
const onChartReady = echart => {
|
||||
/* eslint-disable */
|
||||
console.log('echart is ready', echart)
|
||||
}
|
||||
const onChartLegendselectchanged = (param, echart) => {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
})(this, (exports, echarts) => {
|
||||
let log = function(msg) {
|
||||
if (typeof console !== 'undefined') {
|
||||
/* eslint-disable */
|
||||
console && console.error && console.error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
})(this, (exports, echarts) => {
|
||||
let log = function(msg) {
|
||||
if (typeof console !== 'undefined') {
|
||||
/* eslint-disable */
|
||||
console && console.error && console.error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { parse } from 'qs'
|
||||
import modelExtend from 'dva-model-extend'
|
||||
import { query } from './services/dashboard'
|
||||
import { queryDashboard, queryWeather } from 'api'
|
||||
import { model } from 'utils/model'
|
||||
import * as weatherService from './services/weather'
|
||||
|
||||
export default modelExtend(model, {
|
||||
namespace: 'dashboard',
|
||||
@@ -41,7 +40,7 @@ export default modelExtend(model, {
|
||||
},
|
||||
effects: {
|
||||
*query({ payload }, { call, put }) {
|
||||
const data = yield call(query, parse(payload))
|
||||
const data = yield call(queryDashboard, parse(payload))
|
||||
yield put({
|
||||
type: 'updateState',
|
||||
payload: data,
|
||||
@@ -49,7 +48,7 @@ export default modelExtend(model, {
|
||||
},
|
||||
*queryWeather({ payload = {} }, { call, put }) {
|
||||
payload.location = 'shenzhen'
|
||||
const result = yield call(weatherService.query, payload)
|
||||
const result = yield call(queryWeather, payload)
|
||||
const { success } = result
|
||||
if (success) {
|
||||
const data = result.results[0]
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import modelExtend from 'dva-model-extend'
|
||||
import { queryPostList } from 'api'
|
||||
import { pageModel } from 'utils/model'
|
||||
|
||||
export default modelExtend(pageModel, {
|
||||
namespace: 'post',
|
||||
|
||||
subscriptions: {
|
||||
setup({ dispatch, history }) {
|
||||
history.listen(location => {
|
||||
if (location.pathname === '/post') {
|
||||
dispatch({
|
||||
type: 'query',
|
||||
payload: {
|
||||
status: 2,
|
||||
...location.query,
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
|
||||
effects: {
|
||||
*query({ payload }, { call, put }) {
|
||||
const data = yield call(queryPostList, payload)
|
||||
if (data.success) {
|
||||
yield put({
|
||||
type: 'querySuccess',
|
||||
payload: {
|
||||
list: data.data,
|
||||
pagination: {
|
||||
current: Number(payload.page) || 1,
|
||||
pageSize: Number(payload.pageSize) || 10,
|
||||
total: data.total,
|
||||
},
|
||||
},
|
||||
})
|
||||
} else {
|
||||
throw data
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -1,12 +0,0 @@
|
||||
import { request, config } from 'utils'
|
||||
|
||||
const { api } = config
|
||||
const { posts } = api
|
||||
|
||||
export function query(params) {
|
||||
return request({
|
||||
url: posts,
|
||||
method: 'get',
|
||||
data: params,
|
||||
})
|
||||
}
|
||||
+31
-37
@@ -1,9 +1,14 @@
|
||||
import React from 'react'
|
||||
import Mock from 'mockjs'
|
||||
import { request } from 'utils'
|
||||
import { apiPrefix } from 'utils/config'
|
||||
import { Row, Col, Card, Select, Input, Button } from 'antd'
|
||||
import {
|
||||
userLogin,
|
||||
import api from '@/services/api'
|
||||
|
||||
import styles from './index.less'
|
||||
|
||||
const {
|
||||
loginUser,
|
||||
queryUser,
|
||||
createUser,
|
||||
updateUser,
|
||||
@@ -11,43 +16,49 @@ import {
|
||||
queryUserInfo,
|
||||
queryDashboard,
|
||||
queryUserList,
|
||||
} from 'api'
|
||||
} = api
|
||||
|
||||
import styles from './index.less'
|
||||
const transform = string => {
|
||||
let url = apiPrefix + string
|
||||
let method = 'GET'
|
||||
|
||||
const paramsArray = string.split(' ')
|
||||
if (paramsArray.length === 2) {
|
||||
method = paramsArray[0]
|
||||
url = apiPrefix + paramsArray[1]
|
||||
}
|
||||
return {
|
||||
url,
|
||||
method,
|
||||
desc: 'intercept request by mock.js',
|
||||
}
|
||||
}
|
||||
|
||||
export const requestOptions = [
|
||||
{
|
||||
url: queryUserInfo,
|
||||
desc: 'intercept request by mock.js',
|
||||
...transform(queryUserInfo),
|
||||
},
|
||||
{
|
||||
url: queryDashboard,
|
||||
desc: 'intercept request by mock.js',
|
||||
...transform(queryDashboard),
|
||||
},
|
||||
{
|
||||
url: userLogin,
|
||||
method: 'post',
|
||||
...transform(loginUser),
|
||||
data: {
|
||||
username: 'guest',
|
||||
password: 'guest',
|
||||
},
|
||||
desc: 'intercept request by mock.js',
|
||||
},
|
||||
{
|
||||
url: queryUserList,
|
||||
desc: 'intercept request by mock.js',
|
||||
...transform(queryUserList),
|
||||
},
|
||||
{
|
||||
url: queryUser,
|
||||
desc: 'intercept request by mock.js',
|
||||
...transform(queryUser),
|
||||
data: Mock.mock({
|
||||
id: '@id',
|
||||
}),
|
||||
},
|
||||
{
|
||||
url: createUser,
|
||||
desc: 'intercept request by mock.js',
|
||||
method: 'post',
|
||||
...transform(createUser),
|
||||
data: Mock.mock({
|
||||
name: '@cname',
|
||||
nickName: '@last',
|
||||
@@ -68,18 +79,14 @@ export const requestOptions = [
|
||||
}),
|
||||
},
|
||||
{
|
||||
url: updateUser,
|
||||
desc: 'intercept request by mock.js',
|
||||
method: 'patch',
|
||||
...transform(updateUser),
|
||||
data: Mock.mock({
|
||||
id: '@id',
|
||||
name: '@cname',
|
||||
}),
|
||||
},
|
||||
{
|
||||
url: removeUser,
|
||||
desc: 'intercept request by mock.js',
|
||||
method: 'delete',
|
||||
...transform(removeUser),
|
||||
data: Mock.mock({
|
||||
id: '@id',
|
||||
}),
|
||||
@@ -89,18 +96,6 @@ export const requestOptions = [
|
||||
desc: 'intercept request by mock.js',
|
||||
method: 'get',
|
||||
},
|
||||
{
|
||||
url: 'http://api.asilu.com/weather/',
|
||||
desc:
|
||||
'cross-domain request, but match config.baseURL(./src/utils/config.js)',
|
||||
},
|
||||
{
|
||||
url: 'http://www.zuimeitianqi.com/zuimei/queryWeather',
|
||||
data: {
|
||||
cityCode: '01010101',
|
||||
},
|
||||
desc: "cross-domain request by yahoo's yql",
|
||||
},
|
||||
]
|
||||
|
||||
export default class RequestPage extends React.Component {
|
||||
@@ -139,7 +134,6 @@ export default class RequestPage extends React.Component {
|
||||
})
|
||||
request({ ...requestParams }).then(data => {
|
||||
const { state } = this
|
||||
console.log(data)
|
||||
state.result = [
|
||||
this.state.result,
|
||||
<div key="complete">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import request from 'utils/request'
|
||||
import { apiPrefix } from 'utils/config'
|
||||
|
||||
import api from './api'
|
||||
|
||||
const gen = params => {
|
||||
@@ -26,4 +27,12 @@ for (const key in api) {
|
||||
APIFunction[key] = gen(api[key])
|
||||
}
|
||||
|
||||
APIFunction.queryWeather = params => {
|
||||
params.key = 'i7sau1babuzwhycn'
|
||||
return request({
|
||||
url: `${apiPrefix}/weather/now.json`,
|
||||
data: params,
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = APIFunction
|
||||
|
||||
+1
-18
@@ -1,26 +1,9 @@
|
||||
const APIV1 = '/api/v1'
|
||||
const APIV2 = '/api/v2'
|
||||
|
||||
module.exports = {
|
||||
name: 'AntD Admin',
|
||||
siteName: 'AntD Admin',
|
||||
prefix: 'antdAdmin',
|
||||
footerText: 'Ant Design Admin © 2018 zuiidea',
|
||||
logo: '/logo.svg',
|
||||
openPages: ['/login'],
|
||||
apiPrefix: '/api/v1',
|
||||
APIV1,
|
||||
APIV2,
|
||||
api: {
|
||||
userLogin: `${APIV1}/user/login`,
|
||||
userLogout: `${APIV1}/user/logout`,
|
||||
userInfo: `${APIV1}/userInfo`,
|
||||
users: `${APIV1}/users`,
|
||||
posts: `${APIV1}/posts`,
|
||||
user: `${APIV1}/user/:id`,
|
||||
dashboard: `${APIV1}/dashboard`,
|
||||
menus: `${APIV1}/menus`,
|
||||
weather: `${APIV1}/weather`,
|
||||
v1test: `${APIV1}/test`,
|
||||
v2test: `${APIV2}/test`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
RoleType: {
|
||||
ADMIN: 'admin',
|
||||
DEFAULT: 'admin',
|
||||
DEVELOPER: 'developer',
|
||||
},
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
const EnumRoleType = {
|
||||
ADMIN: 'admin',
|
||||
DEFAULT: 'admin',
|
||||
DEVELOPER: 'developer',
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
EnumRoleType,
|
||||
}
|
||||
Reference in New Issue
Block a user