Files
lingji-work-fe/src/views/property-marketing/assignment-management/components/task-item.vue

370 lines
10 KiB
Vue
Raw Normal View History

2025-09-18 14:40:47 +08:00
<template>
2025-09-24 12:08:21 +08:00
<a-trigger trigger="click" position="br" @click.stop @popup-visible-change="onPopupVisibleChange">
2025-09-19 17:58:13 +08:00
<div class="task-item">
2025-09-20 11:25:34 +08:00
<div class="color-indicator" :style="{ background: getTaskColor() }"></div>
2025-09-24 12:08:21 +08:00
<div>{{ timestampToTime(task.execution_time) }}</div>
2025-09-23 17:11:51 +08:00
<div class="task-name" :title="task?.name || '-'">{{ task?.name || 'AI生成内容' }}</div>
2025-09-19 16:08:00 +08:00
</div>
<template #content>
2025-09-20 11:25:34 +08:00
<div class="flex flex-col items-start popup-content" @click="gotoDetail">
2025-09-19 17:58:13 +08:00
<div class="flex flex-col items-start p-16px w-full" @click="gotoDetail">
<div class="flex justify-between w-full items-center">
2025-09-20 11:25:34 +08:00
<div class="flex items-center title-container">
2025-09-19 17:58:13 +08:00
<img
:src="getPlatformIcon(record.platform)"
style="border-radius: 8px; width: 16px; height: 16px; margin-right: 8px; font-size: 14px"
/>
2025-09-23 17:11:51 +08:00
<div class="task-title" :title="record.name || 'AI生成内容'">{{ record.name || 'AI生成内容' }}</div>
2025-09-19 17:58:13 +08:00
</div>
<div
2025-09-20 11:25:34 +08:00
class="status-tag"
2025-09-19 17:58:13 +08:00
:style="{
color: getTaskColor(),
backgroundColor: getTaskColor() + '50',
}"
>
2025-09-20 11:25:34 +08:00
{{ getTaskStatusText(task.status) }}
2025-09-19 17:58:13 +08:00
</div>
</div>
<div class="text-12px color-#939499 mt-4px h-22px" @click="gotoDetail">
{{ timestampToTime1(task.execution_time) }}
</div>
</div>
2025-09-23 17:11:51 +08:00
<div class="font-size-14px color-#211F24 color-#211F24 task-description" :title="task.name || 'AI生成内容'">
{{ task.name || 'AI生成内容' }}
2025-09-19 17:58:13 +08:00
</div>
2025-09-24 16:20:33 +08:00
<div v-if="task.ai_generate_status == 0" class="AILoding">
2025-09-20 12:37:28 +08:00
<ASpin />
<div style="color: #9a56ba">内容生成中...</div>
<div style="color: #9a56ba">完成后将自动展示您可先返回其他操作</div>
</div>
2025-09-24 12:08:21 +08:00
2025-09-24 16:20:33 +08:00
<div v-else-if="task.ai_generate_status == 1 && taskDetail" class="w-full pl-16px">
2025-09-24 12:08:21 +08:00
<div
v-for="item in choseTextArray"
:key="item.id"
class="flex items-center bg-#F7F8FA border-rounded-8px w-full justify-items-center pt-8px pb-8px pl-12px pr-12px mb-16px"
>
{{ item }}
</div>
<div class="flex items-center w-full">
<img
v-for="item in choseImgArray"
:key="item.id"
:src="item.cover || item.url"
class="w-88 h-88 mr-8px border-rounded-8px"
/>
</div>
<div class="flex items-center w-full">
<video
v-for="item in choseVideoArray"
:key="item.id"
:src="item.cover || item.url"
class="w-44 h-44 mr-8px border-rounded-8px object-fit-contain"
/>
</div>
</div>
2025-09-19 17:58:13 +08:00
<div class="flex items-center mt-12px w-full h-1px bg-#E6E6E8"></div>
2025-09-24 16:20:33 +08:00
<div class="flex items-center mt-12px mb-16px action-buttons w-full px-16px">
<div class="flex items-center mr-12px" @click.stop="handleDelete" v-if="task.status != 1">
<icon-delete style="font-size: 20px; margin-left: 0" />
</div>
<div class="flex w-full" :class="{ 'justify-between': task.ai_generate_status == 0 }">
<a-date-picker
2025-09-24 16:53:14 +08:00
v-model="datePickerValue"
2025-09-24 16:20:33 +08:00
placeholder="修改发布时间"
2025-09-24 16:27:52 +08:00
:show-time="{ format: 'HH:mm' }"
2025-09-24 16:20:33 +08:00
format="YYYY-MM-DD HH:mm"
value-format="YYYY-MM-DD HH:mm"
@change="onChange"
@ok="onOk"
@click.stop
@mousedown.stop
@focus.stop
/>
<button v-if="task.ai_generate_status == 0" class="opt-btn ml-12px opt-right" @click.stop="handleAICreate">
AI立即生成
</button>
2025-09-19 17:58:13 +08:00
</div>
</div>
</div>
2025-09-19 16:08:00 +08:00
</template>
</a-trigger>
2025-09-19 10:34:26 +08:00
</template>
<script setup lang="ts">
2025-09-24 12:08:21 +08:00
import { ref, onMounted, watch } from 'vue';
2025-09-20 12:37:28 +08:00
import { Spin as ASpin } from 'ant-design-vue';
2025-09-24 16:20:33 +08:00
import dayjs from 'dayjs';
2025-09-19 17:58:13 +08:00
import iconDy from '@/assets/img/platform/icon-dy.png';
import iconXhs from '@/assets/img/platform/icon-xhs.png';
import iconBilibili from '@/assets/img/platform/icon-bilibili.png';
import iconKs from '@/assets/img/platform/icon-ks.png';
import iconSph from '@/assets/img/platform/icon-sph.png';
import iconWb from '@/assets/img/platform/icon-wb.png';
import iconGzh from '@/assets/img/platform/icon-gzh.png';
import iconWarn from '@/assets/img/media-account/icon-warn.png';
2025-09-24 12:08:21 +08:00
import { getTaskSchedulesDetail } from '@/api/all/assignment-management';
2025-09-24 16:20:33 +08:00
import { DatePicker } from '@arco-design/web-vue';
2025-09-19 15:53:12 +08:00
// 定义props和emit
const props = defineProps({
task: Object,
record: Object,
});
2025-09-19 17:58:13 +08:00
2025-09-24 12:08:21 +08:00
const taskDetail = ref(null);
const choseImgArray = ref([]);
const choseTextArray = ref([]);
const choseVideoArray = ref([]);
const getTaskDetail = async () => {
if (!props.task || !props.task.id) return;
2025-09-20 11:25:34 +08:00
2025-09-24 12:08:21 +08:00
try {
const res = await getTaskSchedulesDetail(props.task.id);
2025-09-24 16:20:33 +08:00
2025-09-24 12:08:21 +08:00
if (res && res.data) {
2025-09-24 16:20:33 +08:00
datePickerValue.value = dayjs(res.data.execution_time * 1000);
console.log('任务详情:', datePickerValue.value);
if ('work' in res.data && res.data.work) {
2025-09-24 12:08:21 +08:00
taskDetail.value = res.data.work;
choseImgArray.value = res.data.work.files.filter((item) => [0].includes(item.type));
choseTextArray.value = res.data.work.files.filter((item) => [2].includes(item.type));
choseVideoArray.value = res.data.work.files.filter((item) => [1].includes(item.type));
} else {
taskDetail.value = res.data.raw_materials;
choseImgArray.value = taskDetail.value.filter((item) => [0].includes(item.type));
choseTextArray.value = taskDetail.value.filter((item) => [2].includes(item.type));
choseVideoArray.value = taskDetail.value.filter((item) => [1].includes(item.type));
}
}
} catch (error) {
console.error('获取任务详情失败:', error);
}
};
2025-09-24 16:20:33 +08:00
const onChange = (date, dateString) => {
console.log('Selected Date: ', date, dateString);
};
const onOk = (value) => {
2025-09-24 16:27:52 +08:00
console.log('DatePicker OK: ', value);
2025-09-24 16:20:33 +08:00
if (value) {
emit('handle-task', 'edit-time', props.task, value);
}
};
2025-09-24 12:08:21 +08:00
const onPopupVisibleChange = (visible) => {
if (visible) {
getTaskDetail();
}
};
2025-09-19 17:58:13 +08:00
const handleDelete = () => {
emit('handle-task', 'delete', props.task, props.record);
};
const gotoDetail = () => {
console.log('跳转详情');
emit('handle-task', 'goto-detail', props.task, props.record);
};
2025-09-24 16:27:52 +08:00
const handleTimeChange = (time: string) => {
// if (time) {
// emit('handle-task', 'edit-time', props.task, timestampToTime1() + ' ' + time + ':00');
// }
};
2025-09-24 12:08:21 +08:00
const handleAICreate = () => {
emit('handle-task', 'ai-create', props.task, props.record);
};
const timestampToTime = (timestamp: number): string => {
// 如果没有传入时间戳,则返回空字符串
if (!timestamp) return '';
// 将时间戳转换为毫秒(如果时间戳是秒单位的话)
const date = new Date(timestamp * 1000);
2025-09-19 17:58:13 +08:00
2025-09-24 12:08:21 +08:00
// 格式化为 HH:mm 格式
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${hours}:${minutes}`;
};
2025-09-24 16:20:33 +08:00
const timestampToTime1 = (timestamp: number): string => {
// 如果没有传入时间戳,则使用当前时间
if (!timestamp) {
timestamp = Date.now() / 1000; // 使用秒级时间戳保持一致性
}
2025-09-24 16:53:14 +08:00
2025-09-24 16:20:33 +08:00
const date = new Date(timestamp * 1000);
2025-09-19 17:58:13 +08:00
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 补零
const day = String(date.getDate()).padStart(2, '0'); // 补零
return `${month}${day}`;
2025-09-19 15:53:12 +08:00
};
2025-09-19 17:58:13 +08:00
2025-09-19 16:08:00 +08:00
const emit = defineEmits(['filter-change', 'handle-task']);
2025-09-19 17:58:13 +08:00
2025-09-24 16:20:33 +08:00
// 日期选择器的值
2025-09-24 16:27:52 +08:00
const datePickerValue = ref(null);
2025-09-24 16:20:33 +08:00
2025-09-19 17:58:13 +08:00
// 平台配置
const platformConfig = {
icons: {
0: iconDy,
1: iconXhs,
2: iconBilibili,
3: iconKs,
4: iconSph,
5: iconWb,
6: iconGzh,
},
};
// 获取平台图标
const getPlatformIcon = (platform: number) => platformConfig.icons[platform] || iconWarn;
2025-09-19 15:53:12 +08:00
// 根据任务类型获取颜色
const getTaskColor = () => {
if (!props.task) return '#000';
// 根据colorTip.vue中的颜色定义设置不同状态的颜色
switch (props.task.status) {
case 0: // 待生成
return '#ffae00';
case 1: // 待发布
return '#6d4cfe';
case 2: // 已发布
return '#939499';
case 3: // 发布失败
return '#f64b31';
default:
return props.task.color || '#939499';
}
};
2025-09-19 17:58:13 +08:00
const getTaskStatusText = (status) => {
2025-09-20 11:25:34 +08:00
console.log('任务状态:', status);
2025-09-19 17:58:13 +08:00
switch (status) {
case 0:
return '待生成';
case 1:
return '待发布';
case 2:
return '已发布';
case 3:
return '发布失败';
default:
return '未知状态';
}
};
2025-09-19 10:34:26 +08:00
</script>
<style lang="less" scoped>
.task-item {
width: 100%;
2025-09-19 15:53:12 +08:00
font-size: 12px;
height: 19px;
display: flex;
align-items: center;
gap: 4px;
2025-09-20 11:25:34 +08:00
min-width: 0;
2025-09-19 15:53:12 +08:00
&:last-child {
margin-bottom: 0;
}
2025-09-19 10:34:26 +08:00
}
2025-09-19 17:58:13 +08:00
2025-09-20 11:25:34 +08:00
.color-indicator {
width: 4px;
height: 18px;
border-radius: 2px;
flex-shrink: 0;
}
.task-name {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
width: 0;
}
.popup-content {
width: 388px;
background-color: #fff;
box-shadow: #e6e6e8 0px 2px 8px;
border-radius: 4px;
}
.title-container {
flex: 1;
min-width: 0;
}
.task-title {
font-size: 16px;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
min-width: 0;
line-height: 1.2;
}
.task-description {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
line-height: 1.2;
flex: 1;
min-width: 0;
width: 365px;
2025-09-20 12:42:00 +08:00
margin-top: -10px;
margin-bottom: 12px;
padding: 0 16px;
2025-09-20 11:25:34 +08:00
}
.status-tag {
padding: 2px 8px;
border-radius: 4px;
flex-shrink: 0;
}
2025-09-19 17:58:13 +08:00
.opt-btn {
width: 154px;
height: 32px;
font-size: 14px;
background: #f2f3f5;
border: none;
border-radius: 4px;
}
.opt-right {
background: linear-gradient(90deg, #fbf9ff 0%, #f3fafe 100%);
color: #9a56ba;
}
2025-09-20 12:37:28 +08:00
.AILoding {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 356px;
height: 108px;
border-radius: 8px;
background: linear-gradient(90deg, #fbf9ff 0%, #f3fafe 100%);
color: linear-gradient(90deg, #9a56ba 0%, #576fd1 100%);
margin-left: 16px;
font-weight: 400;
font-style: Regular;
font-size: 12px;
leading-trim: NONE;
line-height: 20px;
letter-spacing: 0%;
text-align: center;
}
2025-09-19 10:34:26 +08:00
</style>