// pages/login.js const util = require("../utils/util"); const tools = require("../utils/tool"); const App = getApp(); var mobile = /^(13[0-9]|14[4579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[1589])\d{8}$/; Page({ /** * 页面的初始数据 */ data: { appAssetsUrl: App.appAssetsUrl, appAssetsUrl2: App.appAssetsUrl2, pass: true, focus: false, cpass: true, cfocus: false, btntxt: "获取验证码", settimeoutName: "", countstatus: false, telInput: "", uuid: "", imgCode: "", code: "", params: { id: "", vipname: "", memberphoto: "", }, inviteCode: "", showUserBtn: false, isCheck: false, openid: "", meetId: "", expertId: "", memberId: "", loginPopup: false, code: null, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.setNavigationBarTitle({ title: "青雲慧", }); let taht = this; if (options.meetId && options.expertId && options.memberId) { this.setData({ meetId: options.meetId, expertId: options.expertId, memberId: options.memberId, }); } wx.login({ success(res) { App._post_form( "member/authorization", "application/json;charset=UTF-8", { code: res.code, }, (data) => { if (data.code == 0) { wx.setStorageSync("openid", data.data.openid); wx.setStorageSync("session_key", data.data.session_key); taht.setData({ openid: data.data.openid, }); } } ); }, }); if (options.inviteCode) { var inviteCode = decodeURIComponent(options.inviteCode); // let inviteCode = options.inviteCode; this.setData({ inviteCode, }); } console.log(options, "options"); }, reCode() { // this.getUrl(); }, toPrivacy() { wx.navigateTo({ url: "/pages/privacy/privacy", }); }, toHome() { wx.switchTab({ url: "/pages/home/index/index", }); }, goxy() { wx.navigateTo({ url: "/pages/volunteer/worldXyi/worldXyi", }); }, getUrl() { this.data.uuid = this.get_uuid(); this.setData({ url: App.apiRoot + "captcha.jpg?uuid=" + this.data.uuid, }); }, change(e) { console.log(e); if (e.detail.value.length > 0) { this.setData({ isCheck: true, }); } else { this.setData({ isCheck: false, }); } }, updateUserInfo(e) { let _this = this; wx.getUserProfile({ desc: "用于完善会员资料", // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { var userinfo = res.userInfo; _this.data.params.memberphoto = userinfo.avatarUrl; _this.data.params.vipname = userinfo.nickName; }, }); return; App._post_form( "member/apiUpdateMeberInfo", "application/json", JSON.stringify(_this.data.allData), function (res) { if (res.code === 0) { wx.showLoading({ title: "保存中...", duration: 1000, }); _this.PushVipInfo(); if (_this.data.nolink === true) { wx.switchTab({ url: "/pages/my/index/index", }); } else if (_this.data.nolink === false) { wx.navigateBack({ delta: 1, }); } } } ); }, getImgCode(e) { this.data.imgCode = e.detail.value; }, //统计积分(每日登录) addScore: function () { if (!util.getUserId()) { return; } wx.showLoading({ title: "努力加载中...", }); App._post_form( "scoreStu/dailyLogin", "", { stuId: util.getUserId(), }, function (res) { wx.hideToast(); } ); }, // getPhoneNumber(e) { // var that = this; // if (e.detail.errMsg != "getPhoneNumber:ok") { // return; // } // var params = { // encryptedData: e.detail.encryptedData, // iv: e.detail.iv, // sessionKey: wx.getStorageSync("session_key"), // }; // App._post_form( // "member/decodeUserInfo?encryptedData=" + // params.encryptedData + // "&iv=" + // params.iv + // "&sessionKey=" + // params.sessionKey, // "application/json;charset=UTF-8", // params, // function (data) { // if (data.code == 0) { // that.setData({ // telInput: data.msg, // showUserBtn: true, // }); // } // }, // function (err) { // wx.showToast({ // title: "请求失败", // icon: "none", // duration: 3500, // }); // return; // } // ); // }, handleAgreePrivacyAuthorization() { }, getUserInfo() { if (!this.data.isCheck) { wx.showToast({ title: "请勾选隐私协议", icon: "none", duration: 3500, }); return; } let that = this; that.login(); // wx.getUserProfile({ // desc: "用于确认用户身份", // success: (res) => { // // wx.setStorageSync("userInfo", res.userInfo); // // that.setData({ // // ["params.memberphoto"]: res.userInfo.avatarUrl, // // ["params.vipname"]: res.userInfo.nickName, // // }); // that.login(); // }, // fail(err) { // wx.showToast({ // title: "获取用户信息失败", // icon: "none", // }); // }, // }); }, login() { let that = this; var pr = { openid: wx.getStorageSync("openid"), // tel: this.data.telInput, // inviteCode: this.data.inviteCode, // memberPhoto: this.data.params.memberphoto, // vipname: this.data.params.vipname, }; wx.showLoading({ title: "提交中...", }); App._post_form( "auth/appletsLogin", "application/json;charset=UTF-8", pr, function (res) { if (res.code === 0) { if (res.memberinfo) { wx.setStorageSync("USER", res.memberinfo); that.setData({ "params.id": res.memberinfo.id, }); that.addScore(); if (that.data.meetId != "") { //跳到我的约见详情页 wx.reLaunch({ url: `/meet/meet/addmeet?meetId=${this.data.meetId}&expertId=${this.data.expertId}&memberId=${this.data.memberId}`, success() {}, }); } else { wx.reLaunch({ url: "/pages/home/index/index?login=1", success() { let pages = getCurrentPages(); let prevpage = pages[pages.length - 1]; if (prevpage.hasOwnProperty("loadCity")) { prevpage.loadCity(); } }, }); } return; } that.setData({ loginPopup: true }) return false } }, function (err) { wx.showToast({ title: "请求失败", icon: "none", duration: 3500, }); return; } ); }, closePopup() { this.setData({ loginPopup: false }) }, register() { if (!this.data.params.memberphoto) { return tools.alert("请先获取头像信息"); } if (!this.data.params.vipname) { return tools.alert("请先获取昵称信息"); } wx.setStorageSync("userInfo", { avatarUrl: this.data.params.memberphoto, nickName: this.data.params.vipname }); wx.navigateTo({ url: "/pages/register/register?inviteCode=" + this.data.inviteCode + "&openid=" + this.data.openid + "&meetId=" + this.data.meetId + "&expertId=" + this.data.expertId + "&memberId=" + this.data.memberId, }); return; }, //获取头像 getUserImg(res) { let that = this; wx.showLoading({ title: '上传中', }); let apiUrl = App.apiRoot + 'file/upload'; let a = wx.uploadFile({ url: apiUrl, filePath: res.detail.avatarUrl, name: 'file', success: (res) => { const newData = JSON.parse(res.data) if (newData.code == '000000') { that.setData({ ['params.memberphoto']: newData.data }); wx.hideLoading(); } }, fail() { wx.hideLoading(); }, }); }, getNickname(e) { let name = e.detail.value.trim(); this.setData({ ['params.vipname']: name }); console.log('this.params', this.data.params); }, formSubmit(e) { let _this = this; if (e.detail.value) { let value = e.detail.value; if (!value.tel) { _this.setData({ pass: false, }); return; } else { if (!mobile.test(_this.data.telInput)) { _this.setData({ pass: false, }); return; } } if (!value.code) { _this.setData({ cpass: false, cfocus: false, }); return; } wx.login({ success(res) { if (res.code) { // 发起网络请求 let parm = { tel: value.tel, code: res.code, authCode: value.code, }; App._post_form( "member/appLogin", "application/json", JSON.stringify(parm), function (res) { if (res.code === 0) { wx.setStorageSync("USER", res.memberinfo); wx.reLaunch({ url: "/pages/home/index/index", }); } else { wx.showModal({ title: "温馨提示", content: res.msg, showCancel: false, }); } } ); } else { console.log("登录失败!" + res.errMsg); } }, }); } }, sendCode() { let _this = this; if (_this.data.telInput) { if (!mobile.test(_this.data.telInput)) { _this.setData({ pass: false, cfocus: true, }); return; } if (_this.data.countstatus === false) { if (_this.data.imgCode) { App._post_form( "verification/verKey", "", { phone: _this.data.telInput, code: _this.data.imgCode, uuid: _this.data.uuid, }, function (res) { if (res.code === 0) { setTimeout(() => { wx.showToast({ title: "发送成功,请查收!", icon: "none", duration: 2000, }); }, 200); // _this.data.code = res.key; } else { console.log(res); wx.showToast({ title: res.msg, icon: "none", duration: 2000, }); } } ); } else { wx.showToast({ title: "请输入图形验证码后获取短信验证码", icon: "none", duration: 3500, }); return; } } util.getPhoneCode(60, _this, _this.data.countstatus); } else { _this.setData({ pass: false, }); } }, focus() { this.setData({ focus: true, pass: true, }); }, blur(e) { if (e.detail.value) { this.data.telInput = e.detail.value; } this.setData({ focus: false, pass: true, }); }, cfocus() { this.setData({ cfocus: true, cpass: true, }); }, cblur() { this.setData({ cfocus: false, }); }, get_uuid() { var s = []; var hexDigits = "0123456789abcdef"; for (var i = 0; i < 36; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); } s[14] = "4"; s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); s[8] = s[13] = s[18] = s[23] = "-"; var uuid = s.join(""); return uuid; }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {}, inviteCodeInput(e) { this.setData({ inviteCode: e.detail.value, }); }, });