cyber/src/components/AccountWorkPiece.vue
2025-03-29 10:39:20 +08:00

167 lines
3.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup>
import {defineProps} from 'vue'
import DefaultCover from "./DefaultCover.vue";
import router from "../router/index.js";
import store from "../store/index.js";
import {blogImage} from "../utils/imageResource.js";
import swal from "../utils/sweetalert.js";
import api from "../utils/axios.js";
import {formatGMTToLocal} from "../utils/formatTime.js";
const props = defineProps({
cover: {
type: String,
default: ''
},
title: {
type: String,
default: ''
},
createdTime: {
type: String,
default: ''
},
lastModifiedTime: {
type: String,
default: ''
},
isDraft: {
type: Boolean,
default: false
},
id: {
type: Number,
required: true
}
})
const emit = defineEmits(['refresh']);
// 测试函数,可以根据需求替换
function onEdit() {
store.state.editStore.currentBlogId = props.id;
router.push('/editor');
}
async function onDelete() {
const result = await swal.window('info', '确定删除吗?', '此操作不可撤销', '确实', '取消');
try {
if (result.isConfirmed) {
const response = await api.delete(`/blogs/${props.id}`);
if (response.code === 0) {
swal.tip('success', '删除成功');
emit('refresh', 1);
return;
}
swal.tip('error', '删除失败');
}
} catch {
swal.tip('error', '网络错误');
}
}
function onPermission() {
console.log('权限')
}
</script>
<template>
<div class="work-piece">
<!-- 左侧博客封面 + 标题 -->
<div class="piece-left">
<!-- <img :src="cover" alt="封面" class="cover-image" />-->
<DefaultCover :imageSrc="blogImage(cover)" :text="title" size="60px" class="cover-image"/>
<div class="title-text">{{ title }}</div>
</div>
<!-- 右侧时间和操作按钮 -->
<div class="piece-right">
<!-- 上方时间信息 -->
<div class="times">
<div>创建时间{{ formatGMTToLocal(createdTime) }}</div>
<div>最后修改{{ formatGMTToLocal(lastModifiedTime) }}</div>
</div>
<!-- 下方操作 -->
<div class="actions">
<span class="action-btn" @click="onEdit">编辑</span>
<router-link v-if="!isDraft" class="action-btn" :to="`/blog/${id}`" target="_blank">查看</router-link>
<span class="action-btn" @click="onDelete">删除</span>
<!-- 草稿时不显示权限 -->
<!-- <span-->
<!-- v-if="!isDraft"-->
<!-- class="action-btn"-->
<!-- @click="onPermission"-->
<!-- >-->
<!-- 权限-->
<!-- </span>-->
</div>
</div>
</div>
</template>
<style scoped>
/* 容器:一条“横向卡片” */
.work-piece {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #24303f; /* 暗色稍微提亮 */
border-radius: 6px;
padding: 10px;
}
.theme-light .work-piece {
background-color: #f2f2f2;
color: black;
}
/* 左侧 */
.piece-left {
display: flex;
align-items: center;
gap: 12px;
}
.cover-image {
width: 60px;
height: 60px;
object-fit: cover;
border-radius: 4px;
overflow: hidden;
}
.title-text {
font-size: 16px;
font-weight: bold;
}
/* 右侧 */
.piece-right {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
}
.times {
opacity: 0.5;
font-size: small;
text-align: right;
}
.actions {
display: flex;
gap: 16px;
}
.action-btn {
font-size: 14px;
opacity: 0.6;
cursor: pointer;
}
.action-btn:hover {
opacity: 0.5;
}
</style>