Skip to content

Commit

Permalink
api请求是传递APP版本号
Browse files Browse the repository at this point in the history
  • Loading branch information
TruthHun88 committed May 11, 2020
1 parent 269e6c2 commit e58d7e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
onLaunch: function() {
let info = uni.getSystemInfoSync()
info.versionCode = 0
info.version = "v1.0.0"
info.version = config.info.version
info.appVersion = config.info.version
info.bookshelfChanged = false
if (info.model && info.model.indexOf('iPhone') !== -1) {
Expand Down
3 changes: 1 addition & 2 deletions utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import util from "./util.js"

const keyCategories = 'categories';
const keyCacheExpire = 'categories-expire';
const expire = 600; // 600 second
const expire = 60; // 600 second

// 获取书籍分类
const getCategories = () => {
Expand Down Expand Up @@ -63,7 +63,6 @@ const getCategoryByCid = (cid) => {
}



module.exports = {
getCategories,
getCategoryByCid,
Expand Down
8 changes: 8 additions & 0 deletions utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ Promise.prototype.finally = function(callback) {
);
}

const _getVersion = () => {
let version = getSysInfo().appVersion
if (version != undefined && version != "") return version
return ''
}

// 只有请求结果返回 200 的时候,才会resolve,否则reject
const request = (api, params = {}, method = "GET", header = {}) => {
return new Promise(function(resolve, reject) {
Expand All @@ -127,6 +133,8 @@ const request = (api, params = {}, method = "GET", header = {}) => {

let token = getToken()
if (token) header['authorization'] = token

header['x-version'] = _getVersion()

uni.request({
url: api,
Expand Down

0 comments on commit e58d7e3

Please sign in to comment.