This commit is contained in:
陆柯 2020-05-23 21:24:13 +08:00
parent 73bd6564c6
commit ad75cd1aee
2 changed files with 76 additions and 6 deletions

View File

@ -4,7 +4,7 @@ module.exports = function showToast({type, icon, image, title, duration}){
}else {
// #ifndef APP-PLUS
if (!image){
image = `../static/Common.${type}.png`
image = `../static/Common.${type?type:'info'}.png`
}
uni.showToast({icon, image, title, duration})
// #endif

View File

@ -1,6 +1,76 @@
module.exports={
cColorText: require('./cColorText/cColorText.vue'),
cPager: require('./cPager/cPager.vue'),
cQrcode: require('./cQrcode/cQrcode.vue'),
cToast: require('./cToast/cToast.vue')
module.exports = {
clog(message){
console.log('【【【【【【【【【【', getApp().$options.router.currentRoute.path, message, '】】】】】】】】】】】')
},
async request(obj){
obj.method = 'POST'
obj.url = this.makeUrl(obj.url)
if (uni.getStorageSync('_passtoken')) {
obj.header = obj.header || {}
obj.header._passtoken = uni.getStorageSync('_passtoken')
}
if (obj.data && (typeof(obj.method) === 'undefined' || obj.method==='GET')) { // 如果不是 POST 方法,要额外把参数JSON化
for (let key in obj.data) {
obj.data[key] = JSON.stringify(obj.data[key])
}
}
console.log('👇 👇 👇 👇 👇 👇 👇 👇 < Request >', obj, '👆 👆 👆 👆 👆 👆 👆 👆 < /Request >')
let [error, response] = await uni.request(obj)
console.log('⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ < Response >', response, '⬆️ ⬆️ ⬆️ ⬆️ ⬆️ ⬆️ ⬆️ ⬆️ < /Response >')
return [error, response]
},
async uploadFile(obj){
obj.url = this.makeUrl(obj.url)
if (uni.getStorageSync('_passtoken')) {
obj.header = obj.header || {}
obj.header._passtoken = uni.getStorageSync('_passtoken')
}else{
return [{ errMsg:'offline user cannot upload files' }, null]
}
if (obj.formData) { // multer 不会自动处理 JSON 数据,必须前后端配合处理
for (let key in obj.formData) {
obj.formData[key] = JSON.stringify(obj.formData[key])
}
}
if (!obj.name) obj.name = 'file'
let [error, response] = await uni.uploadFile(obj)
if (response && response.data) {
try {
response.data = JSON.parse(response.data)
}catch (exception) {}
}
return [error, response]
},
openUrl(url){
// #ifdef APP-PLUS
plus.runtime.openURL(url)
// #endif
// #ifdef H5
window.open(url, "_blank")
// #endif
},
getPlatform(){
if (window && window.navigator) {
var agent = navigator.userAgent.toLowerCase()
if (agent.match(/MicroMessenger/i) == "micromessenger") {
return 'H5.wechat';
} else {
return 'H5'
}
}
switch(uni.getSystemInfoSync().platform){
case 'android': return 'app.android'
case 'ios': return 'app.ios'
case 'devtools': return 'devtools'
default: return 'unknown'
}
},
}