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.
297 lines
8.8 KiB
297 lines
8.8 KiB
export const filter = {
|
|
/**
|
|
* 过滤获取到的数据 根据开始截止时间
|
|
* @param {object} data 缓存拿到的数据
|
|
* @param {number} start ms
|
|
* @param {number} end ms
|
|
* @returns
|
|
*/
|
|
projects(data, start, end) {
|
|
if (!data || !data.length) return [];
|
|
return data.filter(item => start <= +item.endTime && end >= +item.startTime);
|
|
},
|
|
};
|
|
|
|
export default {
|
|
/**
|
|
* 项目列表某天的 获取
|
|
* @param {number} startTime
|
|
* @param {number} endTime
|
|
* @returns
|
|
*/
|
|
async getProjectsByDay(startTime, endTime) {
|
|
try {
|
|
const data = await uni.$storage.getStorage('projects');
|
|
return filter.projects(JSON.parse(data), startTime, endTime);
|
|
} catch (error) {
|
|
return [];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 项目列表 存
|
|
* @param {array} data
|
|
*/
|
|
putProjects(data) {
|
|
try {
|
|
if (!data || !data.length) return; // 服务端没数据不做操作
|
|
let value = uni.$storage.getStorageSync('projects');
|
|
let locals = value ? JSON.parse(value) : [];
|
|
if (!locals || !locals.length) {
|
|
// 本地没数据
|
|
locals = data || [];
|
|
} else {
|
|
// 本地有数据
|
|
data.forEach(item => {
|
|
let localData = locals.find(local => item.id === local.id);
|
|
if (localData) {
|
|
// 有相同数据 就用新的data里的数据
|
|
localData = item;
|
|
} else {
|
|
// 没有就直接存本地
|
|
locals.push(item);
|
|
}
|
|
});
|
|
}
|
|
uni.$storage.setStorage('projects', locals);
|
|
} catch (error) {
|
|
console.error('error: ', error);
|
|
uni.$storage.setStorage('projects', []);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 当前显示的角色信息 获取
|
|
* @param {object} params
|
|
* @returns
|
|
*/
|
|
async getShowRole(projectId) {
|
|
try {
|
|
const data = await uni.$storage.getStorage(`roles_${projectId}`);
|
|
return filter.roles(JSON.parse(data));
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 当前显示的角色信息 存
|
|
* @param {array} data
|
|
*/
|
|
putShowRole(projectId, data) {
|
|
try {
|
|
if (!data || !data.visibleList || !data.visibleList.length) return; // 服务端没数据不做操作
|
|
let value = uni.$storage.getStorageSync(`roles_${projectId}`);
|
|
let locals = value ? JSON.parse(value) : null;
|
|
if (!locals || !locals.length) {
|
|
// 本地没数据
|
|
locals = data || null;
|
|
} else {
|
|
// 本地有数据
|
|
data.invisibleList.forEach(item => {
|
|
let invisibleListLocalData = locals.invisibleList.find(local => item.id === local.id);
|
|
if (invisibleListLocalData) {
|
|
// 有相同数据 就用新的data里的数据
|
|
invisibleListLocalData = item;
|
|
} else {
|
|
// 没有就直接存本地
|
|
locals.invisibleList.push(item);
|
|
}
|
|
});
|
|
data.visibleList.forEach(item => {
|
|
let localData = locals.visibleList.find(local => item.id === local.id);
|
|
if (localData) {
|
|
// 有相同数据 就用新的data里的数据
|
|
localData = item;
|
|
} else {
|
|
// 没有就直接存本地
|
|
locals.visibleList.push(item);
|
|
}
|
|
});
|
|
}
|
|
uni.$storage.setStorage(`roles_${projectId}`, locals);
|
|
} catch (error) {
|
|
console.error('error: ', error);
|
|
uni.$storage.setStorage(`roles_${projectId}`, []);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 定期任务 获取
|
|
* @param {number} startTime
|
|
* @param {number} endTime
|
|
* @returns
|
|
*/
|
|
async getStorageRegularTask(params) {
|
|
try {
|
|
const data = await uni.$storage.getStorage(`plan_task_${params.projectId}_${params.roleId}`);
|
|
return filter.planTask(JSON.parse(data), params.timeNode, params.queryNum, params.timeUnit, params.queryType);
|
|
} catch (error) {
|
|
return [];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 定期任务 存
|
|
* @param {array} data
|
|
*/
|
|
putStorageRegularTask(params, data) {
|
|
try {
|
|
if (!data || !data.length) return; // 服务端没数据不做操作
|
|
let value = uni.$storage.getStorageSync(`plan_task_${params.projectId}_${params.roleId}`);
|
|
let locals = value ? JSON.parse(value) : [];
|
|
if (!locals || !locals.length) {
|
|
// 本地没数据
|
|
locals = data || [];
|
|
} else {
|
|
// 本地有数据
|
|
data.forEach(item => {
|
|
let localData = locals.find(local => item.id === local.id);
|
|
if (localData) {
|
|
// 有相同数据 就用新的data里的数据
|
|
localData = item;
|
|
} else {
|
|
// 没有就直接存本地
|
|
locals.push(item);
|
|
}
|
|
});
|
|
}
|
|
uni.$storage.setStorage(`plan_task_${params.projectId}_${params.roleId}`, locals);
|
|
} catch (error) {
|
|
console.error('error: ', error);
|
|
uni.$storage.setStorage(`plan_task_${params.projectId}_${params.roleId}`, []);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 永久的日常任务 获取
|
|
* @param {number} startTime
|
|
* @param {number} endTime
|
|
* @returns
|
|
*/
|
|
async getStoragePermanent(params) {
|
|
try {
|
|
const data = await uni.$storage.getStorage(`fixed_tasks_${params.projectId}_${params.roleId}`);
|
|
return filter.fixedTasks(JSON.parse(data));
|
|
} catch (error) {
|
|
return [];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 永久的日常任务 存
|
|
* @param {array} data
|
|
*/
|
|
putStoragePermanent(params, data) {
|
|
try {
|
|
if (!data || !data.length) return; // 服务端没数据不做操作
|
|
let value = uni.$storage.getStorageSync(`fixed_tasks_${params.projectId}_${params.roleId}`);
|
|
let locals = value ? JSON.parse(value) : [];
|
|
if (!locals || !locals.length) {
|
|
// 本地没数据
|
|
locals = data || [];
|
|
} else {
|
|
// 本地有数据
|
|
data.forEach((item, index) => {
|
|
let localData = locals.find(local => item.detailId === local.detailId);
|
|
if (localData) {
|
|
// 有相同数据 就用新的data里的数据
|
|
localData = item;
|
|
} else {
|
|
locals.splice(index, 1);
|
|
// 没有就直接存本地
|
|
locals.push(item);
|
|
}
|
|
});
|
|
}
|
|
uni.$storage.setStorage(`fixed_tasks_${params.projectId}_${params.roleId}`, locals);
|
|
} catch (error) {
|
|
console.error('error: ', error);
|
|
uni.$storage.setStorage(`fixed_tasks_${params.projectId}_${params.roleId}`, []);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 日常任务 获取
|
|
* @param {number} timeNode
|
|
* @returns
|
|
*/
|
|
async getDailyTask(params) {
|
|
try {
|
|
const data = await uni.$storage.getStorage(`variable_tasks_${params.projectId}_${params.roleId}`);
|
|
return filter.dailyTask(JSON.parse(data), params.timeNode);
|
|
} catch (error) {
|
|
return [];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 日常任务 存
|
|
* @param {array} data
|
|
*/
|
|
putDailyTask(params, data) {
|
|
try {
|
|
if (!data || !data.length) return; // 服务端没数据不做操作
|
|
let value = uni.$storage.getStorageSync(`variable_tasks_${params.projectId}_${params.roleId}`);
|
|
let locals = value ? JSON.parse(value) : [];
|
|
if (!locals || !locals.length) {
|
|
// 本地没数据
|
|
locals = data || [];
|
|
} else {
|
|
// 本地有数据
|
|
data.forEach(item => {
|
|
let localData = locals.find(local => item.detailId === local.detailId);
|
|
if (localData) {
|
|
// 有相同数据 就用新的data里的数据
|
|
localData = item;
|
|
} else {
|
|
// 没有就直接存本地
|
|
locals.push(item);
|
|
}
|
|
});
|
|
}
|
|
uni.$storage.setStorage(`variable_tasks_${params.projectId}_${params.roleId}`, locals);
|
|
} catch (error) {
|
|
console.error('error: ', error);
|
|
uni.$storage.setStorage(`variable_tasks_${params.projectId}_${params.roleId}`, []);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 插件信息 获取
|
|
* @param {string} pluginId
|
|
* @returns
|
|
*/
|
|
async getPlugin(pluginId) {
|
|
try {
|
|
const data = await uni.$storage.getStorage(`plugin_${pluginId}`);
|
|
return filter.plugin(JSON.parse(data));
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 插件信息 存
|
|
* @param {string} pluginId
|
|
* @param {object} data
|
|
*/
|
|
putPlugin(pluginId, data) {
|
|
try {
|
|
if (!data || !data.id) return; // 服务端没数据不做操作
|
|
let value = uni.$storage.getStorageSync(`plugin_${pluginId}`);
|
|
let locals = value ? JSON.parse(value) : null;
|
|
if (!locals || !locals.length) {
|
|
// 本地没数据
|
|
locals = data || null;
|
|
} else {
|
|
// 本地有数据
|
|
locals = data;
|
|
}
|
|
uni.$storage.setStorage(`plugin_${pluginId}`, locals);
|
|
} catch (error) {
|
|
console.error('error: ', error);
|
|
uni.$storage.setStorage(`plugin_${pluginId}`, null);
|
|
}
|
|
},
|
|
};
|
|
|