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

1
src/components/Roles/Roles.vue

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

32
src/components/TimeLine/TimeLine.vue

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

33
src/pages/project/project.vue

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

2
src/store/task/state.js

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

7
src/utils/time.js

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

Loading…
Cancel
Save