| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190 |
- $(document).ready(function() {
- let fileSearch, fileReference;
- autoFlashHeight();
-
- /**
- * FilingSjs - 资料管理 SpreadJS 版本
- * 使用 SpreadJS 替代 zTree 展示文件分类树,保留完整的文件管理功能
- */
- class FilingSjs {
- constructor() {
- // 初始化 SpreadJS
- this.spread = SpreadJsObj.createNewSpread($('#filing-spread')[0]);
- this.spread.options.showHorizontalScrollbar = false; // 隐藏水平滚动条
- this.sheet = this.spread.getActiveSheet();
- // 初始化 PathTree,使用 zh_filing 原有字段映射
- this.filingTree = createNewPathTree('base', {
- id: 'tree_id',
- pid: 'tree_pid',
- order: 'order',
- level: 'level',
- isLeaf: 'is_leaf',
- fullPath: 'full_path',
- rootId: -1,
- });
- // SpreadJS 表格配置
- this.spreadSetting = {
- cols: [
- {
- title: '分类名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 220, formatter: '@', cellType: 'tree',
- getValue: function(data) {
- return data.name;
- },
- getIcon: function(data) {
- return data.is_leaf ? 'file' : 'folder';
- },
- },
- { title: '文件数', colSpan: '1', rowSpan: '1', field: 'total_file_count', hAlign: 1, width: 70, formatter: '@' },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headColWidth: [25],
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- selectedBackColor: '#e8f4fd',
- };
- SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
- // 文件管理相关属性
- this.pageCount = 15;
- this.curPage = 1;
- this.curTotalPage = 1;
- this.curFiling = null;
- this.selectRemoveNode = null;
- this.fileOrderKey = 'fileOrderSjs';
- this.fileOrder = getLocalCache(this.fileOrderKey) || 'create_time|desc';
- this.curFilingKey = 'cur-filing-sjs-' + window.location.pathname.split('/')[2];
- this._isRenaming = false;
- this._bindEvents();
- this._loadFilingData();
- this.refreshFileOrderButton();
- }
- /**
- * 递归累加文件数
- */
- _calcTotalFileCount(data) {
- for (const node of data) {
- node.total_file_count = 0;
- node._children = [];
- }
- for (const node of data) {
- if (node.tree_pid !== -1) {
- const parent = data.find(x => x.tree_id === node.tree_pid);
- if (parent) {
- parent._children.push(node);
- }
- }
- }
- const calcNode = (node) => {
- if (node._children && node._children.length > 0) {
- for (const child of node._children) {
- calcNode(child);
- }
- node.total_file_count = node._children.reduce((sum, child) => {
- return sum + child.total_file_count;
- }, 0);
- } else {
- node.total_file_count = node.file_count || 0;
- }
- };
- const roots = data.filter(x => x.tree_pid === -1);
- for (const root of roots) {
- calcNode(root);
- }
- for (const node of data) {
- delete node._children;
- }
- }
- /**
- * 转换数据格式
- */
- _convertData(sourceData) {
- const data = [];
- const skippedIds = new Set();
- const sortedData = [...sourceData].sort((a, b) => {
- return Number(a.tree_level) - Number(b.tree_level);
- });
- for (const node of sortedData) {
- if (skippedIds.has(node.tree_pid)) {
- skippedIds.add(node.id);
- continue;
- }
- const parent = (node.tree_pid === '-1' || node.tree_pid === -1)
- ? undefined
- : data.find(x => x.id === node.tree_pid);
- const hasChild = sourceData.some(x => x.tree_pid === node.id);
- if (!parent && node.tree_pid !== '-1' && node.tree_pid !== -1) {
- skippedIds.add(node.id);
- continue;
- }
- const convertedNode = {
- id: node.id,
- tree_id: data.length + 1,
- tree_pid: parent ? parent.tree_id : -1,
- order: Number(node.tree_order) + 1,
- level: Number(node.tree_level),
- is_leaf: !hasChild,
- full_path: '',
- name: node.name,
- filing_type: Number(node.filing_type),
- file_count: Number(node.file_count) || 0,
- is_fixed: node.is_fixed,
- tips: node.tips || '',
- upload_tips: node.upload_tips || '',
- spid: node.spid,
- };
- data.push(convertedNode);
- }
- this._calcTotalFileCount(data);
- return data;
- }
- /**
- * 加载 filing 数据到 SpreadJS
- */
- _loadFilingData() {
- const convertedData = this._convertData(filing);
- this.filingTree.loadDatas(convertedData);
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
- // 恢复上次选中的节点
- const curCache = getLocalCache(this.curFilingKey);
- if (curCache) {
- const curNode = this.filingTree.nodes.find(x => x.id === curCache);
- if (curNode) {
- this.setCurFiling(curNode);
- }
- }
- this.refreshFileCountHint();
- }
- /**
- * 绑定事件
- */
- _bindEvents() {
- const self = this;
- // 选中行变化事件
- this.spread.bind(spreadNS.Events.SelectionChanged, async function(e, info) {
- if (self._isRenaming) return;
- const node = SpreadJsObj.getSelectObject(self.sheet);
- if (node && (!self.curFiling || self.curFiling.id !== node.id)) {
- await self.setCurFiling(node);
- }
- });
- // 显示层级按钮点击
- $('[name=showLevel]').click(function() {
- const tag = $(this).attr('tag');
- self._showLevel(tag);
- });
- // 添加同级
- $('#add-slibing').click(function() {
- if (!self.curFiling) return;
- if (self.curFiling.is_fixed) {
- toastr.error('固定分类不可添加同级');
- return;
- }
- self.addSiblingFiling(self.curFiling);
- });
- // 添加子级
- $('#add-child').click(function() {
- if (!self.curFiling) return;
- const children = self.filingTree.getChildren(self.curFiling);
- const fixedChild = children.find(x => x.is_fixed);
- if (fixedChild) {
- toastr.error('该分类下存在固定分类,不可添加子级');
- return;
- }
- if (self.curFiling.file_count > 0) {
- toastr.error('该分类下已导入文件,不可添加子级');
- return;
- }
- self.addChildFiling(self.curFiling);
- });
- // 文件排序
- $('[name=file-sort]').click(function() {
- const tag = $(this).attr('tag');
- self.changeFileOrder(tag);
- });
- // 分页
- $('.page-select[content=pre]').click(function() {
- self.prePage();
- });
- $('.page-select[content=next]').click(function() {
- self.nextPage();
- });
- // 双击行内重命名分类
- $('#filing-spread').dblclick(function() {
- if (!canFiling) return;
- if (self._isRenaming) return;
- const node = SpreadJsObj.getSelectObject(self.sheet);
- if (!node || node.is_fixed) return;
- self._isRenaming = true;
- const rowIndex = self.filingTree.nodes.indexOf(node);
- const cellRect = self.sheet.getCellRect(rowIndex, 0);
- const containerRect = $('#filing-spread')[0].getBoundingClientRect();
- const inputLeft = containerRect.left + window.scrollX + cellRect.x + 2;
- const inputTop = containerRect.top + window.scrollY + cellRect.y + 2;
- const inputWidth = cellRect.width - 4;
- const inputHeight = cellRect.height - 4;
- const $input = $('<input type="text" class="form-control form-control-sm">')
- .val(node.name)
- .css({
- position: 'absolute',
- left: inputLeft,
- top: inputTop,
- width: inputWidth,
- height: inputHeight,
- zIndex: 1000,
- fontSize: '12px',
- padding: '0 4px',
- border: '2px solid #4a90d9',
- borderRadius: '2px',
- outline: 'none',
- boxShadow: '0 0 4px rgba(74,144,217,0.4)',
- });
- let handled = false;
- const finishEdit = async (save) => {
- if (handled) return;
- handled = true;
- const newName = $input.val().trim();
- $input.remove();
- self._isRenaming = false;
- if (save && newName && newName !== node.name) {
- await self.renameFiling(node, newName);
- }
- };
- $input.on('keydown', function(e) {
- if (e.keyCode === 13) { // Enter
- e.preventDefault();
- finishEdit(true);
- } else if (e.keyCode === 27) { // Escape
- e.preventDefault();
- finishEdit(false);
- }
- });
- $input.on('blur', function() { finishEdit(true); });
- $('body').append($input);
- $input.focus().select();
- });
- // 右键菜单 - 删除分类
- $.contextMenu({
- selector: '#filing-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'delete': {
- name: '删除',
- icon: 'fa-trash-o',
- callback: function () {
- const node = SpreadJsObj.getSelectObject(self.sheet);
- if (!node || node.is_fixed) return;
- self.selectRemoveNode = node;
- $('#del-filing').modal('show');
- },
- disabled: function () {
- const node = SpreadJsObj.getSelectObject(self.sheet);
- return !canFiling || !node || node.is_fixed;
- },
- },
- },
- });
- }
- /**
- * 设置当前选中的分类
- */
- async setCurFiling(node) {
- this.curFiling = node;
- this._applyCurrentPermission(node);
- this.curPage = 1;
- this.refreshPages();
- const permission = this._getFilingPermission(node.id);
- if (!permission.can_view) {
- $('#file-view').hide();
- setLocalCache(this.curFilingKey, node.id);
- return;
- }
- // 判断是否为叶子节点:无子节点或有文件都视为可展示文件的节点
- const hasChildren = this.filingTree.getChildren(node).length > 0;
- const isLeafNode = !hasChildren || node.file_count > 0;
- if (isLeafNode) {
- $('#file-view').show();
- this.refreshUploadTips(node);
- await this.loadFiles(node, 1);
- this.refreshFilesTable();
- } else {
- $('#file-view').hide();
- }
- setLocalCache(this.curFilingKey, node.id);
- }
- /**
- * 刷新当前目录的上报说明
- */
- refreshUploadTips(node) {
- const uploadTips = node ? String(node.upload_tips || '').trim() : '';
- $('#filing-upload-tips')
- .text(uploadTips || '暂无上报说明')
- .toggleClass('text-muted', !uploadTips);
- }
- _getFilingPermission(filingId) {
- return filingPermissionMap[String(filingId)] || {
- can_view: 0,
- can_upload: 0,
- can_edit_file: 0,
- can_edit_dir: 0,
- can_lock_file: 0,
- };
- }
- _applyCurrentPermission(node) {
- const permission = this._getFilingPermission(node.id);
- canUpload = Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_upload);
- canEdit = Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_edit_file);
- canFiling = Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_edit_dir);
- canLockFile = Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_lock_file);
- $('.js-can-upload').toggle(canUpload);
- $('.js-can-edit-dir').toggle(canFiling);
- }
- canUploadFiling(filingId) {
- const permission = this._getFilingPermission(filingId);
- return Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_upload);
- }
- canEditFiling(filingId) {
- const permission = this._getFilingPermission(filingId);
- return Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_edit_file);
- }
- isFileLocked(file) {
- return Boolean(file) && Number(file.is_locked) === 1;
- }
- /**
- * 刷新文件数量提示
- */
- refreshFileCountHint() {
- const sum = _.sum(this.filingTree.nodes.filter(x => x.level === 1).map(x => x.total_file_count));
- $('#file-count').html(`文件总数:${sum}`);
- }
- /**
- * 刷新文件排序按钮
- */
- 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`);
- }
- }
- }
- /**
- * 刷新分页
- */
- refreshPages() {
- if (!this.curFiling) return;
- this.curTotalPage = Math.ceil(this.curFiling.file_count / this.pageCount);
- this.curPage = Math.min(this.curTotalPage, Math.max(this.curPage, 1));
- $('#curPage').html(this.curPage);
- $('#curTotalPage').html(this.curTotalPage);
- if (this.curTotalPage > 1) {
- $('#showPage').show();
- } else {
- $('#showPage').hide();
- }
- }
- /**
- * 加载文件列表
- */
- async loadFiles(node, page) {
- if (!node.files) node.files = [];
- if (!node.file_count) return;
- const needFiles = Math.min(page * this.pageCount, node.file_count);
- if (node.files.length >= needFiles) return;
- const files = await postDataAsync('file/load', {
- filing_id: node.id,
- page,
- count: this.pageCount,
- order: this.fileOrder
- });
-
- files.forEach(x => {
- const file = node.files.find(f => f.id === x.id);
- if (file) {
- Object.assign(file, x);
- } else {
- node.files.push(x);
- }
- });
- }
- /**
- * 刷新文件表格
- */
- refreshFilesTable() {
- const html = [];
- const files = this.curFiling.files;
- if (!files || files.length === 0) {
- $('#file-list').html('');
- return;
- }
- const startIndex = (this.curPage - 1) * this.pageCount;
- const endIndex = this.curPage * this.pageCount;
- for (let i = startIndex; i < endIndex && i < files.length; i++) {
- const file = files[i];
- html.push(this._getFileHtml(file));
- }
- $('#file-list').html(html.join(''));
- }
- /**
- * 生成文件HTML
- */
- _getFileHtml(file) {
- const isLocked = this.isFileLocked(file);
- const canOperateFile = !isLocked && canEdit;
- const moveHtml = canOperateFile ?
- `<a href="javascript: void(0);" class="dropdown-item text-primary" name="move-file" fid="${file.id}"><i class="fa fa-exchange fa-fw"></i> 移动</a>` : '';
- const editHtml = canOperateFile ?
- `<a href="javascript: void(0);" class="dropdown-item text-primary" name="edit-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i> 重命名</a>` : '';
- const viewHtml = file.viewpath ?
- `<a href="${file.viewpath}" class="dropdown-item text-primary" 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="dropdown-item text-primary"><i class="fa fa-download fa-fw"></i> 下载</a>`;
- const delHtml = canOperateFile ?
- `<div class="dropdown-divider"></div><a href="javascript: void(0);" class="dropdown-item text-danger" name="del-file" fid="${file.id}"><i class="fa fa-trash-o fa-fw"></i> 删除</a>` : '';
- const lockId = `file-lock-${file.id}`;
- const lockHtml = canLockFile ?
- `<div class="custom-control custom-switch d-inline-block">
- <input type="checkbox" class="custom-control-input" name="file-lock" id="${lockId}" fid="${file.id}" ${isLocked ? 'checked' : ''}>
- <label class="custom-control-label" for="${lockId}"></label>
- </div>` : (isLocked ? '<i class="fa fa-lock text-danger" title="文件已锁定"></i>' : '');
- 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}"><div class="d-flex justify-content-between align-items-center table-file"><div name="filename" fid="${file.id}">${file.filename}${file.fileext}</div></div></td>`);
- html.push(`<td class="text-center">${lockHtml}</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(`<td class="text-center">
- <div class="dropdown">
- <a href="javascript: void(0);" class="dropdown-toggle text-primary" data-toggle="dropdown"><i class="fa fa-bars"></i></a>
- <div class="dropdown-menu">
- ${editHtml}${viewHtml}${moveHtml}${downHtml}${delHtml}
- </div>
- </div>
- </td>`);
- html.push('</tr>');
- return html.join('');
- }
- /**
- * 生成文件名显示HTML
- */
- _getFileNameHtml(file) {
- 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>`;
- }
- /**
- * 添加同级分类
- */
- addSiblingFiling(node) {
- const self = this;
- const treePid = node.tree_pid === -1 ? '-1' : this._findOriginalId(node.tree_pid);
- postData('filing/add', { tree_pid: treePid, tree_pre_id: node.id }, function(result) {
- filing.push(result);
- self._reloadFilingTree();
- });
- }
- /**
- * 添加子级分类
- */
- addChildFiling(node) {
- const self = this;
- postData('filing/add', { tree_pid: node.id }, function(result) {
- filing.push(result);
- self._reloadFilingTree();
- });
- }
- /**
- * 重新加载归档树
- */
- _reloadFilingTree() {
- const convertedData = this._convertData(filing);
- this.filingTree.loadDatas(convertedData);
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
- this.refreshFileCountHint();
- }
- /**
- * 删除分类
- */
- delFiling(node, callback) {
- const self = this;
- const parent = this.filingTree.getParent(node);
- postData('filing/del', { id: node.id }, function(result) {
- // 更新 filing 数组:移除已删除的节点
- if (result && result.delete) {
- for (const delId of result.delete) {
- const idx = filing.findIndex(x => x.id === delId);
- if (idx >= 0) filing.splice(idx, 1);
- }
- }
- // 更新兄弟节点的 tree_order
- if (result && result.update) {
- for (const u of result.update) {
- const srcNode = filing.find(x => x.id === u.id);
- if (srcNode) srcNode.tree_order = u.tree_order;
- }
- }
- // 重新加载树
- self._reloadFilingTree();
- $('#file-view').hide();
- self.curFiling = null;
- if (callback) callback();
- });
- }
- /**
- * 重命名分类
- */
- async renameFiling(node, newName) {
- const result = await postDataAsync('filing/save', { id: node.id, name: newName });
- const srcNode = filing.find(x => x.id === node.id || x.id == node.id);
- if (srcNode) srcNode.name = newName;
- node.name = newName;
- const countHint = node.total_file_count > 0 ? `(${node.total_file_count})` : '';
- node.name = newName;
- const rowIndex = this.filingTree.nodes.indexOf(node);
- if (rowIndex >= 0) {
- SpreadJsObj.reLoadRowsData(this.sheet, [rowIndex]);
- }
- let parent = this.filingTree.getParent(node);
- while (parent) {
- const pIdx = this.filingTree.nodes.indexOf(parent);
- if (pIdx >= 0) SpreadJsObj.reLoadRowsData(this.sheet, [pIdx]);
- parent = this.filingTree.getParent(parent);
- }
- return result;
- }
- /**
- * 移动分类
- */
- moveFiling(node, newTreePid, newOrder, callback) {
- const self = this;
- const srcNode = filing.find(x => x.id === node.id || x.id == node.id);
- if (!srcNode) return;
- if (String(srcNode.tree_pid) === String(newTreePid) && Number(srcNode.tree_order) === newOrder) {
- if (callback) callback();
- return;
- }
- postData('filing/move', { id: node.id, tree_pid: newTreePid, tree_order: newOrder }, function(result) {
- srcNode.tree_pid = newTreePid;
- srcNode.tree_order = newOrder;
- self._reloadFilingTree();
- if (callback) callback();
- });
- }
- /**
- * 查找原始ID
- */
- _findOriginalId(treeId) {
- const node = this.filingTree.nodes.find(x => x.tree_id === treeId);
- return node ? node.id : null;
- }
- /**
- * 改变文件排序
- */
- changeFileOrder(fileOrder) {
- this.fileOrder = fileOrder;
- setLocalCache(this.fileOrderKey, fileOrder);
- this.refreshFileOrderButton();
- if (this.curFiling) {
- this.curFiling.files = [];
- this.setCurFiling(this.curFiling);
- }
- }
- /**
- * 上一页
- */
- prePage() {
- if (this.curPage === 1) return;
- this.curPage = this.curPage - 1;
- this.refreshPages();
- this.refreshFilesTable();
- }
- /**
- * 下一页
- */
- async nextPage() {
- if (this.curPage === this.curTotalPage) return;
- await this.loadFiles(this.curFiling, this.curPage + 1);
- this.curPage = this.curPage + 1;
- this.refreshPages();
- this.refreshFilesTable();
- }
- /**
- * 按层级显示
- */
- _showLevel(level) {
- if (level === 'last') {
- this.filingTree.expandByCustom(() => { return true; });
- } else {
- this.filingTree.expandByLevel(parseInt(level));
- }
- SpreadJsObj.refreshTreeRowVisible(this.sheet);
- }
- /**
- * 批量下载文件
- */
- batchDownloadFiles() {
- const self = this;
- const checkedFiles = $('input[name=bd-check]:checked');
- if (checkedFiles.length === 0) return;
- const files = [];
- checkedFiles.each(function() {
- const fid = $(this).attr('fid');
- const file = self.curFiling.files.find(f => f.id === fid);
- file && files.push(file);
- });
- if (files.length === 0) return;
- $('#batch-download').attr('disabled', 'true');
- AliOss.zipFiles(files, self.curFiling.name + '.zip', (fails) => {
- $('#batch-download').removeAttr('disabled');
- if (fails.length === 0) {
- toastr.success('下载成功');
- } else {
- toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
- }
- }, () => {
- $('#batch-download').removeAttr('disabled');
- toastr.error('批量下载失败');
- });
- }
- /**
- * 根据id查找归档节点
- */
- findFiling(id) {
- return this.filingTree.nodes.find(x => x.id === id || x.id == id);
- }
- /**
- * 获取当前归档完整路径
- */
- getCurFilingFullPath() {
- let cur = this.curFiling;
- const result = [];
- while (cur) {
- result.unshift(cur.name);
- cur = this.filingTree.getParent(cur);
- }
- return result.join('/');
- }
- /**
- * 生成行内编辑HTML
- */
- _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>`;
- }
- /**
- * 重命名文件
- */
- renameFile(file, filename) {
- const self = this;
- const td = $(`td[fid=${file.id}]`);
- postData('file/save', { id: file.id, filename }, function(data) {
- const relaFiling = self.findFiling(file.filing_id);
- const relaFile = relaFiling.files.find(x => x.id === file.id);
- if (relaFile) {
- relaFile.filename = data.filename;
- relaFile.fileext = data.fileext;
- }
- file.filename = data.filename;
- file.fileext = data.fileext;
- td.html(self._getFileNameHtml(file));
- if (fileSearch) fileSearch.renameSearchFile(file.id, data);
- }, function() {
- td.html(self._getFileNameHtml(file));
- if (fileSearch) fileSearch.renameSearchFile(file.id);
- });
- }
- /**
- * 删除文件
- */
- delFiles(files, callback, hint) {
- const self = this;
- const del = function() {
- postData('file/del', { del: files }, async function(data) {
- const relaFiling = data.filing.id === self.curFiling.id
- ? self.curFiling : self.findFiling(data.filing.id);
- if (relaFiling && relaFiling.files) {
- for (const id of data.del) {
- const fIndex = relaFiling.files.findIndex(x => x.id === id);
- if (fIndex >= 0) relaFiling.files.splice(fIndex, 1);
- if (fileSearch) fileSearch.removeSearchFile(id);
- }
- }
- self.updateFilingFileCount(relaFiling, data.filing.file_count);
- if (data.filing.id === self.curFiling.id) {
- await self.loadFiles(self.curFiling, self.curPage);
- self.refreshPages();
- self.refreshFilesTable();
- }
- self.refreshFileCountHint();
- if (callback) callback();
- });
- };
- if (hint) {
- deleteAfterHint(del, hint);
- } else {
- del();
- }
- }
- /**
- * 更新归档文件计数
- */
- updateFilingFileCount(node, count) {
- if (!node) return;
- const differ = count - (node.file_count || 0);
- node.file_count = count;
- node.total_file_count = count;
- // 更新 SpreadJS 显示
- const rowIndex = this.filingTree.nodes.indexOf(node);
- if (rowIndex >= 0) {
- SpreadJsObj.reLoadRowsData(this.sheet, [rowIndex]);
- }
- // 递归更新父节点
- let parent = this.filingTree.getParent(node);
- while (parent) {
- parent.total_file_count = parent.total_file_count ? parent.total_file_count + differ : differ;
- const pIndex = this.filingTree.nodes.indexOf(parent);
- if (pIndex >= 0) {
- SpreadJsObj.reLoadRowsData(this.sheet, [pIndex]);
- }
- parent = this.filingTree.getParent(parent);
- }
- }
- /**
- * 移动文件
- */
- moveFile(file, filingId, callback) {
- if (file.filing_id === filingId) {
- callback();
- return;
- }
- const self = this;
- postData('file/move', { id: file.id, filingId: filingId }, function(data) {
- const orgFiling = self.findFiling(file.filing_id);
- if (orgFiling) {
- self.updateFilingFileCount(orgFiling, orgFiling.file_count - 1);
- const fIndex = orgFiling.files.findIndex(x => x.id === file.id);
- if (fIndex >= 0) orgFiling.files.splice(fIndex, 1);
- }
- const targetFiling = self.findFiling(filingId);
- if (targetFiling) {
- self.updateFilingFileCount(targetFiling, targetFiling.file_count + 1);
- }
- if (fileSearch) fileSearch.refreshSearchFile(data.file);
- callback();
- });
- }
- setFileLocked(file, isLocked, errorCallback) {
- const self = this;
- postData('file/lock', { id: file.id, is_locked: isLocked ? 1 : 0 }, function(data) {
- file.is_locked = Number(data.is_locked) === 1 ? 1 : 0;
- if (fileSearch) fileSearch.refreshSearchFile(data);
- self.refreshFilesTable();
- }, errorCallback);
- }
- /**
- * 引用文件
- */
- relaFiles(files, callback) {
- const self = this;
- postData('file/rela', { filing_id: this.curFiling.id, files: files }, function(data) {
- self.updateFilingFileCount(self.curFiling, data.filing.file_count);
- if (!self.curFiling.files) self.curFiling.files = [];
- self.curFiling.files.unshift(...data.files);
- self.refreshPages();
- self.refreshFilesTable();
- self.refreshFileCountHint();
- if (callback) callback();
- });
- }
- /**
- * 检查同名文件
- */
- checkFilesExist(files, callback) {
- const data = [];
- for (const file of files) {
- if (file === undefined) return;
- data.push(file.name);
- }
- postData('file/check', { filing_id: this.curFiling.id, files: data }, function(result) {
- callback(result);
- });
- }
- /**
- * 清除所有文件缓存
- */
- _clearAllFileCache() {
- for (const node of this.filingTree.nodes) {
- if (node.is_leaf && node.files) {
- node.files.length = 0;
- }
- }
- }
- /**
- * 获取所有有查看权限的资料目录ID。
- */
- getAllFilingId() {
- return this.filingTree.nodes.filter(node => {
- return Boolean(this._getFilingPermission(node.id).can_view);
- }).map(node => node.id);
- }
- /**
- * 获取当前节点及其子节点中有查看权限的资料目录ID。
- */
- getCurFilingId() {
- if (!this.curFiling) return [];
- const includedTreeIds = new Set([this.curFiling.tree_id]);
- const result = [];
- this.filingTree.nodes.forEach(node => {
- if (node.tree_id !== this.curFiling.tree_id && !includedTreeIds.has(node.tree_pid)) return;
- includedTreeIds.add(node.tree_id);
- if (this._getFilingPermission(node.id).can_view) result.push(node.id);
- });
- return result;
- }
- }
- // 初始化
- const filingSjs = new FilingSjs();
- // 首次进入空资料项目时,由拥有“管理目录”权限的用户选择初始化方式。
- if (needFilingInitialization) {
- const initializationDescription = {
- blank: '从空白目录开始创建资料目录',
- template: '从系统内置模板库中选取',
- project: '从系统中其他有管理目录权限的项目资料中选取',
- };
- const refreshInitializationType = function() {
- const initType = $('[name=filing-initialization-type]:checked').val();
- $('#filing-initialization-description').text(initializationDescription[initType] || '');
- $('#filing-initialization-template-wrap').toggle(initType === 'template');
- $('#filing-initialization-project-wrap').toggle(initType === 'project');
- };
- $('[name=filing-initialization-type]').on('change', refreshInitializationType);
- $('#filing-initialization-ok').on('click', function() {
- const button = $(this);
- const initType = $('[name=filing-initialization-type]:checked').val();
- const data = { init_type: initType };
- if (initType === 'template') {
- data.template_id = $('#filing-initialization-template').val();
- if (!data.template_id) {
- toastr.warning('请选择系统模板库');
- return;
- }
- }
- if (initType === 'project') {
- data.source_spid = $('#filing-initialization-project').val();
- if (!data.source_spid) {
- toastr.warning('请选择来源项目');
- return;
- }
- }
- button.prop('disabled', true);
- postData('filing/init', data, function() {
- window.location.reload();
- }, function() {
- button.prop('disabled', false);
- });
- });
- refreshInitializationType();
- $('#filing-initialization-modal').appendTo(document.body).modal('show');
- }
- /**
- * MoveFileObj - 移动文件弹窗(SpreadJS树选择目标目录)
- */
- class MoveFileObj {
- constructor() {
- const self = this;
- this.moveTree = null;
- this.spread = null;
- this.sheet = null;
- this.file = null;
- this.filingTree = createNewPathTree('base', {
- id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level',
- isLeaf: 'is_leaf', fullPath: 'full_path', rootId: -1,
- });
- this.spreadSetting = {
- cols: [
- {
- title: '分类名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 280, formatter: '@', cellType: 'tree',
- getValue: function(data) {
- return data.name;
- },
- getIcon: function(data) {
- return data.is_leaf ? 'file' : 'folder';
- },
- },
- ],
- emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21,
- headColWidth: [25], headerFont: '12px 微软雅黑', font: '12px 微软雅黑',
- readOnly: true, selectedBackColor: '#e8f4fd',
- };
- $('#move-file2-ok').click(function() {
- const node = SpreadJsObj.getSelectObject(self.sheet);
- if (!node) {
- toastr.warning('请选择目标分类');
- return;
- }
- if (!node.is_leaf) {
- toastr.warning('请选择最底层目标分类');
- return;
- }
- if (String(node.id) !== String(self.file.filing_id) && !filingSjs.canUploadFiling(node.id)) {
- toastr.warning('您没有目标分类的上传/引用权限');
- return;
- }
- filingSjs.moveFile(self.file, node.id, function() {
- $('#move-file2').modal('hide');
- filingSjs.refreshPages();
- filingSjs.refreshFilesTable();
- });
- });
- $('a[name=mf2-showLevel]').click(function() {
- const tag = $(this).attr('tag');
- setTimeout(() => {
- showWaitingView();
- self._expandByLevel(tag);
- closeWaitingView();
- }, 100);
- });
- }
- _expandByLevel(level) {
- const nodes = this.filingTree.nodes;
- if (level === 'last') {
- for (const node of nodes) {
- node.expanded = !node.is_leaf;
- }
- } else {
- const maxLevel = parseInt(level);
- for (const node of nodes) {
- node.expanded = !node.is_leaf && node.level < maxLevel;
- }
- }
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
- }
- initMoveTree() {
- const convertedData = filingSjs._convertData(filing);
- this.filingTree.loadDatas(convertedData);
- if (this.spread) {
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
- } else {
- this.spread = SpreadJsObj.createNewSpread($('#moveFile')[0]);
- this.sheet = this.spread.getActiveSheet();
- SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
- }
- }
- show(file) {
- this.file = file;
- this.initMoveTree();
- $('#move-file2').modal('show');
- }
- }
- const moveFileObj = new MoveFileObj();
- /**
- * RelaFileLoader - 引用文件(标段树使用SpreadJS替代zTree)
- */
- class RelaFileLoader {
- constructor() {
- const self = this;
- this.curTender = null;
- this.curFiles = [];
- this.tenderFileType = [];
- this.tenderTree = null;
- this.spread = null;
- this.sheet = null;
- this.tenderPathTree = createNewPathTree('base', {
- id: 'tmt_id', pid: 'tmt_pid', order: 'sort', level: 'level',
- isLeaf: 'is_leaf', fullPath: 'full_path', rootId: -1,
- });
- this.spreadSetting = {
- cols: [{
- title: '标段列表', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 280,
- formatter: '@', cellType: 'tree',
- getValue: function(data) {
- return data.name;
- },
- getIcon: function(data) {
- return data.source_node && data.source_node.tid ? 'file' : 'folder';
- },
- }],
- emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21,
- headColWidth: [25], headerFont: '12px 微软雅黑', font: '12px 微软雅黑',
- readOnly: true, selectedBackColor: '#e8f4fd',
- };
- this.spread = SpreadJsObj.createNewSpread($('#rela-tender')[0]);
- this.sheet = this.spread.getActiveSheet();
- SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
- this.spread.bind(spreadNS.Events.SelectionChanged, async function(e, info) {
- const node = SpreadJsObj.getSelectObject(self.sheet);
- if (node && (!self.curTender || self.curTender.tmt_id !== node.tmt_id)) {
- await 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); });
- $('#tf-select').change(function() { self.selectTfId(this.value); });
- }
- _convertTenderData(data) {
- const tenderPathTree = Tender2Tree.convert(data.category, data.tenders, null, null, function(node, source) {
- _.assign(node, source);
- }, data.selfCategoryLevel);
- const sortedData = [...tenderPathTree.nodes].sort((a, b) => Number(a.level) - Number(b.level));
- const result = [];
- for (const node of sortedData) {
- const parent = (node.tmt_pid === -1 || node.tmt_pid === '-1') ? undefined : result.find(x => x.tmt_id === node.tmt_pid);
- if (!parent && node.tmt_pid !== -1 && node.tmt_pid !== '-1') continue;
- const hasChild = tenderPathTree.nodes.some(x => x.tmt_pid === node.tmt_id);
- result.push({
- tmt_id: node.tmt_id, tmt_pid: parent ? parent.tmt_id : -1,
- sort: node.sort || 0, level: node.level || 0,
- is_leaf: !hasChild, full_path: '', name: node.name, source_node: node,
- });
- }
- for (const node of result) { node._children = []; }
- for (const node of result) {
- if (node.tmt_pid !== -1) {
- const parent = result.find(x => x.tmt_id === node.tmt_pid);
- if (parent) parent._children.push(node);
- }
- }
- const calcCount = (node) => {
- if (node._children && node._children.length > 0) {
- for (const child of node._children) calcCount(child);
- node.total_file_count = node._children.reduce((sum, child) => sum + (child.total_file_count || 0), 0);
- } else { node.total_file_count = 0; }
- };
- for (const root of result.filter(x => x.tmt_pid === -1)) calcCount(root);
- for (const node of result) delete node._children;
- return result;
- }
- async showRelaFile() {
- $('#rela-filing-hint').html(`当前目录:${filingSjs.getCurFilingFullPath()}`);
- if (!this.tenderTree) {
- const data = await postDataAsync('file/rela/tender', {});
- this._tenderRawData = data;
- const convertedData = this._convertTenderData(data);
- this.tenderPathTree.loadDatas(convertedData);
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tenderPathTree);
- }
- this.clearFileSelect();
- this.refreshSelectHint();
- if (this.tenderPathTree.nodes.length > 0) {
- this.sheet.setActiveCell(0, 0);
- await this.setCurTender(this.tenderPathTree.nodes[0]);
- }
- }
- clearFileSelect() {
- if (!this.tenderPathTree) return;
- const recursiveFun = (nodes) => {
- if (!nodes || nodes.length === 0) return;
- for (const node of nodes) {
- const x = node.source_node;
- if (x.tid) {
- 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; }); });
- } else {
- recursiveFun(this.tenderPathTree.getChildren(node));
- }
- }
- };
- const roots = this.tenderPathTree.nodes.filter(n => n.level === 1);
- recursiveFun(roots);
- }
- refreshSelectHint() {
- if (this.curTender && this.curTender.source_node.tid) {
- $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
- } else {
- $('#cur-tender-hint').html('');
- }
- const nodes = this.tenderPathTree.nodes;
- const selectTenders = nodes.filter(x => x.source_node.tid && x.source_node.selectFiles && x.source_node.selectFiles.length > 0);
- if (selectTenders.length > 0) {
- const count = selectTenders.reduce((rst, x) => 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 => 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 => x.rf_id === file.rf_id);
- this.curTender.source_node.selectFiles.splice(index, 1);
- }
- this.refreshSelectHint();
- }
- }
- refreshTenderFileSelectId() {
- if (['change', 'change_apply', 'change_plan', 'change_project'].indexOf(this.rfType.type) >= 0) {
- const type = this.tenderFileType.find(x => x.value === this.rfType.type);
- const html = type.select.map(x => `<option value="${x.value}">${x.text}</option>`);
- $('#tf-select').html(html.join('')).show();
- this.rfType.selectId = type.select[0].value;
- } else {
- $('#tf-select').html('').hide();
- }
- }
- refreshTenderFileStage() {
- if (this.rfType.sub_type) {
- const type = this.tenderFileType.find(x => x.value === this.rfType.type);
- const subType = type.subType ? type.subType.find(x => 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 => x.value === this.rfType.type);
- if (type && 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 = [];
- if (tender.advance && tender.advance.length > 0) {
- const advanceType = [];
- tender.advance.forEach(x => {
- let at = advanceType.find(y => 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 });
- }
- if (tender.tid) this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
- if (tender.stage && tender.stage.length > 0) {
- const stages = tender.stage.map(x => ({ value: x.id, text: `第${x.order}期` }));
- this.tenderFileType.push({
- value: 'stage', text: '计量期',
- subType: [
- { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
- { value: 'dealPay', text: '合同支付', stage: JSON.parse(JSON.stringify(stages)) },
- { value: 'stageIm', text: '中间计量', stage: JSON.parse(JSON.stringify(stages)) },
- ],
- });
- }
- if (tender.change && tender.change.length > 0) {
- this.tenderFileType.push({ value: 'change', text: '变更令', select: tender.change.map(x => ({ value: x.cid, text: x.code })) });
- }
- if (tender.change_plan && tender.change_plan.length > 0) {
- this.tenderFileType.push({ value: 'change_plan', text: '变更方案', select: tender.change_plan.map(x => ({ value: x.id, text: x.code })) });
- }
- if (tender.change_apply && tender.change_apply.length > 0) {
- this.tenderFileType.push({ value: 'change_apply', text: '变更申请', select: tender.change_apply.map(x => ({ value: x.id, text: x.code })) });
- }
- if (tender.change_project && tender.change_project.length > 0) {
- this.tenderFileType.push({ value: 'change_project', text: '变更立项', select: tender.change_project.map(x => ({ value: x.id, text: x.code })) });
- }
- this.rfType = { type: tender.tid ? this.tenderFileType[0].value : '' };
- this.refreshTenderFileType();
- this.refreshTenderFileSubType();
- this.refreshTenderFileStage();
- this.refreshTenderFileSelectId();
- }
- async selectTfId(id) { this.rfType.selectId = id; await this.loadFiles(); this.refreshFileTable(); }
- 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(); this.refreshTenderFileSelectId(); await this.loadFiles(); this.refreshFileTable(); }
- refreshFileTable() {
- const html = [];
- const typeStr = [];
- $('option:selected', '#rela-file').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.source_node.tid, ...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 stage = this.curTender.source_node.stage.find(x => x.id == this.rfType.stage);
- if (!stage) { this.curFiles = []; return; }
- if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(this.rfType);
- this.curFiles = stage[this.rfType.sub_type];
- }
- async _loadAdvanceFile() {
- const advance = this.curTender.source_node.advance.find(x => x.id == this.rfType.stage);
- if (!advance) { this.curFiles = []; return; }
- if (!advance.files) advance.files = await this._loadRelaFiles(this.rfType);
- this.curFiles = advance.files;
- }
- async _loadChangeFile() {
- const change = this.curTender.source_node.change.find(x => x.cid === this.rfType.selectId);
- if (!change) { this.curFiles = []; return; }
- if (!change.files) change.files = await this._loadRelaFiles(this.rfType);
- this.curFiles = change.files;
- }
- async _loadChangePlanFile() {
- const change = this.curTender.source_node.change_plan.find(x => x.id == this.rfType.selectId);
- if (!change) { this.curFiles = []; return; }
- if (!change.files) change.files = await this._loadRelaFiles(this.rfType);
- this.curFiles = change.files;
- }
- async _loadChangeProjectFile() {
- const change = this.curTender.source_node.change_project.find(x => x.id == this.rfType.selectId);
- if (!change) { this.curFiles = []; return; }
- if (!change.files) change.files = await this._loadRelaFiles(this.rfType);
- this.curFiles = change.files;
- }
- async _loadChangeApplyFile() {
- const change = this.curTender.source_node.change_apply.find(x => x.id == this.rfType.selectId);
- if (!change) { this.curFiles = []; return; }
- if (!change.files) change.files = await this._loadRelaFiles(this.rfType);
- this.curFiles = change.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;
- case 'change': await this._loadChangeFile(); break;
- case 'change_plan': await this._loadChangePlanFile(); break;
- case 'change_project': await this._loadChangeProjectFile(); break;
- case 'change_apply': await this._loadChangeApplyFile(); break;
- default: this.curFiles = [];
- }
- 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 = [];
- for (const node of this.tenderPathTree.nodes) {
- if (!node.source_node.selectFiles || node.source_node.selectFiles.length === 0) continue;
- 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;
- }
- }
- /**
- * FileSearch - 文件搜索类
- */
- 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 canOperateFile = !filingSjs.isFileLocked(file) && filingSjs.canEditFiling(file.filing_id);
- const editHtml = canOperateFile ? `<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 = canOperateFile ? `<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 name="filename" 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_id = filter === 'all' ? filingSjs.getAllFilingId() : filingSjs.getCurFilingId();
- return { filing_id };
- }
- 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 self = this;
- const searchData = this.getSearchFilter();
- searchData.keyword = $('#search-keyword', '#search').val();
- if (!searchData.keyword) {
- toastr.warning('请输入查询的文件名称');
- this.getResultHtml([]);
- return;
- }
- postData('file/search', searchData, function(result) {
- if (result.list.length === result.limit) toastr.warning(`最多查询${result.limit}个结果,请给出更准确的文件名称`);
- $('#search-list').html(self.getResultHtml(result.list));
- });
- }
- refreshSearchFile(file) {
- const sfile = this.searchResult.find(x => x.id === file.id);
- if (sfile) {
- for (const prop in file) {
- if (prop === 'id') continue;
- sfile[prop] = file[prop];
- }
- const row = $(`tr[fid=search_${sfile.id}]`);
- if (row.length > 0) row.replaceWith(this.getFileHtml(sfile));
- }
- }
- removeSearchFile(fid) {
- $(`tr[fid=search_${fid}]`, '#search').remove();
- const index = this.searchResult.findIndex(x => x.id === fid);
- if (index >= 0) this.searchResult.splice(index, 1);
- }
- renameSearchFile(fid, data) {
- const file = this.searchResult.find(x => 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;
- $('input', '#search').bind('keydown', function(e) {
- if (e.keyCode === 13) self.search();
- });
- $('button', '#search').bind('click', () => { self.search(); });
- }
- }
- fileSearch = new FileSearch();
- /**
- * FilingPermission - 授权用户管理
- */
- 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' },
- { title: '归档单位', colSpan: '1', rowSpan: '1', field: 'file_company', hAlign: 0, width: 80, formatter: '@', cellType: 'autoTip' },
- ],
- 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) {
- if (info.newSelections[0].col === 1) {
- info.sheet.setSelection(info.oldSelections[0].row, info.oldSelections[0].col, info.oldSelections[0].rowCount, info.oldSelections[0].colCount);
- SpreadJsObj.reloadRowsBackColor(info.sheet, [info.newSelections[0].row, info.oldSelections[0].row]);
- } else {
- 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(e) {
- const type = $(this).data('type');
- if (type === 'all') {
- const cid = parseInt($(this).data('id'));
- const company = self.company.find(x => 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 => x.id === uid);
- if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
- }
- self.loadCurFiling();
- e.stopPropagation();
- });
- $('#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();
- this.syncPermissionUserSelectedMarks();
- });
- $('#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 => 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;
- this.syncPermissionUserSelectedMarks();
- }
- refreshBtn() {
- const self = this;
- const filing = this.permissionTree.nodes.find(x => 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 = [];
- const currentFilingUserIds = new Set();
- if (this.permissionUser && Array.isArray(this.permissionUser)) {
- for (const f of this.permissionUser) {
- if (f.filing_type && f.filing_type.indexOf(this.curFiling) >= 0) {
- currentFilingUserIds.add(f.id);
- }
- }
- }
- 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) {
- const initialDisplayStyle = currentFilingUserIds.has(u.id) ? 'display:inline-block;' : 'display:none;';
- 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><span class="selected-mark text-success ml-2" style="${initialDisplayStyle}"><i class="fa fa-check"></i></span></p>`);
- html.push(`<span class="text-muted">${u.role}</span>`);
- html.push('</dd>');
- }
- html.push('</div>');
- }
- $('#puList').html(html.join(''));
- }
- syncPermissionUserSelectedMarks() {
- const tableUserIds = new Set();
- $(this.setting.list + ' tr').each(function() {
- const $firstInput = $(this).find('input[name="ftu-check"]').first();
- if ($firstInput.length) {
- const uid = parseInt($firstInput.attr('uid'), 10);
- if (!isNaN(uid)) tableUserIds.add(uid);
- }
- });
- $('#puList dd[data-id]').each(function() {
- const userId = parseInt($(this).data('id'), 10);
- const $mark = $(this).find('.selected-mark');
- if (!isNaN(userId) && $mark.length > 0 && $(this).data('type') !== 'all') {
- if (tableUserIds.has(userId)) { $mark.show(); } else { $mark.hide(); }
- }
- });
- }
- _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 => x.id === node.tree_pid);
- const child = sourceTree.nodes.find(x => 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_company: node.file_company,
- file_count: node.file_count,
- });
- }
- return data;
- }
- loadPermission() {
- this.permissionTree.loadDatas(this._convertData({nodes: filing}));
- 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 => 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 refreshSideLayout = function() {
- filingSjs.spread.refresh();
- if (fileReference) fileReference.spread.refresh();
- };
- const showSideTools = function(show) {
- const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
- if (show) {
- right.show();
- autoFlashHeight();
- const percent = 100 - right.outerWidth() / parent.width() * 100;
- left.css('width', percent + '%');
- } else {
- left.css('width', '100%');
- right.hide();
- }
- // 容器宽度变化后再刷新 SpreadJS,避免继续使用展开前的画布尺寸。
- setTimeout(refreshSideLayout, 0);
- };
- // 展开收起侧边工具栏
- $('a', '#side-menu').bind('click', function(e) {
- e.preventDefault();
- const tab = $(this), tabPanel = $(tab.attr('content'));
- if (!tab.hasClass('active')) {
- $('a', '#side-menu').removeClass('active');
- $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('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,
- 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'));
- }
- });
- // 左右拖拽分隔条
- $.divResizer({
- select: '#file-right-spr',
- callback: function() { filingSjs.spread.refresh(); },
- });
- $.divResizer({
- select: '#right-spr',
- callback: refreshSideLayout,
- });
- // ========== 事件委托绑定 ==========
- // 文件行内操作:鼠标悬停显示按钮
- $('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('change', 'input[name=file-lock]', function() {
- const lockSwitch = $(this);
- const fid = this.getAttribute('fid');
- const file = filingSjs.curFiling.files.find(x => x.id === fid);
- if (!file) {
- lockSwitch.prop('checked', !this.checked);
- return;
- }
- const isLocked = this.checked;
- lockSwitch.prop('disabled', true);
- filingSjs.setFileLocked(file, isLocked, function() {
- lockSwitch.prop('checked', !isLocked).prop('disabled', false);
- });
- });
- // 单个删除文件
- $('body').on('click', 'a[name=del-file]', function() {
- const fid = this.getAttribute('fid');
- const filename = $(`div[name=filename][fid=${fid}]`)[0].innerHTML;
- filingSjs.delFiles([fid], null, `确认删除「${filename}」?`);
- });
- // 重命名文件 - 进入编辑模式
- $('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 = filingSjs.curFiling.files.find(x => x.id === id);
- $(`td[fid=${id}]`).html(filingSjs._getEditFileNameHtml(file));
- });
- // 重命名文件 - 确认
- $('body').on('click', 'a[name=edit-file-ok]', function() {
- const td = $(this).parent().parent().parent();
- const fid = td.attr('fid');
- const file = filingSjs.curFiling.files.find(x => x.id === fid);
- if (!file) return;
- const filename = $('input', td).val();
- if (filename === file.filename + file.fileext) {
- td.html(filingSjs._getFileNameHtml(file));
- return;
- }
- filingSjs.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 = filingSjs.curFiling.files.find(x => x.id === fid);
- if (!file) return;
- td.html(filingSjs._getFileNameHtml(file));
- });
- // 移动文件
- $('body').on('click', 'a[name=move-file]', function() {
- const id = this.getAttribute('fid');
- const file = filingSjs.curFiling.files.find(x => x.id === id);
- moveFileObj.show(file);
- });
- // 搜索结果中删除文件
- $('body').on('click', 'a[name=del-search-file]', function() {
- const del = [this.getAttribute('fid')];
- const filename = $('[name=filename]', $(this).closest('tr'))[0].innerHTML;
- filingSjs.delFiles(del, null, `确认删除「${filename}」?`);
- });
- // 搜索结果中定位文件
- $('body').on('click', 'a[name=locate-search-file]', function() {
- const fid = this.getAttribute('fid');
- const file = fileSearch.searchResult.find(x => x.id === fid);
- if (!file) return;
- const filingNode = filingSjs.findFiling(file.filing_id);
- if (filingNode) {
- const rowIndex = filingSjs.filingTree.nodes.indexOf(filingNode);
- if (rowIndex >= 0) {
- filingSjs.sheet.setActiveCell(rowIndex, 0);
- filingSjs.setCurFiling(filingNode);
- }
- }
- });
- // 搜索结果中重命名文件
- $('body').on('click', 'a[name=edit-search-file]', function() {
- const id = this.getAttribute('fid');
- const file = fileSearch.searchResult.find(x => x.id === id);
- $(`td[fid=search_${id}]`).html(fileSearch.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 = fileSearch.searchResult.find(x => x.id === fid);
- if (!file) return;
- filingSjs.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 = fileSearch.searchResult.find(x => x.id === fid);
- if (!file) return;
- td.html(`${file.filename}${file.fileext}`);
- });
- // ========== Modal 事件 ==========
- // 上传文件弹窗显示时重置
- $('#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(function() {
- $('#add-file-ok').attr('disabled', true);
- const input = $(this);
- filingSjs.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').off('click').on('click', function() {
- const input = $('#upload-file');
- const filter = $('#filter-same')[0].checked;
- const filterFiles = filter ? $('#filter-same').attr('filterFiles').split('$;$') : [];
- const files = input[0].files;
- if (!files || files.length === 0) { toastr.error('未选择上传文件。'); return; }
- const formData = new FormData();
- formData.append('filing_id', filingSjs.curFiling.id);
- let count = 0;
- for (const file of files) {
- if (filterFiles.indexOf(file.name) >= 0) continue;
- if (file.size > 50 * 1024 * 1024) { toastr.error('上传文件大小超过50MB。'); return; }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) { toastr.error('仅支持造价文件、Office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。'); return; }
- formData.append('size', file.size);
- formData.append('file[]', file);
- count++;
- }
- if (count === 0) { toastr.warning('没有可上传的文件'); return; }
- postDataWithFile('file/upload', formData, function(data) {
- filingSjs.updateFilingFileCount(filingSjs.curFiling, data.filing.file_count);
- if (!filingSjs.curFiling.files) filingSjs.curFiling.files = [];
- filingSjs.curFiling.files.unshift(...data.files);
- filingSjs.refreshPages();
- filingSjs.refreshFilesTable();
- filingSjs.refreshFileCountHint();
- $(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(function() {
- $('#add-big-file-ok').attr('disabled', true);
- const input = $(this);
- filingSjs.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').off('click').on('click', function() {
- const input = $('#upload-big-file');
- const file = input[0].files[0];
- if (!file) { toastr.error('未选择上传文件。'); return; }
- if (file.size > 500 * 1024 * 1024) { toastr.error('上传文件大小超过500MB。'); return; }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) { toastr.error('仅支持造价文件、Office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。'); return; }
- AliOss.uploadBigFile(file, 'file/upload/big', { filing_id: filingSjs.curFiling.id },
- { progressObj: $('#upload-big-file-progress'), resumeObj: $('#add-big-file-resume'), stopObj: $('#add-big-file-stop') },
- function(result) {
- if (!filingSjs.curFiling.files) filingSjs.curFiling.files = [];
- filingSjs.curFiling.files.unshift(...result.files);
- filingSjs.updateFilingFileCount(filingSjs.curFiling, result.filing.file_count);
- filingSjs.refreshPages();
- filingSjs.refreshFilesTable();
- filingSjs.refreshFileCountHint();
- $(input).val('');
- $('#add-big-file').modal('hide');
- }
- );
- });
- // 删除分类确认弹窗
- $('#del-filing-ok').off('click').on('click', function() {
- if (filingSjs.selectRemoveNode) {
- filingSjs.delFiling(filingSjs.selectRemoveNode, function() {
- $('#del-filing').modal('hide');
- });
- }
- });
- // 批量删除确认
- $('#batch-del-file-ok').off('click').on('click', function() {
- const del = [];
- const checkes = $('[name=bd-check]:checked');
- checkes.each(function() { del.push(this.getAttribute('fid')); });
- filingSjs.delFiles(del, function() {
- $('#batch-del-file').modal('hide');
- });
- });
- // 覆盖批量删除按钮(增加权限检查)
- $('#batch-del-file-btn').off('click').on('click', function() {
- if (projectFileLocked) { toastr.error('管理员锁定中,暂无法删除文件'); return; }
- if (!canEdit) { toastr.error('您没有当前目录的编辑文件权限'); return; }
- const checkes = $('[name=bd-check]:checked');
- if (checkes.length === 0) { toastr.warning('请选择要删除的文件'); return; }
- for (const c of checkes) {
- const fid = c.getAttribute('fid');
- const file = filingSjs.curFiling.files.find(x => x.id === fid);
- if (!file) continue;
- if (filingSjs.isFileLocked(file)) {
- toastr.error(`文件【${file.filename + file.fileext}】已锁定,无法删除`);
- return;
- }
- }
- $('#batch-del-file').modal('show');
- });
- // 覆盖批量下载(使用zip打包)
- $('#batch-download').off('click').on('click', function() {
- filingSjs.batchDownloadFiles();
- });
- // 覆盖移动文件确认
- $('#move-file2-ok').off('click');
- // 引用文件
- const relaFileLoader = new RelaFileLoader();
- $('#rela-file').on('show.bs.modal', function() {
- relaFileLoader.showRelaFile(this.getAttribute('content'));
- });
- // 授权用户
- const filingPermission = new FilingPermission({
- modal: '#filing-permission',
- list: '#filing-valid',
- spread: '#permission-spread',
- });
- });
|