50 lines
1.2 KiB
Vue
Raw Normal View History

<template>
<view class="wh-full">
<web-view :src="payUrl"></web-view>
</view>
</template>
<script lang="ts" setup>
import { onLoad } from "@dcloudio/uni-app";
import { useWebSocket } from '@/utils/webSocket/webSocket'
import { useUserStore } from "@/store/modules/user";
const { getUser } = useUserStore();
const payUrl = ref("");
2025-07-01 20:54:38 +08:00
const ws = useWebSocket(`/zhxy/webSocket/${getUser.userId}`, (type: string, res: any) => {
console.log('收到WebSocket消息:', type, res.data);
// 将data从字符串转为对象
const dataObj = JSON.parse(res.data);
if (dataObj.action === 'pay') {
uni.showToast({
title: '支付成功',
icon: 'success',
2025-07-01 20:54:38 +08:00
});
ws.closeConnect();
// 跳转到支付成功页面
setTimeout(() => {
uni.reLaunch({
url: "/pages/base/course-selection/payment-success",
});
}, 1000)
}
});
onLoad((options: any) => {
if (options.payUrl) {
payUrl.value = decodeURIComponent(options.payUrl);
ws.reconnect();
} else {
uni.showToast({ title: '缺少支付地址', icon: 'none' })
setTimeout(() => {
uni.navigateBack()
}, 1000)
}
});
2025-07-01 20:54:38 +08:00
onBeforeUnmount(() => {
ws.closeConnect();
});
</script>
<style lang="scss" scoped></style>