f
This commit is contained in:
@@ -58,9 +58,32 @@
|
|||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
|
|
||||||
|
<!-- 开发环境:测试支付(仅开发环境显示) -->
|
||||||
|
<van-cell
|
||||||
|
v-if="isDev"
|
||||||
|
title="测试支付(开发)"
|
||||||
|
clickable
|
||||||
|
@click="selectedPaymentMethod = 'test'"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<van-icon
|
||||||
|
size="24"
|
||||||
|
name="passed"
|
||||||
|
color="#07c160"
|
||||||
|
class="mr-2"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #right-icon>
|
||||||
|
<van-radio
|
||||||
|
v-model="selectedPaymentMethod"
|
||||||
|
name="test"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</van-cell>
|
||||||
|
|
||||||
<!-- 支付宝支付 -->
|
<!-- 支付宝支付 -->
|
||||||
<van-cell
|
<van-cell
|
||||||
v-else
|
v-if="!isWeChat"
|
||||||
title="支付宝支付"
|
title="支付宝支付"
|
||||||
clickable
|
clickable
|
||||||
@click="selectedPaymentMethod = 'alipay'"
|
@click="selectedPaymentMethod = 'alipay'"
|
||||||
@@ -94,6 +117,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, defineProps } from "vue";
|
import { ref, defineProps } from "vue";
|
||||||
const { isWeChat } = useEnv();
|
const { isWeChat } = useEnv();
|
||||||
|
const isDev = import.meta.env.DEV;
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: {
|
data: {
|
||||||
@@ -110,9 +134,13 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const show = defineModel();
|
const show = defineModel();
|
||||||
const selectedPaymentMethod = ref(isWeChat.value ? "wechat" : "alipay");
|
const selectedPaymentMethod = ref(
|
||||||
|
isDev ? "test" : isWeChat.value ? "wechat" : "alipay"
|
||||||
|
);
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (isWeChat.value) {
|
if (isDev) {
|
||||||
|
selectedPaymentMethod.value = "test";
|
||||||
|
} else if (isWeChat.value) {
|
||||||
selectedPaymentMethod.value = "wechat";
|
selectedPaymentMethod.value = "wechat";
|
||||||
} else {
|
} else {
|
||||||
selectedPaymentMethod.value = "alipay";
|
selectedPaymentMethod.value = "alipay";
|
||||||
@@ -121,13 +149,6 @@ onMounted(() => {
|
|||||||
const orderNo = ref("");
|
const orderNo = ref("");
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const discountPrice = ref(false); // 是否应用折扣
|
const discountPrice = ref(false); // 是否应用折扣
|
||||||
onMounted(() => {
|
|
||||||
if (isWeChat.value) {
|
|
||||||
selectedPaymentMethod.value = "wechat";
|
|
||||||
} else {
|
|
||||||
selectedPaymentMethod.value = "alipay";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async function getPayment() {
|
async function getPayment() {
|
||||||
const { data, error } = await useApiFetch("/pay/payment")
|
const { data, error } = await useApiFetch("/pay/payment")
|
||||||
@@ -139,10 +160,23 @@ async function getPayment() {
|
|||||||
.json();
|
.json();
|
||||||
|
|
||||||
if (data.value && !error.value) {
|
if (data.value && !error.value) {
|
||||||
|
const prepayId = data.value.data.prepay_id ?? data.value.data.prepayId;
|
||||||
|
const orderNoFromApi = data.value.data.order_no;
|
||||||
|
orderNo.value = orderNoFromApi;
|
||||||
|
|
||||||
|
// 开发环境测试支付:直接跳转结果页
|
||||||
|
if (selectedPaymentMethod.value === "test" && prepayId === "test_payment_success") {
|
||||||
|
router.push({
|
||||||
|
path: "/payment/result",
|
||||||
|
query: { orderNo: orderNoFromApi },
|
||||||
|
});
|
||||||
|
show.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedPaymentMethod.value === "alipay") {
|
if (selectedPaymentMethod.value === "alipay") {
|
||||||
orderNo.value = data.value.data.order_no;
|
|
||||||
// 存储订单ID以便支付宝返回时获取
|
// 存储订单ID以便支付宝返回时获取
|
||||||
const prepayUrl = data.value.data.prepay_id;
|
const prepayUrl = prepayId;
|
||||||
const paymentForm = document.createElement("form");
|
const paymentForm = document.createElement("form");
|
||||||
paymentForm.method = "POST";
|
paymentForm.method = "POST";
|
||||||
paymentForm.action = prepayUrl;
|
paymentForm.action = prepayUrl;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export default defineConfig({
|
|||||||
strictPort: true, // 如果端口被占用则抛出错误而不是使用下一个可用端口
|
strictPort: true, // 如果端口被占用则抛出错误而不是使用下一个可用端口
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api/v1": {
|
"/api/v1": {
|
||||||
target: "http://127.0.0.1:8888", // 本地接口地址
|
// target: "http://127.0.0.1:8888", // 本地接口地址
|
||||||
// target: "https://www.tianyuancha.cn", // 本地接口地址
|
target: "https://www.tianyuancha.cn", // 本地接口地址
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user