21 changed files with 1270 additions and 422 deletions
@ -0,0 +1,11 @@ |
|||
const isEmpty = (obj) => { |
|||
if (obj == undefined || obj == null || obj === "" || obj === "null") { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
export { |
|||
isEmpty |
|||
} |
@ -0,0 +1,8 @@ |
|||
const toast = (msg) => { |
|||
uni.showToast({ |
|||
title: msg, |
|||
icon: 'none' |
|||
}) |
|||
} |
|||
|
|||
export default toast |
@ -0,0 +1,174 @@ |
|||
import { |
|||
isEmpty |
|||
} from './TextUtils.js' |
|||
|
|||
const wxAuthLogin = () => { |
|||
// 判断是否已经登陆
|
|||
if (getApp().globalData.isLogin) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(getApp().globalData.sysUserSid) |
|||
}) |
|||
} |
|||
|
|||
return new Promise((resolve, reject) => { |
|||
// 授权登录
|
|||
wx.login({ |
|||
// 未配置 onlyAuthorize 的情况下调用此接口,code 值不返回,用以换取 authResult 。
|
|||
// 配置 onlyAuthorize 会把未使用过的 code 值返回,
|
|||
onlyAuthorize:true, |
|||
success: function(res) { |
|||
console.log('Http网络请求res',res) |
|||
if (res.code) { |
|||
|
|||
if (getApp().globalData.isDebug) { |
|||
console.log('Http网络请求info', { |
|||
"wxCode": res.code |
|||
}) |
|||
} |
|||
uni.showLoading({ |
|||
title: '加载中...', |
|||
mask: true |
|||
}); |
|||
|
|||
uni.request({ |
|||
// 组装请求地址
|
|||
url: getApp().globalData.wxAuthLoginURL, |
|||
// 请求方式 GET POST
|
|||
method: "GET", |
|||
header: { |
|||
// 传参方式
|
|||
'content-type': "application/x-www-form-urlencoded" |
|||
}, |
|||
// 具体参数
|
|||
data: { |
|||
"wxCode": res.code |
|||
}, |
|||
|
|||
success: res => { |
|||
|
|||
// 关闭显示框
|
|||
uni.hideLoading(); |
|||
|
|||
console.log(res) |
|||
|
|||
if (getApp().globalData.isDebug) { |
|||
console.log('Http网络路径', getApp().globalData.wxAuthLoginURL) |
|||
console.log('Http网络请求结果', JSON.parse(JSON.stringify( |
|||
res.data))) |
|||
} |
|||
|
|||
|
|||
if (res.statusCode == 200) { |
|||
// 下面是接口返回的数据
|
|||
if (!res.data.success) { |
|||
if ("A01001" == res.data.code || "A01002" == res.data.code ) { |
|||
// 绑定手机号
|
|||
uni.navigateTo({ |
|||
url: '../index/BindPhone?sysUserWxAuthSid=' + res.data.data |
|||
}) |
|||
// reject("绑定手机号")
|
|||
} |
|||
else { |
|||
// 错误提示
|
|||
if (isEmpty(res.data)) { |
|||
// 未成功获取到服务器返回的json
|
|||
uni.showToast({ |
|||
// 不能超过7个字
|
|||
title: "服务器响应为空", |
|||
icon: "error" |
|||
}) |
|||
reject("服务器响应为空") |
|||
} else { |
|||
|
|||
let errorMsg = res.data.msg |
|||
|
|||
if (isEmpty(errorMsg)) { |
|||
errorMsg = url+"服务器未返回错误信息" |
|||
} |
|||
|
|||
uni.showToast({ |
|||
title: errorMsg, |
|||
// 保证文字长度
|
|||
icon: "none", |
|||
duration: 3000 |
|||
}) |
|||
} |
|||
|
|||
reject(errorMsg) |
|||
} |
|||
return |
|||
} |
|||
|
|||
// 保存
|
|||
uni.setStorageSync("sysUserSid", res.data.data.sysUserSid); |
|||
uni.setStorageSync("isLogin", res.data.data.isLogin); |
|||
getApp().globalData.isLogin = res.data.data.isLogin |
|||
getApp().globalData.sysUserSid = res.data.data.sysUserSid |
|||
getApp().globalData.token = res.data.data.token |
|||
|
|||
// 直接返回Response
|
|||
resolve(getApp().globalData.sysUserSid) |
|||
|
|||
|
|||
} else { |
|||
|
|||
uni.showToast({ |
|||
title: res.statusCode + ":" + res |
|||
.errMsg, |
|||
// 保证文字长度
|
|||
icon: "none", |
|||
duration: 3000 |
|||
}) |
|||
|
|||
reject(res.errMsg) |
|||
} |
|||
|
|||
}, |
|||
fail: (err) => { |
|||
// 关闭显示框
|
|||
uni.hideLoading(); |
|||
|
|||
if (getApp().globalData.isDebug) { |
|||
console.log("Http网络请求fail", err) |
|||
} |
|||
|
|||
|
|||
uni.showToast({ |
|||
title: '请检查网络', |
|||
icon: 'error' |
|||
}) |
|||
|
|||
reject(err) |
|||
|
|||
}, |
|||
complete: () => { |
|||
|
|||
} |
|||
}); |
|||
|
|||
|
|||
} else { |
|||
|
|||
uni.showToast({ |
|||
title: "授权登录获取code失败:" + res.errMsg, |
|||
icon: 'none' |
|||
}) |
|||
|
|||
reject(res.errMsg) |
|||
} |
|||
}, |
|||
fail: function(res) { |
|||
uni.showToast({ |
|||
title: "授权登录失败:" + res.errMsg, |
|||
icon: 'none' |
|||
}) |
|||
|
|||
reject(res.errMsg) |
|||
} |
|||
}); |
|||
|
|||
}) |
|||
|
|||
} |
|||
|
|||
export default wxAuthLogin |
@ -0,0 +1,106 @@ |
|||
import { |
|||
isEmpty |
|||
} from './TextUtils.js' |
|||
|
|||
const wxAuthLogin = () => { |
|||
// 判断是否已经登陆
|
|||
if (getApp().globalData.isLogin) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(getApp().globalData.sysUserSid) |
|||
}) |
|||
} |
|||
|
|||
return new Promise((resolve, reject) => { |
|||
// 获取信息
|
|||
// 获取用户信息
|
|||
uni.getUserProfile({ |
|||
desc: '获取基本信息', |
|||
success: function(infoRes) { |
|||
|
|||
_this.data.nickName = infoRes.userInfo.nickName; |
|||
_this.data.gender = infoRes.userInfo.gender == 1 ? "男" : "女"; |
|||
_this.data.oauthHeadImg = infoRes.userInfo.avatarUrl; |
|||
_this.data.fromkey = "WeiXin"; |
|||
|
|||
uni.login({ |
|||
provider: 'weixin', |
|||
success: function(loginRes) { |
|||
|
|||
uni.request({ |
|||
url: getApp().globalData.wxAuthLoginURL + |
|||
"?wxCode=" + loginRes |
|||
.code, |
|||
method: "GET", |
|||
header: { |
|||
// 传参方式
|
|||
'content-type': "application/x-www-form-urlencoded" |
|||
}, |
|||
// 具体参数
|
|||
data: { |
|||
"wxCode": loginRes.code |
|||
}, |
|||
}).then((res) => { |
|||
console.log(res) |
|||
|
|||
_this.data.openid = res.data.openid; |
|||
_this.data.unionId = res.data.unionid; |
|||
|
|||
// _this.HTTP({
|
|||
// url: "oauth/afterlogin",
|
|||
// data: {
|
|||
// "openid": _this.data.openid,
|
|||
// "unionId": _this.data.unionId,
|
|||
// "nickName": _this.data.nickName,
|
|||
// "gender": _this.data.gender,
|
|||
// "oauthHeadImg": _this.data
|
|||
// .oauthHeadImg,
|
|||
// "fromkey": _this.data.fromkey
|
|||
// },
|
|||
// loading: true
|
|||
// }).then((res) => {
|
|||
// // 保存
|
|||
// _this.WritePreference("memberSid",
|
|||
// res.data
|
|||
// .memberSid)
|
|||
// getApp().globalData.isLogin = true
|
|||
// getApp().globalData.memberSid = res
|
|||
// .data
|
|||
// .memberSid
|
|||
// // $emit 触发事件 (主要返回给webviwew页面)
|
|||
// uni.$emit('login', res.data
|
|||
// .memberSid)
|
|||
// _this.Back()
|
|||
// }, (err) => {
|
|||
// if (err.data != null) {
|
|||
// err.data.cookie = _this
|
|||
// .ReplaceAll(err.data.cookie,
|
|||
// "=", "-")
|
|||
// uni.redirectTo({
|
|||
// url: "./BdtelephoneActivity?cookie=" +
|
|||
// err.data.cookie
|
|||
// })
|
|||
// }
|
|||
// })
|
|||
|
|||
}, (err) => { |
|||
// 错误提示
|
|||
_this.Toast("出错了:" + err.data.errmsg) |
|||
}) |
|||
|
|||
}, |
|||
fail: function(err) { |
|||
_this.Toast(err) |
|||
} |
|||
}); |
|||
}, |
|||
fail: function(err) { |
|||
// 用户拒绝
|
|||
_this.Toast(err.errMsg) |
|||
} |
|||
}); |
|||
|
|||
}) |
|||
|
|||
} |
|||
|
|||
export default wxAuthLogin |
@ -0,0 +1,94 @@ |
|||
// 静默登录
|
|||
import { |
|||
isEmpty |
|||
} from './TextUtils.js' |
|||
const wxSilentLogin = () => { |
|||
return new Promise((resolve, reject) => { |
|||
wx.login({ |
|||
success: function(res) { |
|||
if (res.code) { |
|||
if (getApp().globalData.isDebug) { |
|||
console.log('Http网络请求信息', { |
|||
"wxCode": res.code |
|||
}) |
|||
} |
|||
uni.request({ |
|||
// 组装请求地址
|
|||
url: getApp().globalData.wxSilentLoginURL + "?wxCode=" + res |
|||
.code, |
|||
// 请求方式 GET POST
|
|||
method: "GET", |
|||
header: { |
|||
// 传参方式
|
|||
'content-type': "application/x-www-form-urlencoded" |
|||
}, |
|||
// 具体参数
|
|||
data: { |
|||
"wxCode": res.code |
|||
}, |
|||
success: res => { |
|||
console.log(res) |
|||
// if (getApp().globalData.isDebug) {
|
|||
// console.log('Http网络路径', getApp().globalData
|
|||
// .wxSilentLoginURL)
|
|||
// }
|
|||
if (res.statusCode == 200) { |
|||
if (!res.data.success) { |
|||
|
|||
if (res.data.code == 500) { |
|||
// 未关注小程序 首次登录 也无账号
|
|||
uni.showToast({ |
|||
title: "您的平台应用未被授权,请联系工作人员。", |
|||
icon: 'none', |
|||
duration: 3000, |
|||
}) |
|||
wx.exitMiniProgram({ |
|||
success: function() {}, |
|||
fail: function() {} |
|||
}) |
|||
return |
|||
} |
|||
|
|||
if (res.data.code == 100) { |
|||
// 有账号 未绑定用户
|
|||
uni.redirectTo({ |
|||
url: '../index/BindPhone?sysUserWxAuthSid=' + |
|||
res.data.data |
|||
}) |
|||
} |
|||
|
|||
} else { |
|||
console.log("Http网络请求res", res) |
|||
console.log("Global-Auth-Token", res.data.data.token) |
|||
uni.setStorageSync("Global-Auth-Token", res.data.data.token) |
|||
getApp().globalData.username = res.data.data.userName |
|||
getApp().globalData.token = res.data.data.token |
|||
getApp().globalData.sid = res.data.data.sid |
|||
getApp().globalData.mobile = res.data.data.mobile |
|||
getApp().globalData.isLogin= true |
|||
} |
|||
} else { |
|||
getApp().globalData.isLogin = false |
|||
} |
|||
}, |
|||
fail: (err) => { |
|||
if (getApp().globalData.isDebug) { |
|||
console.log("Http网络请求fail", err) |
|||
} |
|||
}, |
|||
complete: () => {} |
|||
}); |
|||
} |
|||
}, |
|||
fail: function(res) { |
|||
uni.showToast({ |
|||
title: "静默登录失败:" + res.errMsg, |
|||
icon: 'none' |
|||
}) |
|||
|
|||
reject(res.errMsg) |
|||
} |
|||
}); |
|||
}) |
|||
} |
|||
export default wxSilentLogin |
@ -0,0 +1,132 @@ |
|||
<template> |
|||
<view :style="{'border-radius': '5rpx','height': '65rpx','width': '160rpx','text-align': 'center','line-height': '65rpx','font-size': '26rpx', |
|||
'background-color': background,'color': 'white'}" |
|||
@click="click"> |
|||
{{textDetail}} |
|||
</view> |
|||
</template> |
|||
|
|||
<script> |
|||
export default { |
|||
data() { |
|||
return { |
|||
'background': '#2fa1f0', |
|||
"isCanClick": true, |
|||
"textDetail": "获取验证码", |
|||
"countdown": 60, |
|||
'cookie': '', |
|||
pageData:{ |
|||
phone:"", |
|||
type:"4" |
|||
} |
|||
}; |
|||
}, |
|||
methods: { |
|||
getCookie() { |
|||
return this.cookie; |
|||
}, |
|||
click() { |
|||
|
|||
|
|||
if (!this.isCanClick) { |
|||
return |
|||
} |
|||
|
|||
if (this.phoneNum.length != 11 || !this.phoneNum.startsWith("1")) { |
|||
this.Toast("请输入合法的手机号") |
|||
} else { |
|||
|
|||
// 更改样式并且不可点击 |
|||
this.background = "gray" |
|||
|
|||
this.isCanClick = false |
|||
|
|||
let timeOut = setInterval(() => { |
|||
|
|||
if (this.countdown == 1) { |
|||
this.textDetail = "获取验证码" |
|||
this.countdown = 60 |
|||
clearInterval(timeOut) |
|||
this.background = "#2fa1f0" |
|||
|
|||
this.isCanClick = true |
|||
} else { |
|||
this.countdown = this.countdown - 1; |
|||
this.textDetail = this.countdown + "s" |
|||
} |
|||
}, 1000) |
|||
|
|||
let _this = this |
|||
|
|||
_this.pageData.phone = _this.phoneNum |
|||
|
|||
// if (this.sendByCookie != null) { |
|||
|
|||
// // 此方法会判断是否是小程序,小程序才执行cookie |
|||
// this.HttpCookie({ |
|||
// 'url': this.url, |
|||
// 'data': { |
|||
// "mobile": this.phoneNum |
|||
// }, |
|||
// cookie: this.sendByCookie, |
|||
// loading: true |
|||
// }).then((res) => { |
|||
// _this.cookie = res.data |
|||
// }, (err) => { |
|||
// clearInterval(timeOut) |
|||
// this.countdown = 60 |
|||
// // 失败重置状态 |
|||
// this.background = "#2fa1f0" |
|||
|
|||
// this.isCanClick = true |
|||
// this.textDetail = "获取验证码" |
|||
// }) |
|||
|
|||
// } else { |
|||
|
|||
_this.$api.sendVerificationCode(_this.pageData).then((resp) => { |
|||
// if (resp.success) { |
|||
console.log('1111', resp) |
|||
|
|||
}).catch(e => { |
|||
console.log('eeeee', e) |
|||
clearInterval(timeOut) |
|||
_this.countdown = 60 |
|||
// 失败重置状态 |
|||
_this.background = "#2fa1f0" |
|||
|
|||
_this.isCanClick = true |
|||
_this.textDetail = "获取验证码" |
|||
}) |
|||
|
|||
// _this.HTTP({ |
|||
// url: _this.url+"/"+_this.phoneNum+"/4", |
|||
// data: {}, |
|||
// method: 'GET', |
|||
// paramsType: "FORM", |
|||
// loading: true |
|||
// }).then((res) => { |
|||
// _this.cookie = res.data |
|||
// console.log('=======', res) |
|||
// }, (err) => { |
|||
// clearInterval(timeOut) |
|||
// this.countdown = 60 |
|||
// // 失败重置状态 |
|||
// this.background = "#2fa1f0" |
|||
|
|||
// this.isCanClick = true |
|||
// this.textDetail = "获取验证码" |
|||
// }) |
|||
|
|||
// } |
|||
} |
|||
} |
|||
}, |
|||
props: ['phoneNum', 'url', 'data', 'sendByCookie'], |
|||
|
|||
} |
|||
</script> |
|||
|
|||
<style> |
|||
|
|||
</style> |
@ -0,0 +1,176 @@ |
|||
<template> |
|||
<view> |
|||
|
|||
<view style="margin-top: 30rpx;"> |
|||
<view class="inputRow"> |
|||
<image src="../../static/baseIcon/username.png" mode="aspectFill" class="drawableLeft"></image> |
|||
<input type="number" maxlength="11" @input="phoneText" placeholder="请输入手机号" class="input" /> |
|||
<SendCodeItem :phoneNum="page.mobile" url="/v1/wxuser/sendVerificationCode" @click="send" |
|||
ref="wxCodeItem"></SendCodeItem> |
|||
</view> |
|||
</view> |
|||
|
|||
|
|||
<view class="inputRow"> |
|||
<image src="../../static/baseIcon/code.png" mode="aspectFill" class="drawableLeft"></image> |
|||
<input type="number" @input="codeText" maxlength="6" placeholder="请输入验证码" class="input" /> |
|||
</view> |
|||
|
|||
|
|||
<view class="btn" @click="next"> |
|||
<text class="btnText">绑定手机</text> |
|||
</view> |
|||
|
|||
|
|||
</view> |
|||
</template> |
|||
|
|||
<script> |
|||
export default { |
|||
data() { |
|||
return { |
|||
page: { |
|||
mobile: '', |
|||
openid: '', |
|||
code: '' |
|||
} |
|||
}; |
|||
}, |
|||
onShow() { |
|||
/* #ifdef MP-WEIXIN */ |
|||
wx.hideHomeButton(); |
|||
/* #endif */ |
|||
}, |
|||
onLoad(options) { |
|||
this.page.openid = options.sysUserWxAuthSid |
|||
console.log('=======', options) |
|||
console.log('=======', options.sysUserWxAuthSid) |
|||
}, |
|||
methods: { |
|||
next() { |
|||
var mobileLength = this.page.mobile.length; |
|||
var codeLength = this.page.code.length; |
|||
if (mobileLength == 0) { |
|||
this.Toast("请输入手机号") |
|||
return; |
|||
} |
|||
if (codeLength == 0) { |
|||
this.Toast("验证码不能为空") |
|||
return; |
|||
} |
|||
let _this = this |
|||
console.log('1111', _this.page) |
|||
_this.$api.wxBindMobile(_this.page).then((resp) => { |
|||
// if (resp.success) { |
|||
console.log('1111', resp) |
|||
|
|||
getApp().globalData.username = resp.userName |
|||
getApp().globalData.token = resp.token |
|||
getApp().globalData.sid = resp.sid |
|||
getApp().globalData.mobile = resp.mobile |
|||
getApp().globalData.isLogin = true |
|||
|
|||
// _this.WritePreference("sysUserSid", res.data) |
|||
// _this.WritePreference("isLogin", true) |
|||
// getApp().globalData.isLogin = true |
|||
// getApp().globalData.sysUserSid = res.data |
|||
|
|||
uni.switchTab({ |
|||
url: '/pages/home/WorkFragment' |
|||
}); |
|||
}).catch(e => { |
|||
console.log('eeeee', e) |
|||
}) |
|||
|
|||
|
|||
// this.HTTP({ |
|||
// url: 'aos/v1/aosUser/wxBindMobile', |
|||
// data: { |
|||
// mobile: this.page.phone, |
|||
// sysUserWxAuthSid: this.page.sysUserWxAuthSid, |
|||
// code: this.page.code |
|||
// }, |
|||
// method: 'POST', |
|||
// paramsType: "JSON", |
|||
// loading: true |
|||
// }).then((res) => { |
|||
// console.log('=======', res) |
|||
// if (res.code == 200) { |
|||
// // 保存 |
|||
// _this.WritePreference("sysUserSid", res.data) |
|||
// _this.WritePreference("isLogin", true) |
|||
// getApp().globalData.isLogin = true |
|||
// getApp().globalData.sysUserSid = res.data |
|||
// console.log( |
|||
// '=======1111111111111111111111111111111sdfasdf;kjasdfjkasdklfkasdjf;asdddddddddddddd', |
|||
// res) |
|||
// // $emit 触发事件 (主要返回给webviwew页面) |
|||
// // uni.$emit('login', res.data.memberSid) |
|||
// uni.navigateBack({ |
|||
// delta: 10 |
|||
// }); |
|||
|
|||
// } |
|||
// }); |
|||
|
|||
|
|||
}, |
|||
phoneText(e) { |
|||
//手机号 |
|||
this.page.mobile = e.detail.value; |
|||
}, |
|||
send(e) { //发送验证码 |
|||
console.log(e); |
|||
}, |
|||
codeText(e) { |
|||
//验证码 |
|||
this.page.code = e.detail.value; |
|||
} |
|||
} |
|||
}; |
|||
</script> |
|||
|
|||
<style lang="scss"> |
|||
.inputRow { |
|||
display: flex; |
|||
margin-left: 30rpx; |
|||
margin-right: 30rpx; |
|||
margin-bottom: 10rpx; |
|||
margin-top: 10rpx; |
|||
padding-bottom: 10rpx; |
|||
border-bottom: 0.1px #F1F1F1 solid; |
|||
align-items: center; |
|||
|
|||
.input { |
|||
margin-left: 20rpx; |
|||
height: 70rpx; |
|||
flex: 1; |
|||
font-size: 32rpx; |
|||
} |
|||
|
|||
.drawableLeft { |
|||
width: 40rpx; |
|||
height: 40rpx; |
|||
margin: 20rpx; |
|||
} |
|||
} |
|||
|
|||
.btn { |
|||
display: flex; |
|||
width: 90%; |
|||
height: 80rpx; |
|||
flex-direction: column; |
|||
background-color: #007AFF; |
|||
margin-top: 80rpx; |
|||
margin-left: auto; |
|||
margin-right: auto; |
|||
align-items: center; |
|||
justify-content: center; |
|||
border-radius: 10rpx; |
|||
|
|||
.btnText { |
|||
color: #ffffff; |
|||
font-size: 33rpx; |
|||
} |
|||
} |
|||
</style> |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in new issue