feat: complete buy and sell function
This commit is contained in:
Binary file not shown.
@@ -29,5 +29,5 @@ func (r *Router) Register(router fiber.Router) {
|
||||
group.Get(":hash", r.controller.Show)
|
||||
group.Get(":hash/:type<regex([video|audio])>", r.controller.MediaIndex)
|
||||
group.Get(":hash/:type<regex([video|audio])>/:segment.ts", r.controller.MediaSegment)
|
||||
group.Get(":hash/checkout", r.controller.Checkout)
|
||||
group.Patch(":hash/checkout", r.controller.Checkout)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<van-row gutter="20">
|
||||
<van-row gutter="20" v-if="!pageLoading">
|
||||
<van-col span="12">
|
||||
<van-button type="primary" plain round @click="play(item.hash, 'video')" size="large" block>看视频</van-button>
|
||||
</van-col>
|
||||
@@ -43,6 +43,7 @@ import { onBeforeUnmount, onMounted } from "vue";
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const pageLoading = ref(true)
|
||||
|
||||
const item = ref({
|
||||
title: "加载中...",
|
||||
@@ -77,6 +78,53 @@ onMounted(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const buy = () => {
|
||||
// get use balance
|
||||
request
|
||||
.get("/users/info")
|
||||
.then((res) => {
|
||||
if (res.data.balance < item.value.price) {
|
||||
showConfirmDialog({
|
||||
title: '余额不足',
|
||||
message: `您的账户余额为 ${res.data.balance} 点,不足以购买此视频。是否前往充值?`,
|
||||
})
|
||||
.then(() => {
|
||||
router.replace({
|
||||
name: "tab.user",
|
||||
params: {
|
||||
tenant: route.params.tenant,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
return;
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
showConfirmDialog({
|
||||
title: '购买确认',
|
||||
message: `您的账户余额为 ${res.data.balance} 点,购买此视频将花费 ${item.value.price} 点。是否确认购买?`,
|
||||
})
|
||||
.then(() => {
|
||||
request
|
||||
.patch(`/medias/${route.params.hash}/checkout`)
|
||||
.then((res) => {
|
||||
showSuccessToast('购买成功');
|
||||
loadMedia(route.params.hash);
|
||||
})
|
||||
.catch((err) => {
|
||||
showFailToast('购买失败: ' + err.response.data.message);
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
return;
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
const onClickLeft = () => {
|
||||
if (route.meta.from?.name) {
|
||||
router.back();
|
||||
@@ -91,17 +139,18 @@ const onClickLeft = () => {
|
||||
};
|
||||
|
||||
const loadMedia = (hash) => {
|
||||
setTimeout(() => {
|
||||
request
|
||||
.get(`/medias/${hash}`)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
item.value = res.data;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("ERROR", err);
|
||||
});
|
||||
}, 1000);
|
||||
request
|
||||
.get(`/medias/${hash}`)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
item.value = res.data;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("ERROR", err);
|
||||
})
|
||||
.finally(() => {
|
||||
pageLoading.value = false
|
||||
});
|
||||
};
|
||||
|
||||
const play = (hash, type) => {
|
||||
|
||||
Reference in New Issue
Block a user