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"
,
"version"
:
"1.4.
8
"
,
"version"
:
"1.4.
9
"
,
"description"
:
"glsx common"
,
"main"
:
"./dist/glsx-common.js"
,
"private"
:
false
,
...
...
src/http.js
View file @
ce518e4
...
...
@@ -34,7 +34,7 @@ Http.prototype.create = function () {
let
_configSign
=
this
.
customer
.
sign
||
{}
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'
)
{
config
.
params
=
data
}
else
if
(
method
==
'post'
)
{
...
...
@@ -67,9 +67,7 @@ Http.prototype.create = function () {
if
(
errValue
&&
errValue
==
errId_logout_value
)
{
return
logout
(
logout_function
)
}
if
(
alert
)
{
alert
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
}
alert
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
break
}
return
res
[
data_key
]
...
...
src/storage.js
View file @
ce518e4
...
...
@@ -4,49 +4,61 @@
* @Last Modified by: limin
* @Last Modified time: 2018-08-31 18:28:26
*/
const
aseKey
=
'UkRPT0pp'
//秘钥必须为:8/16/32位
const
isPro
=
process
.
env
.
NODE_ENV
!==
'production'
const
TYPE
=
{
LOCAL
:
"localStorage"
,
SESSION
:
"sessionStorage"
,
}
;
LOCAL
:
'localStorage'
,
SESSION
:
'sessionStorage'
}
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
)
{
if
(
isObject
(
val
))
window
[
type
].
setItem
(
key
,
JSON
.
stringify
(
val
))
;
else
window
[
type
].
setItem
(
key
,
val
);
if
(
isObject
(
val
))
window
[
type
].
setItem
(
key
,
JSON
.
stringify
(
val
))
else
window
[
type
].
setItem
(
key
,
encrypt
(
val
))
}
function
get
(
key
,
type
=
TYPE
.
LOCAL
)
{
var
val
=
window
[
type
].
getItem
(
key
)
;
var
val
=
window
[
type
].
getItem
(
key
)
try
{
if
(
val
&&
val
.
startsWith
(
"#"
))
{
return
val
;
if
(
val
&&
val
.
startsWith
(
'#'
))
{
return
val
}
const
value
=
JSON
.
parse
(
val
);
return
value
;
const
value
=
JSON
.
parse
(
decrypt
(
val
))
return
value
}
catch
(
e
)
{
throw
e
;
throw
e
}
}
function
remove
(
key
,
type
=
TYPE
.
LOCAL
)
{
window
[
type
].
removeItem
(
key
)
;
window
[
type
].
removeItem
(
key
)
}
function
setSession
(
key
,
val
,
ex
=
20
)
{
set
(
key
,
val
,
TYPE
.
SESSION
)
;
set
(
key
,
val
,
TYPE
.
SESSION
)
}
function
getSession
(
key
)
{
return
get
(
key
,
TYPE
.
SESSION
)
;
return
get
(
key
,
TYPE
.
SESSION
)
}
function
removeSession
(
key
)
{
remove
(
key
,
TYPE
.
SESSION
)
;
remove
(
key
,
TYPE
.
SESSION
)
}
// 默认30minute
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
)
{
var
obj
=
get
(
key
)
;
if
(
obj
.
t
>
Date
.
now
())
return
obj
.
v
;
else
return
null
;
var
obj
=
get
(
key
)
if
(
obj
.
t
>
Date
.
now
())
return
obj
.
v
else
return
null
}
export
default
{
set
,
...
...
@@ -56,5 +68,5 @@ export default {
getSession
,
removeSession
,
setExpire
,
getExpire
,
}
;
getExpire
}
src/util.js
View file @
ce518e4
...
...
@@ -152,16 +152,16 @@ export const Util = {
createSign
:
function
(
params
,
secret
,
noSignAttr
=
[],
way
=
'sha1'
)
{
delete
params
.
sign
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
collect
=
objQs
.
reduce
((
collect
,
item
)
=>
{
const
[
key
,
value
]
=
item
.
split
(
'='
)
if
(
value
===
null
)
{
value
=
''
}
else
if
(
typeof
obj
===
'object'
)
{
}
else
if
(
typeof
value
===
'object'
)
{
value
=
JSON
.
stringify
(
value
)
}
collect
[
key
]
=
value
collect
[
key
]
=
decodeURIComponent
(
value
)
return
collect
},
{})
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