From 9bde1998a8a0bc6c1ab314f8cf27c10aef016689 Mon Sep 17 00:00:00 2001 From: songshankun <songshankun@foxmail.com> Date: 星期一, 30 十月 2023 20:30:09 +0800 Subject: [PATCH] feat: 通道展示组件添加查看更多逻辑;任务选中展示;添加加工信息组件 --- src/stores/tasks.ts | 100 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 97 insertions(+), 3 deletions(-) diff --git a/src/stores/tasks.ts b/src/stores/tasks.ts index 32c3a64..8f8599d 100644 --- a/src/stores/tasks.ts +++ b/src/stores/tasks.ts @@ -1,12 +1,106 @@ -import { ref } from 'vue' +import { computed, ref } from 'vue' import { defineStore } from 'pinia' -import type { Task } from '@/api/task' +import type { Task, TasksGroupByChannel, TasksResponse } from '@/api/task' +import type { TaskListParams } from '@/api' +import { getTaskList } from '@/api' + +export interface ChannelMoreBtnStatus { + /** true 浠诲姟鏈姞杞藉畬 false 鎵�鏈変换鍔″凡缁忓姞杞藉畬鎴�*/ + [channel: number]: boolean +} export const useTasksStore = defineStore('tasks', () => { + const channels = ref<TasksGroupByChannel>({}) + + const currentType = ref<1 | 2 | 3>(1) + + /** + * 鑾峰彇浠诲姟鏁版嵁 + * @param type 1鏈畬鎴�2浠婂ぉ鏈畬鎴�3宸插畬鎴� + */ + function getChannels(type: 1 | 2 | 3) { + currentType.value = type + const params: TaskListParams = { + type, + offset: 0, + limit: 3 + } + getTaskList(params) + .then((res) => { + channels.value = res.data + }) + .catch((err) => { + console.error(err) + channels.value = [] + }) + } + + function moreChannelTasksBtn(channelNumber: number) { + const taskLength = channels.value[channelNumber].Tasks?.length ?? 0 + const params: TaskListParams = { + type: currentType.value, + channel: channelNumber, + offset: taskLength, + limit: 10 + } + getTaskList(params) + .then((res) => { + const existTasks = channels.value![channelNumber].Tasks ?? [] + channels.value[channelNumber] = res.data[channelNumber] ?? {} + channels.value[channelNumber].Tasks = channels.value[channelNumber].Tasks ?? [] + channels.value[channelNumber].Tasks = [...existTasks, ...channels.value[channelNumber].Tasks] + }) + .catch((err) => { + console.error(err) + }) + } + + function foldChannelTasksBtn(channelNumber: number) { + const tasks = channels.value[channelNumber].Tasks ?? [] + channels.value[channelNumber].Tasks = tasks.slice(0, 3) + } + + const moreBtnStatus = computed(() => { + return Object.entries(channels.value).reduce((pre, currentValue) => { + const channelNumber = +currentValue[0] + const channelData = currentValue[1] as TasksResponse + pre[channelNumber] = channelData.TaskCount > (channelData.Tasks?.length ?? 0) + return pre + }, {} as ChannelMoreBtnStatus) + }) + /** 褰撳墠楂樹寒鐨勪换鍔� */ const activeTask = ref<Task>() function setActiveTask(task: Task) { activeTask.value = task } - return { activeTask, setActiveTask } + + const requestParamsMap = ref<{ + [channel: number]: TaskListParams + }>({}) + function getParamsByChannel(channel: number) { + return ( + requestParamsMap.value[channel] ?? { + type: 1, + offset: 0, + limit: 3 + } + ) + } + + function setParamsByChannel(channel: number, params: TaskListParams) { + requestParamsMap.value[channel] = params + } + return { + channels, + getChannels, + moreBtnStatus, + activeTask, + setActiveTask, + requestParamsMap, + getParamsByChannel, + setParamsByChannel, + moreChannelTasksBtn, + foldChannelTasksBtn + } }) -- Gitblit v1.8.0