Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
npm
/
glsx-common
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit cb59d3b1
authored
Nov 14, 2022
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
2.0.4
1 parent
f340a89a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
3 deletions
dist/glsx-common.js
package.json
src/http.js
dist/glsx-common.js
View file @
cb59d3b
...
@@ -547,7 +547,7 @@ eval("\n\nvar GetIntrinsic = __webpack_require__(/*! get-intrinsic */ \"./node_m
...
@@ -547,7 +547,7 @@ eval("\n\nvar GetIntrinsic = __webpack_require__(/*! get-intrinsic */ \"./node_m
/***/
((
__unused_webpack_module
,
__webpack_exports__
,
__webpack_require__
)
=>
{
/***/
((
__unused_webpack_module
,
__webpack_exports__
,
__webpack_require__
)
=>
{
"use strict"
;
"use strict"
;
eval
(
"__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util */ \"./src/util.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! qs */ \"./node_modules/qs/lib/index.js\");\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(qs__WEBPACK_IMPORTED_MODULE_2__);\n/*\r\n * @Author: limin\r\n * @Date: 2018-06-25 10:28:18\r\n * @Last Modified by: huyue\r\n * @Last Modified time: 2021-07-16 18:02:05\r\n */\r\n\r\n\r\n\r\nfunction Http(options = {}) {\r\n this.service = axios__WEBPACK_IMPORTED_MODULE_1___default().create({\r\n withCredentials: true,\r\n method: 'POST'\r\n })\r\n const { response = {}, request = {}, headers = {}, alert, sign, signWay = 'sha1', secret } = options\r\n this.customer = {\r\n response,\r\n alert,\r\n sign,\r\n secret,\r\n signWay,\r\n sessionId: headers.token\r\n }\r\n const { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' } = request\r\n Object.assign(this.service.defaults, { headers: Object.assign({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, headers) }, { baseURL, timeout, withCredentials, responseType })\r\n return this.create()\r\n}\r\nHttp.prototype.create = function () {\r\n this.service.interceptors.request.use(\r\n config => {\r\n let { data = {}, sign = true, noSignAttr = [] } = config\r\n data.sessionId = this.customer.sessionId || data.sessionId\r\n if (sign) {\r\n let _configSign = this.customer.sign || {}\r\n data = _util__WEBPACK_IMPORTED_MODULE_0__[\"default\"].createSign(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)\r\n }\r\n const method = config.method.toLowerCase()\r\n if (method == 'get') {\r\n config.params = data\r\n } else if (method == 'post') {\r\n if (config.headers['Content-Type'] == 'multipart/form-data') {\r\n config.data = _util__WEBPACK_IMPORTED_MODULE_0__[\"default\"].appendFormData(data)\r\n } else {\r\n config.data = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(data)\r\n }\r\n }\r\n return config\r\n },\r\n error => Promise.reject(error)\r\n )\r\n this.service.interceptors.response.use(\r\n ({ data: res, config: { returnAll } }) => {\r\n const {\r\n response: { code_key, errId = 'errId', code_success_value = '0', data_key = 'data', errId_logout_value, logout_function = 'logout' },\r\n alert
= Promise.reject
\r\n } = this.customer\r\n // if (returnAll || !alert) {\r\n // return res\r\n // }\r\n let codekey = Array.isArray(code_key) ? code_key.find(key => res.hasOwnProperty(key)) : code_key\r\n let code = res[codekey]\r\n let errValue = res[errId]\r\n if (returnAll || !alert) {\r\n if ((code && code == errId_logout_value) || (errValue && errValue == errId_logout_value)) {\r\n logout(logout_function)\r\n }\r\n return res\r\n }\r\n // 特殊的code处理,可以增加\r\n switch (code + '') {\r\n case code_success_value + '':\r\n break\r\n case errId_logout_value + '':\r\n logout(logout_function)\r\n break\r\n default:\r\n if (errValue && errValue == errId_logout_value) {\r\n return logout(logout_function)\r\n }\r\n alert(res.message || res.msg || '出错了,请联系管理员')\r\n break\r\n }\r\n return res[data_key]\r\n },\r\n error => {\r\n const { alert } = this.customer\r\n alert && alert(error.message || '出错了,请联系管理员')\r\n // 返回接口返回的错误信息\r\n return Promise.reject(error)\r\n }\r\n )\r\n this.service.axios = (axios__WEBPACK_IMPORTED_MODULE_1___default())\r\n return this.service\r\n}\r\nfunction logout(logout_function) {\r\n if (window[logout_function]) {\r\n window[logout_function]()\r\n return\r\n }\r\n window.history.pushState(null, '', '/login')\r\n}\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Http);\r\n\n\n//# sourceURL=webpack://glsx-common/./src/http.js?"
);
eval
(
"__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util */ \"./src/util.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! qs */ \"./node_modules/qs/lib/index.js\");\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(qs__WEBPACK_IMPORTED_MODULE_2__);\n/*\r\n * @Author: limin\r\n * @Date: 2018-06-25 10:28:18\r\n * @Last Modified by: huyue\r\n * @Last Modified time: 2021-07-16 18:02:05\r\n */\r\n\r\n\r\n\r\nfunction Http(options = {}) {\r\n this.service = axios__WEBPACK_IMPORTED_MODULE_1___default().create({\r\n withCredentials: true,\r\n method: 'POST'\r\n })\r\n const { response = {}, request = {}, headers = {}, alert, sign, signWay = 'sha1', secret } = options\r\n this.customer = {\r\n response,\r\n alert,\r\n sign,\r\n secret,\r\n signWay,\r\n sessionId: headers.token\r\n }\r\n const { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' } = request\r\n Object.assign(this.service.defaults, { headers: Object.assign({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, headers) }, { baseURL, timeout, withCredentials, responseType })\r\n return this.create()\r\n}\r\nHttp.prototype.create = function () {\r\n this.service.interceptors.request.use(\r\n config => {\r\n let { data = {}, sign = true, noSignAttr = [] } = config\r\n data.sessionId = this.customer.sessionId || data.sessionId\r\n if (sign) {\r\n let _configSign = this.customer.sign || {}\r\n data = _util__WEBPACK_IMPORTED_MODULE_0__[\"default\"].createSign(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)\r\n }\r\n const method = config.method.toLowerCase()\r\n if (method == 'get') {\r\n config.params = data\r\n } else if (method == 'post') {\r\n if (config.headers['Content-Type'] == 'multipart/form-data') {\r\n config.data = _util__WEBPACK_IMPORTED_MODULE_0__[\"default\"].appendFormData(data)\r\n } else {\r\n config.data = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(data)\r\n }\r\n }\r\n return config\r\n },\r\n error => Promise.reject(error)\r\n )\r\n this.service.interceptors.response.use(\r\n ({ data: res, config: { returnAll } }) => {\r\n const {\r\n response: { code_key, errId = 'errId', code_success_value = '0', data_key = 'data', errId_logout_value, logout_function = 'logout' },\r\n alert\r\n } = this.customer\r\n // if (returnAll || !alert) {\r\n // return res\r\n // }\r\n let codekey = Array.isArray(code_key) ? code_key.find(key => res.hasOwnProperty(key)) : code_key\r\n let code = res[codekey]\r\n let errValue = res[errId]\r\n if (returnAll || !alert) {\r\n if ((code && code == errId_logout_value) || (errValue && errValue == errId_logout_value)) {\r\n logout(logout_function)\r\n }\r\n return res\r\n }\r\n // 特殊的code处理,可以增加\r\n switch (code + '') {\r\n case code_success_value + '':\r\n break\r\n case errId_logout_value + '':\r\n logout(logout_function)\r\n break\r\n default:\r\n if (errValue && errValue == errId_logout_value) {\r\n return logout(logout_function)\r\n }\r\n alert(res.message || res.msg || '出错了,请联系管理员')\r\n break\r\n }\r\n return res[data_key]\r\n },\r\n error => {\r\n const { alert } = this.customer\r\n alert && alert(error.message || '出错了,请联系管理员')\r\n // 返回接口返回的错误信息\r\n return Promise.reject(error)\r\n }\r\n )\r\n this.service.axios = (axios__WEBPACK_IMPORTED_MODULE_1___default())\r\n return this.service\r\n}\r\nfunction logout(logout_function) {\r\n if (window[logout_function]) {\r\n window[logout_function]()\r\n return\r\n }\r\n window.history.pushState(null, '', '/login')\r\n}\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Http);\r\n\n\n//# sourceURL=webpack://glsx-common/./src/http.js?"
);
/***/
}),
/***/
}),
...
...
package.json
View file @
cb59d3b
{
{
"name"
:
"glsx-common"
,
"name"
:
"glsx-common"
,
"version"
:
"2.0.
3
"
,
"version"
:
"2.0.
4
"
,
"description"
:
"glsx common"
,
"description"
:
"glsx common"
,
"main"
:
"./dist/glsx-common.js"
,
"main"
:
"./dist/glsx-common.js"
,
"private"
:
false
,
"private"
:
false
,
...
...
src/http.js
View file @
cb59d3b
...
@@ -52,7 +52,7 @@ Http.prototype.create = function () {
...
@@ -52,7 +52,7 @@ Http.prototype.create = function () {
({
data
:
res
,
config
:
{
returnAll
}
})
=>
{
({
data
:
res
,
config
:
{
returnAll
}
})
=>
{
const
{
const
{
response
:
{
code_key
,
errId
=
'errId'
,
code_success_value
=
'0'
,
data_key
=
'data'
,
errId_logout_value
,
logout_function
=
'logout'
},
response
:
{
code_key
,
errId
=
'errId'
,
code_success_value
=
'0'
,
data_key
=
'data'
,
errId_logout_value
,
logout_function
=
'logout'
},
alert
=
Promise
.
reject
alert
}
=
this
.
customer
}
=
this
.
customer
// if (returnAll || !alert) {
// if (returnAll || !alert) {
// return res
// return res
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment