Browse Source

fix: 滚动id函数优化

pull/1/head
wally 4 years ago
parent
commit
b351b67b4b
  1. 1
      CHANGELOG.md
  2. 1
      src/components/Roles/Roles.vue
  3. 32
      src/components/TimeLine/TimeLine.vue
  4. 33
      src/pages/project/project.vue
  5. 6
      src/store/task/mutations.js
  6. 2
      src/store/task/state.js
  7. 7
      src/utils/time.js

1
CHANGELOG.md

@ -11,6 +11,7 @@
default plugin | 添加默认插件;项目列表;全局项目最大高度设置 | ed1d87b
- | indexedDB | 687394e
mp | 兼容小程序,去除window,document等 | 9178255
- | network控制本地缓存的使用 | 858429e
phone-bind | 验证码validate | a427250
pinch | alloy finger实现图片的pinch放大缩小 | de01343
plugin | 插件添加了token及param参数 | aeb0292

1
src/components/Roles/Roles.vue

@ -92,7 +92,6 @@ export default {
.exec();
const system = uni.getSystemInfoSync(); //
console.log('system: ', system);
//
let left = 0;
let screenWidth = system.windowWidth;

32
src/components/TimeLine/TimeLine.vue

@ -6,7 +6,7 @@
:lower-threshold="300"
scroll-y="true"
:upper-threshold="300"
:scroll-into-view="viewId"
:scroll-into-view="scrollToTaskId"
@scroll="scroll"
@scrolltolower="handleScrollBottom"
@scrolltoupper="handleScrollTop"
@ -36,12 +36,12 @@ export default {
computed: {
...mapState('role', ['visibleRoles']),
...mapState('task', ['scrollTop', 'showTips', 'tasks', 'topEnd', 'bottomEnd', 'showSkeleton', 'timeNode', 'viewId']),
...mapState('task', ['scrollTop', 'showTips', 'tasks', 'topEnd', 'bottomEnd', 'showSkeleton', 'timeNode', 'scrollToTaskId']),
...mapGetters('task', ['timeGranularity']),
},
methods: {
...mapMutations('task', ['setScrollTop', 'setShrink', 'setUpTasks', 'setDownTasks', 'setViewId']),
...mapMutations('task', ['setScrollTop', 'setShrink', 'setUpTasks', 'setDownTasks', 'setScrollToTaskId']),
//
scroll(e) {
@ -96,22 +96,16 @@ export default {
//
setScrollPosition() {
const { tasks, timeNode } = this;
for (let i = 0; i < tasks.length; i++) {
const item = tasks[i];
const show = this.$t.time.isSame(+item.planStart, +timeNode, this.timeGranularity);
// storagetimeNode,storetimeNode
const taskId = this.$t.storage.getStorageSync('taskId');
// storage
if (taskId) {
this.setViewId(`a${taskId}`);
this.$t.storage.setStorageSync('taskId', '');
return;
}
if (show) {
this.setViewId(`a${item.id}`);
return;
}
// storagetaskId id
const taskId = this.$t.storage.getStorageSync('taskId');
if (taskId) {
this.setScrollToTaskId(`a${taskId}`);
this.$t.storage.setStorageSync('taskId', ''); //
} else {
// taskId
// 线id 线
const task = this.tasks.find(item => this.$moment(+item.planStart).isSame(this.timeNode, this.timeGranularity));
task && this.setScrollToTaskId(`a${task.id}`); // task id
}
},
},

33
src/pages/project/project.vue

@ -11,7 +11,7 @@
<Globals />
<!-- 定期任务面板 -->
<TimeLine @getTasks="getTasks" class="flex-1 overflow-hidden" ref="child" />
<TimeLine @getTasks="getTasks" class="flex-1 overflow-hidden" ref="timeLine" />
</view>
</view>
</template>
@ -47,6 +47,7 @@ export default {
*/
timeNode(val) {
if (val && this.roleId) {
this.clearTasksData();
//
this.initTasks();
}
@ -107,8 +108,7 @@ export default {
// tokenuserIdtoken
// token userId
if (!options || !options.u) {
// u (userId)
this.$t.ui.showToast('缺少用户信息参数');
this.$t.ui.showToast('缺少用户信息参数'); // u (userId)
} else {
this.getToken(options.u);
}
@ -118,17 +118,14 @@ export default {
options && options.pname && this.setProjectName(options.pname);
if (!options || !options.p) {
// id
this.$t.ui.showToast('缺少项目信息参数');
this.$t.ui.showToast('缺少项目信息参数'); // id
} else {
// id
this.getProjectById({ projectId: options.p });
this.getProjectById({ projectId: options.p }); // id
}
},
/**
* 通过项目id获取项目信息
* @param {string} projectId
* @param {object} params 提交的参数
*/
async getProjectById(params) {
@ -159,8 +156,8 @@ export default {
});
},
//
async initTasks() {
//
clearTasksData() {
//
this.setPermanents([]);
this.setDailyTasks([]);
@ -169,15 +166,19 @@ export default {
//
//
this.clearEndFlag();
//
this.getGlobalData();
//
this.setPrevTasks();
},
//
async initTasks() {
this.getGlobalData(); //
this.setPrevTasks(); //
// storage
// taskIdid
//
const storageTaskId = this.$t.storage.getStorageSync('taskId');
this.$nextTick(() => {
if (!storageTaskId) {
this.$refs.child.setScrollPosition();
this.$refs.timeLine.setScrollPosition();
}
});
//
@ -188,7 +189,7 @@ export default {
// storage
this.$nextTick(() => {
if (storageTaskId) {
this.$refs.child.setScrollPosition();
this.$refs.timeLine.setScrollPosition();
}
});
},

6
src/store/task/mutations.js

@ -11,10 +11,10 @@ const mutations = {
/**
* 记录时间轴向上滚动的距离
* @param { object } state
* @param { string } data
* @param {string} taskId
*/
setViewId(state, data) {
state.viewId = data;
setScrollToTaskId(state, taskId) {
state.scrollToTaskId = taskId;
},
/**

2
src/store/task/state.js

@ -1,6 +1,6 @@
const state = {
scrollTop: 0,
viewId: '', // 时间轴自动滚动的位置
scrollToTaskId: '', // 时间轴自动滚动的位置
isShrink: false, // true: 收起, false:展开
tip: {
taskId: '', // 当前正在修改状态的任务的id

7
src/utils/time.js

@ -104,12 +104,9 @@ const validateTimeIsToday = time => {
* 检测两个日期是否相同
* @param {number | date} time
* @param {number | date} value
* @param {string} cycle 传入 day 将会比较 day month和 year
* @param {string} cycle 传入 day 将会比较 day month和 year 一般是时间颗粒度
*/
const isSame = (time, value, cycle) => {
const str = dayjs(time).isSame(value, cycle);
return str;
};
const isSame = (time, value, cycle) => dayjs(time).isSame(value, cycle);
/**
* 格式化开始时间

Loading…
Cancel
Save