【新增】实现支付宝小程序适配。

This commit is contained in:
jianweie
2024-04-22 23:04:58 +08:00
parent 8a4fe681cb
commit a6ad9274e1
53 changed files with 13032 additions and 107 deletions

View File

@@ -428,7 +428,10 @@ const install = (Vue, vm) => {
let submitInvoiceApply = (params, config = {}) => http.post('/Api/Order/SubmitInvoiceApply', params, { custom: { methodName: 'order.submitInvoiceApply', needToken: true } });
//支付宝解析code
let getAliPayAppAuthTokenBYCode = (params, config = {}) => http.post('/Api/AliPayAuth/getAliPayAppAuthTokenBYCode', params, { custom: { methodName: 'user.GetAliPayAppAuthTokenByCode', needToken: false } });
//支付宝小程序手机授权(拉取手机号码)
let loginByGetPhoneNumberForAli = (params, config = {}) => http.post('/Api/User/DecryptPhoneNumberByAli', params, { custom: { methodName: 'user.loginByGetPhoneNumberForAli', needToken: false } });
// 将各个定义的接口名称统一放进对象挂载到vm.$u.api(因为vm就是this也即this.$u.api)下
vm.$u.api = {
@@ -632,7 +635,10 @@ const install = (Vue, vm) => {
uploadFilesFByBase64,
getPromotionList,
checkInvoice,
submitInvoiceApply
submitInvoiceApply,
getAliPayAppAuthTokenBYCode,
loginByGetPhoneNumberForAli
};
}

View File

@@ -10,7 +10,7 @@
}"
:style="{ 'background-color': styles.buttonColor }"
@click="open">
<image class="icon icon-jia" src="/static/images/common/menu.png" mode="" :class="{ active: showContent }"></image>
<image class="icon icon-jia" src="/static/images/common/menu.png" mode="aspectFit" :class="{ active: showContent }"></image>
<!-- <text class="icon icon-jia" :class="{ active: showContent }"></text> -->
</view>
<view class="fab-content"
@@ -30,10 +30,10 @@
:style="{
color: item.active ? styles.selectedColor : styles.color
}"
@click="taps(index, item)">
@click="taps(index, item)">
<image class="content-image icon"
:src="item.active ? item.selectedIconPath : item.iconPath"
mode=""></image>
:src="item.active ? item.selectedIconPath : item.iconPath"
mode="aspectFit"></image>
<text class="text">{{ item.text }}</text>
</view>
<view v-if="flexDirectionEnd || horizontalRight" class="fab-item first"></view>

View File

@@ -36,3 +36,6 @@
.noCaptcha { display: block; }
.regain { display: block; }
}
.aliGetNumberButton { height: 40px; position: relative; -webkit-box-align: center; -webkit-align-items: center; align-items: center; -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center; display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; flex-direction: row; box-sizing: border-box; flex-direction: row; padding: 0 12px; font-size: 14px; color: #fff; background-color: #5ac725; border-color: #5ac725; border-width: 1px; border-style: solid; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; }

View File

@@ -1,7 +1,7 @@
<template>
<view>
<u-toast ref="uToast" />
<!-- #ifndef MP-WEIXIN -->
<!-- #ifndef MP-WEIXIN || MP-ALIPAY -->
<u-popup class="coreshop-bottom-popup-box" :show="showLogin && sessionAuthIdTool" @close="hideModal" mode="bottom" :closeable="true">
<view class="radius coreshop-bg-white wrap">
<view v-if="!showCodeBox">
@@ -40,7 +40,7 @@
</view>
</u-popup>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<!-- #ifdef MP-ALIPAY -->
<u-popup class="coreshop-bottom-popup-box" :show="showLogin && sessionAuthIdTool" @close="hideModal" mode="center">
<view class="radius coreshop-bg-white">
<view class="modal-box">
@@ -66,7 +66,55 @@
<u-checkbox-group>
<u-checkbox v-model="agreement" :checked="agreement" @change="checkboxChange" size="20" active-color="#19be6b"></u-checkbox>
</u-checkbox-group>
<view class="coreshop-text-black-view">
<text class="coreshop-text-black">同意</text>
<text class="text-blue" @tap="goUserAgreementPage">服务协议</text>
<text class="coreshop-text-black"></text>
<text class="text-blue" @tap="goUserPrivacyPolicy">隐私协议</text>
</view>
</view>
</view>
<view class="coreshop-flex coreshop-justify-between coreshop-padding-left-15 coreshop-padding-right-15">
<view class="coreshop-padding-5">
<u-button @click="closeAuth">暂不授权</u-button>
</view>
<view class="coreshop-padding-5">
<u-button type="success" :disabled="isDisabled" v-if="isDisabled">确定授权</u-button>
<!--<u-button type="success" open-type="getAuthorize" scope="phoneNumber" @getphonenumber="getAliPhoneNumber" v-else>确定授权</u-button>-->
<button class="aliGetNumberButton" open-type="getAuthorize" scope="phoneNumber" @getAuthorize="getAliPhoneNumber" v-else>确定授权</button>
</view>
</view>
</view>
</view>
</u-popup>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<u-popup class="coreshop-bottom-popup-box" :show="showLogin && sessionAuthIdTool" @close="hideModal" mode="center">
<view class="radius coreshop-bg-white">
<view class="modal-box">
<view class="modal-box-detail-detail">
<view class="shopDesc">
<view class="coreshop-avatar sm round margin-left">
<u--image width="24px" height="24px" :src="shopLogo"></u--image>
</view>
<text class="shopName">
{{shopName||'登录授权'}}
</text>
<text class="get">
申请
</text>
</view>
<view class="modal-box-detail-title3">获取以下权限为您提供服务</view>
<view class="modal-box-detail-desc">
1获取你的手机号提供更好的账户安全物流订单状态提醒等服务在接下来微信授权手机号的弹窗中选择允许<br />
2使用我们的相关服务需要将您的手机号授权给我们
</view>
<!--服务协议-->
<view class="coreshop-margin-top-15 coreshop-margin-bottom-30 agreement-checked-view">
<u-checkbox-group>
<u-checkbox v-model="agreement" :checked="agreement" @change="checkboxChange" size="20" active-color="#19be6b"></u-checkbox>
</u-checkbox-group>
<view class="coreshop-text-black-view">
<text class="coreshop-text-black">同意</text>
@@ -195,28 +243,21 @@
const _this = this
// #ifdef MP-WEIXIN
var userInfo = this.$store.state.userInfo;
//var token = this.$db.get('userToken');
if (Object.keys(userInfo).length != 0) {
//console.log("获取到store.state用户数据");
} else {
if (Object.keys(userInfo).length == 0) {
_this.$store.commit('userInfo', "");
_this.doToken();
_this.doWeChatToken();
}
// #endif
// #ifdef MP-ALIPAY
var userInfo = this.$store.state.userInfo;
if (Object.keys(userInfo).length == 0) {
_this.$store.commit('userInfo', "");
_this.doAliPayToken();
}
// #endif
},
//watch: {
// 'hasLogin': {
// handler(newVal) {
// //console.log(newVal);
// if (newVal == false) {
// //console.log("watch监听");
// this.doToken();
// }
// },
// deep: true,
// immediate: true,
// }
//},
onShow() {
let _this = this;
_this.timer = parseInt(_this.$db.get('timer'));
@@ -342,15 +383,37 @@
}
})
},
doToken() {
doWeChatToken() {
const _this = this
//console.log("重新获取用户数据");
_this.getCode(function (code) {
var data = {
let data = {
code: code
}
_this.$u.api.onLogin(data).then(res => {
if (res.status) {
if (res.data.auth) {
_this.$db.set('userToken', res.data.auth.token)
_this.$store.commit('hasLogin', true);
}
if (res.data.user) {
_this.$store.commit('userInfo', res.data.user);
}
_this.sessionAuthIdTool = res.otherData;
} else {
_this.$u.toast(res.msg);
_this.$store.commit('userInfo', "");
_this.sessionAuthIdTool = res.otherData;
}
})
})
},
doAliPayToken() {
const _this = this
_this.getCode(function (code) {
let data = {
id: code
}
_this.$u.api.getAliPayAppAuthTokenBYCode(data).then(res => {
if (res.status) {
if (res.data.auth) {
_this.$db.set('userToken', res.data.auth.token)
@@ -378,7 +441,7 @@
} else {
this.isDisabled = true;
}
console.log(this.agreement);
//console.log(this.agreement);
},
// 隐藏登录弹窗
hideModal() {
@@ -396,21 +459,16 @@
},
getCode: function (callback) {
let _this = this
// #ifdef MP-WEIXIN
uni.login({
// #ifdef MP-ALIPAY
scopes: 'auth_user',
// #endif
success: function (res) {
//console.log(res);
if (res.code) {
return callback(res.code)
} else {
//login成功但是没有取到code
_this.$refs.uToast.show({ message: '未取得code请重试', type: 'error', })
}
},
fail: function (res) {
//console.log(res);
var scene = this.$store.state.scene;
//判断是否为 朋友圈内打开“单页模式",单页模式下,数据交互无法执行。所以不进行提醒
if (scene != 1154) {
@@ -418,6 +476,18 @@
}
}
})
// #endif
// #ifdef MP-ALIPAY
my.getAuthCode({
scopes: 'auth_user',
success: (res) => {
console.log(res);
return callback(res.authCode)
},
});
// #endif
},
toLogin: function (data) {
let _this = this
@@ -470,9 +540,60 @@
_this.agreement = false;
_this.isDisabled = true;
_this.showLogin = false;
console.log(e.mp.detail.errMsg);
//console.log(e.mp.detail.errMsg);
}
},
async getAliPhoneNumber() {
let _this = this
if (_this.agreement == false) {
_this.$refs.uToast.show({ message: '请先勾选并同意服务', type: 'error', })
return false;
} else {
my.getPhoneNumber({
success: (res) => {
console.log('获取手机号码', res);
let encryptedData = JSON.parse(res.response);
console.log('获取手机号码2', encryptedData);
var data = {
sessionAuthId: _this.sessionAuthIdTool,
sign: encryptedData.sign,
encryptedData: encryptedData.response,
}
//有推荐码的话,带上
var invitecode = _this.$db.get('invitecode')
if (invitecode) {
data.invitecode = invitecode
}
_this.$u.api.loginByGetPhoneNumberForAli(data).then(res => {
console.log(res);
if (res.status) {
//判断是否返回了token如果没有就说明没有绑定账号跳转到绑定页面
if (res.data.token) {
//console.log("登陆成功设置token并返回上一页");
//登陆成功设置token并返回上一页
_this.$db.set('userToken', res.data.token)
_this.$store.commit('hasLogin', true);
_this.showLogin = false;
_this.$refs.uToast.show({ message: '登录成功', type: 'success', })
return false
}
} else if (!res.status && res.code == 500) {
_this.$u.route({ type: 'switchTab', url: '/pages/index/default/default' });
} else {
_this.$u.toast('登录失败,请重试')
}
})
},
fail: (res) => {
console.log(res);
},
});
_this.agreement = false;
_this.isDisabled = true;
_this.showLogin = false;
}
},
//实际的去登陆
toGetPhoneNumber: function (data) {

View File

@@ -43,7 +43,7 @@
.ad-img { width: 100%; float: left; }
.ad-img:last-child { margin-bottom: 0; }
.imgup-btn { position: absolute; z-index: 1; bottom: 10px; width: 100%; min-height: 30px; text-align: center;
.coreshop-btn { line-height: 2; font-size: 14px; padding: 0 25px; border-radius: 25px; }
.coreshop-btn { font-size: 14px; padding: 0 25px; border-radius: 25px; height: 70rpx;line-height: 70rpx; }
}
}
</style>

View File

@@ -3,7 +3,8 @@
<u-grid :col="limit" :border="false">
<u-grid-item v-for="(item, index) in ListData" :key="index" @click="showSliderInfo(item.linkType, item.linkValue)">
<view class="coreshop-padding-bottom-10 coreshop-padding-top-10">
<u-icon :name="item.image" width="50" height="50" :label="item.text" :labelSize="13" labelPos="bottom" :top="25" space="10"></u-icon>
<u-image class="show coreshop-margin-auto" width="100rpx" height="100rpx" :src="item.image"></u-image>
<u-icon :label="item.text" :labelSize="13" labelPos="bottom" :top="25" space="10"></u-icon>
</view>
</u-grid-item>
</u-grid>

View File

@@ -12,7 +12,7 @@
<view class="tab-box coreshop-flex coreshop-align-center">
<view class="tab-item" @tap="onTab(tab.id,tab.status)" :class="{ 'tab-active': tabCurrent === tab.id }" v-for="tab in tabList" :key="tab.id">
<text class="tab-title">{{ tab.title }}</text>
<text v-show="tabCurrent === tab.id" class="tab-triangle"></text>
<text v-if="tabCurrent === tab.id" class="tab-triangle"></text>
</view>
</view>
<view class="content-box">

View File

@@ -15,15 +15,17 @@
<!--商家及推荐-->
<view class="coreshop-margin-20 coreshop-goods-shop-info-view-box">
<view class="coreshop-shop-view">
<view class="coreshop-position-absolute">
<view class="coreshop-display-flex coreshop-align-center ">
<view>
<u-avatar :src="shopLogo" shape="square"></u-avatar>
</view>
<view class="coreshop-margin-left-10 coreshop-padding-left-40 coreshop-padding-right-40">
<view class="coreshop-margin-left-10 coreshop-flex-sub">
<view class="coreshop-margin-bottom-5 coreshop-text-white">{{shopName || ' '}}</view>
<view class="coreshop-font-sm u-line-1 coreshop-text-white">{{shareTitle || ' '}}</view>
</view>
<u-button type="default" size="mini" :plain="true" @click="doPhoneCall" icon="phone" text="联系商家" color="#272d47"></u-button>
<view style="width: 150rpx;">
<u-button type="default" size="mini" :plain="true" @click="doPhoneCall" icon="phone" text="联系商家" color="#272d47"></u-button>
</view>
</view>
</view>

View File

@@ -413,20 +413,20 @@
<!-- 客服按钮 -->
<!-- #ifdef APP-PLUS-NVUE || APP-PLUS -->
<view class="action" @click="showChat()">
<button class="noButtonStyle">
<button class="noButtonStyle" style="width: 120rpx;" >
<u-icon name="server-fill" :size="20" label="找客服" :labelSize="12" labelPos="bottom"></u-icon>
</button>
</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="action">
<button open-type="contact" bindcontact="showChat" class="noButtonStyle" :send-message-title="goodsInfo.name" :send-message-path="'/pages/goods/goodDetails/goodDetails?id='+goodsInfo.id" :send-message-img="goodsInfo.image" show-message-card="true">
<button style="width: 120rpx;" open-type="contact" bindcontact="showChat" class="noButtonStyle" :send-message-title="goodsInfo.name" :send-message-path="'/pages/goods/goodDetails/goodDetails?id='+goodsInfo.id" :send-message-img="goodsInfo.image" show-message-card="true">
<u-icon name="server-fill" :size="20" label="找客服" :labelSize="12" space="5px" labelPos="bottom"></u-icon>
</button>
</view>
<!-- #endif -->
<view class="action" @click="redirectCart">
<button class="noButtonStyle">
<button class="noButtonStyle" style="width: 120rpx;" >
<u-badge type="warning" :value="cartNums" showZero="false" absolute="true" :offset="[1, 4]"></u-badge>
<u-icon name="shopping-cart-fill" :size="24" label="购物车" :labelSize="12" space="1px" labelPos="bottom"></u-icon>
</button>

View File

@@ -3,6 +3,7 @@
.user-info-box { padding-top: 20px;
.login-user-view { position: relative; text-align: center;
.login-user-avatar-view { position: relative; margin-bottom: 10px; align-items: center; justify-content: center; display: flex; }
}
}
.user-info-tip-box { position: relative; margin: 10px 14px; border-radius: 10px; padding: 10px 14px;
@@ -11,6 +12,10 @@
}
}
}
.btn-login{
width: 150rpx;
margin: auto;
}
.coreshop-view-content { padding: 0 10px 10px 10px; margin-top: -32px;
.coreshop-user-info-order-box { border-radius: 10px;
.coreshop-list {

View File

@@ -22,13 +22,17 @@
<open-data type="userAvatarUrl"></open-data>
</view>
</view>
<u-button type="default" size="mini" @click="goLogin()">立即登录</u-button>
<view class="btn-login" >
<u-button type="default" size="mini" @click="goLogin()">立即登录</u-button>
</view>
<!-- #endif -->
<!-- #ifdef MP-ALIPAY -->
<view class="login-user-avatar-view">
<u-avatar :src="userInfo.avatarImage" size="large"></u-avatar>
<u-avatar :src="userInfo.avatarImage" size="60"></u-avatar>
</view>
<view class="btn-login" >
<u-button type="default" size="mini" @click="goLogin()">立即登录</u-button>
</view>
<u-button type="default" size="mini" @click="goLogin()">立即登录</u-button>
<!-- #endif -->
</view>

View File

@@ -129,8 +129,9 @@
if (res.status) {
uni.requestPayment({
provider: 'alipay',
tradeNO: res.data.trade_no,
orderInfo: res.data.tradeNo,
success: function (e) {
console.log(e);
if (e.errMsg === 'requestPayment:ok') {
_this.$refs.uToast.show({
message: res.msg, type: 'success', complete: function () {

View File

@@ -215,6 +215,9 @@ view, text { box-sizing: border-box; }
/*底部tab切换区域占高*/
.coreshop-tabbar-height { min-height: 50px; height: calc(50px + env(safe-area-inset-bottom) / 2); margin-top: 15px; }
.coreshop-margin-auto{
margin: auto;
}
/*宽屏按钮*/
.coreshop-btn { display: inline-block; box-sizing: border-box; border-radius: 0; font-size: 14px; transform: scale(1); transition: all .5s; }