TaskSystem-admin/src/views/task/taskCalendar.vue

235 lines
6.2 KiB
Vue
Raw Normal View History

2023-08-08 12:03:03 +08:00
<template>
<div>
<el-card class="!border-none" v-loading="loading" shadow="never">
2023-08-11 18:23:36 +08:00
<el-button v-perms="['flow_type/add']" type="primary" @click="handleAdd">
2023-08-08 12:03:03 +08:00
<template #icon>
<icon name="el-icon-Plus" />
</template>
新增
2023-08-11 18:23:36 +08:00
</el-button>
2023-08-08 12:03:03 +08:00
<div class="mt-4">
<el-calendar v-model="dateValue">
<template #dateCell="{ data }">
<div style="width: 100%; height: 100%">
<p
:class="data.isSelected ? 'is-selected' : ''"
style="padding: 8px 8px 0 8px"
>
{{ data.day.split("-").slice(1).join("-") }}
<!-- {{ data.isSelected ? '✔️' : '' }} -->
</p>
2023-08-10 18:05:35 +08:00
<div>{{ dateNow(data.day) }}</div>
2023-08-08 12:03:03 +08:00
<div
class="task"
:class="{
fou: item.priority == 4,
tow: item.priority == 2,
the: item.priority == 3,
}"
@click="handleEdit(item)"
2023-08-08 20:54:28 +08:00
v-for="(item, index) in taskList"
2023-08-08 12:03:03 +08:00
:key="index"
>
{{ item.title }}
</div>
</div>
<!-- <div class="task" style="color: var(--el-color-primary);">完成BUG测试</div>
<div class="task" style="color: var(--el-color-danger);">完成BUG测试</div> -->
</template>
</el-calendar>
</div>
</el-card>
2023-08-09 12:03:55 +08:00
2023-08-08 12:03:03 +08:00
<edit-popup
ref="editRef"
:dict-data="dictData"
:dateValue="dateValue"
2023-08-10 16:41:57 +08:00
:detailsdata="detailsdata"
2023-08-08 12:03:03 +08:00
@success="loadTask"
@close="showEdit = false"
/>
2023-08-11 18:23:36 +08:00
<EditTowPopup
ref="editTowRef"
:dict-data="dictData"
:dateValue="dateValue"
:detailsdata="detailsdata"
@success="loadTask"
@close="showEditTow = false"
/>
2023-08-08 12:03:03 +08:00
</div>
</template>
<script lang="ts" setup name="task">
import { useDictData } from "@/hooks/useDictOptions";
import { apiTaskIndex } from "@/api/task";
import { timeFormat } from "@/utils/util";
import feedback from "@/utils/feedback";
// import { getRoutePath } from "router";
import EditPopup from "./edit.vue";
2023-08-11 18:23:36 +08:00
import EditTowPopup from "./editTow.vue";
2023-08-08 12:03:03 +08:00
import { reactive, watch } from "vue";
2023-08-10 18:05:35 +08:00
import { apiTaskList, apiTaskDetails } from "@/api/task";
2023-08-11 18:23:36 +08:00
import { apiTaskSchedulingPlanAdd } from "@/api/task_scheduling_plan";
2023-08-08 12:03:03 +08:00
const dateValue = ref(new Date());
2023-08-10 18:05:35 +08:00
const detailsdata = reactive({
create_time: "",
create_user_id: 0,
delete_time: "",
end_time: "",
extend: "",
id: "",
scheduling_id: "",
sn: "",
start_time: "",
status: "",
task_id: "",
task_info: {
admin_id: 0,
content: "",
create_time: "",
delete_time: "",
id: 0,
money: "",
status: 0,
title: "",
type: 0,
type_name: "",
update_time: "",
},
template_id: 0,
update_time: "",
});
watch(
() => dateValue,
async (newValue, oldValue) => {
2023-08-11 18:23:36 +08:00
const id = taskList.value.find(
(item) =>
item.start_time.split(" ")[0] == timeFormat(newValue.value.getTime())
)?.id;
if (id) {
const res = await apiTaskDetails({ id });
Object.keys(detailsdata).forEach((key) => {
res[key] ? (detailsdata[key] = res[key]) : null;
});
editRef.value?.open("add");
initShowDate(timeFormat(newValue.value.getTime()));
2023-08-10 18:05:35 +08:00
}
2023-08-08 12:03:03 +08:00
},
{ deep: true }
);
2023-08-08 20:54:28 +08:00
2023-08-08 12:03:03 +08:00
// 加载
const loading = ref(true);
const editRef = shallowRef<InstanceType<typeof EditPopup>>();
2023-08-11 18:23:36 +08:00
const editTowRef = shallowRef<InstanceType<typeof EditPopup>>();
2023-08-08 12:03:03 +08:00
// 是否显示编辑框
const showEdit = ref(false);
2023-08-11 18:23:36 +08:00
const showEditTow = ref(false);
2023-08-08 12:03:03 +08:00
// 查询条件
const queryParams = reactive({
start_time: "",
end_time: "",
page_no: 1,
pageSize: 150,
});
const taskList = ref<any>([]);
// 查询
const loadTask = async () => {
// let res: any = await apiTaskIndex(queryParams);
// taskList.value = res.lists;
2023-08-10 18:05:35 +08:00
apiTaskList(queryParams).then((res) => {
taskList.value = res.lists;
});
2023-08-08 12:03:03 +08:00
loading.value = false;
};
const start_date = ref("");
const end_date = ref("");
// 计算当前显示的第一天和最后一天
const initShowDate = (dateStr = "") => {
const currentDate = dateStr ? new Date(dateStr) : new Date();
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth();
const lastDay = new Date(currentYear, currentMonth + 1, 0).getDay(); //获取第一天星期
const startDay = new Date(currentYear, currentMonth, 1).getDay(); //获取最后一天星期
// console.log(new Date(currentYear, currentMonth, 1-startDay).getDate());
// console.log(new Date(currentYear, currentMonth + 1, 6-lastDay).getDate());
start_date.value = timeFormat(
new Date(currentYear, currentMonth, 1 - startDay).getTime()
); //获取第一天时间
end_date.value = timeFormat(
new Date(currentYear, currentMonth + 1, 6 - lastDay).getTime()
); //获取最后一天时间
if (queryParams.start_time != start_date.value) {
queryParams.start_time = start_date.value;
queryParams.end_time = end_date.value;
loading.value = true;
loadTask();
}
};
initShowDate();
2023-08-10 18:05:35 +08:00
const dateNow = (day) => {
return taskList.value.find((item) => item.start_time.split(" ")[0] == day)
?.template_name;
};
2023-08-08 20:54:28 +08:00
2023-08-08 12:03:03 +08:00
// 获取字典数据
2023-08-08 15:13:07 +08:00
// const { dictData } = useDictData("");
2023-08-08 12:03:03 +08:00
// 添加
const handleAdd = async () => {
2023-08-11 18:23:36 +08:00
showEditTow.value = true;
2023-08-08 12:03:03 +08:00
await nextTick();
2023-08-11 18:23:36 +08:00
editTowRef.value?.open("add");
2023-08-08 12:03:03 +08:00
};
// 编辑
2023-08-09 12:03:55 +08:00
// const handleEdit = async (data: any) => {
// showEdit.value = true;
// await nextTick();
// editRef.value?.open("edit");
// editRef.value?.setFormData(data);
// };
2023-08-08 12:03:03 +08:00
// 删除
// const handleDelete = async (id: number | any[]) => {
// await feedback.confirm("确定要删除?");
// await apiFlowTypeDelete({ id });
// getLists();
// };
// getLists();
</script>
<style lang="scss">
.is-selected {
color: #1989fa;
}
.el-calendar-table .el-calendar-day {
height: auto;
min-height: 6.2rem;
padding: 0;
}
.task {
font-size: 0.8rem;
color: #f7ba2a;
white-space: nowrap; /* 设置文本不换行 */
overflow: hidden; /* 隐藏溢出的部分 */
text-overflow: ellipsis; /* 在溢出的部分显示省略号 */
}
.the {
color: #ff5100;
}
.tow {
color: #f38200;
}
.fou {
color: red;
}
</style>