Commit 51535ebb authored by 李俊赕's avatar 李俊赕

opt-login-vue

parent 1d341e43
// 所有模块公共API // 所有模块公共API
// 资料页面接口 import globalUrl from '@/common/base_url.js'
const ucenterApiUrl = globalUrl.ucenterUrl.apiUrl
let commonApiFun = function(vm){ let commonApiFun = function(vm){
// let getWorkertype = async (params = {}) => await vm.$u.get('/addons/cms/wxapp.user/getworkertype', params); let loginWxByUser = async (params = {}) => await vm.$u.get('/wxh-support-rest/rest/ssoinfo/v3/getUsersByCode', params);
// let getTag = async (params = {}) => await vm.$u.get('/api/cmstag/tagListByType', params); let loginWxByPhone = async (params = {}) => await vm.$u.post('/wxh-support-rest/rest/ssoinfo/v3/findByMobile', params,{'content-type': 'application/x-www-form-urlencoded'});
// let getDynamicTag = async (params = {}) => await vm.$u.get('/api/cmstag/tagListByType2', params);
// let selectWorkerType = async (params = {}) => await vm.$u.post('/addons/cms/wxapp.user/worker', params);
const commonApi = { const commonApi = {
// getWorkertype, loginWxByUser,
// getTag, loginWxByPhone
// getDynamicTag,
// selectWorkerType
} }
return commonApi return commonApi
} }
......
...@@ -57,7 +57,7 @@ ucenterUrl = { ...@@ -57,7 +57,7 @@ ucenterUrl = {
} }
systemUrl = { systemUrl = {
// apiUrl:'https://192.168.1.22' // apiUrl:'https://192.168.1.22'
apiUrl:'https://192.168.0.208' //郭小青电脑 apiUrl:'http://192.168.0.208:8192' //郭小青电脑
} }
/* --------------------------- test end --------------------------- */ /* --------------------------- test end --------------------------- */
......
...@@ -44,7 +44,9 @@ let noLoginUrl = [ ...@@ -44,7 +44,9 @@ let noLoginUrl = [
'/v1/h5/settled/get-settled-info', '/v1/h5/settled/get-settled-info',
'/v1/h5/settled/area', '/v1/h5/settled/area',
'/v1/h5/settled/save-info', '/v1/h5/settled/save-info',
'/v1/h5/settled/card-front' '/v1/h5/settled/card-front',
'/wxh-support-rest/rest/ssoinfo/v3/getUsersByCode',
'/wxh-support-rest/rest/ssoinfo/v3/findByMobile'
]; ];
//设置session_id //设置session_id
const getSessionId = function(vm) { const getSessionId = function(vm) {
...@@ -77,7 +79,7 @@ const install = (Vue, vm) => { ...@@ -77,7 +79,7 @@ const install = (Vue, vm) => {
let token = util.getToken() let token = util.getToken()
console.log(token,'token') console.log(token,'token')
// let token = 'RTOKENe56f873b5823477fa2e15572f8fa7eb3a5fb6f7b' // let token = 'RTOKENe56f873b5823477fa2e15572f8fa7eb3a5fb6f7b'
if(!token){ if(!token && noLoginUrl.indexOf(config.url)<0){
vm.$u.route('/pages/login/wxlogin'); vm.$u.route('/pages/login/wxlogin');
} }
// // const token = app && app.globalData && app.globalData.token || '' // // const token = app && app.globalData && app.globalData.token || ''
......
<template>
<view class="">
<view class="backView">
<view class="noticeView">
<image class="noticeImage" :src="icon_auth_notice_new" mode=""></image>
</view>
<button class="loginBtn" v-if="!isNewUser" open-type="getUserInfo" lang="zh_CN" @getuserinfo="getUserInfo">
<text class="u-font-32 white">立即登录</text>
</button>
<button class="loginBtn" v-if="isNewUser" open-type="getPhoneNumber" throttle-time="1000" @getphonenumber="getPhoneNumber">
<text class="u-font-32 white">授权登录</text>
</button>
<view class="cancelView">
<text class="cancelText" @click="cancelClick()">取消</text>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
domain_name:'http://192.168.0.208:8192',
isNewUser:false,
unionID:'',
openID:'',
icon_notice:'',
TimeID:-1,
icon_auth_notice_new:''
}
},
onLoad() {
getApp().trackPage('授权登录页')
this.icon_notice = getApp().globalData.icon_auth_notice
this.icon_auth_notice_new = getApp().globalData.icon_auth_notice_new
//this.domain_name = getApp().globalData.domain_Name
//console.log('当前域名:'+this.domain_name)
},
methods: {
//用户授权得到用户的信息
getUserInfo: async function(e) {
clearTimeout(this.TimeID);
this.TimeID = setTimeout(() => {
//console.log('获取用户信息')
//console.log(e.detail.userInfo)
if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
});
} else {
this.getCode()
}
}, 1000);
},
//小程序获取code
getCode: async function() {
let that = this
uni.showLoading({
title:'加载中'
})
return new Promise((resolve, reject) => {
uni.login({
// #ifdef MP-ALIPAY
scopes: 'auth_user',
// #endif
success: function(res) {
console.log('getCode成功')
console.log(res)
if (res.code) {
that.getUsersByCode(res.code)
//that.getUnionID(res.code)
//resolve(res.code);
} else {
//login成功,但是没有取到code
reject('未取得code');
}
},
fail: function(res) {
reject('用户授权失败wx.login');
},
complete() {
uni.hideLoading()
}
});
});
},
//通过code获取用户信息(新接口)
getUsersByCode: async function(code) {
//console.log('通过code获取用户信息 请求接口:')
//console.log(getApp().globalData.domain_Name
//+getApp().globalData.getUsersByCode)
uni.showLoading({
title:'加载中'
})
//getApp().globalData.domain_Name
// 'http://192.168.0.208:8192'
uni.request({
url: getApp().globalData.domain_Name
+getApp().globalData.getUsersByCode,
method: 'GET',
data: {
code: code,
},
success: (res) => {
//console.log('通过code获取用户信息(新接口) 成功')
//console.log(res)
if(res.data.code==200){
this.unionID = res.data.data.user.unionid
this.openID = res.data.data.user.wxopenid
if(res.data.data.token){
uni.showToast({
icon:'none',
title:'登陆成功'
})
this.saveUserInfo(res)
}else{
uni.showToast({
icon:'none',
title:'新用户请授权登录'
})
this.isNewUser = true
}
}else{
uni.showToast({
icon:'none',
title:res.data.message
})
}
},
fail: (e) => {
//console.log('通过code获取用户信息(新接口) 失败')
//console.log(e)
},
complete() {
uni.hideLoading()
}
})
},
//用户信息存本地
saveUserInfo: async function(res) {
//console.log('用户信息存本地 token:' +res.data.data.token);
// this.$u.vuex('vuex_token', res.data.data.token)
uni.setStorage({
key: 'token',
data: res.data.data.token,
success: function (e) {
//console.log('保存token 成功'+e);
}
});
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2]; //上一个页面
if(prevPage.route=='pages/index/index'){
prevPage.$vm.isRefresh = true;
}
uni.navigateBack({
})
},
//获取用户手机号
getPhoneNumber: async function(e) {
clearTimeout(this.TimeID);
this.TimeID = setTimeout(() => {
//console.log('获取用户手机号')
//console.log(e.detail)
if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
//this.$u.toast('未授权');
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
});
} else {
this.findByMobile(e)
}
}, 1000);
},
//通过手机号获取用户信息
findByMobile: async function(e) {
uni.showLoading({
title:'加载中'
})
uni.request({
url: getApp().globalData.domain_Name
+getApp().globalData.findByMobile,
method: 'POST',
data: {
wxopenid: this.openID,
unionid:this.unionID,
encryptedData:e.detail.encryptedData,
iv:e.detail.iv
},
header:{
'Content-Type': 'application/x-www-form-urlencoded'
},
success: (res) => {
//console.log('通过手机号获取用户信息 成功')
//console.log(res)
if(res.data.code==200){
uni.showToast({
icon:'none',
title:'登录成功'
})
this.saveUserInfo(res)
}else{
uni.showToast({
icon:'none',
title:res.data.message
})
}
},
fail: (e) => {
//console.log('通过code获取用户信息(新接口) 失败')
//console.log(e)
},
complete() {
uni.hideLoading()
}
})
},
//取消点击
cancelClick: function() {
uni.navigateBack({
})
},
/*
//微信授权
toLogin: async function(data) {
uni.showLoading({
title:'授权中……'
})
let res = await this.$u.api.gowxLogin(data);
console.log('微信授权')
console.log(res)
uni.hideLoading()
if (res.code!==1) {
this.$u.toast(res.msg);
return;
}
if (res.data) {
//this.setLoginStatus()
// this.success(res.data.user.id);
}
},
//获取unionID
getUnionID: async function(code) {
uni.request({
url: getApp().globalData.domain_Name
+'/wxh-support-rest/rest/ssoinfo/getUsersByCode',
method: 'GET',
data: {
code: code,
},
success: (res) => {
console.log('获取unionID 成功')
console.log(res)
if(res.data.code==200){
this.getSSOID(res.data.data.unionid)
}
},
fail: (e) => {
console.log('获取unionID 失败')
console.log(e)
}
})
},
//获取SSOID
getSSOID: async function(unionID) {
uni.request({
url: getApp().globalData.domain_Name
+ '/wxh-support-rest/rest/ssoinfo/v2/findByUnionId',
method: 'GET',
data: {
unionid: unionID,
},
success: (res) => {
console.log('获取SSOID 成功')
console.log(res)
},
fail: (e) => {
console.log('获取SSOID 失败')
console.log(e)
}
})
},
//获取loginCode
getLoginCode: async function() {
uni.request({
url: getApp().globalData.domain_Name
+ '/wxh-support-rest/rest/ssoinfo/v2/getLoginCode',
method: 'GET',
data: {
ssoId: '93140',
},
success: (res) => {
console.log('获取loginCode 成功')
console.log(res)
if(res.data.code==200){
this.getToken(res.data.data.loginCode)
}
},
fail: (e) => {
console.log('获取loginCode 失败')
console.log(e)
}
})
},
//获取token
getToken: async function(loginCode) {
uni.request({
url: getApp().globalData.domain_Name
+ '/wxh-support-rest/rest/worker/login/applets/'
+loginCode,
method: 'GET',
data: {
},
success: (res) => {
console.log('获取token 成功')
console.log(res)
},
fail: (e) => {
console.log('获取token 失败')
console.log(e)
}
})
},
*/
}
}
</script>
<style>
.backView{
background-color: #FFFFFF;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
.noticeView{
background-color: #FFFFFF;
width: 100%;
height: 470rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.noticeImage{
background-color: #FFFFFF;
width: 386rpx;
height: 270rpx;
margin-top: 180rpx;
}
.loginBtn{
background-color: #2272FF;
width: 390rpx;
height: 80rpx;
border-radius: 40rpx;
margin-top: 334rpx;
display: flex;
align-items: center;
justify-content: center;
}
.cancelView{
width: 100%;
margin-top: 30rpx;
display: flex;
align-items: center;
justify-content: center;
}
.cancelText{
color: #666666;
font-size: 32rpx;
}
.white{
color: #FFFFFF;
}
</style>
This diff is collapsed.
<template>
<view class="">
<!-- 顶部导航 -->
<fa-navbar :title="barTitle"></fa-navbar>
<view class="content">
<view class="u-p-t-30 u-flex-col u-col-center">
<image class="logo" :src="$util.getStaticUrl('login_logo.png')" mode="aspectFit" />
<text class="title">蓝领星球</text>
</view>
<view class="btn-box">
<template v-if="needAuth">
<view class="auth-tip">我们需要取得您的授权,以关联您的蓝领星球账号</view>
<view class="u-flex u-row-between">
<button class="login-refuse btn" @click="handleRefuse">拒绝</button>
<!-- #ifdef MP-WEIXIN -->
<button class="login-accept btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="getUserInfo">接受</button>
<!-- #endif -->
<!-- #ifdef MP-ALIPAY -->
<button class="login-accept btn" @click="getALICode">授权登录</button>
<!-- <u-button shape="circle" @click="getALICode">授权登录</u-button> -->
<!-- #endif -->
</view>
</template>
<template v-else>
<view class="auth-tip">授权成功,立即登录</view>
<!-- #ifdef MP-WEIXIN -->
<button class="login-now btn" open-type="getPhoneNumber" throttle-time="1000" @getphonenumber="getPhoneNumber">立即登录</button>
<!-- #endif -->
</template>
</view>
<view class="tips-list u-m-t-80">
<view class="tips-item u-flex" v-for="(item,index) in tipsList" :key="index">
<image class="icon" :src="item.img" />
<view>
<view class="title">{{item.title}}</view>
<view class="txt">{{item.intro}}</view>
</view>
</view>
</view>
<u-top-tips ref="uTips" :navbar-height="statusBarHeight + navbarHeight"></u-top-tips>
</view>
<!-- 底部导航 -->
<fa-tabbar></fa-tabbar>
</view>
</template>
<script>
import {
login
} from '@/common/fa.mixin.js';
export default {
mixins: [login],
data() {
return {
// 状态栏高度,H5中,此值为0,因为H5不可操作状态栏
statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
// 导航栏内容区域高度,不包括状态栏高度在内
navbarHeight: 44,
needAuth: true,
barTitle: '微信授权',
tipsList: [{
img: this.$util.getStaticUrl('icon/login_search.png'),
title: '搜答案',
intro: '利用AI检索技术,精准解决您的技术难题'
},{
img: this.$util.getStaticUrl('icon/login_datum.png'),
title: '查资料',
intro: '海量厂家资料、操作手册、技术资料,免费供阅'
},{
img: this.$util.getStaticUrl('icon/login_ask.png'),
title: '问专家',
intro: '提供社群互动,专家1v1 服务,为您排忧解难'
}
]
};
},
onLoad() {
this.setLoginStatus()
},
methods: {
handleRefuse() {
//this.$u.toast('未授权');
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
});
setTimeout(() => {
this.$Router.back(1)
}, 1000);
},
getCode: async function() {
return new Promise((resolve, reject) => {
uni.login({
// #ifdef MP-ALIPAY
scopes: 'auth_user',
// #endif
success: function(res) {
if (res.code) {
resolve(res.code);
} else {
//login成功,但是没有取到code
reject('未取得code');
}
},
fail: function(res) {
reject('用户授权失败wx.login');
}
});
});
},
//用户授权得到用户的信息
getUserInfo: async function(e) {
this.$u.vuex('vuex_other_user', e.detail.userInfo)
if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
//this.$u.toast('未授权');
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
});
} else {
try {
let code = await this.getCode();
let rawData = e.detail
let data = {
code: code,
nickname: rawData.userInfo.nickName,
avatar: rawData.userInfo.avatarUrl,
encryptedData: rawData.encryptedData,
iv: rawData.iv
}
//有推荐码的话,带上
// if (this.vuex_invitecode) {
// data.invitecode = this.vuex_invitecode;
// }
this.toLogin(data);
} catch (e) {
this.$u.toast(e);
}
}
},
//微信授权
toLogin: async function(data) {
uni.showLoading({
title:'授权中……'
})
let res = await this.$u.api.gowxLogin(data);
uni.hideLoading()
if (res.code!==1) {
this.$u.toast(res.msg);
return;
}
if (res.data) {
let app = getApp();
app.identify(this.vuex_other_user, res.data.openid, res.data.unionid);
// app.identify(res.data);
this.$u.vuex('vuex_third', res.data);
this.$u.vuex('vuex_wx_uid', res.data.user_id + 'uid');
this.setLoginStatus()
// this.success(res.data.user.id);
}
},
// 绑定手机号
towxBindPhone: async function(data) {
uni.showLoading({
title:'登录中……'
})
let res = await this.$u.api.gowxBindPhone(data);
uni.hideLoading()
if (!res.code) {
this.$u.toast(res.msg);
return;
}
if (res.data) {
let app = getApp();
this.$u.vuex('vuex_token', res.data.userInfo.token);
if (!this.vuex_worktypeId) {
this.$u.vuex('vuex_worktype_visible', true);
}
let user = {
mobile: res.data.userInfo.mobile,
uid: res.data.userInfo.user_id
}
app.setUserId(res.data.userInfo.wxhuid)
app.setUser(user)
this.$Router.back(1)
return;
}
},
clickOneTime: function(e) {
let func = function() {
this.getPhoneNumber(e)
}
this.$u.debounce(func, 500)
},
getPhoneNumber: async function(e) {
/*
let func = function(){
this.toNext(e)
}
this.$u.debounce(func, 500)
*/
if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
//this.$u.toast('未授权');
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
});
} else {
try {
let code = await this.getCode();
let rawData = e.detail
let data = {
code: code,
encryptedData: rawData.encryptedData,
iv: rawData.iv,
}
//有推荐码的话,带上
// if (this.vuex_invitecode) {
// data.invitecode = this.vuex_invitecode;
// }
this.towxBindPhone(data);
} catch (e) {
this.$u.toast(e);
}
}
},
setLoginStatus() {
// console.log(this.vuex_wx_uid,'this.vuex_wx_uid')
if (this.vuex_wx_uid) {
this.needAuth = false
this.barTitle = '授权登录'
}
},
// #ifdef MP-ALIPAY
getALICode() {
let that = this;
uni.login({
scopes: 'auth_user',
success: res => {
if (res.authCode) {
uni.getUserInfo({
provider: 'alipay',
success: function(infoRes) {
if (infoRes.errMsg == 'getUserInfo:ok') {
let user_info = {
nickname: infoRes.nickName,
avatar: infoRes.avatar
};
that.aLiLoginStep1(res.authCode, user_info);
}
},
fail: function(errorRes) {
this.$u.toast('未取得用户昵称头像信息');
}
});
} else {
this.$u.toast('未取得code');
}
},
fail: function(res) {
this.$u.toast('用户授权失败my.login');
}
});
},
aLiLoginStep1: async function(code, user_info) {
let data = {
code: code,
user_info: user_info
};
let res = await this.$u.api.alilogin1(data);
if (!res.code) {
this.$u.toast(res.msg);
return;
}
}
// #endif
}
};
</script>
<style lang="scss">
page {
background-color: #FFFFFF;
}
.btn {
margin: 0;
padding: 0;
width: 318rpx;
height: 86rpx;
line-height: 86rpx;
border-radius: 49rpx;
color: #ffffff;
font-weight: bold;
}
.btn::before,
.btn::after {
border: none;
}
.logo {
margin-bottom: 15rpx;
width: 208rpx;
height: 152rpx;
}
.title {
font-size: 40rpx;
font-weight: bold;
color: #333333;
line-height: 1;
}
.auth-tip {
margin-top: 80rpx;
margin-bottom: 40rpx;
text-align: center;
font-size: 28rpx;
color: #888888;
line-height: 1;
}
.btn-box {
padding: 0 40rpx;
margin-bottom: 80rpx;
}
.btn.login-refuse {
color: #333333;
background: #EDEDED;
}
.btn.login-accept {
background: #07C160;
box-shadow: 6rpx 6rpx 40rpx rgba(7, 193, 96, 0.5);
}
.btn.login-now {
width: 670rpx;
// height: 98rpx;
background: #07C160;
border-radius: 49rpx;
color: #ffffff;
font-weight: bold;
box-shadow: 6rpx 6rpx 40rpx rgba(7, 193, 96, 0.5);
}
.tips-list {
padding: 28rpx 40rpx;
.tips-item {
margin-bottom: 55rpx;
.icon {
margin-right: 36rpx;
width: 60rpx;
height: 60rpx;
}
.title {
margin-bottom: 21rpx;
font-size: 28rpx;
color: #333333;
}
.txt {
font-size: 24rpx;
color: #888888;
}
}
}
</style>
...@@ -96,8 +96,18 @@ ...@@ -96,8 +96,18 @@
}, },
components: { components: {
},
watch:{
isRefresh(val){
if(val){
this.initPage()
}
}
}, },
methods: { methods: {
refreshPage(){
this.getBaseInfo()
},
checkBaseInfo() { checkBaseInfo() {
const baseInfo = this.baseInfo; const baseInfo = this.baseInfo;
let rulesObj = { let rulesObj = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment