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">
action-text="查看" <TaskCard v-for="(task, index) in list"
:card-config="cardConfig" :key="task.id || index"
:list="list" action-text="查看"
:status="getCardStatus" :card-config="cardConfig"
:title="getCardTitle" :status="getCardStatus"
@action="viewDetail" /> :task="task"
:title="getCardTitle"
@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" <div class="card-header">
:key="index" <span class="status-tag" :style="getStatusStyle()">
class="task-card"> {{ getStatusName() }}
<div class="card-header"> </span>
<span class="status-tag" :style="getStatusStyle(task)"> <span class="task-title">{{ getTitle() }}</span>
{{ getStatusName(task) }} </div>
</span>
<span class="task-title">{{ getTitle(task) }}</span>
</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>
</template>
</div>
<div v-if="actionText && isActionShow(task)" class="card-footer">
<div class="view-btn" @click="$emit('action', task)">
{{ actionText }}
</div> </div>
</template>
</div>
<div v-if="actionText && isActionShow()" class="card-footer">
<div class="view-btn" @click="$emit('action', task)">
{{ actionText }}
</div> </div>
</div> </div>
</div> </div>
...@@ -35,11 +31,11 @@ ...@@ -35,11 +31,11 @@
<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,118 +59,116 @@ export default { ...@@ -63,118 +59,116 @@ 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; margin-bottom: 12px;
margin-bottom: 12px;
.card-header {
display: flex;
align-items: center;
margin-bottom: 14px;
.status-tag {
font-size: 10px;
padding: 2px 6px;
border-radius: 4px;
margin-right: 8px;
flex-shrink: 0;
}
.task-title {
font-size: 14px;
font-weight: 600;
color: #000000e5;
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
.card-header { .card-body {
.info-row {
display: flex; display: flex;
align-items: center; align-items: flex-start;
margin-bottom: 14px; margin-bottom: 10px;
font-size: 12px;
color: #00000066;
.status-tag { &:last-child {
font-size: 10px; margin-bottom: 0;
padding: 2px 6px;
border-radius: 4px;
margin-right: 8px;
flex-shrink: 0;
} }
.task-title { .icon {
margin-top: 2px;
margin-right: 6px;
font-size: 14px; font-size: 14px;
font-weight: 600; color: #00000042;
color: #000000e5; }
.content-wrapper {
flex: 1; flex: 1;
min-width: 0;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
}
}
.card-body {
.info-row {
display: flex;
align-items: flex-start;
margin-bottom: 10px;
font-size: 12px;
color: #00000066;
&:last-child {
margin-bottom: 0;
}
.icon { .label,
margin-top: 2px; .value {
margin-right: 6px; display: inline;
font-size: 14px;
color: #00000042;
}
.content-wrapper {
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
.label,
.value {
display: inline;
}
} }
} }
} }
}
.card-footer { .card-footer {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
margin-top: 12px; margin-top: 12px;
.view-btn { .view-btn {
background: #f0f4ff; background: #f0f4ff;
color: #2c66f7; color: #2c66f7;
font-size: 12px; font-size: 12px;
padding: 6px 16px; padding: 6px 16px;
border-radius: 14px; border-radius: 14px;
}
} }
} }
} }
......
<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"
:action-visible="canViewDetail" :key="task.id || index"
:card-config="cardConfig" action-text="查看"
:list="list" :action-visible="canViewDetail"
:status="getCardStatus" :card-config="cardConfig"
:title="cardTitle" :status="getCardStatus"
@action="viewDetail" /> :task="task"
:title="cardTitle"
@action="viewDetail" />
</van-list> </van-list>
<van-empty v-if="!loading && !refreshing && list.length === 0" <van-empty v-if="!loading && !refreshing && list.length === 0"
description="暂无任务" description="暂无任务"
...@@ -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!