Commit 63d78e43 by liimin

v0.2.7

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