商品详情页支付时加入是否登录的判断逻辑

This commit is contained in:
xiaogang 2024-08-06 09:16:09 +08:00
parent a28028c8fc
commit f8db65929e
3 changed files with 11 additions and 4 deletions

View File

@ -1,7 +1,6 @@
# 兴业优酷 # 兴业优酷
# VITE_BASE_URL = 'http://192.168.110.50:8083' # VITE_BASE_URL = 'http://192.168.110.50:8083'
# 邮储奶茶活动(测试环境) # 邮储奶茶活动(测试环境)
# VITE_BASE_URL = 'http://milk.api.test.86698.cn' # VITE_BASE_URL = 'http://milk.api.test.86698.cn'
# VITE_YCNC_MERCH_CODE = '100610100019029' # VITE_YCNC_MERCH_CODE = '100610100019029'

View File

@ -43,10 +43,12 @@
<script setup> <script setup>
import { onMounted, reactive, ref, unref } from 'vue'; import { onMounted, reactive, ref, unref } from 'vue';
import { onLoad } from '@dcloudio/uni-app'; import { onLoad } from '@dcloudio/uni-app';
import { queryDetail, goPay } from '../../api/ycnc'; import { queryDetail, goPay, login } from '../../api/ycnc';
import usePay from './hooks/usePay'; import usePay from './hooks/usePay';
import useCode from './hooks/useCode';
const id = ref('') const id = ref('')
const authCode = ref('');
const detailObj = reactive({}) const detailObj = reactive({})
@ -68,7 +70,14 @@
}) })
} }
const toPay = () => { const toPay = async () => {
const token = window.localStorage.getItem('token') || '';
if(!token){
const code = await useCode();
authCode.value = code
const {token} = await login({params:{code:unref(authCode)}});
window.localStorage.setItem('token',token);
}
const params = { const params = {
product_id:unref(id) product_id:unref(id)
} }

View File

@ -72,7 +72,6 @@
queryProducts(); queryProducts();
const token = window.localStorage.getItem('token') || ''; const token = window.localStorage.getItem('token') || '';
if(!token){ if(!token){
console.log('进入登录过程');
const code = await useCode(); const code = await useCode();
authCode.value = code authCode.value = code
const {token} = await login({params:{code:unref(authCode)}}); const {token} = await login({params:{code:unref(authCode)}});