tall小程序和时间轴结合在小程序中
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.7 KiB

<template>
<view :style="{ height: height }" class="flex flex-col overflow-hidden">
<Title />
<view class="container flex flex-col flex-1 overflow-hidden bg-gray-100">
<Roles @getTasks="getTasks" />
<Globals :plugins="plugins" />
<TimeLine @getTasks="getTasks" class="flex-1 overflow-hidden" ref="child" />
</view>
</view>
</template>
<script>
4 years ago
import { mapState, mapMutations, mapActions } from 'vuex';
export default {
data() {
return { title: 'Hello', height: '', scrollHeight: null, plugins: [] };
},
computed: {
...mapState('user', ['user', 'token']),
...mapState('home', ['visibleRoles', 'roleId', 'timeNode', 'timeUnit', 'tasks']),
},
4 years ago
async onLoad(options) {
4 years ago
console.log('options: ', options);
// this.openPage();
const TOKEN = uni.getStorageSync('anyringToken');
if (!TOKEN || !this.token) {
await this.getUserId(options.u);
}
const params = { projectId: options.p };
this.setProjectName(options.pname);
// 根据项目id获取项目信息
await this.getProjectById(params);
// 根据项目id获取角色列表
await this.getRoles(params);
this.setInitialRoleId(this.visibleRoles);
// 根据时间基准点和角色查找定期任务
await this.getTasks({ queryType: 0 });
await this.getTasks({ queryType: 1 });
// 根据角色查找永久的日常任务
await this.getPermanent();
// 根据时间和角色查找日常任务
await this.getGlobal();
// 查上下的定期任务
if (this.tasks && this.tasks.length) {
console.log('this.tasks[0].planStart: ', this.tasks[0].planStart);
await this.getTasks({ timeNode: +this.tasks[0].planStart, queryType: 0, queryNum: 6 });
console.log('this.tasks[this.tasks.length - 1].planStart: ', this.tasks[this.tasks.length - 1].planStart);
await this.getTasks({ timeNode: +this.tasks[this.tasks.length - 1].planStart, queryType: 1, queryNum: 6 });
}
},
mounted() {
this.height = window.screen.height + 'px';
},
methods: {
...mapMutations('home', [
'setProject',
'setInvisibleRoles',
'setVisibleRoles',
'setRoleId',
'setUpTasks',
'setDownTasks',
'setDailyTasks',
'setProjectName',
]),
4 years ago
...mapActions('user', ['getUserId']),
...mapActions('home', ['getProjectById', 'getRoles', 'handleRegularTask']),
4 years ago
openPage() {
console.log('open');
this.$u.route('/pages/pinch/pinch');
},
// 设置 初始显示角色信息
setInitialRoleId(visibleList) {
const index = visibleList.findIndex(item => item.mine);
const currentRole = index > 0 ? visibleList[index] : visibleList[0];
const currentRoleId = currentRole ? currentRole.id : '';
this.setRoleId(currentRoleId);
},
/**
* 根据时间基准点和角色查找定期任务
* @param {string} roleId 角色id
* @param {string} timeNode 时间基准点 默认当前
* @param {string} timeUnit 时间颗粒度 默认天
* @param {string} queryNum 查找颗粒度数量 默认3个
* @param {string} queryType 0向上查找 1向下查找(默认) 下查包含自己上查不包含
*/
async getTasks(query) {
try {
const { roleId, timeNode, timeUnit } = this;
const params = { roleId };
params.timeNode = query.timeNode || timeNode;
params.timeUnit = query.timeUnit || timeUnit;
params.queryNum = query.queryNum || 3;
params.queryType = query.queryType;
console.log('params: ', params);
const res = await this.handleRegularTask(params);
query.queryType === 0 ? this.setUpTasks(res) : this.setDownTasks(res);
this.$refs.child.setDatumPoint();
} catch (error) {
console.log('error: ', error);
}
},
/**
* 根据角色查找永久的日常任务
* @param {string} roleId 角色id
*/
async getPermanent() {
try {
const res = await this.$u.api.getPermanent({ roleId: this.roleId });
console.log('res', res);
} catch (error) {
console.log('error: ', error);
}
},
/**
* 根据时间和角色查找日常任务
* @param {string} roleId 角色id
* @param {string} timeNode 时间基准点 默认当前
* @param {string} timeUnit 时间颗粒度 默认天
*/
async getGlobal() {
try {
const { roleId, timeNode, timeUnit } = this;
const params = { roleId, timeNode, timeUnit };
const res = await this.$u.api.getGlobal(params);
for (let task of res) {
for (let item of task.plugins) {
this.plugins.push(...item);
}
}
this.setDailyTasks(res);
} catch (error) {
console.log('error: ', error);
}
},
},
};
</script>