Browse Source

fix: 1.时间轴数据渲染 2.时间基准线

develop
song 4 years ago
parent
commit
d643af2cfa
  1. 79
      CHANGELOG.md
  2. 9
      src/components/Roles/Roles.vue
  3. 144
      src/components/TimeLine/TimeLine.vue
  4. 3
      src/components/TimeLine/component/TimeBox.vue
  5. 44
      src/mixins/timeline.js
  6. 144
      src/pages/project/project.vue
  7. 16
      src/store/task/actions.js
  8. 149
      src/store/task/mutations.js
  9. 1
      src/store/task/state.js
  10. 12
      src/utils/time.js

79
CHANGELOG.md

@ -1,4 +1,4 @@
# 0.1.0 (2021-08-13) # 0.1.0 (2021-08-17)
### 🌟 新功能 ### 🌟 新功能
范围|描述|commitId 范围|描述|commitId
@ -53,26 +53,6 @@
### 🎨 代码样式 ### 🎨 代码样式
范围|描述|commitId 范围|描述|commitId
--|--|-- --|--|--
- | calendar注释 | a2ec112
- | 代码审查 | d75134c
- | 代码格式细节调整 | cb2532b
- | 任务快捷方式图标增加 | 4aba872
- | 修改角色样式 | 73e268e
- | 删除calendar中多余的console | e339eec
- | 删除console.log | 5064a38
- | 删除index中没用的alert代码 | 9c9eec7
- | 删除mock,console;upload添加loading | 99d42e2
- | 删除多余字段 | 5ae3973
- | 删除插件携带的多余文件 | 0f392bb
- | 删除没用代码 | 34b20e1
- | 图标修改 | 54bca09
- | 无基本变化 | 21ac4bb
- | 日常任务修改 | dfa7ee2
- | 更新代码 | 8c27e68
- | 更新代码 | 1f40a76
- | 格式细节调整 | b907a03
- | 添加插件数据 | 2f11b42
- | 组件新建 | 89c0035
- | calendar注释 | [a2ec112](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/a2ec112) - | calendar注释 | [a2ec112](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/a2ec112)
- | 代码审查 | [d75134c](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/d75134c) - | 代码审查 | [d75134c](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/d75134c)
- | 代码格式细节调整 | [cb2532b](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/cb2532b) - | 代码格式细节调整 | [cb2532b](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/cb2532b)
@ -93,52 +73,12 @@
- | 格式细节调整 | [b907a03](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/b907a03) - | 格式细节调整 | [b907a03](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/b907a03)
- | 添加插件数据 | [2f11b42](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/2f11b42) - | 添加插件数据 | [2f11b42](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/2f11b42)
- | 组件新建 | [89c0035](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/89c0035) - | 组件新建 | [89c0035](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/89c0035)
- | 细节调整 | [2cfc09a](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/2cfc09a)
### 🐛 Bug 修复 ### 🐛 Bug 修复
范围|描述|commitId 范围|描述|commitId
--|--|-- --|--|--
ID1000343 | 解决向下预加载查询参数时间没+1颗粒度;以及滚动加载颗粒度写死的问题 | 940603a, closes #ID1000343
plugin | 插件解析机制完善 | 0f5a27d
project title | 项目标题修改; 切换角色移除script | 5c20017
roles | 修复默认显示不是我的角色的问题 | b69f94f
role | 切换角色的逻辑修正完善 | 4ae534f
task任务逻辑完善 | 减少初始global及regular的不必要请求 | bd4bd38
- | title.vue根据页面栈显示返回按钮;标题文本超出显示... | 0cbacf4
- | 上下滑动加载定期任务 | 4090d89
- | 上下滚动时间轴 | d533a01
- | 下拉加载定期任务传参,时间格式化修改 | 0b95a0e
- | 任务开始时间延迟插件 | 992a313
- | 修改main | 749ae9a
- | 修改小红点传参 | 87b20fd
- | 修改报错 | 531c14d
- | 修改接口路径 | df6acf2
- | 修改角色栏组件 | a54c601
- | 切换到默认项目角色没有激活状态的bug | 438d448
- | 切换日历时查询小红点 | 7091789
- | 定期任务接口 | aa4981c
- | 定期任务插件 | 92b3254
- | 定期任务未加载时,显示空的时间轴并能上下滑动 | ce38093
- | 定期任务骨架屏修改 | 8ff72dd
- | 平车演示临时去掉项目快捷方式的toast提示 | e0b2c23
- | 手动展开日常任务 | 0a4a622
- | 提示信息显示bug及日常任务收缩问题 | f2f06c5
- | 插件bug解决 | 41257eb
- | 收到消息修改任务状态 | c378063
- | 日历无任务时添加小绿点,时间轴刻度无任务不显示时分 | 0f90868
- | 日常任务html数据查验 | 880ce5c
- | 日常任务插件遍历时的key值修改 | cd26285
- | 日常任务插件面板高度修改 | 249f9e4
- | 时间轴上下滑动 | 4d0ae46
- | 时间轴上下滚动数据加载bug修改 | e82ede4
- | 时间轴插件 | 225d3cc
- | 时间轴无任务时时间刻度加载修改 | 4921672
- | 时间轴骨架屏修改 | ca78d02
- | 角色显示状态修改 | 7d3b906
- | 角色栏修改 | 19228d6
- | 解决时间轴报错 | da1eece
- | 跳转详情页返回路径修改 | c5e17c0
- | 骨架屏替换 | e9fdd71
ID1000343 | 解决向下预加载查询参数时间没+1颗粒度;以及滚动加载颗粒度写死的问题 | [940603a](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/940603a), closes [#ID1000343](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/issues/ID1000343) ID1000343 | 解决向下预加载查询参数时间没+1颗粒度;以及滚动加载颗粒度写死的问题 | [940603a](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/940603a), closes [#ID1000343](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/issues/ID1000343)
plugin | 插件解析机制完善 | [0f5a27d](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/0f5a27d) plugin | 插件解析机制完善 | [0f5a27d](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/0f5a27d)
project title | 项目标题修改; 切换角色移除script | [5c20017](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/5c20017) project title | 项目标题修改; 切换角色移除script | [5c20017](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/5c20017)
@ -157,6 +97,7 @@
- | 修改角色栏组件 | [a54c601](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/a54c601) - | 修改角色栏组件 | [a54c601](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/a54c601)
- | 切换到默认项目角色没有激活状态的bug | [438d448](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/438d448) - | 切换到默认项目角色没有激活状态的bug | [438d448](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/438d448)
- | 切换日历时查询小红点 | [7091789](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/7091789) - | 切换日历时查询小红点 | [7091789](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/7091789)
- | 定期任务key值修改 | [c6688db](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/c6688db)
- | 定期任务接口 | [aa4981c](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/aa4981c) - | 定期任务接口 | [aa4981c](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/aa4981c)
- | 定期任务插件 | [92b3254](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/92b3254) - | 定期任务插件 | [92b3254](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/92b3254)
- | 定期任务未加载时,显示空的时间轴并能上下滑动 | [ce38093](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/ce38093) - | 定期任务未加载时,显示空的时间轴并能上下滑动 | [ce38093](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/ce38093)
@ -219,16 +160,6 @@
### 🚀 性能优化 ### 🚀 性能优化
范围|描述|commitId 范围|描述|commitId
--|--|-- --|--|--
- | 修改定期任务骨架屏高度 | 909a734
- | 插件查询及展示 | 4dba770
- | 整理代码 | 7a55315
- | 日历的更改 | 7353ac8
- | 测试接口 | 215e074
- | 组件文件夹新建 | 22bfe7b
- | 组件文件夹新建 | 17bb8c9
- | 组件文件夹新建 | 1421504
- | 角色栏文字颜色修改 | 215c6b3
- | 解决警告 | c932b09
- | 修改定期任务骨架屏高度 | [909a734](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/909a734) - | 修改定期任务骨架屏高度 | [909a734](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/909a734)
- | 插件查询及展示 | [4dba770](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/4dba770) - | 插件查询及展示 | [4dba770](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/4dba770)
- | 整理代码 | [7a55315](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/7a55315) - | 整理代码 | [7a55315](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/7a55315)
@ -260,9 +191,7 @@
范围|描述|commitId 范围|描述|commitId
--|--|-- --|--|--
- | style:index | 978f272
- | !2 基础模板v1.1.0 | f5e61dd
- | init | c0f1deb
- | style:index | [978f272](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/978f272) - | style:index | [978f272](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/978f272)
- | !2 基础模板v1.1.0 | [f5e61dd](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/f5e61dd) - | !2 基础模板v1.1.0 | [f5e61dd](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/f5e61dd)
- | init | [c0f1deb](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/c0f1deb) - | init | [c0f1deb](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/c0f1deb)

9
src/components/Roles/Roles.vue

@ -58,7 +58,7 @@ export default {
methods: { methods: {
...mapActions('task', ['handleRegularTask', 'getPermanent']), ...mapActions('task', ['handleRegularTask', 'getPermanent']),
...mapMutations('role', ['setRoleId']), ...mapMutations('role', ['setRoleId']),
...mapMutations('task', ['setPermanents', 'setDailyTasks', 'clearEndFlag', 'setTimeNode']), ...mapMutations('task', ['setPermanents', 'setDailyTasks', 'clearEndFlag']),
// //
setCurrentRole(index) { setCurrentRole(index) {
@ -92,13 +92,6 @@ export default {
this.setRoleId(id); this.setRoleId(id);
//index //index
this.setCurrentRole(index); this.setCurrentRole(index);
//
this.setPermanents([]);
this.setDailyTasks([]);
//
//
//
this.clearEndFlag();
}); });
} catch (error) { } catch (error) {
console.error('role.vue changeRole error: ', error); console.error('role.vue changeRole error: ', error);

144
src/components/TimeLine/TimeLine.vue

@ -4,9 +4,9 @@
<scroll-view <scroll-view
:lower-threshold="300" :lower-threshold="300"
:scrollTop="top" scroll-y="true"
:scrollY="true"
:upper-threshold="300" :upper-threshold="300"
:scroll-into-view="viewId"
@scroll="scroll" @scroll="scroll"
@scrolltolower="handleScrollBottom" @scrolltolower="handleScrollBottom"
@scrolltoupper="handleScrollTop" @scrolltoupper="handleScrollTop"
@ -23,25 +23,26 @@
// import Barrier from './component/Barrier.vue'; // import Barrier from './component/Barrier.vue';
import { mapState, mapMutations, mapGetters } from 'vuex'; import { mapState, mapMutations, mapGetters } from 'vuex';
import TimeBox from './component/TimeBox.vue'; import TimeBox from './component/TimeBox.vue';
import mixin from '@/mixins/timeline';
export default { export default {
name: 'TimeLine', name: 'TimeLine',
components: { TimeBox }, components: { TimeBox },
mixins: [mixin],
data() { data() {
return { top: 0 }; return {
top: 0,
viewId: '', //
};
}, },
computed: { computed: {
...mapState('role', ['visibleRoles']), ...mapState('role', ['visibleRoles']),
...mapState('task', ['scrollTop', 'showTips', 'tasks', 'topEnd', 'bottomEnd', 'showSkeleton', 'randomId']), ...mapState('task', ['scrollTop', 'showTips', 'tasks', 'topEnd', 'bottomEnd', 'showSkeleton', 'timeNode']),
...mapGetters('task', ['timeGranularity']), ...mapGetters('task', ['timeGranularity']),
}, },
mounted() {
this.setDatumPoint();
},
methods: { methods: {
...mapMutations('task', ['setScrollTop', 'setShrink', 'setUpTasks', 'setDownTasks']), ...mapMutations('task', ['setScrollTop', 'setShrink', 'setUpTasks', 'setDownTasks']),
@ -58,52 +59,8 @@ export default {
const startTime = this.tasks[0].planStart - 0; const startTime = this.tasks[0].planStart - 0;
if ((this.tasks[0].plugins && this.tasks[0].plugins.length === 0) || this.topEnd) { if ((this.tasks[0].plugins && this.tasks[0].plugins.length === 0) || this.topEnd) {
// //
// console.warn(': '); console.warn('滚动到顶部没有数据时: ');
const addTasks = [ const addTasks = this.setTime(startTime, true);
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, -6, 'day').valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, -5, 'day').valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, -4, 'day').valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, -3, 'day').valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, -2, 'day').valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, -1, 'day').valueOf(),
},
];
this.setUpTasks(addTasks); this.setUpTasks(addTasks);
} else { } else {
// //
@ -124,54 +81,12 @@ export default {
const startTime = tasks[tasks.length - 1].planStart - 0; const startTime = tasks[tasks.length - 1].planStart - 0;
if ((tasks[0].plugins && tasks[0].plugins.length === 0) || this.bottomEnd) { if ((tasks[0].plugins && tasks[0].plugins.length === 0) || this.bottomEnd) {
// //
// console.warn(': '); console.warn('滚动到底部没有数据时: ');
const addTasks = [ const addTasks = this.setTime(startTime, false);
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, 1, timeGranularity).valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, 2, timeGranularity).valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, 3, timeGranularity).valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, 4, timeGranularity).valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, 5, timeGranularity).valueOf(),
},
{
id: this.randomId,
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, 6, timeGranularity).valueOf(),
},
];
this.setDownTasks(addTasks); this.setDownTasks(addTasks);
} else { } else {
// =+ // =+
console.warn('滚动到底部有数据时: ');
const timeNode = this.$t.time.add(startTime, 1, timeGranularity).valueOf(); const timeNode = this.$t.time.add(startTime, 1, timeGranularity).valueOf();
const downQuery = { const downQuery = {
timeNode, timeNode,
@ -182,25 +97,20 @@ export default {
} }
}, },
// //
setDatumPoint() { setViewId() {
const { tasks } = this; const { tasks, timeNode } = this;
if (tasks && tasks.length) { for (let i = 0; i < tasks.length; i++) {
let tasksHeight = 0; const item = tasks[i];
const scrollHeight = document.getElementById('scroll').clientHeight; const show = this.$t.time.isSame(+item.planStart, +timeNode, this.timeGranularity);
let width = document.documentElement.clientWidth; if (item.detailId) {
for (let i = 0; i < 3; i++) { this.viewId = `a${item.id}`;
if (tasks[i].panel && tasks[i].panel.height) { return;
// + 42 }
tasksHeight += +tasks[i].panel.height + 42; if (show) {
} else { this.viewId = `a${item.id}`;
// rem + 42 return;
// u-card h-16 = 4rem
// += 1rem + 42 = width / 20 + 42
tasksHeight += (width / 20) * 4 + 42;
}
} }
this.top = tasksHeight - scrollHeight / 2;
} }
}, },
}, },

3
src/components/TimeLine/component/TimeBox.vue

@ -2,12 +2,13 @@
<view class="column"> <view class="column">
<!-- v-if="tasks && tasks.length" --> <!-- v-if="tasks && tasks.length" -->
<view> <view>
<view :key="task.id" v-for="task in tasks"> <view :key="task.id" v-for="task in tasks" class="ssssss" :id="`a${task.id}`">
<view class="flex"> <view class="flex">
<TimeStatus :task="task" /> <TimeStatus :task="task" />
<view class="flex items-center justify-between flex-1 ml-2 task-column"> <view class="flex items-center justify-between flex-1 ml-2 task-column">
<view v-if="task.process !== 4">{{ $moment(+task.planStart).format(startTimeFormat) }}</view> <view v-if="task.process !== 4">{{ $moment(+task.planStart).format(startTimeFormat) }}</view>
<view v-else>{{ $moment(+task.planStart).format('D日') }}</view> <view v-else>{{ $moment(+task.planStart).format('D日') }}</view>
<!-- 任务功能菜单 --> <!-- 任务功能菜单 -->
<TaskTools v-if="task.process !== 4" /> <TaskTools v-if="task.process !== 4" />
</view> </view>

44
src/mixins/timeline.js

@ -0,0 +1,44 @@
import { mapGetters } from 'vuex';
const mixin = {
computed: mapGetters('task', ['timeGranularity']),
methods: {
/**
* 设置时间轴空数据
* @param {*} startTime
* @param {*} show true 向上加载,false 向下加载
*/
setTime(startTime, show) {
let { timeGranularity } = this;
let arr = [];
let str = {};
if (show) {
for (let i = 10; i > 0; i--) {
str = {
id: this.$u.guid(20, false, 10),
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, `-${i}` - 0, timeGranularity).valueOf(),
};
arr.push(str);
}
} else {
for (let i = 0; i < 10; i++) {
str = {
id: this.$u.guid(20, false, 10),
panel: {},
plugins: [],
process: 4,
planStart: this.$t.time.add(startTime, i + 1, timeGranularity).valueOf(),
};
arr.push(str);
}
}
return arr;
},
},
};
export default mixin;

144
src/pages/project/project.vue

@ -18,8 +18,10 @@
<script> <script>
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'; import { mapState, mapGetters, mapMutations, mapActions } from 'vuex';
import mixin from '@/mixins/timeline';
export default { export default {
mixins: [mixin],
data() { data() {
return { height: '' }; return { height: '' };
}, },
@ -41,12 +43,10 @@ export default {
* 重新根据时间和角色查询普通日常任务 * 重新根据时间和角色查询普通日常任务
* 永久日常任务不发生改变 * 永久日常任务不发生改变
*/ */
timeNode(val) { async timeNode(val) {
console.log('val: ', val);
if (val && this.roleId) { if (val && this.roleId) {
// //
this.getGlobalData(); await this.initTasks();
this.getInitTasks();
} }
}, },
@ -58,13 +58,11 @@ export default {
*/ */
roleId(val) { roleId(val) {
if (val) { if (val) {
console.log('角色发生变化: ', val);
// storagetimeNode,storetimeNode // storagetimeNode,storetimeNode
this.setTimeNode( this.setTimeNode(+this.$t.storage.getStorageSync('timeNode') !== 0 ? +this.$t.storage.getStorageSync('timeNode') : Date.now());
+this.$t.storage.getStorageSync('timeNode') !== 0 ? +this.$t.storage.getStorageSync('timeNode') !== 0 : Date.now(),
);
// storage // storage
this.$t.storage.setStorageSync('timeNode', ''); this.$t.storage.setStorageSync('timeNode', '');
console.log('当角色发生变化时: ', this.timeNode);
// //
this.getPermanent(val); this.getPermanent(val);
} }
@ -77,6 +75,7 @@ export default {
onUnload() { onUnload() {
this.clearEndFlag(); this.clearEndFlag();
this.clearTasks();
}, },
methods: { methods: {
@ -87,7 +86,18 @@ export default {
...mapMutations('user', ['setToken']), ...mapMutations('user', ['setToken']),
...mapMutations('project', ['setProject', 'setProjectName']), ...mapMutations('project', ['setProject', 'setProjectName']),
...mapMutations('role', ['setInvisibleRoles', 'setVisibleRoles', 'setRoleId']), ...mapMutations('role', ['setInvisibleRoles', 'setVisibleRoles', 'setRoleId']),
...mapMutations('task', ['setUpTasks', 'setDownTasks', 'setDailyTasks', 'setTimeNode', 'clearEndFlag', 'setShowSkeleton']), ...mapMutations('task', [
'setPermanents',
'setUpTasks',
'setDownTasks',
'setDailyTasks',
'setTimeNode',
'clearTasks',
'clearEndFlag',
'setShowSkeleton',
'setTopEnd',
'setBottomEnd',
]),
/** /**
* 初始化 * 初始化
@ -113,11 +123,6 @@ export default {
// id // id
this.$t.ui.showToast('缺少项目信息参数'); this.$t.ui.showToast('缺少项目信息参数');
} else { } else {
// storagetimeNode,storetimeNode
this.setTimeNode(this.$t.storage.getStorageSync('timeNode') - 0);
// storage
this.$t.storage.setStorageSync('timeNode', '');
console.log('timeNode: ', this.$t.storage.getStorageSync('timeNode'), this.timeNode);
// id // id
await this.getProjectById({ projectId: options.p }); await this.getProjectById({ projectId: options.p });
// id // id
@ -129,6 +134,28 @@ export default {
} }
}, },
//
async initTasks() {
//
this.setPermanents([]);
this.setDailyTasks([]);
//
this.clearTasks();
//
//
this.clearEndFlag();
//
this.getGlobalData();
//
this.setPrevTasks();
//
this.setNextTasks();
await this.getInitTasks();
setTimeout(() => {
this.$refs.child.setViewId();
}, 2000);
},
// || // ||
async getInitTasks() { async getInitTasks() {
// //
@ -136,20 +163,21 @@ export default {
await this.getTasks({ queryType: 1 }); await this.getTasks({ queryType: 1 });
// //
if (this.tasks && this.tasks.length && this.tasks[0].detailId) { const detailId = this.tasks.findIndex(task => task.detailId);
this.$nextTick(() => { if (detailId !== -1) {
this.$nextTick(async () => {
const { tasks, timeGranularity } = this; const { tasks, timeGranularity } = this;
this.getTasks({ timeNode: +tasks[0].planStart, queryType: 0, queryNum: 6 }); // await this.getTasks({ timeNode: +tasks[0].planStart, queryType: 0, queryNum: 6 }); //
// //
const nextQueryTime = +this.$t.time.add(+tasks[tasks.length - 1].planStart, 1, timeGranularity); const nextQueryTime = +this.$t.time.add(+tasks[tasks.length - 1].planStart, 1, timeGranularity);
this.getTasks({ timeNode: nextQueryTime, queryType: 1, queryNum: 6 }); // await this.getTasks({ timeNode: nextQueryTime, queryType: 1, queryNum: 6 }); //
}); });
} else { } else {
// //
// //
this.setUpTasks(); this.setPrevTasks();
// //
this.setDownTasks(); this.setNextTasks();
} }
}, },
@ -184,9 +212,14 @@ export default {
queryNum: query.queryNum || 3, queryNum: query.queryNum || 3,
queryType: query.queryType, queryType: query.queryType,
}; };
console.log('params: ', params); const res = await this.getRegulars(params);
await this.getRegulars(params);
this.setShowSkeleton(false); this.setShowSkeleton(false);
// 0 -> 1 ->
if (res && res.length) {
this.replacePrevData(res, params.queryType);
} else {
params.queryType === 0 ? this.setPrevTasks() : this.setNextTasks();
}
} catch (error) { } catch (error) {
this.setShowSkeleton(false); this.setShowSkeleton(false);
console.error('error: ', error); console.error('error: ', error);
@ -199,6 +232,73 @@ export default {
const param = { roleId, timeNode, timeUnit }; const param = { roleId, timeNode, timeUnit };
this.getGlobal(param); this.getGlobal(param);
}, },
//
setPrevTasks() {
this.setTopEnd(true);
let sTime = '';
if (!this.tasks || !this.tasks.length) {
sTime = +new Date().getTime();
} else {
sTime = +this.tasks[0].planStart - 0;
}
const initData = this.setTime(sTime, true);
this.setUpTasks(initData);
},
//
setNextTasks() {
this.setBottomEnd(true);
let sTime = '';
if (!this.tasks || !this.tasks.length) {
sTime = +new Date().getTime();
} else {
sTime = +this.tasks[this.tasks.length - 1].planStart - 0;
}
const initData = this.setTime(sTime, false);
this.setDownTasks(initData);
},
//
replacePrevData(data, type) {
let newTasks = [...this.tasks];
for (let i = 0; i < newTasks.length; i++) {
const task = newTasks[i];
let arr = [];
for (let j = 0; j < data.length; j++) {
const item = data[j];
//
if (+data[0].planStart < +newTasks[0].planStart) {
this.setPrevTasks();
newTasks = [...this.tasks];
break;
} else if (+data[data.length - 1].planStart > +newTasks[newTasks.length - 1].planStart) {
this.setNextTasks();
newTasks = [...this.tasks];
break;
} else {
//
const taskItem = this.$t.time.isSame(+item.planStart, +task.planStart, this.timeGranularity);
if (taskItem) {
arr.push(item);
if (task.detailId) {
newTasks.splice(i, 0, item);
} else {
if (arr.length === 1) {
newTasks.splice(i, 1, item);
}
if (arr.length > 1) {
newTasks.splice(i, 0, item);
}
}
i++;
}
}
}
}
this.clearTasks();
type === 0 ? this.setUpTasks(newTasks) : this.setDownTasks(newTasks);
},
}, },
}; };
</script> </script>

16
src/store/task/actions.js

@ -18,10 +18,10 @@ const actions = {
* @param {*} commit * @param {*} commit
* @param {object} param 请求参数 roleId, timeNode, timeUnit * @param {object} param 请求参数 roleId, timeNode, timeUnit
*/ */
async getGlobal({ commit }, param) { async getGlobal(param) {
try { try {
const data = await uni.$u.api.getGlobal(param); await uni.$u.api.getGlobal(param);
commit('setDailyTasks', data); // commit('setDailyTasks', data);
} catch (error) { } catch (error) {
console.log('task actions getGlobal error: ', error); console.log('task actions getGlobal error: ', error);
} }
@ -33,16 +33,10 @@ const actions = {
* @param {number} param.queryType 必填 0 -> 向上 1 -> 向下 * @param {number} param.queryType 必填 0 -> 向上 1 -> 向下
*/ */
// eslint-disable-next-line // eslint-disable-next-line
async getRegulars({ commit, state }, param) { async getRegulars(param) {
try { try {
// 向上查 且 上边没数据了 不查
// if (param.queryType === 0) return;
// 向下查 且 下边美术家了 不查
// if (param.queryType === 1) return;
const data = await uni.$u.api.getRegularTask(param); const data = await uni.$u.api.getRegularTask(param);
// 0 -> 向上 1 -> 向下 return data;
// data 有无的判断在mutations里
param.queryType === 0 ? commit('setUpTasks', data) : commit('setDownTasks', data);
} catch (error) { } catch (error) {
throw error || '获取定期任务失败'; throw error || '获取定期任务失败';
} }

149
src/store/task/mutations.js

@ -52,7 +52,6 @@ const mutations = {
*/ */
setTimeNode(state, data) { setTimeNode(state, data) {
state.timeNode = data; state.timeNode = data;
console.log('state.timeNode : ', state.timeNode);
}, },
/** /**
@ -70,65 +69,10 @@ const mutations = {
* @param {Array} data 服务端返回的模板数组 * @param {Array} data 服务端返回的模板数组
*/ */
setUpTasks(state, data) { setUpTasks(state, data) {
if (!data || !data.length) { if (!state.tasks.length) {
state.topEnd = true; state.tasks = [...data];
let sTime = '';
if (!state.tasks || !state.tasks.length) {
sTime = +new Date().getTime();
} else {
sTime = +state.tasks[0].planStart - 0;
}
const initData = [
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, -6, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, -5, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, -4, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, -3, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, -2, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, -1, 'day').valueOf(),
},
];
state.tasks = [...initData.concat(state.tasks)];
} else { } else {
if (!state.tasks && !state.tasks.length) { state.tasks = [...data.concat(state.tasks)];
state.tasks = [...data];
} else {
state.tasks = [...data.concat(state.tasks)];
}
} }
}, },
@ -138,65 +82,10 @@ const mutations = {
* @param {Array} data 服务端返回的模板数组 * @param {Array} data 服务端返回的模板数组
*/ */
setDownTasks(state, data) { setDownTasks(state, data) {
if (!data || !data.length) { if (!state.tasks && !state.tasks.length) {
state.bottomEnd = true; state.tasks = [...data];
let sTime = '';
if (!state.tasks || !state.tasks.length) {
sTime = +new Date().getTime();
} else {
sTime = +state.tasks[state.tasks.length - 1].planStart - 0;
}
const initData = [
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, 1, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, 2, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, 3, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, 4, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, 5, 'day').valueOf(),
},
{
id: state.randomId,
panel: {},
plugins: [],
process: 4,
planStart: uni.$t.time.add(sTime, 6, 'day').valueOf(),
},
];
state.tasks = [...state.tasks.concat(initData)];
} else { } else {
if (!state.tasks && !state.tasks.length) { state.tasks = [...state.tasks.concat(data)];
state.tasks = [...data];
} else {
state.tasks = [...state.tasks.concat(data)];
}
} }
}, },
@ -218,13 +107,35 @@ const mutations = {
state.permanents = tasks || []; state.permanents = tasks || [];
}, },
// 清空标志位 任务 如切换角色等使用 /**
* 设置时间轴是否继续向上查任务
* @param {Object} state
* @param {Boolean} show
*/
setTopEnd(state, show) {
state.topEnd = show;
},
/**
* 设置时间轴是否继续向下查任务
* @param {Object} state
* @param {Boolean} show
*/
setBottomEnd(state, show) {
state.bottomEnd = show;
},
// 清空标志位 如切换角色等使用
clearEndFlag(state) { clearEndFlag(state) {
state.tasks = [];
state.topEnd = false; state.topEnd = false;
state.bottomEnd = false; state.bottomEnd = false;
}, },
// 清空定期任务
clearTasks(state) {
state.tasks = [];
},
/** /**
* 收到消息设置任务状态 * 收到消息设置任务状态
* @param {Object} state * @param {Object} state

1
src/store/task/state.js

@ -25,7 +25,6 @@ const state = {
// 定期任务 // 定期任务
tasks: [], tasks: [],
showSkeleton: false, // 定期任务骨架屏 showSkeleton: false, // 定期任务骨架屏
randomId: Math.floor(Math.random() * 100000000000000000000), // 随机id
}; };
export default state; export default state;

12
src/utils/time.js

@ -100,6 +100,17 @@ const validateTimeIsToday = time => {
return timeDate.getFullYear() === date.getFullYear() && timeDate.getMonth() === date.getMonth() && timeDate.getDate() === date.getDate(); return timeDate.getFullYear() === date.getFullYear() && timeDate.getMonth() === date.getMonth() && timeDate.getDate() === date.getDate();
}; };
/**
* 检测两个日期是否相同
* @param {number | date} time
* @param {number | date} value
* @param {string} cycle 传入 day 将会比较 day month和 year
*/
const isSame = (time, value, cycle) => {
const str = dayjs(time).isSame(value, cycle);
return str;
};
/** /**
* 格式化开始时间 * 格式化开始时间
* @param {Number} timestamp 时间戳 * @param {Number} timestamp 时间戳
@ -344,6 +355,7 @@ export default {
convertTime, convertTime,
secondToMinute, secondToMinute,
setTimestampToStr, setTimestampToStr,
isSame,
formatBeginTime, formatBeginTime,
formatDuration, formatDuration,
formatDurationToObject, formatDurationToObject,

Loading…
Cancel
Save