Browse Source

feat: 时间轴定期任务

text-draggable
xuesinan 4 years ago
parent
commit
352056f3ba
  1. 1
      .eslintrc.js
  2. 7
      src/components/tall/center/Global.vue
  3. 10
      src/components/tall/center/Index.vue
  4. 163
      src/components/tall/center/RegularTask.vue
  5. 10
      src/store/tall/task/index.js
  6. 5
      src/utils/task.js

1
.eslintrc.js

@ -10,6 +10,7 @@ module.exports = {
},
plugins: ['vue'],
rules: {
'no-loop-func': 'off',
'import/no-unresolved': 0,
'import/extensions': 0,
'import/no-extraneous-dependencies': 0,

7
src/components/tall/center/Global.vue

@ -6,7 +6,7 @@
</div>
<template v-if="globals.length > 0">
<div class="global-task cursor-pointer" v-for="(item, index) in globals" :key="index" @click="toDetail(item)">
<div class="global-task cursor-pointer" v-for="(item, index) in globals" :key="index">
<template v-if="item.plugins && item.plugins.length">
<div v-for="(pluginArr, i) in item.plugins" :key="i">
<div class="pb-3" v-if="pluginArr.length">
@ -84,11 +84,6 @@ async function getGlobalData(id) {
}
}
function toDetail(item) {
// store.commit('task/setTaskDetail', item);
console.log(item);
}
function toWorkbench() {}
</script>

10
src/components/tall/center/Index.vue

@ -71,7 +71,7 @@ import { ReloadOutlined, MoreOutlined } from '@ant-design/icons-vue';
const store = useStore();
const project = computed(() => store.state.projects.project); //
const sessionTasks = sessionStorage.getItem('regularTasks'); //
// const sessionTasks = sessionStorage.getItem('regularTasks'); //
const globals = computed(() => store.getters['task/globals']); //
const globalRef = ref(null);
@ -86,10 +86,10 @@ watch(globals, () => {
console.log('globalHeight', globalHeight.value, clientHeight.value, tasksHeight.value);
});
if (sessionTasks) {
const arr = JSON.parse(sessionTasks);
store.commit('task/setRegularTasks', arr);
}
// if (sessionTasks) {
// const arr = JSON.parse(sessionTasks);
// store.commit('task/setRegularTasks', arr);
// }
// watch(project, async () => {
// if (project.value.id) {

163
src/components/tall/center/RegularTask.vue

@ -4,29 +4,41 @@
<div class="task-time flex items-center justify-between">
<div class="flex items-center">
<PlayCircleOutlined style="font-size: 23px; color: #999999" />
<span>{{ dayjs(item.planStart).format('M月D日 HH:mm') }}</span>
<span v-if="item.process === 4">{{ dayjs(+item.planStart).format('M月D日') }}</span>
<span v-else>{{ dayjs(+item.planStart).format('M月D日 HH:mm') }}</span>
</div>
<div class="task-action"></div>
</div>
<div class="task-info">
<div>
<div class="task-card">
<div class="task-name cursor-pointer" @click="toDetail(item)">
<template v-for="v in item.plugins">
<template v-if="v[0].pluginId == 1">{{ item.name }}</template>
<div class="task-card-null" v-if="item.process === 4"></div>
<div class="task-card" v-else>
<div class="task-name cursor-pointer">
<template v-if="item.plugins && item.plugins.length">
<div v-for="(pluginArr, i) in item.plugins" :key="i">
<div :class="{ 'pt-3': i > 0 }" v-if="pluginArr.length">
<Plugin
class="task-card-plugin"
v-for="plugin in pluginArr"
:key="plugin.pluginTaskId"
:plugin-id="plugin.pluginId"
:plugin-task-id="plugin.pluginTaskId"
:business-plugin-id="plugin.businessPluginId"
:plugin-info="plugin"
:param="plugin.param"
:style-type="plugin.styleType || 0"
:task="item"
/>
</div>
</div>
</template>
</div>
<div class="task-con" v-if="item.sonList && item.sonList.length > 0">
<div v-for="(val, key) in item.sonList" :key="key">
<!-- <a-checkbox>{{ val.name }}</a-checkbox> -->
<span class="son-task-name cursor-pointer" @click.stop="toSonDetail(item, val.detailId)">{{ val.name }}</span>
<div v-else class="">
<Plugin plugin-id="1" :task="item" />
</div>
</div>
<!-- <div class="open-icon" v-if="item.sonList" @click="openCard">
<img />
</div> -->
</div>
</div>
</div>
@ -40,6 +52,7 @@ import { useStore } from 'vuex';
import dayjs from 'dayjs';
import uTask from 'utils/task';
import { PlayCircleOutlined } from '@ant-design/icons-vue';
import { flatten } from 'lodash';
import { getRegularTask } from 'apis';
import { message } from 'ant-design-vue';
@ -58,7 +71,7 @@ const timeGranularity = computed(() => store.getters['task/timeGranularity']); /
const timeLineType = computed(() => store.state.task.timeLineType); //
const downNextPage = computed(() => store.state.task.downNextPage); //
const upNextPage = computed(() => store.state.task.upNextPage); //
setNextPlaceholderTasks(); //
// setNextPlaceholderTasks(); //
onMounted(() => {
window.addEventListener('scroll', handleScroll, true);
@ -85,12 +98,18 @@ function handleScroll(e) {
//
if (scrollTop + windowHeight === scrollHeight) {
//
setNextPlaceholderTasks(); //
console.warn('滚动到底部: ');
// setNextPlaceholderTasks(); //
const params = { pageNum: downNextPage.value, queryType: 1, triggerType: 0 };
dataRender(params);
}
//
if (scrollTop === 0) {
setPrevPlaceholderTasks(); //
console.warn('滚动到顶部: ');
// setPrevPlaceholderTasks(); //
const params = { pageNum: upNextPage.value, queryType: 0, triggerType: 0 };
dataRender(params);
}
}
@ -108,7 +127,7 @@ async function getTasks(query) {
const { url } = store.state.projects.project;
try {
const data = await getRegularTask(params, url);
store.commit('task/setRegularTasks', data);
// store.commit('task/setRegularTasks', data);
if (params.param.queryType === 0) {
store.commit('task/setUpRealTasks', data.list);
@ -136,7 +155,7 @@ function generateGetTaskParam(query) {
timeUnit: query.timeUnit || timeUnit.value,
queryType: query.queryType === 0 ? 0 : 1,
pageNum: query.pageNum || 1,
pageSize: query.pageSize || 10,
pageSize: query.pageSize || uTask.pageTaskCount,
taskId: query.taskId || currLocationTaskId.value,
businessCode: query.businessCode || businessCode.value,
triggerType: query.triggerType || 1,
@ -153,7 +172,6 @@ async function renderScaleTask(query) {
const params = generateGetTaskParam(query);
//
const centerData = (await showTaskTime(params, realTasks.value, tasks.value)) || [];
console.log('centerData', centerData);
await handleTasksData(params, centerData, realTasks.value);
}
@ -188,11 +206,11 @@ async function showTaskTime(params, reals, showTasks) {
});
const lastId = showTasks[lastDetailIndex].id; // id
realTasks.forEach((item, index) => {
reals.forEach((item, index) => {
if (params.queryType === 1 && item.id === lastId) {
centerData = realTasks.slice(index + 1, index + 1 + params.pageSize);
centerData = reals.slice(index + 1, index + 1 + params.pageSize);
} else if (params.queryType === 0 && item.id === firstId) {
centerData = index >= params.pageSize ? realTasks.slice(index - params.pageSize, index) : realTasks.slice(0, index);
centerData = index >= params.pageSize ? reals.slice(index - params.pageSize, index) : reals.slice(0, index);
}
});
}
@ -202,11 +220,11 @@ async function showTaskTime(params, reals, showTasks) {
//
async function handleTasksData(params, centerData) {
const showTasks = tasks.value;
let showTasks = tasks.value;
//
const firstTime = showTasks.length > 0 ? showTasks[0].planStart : new Date().getTime();
const upTargetTime = dayjs(+firstTime).subtract(params.pageSize, timeGranularity.value); //
//
// +1 ||
const lastTime =
showTasks.length > 0 ? dayjs(+showTasks[showTasks.length - 1].planStart).add(1, timeGranularity.value) : new Date().getTime();
const downTargetTime = dayjs(+lastTime).add(params.pageSize - 1, timeGranularity.value); //
@ -215,13 +233,17 @@ async function handleTasksData(params, centerData) {
if (centerData.length) {
const arr = [];
centerData.forEach(v => {
// const centerTime = ''; // +/-15
let isExceed = false; // 15
let isLimit = false;
let isExceed = false; // 10
if (params.queryType) {
isExceed = dayjs(+downTargetTime).isAfter(+v.planStart, timeGranularity.value);
isLimit =
dayjs(+lastTime).isBefore(+v.planStart, timeGranularity.value) || dayjs(+lastTime).isSame(+v.planStart, timeGranularity.value);
isExceed = isLimit && dayjs(+downTargetTime).isAfter(+v.planStart, timeGranularity.value);
} else {
isExceed = dayjs(+upTargetTime).isBefore(+v.planStart, timeGranularity.value);
isLimit =
dayjs(+firstTime).isAfter(+v.planStart, timeGranularity.value) || dayjs(+firstTime).isSame(+v.planStart, timeGranularity.value);
isExceed = isLimit && dayjs(+upTargetTime).isBefore(+v.planStart, timeGranularity.value);
}
if (isExceed) {
@ -233,39 +255,61 @@ async function handleTasksData(params, centerData) {
if (arr.length === centerData.length && centerData.length < params.pageSize && nextPage > 0) {
getTasks({ pageNum: nextPage, queryType: params.queryType });
} else {
/**
* 符合条件的数据 < centerData的数据
* 或者
* centerData的数据全部符合条件但是 < 10而且没有下一页不能向下查
* 数据需要补齐10天的刻度
* 所以循环长度为params.pageSize
*/
let newArr = [];
let breakTime = ''; //
let continueTime = ''; //
//
const currTime = params.queryType === 0 ? upTargetTime : lastTime;
// < centerData
//
// centerData < 15
// 15
// params.pageSize
// centerData = 15
//
//
// =
let tempLen = -1; //
let currTime = params.queryType === 0 ? upTargetTime : lastTime; //
// centerData = 10 =
if (arr.length === centerData.length && centerData.length === params.pageSize) {
if (params.queryType === 0) {
continueTime = arr[0].planStart;
} else {
breakTime = arr[arr.length - 1].planStart;
}
tempLen = params.pageSize;
currTime = arr[0].planStart;
}
console.log(currTime, breakTime, continueTime);
//
const sameTime = params.queryType === 0 ? firstTime : dayjs(+lastTime).subtract(1, timeGranularity.value);
//
const firstArr = arr.filter(item => dayjs(+item.planStart).isSame(+sameTime, timeGranularity.value));
console.log(sameTime, arr, newArr);
if (firstArr.length && params.queryType === 1) {
newArr = [...newArr, ...firstArr];
//
const repeatArr = showTasks.filter(item => dayjs(+item.planStart).isSame(+sameTime, timeGranularity.value));
//
if (repeatArr.length === 1 && !repeatArr[0].detailId) {
showTasks = params.queryType === 0 ? showTasks.slice(1) : showTasks.slice(0, showTasks.length - 2);
}
if (firstArr.length) {
newArr = params.queryType === 0 ? [...firstArr, ...newArr] : [...newArr, ...firstArr];
}
for (let i = 0; i < params.pageSize; i++) {
const termArr = arr.filter(item => dayjs(+item.planStart).isSame(+currTime, timeGranularity.value));
if (termArr.length === 0) {
let newTasks = [];
newTasks = uTask.setPlaceholderTasks(+currTime, false, timeGranularity.value, 1);
newArr = [...newArr, ...newTasks];
} else {
newArr = [...newArr, ...termArr];
if (tempLen) tempLen--;
}
if (tempLen === 0) break;
// <params.pageSize
currTime = dayjs(+currTime).add(1, timeGranularity.value);
}
showTasks = params.queryType === 0 ? [...newArr, ...showTasks] : [...showTasks, ...newArr];
showTasks = flatten(showTasks); // 1
store.commit('task/clearTasks');
params.queryType === 0 ? store.commit('task/setUpTasks', showTasks) : store.commit('task/setDownTasks', showTasks);
}
} else {
params.queryType === 0 ? setPrevPlaceholderTasks(params) : setNextPlaceholderTasks(params);
@ -307,11 +351,6 @@ function setNextPlaceholderTasks() {
// store.commit('task/setCurrDownTimeNode', startTime);
store.commit('task/setDownTasks', initData);
}
function toDetail(item) {
console.log(item);
// store.commit('task/setTaskDetail', item);
}
</script>
<style scoped>
@ -346,9 +385,13 @@ function toDetail(item) {
border-left: 1px solid #d2d2d2;
}
.task-info .task-card {
padding: 16px;
border-radius: 8px;
.task-card-null {
height: 20px;
}
.task-card-plugin {
padding: 12px;
border-radius: 10px;
-moz-box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.12);
-webkit-box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.12);
box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.12);

10
src/store/tall/task/index.js

@ -27,7 +27,7 @@ export default {
newProjectInfo: {},
showScrollTo: false, // 是否可以设置时间轴自动滚动的位置
regularTasks: [], // 定期任务
// regularTasks: [], // 定期任务
realTasks: [], // 真实定期任务
currLocationTaskId: '', // 前需要定位到的任务id
businessCode: '', // 当前打开的项目的所属服务
@ -300,10 +300,10 @@ export default {
* @param {object} state
* @param {array} tasks 服务端查询到的定期任务书籍
*/
setRegularTasks(state, tasks) {
state.regularTasks = tasks || [];
// sessionStorage.setItem('regularTasks', JSON.stringify(tasks));
},
// setRegularTasks(state, tasks) {
// state.regularTasks = tasks || [];
// // sessionStorage.setItem('regularTasks', JSON.stringify(tasks));
// },
/**
* 真实定期任务

5
src/utils/task.js

@ -1,5 +1,7 @@
import dayjs from 'dayjs';
const pageTaskCount = 15;
/**
* 设置时间轴空数据
* @param {number} startTime
@ -9,7 +11,7 @@ import dayjs from 'dayjs';
*/
const setPlaceholderTasks = (startTime, isUp, timeGranularity, pageCount) => {
const result = [];
pageCount = pageCount || 10;
pageCount = pageCount || pageTaskCount;
for (let i = 0; i < pageCount; i++) {
const delta = isUp ? `-${i + 1}` - 0 : i;
@ -59,4 +61,5 @@ const computeFillPlaceholderTaskCount = obj => {
export default {
setPlaceholderTasks,
computeFillPlaceholderTaskCount,
pageTaskCount,
};

Loading…
Cancel
Save