rename makeUrl to makeServerUrl

This commit is contained in:
陆柯 2021-08-20 14:18:57 +08:00
parent 7668573fb0
commit d805b34769

View File

@ -69,7 +69,7 @@ module.exports = {
// if (page.$store._mutations['i18n/setTabbar']) page.$store.commit('i18n/setTabbar') // 必须要在有 tab 的页面里重置才有效果
// },
makeUrl(route = '') {
makeServerUrl(route = '') {
if (route && typeof route === 'object') {
route = `${route.api}/${route.class}/${route.method}`
}
@ -96,14 +96,14 @@ module.exports = {
makeBgUrl(path) {
if (path) {
return `url(${this.makeUrl(path)})`
return `url(${this.makeServerUrl(path)})`
}
return ''
},
// 再次封装 uni.request输入参数和 uni.request 保持基本一致。主要为了插入 _passtoken简化 url 的组装,以及输出提示。
async request({ method = 'POST', url, header = {}, data = {} }) {
url = this.makeUrl(url)
url = this.makeServerUrl(url)
header._passtoken = uni.getStorageSync('_passtoken')
if (method === 'GET') {
// 如果不是 POST 方法,要额外把参数JSON化
@ -157,7 +157,7 @@ module.exports = {
}
let [error, { statusCode, header, errMsg, data: resultServer = {} } = {}] = await uni.request({
method: httpMethod,
url: this.makeUrl(`${apiVersion}/${apiWho}/${apiTodo}`),
url: this.makeServerUrl(`${apiVersion}/${apiWho}/${apiTodo}`),
header: { _passtoken: uni.getStorageSync('_passtoken') },
data: apiWhat,
})
@ -214,7 +214,7 @@ module.exports = {
}
uni.showLoading()
let [errorUpload, response] = await uni.uploadFile({ url: this.makeUrl(url), filePath, name, header, formData })
let [errorUpload, response] = await uni.uploadFile({ url: this.makeServerUrl(url), filePath, name, header, formData })
uni.hideLoading()
if (response && response.data) {