| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- // pages/login/index.js
- const api = require('../../api/index.js');
- const app = getApp();
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- // 状态栏高度
- statusBarHeight: wx.getStorageSync('statusBarHeight'),
- // 导航栏高度
- navBarHeight: wx.getStorageSync('navBarHeight'),
- // 导航栏和状态栏高度
- navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
- // 胶囊
- menu:wx.getStorageSync('menu'),
- account:'',
- password:'',
- passwordtype:true,
- checked:false,
- shakeClass: '', // 控制晃动动画的类名
- Loginswitch:true
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // 检查是否需要展示隐私协议
- wx.getPrivacySetting({
- success: res => {
- if (res.needAuthorization) {
- // 需要用户同意隐私协议,显示授权弹窗
- this.setData({
- showPrivacy: true
- })
- }
- }
- })
- },
- onpassword(){
- console.log(111);
- this.setData({
- passwordtype:!this.data.passwordtype
- })
- },
- checkboxChange(e) {
- let _this = this
- console.log('checkbox发生change事件,携带value值为:', e.currentTarget.dataset.value)
-
- wx.requestSubscribeMessage({
- tmplIds: ['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'],
- success(res) {
- console.log(res);
- if(res['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q'] === 'accept') {
- // 用户同意订阅
- console.log(2222222);
- console.log(!e.currentTarget.dataset.value);
- _this.setData({
- checked:!e.currentTarget.dataset.value
- })
- }else{
- wx.showToast({
- title: '您将收不到新工单通知',
- icon: 'success',
- });
- }
- },fail: (err) => {
- // console.error('请求失败:', err);
- console.log(err);
- wx.showToast({ title: '请开启订阅消息通知', icon: 'none' });
- }
-
- })
-
-
- },
-
- onHandleLogin(){
- wx.getPhoneNumber({
- success: (res) => {
- const encryptedData = res.encryptedData;
- const iv = res.iv;
- console.log(encryptedData);
- console.log(iv);
- // 将encryptedData和iv发送给后端,用于解密手机号码
- },
- fail: (err) => {
- console.error('获取手机号码失败', err);
- }
- });
- },
- authorizationbtn(){
-
- wx.requestSubscribeMessage({
- tmplIds: ['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'],
- success(res) {
- console.log(res);
- if(res['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'] === 'accept') {
- // 用户同意订阅
- }
- }
- })
-
- },
-
- bindKeyInput1: function (e) {
- this.setData({
- account: e.detail.value
- })
- },
- bindKeyInput2: function (e) {
- this.setData({
- password: e.detail.value
- })
- },
- // 隐私协议同意按钮回调
- handleAgreePrivacy() {
- this.setData({
- showPrivacy: false
- })
- // 用户同意后,再执行登录流程
- },
- onstatus(){
- if (!this.data.checked) {
- return wx.showToast({
- title: '请勾选同意',
- icon: 'none',
-
- });
- }
- },
- // 获取手机号回调
- onGetPhoneNumber(e) {
- console.log(e);
- let _this = this
- if (!this.data.checked) {
- return wx.showToast({
- title: '请勾选同意',
- icon: 'none',
-
- });
- }
- // wx.requestSubscribeMessage({
- // tmplIds: ['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'],
- // success(res) {
- // console.log(res);
- // if(res['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q'] === 'accept') {
- // // 用户同意订阅
- // console.log(2222222);
-
- wx.login({
- success: ress => {
- console.log(ress);
- const code = ress.code;
- // 2. 将 code 发送到服务器,换取到 openId 和 phoneNumber
- // 这里的 your_server_url 需要替换成你自己的服务器地址
-
- let obj = {
- phonecode:e.detail.code,
- code:code
- }
- api.request(`/SysPartnerLogController/login`, 'post',obj,{ isPublic: true })
- .then((data) => {
- console.log(data);
- if (data.code == 200) {
-
- // 设置数据到本地存储
- wx.setStorage({
- key: 'token', // 存储的key值
- data:data.data.token,
- success: function(ress) {
- console.log(ress);
- wx.setStorageSync('hasLogin', true);
- _this.getuser()
- // wx.reLaunch({
- // url: '/pages/index/index'
- // });
-
-
- }
- });
- }else{
- wx.showToast({
- title: data.msg,
- icon: 'success',
- });
- }
-
- })
- .catch((err) => {
- wx.showToast({
- title:'登录失败',
- icon: 'none',
- });
- console.error('请求失败:', err);
- });
- }
- })
- // }else{
- // wx.showToast({
- // title: '您将收不到新工单通知',
- // icon: 'success',
- // });
- // }
- // },fail: (err) => {
- // // console.error('请求失败:', err);
- // console.log(err);
- // wx.showToast({ title: '请开启订阅消息通知', icon: 'none' });
- // }
-
- // })
-
-
-
- },
- getuser(){
- api.request(`/partner/selectinformation`, 'POST',{})
- .then((res) => {
- // 设置数据到本地存储
- wx.setStorage({
- key: 'partnerPosition', // 存储的key值
- data:res.data,
- success: function(ress) {
- app.redirectByRole(res.data);
- wx.showToast({
- title: '登录成功',
- icon: 'success',
- });
- // wx.getStorageSync('token');
- }
- });
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- // 处理登录按钮点击
- onLogin() {
- // 获取本地存储的数据
- if (!this.data.checked) {
- return wx.showToast({
- title: '请勾选同意',
- icon: 'none',
-
- });
-
- }
- if(this.data.account==''){
- return wx.showToast({
- title: '请输入手机号码',
- icon: 'none',
-
- });
- }else if(this.data.account.length!=11) {
- return wx.showToast({
- title: '请输入正确手机号码',
- icon: 'none',
- });
- }
- let _this = this
-
-
- wx.login({
- success: res => {
- console.log(res);
- const code = res.code;
- // 2. 将 code 发送到服务器,换取到 openId 和 phoneNumber
- // 这里的 your_server_url 需要替换成你自己的服务器地址
-
- let obj = {
- phone:_this.data.account,
- code:code,
- sharecode:_this.data.password
- }
- api.request(`/SysPartnerLogController/loginphone`, 'post',obj,{ isPublic: true })
- .then((data) => {
- console.log(data);
- if (data.code == 200) {
-
- // 设置数据到本地存储
- wx.setStorage({
- key: 'token', // 存储的key值
- data:data.data.token,
- success: function(ress) {
- console.log(ress);
-
- wx.reLaunch({
- url: '/pages/index/index'
- });
- wx.showToast({
- title: '登录成功',
- icon: 'success',
- });
-
- }
- });
- }else{
- wx.showToast({
- title: data.msg,
- icon: 'success',
- });
- }
-
- })
- .catch((err) => {
- wx.showToast({
- title:err.msg+',请使用手机号一键登录',
- icon: 'none',
- });
- console.error('请求失败:', err);
- });
- }
- })
-
-
-
-
- },
- onprivacy(e){
- console.log(e.target.dataset.name);
- wx.navigateTo({
- url: `/pages/privacy/index?name=${e.target.dataset.name}`,
- })
-
- },
- // 切换登录模式
- onswitch(e){
- console.log(e);
- // if (!e.target.dataset.value) {
- // return wx.showToast({
- // title: '待开发',
- // icon: 'none',
- // });
-
- // }
- this.setData({
- Loginswitch:e.target.dataset.value
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|