|
@@ -0,0 +1,367 @@
|
|
|
+$(document).ready(function() {
|
|
|
+ class FilingObj {
|
|
|
+ constructor(setting) {
|
|
|
+ // 原始数据整理后的树结构,用来整理zTree显示
|
|
|
+ this.dragTree = createDragTree({
|
|
|
+ id: 'id',
|
|
|
+ pid: 'tree_pid',
|
|
|
+ level: 'tree_level',
|
|
|
+ order: 'tree_order',
|
|
|
+ rootId: '-1'
|
|
|
+ });
|
|
|
+ // 界面显示的zTree
|
|
|
+ this.setting = setting;
|
|
|
+ this.filingTree = null;
|
|
|
+ this.pageCount = 15;
|
|
|
+ }
|
|
|
+ analysisFiling(data) {
|
|
|
+ this.dragTree.loadDatas(data);
|
|
|
+ this.dragTree.recursiveFun(this.dragTree.children, x => {
|
|
|
+ if (x.children && x.children.length > 0) {
|
|
|
+ x.total_file_count = x.children.map(y => {
|
|
|
+ return y.total_file_count;
|
|
|
+ }).reduce((pre, value) => {
|
|
|
+ return pre + value
|
|
|
+ }, 0);
|
|
|
+ } else {
|
|
|
+ x.total_file_count = x.file_count;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const sortNodes = this.dragTree.nodes.map(x => {
|
|
|
+ return {
|
|
|
+ id: x.id,
|
|
|
+ tree_pid: x.tree_pid,
|
|
|
+ name: x.name + (x.total_file_count > 0 ? `(${x.total_file_count})` : ''),
|
|
|
+ spid: x.spid,
|
|
|
+ source_node: x,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ this.filingTree = $.fn.zTree.init($('#filing'), this.setting, sortNodes);
|
|
|
+ }
|
|
|
+ _getFileHtml(file) {
|
|
|
+ const html = [];
|
|
|
+ html.push('<tr>');
|
|
|
+ html.push('<tr><td><input type="checkbox"></td>');
|
|
|
+ const editHtml = file.canEdit ? '<a href="" class="mr-1"><i class="fa fa-pencil fa-fw"></i></a>' : '';
|
|
|
+ const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1"><i class="fa fa-eye fa-fw"></i></a>` : '';
|
|
|
+ const downHtml = '<a href="" class="mr-1"><i class="fa fa-download fa-fw"></i></a>';
|
|
|
+ const delHtml = file.canEdit ? '<a href="" class="mr-1"><i class="fa fa-trash-o fa-fw"></i></a>' : '';
|
|
|
+ html.push(`<td><div class="d-flex justify-content-between align-items-center table-file"><div></div>${file.filename}</div><div class="btn-group-table" style="display: none;">${editHtml}${viewHtml}${downHtml}${delHtml}</div></div></td>`);
|
|
|
+ html.push(`<td>${file.user_name}</td>`);
|
|
|
+ html.push(`<td>${moment(file.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
|
|
|
+ html.push('<td>${file.fileext_str}</td>');
|
|
|
+ html.push('</tr>');
|
|
|
+ return html.join('');
|
|
|
+ }
|
|
|
+ refreshFilesTable() {
|
|
|
+ const html = [];
|
|
|
+ const files = this.curFiling.source_node.files;
|
|
|
+ if (!files || files.length === 0) return;
|
|
|
+
|
|
|
+ const startIndex = (this.curPage - 1)*this.pageCount;
|
|
|
+ const endIndex = this.curPage*this.pageCount;
|
|
|
+ for (const [i, f] of files.entries()) {
|
|
|
+ if (i < startIndex || i >= endIndex) continue;
|
|
|
+ html.push(this._getFileHtml(f));
|
|
|
+ }
|
|
|
+ $('#file-list').html(html.join(''));
|
|
|
+ }
|
|
|
+ async loadFiles(node, page) {
|
|
|
+ if (node.source_node.children && node.source_node.children.length > 0) return;
|
|
|
+
|
|
|
+ if (!node.source_node.file_count) return;
|
|
|
+ if (node.source_node.files.length === node.source_node.file_count) return;
|
|
|
+
|
|
|
+ const needFiles = Math.min(page*this.pageCount, node.source_node.file_count);
|
|
|
+ if (needFiles < node.source_node.files.length) return;
|
|
|
+
|
|
|
+ if (!node.source_node.files) node.source_node.files = [];
|
|
|
+ const files = await postDataAsync('file/load', { filing_id: node.id, page, count: this.pageCount });
|
|
|
+ node.source_node.files.push(...files);
|
|
|
+ node.source_node.files.sort((x, y) => {
|
|
|
+ return x.create_time - y.create_time;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ addSiblingFiling(node) {
|
|
|
+ const self = this;
|
|
|
+ postData('filing/add', { tree_pid: node.tree_pid, tree_pre_id: node.id }, function(result) {
|
|
|
+ const refreshData = self.dragTree.loadPostData(result);
|
|
|
+ const newNode = refreshData.create[0];
|
|
|
+ self.filingTree.addNodes(node.getParentNode(), node.getIndex(), [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid, source_node: newNode}]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ addChildFiling(node) {
|
|
|
+ const self = this;
|
|
|
+ postData('filing/add', { tree_pid: node.id }, function(result) {
|
|
|
+ const refreshData = self.dragTree.loadPostData(result);
|
|
|
+ const newNode = refreshData.create[0];
|
|
|
+ self.filingTree.addNodes(node, -1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid, source_node: newNode}]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ delFiling(node) {
|
|
|
+ const self = this;
|
|
|
+ postData('filing/del', { id: node.id }, function(result) {
|
|
|
+ self.dragTree.loadPostData(result);
|
|
|
+ self.filingTree.removeNode(node);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ async renameFiling(node, newName) {
|
|
|
+ return await postDataAsync('filing/save', { id: node.id, name: newName });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const levelTreeSetting = {
|
|
|
+ view: {
|
|
|
+ selectedMulti: false
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ simpleData: {
|
|
|
+ idKey: 'id',
|
|
|
+ pIdKey: 'tree_pid',
|
|
|
+ rootPId: '-1',
|
|
|
+ enable: true,
|
|
|
+ }
|
|
|
+ },
|
|
|
+ edit: {
|
|
|
+ enable: true,
|
|
|
+ showRemoveBtn: false,
|
|
|
+ showRenameBtn: function(treeId, treeNode) {
|
|
|
+ if (!canFiling) return false;
|
|
|
+ return !treeNode.source_node.is_fixed;
|
|
|
+ },
|
|
|
+ renameTitle: '编辑',
|
|
|
+ drag: {
|
|
|
+ isCopy: false,
|
|
|
+ isMove: false,
|
|
|
+ }
|
|
|
+ },
|
|
|
+ callback: {
|
|
|
+ onClick: async function (e, key, node) {
|
|
|
+ if (filingObj.curFiling && filingObj.curFiling.id === node.id) return;
|
|
|
+
|
|
|
+ filingObj.curFiling = node;
|
|
|
+ filingObj.curPage = 1;
|
|
|
+ if (filingObj.curFiling.source_node.children && filingObj.curFiling.source_node.children.length > 0) {
|
|
|
+ $('#file-view').hide();
|
|
|
+ } else {
|
|
|
+ $('#file-view').show();
|
|
|
+ await filingObj.loadFiles(node, 1);
|
|
|
+ filingObj.refreshFilesTable();
|
|
|
+ }
|
|
|
+ if (filingObj.curFiling.source_node.filing_type === 5) {
|
|
|
+ $('#rela-file').parent().show();
|
|
|
+ } else {
|
|
|
+ $('#rela-file').parent().hide();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ beforeRename: async function(key, node, newName, isCancel) {
|
|
|
+ const result = await filingObj.renameFiling(node, newName);
|
|
|
+ return !result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const filingObj = new FilingObj(levelTreeSetting);
|
|
|
+ filingObj.analysisFiling(filing);
|
|
|
+ $('#add-slibing').click(() => {
|
|
|
+ if (!filingObj.curFiling) return;
|
|
|
+ if (filingObj.curFiling.source_node.is_fixed) {
|
|
|
+ toastr.error('固定分类不可添加同级');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ filingObj.addSiblingFiling(filingObj.curFiling);
|
|
|
+ });
|
|
|
+ $('#add-child').click(() => {
|
|
|
+ if (!filingObj.curFiling) return;
|
|
|
+ if (filingObj.curFiling.source_node.file_count > 0) {
|
|
|
+ toastr.error('该分类下已导入文件,不可添加子级');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ filingObj.addChildFiling(filingObj.curFiling);
|
|
|
+ });
|
|
|
+ $('#del-filing').click(() => {
|
|
|
+ if (!filingObj.curFiling) return;
|
|
|
+ if (filingObj.curFiling.source_node.is_fixed) {
|
|
|
+ toastr.error('固定分类不可删除');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ filingObj.delFiling(filingObj.curFiling);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 授权相关
|
|
|
+ class FilingPermission {
|
|
|
+ constructor (setting) {
|
|
|
+ this.setting = setting;
|
|
|
+ const self = this;
|
|
|
+ $(setting.modal).on('show.bs.modal', () => {
|
|
|
+ self.loadPermission();
|
|
|
+ });
|
|
|
+ $(`${setting.modal}-ok`).click(() => {
|
|
|
+ self.savePermission();
|
|
|
+ });
|
|
|
+ $('[name=ftName]').click(function () {
|
|
|
+ const filingId = this.getAttribute('ftid');
|
|
|
+ self.setCurFiling(filingId);
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.book-list').on('click', 'dt', function () {
|
|
|
+ const idx = $(this).find('.acc-btn').attr('data-groupid');
|
|
|
+ const type = $(this).find('.acc-btn').attr('data-type');
|
|
|
+ if (type === 'hide') {
|
|
|
+ $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
|
|
|
+ $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
|
|
|
+ $(this).find('.acc-btn').attr('data-type', 'show')
|
|
|
+
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
|
|
|
+ $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
|
|
|
+ $(this).find('.acc-btn').attr('data-type', 'hide')
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+ $('dl').on('click', 'dd', function () {
|
|
|
+ const type = $(this).data('type');
|
|
|
+ if (type === 'all') {
|
|
|
+ const cid = parseInt($(this).data('id'));
|
|
|
+ const company = self.company.find(x => { return x.id === cid });
|
|
|
+ for (const u of company.users) {
|
|
|
+ if (u.filing_type.indexOf(self.curFiling) < 0) u.filing_type.push(self.curFiling);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const uid = $(this).data('id');
|
|
|
+ const pu = self.permissionUser.find(x => { return x.id === uid });
|
|
|
+ if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
|
|
|
+ }
|
|
|
+ self.loadCurFiling();
|
|
|
+ });
|
|
|
+ $('#sync-filing').click(function() {
|
|
|
+ const selectFiling = $('[name=cbft]:checked');
|
|
|
+ if (selectFiling.length === 0) {
|
|
|
+ toastr.warning('请先选择文档类别');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const selectFilingId = [];
|
|
|
+ selectFiling.each((i, x) => { selectFilingId.push(x.value); });
|
|
|
+ self.syncFiling(self.curFiling, selectFilingId);
|
|
|
+ toastr.success('同步成功');
|
|
|
+ $('[name=cbft]').each((i, x) => { x.checked = false; });
|
|
|
+ });
|
|
|
+ $('#batch-del-filing').click(() => {
|
|
|
+ const selectUser = $('[name=ftu-check]:checked');
|
|
|
+ if (selectUser.length === 0) {
|
|
|
+ toastr.warning('请先选择用户');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const userId = [];
|
|
|
+ selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
|
|
|
+ self.delFiling(self.curFiling, userId);
|
|
|
+ self.loadCurFiling();
|
|
|
+ });
|
|
|
+ $('body').on('click', '[name=del-filing]', function() {
|
|
|
+ const id = this.getAttribute('uid');
|
|
|
+ self.delFiling(self.curFiling, id);
|
|
|
+ self.loadCurFiling();
|
|
|
+ })
|
|
|
+ }
|
|
|
+ analysisFiling(data) {
|
|
|
+ this.permissionUser = data;
|
|
|
+ this.permissionUser.forEach(x => { x.filing_type = x.filing_type ? x.filing_type.split(',') : []; });
|
|
|
+
|
|
|
+ this.company = [];
|
|
|
+ for (const pu of this.permissionUser) {
|
|
|
+ let c = this.company.find(x => { return x.company === pu.company });
|
|
|
+ if (!c) {
|
|
|
+ c = { id: this.company.length + 1, company: pu.company, users: [] };
|
|
|
+ this.company.push(c);
|
|
|
+ }
|
|
|
+ c.users.push(pu);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ loadCurFiling() {
|
|
|
+ const html = [];
|
|
|
+ for (const f of this.permissionUser) {
|
|
|
+ if (f.filing_type.indexOf(this.curFiling) < 0) continue;
|
|
|
+ html.push('<tr>');
|
|
|
+ html.push(`<td><input uid="${f.id}" type="checkbox" name="ftu-check"></td>`);
|
|
|
+ html.push(`<td>${f.name}</td>`);
|
|
|
+ html.push(`<td>${moment(f.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
|
|
|
+ html.push(`<td>${f.file_permission}</td>`);
|
|
|
+ html.push(`<td><button class="btn btn-sm btn-outline-danger" uid="${f.id}" name="del-filing">移除</button></td>`);
|
|
|
+ html.push('</tr>');
|
|
|
+ }
|
|
|
+ $(this.setting.list).html(html.join(''));
|
|
|
+ }
|
|
|
+ setCurFiling(filingType) {
|
|
|
+ this.curFiling = filingType;
|
|
|
+ $('[name=ftName]').removeClass('bg-warning-50');
|
|
|
+ $(`[ftid=${filingType}]`).addClass('bg-warning-50');
|
|
|
+ this.loadCurFiling();
|
|
|
+ }
|
|
|
+ loadPermissionUser() {
|
|
|
+ const html = [];
|
|
|
+ for (const c of this.company) {
|
|
|
+ html.push(`<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${c.id}" data-type="hide"><i class="fa fa-plus-square"></i></a> ${c.company}</dt>`);
|
|
|
+ html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
|
|
|
+ html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${c.id}" data-type="all"><p class="mb-0 d-flex"><span class="text-primary">添加单位下全部用户</span></p></dd>`);
|
|
|
+ for (const u of c.users) {
|
|
|
+ html.push(`<dd class="border-bottom p-2 mb-0 " data-id="${u.id}" >`);
|
|
|
+ html.push(`<p class="mb-0 d-flex"><span class="text-primary">${u.name}</span><span class="ml-auto">${u.mobile}</span></p>`);
|
|
|
+ html.push(`<span class="text-muted">${u.role}</span>`);
|
|
|
+ html.push(`</dd>`);
|
|
|
+ }
|
|
|
+ html.push('</div>');
|
|
|
+ }
|
|
|
+ $('#puList').html(html.join(''));
|
|
|
+ }
|
|
|
+ loadPermission() {
|
|
|
+ const self = this;
|
|
|
+ postData('permission', {}, function(result) {
|
|
|
+ self.analysisFiling(result);
|
|
|
+ if (!self.curFiling) {
|
|
|
+ self.setCurFiling($('[name=ftName]').attr('ftid'));
|
|
|
+ } else {
|
|
|
+ self.loadCurFiling();
|
|
|
+ }
|
|
|
+ self.loadPermissionUser();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ syncFiling(sourceId, targetIds) {
|
|
|
+ for (const pu of this.permissionUser) {
|
|
|
+ if (pu.filing_type.indexOf(sourceId) >= 0) {
|
|
|
+ targetIds.forEach(id => {
|
|
|
+ if (pu.filing_type.indexOf(id) < 0) pu.filing_type.push(id);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ targetIds.forEach(id => {
|
|
|
+ if (pu.filing_type.indexOf(id) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(id), 1);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ delFiling(filingId, userId) {
|
|
|
+ const userIds = userId instanceof Array ? userId : [userId];
|
|
|
+ for (const id of userIds) {
|
|
|
+ const pu = this.permissionUser.find(x => { return x.id === id });
|
|
|
+ if (!pu) continue;
|
|
|
+ if (pu.filing_type.indexOf(filingId) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(filingId), 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ savePermission() {
|
|
|
+ const self = this;
|
|
|
+ const data = this.permissionUser.map(x => {
|
|
|
+ return { id: x.id, filing_type: x.filing_type.join(',') };
|
|
|
+ });
|
|
|
+ postData('permission/save', data, function(result) {
|
|
|
+ $(self.setting.modal).modal('hide');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const filingPermission = new FilingPermission({
|
|
|
+ modal: '#filing-permission',
|
|
|
+ list: '#filing-valid',
|
|
|
+ });
|
|
|
+});
|