feat: add post upload action

This commit is contained in:
yanghao05
2025-04-11 09:40:13 +08:00
parent d940c182a4
commit 736991e3ea
5 changed files with 72 additions and 30 deletions

View File

@@ -101,10 +101,6 @@ const confirmDelete = (post) => {
icon: 'pi pi-exclamation-triangle',
acceptClass: 'p-button-danger',
accept: () => {
// // In a real app, you would call an API to delete the post
// posts.value = posts.value.filter(p => p.id !== post.id);
// toast.add({ severity: 'success', summary: '成功', detail: '文章已删除', life: 3000 });
// call remote delete
postService.deletePost(post.id)
.then(() => {
@@ -126,9 +122,13 @@ const formatDate = (date) => {
return dayjs.tz(date, 'Asia/Shanghai').format('YYYY-MM-DD HH:mm:ss');
};
// Calculate price after discount
const calculateDiscountPrice = (price, discount) => {
if (!discount || discount >= 100) return price;
// Add these helper functions next to existing price-related functions
const getDiscountAmount = (price, discount) => {
return price * (100 - discount) / 100;
};
const getFinalPrice = (price, discount) => {
return price * discount / 100;
};
@@ -257,16 +257,12 @@ const formatMediaTypes = (mediaTypes) => {
<Column field="price" header="价格" sortable>
<template #body="{ data }">
<div class="text-sm text-gray-900">
<span class="line-through text-gray-500" v-if="data.discount != 100">
{{ formatPrice(data.price) }}
</span>
<span :class="{ 'ml-2': data.discount != 100 }">
{{ formatPrice(calculateDiscountPrice(data.price, data.discount)) }}
</span>
<span v-if="data.discount != 100" class="ml-2 text-red-500">
({{ data.discount }}%)
</span>
<div class="flex flex-col">
<span class="text-gray-500">原价: {{ formatPrice(data.price) }}</span>
<span class="text-orange-500">优惠: -{{ formatPrice(getDiscountAmount(data.price,
data.discount)) }}</span>
<span class="font-bold">实付: {{ formatPrice(getFinalPrice(data.price, data.discount))
}}</span>
</div>
</template>
</Column>