| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- 'use strict';
- module.exports = app => {
- class WeappFileController extends app.BaseController {
- async getSubProjectPermission(ctx, spid) {
- const sessionUser = ctx.session.sessionUser;
-
- // 如果是管理员,返回全部权限
- if (sessionUser.is_admin) {
- return ctx.service.subProjPermission.adminPermission;
- }
-
- // 否则获取用户在该子项目的权限
- const permission = await ctx.service.subProjPermission.getSubProjectUserPermission(
- spid,
- sessionUser.accountId
- );
-
- if (!permission) {
- throw '您无权查看该项目';
- }
-
- return permission;
- }
- /**
- * 获取文件列表页面数据
- *
- * @param {Object} ctx - 上下文对象
- */
- async file(ctx) {
- try {
- const { id } = ctx.query;
- if (!id) {
- ctx.body = { code: -1, msg: '缺少子项目ID', data: null };
- return;
- }
- // 获取子项目信息
- const subProject = await ctx.service.subProject.getDataById(id);
- if (!subProject) {
- ctx.body = { code: -1, msg: '子项目不存在', data: null };
- return;
- }
- // 获取用户在该子项目的权限信息
- const permission = await this.getSubProjectPermission(ctx, id);
- // 获取有效的归档分类
- const filing = await ctx.service.filing.getValidFiling(id, permission.filing_type);
- // const filing = await ctx.service.filing.getValidFiling(id, subProject.permission.filing_type);
- // 获取所有分类数据
- const categoryData = await ctx.service.category.getAllCategory(subProject);
- // 检查权限
- const canFiling = permission.file_permission.indexOf(ctx.service.subProjPermission.PermissionConst.file.filing.value) >= 0;
- const canUpload = permission.file_permission.indexOf(ctx.service.subProjPermission.PermissionConst.file.upload.value) >= 0;
- const canEdit = permission.file_permission.indexOf(ctx.service.subProjPermission.PermissionConst.file.editfile.value) >= 0;
- // 获取文件引用列表
- const fileReferenceList = await ctx.service.subProject.getFileReference(subProject, ctx.service.subProject.FileReferenceType.file);
- ctx.body = {
- code: 0,
- msg: '获取成功',
- data: {
- filing,
- categoryData,
- canFiling,
- canUpload,
- canEdit,
- fileReferenceList,
- },
- };
- } catch (err) {
- this.log(err);
- ctx.body = { code: -1, msg: err.toString(), data: null };
- }
- }
- /**
- * 获取第一层级归档分类
- *
- * @param {Object} ctx - 上下文对象
- */
- async getFirstLevelFiling(ctx) {
- try {
- const { id } = ctx.query;
- if (!id) {
- ctx.body = { code: -1, msg: '缺少子项目ID', data: null };
- return;
- }
- // 获取子项目信息
- const subProject = await ctx.service.subProject.getDataById(id);
- if (!subProject) {
- ctx.body = { code: -1, msg: '子项目不存在', data: null };
- return;
- }
- // 获取有效的归档分类
- const allFiling = await ctx.service.filing.getValidFiling(id, subProject.permission.filing_type);
- // 过滤出第一层级数据
- const firstLevelFiling = allFiling.filter(item => item.tree_level === 1);
- ctx.body = {
- code: 0,
- msg: '获取成功',
- data: {
- filing: firstLevelFiling,
- },
- };
- } catch (err) {
- this.log(err);
- ctx.body = { code: -1, msg: err.toString(), data: null };
- }
- }
- }
- return WeappFileController;
- };
|