Commit ce518e43 by limin

1.4.9

1 parent c41dad1b
{ {
"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,
......
...@@ -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.toLocaleLowerCase() 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]
......
...@@ -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
}; }
...@@ -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()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!