|
@@ -1,4 +1,5 @@
|
|
|
$(document).ready(function() {
|
|
|
+ let fileSearch;
|
|
|
autoFlashHeight();
|
|
|
$('#filing').height($(".sjs-height-0").height() - $('#add-slibing').parent().parent().height() - 10);
|
|
|
class FilingObj {
|
|
@@ -288,34 +289,35 @@ $(document).ready(function() {
|
|
|
}
|
|
|
delFiles(files, callback) {
|
|
|
postData('file/del', { del: files }, async function(data) {
|
|
|
+ const relaFiling = data.filing.id === filingObj.curFiling.source_node.id
|
|
|
+ ? filingObj.curFiling : filingObj.findFiling(data.filing.id);
|
|
|
for (const id of data.del) {
|
|
|
- const fIndex = filingObj.curFiling.source_node.files.findIndex(x => { return x.id === id });
|
|
|
- if (fIndex >= 0) filingObj.curFiling.source_node.files.splice(fIndex, 1);
|
|
|
+ const fIndex = relaFiling.source_node.files.findIndex(x => { return x.id === id });
|
|
|
+ if (fIndex >= 0) relaFiling.source_node.files.splice(fIndex, 1);
|
|
|
+ fileSearch.removeSearchFile(id);
|
|
|
+ }
|
|
|
+ filingObj.updateFilingFileCount(relaFiling, data.filing.file_count);
|
|
|
+ await filingObj.loadFiles(relaFiling, filingObj.curPage);
|
|
|
+ if (data.filing.id === filingObj.curFiling.source_node.id) {
|
|
|
+ filingObj.refreshPages();
|
|
|
+ filingObj.refreshFilesTable();
|
|
|
}
|
|
|
- filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
|
|
|
- await filingObj.loadFiles(filingObj.curFiling, filingObj.curPage);
|
|
|
- filingObj.refreshPages();
|
|
|
- filingObj.refreshFilesTable();
|
|
|
if (callback) callback();
|
|
|
});
|
|
|
}
|
|
|
- renameFile(fileId, filename) {
|
|
|
+ renameFile(file, filename) {
|
|
|
const self = this;
|
|
|
- const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fileId });
|
|
|
- if (!file) return;
|
|
|
-
|
|
|
- const td = $(`td[fid=${fileId}]`);
|
|
|
- if (filename === file.filename + file.fileext) {
|
|
|
- td.html(this._getFileNameHtml(file));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- postData('file/save', { id: fileId, filename }, function(data) {
|
|
|
- file.filename = data.filename;
|
|
|
- file.fileext = data.fileext;
|
|
|
- td.html(self._getFileNameHtml(file));
|
|
|
+ const td = $(`td[fid=${file.id}]`);
|
|
|
+ postData('file/save', { id: file.id, filename }, function(data) {
|
|
|
+ const relaFiling = filingObj.findFiling(file.filing_id);
|
|
|
+ const relaFile = relaFiling.source_node.files.find(x => { return x.id === file.id });
|
|
|
+ relaFile.filename = data.filename;
|
|
|
+ relaFile.fileext = data.fileext;
|
|
|
+ td.html(self._getFileNameHtml(relaFile));
|
|
|
+ fileSearch.renameSearchFile(file.id, data);
|
|
|
}, function() {
|
|
|
td.html(self._getFileNameHtml(file));
|
|
|
+ fileSearch.renameSearchFile(file.id);
|
|
|
});
|
|
|
}
|
|
|
relaFiles(files, callback) {
|
|
@@ -346,6 +348,9 @@ $(document).ready(function() {
|
|
|
}
|
|
|
setLocalCache(this.curFilingKey, filingObj.curFiling.id);
|
|
|
}
|
|
|
+ findFiling(id) {
|
|
|
+ return filingObj.filingTree.getNodeByParam('id', id);
|
|
|
+ }
|
|
|
prePage() {
|
|
|
if (this.curPage === 1) return;
|
|
|
this.curPage = this.curPage - 1;
|
|
@@ -435,6 +440,37 @@ $(document).ready(function() {
|
|
|
this._clearAllFileCache();
|
|
|
this.setCurFiling(this.curFiling);
|
|
|
}
|
|
|
+ getNodeFilingType(node) {
|
|
|
+ if (!node.is_fixed) return [];
|
|
|
+
|
|
|
+ const types = [];
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ for (const child of node.children) {
|
|
|
+ const childTypes = this.getNodeFilingType(child);
|
|
|
+ if (childTypes.length > 0) types.push(...childTypes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (types.length === 0) types.push(node.filing_type);
|
|
|
+ return types;
|
|
|
+ }
|
|
|
+ getParentFilingType(node) {
|
|
|
+ const parent = this.dragTree.getParent(node);
|
|
|
+ if (!parent) return [];
|
|
|
+ if (parent.is_fixed) return [parent.filing_type];
|
|
|
+ return this.getParentFilingType(parent);
|
|
|
+ }
|
|
|
+ getAllFilingType() {
|
|
|
+ const types = [];
|
|
|
+ for (const node of this.dragTree.children) {
|
|
|
+ types.push(...this.getNodeFilingType(node))
|
|
|
+ }
|
|
|
+ return types;
|
|
|
+ }
|
|
|
+ getCurFilingType() {
|
|
|
+ const cur = filingObj.curFiling;
|
|
|
+ const node = this.dragTree.nodes.find(x => { return x.id === cur.source_node.id; });
|
|
|
+ return node.is_fixed ? this.getNodeFilingType(node) : this.getParentFilingType(node);
|
|
|
+ }
|
|
|
}
|
|
|
const levelTreeSetting = {
|
|
|
treeId: 'filing',
|
|
@@ -662,7 +698,13 @@ $(document).ready(function() {
|
|
|
const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
|
|
|
if (!file) return;
|
|
|
|
|
|
- filingObj.renameFile(fid, $('input', td).val());
|
|
|
+ const filename = $('input', td).val();
|
|
|
+ if (filename === file.filename + file.fileext) {
|
|
|
+ td.html(this._getFileNameHtml(file));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ filingObj.renameFile(file, filename);
|
|
|
});
|
|
|
$('body').on('click', "a[name=edit-file-cancel]", function() {
|
|
|
const td = $(this).parent().parent().parent();
|
|
@@ -1218,6 +1260,164 @@ $(document).ready(function() {
|
|
|
list: '#filing-valid',
|
|
|
});
|
|
|
|
|
|
+ class FileSearch {
|
|
|
+ constructor() {
|
|
|
+ this.searchResult = [];
|
|
|
+ this.initSearch();
|
|
|
+ }
|
|
|
+ getOperateHtml(file) {
|
|
|
+ const locateHtml = `<a href="javascript: void(0);" class="mr-1" name="locate-search-file" fid="${file.id}"><i class="fa fa-crosshairs"></i></a>`;
|
|
|
+ const editHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-search-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>` : '';
|
|
|
+ const downHtml = `<a href="javascript: void(0);" onclick="AliOss.downloadFile('${file.filepath}', '${file.filename + file.fileext}')" class="mr-1"><i class="fa fa-download fa-fw"></i></a>`;
|
|
|
+ const delHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-search-file" fid="${file.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
|
|
|
+ return `<div class="d-flex justify-content-between align-items-center table-file">${locateHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div>`
|
|
|
+ }
|
|
|
+ getFileHtml(file) {
|
|
|
+ const html = [];
|
|
|
+ html.push(`<tr fid="search_${file.id}">`);
|
|
|
+ html.push(`<td fid="search_${file.id}">${file.filename}${file.fileext}</td>`);
|
|
|
+ html.push(`<td class="text-center">${file.user_name}</td>`);
|
|
|
+ html.push(`<td class="text-center">${this.getOperateHtml(file)}</td>`);
|
|
|
+ html.push('</tr>');
|
|
|
+ return html.join('');
|
|
|
+ }
|
|
|
+ getResultHtml (result) {
|
|
|
+ this.searchResult = result;
|
|
|
+ const html = [];
|
|
|
+ for (const r of result) {
|
|
|
+ html.push(this.getFileHtml(r));
|
|
|
+ }
|
|
|
+ return html.join('');
|
|
|
+ }
|
|
|
+ getSearchFilter() {
|
|
|
+ const filter = $('#search-filter').val();
|
|
|
+ const filing_type = filter === 'all' ? filingObj.getAllFilingType() : filingObj.getCurFilingType();
|
|
|
+ return { filing_type };
|
|
|
+ }
|
|
|
+ getEditFileNameHtml(file) {
|
|
|
+ const inputHtml = `<input type="text" class="form-control form-control-sm form-control-s-width" maxlength="100" value="${file.filename + file.fileext}" fid="${file.id}">`;
|
|
|
+ const btnHtml = `<div class="btn-group-table" style="display: none;"><a href="javascript: void(0)" class="mr-1" name="edit-search-file-ok"><i class="fa fa-check fa-fw"></i></a><a href="javascript: void(0)" class="mr-1" name="edit-search-file-cancel"><i class="fa fa-remove fa-fw"></i></a></div>`;
|
|
|
+ return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
|
|
|
+ }
|
|
|
+ search() {
|
|
|
+ const searchData = this.getSearchFilter();
|
|
|
+ searchData.keyword = $('#search-keyword', '#search').val();
|
|
|
+ if (!searchData.keyword) {
|
|
|
+ toastr.warning('请输入查询的文件名称');
|
|
|
+ this.getResultHtml([]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ postData(window.location.pathname + '/search', searchData, function(result) {
|
|
|
+ if (result.list.length === result.limit) toastr.warning(`最多查询${result.limit}个结果,请给出更准确的文件名称`);
|
|
|
+ $('#search-list').html(fileSearch.getResultHtml(result.list));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ removeSearchFile(fid){
|
|
|
+ $(`tr[fid=search_${fid}]`, '#search').remove();
|
|
|
+ const index = this.searchResult.findIndex(x => { return x.id === fid; });
|
|
|
+ this.searchResult.splice(index, 1);
|
|
|
+ }
|
|
|
+ renameSearchFile(fid, data) {
|
|
|
+ const file = this.searchResult.find(x => { return x.id === fid; });
|
|
|
+ if (file) {
|
|
|
+ file.filename = data.filename;
|
|
|
+ file.fileext = data.fileext;
|
|
|
+ const td = $(`td[fid=search_${file.id}]`);
|
|
|
+ td.html(`${file.filename}${file.fileext}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ initSearch() {
|
|
|
+ const self = this;
|
|
|
+ $.divResizer({
|
|
|
+ select: '#right-spr',
|
|
|
+ callback: function() {},
|
|
|
+ });
|
|
|
+ $('input', '#search').bind('keydown', function (e) {
|
|
|
+ if (e.keyCode == 13) self.search();
|
|
|
+ });
|
|
|
+ $('button', '#search').bind('click', () => { self.search(); });
|
|
|
+ $('body').on('click', "a[name=del-search-file]", function() {
|
|
|
+ const del = [this.getAttribute('fid')];
|
|
|
+ filingObj.delFiles(del);
|
|
|
+ });
|
|
|
+ $('body').on('click', "a[name=locate-search-file]", function() {
|
|
|
+ const fid = this.getAttribute('fid');
|
|
|
+ const file = self.searchResult.find(x => { return x.id === fid});
|
|
|
+ const filing = filingObj.findFiling(file.filing_id);
|
|
|
+ filingObj.filingTree.selectNode(filing);
|
|
|
+ filingObj.setCurFiling(filing);
|
|
|
+ });
|
|
|
+ $('body').on('click', "a[name=edit-search-file]", function() {
|
|
|
+ const check = $('[name=search-filename] input[fid]');
|
|
|
+ if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
|
|
|
+
|
|
|
+ const id = this.getAttribute('fid');
|
|
|
+ const file = self.searchResult.find(x => { return x.id === id });
|
|
|
+ $(`td[fid=search_${id}]`).html(self.getEditFileNameHtml(file));
|
|
|
+ });
|
|
|
+ $('body').on('click', "a[name=edit-search-file-ok]", function() {
|
|
|
+ const td = $(this).parent().parent().parent();
|
|
|
+ const fid = td.attr('fid').split('_')[1];
|
|
|
+ const file = self.searchResult.find(x => { return x.id === fid });
|
|
|
+ if (!file) return;
|
|
|
+
|
|
|
+ filingObj.renameFile(file, $('input', td).val());
|
|
|
+ });
|
|
|
+ $('body').on('click', "a[name=edit-search-file-cancel]", function() {
|
|
|
+ const td = $(this).parent().parent().parent();
|
|
|
+ const fid = td.attr('fid').split('_')[1];
|
|
|
+ const file = self.searchResult.find(x => { return x.id === fid });
|
|
|
+ if (!file) return;
|
|
|
+
|
|
|
+ td.html(`${file.filename}${file.fileext}`);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fileSearch = new FileSearch();
|
|
|
+ const showSideTools = function (show) {
|
|
|
+ const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
|
|
|
+ if (show) {
|
|
|
+ right.show();
|
|
|
+ autoFlashHeight();
|
|
|
+ /**
|
|
|
+ * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
|
|
|
+ * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
|
|
|
+ * 故需要通过最终的parent.width再计算一次left.width
|
|
|
+ *
|
|
|
+ * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
|
|
|
+ * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
|
|
|
+ *
|
|
|
+ */
|
|
|
+ //left.css('width', parent.width() - right.outerWidth());
|
|
|
+ //left.css('width', parent.width() - right.outerWidth());
|
|
|
+ const percent = 100 - right.outerWidth() /parent.width() * 100;
|
|
|
+ left.css('width', percent + '%');
|
|
|
+ } else {
|
|
|
+ left.width(parent.width());
|
|
|
+ right.hide();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 展开收起标准清单
|
|
|
+ $('a', '#side-menu').bind('click', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ const tab = $(this), tabPanel = $(tab.attr('content'));
|
|
|
+ // 展开工具栏、切换标签
|
|
|
+ if (!tab.hasClass('active')) {
|
|
|
+ // const close = $('.active', '#side-menu').length === 0;
|
|
|
+ $('a', '#side-menu').removeClass('active');
|
|
|
+ $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
|
|
|
+ tab.addClass('active');
|
|
|
+ tabPanel.addClass('active');
|
|
|
+ // $('.tab-content .tab-pane').removeClass('active');
|
|
|
+ showSideTools(tab.hasClass('active'));
|
|
|
+ } else { // 收起工具栏
|
|
|
+ tab.removeClass('active');
|
|
|
+ tabPanel.removeClass('active');
|
|
|
+ showSideTools(tab.hasClass('active'));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
// 显示层次
|
|
|
(function (select) {
|
|
|
$(select).click(function () {
|