| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- // pages/userLogin/userLogin.js
- //获取应用实例
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- spashTextValue: '- 智慧服务 智创未来 -',
- splashImageUrl: '/images/tu.png',
- splashImageUrl2: '/images/zi.png',
- code: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- app.getScene(options);
- this.getCode();
- },
- getCode(){
- let that = this;
- wx.login({
- success: function (ret) {
- that.setData({
- code: ret.code
- })
- }
- });
- },
- getPhoneNumber(e){
- // console.log(e);
- var that = this;
- wx.showLoading({
- title: '加载中',
- mask: true
- });
- let orgId = wx.getStorageSync("orgId");
- wx.request({
- url: app.globalData.serverUrl + 'login/wxpLogin',
- data: {
- orgId: orgId,
- code: this.data.code,
- iv: e.detail.iv,
- encryptedData: e.detail.encryptedData
- },
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success: function (res) {
- console.log(res);
- wx.hideLoading();
- if (res.data.code == 0) {
- try {
- app.logout();
- wx.setStorageSync("userId", res.data.data.userId);
- wx.setStorageSync("token", res.data.data.token);
- wx.setStorageSync("orgId", res.data.data.orgId);
- } catch (e) { };
- var userinfo = {
- userId: res.data.data.userId,
- token: res.data.data.token,
- };
- app.globalData.userinfo = userinfo;
- wx.switchTab({
- url: '/pages/index/index'
- });
- }else{
- wx.showModal({
- title: '提示',
- content: res.data.message,
- showCancel: false
- })
- }
- that.getCode();
- },
- fail:function(e){
- console.log(e);
- wx.hideLoading();
- wx.showModal({
- title: '提示',
- content: '登录失败,请重试',
- showCancel: false
- })
- that.getCode();
- }
- })
-
- },
- getUserInfo(){
- wx.getUserProfile({
- desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (e) => {
- wx.showLoading({
- title: '加载中',
- mask: true
- });
- let orgId = wx.getStorageSync("orgId");
- wx.request({
- url: app.globalData.serverUrl + 'login/wxLogin',
- data: {
- orgId: orgId,
- code: this.data.code,
- iv: e.iv,
- encryptedData: e.encryptedData
- },
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success: function (res) {
- console.log(res);
- wx.hideLoading();
- if (res.data.code == 0) {
- try {
- app.logout();
- wx.setStorageSync("userId", res.data.data.userId);
- wx.setStorageSync("token", res.data.data.token);
- } catch (e) { };
- var userinfo = {
- userId: res.data.data.userId,
- token: res.data.data.token,
- };
- app.globalData.userinfo = userinfo;
- wx.switchTab({
- url: '/pages/index/index'
- });
- }else{
- wx.showModal({
- title: '提示',
- content: res.data.message,
- showCancel: false
- })
- }
- },
- fail:function(){
- wx.hideLoading();
- wx.showModal({
- title: '提示',
- content: '登录失败,请重试',
- showCancel: false
- })
- }
- })
- }
- });
- },
-
- //提交
- onSubmit: function(){
- var username = this.data.username;
- var password = this.data.password;
- //去除开始结尾空格
- if (username.replace(/^(\s|\xA0)+|(\s|\xA0)+$/g, '') && password){
- wx.showLoading({
- title: '登录中',
- mask: true
- });
- wx.login({
- success: function (loginRes) {
-
- },
- fail:function(e){
- wx.hideLoading();
- wx.showModal({
- title: '提示',
- content: '登录失败,请重试',
- showCancel: false
- })
- }
- })
- }else{
- wx.showModal({
- title: '提示',
- content: '账号或密码为空!',
- showCancel: false
- })
- }
- },
- goYY(){
- var token = wx.getStorageSync("visitorToken");
- if (!token || token == undefined) { //未登录
- wx.login({
- success: function (loginRes) {
- var serverUrl = app.globalData.visitorServerUrl;
- if (loginRes) {
- wx.request({
- url: serverUrl + 'oauth/checkCode',
- data: {
- type: 2,
- code: loginRes.code//临时登录凭证
- },
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success: function (res) {
- if (res.data.code == -101) {
- wx.removeStorageSync("visitorToken");
- wx.redirectTo({
- url: '/pages/splash/splash?type=visitor'
- })
- }else if (res.data.code == 0) {
- try {
- wx.setStorageSync("visitorToken", res.data.data.token);
- wx.setStorageSync("visitorUserId", res.data.data.userId);
- } catch (e) {
- app.logout();
- wx.showModal({
- title: '提示',
- content: '登录异常!',
- showCancel: false
- })
- return false;
- };
- wx.redirectTo({
- url: '/pages/visitor/index'
- });
- }
- },
- fail: function (err) {
- wx.showModal({
- title: '提示',
- content: '登录异常!',
- showCancel: false
- })
- }
- })
- } else {
- wx.showModal({
- title: '提示',
- content: '登录异常!',
- showCancel: false
- })
- }
- }
- })
- }else{
- wx.navigateTo({
- url: '/pages/visitor/index'
- });
- }
-
- },
- })
|