Commit 1fa87131 by chenwq

feat: 重构任务卡片组件,优化任务列表展示逻辑,移除冗余组件

1 parent a3d557a6
<template> <template>
<div class="strategy-task-list"> <div class="strategy-task-list">
<TaskCardList v-if="list.length" <template v-if="list.length">
<TaskCard v-for="(task, index) in list"
:key="task.id || index"
action-text="查看" action-text="查看"
:card-config="cardConfig" :card-config="cardConfig"
:list="list"
:status="getCardStatus" :status="getCardStatus"
:task="task"
:title="getCardTitle" :title="getCardTitle"
@action="viewDetail" /> @action="viewDetail" />
</template>
<van-empty v-else description="暂无任务" /> <van-empty v-else description="暂无任务" />
</div> </div>
</template> </template>
<script> <script>
import constantData from "../constantData.js"; import constantData from "../constantData.js";
import TaskCardList from "./TaskCardList.vue"; import TaskCard from "./TaskCard.vue";
export default { export default {
name: "StrategyTaskList", name: "StrategyTaskList",
components: { components: {
TaskCardList, TaskCard,
}, },
props: { props: {
list: { list: {
...@@ -45,3 +48,11 @@ export default { ...@@ -45,3 +48,11 @@ export default {
}, },
}; };
</script> </script>
<style lang="scss" scoped>
.strategy-task-list {
height: calc(100% - 60px);
overflow: scroll;
padding-bottom: env(safe-area-inset-bottom);
}
</style>
<template> <template>
<div class="task-card-list"> <div class="task-card">
<div v-for="(task, index) in list"
:key="index"
class="task-card">
<div class="card-header"> <div class="card-header">
<span class="status-tag" :style="getStatusStyle(task)"> <span class="status-tag" :style="getStatusStyle()">
{{ getStatusName(task) }} {{ getStatusName() }}
</span> </span>
<span class="task-title">{{ getTitle(task) }}</span> <span class="task-title">{{ getTitle() }}</span>
</div> </div>
<div class="card-body"> <div class="card-body">
<template v-for="(item, itemIndex) in cardConfig"> <template v-for="(item, itemIndex) in cardConfig">
<div v-if="isFieldShow(task, item)" <div v-if="isFieldShow(item)"
:key="item.key || itemIndex" :key="item.key || itemIndex"
class="info-row"> class="info-row">
<van-icon class="icon" :name="item.icon" /> <van-icon class="icon" :name="item.icon" />
<div class="content-wrapper"> <div class="content-wrapper">
<span class="label">{{ getFieldLabel(task, item) }}</span> <span class="label">{{ getFieldLabel(item) }}</span>
<span class="value">{{ getFieldValue(task, item) }}</span> <span class="value">{{ getFieldValue(item) }}</span>
</div> </div>
</div> </div>
</template> </template>
</div> </div>
<div v-if="actionText && isActionShow(task)" class="card-footer"> <div v-if="actionText && isActionShow()" class="card-footer">
<div class="view-btn" @click="$emit('action', task)"> <div class="view-btn" @click="$emit('action', task)">
{{ actionText }} {{ actionText }}
</div> </div>
</div> </div>
</div> </div>
</div>
</template> </template>
<script> <script>
export default { export default {
name: "TaskCardList", name: "TaskCard",
props: { props: {
list: { task: {
type: Array, type: Object,
default: () => [], default: () => ({}),
}, },
cardConfig: { cardConfig: {
type: Array, type: Array,
...@@ -63,43 +59,42 @@ export default { ...@@ -63,43 +59,42 @@ export default {
}, },
}, },
methods: { methods: {
getTitle(task) { getTitle() {
return typeof this.title === "function" ? this.title(task) : this.title; return typeof this.title === "function" ? this.title(this.task) : this.title;
}, },
getStatus(task) { getStatus() {
return this.status ? this.status(task) : {}; return this.status ? this.status(this.task) : {};
}, },
getStatusName(task) { getStatusName() {
return this.getStatus(task).name || "-"; return this.getStatus().name || "-";
}, },
getStatusStyle(task) { getStatusStyle() {
const status = this.getStatus(task); const status = this.getStatus();
return { return {
color: status.color || "#2c66f7", color: status.color || "#2c66f7",
background: status.background || "#2c66f71a", background: status.background || "#2c66f71a",
}; };
}, },
isFieldShow(task, item) { isFieldShow(item) {
return item.isShow ? item.isShow(task) : true; return item.isShow ? item.isShow(this.task) : true;
}, },
getFieldLabel(task, item) { getFieldLabel(item) {
return item.getLabel ? item.getLabel(task) : item.label; return item.getLabel ? item.getLabel(this.task) : item.label;
}, },
getFieldValue(task, item) { getFieldValue(item) {
if (item.getValue) if (item.getValue)
return item.getValue(task) || "-"; return item.getValue(this.task) || "-";
return task[item.key] || "-"; return this.task[item.key] || "-";
}, },
isActionShow(task) { isActionShow() {
return this.actionVisible ? this.actionVisible(task) : true; return this.actionVisible ? this.actionVisible(this.task) : true;
}, },
}, },
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.task-card-list { .task-card {
.task-card {
background: #ffffff; background: #ffffff;
border-radius: 8px; border-radius: 8px;
padding: 16px; padding: 16px;
...@@ -176,6 +171,5 @@ export default { ...@@ -176,6 +171,5 @@ export default {
border-radius: 14px; border-radius: 14px;
} }
} }
}
} }
</style> </style>
<template> <template>
<div class="task-center-list"> <div class="task-center-list">
<van-pull-refresh v-model="refreshing" @refresh="onRefresh"> <van-pull-refresh v-model="refreshing"
class="refresh"
@refresh="onRefresh">
<van-list v-if="list.length" <van-list v-if="list.length"
v-model="loading" v-model="loading"
finished-text="到底了" finished-text="到底了"
:finished="finished" :finished="finished"
@load="onLoadMore"> @load="onLoadMore">
<TaskCardList action-text="查看" <TaskCard v-for="(task, index) in list"
:key="task.id || index"
action-text="查看"
:action-visible="canViewDetail" :action-visible="canViewDetail"
:card-config="cardConfig" :card-config="cardConfig"
:list="list"
:status="getCardStatus" :status="getCardStatus"
:task="task"
:title="cardTitle" :title="cardTitle"
@action="viewDetail" /> @action="viewDetail" />
</van-list> </van-list>
...@@ -26,7 +30,7 @@ import dayjs from "dayjs"; ...@@ -26,7 +30,7 @@ import dayjs from "dayjs";
import api from "@/api/teamWork"; import api from "@/api/teamWork";
import util from "@/utils/util"; import util from "@/utils/util";
import constantData from "../constantData.js"; import constantData from "../constantData.js";
import TaskCardList from "./TaskCardList.vue"; import TaskCard from "./TaskCard.vue";
const TASK_CENTER_CARD_TITLE = "专项带教"; const TASK_CENTER_CARD_TITLE = "专项带教";
...@@ -54,7 +58,7 @@ const TASK_CENTER_CARD_CONFIG = [ ...@@ -54,7 +58,7 @@ const TASK_CENTER_CARD_CONFIG = [
export default { export default {
name: "TaskCenterList", name: "TaskCenterList",
components: { components: {
TaskCardList, TaskCard,
}, },
props: { props: {
startDate: { startDate: {
...@@ -158,3 +162,13 @@ export default { ...@@ -158,3 +162,13 @@ export default {
}, },
}; };
</script> </script>
<style lang="scss" scoped>
.task-center-list {
.refresh {
height: calc(100% - 60px);
overflow: scroll;
padding-bottom: env(safe-area-inset-bottom);
}
}
</style>
...@@ -88,7 +88,7 @@ export default { ...@@ -88,7 +88,7 @@ export default {
.special-task-list-page { .special-task-list-page {
background: #f2f3f7; background: #f2f3f7;
height: 100%; height: 100%;
overflow: auto; overflow: hidden;
box-sizing: border-box; box-sizing: border-box;
padding-bottom: env(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!