Commit 1fa87131 by chenwq

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

1 parent a3d557a6
<template>
<div class="strategy-task-list">
<TaskCardList v-if="list.length"
action-text="查看"
:card-config="cardConfig"
:list="list"
:status="getCardStatus"
:title="getCardTitle"
@action="viewDetail" />
<template v-if="list.length">
<TaskCard v-for="(task, index) in list"
:key="task.id || index"
action-text="查看"
:card-config="cardConfig"
:status="getCardStatus"
:task="task"
:title="getCardTitle"
@action="viewDetail" />
</template>
<van-empty v-else description="暂无任务" />
</div>
</template>
<script>
import constantData from "../constantData.js";
import TaskCardList from "./TaskCardList.vue";
import TaskCard from "./TaskCard.vue";
export default {
name: "StrategyTaskList",
components: {
TaskCardList,
TaskCard,
},
props: {
list: {
......@@ -45,3 +48,11 @@ export default {
},
};
</script>
<style lang="scss" scoped>
.strategy-task-list {
height: calc(100% - 60px);
overflow: scroll;
padding-bottom: env(safe-area-inset-bottom);
}
</style>
<template>
<div class="task-card-list">
<div v-for="(task, index) in list"
:key="index"
class="task-card">
<div class="card-header">
<span class="status-tag" :style="getStatusStyle(task)">
{{ getStatusName(task) }}
</span>
<span class="task-title">{{ getTitle(task) }}</span>
</div>
<div class="task-card">
<div class="card-header">
<span class="status-tag" :style="getStatusStyle()">
{{ getStatusName() }}
</span>
<span class="task-title">{{ getTitle() }}</span>
</div>
<div class="card-body">
<template v-for="(item, itemIndex) in cardConfig">
<div v-if="isFieldShow(task, item)"
:key="item.key || itemIndex"
class="info-row">
<van-icon class="icon" :name="item.icon" />
<div class="content-wrapper">
<span class="label">{{ getFieldLabel(task, item) }}</span>
<span class="value">{{ getFieldValue(task, item) }}</span>
</div>
<div class="card-body">
<template v-for="(item, itemIndex) in cardConfig">
<div v-if="isFieldShow(item)"
:key="item.key || itemIndex"
class="info-row">
<van-icon class="icon" :name="item.icon" />
<div class="content-wrapper">
<span class="label">{{ getFieldLabel(item) }}</span>
<span class="value">{{ getFieldValue(item) }}</span>
</div>
</template>
</div>
<div v-if="actionText && isActionShow(task)" class="card-footer">
<div class="view-btn" @click="$emit('action', task)">
{{ actionText }}
</div>
</template>
</div>
<div v-if="actionText && isActionShow()" class="card-footer">
<div class="view-btn" @click="$emit('action', task)">
{{ actionText }}
</div>
</div>
</div>
......@@ -35,11 +31,11 @@
<script>
export default {
name: "TaskCardList",
name: "TaskCard",
props: {
list: {
type: Array,
default: () => [],
task: {
type: Object,
default: () => ({}),
},
cardConfig: {
type: Array,
......@@ -63,118 +59,116 @@ export default {
},
},
methods: {
getTitle(task) {
return typeof this.title === "function" ? this.title(task) : this.title;
getTitle() {
return typeof this.title === "function" ? this.title(this.task) : this.title;
},
getStatus(task) {
return this.status ? this.status(task) : {};
getStatus() {
return this.status ? this.status(this.task) : {};
},
getStatusName(task) {
return this.getStatus(task).name || "-";
getStatusName() {
return this.getStatus().name || "-";
},
getStatusStyle(task) {
const status = this.getStatus(task);
getStatusStyle() {
const status = this.getStatus();
return {
color: status.color || "#2c66f7",
background: status.background || "#2c66f71a",
};
},
isFieldShow(task, item) {
return item.isShow ? item.isShow(task) : true;
isFieldShow(item) {
return item.isShow ? item.isShow(this.task) : true;
},
getFieldLabel(task, item) {
return item.getLabel ? item.getLabel(task) : item.label;
getFieldLabel(item) {
return item.getLabel ? item.getLabel(this.task) : item.label;
},
getFieldValue(task, item) {
getFieldValue(item) {
if (item.getValue)
return item.getValue(task) || "-";
return task[item.key] || "-";
return item.getValue(this.task) || "-";
return this.task[item.key] || "-";
},
isActionShow(task) {
return this.actionVisible ? this.actionVisible(task) : true;
isActionShow() {
return this.actionVisible ? this.actionVisible(this.task) : true;
},
},
};
</script>
<style lang="scss" scoped>
.task-card-list {
.task-card {
background: #ffffff;
border-radius: 8px;
padding: 16px;
margin-bottom: 12px;
.task-card {
background: #ffffff;
border-radius: 8px;
padding: 16px;
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;
align-items: center;
margin-bottom: 14px;
align-items: flex-start;
margin-bottom: 10px;
font-size: 12px;
color: #00000066;
.status-tag {
font-size: 10px;
padding: 2px 6px;
border-radius: 4px;
margin-right: 8px;
flex-shrink: 0;
&:last-child {
margin-bottom: 0;
}
.task-title {
.icon {
margin-top: 2px;
margin-right: 6px;
font-size: 14px;
font-weight: 600;
color: #000000e5;
color: #00000042;
}
.content-wrapper {
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
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 {
margin-top: 2px;
margin-right: 6px;
font-size: 14px;
color: #00000042;
}
.content-wrapper {
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
.label,
.value {
display: inline;
}
.label,
.value {
display: inline;
}
}
}
}
.card-footer {
display: flex;
justify-content: flex-end;
margin-top: 12px;
.card-footer {
display: flex;
justify-content: flex-end;
margin-top: 12px;
.view-btn {
background: #f0f4ff;
color: #2c66f7;
font-size: 12px;
padding: 6px 16px;
border-radius: 14px;
}
.view-btn {
background: #f0f4ff;
color: #2c66f7;
font-size: 12px;
padding: 6px 16px;
border-radius: 14px;
}
}
}
......
<template>
<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"
v-model="loading"
finished-text="到底了"
:finished="finished"
@load="onLoadMore">
<TaskCardList action-text="查看"
:action-visible="canViewDetail"
:card-config="cardConfig"
:list="list"
:status="getCardStatus"
:title="cardTitle"
@action="viewDetail" />
<TaskCard v-for="(task, index) in list"
:key="task.id || index"
action-text="查看"
:action-visible="canViewDetail"
:card-config="cardConfig"
:status="getCardStatus"
:task="task"
:title="cardTitle"
@action="viewDetail" />
</van-list>
<van-empty v-if="!loading && !refreshing && list.length === 0"
description="暂无任务"
......@@ -26,7 +30,7 @@ import dayjs from "dayjs";
import api from "@/api/teamWork";
import util from "@/utils/util";
import constantData from "../constantData.js";
import TaskCardList from "./TaskCardList.vue";
import TaskCard from "./TaskCard.vue";
const TASK_CENTER_CARD_TITLE = "专项带教";
......@@ -54,7 +58,7 @@ const TASK_CENTER_CARD_CONFIG = [
export default {
name: "TaskCenterList",
components: {
TaskCardList,
TaskCard,
},
props: {
startDate: {
......@@ -158,3 +162,13 @@ export default {
},
};
</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 {
.special-task-list-page {
background: #f2f3f7;
height: 100%;
overflow: auto;
overflow: hidden;
box-sizing: border-box;
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!