Skip to content

Commit

Permalink
chore: 增加 .npmignore
Browse files Browse the repository at this point in the history
  • Loading branch information
lei-mu committed Jun 4, 2020
1 parent 46a09c0 commit f03627b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 41 deletions.
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/.*
*.iml
example/
node_modules/
dist/
docs/
DCloud/
node/
zipDist/
babel.config.js
gruntfile.js
rollup.config.js
57 changes: 31 additions & 26 deletions example/request-demo/utils/luch-request/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import buildURL from '../helpers/buildURL'
import buildFullPath from '../core/buildFullPath'
import settle from '../core/settle'

/**
* 返回可选值存在的配置
* @param {Array} keys - 可选值数组
* @param {Object} config2 - 配置
* @return {{}} - 存在的配置项
*/
const mergeKeys = (keys, config2) => {
let config = {}
keys.forEach(prop => {
Expand All @@ -15,19 +21,19 @@ export default (config) => {
return new Promise((resolve, reject) => {
const _config = {
url: buildURL(buildFullPath(config.baseURL, config.url), config.params),
header: config.header
}
const complete = (response) => {
response.config = config
try {
// 对可能字符串不是json 的情况容错
if (typeof response.data === 'string') {
response.data = JSON.parse(response.data)
header: config.header,
complete: (response) => {
response.config = config
try {
// 对可能字符串不是json 的情况容错
if (typeof response.data === 'string') {
response.data = JSON.parse(response.data)
}
// eslint-disable-next-line no-empty
} catch (e) {
}
// eslint-disable-next-line no-empty
} catch (e) {
settle(resolve, reject, response)
}
settle(resolve, reject, response)
}
let requestTask
if (config.method === 'UPLOAD') {
Expand All @@ -36,40 +42,39 @@ export default (config) => {
fileType: config.fileType,
// #endif
filePath: config.filePath,
name: config.name,
complete: complete
name: config.name
}
const optionalKeys = ['formData',
const optionalKeys = [
// #ifdef APP-PLUS || H5
'files',
// #endif
// #ifdef H5
'file'
'file',
// #endif
'formData'
]
requestTask = uni.uploadFile({..._config, ...otherConfig, ...mergeKeys(optionalKeys, config)})

} else if (config.method === 'DOWNLOAD') {
requestTask = uni.downloadFile({..._config,complete})
requestTask = uni.downloadFile(_config)
} else {
const optionalKeys = [
'method',
'data',
'dataType ',
// #ifndef MP-ALIPAY || APP-PLUS
'responseType',
// #endif
'method',
// #ifdef MP-ALIPAY || MP-WEIXIN
'timeout',
// #endif
// #ifdef H5
'withCredentials',
'dataType',
// #ifndef MP-ALIPAY || APP-PLUS
'responseType',
// #endif
// #ifdef APP-PLUS
'sslVerify'
'sslVerify',
// #endif
// #ifdef H5
'withCredentials'
// #endif
]
requestTask = uni.request({..._config,...mergeKeys(optionalKeys, config), complete})
requestTask = uni.request({..._config,...mergeKeys(optionalKeys, config)})
}
if (config.getTask) {
config.getTask(requestTask, config)
Expand Down
4 changes: 2 additions & 2 deletions example/request-demo/utils/luch-request/core/Request.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @Class Request
* @description luch-request http请求插件
* @version 3.0.1
* @version 3.0.2
* @Author lu-ch
* @Date 2020-06-02
* @Date 2020-06-04
* @Email [email protected]
* 文档: https://quanzhan.co/luch-request/
* github: https://github.com/lei-mu/luch-request
Expand Down
37 changes: 24 additions & 13 deletions example/request-demo/utils/luch-request/core/mergeConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import {deepMerge, isObject} from '../utils'

/**
* 合并局部配置优先的配置,如果局部有该配置项则用局部,如果全局有该配置项则用全局
* @param {Array} keys - 配置项
* @param {Object} globalsConfig - 当前的全局配置
* @param {Object} config2 - 局部配置
* @return {{}}
*/
const mergeKeys = (keys, globalsConfig, config2) => {
let config = {}
keys.forEach(prop => {
Expand Down Expand Up @@ -43,19 +50,23 @@ export default (globalsConfig, config2 = {}) => {
if (method === 'DOWNLOAD') {

} else if (method === 'UPLOAD') {
delete config.header['content-type']
delete config.header['Content-Type']
if (isObject(config.header)) {
delete config.header['content-type']
delete config.header['Content-Type']
}
const uploadKeys = [
// #ifdef MP-ALIPAY
'fileType',
// #endif
'name', 'formData',
// #ifdef APP-PLUS || H5
'files',
// #endif
// #ifdef MP-ALIPAY
'fileType',
// #endif
// #ifdef H5
'file'
'file',
// #endif
'filePath',
'name',
'formData',
]
uploadKeys.forEach(prop => {
if (typeof config2[prop] !== 'undefined') {
Expand All @@ -65,18 +76,18 @@ export default (globalsConfig, config2 = {}) => {
} else {
const defaultsKeys = [
'data',
// #ifdef MP-ALIPAY || MP-WEIXIN
'timeout',
// #endif
'dataType',
// #ifndef MP-ALIPAY || APP-PLUS
'responseType',
// #endif
// #ifdef MP-ALIPAY || MP-WEIXIN
'timeout',
// #ifdef APP-PLUS
'sslVerify',
// #endif
// #ifdef H5
'withCredentials',
// #endif
// #ifdef APP-PLUS
'sslVerify'
'withCredentials'
// #endif
]
config = {...config, ...mergeKeys(defaultsKeys, globalsConfig, config2)}
Expand Down

0 comments on commit f03627b

Please sign in to comment.