优化H5登录逻辑

This commit is contained in:
Gaoxs
2020-08-15 20:07:33 +08:00
parent a65d09015e
commit 0c50a9ebb2
12 changed files with 878 additions and 199 deletions

View File

@ -1,8 +1,8 @@
<template>
<view class="container">
<view v-if="!token">
<!-- 小程序 -->
<view v-if="$deviceType == 'routine'">
<!-- #ifdef MP-WEIXIN -->
<view>
<view class="getUserInfo">
<text>您还未允许微信登录授权请点击下方按钮允许微信授权登录</text>
<button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">允许微信登录授权</button>
@ -10,21 +10,21 @@
<button @click="back">取消微信登录授权</button>
</view>
</view>
<!-- app -->
<view v-if="$deviceType == 'app'">
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<view>
<view class="getUserInfo">
<text>请先登录</text>
<button type="primary" @click="this.toLogin">去登录</button>
<button type="primary" @tap="toLogin">去登录</button>
</view>
</view>
<!-- #endif -->
</view>
</view>
</template>
<script>
import { mapState, mapMutations, mapActions } from "vuex";
// 组件
// import request from "@//api/request";
import { wxappAuth, getUser } from "@/api/user";
import dayjs from "dayjs";
import cookie from "@/utils/store/cookie";
@ -33,11 +33,11 @@ import { login, authorize } from "@/utils";
export default {
data() {
return {
authorize: false
authorize: false,
};
},
computed: {
...mapState(["isAuthorization", "$deviceType", "token"])
...mapState(["isAuthorization", "$deviceType", "token"]),
},
onShow() {
// // 先校验用户是否授权,如果没有授权,显示授权按钮
@ -52,12 +52,17 @@ export default {
},
methods: {
...mapActions(["changeAuthorization", "setUserInfo"]),
...mapMutations(["updateAuthorizationPage",]),
...mapMutations(["updateAuthorizationPage"]),
toLogin() {
this.$yrouter.push({
path: "/pages/user/Login/index",
query: {},
});
},
back() {
this.$yrouter.switchTab({
path: "/pages/home/index",
query: {}
query: {},
});
},
getUserInfo(data) {
@ -65,36 +70,28 @@ export default {
uni.showToast({
title: "取消授权",
icon: "none",
duration: 2000
duration: 2000,
});
return;
}
uni.showLoading({
title: "登录中"
title: "登录中",
});
login()
.then(res => {
.then((res) => {
this.$yrouter.replace({ path: cookie.get("redirect") });
})
.catch(error => {
.catch((error) => {
console.log(error);
uni.showToast({
title: error,
icon: "none",
duration: 2000
duration: 2000,
});
});
},
toLogin() {
this.$yrouter.push({
path: "/pages/user/Login/index",
query: {}
});
}
},
mounted() {
}
mounted() {},
};
</script>

View File

@ -10,15 +10,6 @@
</view>
</view>
<view class="fixed-header-box"></view>
<button @click="testTemplate">测试模板消息</button>
<view class="slider-banner banner">
<swiper indicatorDots="true" v-if="banner.length > 0" autoplay circular>
<block v-for="(item, bannerIndex) in banner" :key="bannerIndex">
@ -60,7 +51,7 @@
</view>
</view> -->
<!-- <view class="wrapper hot" v-if="likeInfo.length > 0"> -->
<uni-notice-bar scrollable="true" @click="goRoll(singNew)" single="true" speed="10" showIcon="true" :text="singNew.info"></uni-notice-bar>
<uni-notice-bar scrollable="true" @click="goRoll(singNew)" single="true" :speed="10" showIcon="true" :text="singNew.info"></uni-notice-bar>
<view class="wrapper hot" v-if="bastList.length > 0">
<image class="bg" src="../../static/images/index-bg.png" mode="widthFix"></image>
<view class="title no-border acea-row row-between-wrapper">
@ -288,14 +279,6 @@
},
methods: {
...mapActions(["getLocation"]),
testTemplate() {
console.log('测试')
// 调用订阅
wx.requestSubscribeMessage({
tmplIds: [''],
success(res) {}
})
},
goRoll(item) {
if (item.uniapp_url) {
this.$yrouter.push(item.uniapp_url)

View File

@ -310,8 +310,9 @@ import CouponListWindow from "@/components/CouponListWindow";
import AddressWindow from "@/components/AddressWindow";
import { postOrderConfirm, postOrderComputed, createOrder } from "@/api/order";
import { mapGetters } from "vuex";
import { handleOrderPayResults } from "@/libs/order";
import { weappPay } from "@/libs/wechat";
import { isWeixin } from "@/utils";
import { isWeixin, handleErrorMessage } from "@/utils";
const NAME = "OrderSubmission",
_isWeixin = isWeixin();
@ -545,7 +546,6 @@ export default {
if (this.$deviceType == "app") {
from.from = "app";
}
console.log(this.storeItems, this.systemStore);
createOrder(this.orderGroupInfo.orderKey, {
realName: this.contacts,
phone: this.contactsTel,
@ -565,105 +565,10 @@ export default {
})
.then((res) => {
uni.hideLoading();
const data = res.data;
switch (data.status) {
case "ORDER_EXIST":
case "EXTEND_ORDER":
uni.showToast({
title: res.msg,
icon: "none",
duration: 2000,
});
this.$yrouter.replace({
path: "/pages/order/OrderDetails/index",
query: {
id: data.result.orderId,
},
});
break;
case "PAY_DEFICIENCY":
break;
case "PAY_ERROR":
uni.showToast({
title: res.msg,
icon: "none",
duration: 2000,
});
this.$yrouter.replace({
path: "/pages/order/OrderDetails/index",
query: {
id: data.result.orderId,
},
});
break;
case "SUCCESS":
uni.showToast({
title: res.msg,
icon: "none",
duration: 2000,
});
this.$yrouter.replace({
path: "/pages/order/OrderDetails/index",
query: {
id: data.result.orderId,
},
});
break;
case "WECHAT_H5_PAY":
// H5支付
this.$yrouter.replace({
path: "/pages/order/OrderDetails/index",
query: {
id: data.result.orderId,
},
});
setTimeout(() => {
// location.href = data.result.jsConfig.mweb_url;
}, 100);
break;
case "WECHAT_PAY":
// 小程序支付
weappPay(data.result.jsConfig).finally(() => {
this.$yrouter.replace({
path: "/pages/order/OrderDetails/index",
query: {
id: data.result.orderId,
},
});
});
break;
case "WECHAT_APP_PAY":
// APP支付
weappPay(data.result.jsConfig).finally(() => {
this.$yrouter.replace({
path: "/pages/order/OrderDetails/index",
query: {
id: data.result.orderId,
},
});
});
break;
// 下面为原先微信支付方式,
// pay(data.result.jsConfig).finally(() => {
// this.$yrouter.replace({
// path: "/pages/order/OrderDetails/index" ,query: { id: data.result.orderId}
// });
// });
}
handleOrderPayResults.call(this, res.data, "create");
})
.catch((err) => {
uni.hideLoading();
uni.showToast({
title:
err.msg ||
err.response.data.msg ||
err.response.data.message ||
"创建订单失败",
icon: "none",
duration: 2000,
});
handleErrorMessage(err, "创建订单失败");
});
},
},