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 ce518e43
authored
Nov 12, 2021
by
limin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.4.9
1 parent
c41dad1b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
30 deletions
package.json
src/http.js
src/storage.js
src/util.js
package.json
View file @
ce518e4
{
{
"name"
:
"glsx-common"
,
"name"
:
"glsx-common"
,
"version"
:
"1.4.
8
"
,
"version"
:
"1.4.
9
"
,
"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 @
ce518e4
...
@@ -34,7 +34,7 @@ Http.prototype.create = function () {
...
@@ -34,7 +34,7 @@ Http.prototype.create = function () {
let
_configSign
=
this
.
customer
.
sign
||
{}
let
_configSign
=
this
.
customer
.
sign
||
{}
data
=
createSign
(
Object
.
assign
({},
_configSign
,
data
),
this
.
customer
.
secret
,
noSignAttr
,
this
.
customer
.
signWay
)
data
=
createSign
(
Object
.
assign
({},
_configSign
,
data
),
this
.
customer
.
secret
,
noSignAttr
,
this
.
customer
.
signWay
)
}
}
const
method
=
config
.
method
.
toLo
caleLo
werCase
()
const
method
=
config
.
method
.
toLowerCase
()
if
(
method
==
'get'
)
{
if
(
method
==
'get'
)
{
config
.
params
=
data
config
.
params
=
data
}
else
if
(
method
==
'post'
)
{
}
else
if
(
method
==
'post'
)
{
...
@@ -67,9 +67,7 @@ Http.prototype.create = function () {
...
@@ -67,9 +67,7 @@ Http.prototype.create = function () {
if
(
errValue
&&
errValue
==
errId_logout_value
)
{
if
(
errValue
&&
errValue
==
errId_logout_value
)
{
return
logout
(
logout_function
)
return
logout
(
logout_function
)
}
}
if
(
alert
)
{
alert
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
alert
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
}
break
break
}
}
return
res
[
data_key
]
return
res
[
data_key
]
...
...
src/storage.js
View file @
ce518e4
...
@@ -4,49 +4,61 @@
...
@@ -4,49 +4,61 @@
* @Last Modified by: limin
* @Last Modified by: limin
* @Last Modified time: 2018-08-31 18:28:26
* @Last Modified time: 2018-08-31 18:28:26
*/
*/
const
aseKey
=
'UkRPT0pp'
//秘钥必须为:8/16/32位
const
isPro
=
process
.
env
.
NODE_ENV
!==
'production'
const
TYPE
=
{
const
TYPE
=
{
LOCAL
:
"localStorage"
,
LOCAL
:
'localStorage'
,
SESSION
:
"sessionStorage"
,
SESSION
:
'sessionStorage'
}
;
}
function
isObject
(
val
)
{
function
isObject
(
val
)
{
return
val
!==
null
&&
typeof
val
===
"object"
;
return
val
!==
null
&&
typeof
val
===
'object'
}
function
encrypt
(
val
)
{
if
(
!
val
)
return
val
return
val
}
function
decrypt
(
val
)
{
if
(
!
val
)
return
val
return
val
}
}
function
set
(
key
,
val
,
type
=
TYPE
.
LOCAL
)
{
function
set
(
key
,
val
,
type
=
TYPE
.
LOCAL
)
{
if
(
isObject
(
val
))
window
[
type
].
setItem
(
key
,
JSON
.
stringify
(
val
))
;
if
(
isObject
(
val
))
window
[
type
].
setItem
(
key
,
JSON
.
stringify
(
val
))
else
window
[
type
].
setItem
(
key
,
val
);
else
window
[
type
].
setItem
(
key
,
encrypt
(
val
))
}
}
function
get
(
key
,
type
=
TYPE
.
LOCAL
)
{
function
get
(
key
,
type
=
TYPE
.
LOCAL
)
{
var
val
=
window
[
type
].
getItem
(
key
)
;
var
val
=
window
[
type
].
getItem
(
key
)
try
{
try
{
if
(
val
&&
val
.
startsWith
(
"#"
))
{
if
(
val
&&
val
.
startsWith
(
'#'
))
{
return
val
;
return
val
}
}
const
value
=
JSON
.
parse
(
val
);
const
value
=
JSON
.
parse
(
decrypt
(
val
))
return
value
;
return
value
}
catch
(
e
)
{
}
catch
(
e
)
{
throw
e
;
throw
e
}
}
}
}
function
remove
(
key
,
type
=
TYPE
.
LOCAL
)
{
function
remove
(
key
,
type
=
TYPE
.
LOCAL
)
{
window
[
type
].
removeItem
(
key
)
;
window
[
type
].
removeItem
(
key
)
}
}
function
setSession
(
key
,
val
,
ex
=
20
)
{
function
setSession
(
key
,
val
,
ex
=
20
)
{
set
(
key
,
val
,
TYPE
.
SESSION
)
;
set
(
key
,
val
,
TYPE
.
SESSION
)
}
}
function
getSession
(
key
)
{
function
getSession
(
key
)
{
return
get
(
key
,
TYPE
.
SESSION
)
;
return
get
(
key
,
TYPE
.
SESSION
)
}
}
function
removeSession
(
key
)
{
function
removeSession
(
key
)
{
remove
(
key
,
TYPE
.
SESSION
)
;
remove
(
key
,
TYPE
.
SESSION
)
}
}
// 默认30minute
// 默认30minute
function
setExpire
(
key
,
val
,
ex
=
1.8e6
)
{
function
setExpire
(
key
,
val
,
ex
=
1.8e6
)
{
set
(
key
,
{
v
:
val
,
t
:
Date
.
now
()
+
ex
})
;
set
(
key
,
{
v
:
val
,
t
:
Date
.
now
()
+
ex
})
}
}
function
getExpire
(
key
)
{
function
getExpire
(
key
)
{
var
obj
=
get
(
key
)
;
var
obj
=
get
(
key
)
if
(
obj
.
t
>
Date
.
now
())
return
obj
.
v
;
if
(
obj
.
t
>
Date
.
now
())
return
obj
.
v
else
return
null
;
else
return
null
}
}
export
default
{
export
default
{
set
,
set
,
...
@@ -56,5 +68,5 @@ export default {
...
@@ -56,5 +68,5 @@ export default {
getSession
,
getSession
,
removeSession
,
removeSession
,
setExpire
,
setExpire
,
getExpire
,
getExpire
}
;
}
src/util.js
View file @
ce518e4
...
@@ -152,16 +152,16 @@ export const Util = {
...
@@ -152,16 +152,16 @@ export const Util = {
createSign
:
function
(
params
,
secret
,
noSignAttr
=
[],
way
=
'sha1'
)
{
createSign
:
function
(
params
,
secret
,
noSignAttr
=
[],
way
=
'sha1'
)
{
delete
params
.
sign
delete
params
.
sign
params
.
timestamp
=
new
Date
().
getTime
()
params
.
timestamp
=
new
Date
().
getTime
()
var
strQs
=
qs
.
stringify
(
params
,
{
arrayFormat
:
'indices'
,
encode
:
false
,
allowDots
:
true
})
var
strQs
=
qs
.
stringify
(
params
,
{
arrayFormat
:
'indices'
,
allowDots
:
true
,
encodeValuesOnly
:
true
})
const
objQs
=
strQs
.
split
(
'&'
)
const
objQs
=
strQs
.
split
(
'&'
)
const
collect
=
objQs
.
reduce
((
collect
,
item
)
=>
{
const
collect
=
objQs
.
reduce
((
collect
,
item
)
=>
{
const
[
key
,
value
]
=
item
.
split
(
'='
)
const
[
key
,
value
]
=
item
.
split
(
'='
)
if
(
value
===
null
)
{
if
(
value
===
null
)
{
value
=
''
value
=
''
}
else
if
(
typeof
obj
===
'object'
)
{
}
else
if
(
typeof
value
===
'object'
)
{
value
=
JSON
.
stringify
(
value
)
value
=
JSON
.
stringify
(
value
)
}
}
collect
[
key
]
=
value
collect
[
key
]
=
decodeURIComponent
(
value
)
return
collect
return
collect
},
{})
},
{})
const
keys
=
Object
.
keys
(
collect
).
sort
()
const
keys
=
Object
.
keys
(
collect
).
sort
()
...
...
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