|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- //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: "https://dongfengqichen.jiyou-tech.com/",//测试接口根目录
- // urlRoot: "",//接口根目录
- urlStatic:"https://www.jiyou-tech.com/2020/496_qichen/static",//静态资源根目录
- openid: "",//OPENID
- session_key: "",//session_key
- userInfo: null,//用户信息
- openidSuccessFuc: null,//方法回调
- nowPage:'1',//当前tabBar
- },
- // 获取openId
- getOpenid: function (code) {
- wx.showLoading({
- title: '加载中',
- mask: true,
- })
- this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
- wx.hideLoading();
- console.log(res);
- if (res.code == 200) {
- wx.setStorageSync("openid", res.data.openid);
- wx.setStorageSync("session_key", res.data.session_key);
- this.globalData.openid = res.data.openid;
- this.globalData.session_key = res.data.session_key;
- // 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);
- }
- })
|