|
|
@@ -0,0 +1,171 @@ |
|
|
|
//app.js |
|
|
|
App({ |
|
|
|
onLaunch: function () { |
|
|
|
// 展示本地存储能力 |
|
|
|
// var openid = wx.getStorageSync('openid') || ""; |
|
|
|
// if (!openid) { |
|
|
|
// // 登录 |
|
|
|
// this.wxLogin(); |
|
|
|
// } else { |
|
|
|
// this.globalData.openid = openid; |
|
|
|
// this.getRegionList(); |
|
|
|
// } |
|
|
|
}, |
|
|
|
wxLogin() { |
|
|
|
wx.login({ |
|
|
|
success: res => { |
|
|
|
if (res.code) { |
|
|
|
this.getOpenid(res.code); |
|
|
|
} else { |
|
|
|
console.log('登录失败!' + res.errMsg) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
globalData: { |
|
|
|
urlRoot: "",//测试接口根目录 |
|
|
|
// urlRoot: "",//接口根目录 |
|
|
|
urlStatic:"https://www.jiyou-tech.com/2020/496_qichen/static",//静态资源根目录 |
|
|
|
openid: "",//OPENID |
|
|
|
userInfo: null,//用户信息 |
|
|
|
openidSuccessFuc: null,//方法回调 |
|
|
|
}, |
|
|
|
// 获取openId |
|
|
|
getOpenid: function (code) { |
|
|
|
wx.showLoading({ |
|
|
|
title: '加载中', |
|
|
|
mask: true, |
|
|
|
}) |
|
|
|
this.wxRequest(this.globalData.urlRoot + "/login/getOpenid", { code: code }, res => { |
|
|
|
wx.hideLoading(); |
|
|
|
if (res.code == 200) { |
|
|
|
wx.setStorageSync("openid", res.openid); |
|
|
|
this.globalData.openid = res.openid; |
|
|
|
this.getRegionList(); |
|
|
|
if (this.globalData.openidSuccessFuc) { |
|
|
|
this.globalData.openidSuccessFuc(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
wx.showToast({ |
|
|
|
title: res.msg, |
|
|
|
icon: "none" |
|
|
|
}) |
|
|
|
} |
|
|
|
}, this); |
|
|
|
}, |
|
|
|
/** |
|
|
|
* wx.request |
|
|
|
*/ |
|
|
|
wxRequest: function (url, params, callback, thisArg, methods, openid) { |
|
|
|
let that = this; |
|
|
|
|
|
|
|
var httpUrl = url; |
|
|
|
var str = ""; |
|
|
|
var count = 0; |
|
|
|
for (let key in params) { |
|
|
|
if (count) { |
|
|
|
str += "&" + key + "=" + params[key]; |
|
|
|
} else { |
|
|
|
str += key + "=" + params[key]; |
|
|
|
} |
|
|
|
count++; |
|
|
|
} |
|
|
|
if (str) { |
|
|
|
httpUrl += "?" + str; |
|
|
|
} |
|
|
|
if (!methods) { |
|
|
|
methods = "GET"; |
|
|
|
} |
|
|
|
if (methods == "POST") { |
|
|
|
wx.request({ |
|
|
|
url: url, |
|
|
|
data: params, |
|
|
|
method: methods, |
|
|
|
header: { |
|
|
|
"content-type": "application/x-www-form-urlencoded", |
|
|
|
"OPENID": this.globalData.openid |
|
|
|
}, |
|
|
|
success: function (re) { |
|
|
|
if (re.data.code == -1002) { |
|
|
|
wx.removeStorageSync('openid'); |
|
|
|
that.wxLogin(); |
|
|
|
// that.wxRequest(url, params, callback, thisArg, methods, openid); |
|
|
|
} |
|
|
|
if (callback && thisArg) { |
|
|
|
callback.call(thisArg, re.data); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: function (re) { |
|
|
|
wx.hideLoading(); |
|
|
|
} |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.request({ |
|
|
|
url: httpUrl, |
|
|
|
method: methods, |
|
|
|
header: { |
|
|
|
"OPENID": this.globalData.openid, |
|
|
|
}, |
|
|
|
success: function (re) { |
|
|
|
if (re.data.code == -1002) { |
|
|
|
wx.removeStorageSync('openid'); |
|
|
|
that.wxLogin(); |
|
|
|
// that.wxRequest(url, params, callback, thisArg, methods, openid); |
|
|
|
} |
|
|
|
if (callback && thisArg) { |
|
|
|
callback.call(thisArg, re.data); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: function (res) { |
|
|
|
wx.hideLoading(); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
submitUserMsg: function (data) {//提交用户信息 |
|
|
|
this.wxRequest(this.globalData.urlRoot + "/login/submitWxInfo", { userInfo: data }, res => { |
|
|
|
}, this, "POST"); |
|
|
|
}, |
|
|
|
codeVerify: function (card) {//身份证号码验证 |
|
|
|
let rule = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/; |
|
|
|
return rule.test(card); |
|
|
|
}, |
|
|
|
mobileVerify: function (mobile) {//手机号验证 |
|
|
|
let rule = /^1\d{10}$/; |
|
|
|
return rule.test(mobile); |
|
|
|
}, |
|
|
|
callMobile: function (e) {//拨打电话 |
|
|
|
wx.makePhoneCall({ |
|
|
|
phoneNumber: e //仅为示例,并非真实的电话号码 |
|
|
|
}) |
|
|
|
}, |
|
|
|
sharePack: function () {//分享 |
|
|
|
return { |
|
|
|
title: '', |
|
|
|
imageUrl: "", |
|
|
|
path: "/pages/index/index" |
|
|
|
} |
|
|
|
}, |
|
|
|
addformId: function (e) {//添加formid |
|
|
|
console.log("下面是formid"); |
|
|
|
console.log(e); |
|
|
|
this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => { |
|
|
|
// if(res.code==200){ |
|
|
|
// console.log(res.msg); |
|
|
|
// }else{ |
|
|
|
// console.log(res.msg); |
|
|
|
// } |
|
|
|
console.log(res.msg); |
|
|
|
}, this, "POST"); |
|
|
|
}, |
|
|
|
getRegionList: function () {//获取可选区域列表 |
|
|
|
this.wxRequest(this.globalData.urlRoot + "/user/getAreaList", {}, res => { |
|
|
|
if (res.code == 200) { |
|
|
|
this.globalData.cityAllData = res.data; |
|
|
|
console.log(this.globalData.cityAllData); |
|
|
|
} else { |
|
|
|
console.log(res.msg) |
|
|
|
} |
|
|
|
}, this); |
|
|
|
} |
|
|
|
}) |