u
This commit is contained in:
parent
73bd6564c6
commit
ad75cd1aee
@ -4,7 +4,7 @@ module.exports = function showToast({type, icon, image, title, duration}){
|
|||||||
}else {
|
}else {
|
||||||
// #ifndef APP-PLUS
|
// #ifndef APP-PLUS
|
||||||
if (!image){
|
if (!image){
|
||||||
image = `../static/Common.${type}.png`
|
image = `../static/Common.${type?type:'info'}.png`
|
||||||
}
|
}
|
||||||
uni.showToast({icon, image, title, duration})
|
uni.showToast({icon, image, title, duration})
|
||||||
// #endif
|
// #endif
|
||||||
|
78
index.js
78
index.js
@ -1,6 +1,76 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
cColorText: require('./cColorText/cColorText.vue'),
|
clog(message){
|
||||||
cPager: require('./cPager/cPager.vue'),
|
console.log('【【【【【【【【【【', getApp().$options.router.currentRoute.path, message, '】】】】】】】】】】】')
|
||||||
cQrcode: require('./cQrcode/cQrcode.vue'),
|
},
|
||||||
cToast: require('./cToast/cToast.vue')
|
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user