Commit 8c36e012 by chenwq

feat(任务管理): 添加任务页面及相关API,重构路由配置

1 parent 61e124af
import api from "./request";
export default {
getApprovalPage(data) {
return api.post("dj.api.supervisor.mini.approval.page", data, "supervisorUrl");
},
};
...@@ -9,7 +9,7 @@ export const mineRoutes = [ ...@@ -9,7 +9,7 @@ export const mineRoutes = [
{ {
path: "tasks", path: "tasks",
name: "mine/tasks", name: "mine/tasks",
component: () => import("@/views/mine/mine/tasks.vue"), component: () => import("@/views/mine/view/tasks.vue"),
meta: { meta: {
title: "我的任务", title: "我的任务",
showTabBar: true, showTabBar: true,
......
export const BASE_IMG_URL = "https://img02.glsx.com.cn/weapp/resource/supervise-wecom/";
export default {
BASE_IMG_URL,
};
<template>
<div class="page-container">
<van-empty description="我的任务开发中..." />
</div>
</template>
<script>
export default {
name: "MineTasks",
};
</script>
<style lang="scss" scoped>
.page-container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f2f3f7;
box-sizing: border-box;
padding-bottom: calc(50px + env(safe-area-inset-bottom));
}
</style>
<template>
<div class="tasks-page">
<div class="bg"></div>
<div class="container">
<div class="user-card">
<img class="avatar" :src="avatarUrl" />
<div class="user-name text-hide">
{{ userInfo?.phone || '' }}
</div>
</div>
<div class="count">
共{{ total || 0 }}条任务
</div>
<div class="content-box">
<van-pull-refresh v-model="refreshing"
class="refresh"
@refresh="onRefresh">
<van-list v-if="list.length"
v-model="loading"
class="list"
finished-text="到底了~"
:finished="finished"
@load="onLoadMore">
<div v-for="(item, index) in list"
:key="getItemKey(item, index)"
class="task-card">
<div class="card-header">
<span class="status-tag" :class="getStatusClass(item)">
{{ getStatusText(item) }}
</span>
<span class="task-name text-hide">{{ getTaskName(item) }}</span>
</div>
<div class="time-row">
<van-icon name="clock" />
<span>完成时间:</span>
<span>{{ getFinishTime(item) }}</span>
</div>
<div class="card-footer">
<button class="action-btn"
type="button"
@click="handleTask(item)">
{{ getActionText(item) }}
</button>
</div>
</div>
</van-list>
<van-empty v-if="!list.length && !loading && !refreshing"
description="暂无任务"
image-size="100"
:image="`${IMG_URL}icon-empty.png`" />
</van-pull-refresh>
</div>
</div>
</div>
</template>
<script>
import api from "@/api/mine";
import util from "@/utils/util";
import constantData from "../constant/constantData.js";
export default {
name: "MineTasks",
data() {
return {
IMG_URL: constantData.BASE_IMG_URL,
avatarUrl: constantData.BASE_IMG_URL + "icon-avatar.png",
userInfo: {},
list: [],
total: 0,
pageNum: 1,
loading: false,
refreshing: false,
finished: false,
};
},
created() {
this.userInfo = util.getLocalStorage("ww_userInfo") || {};
},
methods: {
onRefresh() {
this.finished = false;
this.pageNum = 1;
this.list = [];
this.getList();
},
onLoadMore() {
if (this.finished)
return;
this.getList();
},
getList() {
this.loading = true;
const params = { pageNum: this.pageNum, pageSize: 10, phone: this.userInfo?.phone || "" };
api.getApprovalPage(params).then((res) => {
console.log("getList res:", res);
const rows = res.list || [];
const total = res.total || rows.length;
this.list = this.pageNum === 1 ? rows : this.list.concat(rows);
this.total = total;
this.finished = this.list.length >= total || rows.length === 0;
this.pageNum += 1;
}).catch(() => {
this.finished = true;
}).finally(() => {
this.loading = false;
this.refreshing = false;
});
},
// getRows(res) {
// const data = res?.data || res || {};
// const pageData = data.page || data.result || data;
// return pageData.records || pageData.list || pageData.rows || data.records || data.list || [];
// },
// getTotal(res, rows) {
// const data = res?.data || res || {};
// const pageData = data.page || data.result || data;
// return Number(pageData.total || data.total || rows.length || 0);
// },
getItemKey(item, index) {
return item.id || item.approvalId || item.taskId || index;
},
getTaskName(item) {
return item.approvalName || item.taskName || item.title || item.name || "专项带教审批";
},
getFinishTime(item) {
return item.finishTime || item.completedTime || item.completeTime || item.approvalTime || "-";
},
isDone(item) {
const status = item.status ?? item.approvalStatus ?? item.taskStatus ?? item.state;
const text = `${status || ""}${item.statusName || ""}${item.approvalStatusName || ""}`;
return item.completed === true || item.finished === true || ["1", "2", "done", "completed"].includes(String(status).toLowerCase()) || /已完成|完成|已审批/.test(text);
},
getStatusText(item) {
return item.statusName || item.approvalStatusName || (this.isDone(item) ? "已完成" : "待完成");
},
getStatusClass(item) {
return this.isDone(item) ? "done" : "pending";
},
getActionText(item) {
return this.isDone(item) ? "查看" : "去审批";
},
handleTask(item) {
const url = item.approvalUrl || item.detailUrl || item.pageUrl || item.url || item.h5Url;
if (!url)
return;
if (/^https?:\/\//.test(url)) {
window.location.href = url;
return;
}
this.$router.push(url);
},
},
};
</script>
<style lang="scss" scoped>
.tasks-page {
height: 100%;
position: relative;
overflow: hidden;
box-sizing: border-box;
}
.bg {
width: 100%;
height: 240px;
background: url("https://img02.glsx.com.cn/weapp/resource/supervise-wecom/page-bg.png") no-repeat;
background-size: 100% 240px;
position: absolute;
left: 0;
top: 0;
z-index: 0;
}
.container {
position: relative;
z-index: 1;
height: 100%;
box-sizing: border-box;
margin-top: 51px;
background: #f2f3f7;
border-radius: 24px 24px 0 0;
}
.user-card {
height: 56px;
display: flex;
align-items: center;
position: relative;
.avatar {
width: 56px;
height: 56px;
position: absolute;
left: 24px;
top: -15px;
}
.user-name {
margin-left: 92px;
font-size: 20px;
color: #000000e5;
}
}
.count {
height: 28px;
padding: 0 12px;
font-size: 12px;
color: #00000066;
display: flex;
align-items: center;
}
.content-box {
height: calc(100% - 108px);
box-sizing: border-box;
padding: 0 6px;
overflow: hidden;
.refresh {
height: 100%;
overflow: auto;
}
}
.list {
width: 100%;
}
.task-card {
background: #ffffff;
border-radius: 8px;
padding: 12px;
margin-bottom: 8px;
min-height: 86px;
box-sizing: border-box;
.card-header {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.status-tag {
flex-shrink: 0;
font-size: 10px;
line-height: 16px;
padding: 0 6px;
border-radius: 4px;
margin-right: 8px;
&.pending {
color: #2c66f7;
background: #f0f4ff;
}
&.done {
color: #15c875;
background: #ecfff5;
}
}
.task-name {
flex: 1;
min-width: 0;
font-size: 14px;
font-weight: 600;
color: #000000e5;
}
.time-row {
display: flex;
align-items: center;
font-size: 12px;
color: #00000066;
.van-icon {
margin-right: 5px;
font-size: 13px;
color: #00000042;
}
}
.card-footer {
display: flex;
justify-content: flex-end;
margin-top: 12px;
}
.action-btn {
min-width: 58px;
height: 24px;
padding: 0 14px;
border: 0;
border-radius: 12px;
background: #f0f4ff;
color: #2c66f7;
font-size: 12px;
font-weight: 600;
line-height: 24px;
}
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!