Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zhdd-request

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zhdd-request - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

72

lib/zhdd-request.js

@@ -150,18 +150,23 @@ import axios from 'axios'

const data = this.type === 'formdata' ? new FormData() : {}
let data = this.type === 'formdata' ? new FormData() : {}
// 拼接请求参数
this.paramData && Object.keys(this.paramData).forEach(key => {
const reger = new RegExp('{' + key + '}')
if (reger.test(url)) {
this.config.url = url.replace(reger, this.paramData[key])
} else {
if (this.type === 'formdata') {
data.append(key, this.paramData[key])
if (this.paramData.constructor === Object) {
// 拼接请求参数
this.paramData && Object.keys(this.paramData).forEach(key => {
const reger = new RegExp('{' + key + '}')
if (reger.test(url)) {
this.config.url = url.replace(reger, this.paramData[key])
} else {
data[key] = this.paramData[key]
if (this.type === 'formdata') {
data.append(key, this.paramData[key])
} else {
data[key] = this.paramData[key]
}
}
}
})
})
} else {
data = this.paramData
}
// params是添加到url的请求字符串中的

@@ -187,2 +192,3 @@ // data是添加到请求体(body)中的

default:
this.config.data = data
break

@@ -273,5 +279,5 @@ }

this.request(url, config.method, config).then(res => {
// 下载文件
download(res, config.fileType, config.fileName)
resolve(res, config)
// 下载文件
download(res, config.fileType, config.fileName)
resolve(res, config)
}).catch(e => reject(e))

@@ -289,16 +295,16 @@ } catch (e) {

*/
fileUrl(url, openUrl = true) {
return new Promise((resolve, reject) => {
try {
const href = `${this.instance.defaults.baseURL + url}?${qs.stringify(this.parameters)}`
if (openUrl) {
console.log('下载文件流:', href)
window.open(href)
}
resolve(href)
} catch (e) {
reject(e)
}
})
}
fileUrl(url, openUrl = true) {
return new Promise((resolve, reject) => {
try {
const href = `${this.instance.defaults.baseURL + url}?${qs.stringify(this.parameters)}`
if (openUrl) {
console.log('下载文件流:', href)
window.open(href)
}
resolve(href)
} catch (e) {
reject(e)
}
})
}
}

@@ -320,7 +326,7 @@

const createServersRequest = () => {
for (const key in servicesConfig) {
servicesRequest[key] = () => {
return new Request(key)
for (const key in servicesConfig) {
servicesRequest[key] = () => {
return new Request(key)
}
}
}
}

@@ -327,0 +333,0 @@

{
"name": "zhdd-request",
"version": "2.0.0",
"version": "2.0.1",
"private": false,

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -147,13 +147,21 @@ # zhdd-request

**config [Object] 配置**
| config | 类型 |说明 |
| -- | -- | -- |
fileType | String | 下载文件类型
fileName | String | 下载文件名
| config | 类型 | 说明 |
| -------- | ------ | ------------ |
| fileType | String | 下载文件类型 |
| fileName | String | 下载文件名 |
关于fileType文件类型,可取值:
| config | 类型 |说明 |
| -- | -- | -- |
fileType | String | 下载文件类型
fileName | String | 下载文件名
| 拓展名 | 文件类型 | fileType |
| ------------ | -------------------- | ----------------------------- |
| .jpg 、.jpeg | JPEG 图片 | image/jpeg |
| .png | PNG 图片 | image/png |
| .json | JSON 格式 | application/json |
| .pdf | PDF | application/pdf |
| .ppt | Microsoft PowerPoint | application/vnd.ms-powerpoint |
| .xls | Microsoft Excel | application/vnd.ms-excel |
| .zip | ZIP | application/zip |
| .rar | RAR 存档 | application/x-rar-compressed |
- `fileUrl()` 获取url链接

@@ -172,7 +180,7 @@ ```

| config | 类型 |说明 |
| -- | -- | -- |
baseURL | String | 默认服务域名
timeout | Number | 接口超时时间设置 非必传
headers | Object |请求头 非必传
| config | 类型 | 说明 |
| ------- | ------ | ----------------------- |
| baseURL | String | 默认服务域名 |
| timeout | Number | 接口超时时间设置 非必传 |
| headers | Object | 请求头 非必传 |

@@ -205,6 +213,6 @@ 2. services [Object] 请求多服务域名配置

| type | 类型 |说明 |
| -- | -- | -- |
SUCCESS | String | 请求成功时
ERROR | String | 请求失败时
BEFORE | String |请求之前时
| type | 类型 | 说明 |
| ------- | ------ | ---------- |
| SUCCESS | String | 请求成功时 |
| ERROR | String | 请求失败时 |
| BEFORE | String | 请求之前时 |
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc