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 efefd45f
authored
Oct 19, 2021
by
limin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.4.6
1 parent
248a5662
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
4 deletions
dist/glsx-common.js
package.json
src/http.js
dist/glsx-common.js
View file @
efefd45
...
@@ -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({}, headers, { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }, { 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 = (0,_util__WEBPACK_IMPORTED_MODULE_0__.createSign)(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)\r\n }\r\n const method = config.method.toLocaleLowerCase()\r\n if (method == 'get') {\r\n config.params = data\r\n } else if (method == 'post') {\r\n config.data = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(data)\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 = 'code', errId = 'errId', code_success_value = '0', data_key = 'data', errId_logout_value },\r\n alert\r\n } = this.customer\r\n if (returnAll || !alert) {\r\n return res\r\n }\r\n let code = res[code_key]\r\n let errValue = res[errId]\r\n // 特殊的code处理,可以增加\r\n switch (code + '') {\r\n case code_success_value + '':\r\n
// 请求成功,不弹提示框,成功code可以更改\r\n break\r\n default:\r\n if (errValue == errId_logout_value) {\r\n window.history.pushState(null, '', '/login')\r\n }\r\n if (alert) {\r\n alert(res.message || res.msg || '出错了,请联系管理员')\r\n }\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\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({}, headers, { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }, { 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 = (0,_util__WEBPACK_IMPORTED_MODULE_0__.createSign)(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)\r\n }\r\n const method = config.method.toLocaleLowerCase()\r\n if (method == 'get') {\r\n config.params = data\r\n } else if (method == 'post') {\r\n config.data = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(data)\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 = 'code', errId = 'errId', code_success_value = '0', data_key = 'data', errId_logout_value },\r\n alert\r\n } = this.customer\r\n if (returnAll || !alert) {\r\n return res\r\n }\r\n let code = res[code_key]\r\n let errValue = res[errId]\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()\r\n break\r\n default:\r\n if (errValue && errValue == errId_logout_value) {\r\n logout()\r\n }\r\n if (alert) {\r\n alert(res.message || res.msg || '出错了,请联系管理员')\r\n }\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() {\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 @
efefd45
{
{
"name"
:
"glsx-common"
,
"name"
:
"glsx-common"
,
"version"
:
"1.4.
5
"
,
"version"
:
"1.4.
6
"
,
"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 @
efefd45
...
@@ -58,11 +58,13 @@ Http.prototype.create = function () {
...
@@ -58,11 +58,13 @@ Http.prototype.create = function () {
// 特殊的code处理,可以增加
// 特殊的code处理,可以增加
switch
(
code
+
''
)
{
switch
(
code
+
''
)
{
case
code_success_value
+
''
:
case
code_success_value
+
''
:
// 请求成功,不弹提示框,成功code可以更改
break
case
errId_logout_value
+
''
:
logout
()
break
break
default
:
default
:
if
(
errValue
&&
errValue
==
errId_logout_value
)
{
if
(
errValue
&&
errValue
==
errId_logout_value
)
{
window
.
history
.
pushState
(
null
,
''
,
'/login'
)
logout
(
)
}
}
if
(
alert
)
{
if
(
alert
)
{
alert
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
alert
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
...
@@ -81,4 +83,7 @@ Http.prototype.create = function () {
...
@@ -81,4 +83,7 @@ Http.prototype.create = function () {
this
.
service
.
axios
=
axios
this
.
service
.
axios
=
axios
return
this
.
service
return
this
.
service
}
}
function
logout
()
{
window
.
history
.
pushState
(
null
,
''
,
'/login'
)
}
export
default
Http
export
default
Http
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