Support Stylelint.

Added Prettierrc.
Optimize the configuration file .umirc.js, and Added annotations.
Replace eslint-plugin-umi to eslint-plugin-react-app as eslint bese plugin.
And so on.
This commit is contained in:
zuiidea
2018-09-08 17:10:20 +08:00
parent f02d39ace0
commit 261fbb8428
121 changed files with 13874 additions and 2060 deletions
+54 -46
View File
@@ -7,20 +7,15 @@ import pathToRegexp from 'path-to-regexp'
import { message } from 'antd'
import { YQL, CORS } from './config'
const fetch = (options) => {
let {
method = 'get',
data,
fetchType,
url,
} = options
const fetch = options => {
let { method = 'get', data, fetchType, url } = options
const cloneData = cloneDeep(data)
try {
let domain = ''
if (url.match(/[a-zA-z]+:\/\/[^/]*/)) {
[domain] = url.match(/[a-zA-z]+:\/\/[^/]*/)
;[domain] = url.match(/[a-zA-z]+:\/\/[^/]*/)
url = url.slice(domain.length)
}
const match = pathToRegexp.parse(url)
@@ -37,19 +32,25 @@ const fetch = (options) => {
if (fetchType === 'JSONP') {
return new Promise((resolve, reject) => {
jsonp(url, {
param: `${qs.stringify(data)}&callback`,
name: `jsonp_${new Date().getTime()}`,
timeout: 4000,
}, (error, result) => {
if (error) {
reject(error)
jsonp(
url,
{
param: `${qs.stringify(data)}&callback`,
name: `jsonp_${new Date().getTime()}`,
timeout: 4000,
},
(error, result) => {
if (error) {
reject(error)
}
resolve({ statusText: 'OK', status: 200, data: result })
}
resolve({ statusText: 'OK', status: 200, data: result })
})
)
})
} else if (fetchType === 'YQL') {
url = `http://query.yahooapis.com/v1/public/yql?q=select * from json where url='${options.url}?${encodeURIComponent(qs.stringify(options.data))}'&format=json`
url = `http://query.yahooapis.com/v1/public/yql?q=select * from json where url='${
options.url
}?${encodeURIComponent(qs.stringify(options.data))}'&format=json`
data = null
}
@@ -75,7 +76,9 @@ const fetch = (options) => {
export default function request (options) {
if (options.url && options.url.indexOf('//') > -1) {
const origin = `${options.url.split('//')[0]}//${options.url.split('//')[1].split('/')[0]}`
const origin = `${options.url.split('//')[0]}//${
options.url.split('//')[1].split('/')[0]
}`
if (window.location.origin !== origin) {
if (CORS && CORS.indexOf(origin) > -1) {
options.fetchType = 'CORS'
@@ -87,34 +90,39 @@ export default function request (options) {
}
}
return fetch(options).then((response) => {
const { statusText, status } = response
let data = options.fetchType === 'YQL' ? response.data.query.results.json : response.data
if (data instanceof Array) {
data = {
list: data,
return fetch(options)
.then(response => {
const { statusText, status } = response
let data =
options.fetchType === 'YQL'
? response.data.query.results.json
: response.data
if (data instanceof Array) {
data = {
list: data,
}
}
}
return Promise.resolve({
success: true,
message: statusText,
statusCode: status,
...data,
return Promise.resolve({
success: true,
message: statusText,
statusCode: status,
...data,
})
})
}).catch((error) => {
const { response } = error
let msg
let statusCode
if (response && response instanceof Object) {
const { data, statusText } = response
statusCode = response.status
msg = data.message || statusText
} else {
statusCode = 600
msg = error.message || 'Network Error'
}
.catch(error => {
const { response } = error
let msg
let statusCode
if (response && response instanceof Object) {
const { data, statusText } = response
statusCode = response.status
msg = data.message || statusText
} else {
statusCode = 600
msg = error.message || 'Network Error'
}
/* eslint-disable */
return Promise.reject({ success: false, statusCode, message: msg })
})
/* eslint-disable */
return Promise.reject({ success: false, statusCode, message: msg })
})
}