168 lines
4.0 KiB
Plaintext
168 lines
4.0 KiB
Plaintext
import tools from '@/common/tools.js'
|
||
|
||
module.exports = {
|
||
data() {
|
||
return {
|
||
URL: tools.URL,//资源URL+
|
||
noClick: true,
|
||
}
|
||
},
|
||
computed: {
|
||
app() {
|
||
return getApp().globalData
|
||
},
|
||
isVip() {
|
||
if (this.app.userInfo.membership_level==0){
|
||
return false
|
||
} else return true
|
||
}
|
||
},
|
||
onShow() {
|
||
|
||
},
|
||
onLoad() {
|
||
|
||
},
|
||
methods: {
|
||
GetUrlParam(url,paraName) {
|
||
var arrObj = url.split("?");
|
||
|
||
if (arrObj.length > 1) {
|
||
var arrPara = arrObj[1].split("&");
|
||
var arr;
|
||
|
||
for (var i = 0; i < arrPara.length; i++) {
|
||
arr = arrPara[i].split("=");
|
||
|
||
if (arr != null && arr[0] == paraName) {
|
||
return arr[1];
|
||
}
|
||
}
|
||
return "";
|
||
}
|
||
else {
|
||
return "";
|
||
}
|
||
},
|
||
// 防止处理多次点击
|
||
noMultipleClicks(methods, info) {
|
||
// methods是需要点击后需要执行的函数, info是点击需要传的参数
|
||
let that = this;
|
||
if (that.noClick) {
|
||
// 第一次点击
|
||
that.noClick= false;
|
||
if(info && info !== '') {
|
||
// info是执行函数需要传的参数
|
||
methods(info);
|
||
} else {
|
||
methods();
|
||
}
|
||
setTimeout(()=> {
|
||
that.noClick= true;
|
||
}, 2000)
|
||
} else {
|
||
// 这里是重复点击的判断
|
||
}
|
||
},
|
||
// 跳转下一页
|
||
goNext(url) {
|
||
uni.navigateTo({
|
||
url: url
|
||
})
|
||
},
|
||
// 返回上一页
|
||
goBack(num) {
|
||
uni.navigateBack({
|
||
delta: num
|
||
})
|
||
},
|
||
showtt:function(title,icon) {
|
||
if(title&&title.length>0) {
|
||
uni.showToast({
|
||
title:title,
|
||
duration:2000,
|
||
icon:icon?icon : 'none'
|
||
})
|
||
}
|
||
},
|
||
// from表单的输入
|
||
formInfo(data, keys) {
|
||
let obj = {
|
||
...data
|
||
}
|
||
// data 验证对象 Object
|
||
// keys 验证对象中非必填字段 Array
|
||
if (keys && keys[0]) {
|
||
keys.forEach(val => {
|
||
delete obj[val]
|
||
})
|
||
}
|
||
let show = true
|
||
for (let key in obj) {
|
||
const value = obj[key]
|
||
if (!value) {
|
||
uni.showToast({
|
||
title: '请检查信息是否填写',
|
||
icon: 'none'
|
||
})
|
||
console.log('未填写完整', value, key)
|
||
show = false;
|
||
break;
|
||
}
|
||
}
|
||
return show;
|
||
},
|
||
//函数拷贝
|
||
copyObj(obj = {}) {
|
||
//变量先置空
|
||
let newobj = null;
|
||
|
||
//判断是否需要继续进行递归
|
||
if (typeof(obj) == 'object' && obj !== null) {
|
||
newobj = obj instanceof Array ? [] : {};
|
||
//进行下一层递归克隆
|
||
for (var i in obj) {
|
||
newobj[i] = this.copyObj(obj[i])
|
||
}
|
||
//如果不是对象直接赋值
|
||
} else newobj = obj;
|
||
|
||
return newobj;
|
||
},
|
||
axiosFromToken:function(method,url,data,showLoads){
|
||
let token = uni.getStorageSync('token')?uni.getStorageSync('token') : '';//用户的token
|
||
if(showLoads) { uni.showLoading({ 'title':showLoads }) };//加载中的框
|
||
return new Promise((resolve,reject)=>{
|
||
uni.request({
|
||
url: tools.httpOne + url,//请求地址 url
|
||
method:method,//请求格式 method POST GET
|
||
data:data,//请求参数 data
|
||
header:{ 'content-Type':'application/x-www-form-urlencoded','token':token },
|
||
success:(res)=>{
|
||
if(showLoads) { uni.hideLoading() }
|
||
if(res.statusCode==401) {
|
||
uni.showModal({
|
||
title: '温馨提示',
|
||
content: '尚未登录或登录已过期,是否前往登录?',
|
||
success: (res) => {
|
||
uni.clearStorageSync()
|
||
uni.navigateTo({
|
||
url: "/pages/login/login"
|
||
})
|
||
}
|
||
});
|
||
return false
|
||
}
|
||
resolve(res.data)
|
||
},
|
||
fail:(err)=>{
|
||
reject(err)
|
||
},
|
||
complete() {
|
||
|
||
}
|
||
})
|
||
})
|
||
},
|
||
},
|
||
} |