Commit 63d78e43 by liimin

v0.2.7

1 parent a5244c0f
{
"name": "glsx-common-sdk",
"version": "0.2.0",
"version": "0.2.7",
"description": "glsx-common-sdk",
"main": "src/index.js",
"main": "./dist/glsx-common-sdk.js",
"private": false,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c",
......
import { storediff } from '../../helper/index'
import { GLSX_COMMON_VERSION_STORAGE_VERSION } from './constants'
const webwx = {
getResult: data => {
getResult: (data = {}) => {
const v = storediff.get(GLSX_COMMON_VERSION_STORAGE_VERSION)
const compare = compareVersions(v, data.version)
return { compare, origin: v, isNew: compare === -1, ...data }
},
setVersion: version => {
const v = storediff.get(GLSX_COMMON_VERSION_STORAGE_VERSION)
if(v===version) return
if (v === version) return
storediff.set(GLSX_COMMON_VERSION_STORAGE_VERSION, version)
}
}
......
......@@ -2,14 +2,21 @@ import Request from '../../request/index'
import webwx from './helper'
class Version {
constructor(options = {}) {
options.alert = options.alert || function () {}
options.request.returnAll = false
this.request = new Request(options)
}
async get(data) {
const versionInfo = await this.request.get(data)
return webwx.getResult(versionInfo)
this.version = versionInfo
return this.compare()
}
set(version) {
return webwx.setVersion(version)
webwx.setVersion(version)
return this.compare()
}
compare() {
return webwx.getResult(this.version)
}
}
export default Version
......@@ -26,7 +26,7 @@ const createSign = function (params, secret, noSignAttr = [], way = 'sha1') {
return collect
}
const webRequest = async ({ method, obj = {}, baseUrl, headers = {} }, returnAll, logoutCallback, alert) => {
const webRequest = async ({ method, obj = {}, baseUrl, headers = {} }, returnAll, logoutCallback, alert, initResponse) => {
let requestAddrss = baseUrl
const settings = {
method
......@@ -34,7 +34,7 @@ const webRequest = async ({ method, obj = {}, baseUrl, headers = {} }, returnAll
if (method.toUpperCase() === RequestMethods.GET) {
const params = []
Object.keys(obj).map(key => params.push(`${key}=${encodeURIComponent(obj[key])}`))
requestAddrss = `${baseUrl}?${params.join('&')}`
requestAddrss = baseUrl + (params.length ? `?${params.join('&')}` : '')
settings.headers = headers
} else {
settings.headers = Object.assign({ 'Content-Type': 'application/json' }, headers)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!