|
@@ -20,9 +20,7 @@ $(document).ready(function() {
|
|
|
this.expandCache = cache ? _.uniq(cache.split(',')) : [];
|
|
|
this.curFilingKey = 'cur-filing-' + window.location.pathname.split('/')[2];
|
|
|
}
|
|
|
- analysisFiling(data) {
|
|
|
- const self = this;
|
|
|
- this.dragTree.loadDatas(data);
|
|
|
+ calcTotalFileCount() {
|
|
|
this.dragTree.recursiveFun(this.dragTree.children, x => {
|
|
|
if (x.children && x.children.length > 0) {
|
|
|
x.total_file_count = x.children.map(y => {
|
|
@@ -34,19 +32,34 @@ $(document).ready(function() {
|
|
|
x.total_file_count = x.file_count;
|
|
|
}
|
|
|
});
|
|
|
+ }
|
|
|
+ _loadFilingSourceNode() {
|
|
|
+ const self = this;
|
|
|
+ const loadChildren = function(children) {
|
|
|
+ for (const child of children) {
|
|
|
+ if (child.children && child.children.length > 0) loadChildren(child.children);
|
|
|
+ child.source_node = self.dragTree.getItems(child.id);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const nodes = this.filingTree.getNodes();
|
|
|
+ loadChildren(nodes);
|
|
|
+ }
|
|
|
+ loadFiling() {
|
|
|
+ const self = this;
|
|
|
+ if (this.filingTree) $.fn.zTree.destroy(this.setting.treeId);
|
|
|
const sortNodes = this.dragTree.nodes.map(x => {
|
|
|
const result = {
|
|
|
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,
|
|
|
};
|
|
|
- if (result.source_node.is_fixed) result.isParent = true;
|
|
|
- if (result.source_node.is_folder || result.source_node.is_fixed) result.open = self.expandCache.indexOf(result.id) >= 0;
|
|
|
+ if (x.is_fixed) result.isParent = true;
|
|
|
+ if (x.is_folder || x.is_fixed) result.open = self.expandCache.indexOf(result.id) >= 0;
|
|
|
return result;
|
|
|
});
|
|
|
this.filingTree = $.fn.zTree.init($('#filing'), this.setting, sortNodes);
|
|
|
+ this._loadFilingSourceNode();
|
|
|
const curCache = getLocalCache(this.curFilingKey);
|
|
|
const curNode = curCache ? this.filingTree.getNodeByParam('id', curCache) : null;
|
|
|
if (curNode){
|
|
@@ -54,6 +67,11 @@ $(document).ready(function() {
|
|
|
filingObj.setCurFiling(curNode);
|
|
|
}
|
|
|
}
|
|
|
+ analysisFiling(data) {
|
|
|
+ this.dragTree.loadDatas(data);
|
|
|
+ this.calcTotalFileCount();
|
|
|
+ this.loadFiling();
|
|
|
+ }
|
|
|
_getFileNameHtml(file) {
|
|
|
const editHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
|
|
|
const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
|
|
@@ -133,7 +151,8 @@ $(document).ready(function() {
|
|
|
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() + 1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid, source_node: newNode}]);
|
|
|
+ const nodes = self.filingTree.addNodes(node.getParentNode(), node.getIndex() + 1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid }]);
|
|
|
+ nodes[0].source_node = newNode;
|
|
|
});
|
|
|
}
|
|
|
addChildFiling(node) {
|
|
@@ -141,7 +160,8 @@ $(document).ready(function() {
|
|
|
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}]);
|
|
|
+ const nodes = self.filingTree.addNodes(node, -1, [{ id: newNode.id, tree_pid: newNode.tree_pid, name: newNode.name, spid: newNode.spid}]);
|
|
|
+ nodes[0].source_node = newNode;
|
|
|
});
|
|
|
}
|
|
|
delFiling(node, callback) {
|
|
@@ -305,16 +325,25 @@ $(document).ready(function() {
|
|
|
}
|
|
|
setLocalCache(this.expandKey, this.expandCache.join(','));
|
|
|
}
|
|
|
- moveFiling(node, tree_order) {
|
|
|
- if (tree_order === node.source_node.tree_order) return;
|
|
|
+ moveFiling(node, tree_pid, tree_order) {
|
|
|
+ if (tree_pid === node.source_node.tree_pid && tree_order === node.source_node.tree_order) return;
|
|
|
|
|
|
const self = this;
|
|
|
- postData('filing/move', { id: node.id, tree_order }, function(result) {
|
|
|
- self.dragTree.loadPostData(result);
|
|
|
+ postData('filing/move', { id: node.id, tree_pid, tree_order }, function(result) {
|
|
|
+ const refresh = self.dragTree.loadPostData(result);
|
|
|
+ self.calcTotalFileCount();
|
|
|
+ for (const u of refresh.update) {
|
|
|
+ const node = self.filingTree.getNodeByParam('id', u.id);
|
|
|
+ if (node) {
|
|
|
+ node.name = node.source_node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
|
|
|
+ filingObj.filingTree.updateNode(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
const levelTreeSetting = {
|
|
|
+ treeId: 'filing',
|
|
|
view: {
|
|
|
selectedMulti: false
|
|
|
},
|
|
@@ -375,14 +404,44 @@ $(document).ready(function() {
|
|
|
},
|
|
|
beforeDrop: function(key, nodes, target, moveType, isCopy) {
|
|
|
if (!target) return false;
|
|
|
- if (nodes[0].tree_pid !== target.tree_pid) return false;
|
|
|
+ if (nodes[0].level < 1) {
|
|
|
+ toastr.error('顶层节点请勿移动');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (nodes[0].source_node.filing_type !== target.source_node.filing_type) {
|
|
|
+ toastr.error('请勿跨越最顶层节点移动');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (target.source_node.file_count > 0 && moveType === 'inner') {
|
|
|
+ toastr.error(`节点[${target.source_node.name}]下存在文件,不可添加子级`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- const order = target.getIndex() + 1;
|
|
|
- const max = target.getParentNode().children.length;
|
|
|
+ const order = nodes[0].getIndex() + 1;
|
|
|
+ const targetOrder = target.getIndex() + 1;
|
|
|
+ const targetMax = target.getParentNode().children.length;
|
|
|
if (moveType === 'prev') {
|
|
|
- filingObj.moveFiling(nodes[0], order === 1 ? 1 : order - 1)
|
|
|
+ if (target.tree_pid === nodes[0].tree_pid) {
|
|
|
+ if (targetOrder > order) {
|
|
|
+ filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder - 1);
|
|
|
+ } else {
|
|
|
+ filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === 1 ? 1 : targetOrder);
|
|
|
+ }
|
|
|
} else if (moveType === 'next') {
|
|
|
- filingObj.moveFiling(nodes[0], order === max ? max : order + 1);
|
|
|
+ if (target.tree_pid === nodes[0].tree_pid) {
|
|
|
+ if (targetOrder < order) {
|
|
|
+ filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder + 1);
|
|
|
+ } else {
|
|
|
+ filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder === targetMax ? targetMax : targetOrder);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ filingObj.moveFiling(nodes[0], target.tree_pid, targetOrder + 1);
|
|
|
+ }
|
|
|
+ } else if (moveType === 'inner') {
|
|
|
+ filingObj.moveFiling(nodes[0], target.tree_id, targetMax + 1);
|
|
|
}
|
|
|
}
|
|
|
}
|