Commit 599ff6e1 authored by lijiongliang's avatar lijiongliang

新增京东登录

parent 77869420
......@@ -68,7 +68,13 @@
"scope.userLocation" : {
"desc" : "你的位置信息将用于定位"
}
}
},
"plugins": {
"loginPlugin": {
"version": "1.5.4",
"provider": "wxefe655223916819e"
}
}
},
"mp-alipay" : {
"usingComponents" : true
......
......@@ -38,6 +38,20 @@
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/login/index/index",
"style": {
"navigationBarTitleText": "登录"
}
},
{
"path": "pages/login/web-view/web-view",
"style": {}
},
{
"path": "pages/login/wv-common/wv-common",
"style": {}
}
],
"subPackages": [
......@@ -236,6 +250,12 @@
]
}
],
"plugins": {
"loginPlugin": {
"version": "1.5.4",
"provider": "wxefe655223916819e"
}
},
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "首页",
......@@ -243,7 +263,11 @@
"backgroundColor": "#ffffff",
"rpxCalcMaxDeviceWidth": 750, // rpx 计算所支持的最大设备宽度,单位 px,默认值为 960
"rpxCalcBaseDeviceWidth": 375, // rpx 计算使用的基准设备宽度,设备实际宽度超出 rpx 计算所支持的最大设备宽度时将按基准宽度计算,单位 px,默认值为 375
"rpxCalcIncludeWidth": 750 // rpx 计算特殊处理的值,始终按实际的设备宽度计算,单位 rpx,默认值为 750
"rpxCalcIncludeWidth": 750 ,// rpx 计算特殊处理的值,始终按实际的设备宽度计算,单位 rpx,默认值为 750
"usingComponents": {
"index": "plugin://loginPlugin/index",
"instruction":"plugin://loginPlugin/instruction"
}
}
// "tabBar": {
// "color": "#595656",
......
export let config = {
appid: 1814,
returnPage: undefined,
pageType: undefined,
isLogout: 1,
noWXinfo: 1,
h5path: undefined,
logoPath: undefined,
isTest: undefined,
//1 预发接口,改为undefined 调用线上接口
isKepler: undefined,
navigationBarColor: undefined,
navigationBarTitle: undefined,
tabNum: 2,
requestHost: 'https://wxapplogin2.m.jd.com',
logPluginName: 'DDDDDDDDD',
// 埋点插件的名字 例如:'log-plugin'
selfTipsDialog: false,
// 是否弹窗展示协议授权,默认为false,如果为true,author必须为false
author: true,
hiddenLoginType: '2',
//隐藏按钮 1为 帐密方式;2为微信手机号快捷登录
loginConfig: {
jdLoginBtnStyle: 'color:red',
// 登录/注册按钮样式
wxBtnStyle: 'color:red',
// 微信快捷登录按钮样式
userPlaceholder: '',
// 帐密登录的 placeholder
loginBtnStyle: 'color:red',
// 帐密登录界面登录按钮样式
tabStyle: 'color:green',
//帐密和手机号登录tab样式
currentTabStyle: 'border-color:green' //帐密和手机号登录tab选中
} // selfTips: [{ //无特殊需求不需要配置
// tip:'我是测试1',
// url: 'm.jd.com'
// }, {
// tip:'我是测试2',
// url:'https://pro.m.jd.com/mall/active/2hqsQcyM5bEUVSStkN3BwrBHqVLd/index.html'
// }]
};
This diff is collapsed.
<template>
<block>
<index @smsloginres="smsloginResListener" :config="config" :checkboxChecked="checkboxChecked" />
<view v-if="config.hiddenLoginType != 2">
<button
v-if="!stopClick && checkboxChecked"
class="phone-btn"
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
:style="config.loginConfig && config.loginConfig.wxBtnStyle"
>
微信手机号快捷登录
</button>
<!-- 防止连续点击触发获取微信用户信息 -->
<button class="phone-btn" :style="config.loginConfig && config.loginConfig.wxBtnStyle" v-else @tap="needAuthor">微信手机号快捷登录</button>
</view>
<!-- 弹窗类型展示协议授权 -->
<view class="dialog-tips" v-if="config.selfTipsDialog">
<view>
<instruction class="no-fix" :config="config" @changecheck="changeCheckbox" />
<p>
<button class="phone-btn bg-btn" @tap="reject">拒绝</button>
<button v-if="!stopClick && checkboxChecked" class="phone-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">同意</button>
</p>
</view>
</view>
<!-- 底部展示协议授权 -->
<instruction v-else :config="config" @changecheck="changeCheckbox" />
<view>
<canvas class="f8be360ead1f4a3d9afb5e312b845ebb" canvas-id="fbfd3ec3c4ab4213b9a09b5c5e769ceb"></canvas>
</view>
</block>
</template>
<script>
import util from '../util.js';
let plugin = requirePlugin('loginPlugin');
let fm = require('../fm.min.js');
let config = util.getLoginConfig();
export default {
components: {},
data() {
return {
config,
stopClick: false,
checkboxChecked: !config.author,
detail: '',
code: '',
wxBtnStyle: ''
};
},
onLoad(options) {
let { riskFail } = options;
this.config = util.getLoginConfig(options) //风控失败不重置缓存
if (!riskFail) {
util.setLoginParamsStorage(options);
}
plugin.setLog({
url: 'pages/login/index/index',
pageId: 'WLogin_Diversion'
});
util.setCustomNavigation();
this.getWxcode();
this.setFingerData();
},
onShow() {
plugin.pvLog();
},
methods: {
smsloginResListener(res = {}) {
if (this.checkboxChecked) {
util.handleJump(res.detail);
} else {
this.showLoad();
}
},
showLoad() {
uni.showToast({
title: '请阅读并勾选页面底部协议',
icon: 'none',
duration: 3000
});
},
changeCheckbox(e) {
this.checkboxChecked = e.detail
},
needAuthor() {
if (!this.checkboxChecked) {
this.showLoad();
}
},
getPhoneNumber(event = {}) {
let { stopClick } = this;
if (stopClick) {
uni.showToast({
icon: 'none',
title: '请不要重复点击'
});
return;
}
this.stopClick = true
let { detail } = event;
let { iv, encryptedData } = detail;
plugin.clickLog({
event,
eid: 'WLogin_Diversion_Wechat'
});
if (!iv || !encryptedData) {
this.stopClick = false
return;
}
uni.showLoading({
title: '加载中'
});
this.detail = detail
this.mobileLogin();
plugin.clickLog({
event,
eid: 'WLogin_DiversionWechat_Allow'
});
},
mobileLogin() {
let { code, detail } = this;
let { iv, encryptedData } = detail;
if (!code || !iv || !encryptedData) {
return;
}
const startClick = () => {
uni.hideLoading();
this.stopClick = false
};
plugin
.WXMobileLogin({
iv,
encryptedData,
code
})
.then((res) => {
if ([32, 33].indexOf(res.err_code) >= 0) {
return plugin.loginRequest({});
}
if (res.err_code == 124) {
return this.getWxcode();
} // 风控提示用户去浏览器解除 重新获取code
return res;
})
.then((res) => {
let { pt_key, rsa_modulus, guid } = res;
if (!pt_key && rsa_modulus && guid) {
// login 返回
res.pluginUrl = plugin.formatPluginPage('main');
} // startClick()
util.handleJump(res);
})
.catch((res) => {
startClick();
console.jdLoginLog(res);
});
},
getWxcode() {
uni.login({
success: (res = {}) => {
this.code = res.code
}
});
},
setFingerData() {
fm.config(this, {
bizKey: plugin.bizKey
});
fm.init();
fm.getEid((res = {}) => {
plugin.setJdStorageSync('finger_tk', res.tk);
});
},
// 拒绝协议
reject() {
let { rejectReturnPage, rejectPageType } = this.config;
if (rejectReturnPage) {
uni[`${rejectPageType}` || 'rejectTo']({
url: rejectReturnPage
});
} else {
uni.navigateBack();
}
}
}
};
</script>
<style>
/* pages/login/login.wxss */
.phone-btn {
margin: 40rpx auto 152rpx auto;
width: 658rpx;
height: 92rpx;
line-height: 92rpx;
border-radius: 100rpx;
background-color: #1aad19;
color: #fff;
font-size: 32rpx;
}
.phone-btn::after {
border: none;
}
.f8be360ead1f4a3d9afb5e312b845ebb {
position: absolute;
width: 100%;
height: 100%;
border: solid 1px #cdcdcd;
opacity: 0;
left: -100%;
top: -100%;
z-index: -2147483648;
}
/* 协议弹窗样式 */
.dialog-tips {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
}
.dialog-tips > view {
position: absolute;
border-radius: 16rpx;
width: 80%;
padding: 60rpx 40rpx;
background-color: #fff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.dialog-tips view button {
display: inline-block;
width: 45%;
margin: 0;
}
.dialog-tips view button.phone-btn {
margin-left: 10%;
}
.dialog-tips view button.bg-btn {
background: rgba(242, 242, 242, 1);
border-radius: 50rpx;
color: rgba(136, 136, 136, 1);
margin: 0;
}
.dialog-tips .no-fix > view {
position: static;
margin-bottom: 20rpx;
text-align: left;
}
.dialog-tips .no-fix > view > view {
font-size: 28rpx;
line-height: 50rpx;
color: #1269e2;
}
.dialog-tips .no-fix > view > view:first-child {
color: #000;
}
.dialog-tips .no-fix > view > text:last-child {
display: block;
}
</style>
let plugin = requirePlugin('loginPlugin');
(function () {
if (console.jdLoginLog) return;
let normalLog = console.log;
console.jdLoginLog = (...args) => {
args.unshift('-------登录插件-------');
normalLog && normalLog(...args);
};
})();
const utils = {
redirectPage(url) {
uni.redirectTo({
url
});
},
redirectToH5({ page, wvroute }) {
let url = plugin.formH5Url({
page: decodeURIComponent(page),
wvroute
});
utils.redirectPage(url);
},
navigateToH5({ page, wvroute }) {
let url = plugin.formH5Url({
page: decodeURIComponent(page),
wvroute
});
uni.navigateTo({
url
});
},
setLoginParamsStorage(obj = {}) {
plugin.setLoginStorageSync(utils.getLoginConfig(obj));
},
/*
首页存缓存逻辑(兼容不适用loginConfig直接存缓存):
同名参数优先级:url 中参数 > loginConfig > 缓存中
*/
getLoginConfig(obj = {}) {
//兼容缓存中有returnPage, 传递的参数中无,塞缓存时会用缓存中的值,导致不匹配
const handleUndefinedType = (o = {}) => {
let { pageType = 'redirectTo' } = o;
o.pageType = pageType;
return o;
};
let storageConfig = plugin.getLoginParams();
let config = handleUndefinedType(utils.getDefaultConfig());
let loginParams = { ...storageConfig, ...config };
if (plugin.isObject(obj)) {
loginParams = { ...loginParams, ...handleUndefinedType(obj) };
} else {
console.jdLoginLog('登录参数必须为对象');
}
return loginParams;
},
getDefaultConfig() {
let lgConfig;
try {
lgConfig = require('./config.js');
} catch (err) {
lgConfig = {};
}
return lgConfig.config || {};
},
handleJump(p = {}) {
let { goback, pluginUrl, riskUrl } = p;
if (goback) {
utils.goBack();
return;
}
if (pluginUrl) {
utils.redirectPage(pluginUrl);
return;
}
riskUrl &&
utils.redirectToH5({
page: riskUrl
});
},
goBack() {
let params = plugin.getLoginParams(),
{ returnPage, pageType } = params;
if (pageType == 'navigateBack') {
uni[pageType]();
return;
}
if (!returnPage) {
uni.showToast({
title: '没有returnPage,无法跳转',
icon: 'none'
});
return;
}
if (pageType !== 'h5') {
returnPage = decodeURIComponent(returnPage);
if (pageType && pageType != 'rediretTo') {
uni[pageType]({
url: returnPage
});
} else {
utils.redirectPage(returnPage);
}
return;
} else {
utils.redirectToH5({
page: returnPage
});
return;
}
},
h5Init(options) {
let p = plugin.getLoginParams();
if (plugin.isEmptyObj(p)) utils.setLoginParamsStorage(options);
},
setCustomNavigation() {
let { navigationBarColor, navigationBarTitle } = plugin.getLoginParams();
plugin.isObject(navigationBarColor) && uni.setNavigationBarColor(navigationBarColor);
plugin.isObject(navigationBarTitle) && uni.setNavigationBarTitle(navigationBarTitle);
},
requestWithLoginStatus(obj = {}) {
obj.header = obj.header || {};
let [GUID = '', KEY = '', TOKEN = '', PIN = ''] = plugin.getJdListStorage(['guid', 'pt_key', 'pt_token', 'pt_pin']),
_cookie = `guid=${GUID}; pt_pin=${encodeURIComponent(PIN)}; pt_key=${KEY}; pt_token=${TOKEN}`,
{ cookie } = obj.header;
obj.header.cookie = cookie ? `${cookie};${_cookie}` : _cookie;
uni.request(obj);
},
silentauthlogin(options, goToLogin, callback) {
uni.login({
success(res = {}) {
let { code } = res;
if (code) {
utils.setLoginParamsStorage(options);
plugin
.silentauthlogin({ ...options, code }, goToLogin)
.then((res) => {
callback &&
callback({
isSuccess: res.err_code == 0
});
if (goToLogin && res.err_code == 0) {
utils.handleJump(res);
}
})
.catch((res) => {
callback &&
callback({
isSuccess: false
});
console.jdLoginLog('请重试一次');
});
} else {
callback &&
callback({
isSuccess: false
});
console.jdLoginLog('wx.login 获取code失败');
}
},
fail() {
callback &&
callback({
isSuccess: false
});
}
});
}
};
export default utils;
<template>
<block>
<web-view />
</block>
</template>
<script>
import util from '../util.js';
let plugin = requirePlugin('loginPlugin');
export default {
data() {
return {};
},
onLoad(options = {}) {
// wx.showModal({
// title: '提示',
// content: 'JIN',
// success: res => {
// }
// })
util.setCustomNavigation();
let { token, islogin } = options;
if (Number(islogin) === 0) {
// wx.showModal({
// title: '提示',
// content: JSON.stringify(options),
// success: res => {
// if (res.confirm) {
// util.redirectPage('/pages/login/index/index?riskFail=1')
// }
// }
// })
util.redirectPage('/pages/login/index/index?riskFail=1');
return;
}
this.handleBackFromH5(token);
},
methods: {
handleBackFromH5(token) {
plugin
.tokenLogin({
token
})
.then((res = {}) => {
let { goback, err_msg } = res;
if (goback) {
plugin.gobackLog({
route: 7
});
util.goBack();
return;
}
if (err_msg) {
uni.showModal({
title: '提示',
content: err_msg,
success: (res) => {
if (res.confirm) {
this.handleBackFromH5(token);
}
}
});
}
})
.catch((res) => console.jdLoginLog(res));
}
}
};
</script>
<style></style>
<template>
<block>
<web-view :src="url" />
</block>
</template>
<script>
import util from '../util.js';
let plugin = requirePlugin('loginPlugin');
export default {
data() {
return {
h5_url: '',
url: ''
};
},
onLoad: function (options = {}) {
let { h5_url = '' } = options;
util.h5Init(options);
this.setData({
h5_url
});
util.setCustomNavigation();
this._genToken();
},
onShareAppMessage: function () {
let { h5_url } = this;
return {
title: '京东',
path: `/pages/login/wv-common/wv-common?h5_url=${h5_url}`
};
},
methods: {
_genToken() {
let { h5_url } = this;
plugin
.genToken({
h5_url
})
.then((res) => {
let { isSuccess, err_code, url, tokenkey, err_msg } = res;
if (isSuccess && !err_code) {
this.setData({
url: `${url}?to=${h5_url}&tokenkey=${tokenkey}`
});
} else {
uni.showModal({
title: '提示',
content: err_msg || '页面跳转失败,请重试',
success: (res) => {
if (res.confirm) {
this._genToken();
}
}
});
}
})
.catch((res) => console.jdLoginLog(res));
}
}
};
</script>
<style>
/* pages/login/wv-common/wv-common.wxss */
</style>
......@@ -20,6 +20,7 @@ import index from './home'
import moveCar from './moveCar'
import shop from './shop'
import personal from './personal'
let plugin = requirePlugin('loginPlugin');
export default {
components: {
......@@ -43,6 +44,7 @@ export default {
})
},
onShow: function () {
console.log(plugin.getPtKey(),1111111)
uni.hideHomeButton()
if(this.tab == 'personal'){
this.$refs.personal.getUserInfo();
......@@ -57,11 +59,18 @@ export default {
}
},
methods: {
goLogin(){
let returnPage= '/pages/main';
uni.navigateTo({
url:"/pages/login/index/index?returnPage="+returnPage
})
},
tabChange(index) {
let that = this
switch (index) {
case 0:
this.tab = 'index'
this.goLogin()
break;
case 1:
this.tab = 'moveCar'
......@@ -154,7 +163,7 @@ export default {
this.$refs.myTab.current = i;
});
}
},
}
</script>
......
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