From 38430ddb8612fce15a2f1c940f9bd57d4da3e70b Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 16 九月 2021 11:59:39 +0800 Subject: [PATCH] add new key --- static/api/api.js | 126 +++++++++++++++++++++--------------------- 1 files changed, 63 insertions(+), 63 deletions(-) diff --git a/static/api/api.js b/static/api/api.js index 1925b75..4784db3 100644 --- a/static/api/api.js +++ b/static/api/api.js @@ -1,64 +1,64 @@ -export default class Api { - syncRequest = function(option){ - //姝e紡 - const BASEURL = 'http://111.205.161.131:5116'; - //娴嬭瘯 - //const BASEURL = 'http://192.168.20.10:7006'; - //澶勭悊璇锋眰url - - if(option.url.indexOf('weather')<0 && option.url.indexOf('smartai')<0){ - option.url = BASEURL+option.url; - } - option.method = option.method || "GET" - option.header = option.header || {} - option.data = option.data || {} - option.loading = option.loading ? true : false - option.loadtext = option.loadtext || '鍔犺浇涓�...' - if(option.method == 'GET'){ - option.header['Content-Type'] = 'application/json;charset=UTF-8' - }else{ - option.header['Content-Type'] = 'application/x-www-form-urlencoded' - option.header['Content-Type'] = 'application/json' - } - if(option.loading){ - uni.showLoading({ - mask: true, - title: option.loadtext - }); - } - return new Promise((resolve,reject)=>{ - uni.request({ - url: option.url, - method: option.method, - header: option.header, - data: option.data, - success: (res)=>{ - if(option.loading){ - uni.hideLoading() - } - console.log(res) - if(res.statusCode==200){ - resolve(res) - }else{ - uni.showToast({ - icon: "none", - title: "鏁版嵁鑾峰彇澶辫触锛岃绋嶅悗閲嶈瘯" - }); - } - }, - fail: (err)=>{ - - console.log(err) - if (option.loading) { - uni.hideLoading() - } - uni.showToast({ - icon: "none", - title: "鏁版嵁鑾峰彇澶辫触锛岃绋嶅悗閲嶈瘯" - }) - reject(err) - } - }) - }) - } +export default class Api { + syncRequest = function(option){ + //姝e紡 + const BASEURL = 'http://111.205.161.131:5116'; + //娴嬭瘯 + //const BASEURL = 'http://192.168.20.10:7006'; + //澶勭悊璇锋眰url + + if(option.url.indexOf('weather')<0 && option.url.indexOf('smartai')<0){ + option.url = BASEURL+option.url; + } + option.method = option.method || "GET" + option.header = option.header || {} + option.data = option.data || {} + option.loading = option.loading ? true : false + option.loadtext = option.loadtext || '鍔犺浇涓�...' + if(option.method == 'GET'){ + option.header['Content-Type'] = 'application/json;charset=UTF-8' + }else{ + option.header['Content-Type'] = 'application/x-www-form-urlencoded' + option.header['Content-Type'] = 'application/json' + } + if(option.loading){ + uni.showLoading({ + mask: true, + title: option.loadtext + }); + } + return new Promise((resolve,reject)=>{ + uni.request({ + url: option.url, + method: option.method, + header: option.header, + data: option.data, + success: (res)=>{ + if(option.loading){ + uni.hideLoading() + } + console.log(res) + if(res.statusCode==200){ + resolve(res) + }else{ + uni.showToast({ + icon: "none", + title: "鏁版嵁鑾峰彇澶辫触锛岃绋嶅悗閲嶈瘯" + }); + } + }, + fail: (err)=>{ + + console.log(err) + if (option.loading) { + uni.hideLoading() + } + uni.showToast({ + icon: "none", + title: "鏁版嵁鑾峰彇澶辫触锛岃绋嶅悗閲嶈瘯" + }) + reject(err) + } + }) + }) + } } \ No newline at end of file -- Gitblit v1.8.0