123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- // 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,
- });
- },
- });
|