diff --git a/src/components/Payment.vue b/src/components/Payment.vue
index 5f5180b..b928ac0 100644
--- a/src/components/Payment.vue
+++ b/src/components/Payment.vue
@@ -38,8 +38,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -60,6 +80,7 @@
import { ref, defineProps } from "vue";
import { showConfirmDialog } from "vant";
const { isWeChat } = useEnv();
+const isDev = import.meta.env.DEV;
const props = defineProps({
data: {
@@ -76,9 +97,13 @@ const props = defineProps({
},
});
const show = defineModel();
-const selectedPaymentMethod = ref(isWeChat.value ? "wechat" : "alipay");
+const selectedPaymentMethod = ref(
+ isDev ? "test" : isWeChat.value ? "wechat" : "alipay"
+);
onMounted(() => {
- if (isWeChat.value) {
+ if (isDev) {
+ selectedPaymentMethod.value = "test";
+ } else if (isWeChat.value) {
selectedPaymentMethod.value = "wechat";
} else {
selectedPaymentMethod.value = "alipay";
@@ -87,13 +112,6 @@ onMounted(() => {
const orderNo = ref("");
const router = useRouter();
const discountPrice = ref(false); // 是否应用折扣
-onMounted(() => {
- if (isWeChat.value) {
- selectedPaymentMethod.value = "wechat";
- } else {
- selectedPaymentMethod.value = "alipay";
- }
-});
async function getPayment() {
showConfirmDialog({
@@ -111,10 +129,23 @@ async function getPayment() {
.json();
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") {
- orderNo.value = data.value.data.order_no;
// 存储订单ID以便支付宝返回时获取
- const prepayUrl = data.value.data.prepay_id;
+ const prepayUrl = prepayId;
const paymentForm = document.createElement("form");
paymentForm.method = "POST";
paymentForm.action = prepayUrl;
diff --git a/vite.config.js b/vite.config.js
index 82fb402..077b78b 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -15,8 +15,8 @@ export default defineConfig({
strictPort: true, // 如果端口被占用则抛出错误而不是使用下一个可用端口
proxy: {
"/api/v1": {
- target: "http://127.0.0.1:8888", // 本地接口地址
- // target: "https://www.tianyuancha.cn", // 本地接口地址
+ // target: "http://127.0.0.1:8888", // 本地接口地址
+ target: "https://www.tianyuancha.cn", // 本地接口地址
changeOrigin: true,
},
},