mirror of
https://gitee.com/elegant_wings/dbd-meeting-wx-small.git
synced 2025-06-21 11:59:37 +08:00
描述:手机注册登录
This commit is contained in:
parent
c31f3c1a94
commit
a1d4d934d0
21
miniprogram/api/login/login.js
Normal file
21
miniprogram/api/login/login.js
Normal file
@ -0,0 +1,21 @@
|
||||
import {
|
||||
request
|
||||
} from '../selfRequest';
|
||||
|
||||
// 微信登录接口
|
||||
export function loginRq(data) {
|
||||
return request({
|
||||
url: '/weixin/login',
|
||||
method: "post",
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
// 注册用户
|
||||
export function registerPhone(data) {
|
||||
return request({
|
||||
url: '/social_user_login/login',
|
||||
method: "post",
|
||||
data
|
||||
});
|
||||
}
|
56
miniprogram/api/selfRequest.js
Normal file
56
miniprogram/api/selfRequest.js
Normal file
@ -0,0 +1,56 @@
|
||||
const app = getApp()
|
||||
|
||||
export function request(params) {
|
||||
// 初始化参数
|
||||
let url = app.DOMAIN_NAME + params.url;
|
||||
let header = params.header || {};
|
||||
let data = params.data || {};
|
||||
let method = params.method || "GET";
|
||||
// 初始化数据
|
||||
header["content-type"] = 'application/json';
|
||||
if (wx.getStorageSync('token')) {
|
||||
header["Authorization"] = 'Bearer ' + wx.getStorageSync('token');
|
||||
}
|
||||
if (wx.getStorageSync('parkId')) {
|
||||
data.parkId = wx.getStorageSync('parkId')
|
||||
}
|
||||
|
||||
// 加载中
|
||||
wx.showLoading({
|
||||
mask: true,
|
||||
title: '正在加载..'
|
||||
})
|
||||
// 创建请求
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
header,
|
||||
success: res => {
|
||||
// 加载完成
|
||||
wx.hideLoading()
|
||||
// 身份信息过期
|
||||
if (res.data.code == 402 || res.data.code == 401) {
|
||||
wx.showModal({
|
||||
confirmText: '确认',
|
||||
content: '身份已过期,需重登录',
|
||||
success(res) {
|
||||
// 清空所有缓存
|
||||
wx.clearStorageSync()
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/login',
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// 回调完成
|
||||
resolve(res.data)
|
||||
}
|
||||
},
|
||||
fail: err => {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
@ -4,7 +4,7 @@ App({
|
||||
DOMAIN_NAME: 'http://192.168.0.11:9227', //接口域名
|
||||
IMG_NAME: 'http://192.168.0.11:9227',
|
||||
// DOMAIN_NAME: 'https://demo.metasoft.vip/api',
|
||||
// IMG_NAME: 'https://demo.metasoft.vip/api',
|
||||
// IMG_NAME: 'https://demo.metasoft.vip/api',
|
||||
globals: {
|
||||
refreshMyPages: false,
|
||||
homedata: {},
|
||||
@ -270,9 +270,9 @@ App({
|
||||
})
|
||||
},
|
||||
|
||||
ToWebURL(url){
|
||||
ToWebURL(url) {
|
||||
wx.navigateTo({
|
||||
url: pages/outer/outer,//要跳转的页面(需要新建立一个page页面)
|
||||
url: pages / outer / outer, //要跳转的页面(需要新建立一个page页面)
|
||||
success: () => {
|
||||
|
||||
}
|
||||
|
@ -164,24 +164,7 @@ Page({
|
||||
},
|
||||
|
||||
onShow() {
|
||||
let that = this
|
||||
if (wx.getStorageSync('token')) {
|
||||
app.AjaxRequest('get', {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + app.Getopenid()
|
||||
}, '/user/profile', {}, function (res) {
|
||||
if (res.code == 0) {
|
||||
that.setData({
|
||||
parkName: wx.getStorageSync('parkName')
|
||||
})
|
||||
wx.setStorageSync('MemberInfo', res.data)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/login',
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
navapply(e) {
|
||||
@ -201,10 +184,4 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
navparkList() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/index/parkList/parkList'
|
||||
})
|
||||
},
|
||||
|
||||
})
|
@ -1,23 +1,78 @@
|
||||
let app = getApp();
|
||||
import {
|
||||
loginRq,
|
||||
registerPhone
|
||||
} from "../../api/login/login.js"
|
||||
|
||||
Page({
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
IMG_NAME: app.IMG_NAME,
|
||||
getUserDataType: 'getPhoneNumber',
|
||||
openid: null,
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (e) {
|
||||
this.autoLogin();
|
||||
},
|
||||
|
||||
// 自动登录获取openid
|
||||
autoLogin() {
|
||||
let _this = this;
|
||||
wx.login({
|
||||
success(wxRes) {
|
||||
loginRq({
|
||||
"jsCode": wxRes.code
|
||||
}).then(res => {
|
||||
console.log('loginRq', res);
|
||||
_this.setData({
|
||||
openid: res.openid
|
||||
})
|
||||
// 判断用户是否注册
|
||||
if (res.token) {
|
||||
// 跳转首页
|
||||
_this.jumpIndex(res.openid, res.user.id, res.token.token)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 获取手机号
|
||||
getPhoneNumber(e) {
|
||||
let _this = this;
|
||||
console.log('getPhoneNumber', e)
|
||||
registerPhone({
|
||||
"code": e.detail.code,
|
||||
"openid": _this.data.openid
|
||||
}).then(res => {
|
||||
console.log('registerPhone', res);
|
||||
// 跳转首页
|
||||
_this.jumpIndex(res.openid, res.user.id, res.token.token)
|
||||
})
|
||||
},
|
||||
// 跳转首页
|
||||
jumpIndex(openid, userId, token) {
|
||||
// 存储用户信息
|
||||
wx.setStorageSync('openid', openid)
|
||||
wx.setStorageSync('userId', userId)
|
||||
wx.setStorageSync('token', token)
|
||||
// 跳转首页
|
||||
wx.reLaunch({
|
||||
url: '/pages/index/index',
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 授权登录
|
||||
*/
|
||||
authorLogin: function (e) {
|
||||
console.log('getuserinfo', e.detail.rawData);
|
||||
let _this = this;
|
||||
if (e.detail.errMsg !== 'getUserInfo:ok') {
|
||||
return false;
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
<view class="bottomView">
|
||||
<image class="loginBtnImg" src="{{IMG_NAME + '/profile/static/login/loginBtn.png'}}" mode="aspectFill"></image>
|
||||
<button class="loginBtn" open-type="getUserInfo" bindgetuserinfo="authorLogin"></button>
|
||||
<button wx:if="{{getUserDataType == 'getUserInfo'}}" class="loginBtn" open-type="getUserInfo" bindgetuserinfo="authorLogin"></button>
|
||||
<button wx:if="{{getUserDataType == 'getPhoneNumber'}}" class="loginBtn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>
|
||||
</view>
|
||||
|
||||
</view>
|
@ -3,7 +3,10 @@
|
||||
<!-- 会议室列表 -->
|
||||
<view class="meetingRoomView">
|
||||
<view class="meetingRoomItem">
|
||||
<view class="content">
|
||||
|
||||
</view>
|
||||
<image class="img" src="{{IMG_NAME + '/profile/static/meeting/accessControl/openClose.png'}}" mode="aspectFill" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
Loading…
x
Reference in New Issue
Block a user