123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770 |
- $(document).ready(function() {
- let fileSearch, fileReference;
- autoFlashHeight();
- $('#filing').height($(".sjs-height-0").height() - $('#add-slibing').parent().parent().height() - 10);
- 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;
- this.expandKey = 'filing-' + window.location.pathname.split('/')[2];
- const cache = getLocalCache(this.expandKey);
- this.expandCache = cache ? _.uniq(cache.split(',')) : [];
- this.curFilingKey = 'cur-filing-' + window.location.pathname.split('/')[2];
- $('#filing').height($(".sjs-height-0").height()-$('.d-flex',".sjs-height-0").height() - 10);
- this.fileOrderKey = 'fileOrder';
- this.fileOrder = getLocalCache(this.fileOrderKey) || 'create_time|desc';
- }
- refreshFileOrderButton() {
- const orderBy = this.fileOrder.split('|');
- const field = orderBy[0], sort = orderBy[1];
- const buttons = $('[name=file-sort]');
- for (const b of buttons) {
- const curField = b.getAttribute('field');
- if (curField === field) {
- $(b).html(`<i class="fa fa-sort-amount-${sort}" aria-hidden="true"></i>`).attr('tag', `${curField}|${sort === 'asc' ? 'desc' : 'asc'}`);
- } else {
- $(b).html('<i class="fa fa-sort" aria-hidden="true">').attr('tag', `${curField}|desc`);
- }
- }
- }
- refreshFileCountHint() {
- const sum = _.sum(this.dragTree.children.map(x => { return x.file_count}));
- $('#file-count').html(`文件总数:${sum}`);
- }
- calcTotalFileCount() {
- this.dragTree.recursiveFun(this.dragTree.children, x => {
- if (x.children && x.children.length > 0) {
- x.total_file_count = x.children.reduce((pre, c) => {
- if (x.filing_type === 1) console.log('reduce', c.name, c.total_file_count);
- return pre + c.total_file_count
- }, 0);
- } else {
- x.total_file_count = x.file_count || 0;
- }
- if (x.filing_type === 1) console.log(x.name, x.total_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,
- tips: x.tips || '',
- };
- 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){
- this.filingTree.selectNode(curNode);
- filingObj.setCurFiling(curNode);
- }
- }
- analysisFiling(data) {
- this.dragTree.loadDatas(data);
- this.calcTotalFileCount();
- this.loadFiling();
- this.refreshFileCountHint();
- }
- _getFileNameHtml(file) {
- const moveHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="move-file" fid="${file.id}"><i class="fa fa-exchange fa-fw"></i></a>` : '';
- 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>` : '';
- 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 || canDelete ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-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"><div name="filename" fid="${file.id}">${file.filename}${file.fileext}</div><div class="btn-group-table" style="display: none;">${moveHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div></div>`;
- }
- _getEditFileNameHtml(file) {
- const inputHtml = `<input type="text" class="form-control form-control-sm form-control-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-file-ok"><i class="fa fa-check fa-fw"></i></a><a href="javascript: void(0)" class="mr-1" name="edit-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>`;
- }
- _getFileHtml(file) {
- const html = [];
- html.push(`<tr fid="${file.id}">`);
- html.push(`<td class="text-center"><input type="checkbox" name="bd-check" fid="${file.id}"></td>`);
- html.push(`<td fid="${file.id}">${this._getFileNameHtml(file)}</td>`);
- html.push(`<td class="text-center">${file.user_name}</td>`);
- html.push(`<td class="text-center">${moment(file.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
- html.push(`<td class="text-center">${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) {
- $('#file-list').html('');
- 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(''));
- }
- refreshPages() {
- if (!filingObj.curFiling) return;
- filingObj.curTotalPage = Math.ceil(filingObj.curFiling.source_node.file_count / this.pageCount);
- filingObj.curPage = Math.min(filingObj.curTotalPage, Math.max(filingObj.curPage, 1));
- $('#curPage').html(filingObj.curPage);
- $('#curTotalPage').html(filingObj.curTotalPage);
- if (filingObj.curTotalPage > 1) {
- $('#showPage').show();
- } else {
- $('#showPage').hide();
- }
- }
- async loadFiles(node, page) {
- if (node.source_node.children && node.source_node.children.length > 0) return;
- if (!node.source_node.files) node.source_node.files = [];
- if (!node.source_node.file_count) return;
- if (node.source_node.files && node.source_node.files.length === node.source_node.file_count) return;
- const needFiles = Math.min(page*this.pageCount, node.source_node.file_count);
- if (node.source_node.files && needFiles <= node.source_node.files.length) return;
- const files = await postDataAsync('file/load', { filing_id: node.id, page, count: this.pageCount, order: this.fileOrder });
- files.forEach(x => {
- const file = node.source_node.files.find(f => {return x.id === f.id; });
- if (file) {
- Object.assign(file, x);
- } else {
- node.source_node.files.push(x);
- }
- });
- // 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];
- 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) {
- const self = this;
- postData('filing/add', { tree_pid: node.id }, function(result) {
- const refreshData = self.dragTree.loadPostData(result);
- const newNode = refreshData.create[0];
- 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) {
- const parent = node.getParentNode();
- const self = this;
- postData('filing/del', { id: node.id }, function(result) {
- self.updateFilingFileCount(node, 0);
- self.dragTree.loadPostData(result);
- self.filingTree.removeNode(node);
- self.calcTotalFileCount();
- if (parent) {
- const path = parent.getPath();
- for (const p of path) {
- p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
- if (p.source_node.is_fixed) p.isParent = true;
- filingObj.filingTree.updateNode(p);
- }
- }
- if (callback) callback();
- });
- }
- async renameFiling(node, newName) {
- const result = await postDataAsync('filing/save', { id: node.id, name: newName });
- node.source_node.name = newName;
- node.name = node.source_node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
- return result;
- }
- updateFilingFileCount(filing, count) {
- let differ = count - (filing.source_node.file_count || 0);
- filing.source_node.file_count = count;
- filing.source_node.total_file_count = count;
- filing.name = filing.source_node.name + (filing.source_node.total_file_count > 0 ? `(${filing.source_node.total_file_count})` : '');
- filingObj.filingTree.updateNode(filing);
- let parent = filing.getParentNode();
- while (!!parent) {
- parent.source_node.total_file_count = parent.source_node.total_file_count ? parent.source_node.total_file_count + differ : differ;
- parent.name = parent.source_node.name + (parent.source_node.total_file_count > 0 ? `(${parent.source_node.total_file_count})` : '');
- filingObj.filingTree.updateNode(parent);
- parent = parent.getParentNode();
- }
- }
- checkFilesExist(files, callback) {
- const data = [];
- for (const file of files) {
- if (file === undefined) return [];
- data.push(file.name);
- }
- postData('file/check', { filing_id: filingObj.curFiling.id, files: data }, function(result) {
- callback(result);
- });
- }
- uploadFiles(files, filterFiles, callback) {
- const formData = new FormData();
- formData.append('filing_id', filingObj.curFiling.id);
- let count = 0;
- for (const file of files) {
- if (filterFiles.indexOf(file.name) >= 0) continue;
- if (file === undefined) {
- toastr.error('未选择上传文件。');
- return false;
- }
- if (file.size > 50 * 1024 * 1024) {
- toastr.error('上传文件大小超过50MB。');
- return false;
- }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
- return false;
- }
- formData.append('size', file.size);
- formData.append('file[]', file);
- count++;
- }
- if (count === 0) {
- toastr.warning('没有可上传的文件');
- return false;
- }
- postDataWithFile('file/upload', formData, function (data) {
- filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
- filingObj.curFiling.source_node.files.unshift(...data.files);
- filingObj.refreshPages();
- filingObj.refreshFilesTable();
- filingObj.refreshFileCountHint();
- if (callback) callback();
- });
- }
- uploadBigFile(file, callback) {
- if (file.size > 500 * 1024 * 1024) {
- toastr.error('上传文件大小超过500MB。');
- return false;
- }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
- return false;
- }
- AliOss.uploadBigFile(file, 'file/upload/big', { filing_id: filingObj.curFiling.id },
- { progressObj: $('#upload-big-file-progress'), resumeObj: $('#add-big-file-resume'), stopObj: $('#add-big-file-stop') },
- function(result) {
- filingObj.curFiling.source_node.files.unshift(...result.files);
- filingObj.updateFilingFileCount(filingObj.curFiling, result.filing.file_count);
- filingObj.refreshPages();
- filingObj.refreshFilesTable();
- filingObj.refreshFileCountHint();
- if (callback) callback();
- });
- }
- 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 = 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.refreshFileCountHint();
- }
- if (callback) callback();
- });
- }
- renameFile(file, filename) {
- const self = this;
- 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) {
- postData('file/rela', { filing_id: this.curFiling.id, files: files }, async function(data) {
- filingObj.curFiling.source_node.files.unshift(...data.files);
- filingObj.updateFilingFileCount(filingObj.curFiling, data.filing.file_count);
- filingObj.refreshFilesTable();
- filingObj.refreshFileCountHint();
- filingObj.refreshPages();
- if (callback) callback();
- });
- }
- moveFile(file, filingId, callback) {
- if (file.filing_id === filingId) {
- callback();
- return;
- }
- postData('file/move', { id: file.id, filingId: filingId }, function(data) {
- const orgFiling = filingObj.findFiling(file.filing_id);
- filingObj.updateFilingFileCount(orgFiling, orgFiling.source_node.file_count - 1);
- const fIndex = orgFiling.source_node.files.findIndex(x => { return x.id === file.id });
- if (fIndex >= 0) orgFiling.source_node.files.splice(fIndex, 1);
- const targetFiling = filingObj.findFiling(filingId);
- filingObj.updateFilingFileCount(targetFiling, targetFiling.source_node.file_count + 1);
- if (file.filing_id === filingObj.curFiling.source_node.id) {
- filingObj.refreshPages();
- filingObj.refreshFilesTable();
- }
- fileSearch.refreshSearchFile(data.file);
- callback();
- });
- }
- async setCurFiling(node) {
- filingObj.curFiling = node;
- filingObj.curPage = 1;
- filingObj.refreshPages();
- 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-btn').show();
- } else {
- $('#rela-file-btn').hide();
- }
- 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;
- this.refreshPages();
- this.refreshFilesTable();
- }
- async nextPage() {
- if (this.curPage === this.curTotalPage) return;
- await filingObj.loadFiles(this.curFiling, this.curPage + 1);
- this.curPage = this.curPage + 1;
- this.refreshPages();
- this.refreshFilesTable();
- }
- getCurFilingFullPath(){
- let cur = filingObj.curFiling;
- const result = [];
- while (cur) {
- result.unshift(cur.source_node.name);
- cur = cur.getParentNode();
- }
- return result.join('/');
- }
- expandFiling(node, expand) {
- if (expand) {
- this.expandCache.push(node.id);
- } else{
- this.expandCache = this.expandCache.filter(x => { return x !== node.id });
- }
- setLocalCache(this.expandKey, this.expandCache.join(','));
- }
- expandByLevel(level) {
- this.expandByCustom(x => {
- return x.level + 1 < level;
- })
- }
- expandByCustom(fun) {
- const self = this;
- const expandCache = [];
- const expandChildren = function(children) {
- for (const child of children) {
- if (!child.children || child.children.length === 0) continue;
- const expand = fun(child);
- if (expand) expandCache.push(child.id);
- self.filingTree.expandNode(child, expand, false, false);
- expandChildren(child.children);
- }
- };
- const nodes = this.filingTree.getNodes();
- expandChildren(nodes);
- this.expandCache = expandCache;
- setLocalCache(this.expandKey, this.expandCache.join(','));
- }
- 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_pid, tree_order }, function(result) {
- const refresh = self.dragTree.loadPostData(result);
- self.calcTotalFileCount();
- const updated = [];
- for (const u of refresh.update) {
- const node = self.filingTree.getNodeByParam('id', u.id);
- if (node) {
- const path = node.getPath();
- for (const p of path) {
- if (updated.indexOf(p.id) >= 0) continue;
- p.name = p.source_node.name + (p.source_node.total_file_count > 0 ? `(${p.source_node.total_file_count})` : '');
- filingObj.filingTree.updateNode(p);
- updated.push(p.id);
- }
- }
- }
- });
- }
- _clearAllFileCache() {
- const nodes = this.filingTree.getNodes();
- for (const node of nodes) {
- if (node.children && node.children.length > 0) continue;
- if (node.source_node.files) node.source_node.files.length = 0;
- }
- }
- changeFileOrder(fileOrder) {
- this.fileOrder = fileOrder;
- setLocalCache(this.fileOrderKey, fileOrder);
- this.refreshFileOrderButton();
- 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',
- view: {
- selectedMulti: false,
- showTitle: true,
- },
- data: {
- simpleData: {
- idKey: 'id',
- pIdKey: 'tree_pid',
- rootPId: '-1',
- enable: true,
- },
- key: { title: 'tips' },
- },
- edit: {
- enable: true,
- showRemoveBtn: function(treeId, treeNode) {
- if (!canFiling) return false;
- return !treeNode.source_node.is_fixed;
- },
- showRenameBtn: function(treeId, treeNode) {
- if (!canFiling) return false;
- return !treeNode.source_node.is_fixed;
- },
- renameTitle: '编辑',
- removeTitle: '删除',
- drag: {
- isCopy: false,
- isMove: true,
- pre: true,
- next: true,
- inner: false,
- },
- editNameSelectAll: true,
- },
- callback: {
- onClick: async function (e, key, node) {
- if (filingObj.curFiling && filingObj.curFiling.id === node.id) return;
- filingObj.setCurFiling(node);
- },
- beforeEditName: function(key, node) {
- node.name = node.source_node.name;
- },
- beforeRename: async function(key, node, newName, isCancel) {
- if (!isCancel) await filingObj.renameFiling(node, newName);
- return true;
- },
- onRename: function(e, key, node, isCancel) {
- node.name = node.name + (node.source_node.total_file_count > 0 ? `(${node.source_node.total_file_count})` : '');
- filingObj.filingTree.updateNode(node);
- },
- beforeRemove: function(key, node, isCancel) {
- $('#del-filing').modal('show');
- return false;
- },
- onExpand(e, key, node) {
- filingObj.expandFiling(node, true);
- },
- onCollapse: function(e, key, node) {
- filingObj.expandFiling(node, false);
- },
- beforeDrop: function(key, nodes, target, moveType, isCopy) {
- if (!canFiling) return false;
- if (!target) return false;
- if (nodes[0].level < 1) {
- toastr.error('顶层节点请勿移动');
- return false;
- }
- if (nodes[0].is_fixed) {
- 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 = nodes[0].getIndex() + 1;
- const targetOrder = target.getIndex() + 1;
- const targetMax = target.getParentNode().children.length;
- if (moveType === 'prev') {
- 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') {
- 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);
- }
- }
- }
- };
- 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;
- const fixedChild = filingObj.curFiling.source_node.children.find(x => { return x.is_fixed; });
- if (fixedChild) {
- toastr.error('该分类下存在固定分类,不可添加子级');
- return;
- }
- if (filingObj.curFiling.source_node.file_count > 0) {
- toastr.error('该分类下已导入文件,不可添加子级');
- return;
- }
- filingObj.addChildFiling(filingObj.curFiling);
- });
- $('[name=file-sort]').click(function() {
- const tag = this.getAttribute('tag');
- filingObj.changeFileOrder(tag);
- });
- // $('#del-filing-btn').click(() => {
- // if (!filingObj.curFiling) return;
- // if (filingObj.curFiling.source_node.is_fixed) {
- // toastr.error('固定分类不可删除');
- // return;
- // }
- //
- // $('#del-filing').modal('show');
- // });
- $('#del-filing-ok').click(() => {
- filingObj.delFiling(filingObj.curFiling, function() {
- $('#del-filing').modal('hide');
- });
- });
- $('#add-file').on('show.bs.modal', function() {
- $('#filter-same')[0].checked = false;
- $('#filter-same').parent().hide();
- $('#upload-file-hint').hide();
- $('#upload-file')[0].value = '';
- if ($('#add-file-ok').hasClass('btn-warning')) $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary');
- });
- $('#upload-file').change(() => {
- $('#add-file-ok').attr('disabled', true);
- const input = $('#upload-file');
- filingObj.checkFilesExist(input[0].files, function(result) {
- if (result.length === 0) {
- $('#upload-file-hint').hide();
- $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
- $('#filter-same').parent().hide();
- } else {
- const msg = result[0] + (result.length > 1 ? `(等${result.length}个文件)`: '') + '</br>存在同名文件,请确认是否上传重复';
- $('#upload-file-hint').html(msg).show();
- $('#add-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
- $('#filter-same').parent().show();
- $('#filter-same').attr('filterFiles', result.join('$;$'));
- }
- });
- });
- $('#add-file-ok').click(() => {
- const input = $('#upload-file');
- const filter = $('#filter-same')[0].checked;
- const filterFiles = filter ? $('#filter-same').attr('filterFiles').split('$;$') : [];
- filingObj.uploadFiles(input[0].files, filterFiles, function() {
- $(input).val('');
- $('#add-file').modal('hide');
- });
- });
- $('#add-big-file').on('show.bs.modal', function() {
- $('#upload-big-file-hint').hide();
- $('#upload-big-file')[0].value = '';
- if ($('#add-big-file-ok').hasClass('btn-warning')) $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary');
- });
- $('#upload-big-file').change(() => {
- $('#add-big-file-ok').attr('disabled', true);
- const input = $('#upload-big-file');
- filingObj.checkFilesExist(input[0].files, function(result) {
- if (result.length === 0) {
- $('#upload-big-file-hint').hide();
- $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
- } else {
- $('#upload-big-file-hint').html('存在同名文件,请确认是否上传重复').show();
- $('#add-big-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
- }
- });
- });
- $('#add-big-file-ok').click(() => {
- const input = $('#upload-big-file');
- filingObj.uploadBigFile(input[0].files[0], function () {
- $('#upload-big-file').val('');
- $('#add-big-file').modal('hide');
- });
- });
- $('body').on('mouseenter', ".table-file", function(){
- $(this).children(".btn-group-table").css("display","block");
- });
- $('body').on('mouseleave', ".table-file", function(){
- $(this).children(".btn-group-table").css("display","none");
- });
- $('body').on('click', "a[name=del-file]", function() {
- const del = [this.getAttribute('fid')];
- filingObj.delFiles(del);
- });
- $('body').on('click', "a[name=edit-file]", function() {
- const check = $('[name=filename] input[fid]');
- if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
- const id = this.getAttribute('fid');
- const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
- $(`td[fid=${id}]`).html(filingObj._getEditFileNameHtml(file));
- });
- $('body').on('click', "a[name=edit-file-ok]", function() {
- const td = $(this).parent().parent().parent();
- const fid = td.attr('fid');
- const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
- if (!file) return;
- 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();
- const fid = td.attr('fid');
- const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
- if (!file) return;
- td.html(filingObj._getFileNameHtml(file));
- });
- class MoveFileObj {
- constructor() {
- const self = this;
- this.setting = {
- treeId: 'moveTree',
- view: {
- selectedMulti: false,
- showTitle: true,
- },
- data: {
- simpleData: {
- idKey: 'id',
- pIdKey: 'tree_pid',
- rootPId: '-1',
- enable: true,
- },
- key: { title: 'tips' },
- },
- edit: {
- enable: false,
- },
- };
- this.moveTree = null;
- $('#move-file2-ok').click(function() {
- const targetFiling = self.moveTree.getSelectedNodes()[0];
- if (!targetFiling) {
- toastr.warning('请选择目标分类');
- return;
- }
- if (targetFiling.children && targetFiling.children.length > 0) {
- toastr.warning('请选择最底层目标分类');
- return;
- }
- filingObj.moveFile(self.file, targetFiling.id, function() {
- $('#move-file2').modal('hide');
- });
- });
- // 显示层次
- (function (select) {
- $(select).click(function () {
- const tag = $(this).attr('tag');
- setTimeout(() => {
- showWaitingView();
- switch (tag) {
- case "1":
- case "2":
- case "3":
- case "4":
- self.expandByLevel(parseInt(tag));
- break;
- case "last":
- self.expandByCustom(() => { return true; });
- break;
- }
- closeWaitingView();
- }, 100);
- });
- })('a[name=mf2-showLevel]');
- }
- expandByLevel(level) {
- this.expandByCustom(x => {
- return x.level + 1 < level;
- })
- }
- expandByCustom(fun) {
- const self = this;
- const expandChildren = function(children) {
- for (const child of children) {
- if (!child.children || child.children.length === 0) continue;
- const expand = fun(child);
- self.moveTree.expandNode(child, expand, false, false);
- expandChildren(child.children);
- }
- };
- const nodes = this.moveTree.getNodes();
- expandChildren(nodes);
- }
- initMoveTree() {
- if (this.moveTree) $.fn.zTree.destroy(this.setting.treeId);
- const sortNodes = filingObj.dragTree.nodes.map(x => {
- const result = {
- id: x.id,
- tree_pid: x.tree_pid,
- name: x.name,
- spid: x.spid,
- tips: x.tips || '',
- };
- if (x.is_fixed) result.isParent = true;
- return result;
- });
- this.moveTree = $.fn.zTree.init($('#moveFile'), this.setting, sortNodes);
- }
- show (file) {
- this.file = file;
- this.initMoveTree();
- $('#move-file2').modal('show');
- }
- }
- const moveFileObj = new MoveFileObj();
- $('body').on('click', "a[name=move-file]", function() {
- const id = this.getAttribute('fid');
- const file = filingObj.curFiling.source_node.files.find(x => { return x.id === id });
- moveFileObj.show(file);
- });
- // $('body').on('blur', "[name=filename] input[fid]", function() {
- // filingObj.renameFile(this.getAttribute('fid'), this.value);
- // });
- // $('body').on('keypress', "[name=filename] input[fid]", function(e) {
- // if (e.keyCode == 13) {
- // filingObj.renameFile(this.getAttribute('fid'), this.value);
- // }
- // });
- $('.page-select').click(function() {
- const content = this.getAttribute('content');
- switch(content) {
- case 'pre': filingObj.prePage(); break;
- case 'next': filingObj.nextPage(); break;
- default: return;
- }
- });
- $('#batch-download').click(function () {
- const self = this;
- const files = [];
- const checkes = $('[name=bd-check]:checked');
- checkes.each(function() {
- const fid = this.getAttribute('fid');
- const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid; });
- file && files.push(file);
- });
- if (files.length === 0) return;
- $(self).attr('disabled', 'true');
- AliOss.zipFiles(files, filingObj.curFiling.source_node.name + '.zip', (fails) => {
- $(self).removeAttr('disabled');
- if (fails.length === 0) {
- toastr.success('下载成功');
- } else {
- toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
- }
- }, () => {
- $(self).removeAttr('disabled');
- toastr.error('批量下载失败');
- });
- });
- $('#batch-del-file-btn').click(() => {
- const checkes = $('[name=bd-check]:checked');
- if (checkes.length === 0) {
- return;
- } else {
- for (const c of checkes) {
- const fid = c.getAttribute('fid');
- const file = filingObj.curFiling.source_node.files.find(x => { return x.id === fid });
- if (!file) continue;
- if (file.user_id !== userID) {
- toastr.error(`文件【${file.filename + file.fileext}】不是您上传的文件,请勿删除`);
- return;
- }
- }
- }
- $('#batch-del-file').modal('show');
- });
- $('#batch-del-file-ok').click(function() {
- const del = [];
- const checkes = $('[name=bd-check]:checked');
- checkes.each(function() {
- del.push(this.getAttribute('fid'));
- });
- filingObj.delFiles(del, function() {
- $('#batch-del-file').modal('hide');
- });
- });
- class RelaFileLoader {
- constructor() {
- const self = this;
- // 可导入的标段
- this.treeSetting = {
- view: {
- selectedMulti: false
- },
- data: {
- simpleData: {
- idKey: 'id',
- pIdKey: 'tree_pid',
- rootPId: '-1',
- enable: true,
- }
- },
- edit: {
- enable: false,
- },
- callback: {
- onClick: async function (e, key, node) {
- if (this.curTender && this.curTender.id === node.id) return;
- self.setCurTender(node);
- },
- }
- };
- $('body').on('click', '[name=rf-check]', function () {
- self.selectFile(this.getAttribute('rfid'), this.checked);
- });
- $('#tf-type').change(function() {
- self.selectTfType(this.value);
- });
- $('#tf-sub-type').change(function() {
- self.selectTfSubType(this.value);
- });
- $('#tf-stage').change(function() {
- self.selectTfStage(this.value);
- });
- $('#rela-file-ok').click(function() {
- const selectFiles = self.getSelectRelaFile();
- filingObj.relaFiles(selectFiles, function() {
- $('#rela-file').modal('hide');
- });
- });
- }
- clearFileSelect() {
- if (!this.tenderTree) return;
- const nodes = this.tenderTree.getNodes();
- nodes.forEach(node => {
- const x = node.source_node;
- x.selectFiles = [];
- if (x.att) x.att.forEach(la => { la.checked = false });
- if (x.advance) {
- x.advance.forEach(a => {
- if (a.files) a.files.forEach(aa => { aa.checked = false });
- });
- }
- if (x.stage) {
- x.stage.forEach(s => {
- if (s.att) s.att.forEach(sa => { sa.checked = false });
- })
- }
- });
- }
- refreshSelectHint(){
- if (this.curTender) {
- $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
- } else {
- $('#cur-tender-hint').html('');
- }
- const nodes = this.tenderTree.getNodes();
- const selectTenders = nodes.filter(x => { return x.source_node.selectFiles.length > 0; });
- if (selectTenders.length > 0) {
- const count = selectTenders.reduce((rst, x) => { return rst + x.source_node.selectFiles.length; }, 0);
- $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
- } else {
- $('#rela-file-hint').html('未选择标段、文件');
- }
- }
- selectFile(fileId, isSelect) {
- const file = this.curFiles.find(x => { return x.rf_id == fileId });
- if (file) {
- file.checked = isSelect;
- if (isSelect) {
- this.curTender.source_node.selectFiles.push(file);
- } else {
- const index = this.curTender.source_node.selectFiles.findIndex(x => { return x.rf_id === file.rf_id });
- this.curTender.source_node.selectFiles.splice(index, 1);
- }
- this.refreshSelectHint();
- }
- }
- async showRelaFile(){
- $('#rela-filing-hint').html(`当前目录:${filingObj.getCurFilingFullPath()}`);
- if (!this.tenderTree) {
- const tenders = await postDataAsync('file/rela/tender', {});
- const sortNodes = tenders.map(x => {
- return { id: x.id, tree_pid: -1, name: x.name, source_node: x };
- });
- this.tenderTree = this.filingTree = $.fn.zTree.init($('#rela-tender'), this.treeSetting, sortNodes);
- }
- this.clearFileSelect();
- this.refreshSelectHint();
- const firstNode = this.filingTree.getNodes()[0];
- if (firstNode) {
- this.filingTree.selectNode(firstNode);
- await this.setCurTender(firstNode);
- }
- }
- refreshTenderFileStage() {
- if (this.rfType.sub_type) {
- const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
- const subType = type.subType ? type.subType.find(x => { return x.value === this.rfType.sub_type; }) : null;
- if (subType) {
- this.rfType.stage = subType.stage[0].value;
- const html= [];
- for (const stage of subType.stage) {
- html.push(`<option value="${stage.value}">${stage.text}</option>`);
- }
- $('#tf-stage').html(html.join('')).show();
- } else {
- $('#tf-stage').html('').hide();
- }
- } else {
- $('#tf-stage').html('').hide();
- }
- }
- refreshTenderFileSubType() {
- const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
- if (type.subType && type.subType.length > 0) {
- this.rfType.sub_type = type.subType[0].value;
- const html= [];
- for (const tfst of type.subType) {
- html.push(`<option value="${tfst.value}">${tfst.text}</option>`);
- }
- $('#tf-sub-type').html(html.join('')).show();
- } else {
- $('#tf-sub-type').html('').hide();
- }
- }
- refreshTenderFileType() {
- const html= [];
- for (const tft of this.tenderFileType) {
- html.push(`<option value="${tft.value}">${tft.text}</option>`);
- }
- $('#tf-type').html(html.join(''));
- }
- refreshSelects(tender) {
- this.tenderFileType = [];
- this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
- if (tender.stage && tender.stage.length > 0) {
- const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
- this.tenderFileType.push({
- value: 'stage', text: '计量期',
- subType: [
- { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
- ],
- });
- }
- if (tender.advance && tender.advance.length > 0) {
- const advanceType = [];
- tender.advance.forEach(x => {
- let at = advanceType.find(y => { return y.value === x.type + '' });
- if (!at) {
- at = { value: x.type + '', text: x.type_str, stage: [] };
- advanceType.push(at);
- }
- at.stage.push({ value: x.id, text: `第${x.order}期`});
- });
- this.tenderFileType.push({
- value: 'advance', text: '预付款', subType: advanceType
- });
- }
- this.rfType = { type: this.tenderFileType[0].value };
- this.refreshTenderFileType();
- this.refreshTenderFileSubType();
- this.refreshTenderFileStage();
- }
- async selectTfStage(stage){
- this.rfType.stage = stage;
- await this.loadFiles();
- this.refreshFileTable();
- }
- async selectTfSubType(sub_type){
- this.rfType.sub_type = sub_type;
- this.refreshTenderFileStage();
- await this.loadFiles();
- this.refreshFileTable();
- }
- async selectTfType(type){
- this.rfType.type = type;
- this.refreshTenderFileSubType();
- this.refreshTenderFileStage();
- await this.loadFiles();
- this.refreshFileTable();
- }
- refreshFileTable() {
- const html = [];
- const typeStr = [];
- const selectOption = $('option:selected');
- selectOption.each((i, x) => {
- typeStr.push(x.innerText);
- });
- for (const f of this.curFiles) {
- html.push('<tr>');
- const checked = f.checked ? "checked" : '';
- html.push(`<td><input type="checkbox" name="rf-check" rfid="${f.rf_id}" ${checked}></td>`);
- html.push(`<td>${f.filename}${f.fileext}</td>`);
- html.push(`<td>${typeStr.join(' - ')}</td>`);
- html.push('</tr>');
- }
- $('#rf-files').html(html.join(''));
- };
- initFilesId(files){
- const tender_id = this.curTender.id;
- const rfType = this.rfType;
- files.forEach((f, i) => {
- f.rf_id = `${tender_id}-${rfType.type}-${rfType.sub_type}-${rfType.stage}-${i}`;
- f.rf_key = {
- tender_id, ...rfType, id: f.id,
- };
- });
- }
- async _loadRelaFiles(rfType) {
- return await postDataAsync('file/rela/files', { tender_id: this.curTender.id, ...rfType });
- }
- async _loadLedgerFile() {
- if (!this.curTender.source_node.att) this.curTender.source_node.att = await this._loadRelaFiles(this.rfType);
- this.curFiles = this.curTender.source_node.att;
- }
- async _loadStageFile() {
- const rfType = this.rfType;
- const stage = this.curTender.source_node.stage.find(x => {
- return x.id == rfType.stage;
- });
- if (!stage) {
- this.curFiles = [];
- return;
- }
- if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(rfType);
- this.curFiles = stage[this.rfType.sub_type];
- }
- async _loadAdvanceFile() {
- const rfType = this.rfType;
- const advance = this.curTender.source_node.advance.find(x => {
- return x.id == rfType.stage;
- });
- if (!advance) {
- this.curFiles = [];
- return;
- }
- if (!advance.files) advance.files = await this._loadRelaFiles(rfType);
- this.curFiles = advance.files;
- }
- async loadFiles() {
- switch (this.rfType.type) {
- case 'ledger': await this._loadLedgerFile(); break;
- case 'stage': await this._loadStageFile(); break;
- case 'advance': await this._loadAdvanceFile(); break;
- }
- this.initFilesId(this.curFiles);
- }
- async setCurTender(node) {
- this.curTender = node;
- this.refreshSelects(node.source_node);
- await this.loadFiles();
- this.refreshSelectHint();
- this.refreshFileTable();
- }
- getSelectRelaFile() {
- const data = [];
- const nodes = this.tenderTree.getNodes();
- nodes.forEach(node => {
- if (node.source_node.selectFiles.length === 0) return;
- node.source_node.selectFiles.forEach(x => {
- data.push({
- filename: x.filename, fileext: x.fileext, filepath: x.filepath, filesize: x.filesize,
- rela_info: x.rf_key,
- })
- });
- });
- return data;
- }
- }
- const relaFileLoader = new RelaFileLoader();
- $('#rela-file').on('show.bs.modal', function() {
- relaFileLoader.showRelaFile(this.getAttribute('content'));
- });
- // 授权相关
- class FilingPermission {
- constructor (setting) {
- this.setting = setting;
- const self = this;
- this.spread = SpreadJsObj.createNewSpread($(`${setting.spread}`)[0]);
- this.sheet = this.spread.getActiveSheet();
- this.spreadSetting = {
- cols: [
- { title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 200, formatter: '@', cellType: 'tree'},
- { title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 45, cellType: 'checkbox' },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headColWidth: [25],
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- selectedBackColor: '#fffacd',
- };
- SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
- this.permissionTree = createNewPathTree('base', {
- id: 'tree_id',
- pid: 'tree_pid',
- order: 'order',
- level: 'level',
- isLeaf: 'is_leaf',
- fullPath: 'full_path',
- rootId: -1,
- });
- this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
- if (!info.sheet.zh_setting) return;
- const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
- if (cellType instanceof spreadNS.CellTypes.CheckBox) {
- if (sheet.isEditing()) sheet.endEdit(true);
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field !== 'check') return;
- const tree = self.permissionTree;
- const node = tree.nodes[info.row];
- const row = [info.row];
- node.check = !node.check;
- if (node.children && node.children.length > 0) {
- const posterity = tree.getPosterity(node);
- for (const p of posterity) {
- p.check = node.check;
- row.push(tree.nodes.indexOf(p));
- }
- }
- if (!node.check) {
- const parent = tree.getAllParents(node);
- for (const p of parent) {
- p.check = node.check;
- row.push(tree.nodes.indexOf(p));
- }
- }
- SpreadJsObj.reLoadRowsData(info.sheet, row);
- });
- this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- const node = SpreadJsObj.getSelectObject(info.sheet);
- self.setCurFiling(node.filing_type);
- });
- $(setting.modal).on('show.bs.modal', () => {
- self.loadPermission();
- });
- $(setting.modal).on('shown.bs.modal', () => {
- self.spread.refresh();
- });
- $(`${setting.modal}-ok`).click(() => {
- self.savePermission();
- });
- $('.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 selectFilingId = [];
- self.permissionTree.nodes.forEach(x => { if (x.check && (!x.children || x.children.length === 0)) selectFilingId.push(x.filing_type); });
- if (selectFilingId.length === 0) {
- toastr.warning('请先选择文档类别');
- return;
- }
- self.syncFiling(self.curFiling, selectFilingId);
- toastr.success('同步成功');
- self.permissionTree.nodes.forEach(x => { x.check = false; });
- SpreadJsObj.reloadColData(self.sheet, 1);
- $('#filing-select-all')[0].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();
- });
- $('#batch-add-filing').click(() => {
- const selectFilingId = [];
- self.permissionTree.nodes.forEach(x => { if (x.check && (!x.children || x.children.length === 0)) selectFilingId.push(x.filing_type); });
- if (selectFilingId.length === 0) {
- toastr.warning('请先选择文档类别');
- return;
- }
- 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.batchAddFiling(selectFilingId, userId);
- self.loadCurFiling();
- toastr.success('批量添加成功');
- self.permissionTree.nodes.forEach(x => { x.check = false; });
- SpreadJsObj.reloadColData(self.sheet, 1);
- $('#filing-select-all')[0].checked = false;
- });
- $('body').on('click', '[name=del-filing]', function() {
- const id = this.getAttribute('uid');
- self.delFiling(self.curFiling, id);
- self.loadCurFiling();
- });
- $('#user-select-all').click(function(){
- $('input[uid]').attr('checked', this.checked);
- });
- $('#filing-select-all').click(function(){
- self.permissionTree.nodes.forEach(x => {
- x.check = this.checked;
- });
- SpreadJsObj.reloadColData(self.sheet, 1);
- });
- }
- 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(''));
- $('#user-select-all')[0].checked = false;
- }
- refreshBtn() {
- const self = this;
- const filing = this.permissionTree.nodes.find(x => { return x.filing_type === self.curFiling; });
- if (!filing || (filing.children && filing.children.length > 0)) {
- $('#filing-add-user').hide();
- $('#batch-del-filing').hide();
- $('#batch-add-filing').hide();
- $('#sync-filing').hide();
- } else {
- $('#filing-add-user').show();
- $('#batch-del-filing').show();
- $('#batch-add-filing').show();
- $('#sync-filing').show();
- }
- }
- setCurFiling(filingType) {
- this.curFiling = filingType;
- this.loadCurFiling();
- this.refreshBtn();
- }
- 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(''));
- }
- _convertData(sourceTree) {
- const data = [];
- for (const node of sourceTree.nodes) {
- if (!node.is_fixed) continue;
- const parent = node.tree_pid === '-1' ? undefined : data.find(x => { return x.id === node.tree_pid; });
- const child = sourceTree.nodes.find(x => { return x.tree_pid === node.id; });
- data.push({
- id: node.id,
- tree_id: data.length + 1,
- tree_pid: parent ? parent.tree_id : -1,
- order: node.tree_order + 1,
- level: node.tree_level,
- is_leaf: !child || !child.is_fixed,
- full_path: '',
- name: node.name,
- is_fixed: node.is_fixed,
- filing_type: node.filing_type + '',
- tips: node.tips,
- file_count: node.file_count,
- });
- }
- return data;
- }
- loadPermission() {
- this.permissionTree.loadDatas(this._convertData(filingObj.dragTree));
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.permissionTree);
- const self = this;
- postData('permission', {}, function(result) {
- self.analysisFiling(result);
- if (!self.curFiling) {
- const node = SpreadJsObj.getSelectObject(self.sheet);
- self.setCurFiling(node.filing_type);
- } 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);
- }
- }
- batchAddFiling(filingIds, userId) {
- for (const pu of this.permissionUser) {
- if (userId.indexOf(pu.id) < 0) continue;
- filingIds.forEach(fid => {
- if (pu.filing_type.indexOf(fid) < 0) pu.filing_type.push(fid);
- });
- }
- }
- 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',
- spread: '#permission-spread',
- });
- 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));
- });
- }
- refreshSearchFile(file) {
- const sfile = this.searchResult.find(x => { return x.id === file.id; });
- if (sfile) {
- for (const prop in file) {
- if (prop === 'id') continue;
- sfile[prop] = file[prop];
- }
- }
- }
- 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() {
- if (fileReference) fileReference.spread.refresh();
- },
- });
- $('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'));
- if (tab.attr('content') === '#reference') {
- if (!fileReference) {
- fileReference = $.stdLib({
- selector: '#reference',
- stdType: 'reference',
- libs: fileReferenceList,
- treeSetting: {
- id: 'template_id',
- pid: 'pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'list_id', 'template_id'],
- },
- spreadSetting: {
- cols: [
- {title: '名称', field: 'name', hAlign: 0, width: 420, formatter: '@', cellType: 'tree', wordWrap: true},
- {title: '备注', field: 'remark', hAlign: 1, width: 150, formatter: '@'}
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [30],
- selectedBackColor: '#fffacd',
- readOnly: true,
- localCache: {
- key: 'file_detail_reference',
- colWidth: true,
- },
- },
- page: 'file',
- });
- }
- fileReference.spread.refresh();
- }
- } else { // 收起工具栏
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showSideTools(tab.hasClass('active'));
- }
- });
- // 显示层次
- (function (select) {
- $(select).click(function () {
- const tag = $(this).attr('tag');
- setTimeout(() => {
- showWaitingView();
- switch (tag) {
- case "1":
- case "2":
- case "3":
- case "4":
- filingObj.expandByLevel(parseInt(tag));
- break;
- case "last":
- filingObj.expandByCustom(() => { return true; });
- break;
- }
- closeWaitingView();
- }, 100);
- });
- })('a[name=showLevel]');
- });
|