filesjs.js 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190
  1. $(document).ready(function() {
  2. let fileSearch, fileReference;
  3. autoFlashHeight();
  4. /**
  5. * FilingSjs - 资料管理 SpreadJS 版本
  6. * 使用 SpreadJS 替代 zTree 展示文件分类树,保留完整的文件管理功能
  7. */
  8. class FilingSjs {
  9. constructor() {
  10. // 初始化 SpreadJS
  11. this.spread = SpreadJsObj.createNewSpread($('#filing-spread')[0]);
  12. this.spread.options.showHorizontalScrollbar = false; // 隐藏水平滚动条
  13. this.sheet = this.spread.getActiveSheet();
  14. // 初始化 PathTree,使用 zh_filing 原有字段映射
  15. this.filingTree = createNewPathTree('base', {
  16. id: 'tree_id',
  17. pid: 'tree_pid',
  18. order: 'order',
  19. level: 'level',
  20. isLeaf: 'is_leaf',
  21. fullPath: 'full_path',
  22. rootId: -1,
  23. });
  24. // SpreadJS 表格配置
  25. this.spreadSetting = {
  26. cols: [
  27. {
  28. title: '分类名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 220, formatter: '@', cellType: 'tree',
  29. getValue: function(data) {
  30. return data.name;
  31. },
  32. getIcon: function(data) {
  33. return data.is_leaf ? 'file' : 'folder';
  34. },
  35. },
  36. { title: '文件数', colSpan: '1', rowSpan: '1', field: 'total_file_count', hAlign: 1, width: 70, formatter: '@' },
  37. ],
  38. emptyRows: 0,
  39. headRows: 1,
  40. headRowHeight: [32],
  41. defaultRowHeight: 21,
  42. headColWidth: [25],
  43. headerFont: '12px 微软雅黑',
  44. font: '12px 微软雅黑',
  45. readOnly: true,
  46. selectedBackColor: '#e8f4fd',
  47. };
  48. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  49. // 文件管理相关属性
  50. this.pageCount = 15;
  51. this.curPage = 1;
  52. this.curTotalPage = 1;
  53. this.curFiling = null;
  54. this.selectRemoveNode = null;
  55. this.fileOrderKey = 'fileOrderSjs';
  56. this.fileOrder = getLocalCache(this.fileOrderKey) || 'create_time|desc';
  57. this.curFilingKey = 'cur-filing-sjs-' + window.location.pathname.split('/')[2];
  58. this._isRenaming = false;
  59. this._bindEvents();
  60. this._loadFilingData();
  61. this.refreshFileOrderButton();
  62. }
  63. /**
  64. * 递归累加文件数
  65. */
  66. _calcTotalFileCount(data) {
  67. for (const node of data) {
  68. node.total_file_count = 0;
  69. node._children = [];
  70. }
  71. for (const node of data) {
  72. if (node.tree_pid !== -1) {
  73. const parent = data.find(x => x.tree_id === node.tree_pid);
  74. if (parent) {
  75. parent._children.push(node);
  76. }
  77. }
  78. }
  79. const calcNode = (node) => {
  80. if (node._children && node._children.length > 0) {
  81. for (const child of node._children) {
  82. calcNode(child);
  83. }
  84. node.total_file_count = node._children.reduce((sum, child) => {
  85. return sum + child.total_file_count;
  86. }, 0);
  87. } else {
  88. node.total_file_count = node.file_count || 0;
  89. }
  90. };
  91. const roots = data.filter(x => x.tree_pid === -1);
  92. for (const root of roots) {
  93. calcNode(root);
  94. }
  95. for (const node of data) {
  96. delete node._children;
  97. }
  98. }
  99. /**
  100. * 转换数据格式
  101. */
  102. _convertData(sourceData) {
  103. const data = [];
  104. const skippedIds = new Set();
  105. const sortedData = [...sourceData].sort((a, b) => {
  106. return Number(a.tree_level) - Number(b.tree_level);
  107. });
  108. for (const node of sortedData) {
  109. if (skippedIds.has(node.tree_pid)) {
  110. skippedIds.add(node.id);
  111. continue;
  112. }
  113. const parent = (node.tree_pid === '-1' || node.tree_pid === -1)
  114. ? undefined
  115. : data.find(x => x.id === node.tree_pid);
  116. const hasChild = sourceData.some(x => x.tree_pid === node.id);
  117. if (!parent && node.tree_pid !== '-1' && node.tree_pid !== -1) {
  118. skippedIds.add(node.id);
  119. continue;
  120. }
  121. const convertedNode = {
  122. id: node.id,
  123. tree_id: data.length + 1,
  124. tree_pid: parent ? parent.tree_id : -1,
  125. order: Number(node.tree_order) + 1,
  126. level: Number(node.tree_level),
  127. is_leaf: !hasChild,
  128. full_path: '',
  129. name: node.name,
  130. filing_type: Number(node.filing_type),
  131. file_count: Number(node.file_count) || 0,
  132. is_fixed: node.is_fixed,
  133. tips: node.tips || '',
  134. upload_tips: node.upload_tips || '',
  135. spid: node.spid,
  136. };
  137. data.push(convertedNode);
  138. }
  139. this._calcTotalFileCount(data);
  140. return data;
  141. }
  142. /**
  143. * 加载 filing 数据到 SpreadJS
  144. */
  145. _loadFilingData() {
  146. const convertedData = this._convertData(filing);
  147. this.filingTree.loadDatas(convertedData);
  148. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
  149. // 恢复上次选中的节点
  150. const curCache = getLocalCache(this.curFilingKey);
  151. if (curCache) {
  152. const curNode = this.filingTree.nodes.find(x => x.id === curCache);
  153. if (curNode) {
  154. this.setCurFiling(curNode);
  155. }
  156. }
  157. this.refreshFileCountHint();
  158. }
  159. /**
  160. * 绑定事件
  161. */
  162. _bindEvents() {
  163. const self = this;
  164. // 选中行变化事件
  165. this.spread.bind(spreadNS.Events.SelectionChanged, async function(e, info) {
  166. if (self._isRenaming) return;
  167. const node = SpreadJsObj.getSelectObject(self.sheet);
  168. if (node && (!self.curFiling || self.curFiling.id !== node.id)) {
  169. await self.setCurFiling(node);
  170. }
  171. });
  172. // 显示层级按钮点击
  173. $('[name=showLevel]').click(function() {
  174. const tag = $(this).attr('tag');
  175. self._showLevel(tag);
  176. });
  177. // 添加同级
  178. $('#add-slibing').click(function() {
  179. if (!self.curFiling) return;
  180. if (self.curFiling.is_fixed) {
  181. toastr.error('固定分类不可添加同级');
  182. return;
  183. }
  184. self.addSiblingFiling(self.curFiling);
  185. });
  186. // 添加子级
  187. $('#add-child').click(function() {
  188. if (!self.curFiling) return;
  189. const children = self.filingTree.getChildren(self.curFiling);
  190. const fixedChild = children.find(x => x.is_fixed);
  191. if (fixedChild) {
  192. toastr.error('该分类下存在固定分类,不可添加子级');
  193. return;
  194. }
  195. if (self.curFiling.file_count > 0) {
  196. toastr.error('该分类下已导入文件,不可添加子级');
  197. return;
  198. }
  199. self.addChildFiling(self.curFiling);
  200. });
  201. // 文件排序
  202. $('[name=file-sort]').click(function() {
  203. const tag = $(this).attr('tag');
  204. self.changeFileOrder(tag);
  205. });
  206. // 分页
  207. $('.page-select[content=pre]').click(function() {
  208. self.prePage();
  209. });
  210. $('.page-select[content=next]').click(function() {
  211. self.nextPage();
  212. });
  213. // 双击行内重命名分类
  214. $('#filing-spread').dblclick(function() {
  215. if (!canFiling) return;
  216. if (self._isRenaming) return;
  217. const node = SpreadJsObj.getSelectObject(self.sheet);
  218. if (!node || node.is_fixed) return;
  219. self._isRenaming = true;
  220. const rowIndex = self.filingTree.nodes.indexOf(node);
  221. const cellRect = self.sheet.getCellRect(rowIndex, 0);
  222. const containerRect = $('#filing-spread')[0].getBoundingClientRect();
  223. const inputLeft = containerRect.left + window.scrollX + cellRect.x + 2;
  224. const inputTop = containerRect.top + window.scrollY + cellRect.y + 2;
  225. const inputWidth = cellRect.width - 4;
  226. const inputHeight = cellRect.height - 4;
  227. const $input = $('<input type="text" class="form-control form-control-sm">')
  228. .val(node.name)
  229. .css({
  230. position: 'absolute',
  231. left: inputLeft,
  232. top: inputTop,
  233. width: inputWidth,
  234. height: inputHeight,
  235. zIndex: 1000,
  236. fontSize: '12px',
  237. padding: '0 4px',
  238. border: '2px solid #4a90d9',
  239. borderRadius: '2px',
  240. outline: 'none',
  241. boxShadow: '0 0 4px rgba(74,144,217,0.4)',
  242. });
  243. let handled = false;
  244. const finishEdit = async (save) => {
  245. if (handled) return;
  246. handled = true;
  247. const newName = $input.val().trim();
  248. $input.remove();
  249. self._isRenaming = false;
  250. if (save && newName && newName !== node.name) {
  251. await self.renameFiling(node, newName);
  252. }
  253. };
  254. $input.on('keydown', function(e) {
  255. if (e.keyCode === 13) { // Enter
  256. e.preventDefault();
  257. finishEdit(true);
  258. } else if (e.keyCode === 27) { // Escape
  259. e.preventDefault();
  260. finishEdit(false);
  261. }
  262. });
  263. $input.on('blur', function() { finishEdit(true); });
  264. $('body').append($input);
  265. $input.focus().select();
  266. });
  267. // 右键菜单 - 删除分类
  268. $.contextMenu({
  269. selector: '#filing-spread',
  270. build: function ($trigger, e) {
  271. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
  272. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  273. },
  274. items: {
  275. 'delete': {
  276. name: '删除',
  277. icon: 'fa-trash-o',
  278. callback: function () {
  279. const node = SpreadJsObj.getSelectObject(self.sheet);
  280. if (!node || node.is_fixed) return;
  281. self.selectRemoveNode = node;
  282. $('#del-filing').modal('show');
  283. },
  284. disabled: function () {
  285. const node = SpreadJsObj.getSelectObject(self.sheet);
  286. return !canFiling || !node || node.is_fixed;
  287. },
  288. },
  289. },
  290. });
  291. }
  292. /**
  293. * 设置当前选中的分类
  294. */
  295. async setCurFiling(node) {
  296. this.curFiling = node;
  297. this._applyCurrentPermission(node);
  298. this.curPage = 1;
  299. this.refreshPages();
  300. const permission = this._getFilingPermission(node.id);
  301. if (!permission.can_view) {
  302. $('#file-view').hide();
  303. setLocalCache(this.curFilingKey, node.id);
  304. return;
  305. }
  306. // 判断是否为叶子节点:无子节点或有文件都视为可展示文件的节点
  307. const hasChildren = this.filingTree.getChildren(node).length > 0;
  308. const isLeafNode = !hasChildren || node.file_count > 0;
  309. if (isLeafNode) {
  310. $('#file-view').show();
  311. this.refreshUploadTips(node);
  312. await this.loadFiles(node, 1);
  313. this.refreshFilesTable();
  314. } else {
  315. $('#file-view').hide();
  316. }
  317. setLocalCache(this.curFilingKey, node.id);
  318. }
  319. /**
  320. * 刷新当前目录的上报说明
  321. */
  322. refreshUploadTips(node) {
  323. const uploadTips = node ? String(node.upload_tips || '').trim() : '';
  324. $('#filing-upload-tips')
  325. .text(uploadTips || '暂无上报说明')
  326. .toggleClass('text-muted', !uploadTips);
  327. }
  328. _getFilingPermission(filingId) {
  329. return filingPermissionMap[String(filingId)] || {
  330. can_view: 0,
  331. can_upload: 0,
  332. can_edit_file: 0,
  333. can_edit_dir: 0,
  334. can_lock_file: 0,
  335. };
  336. }
  337. _applyCurrentPermission(node) {
  338. const permission = this._getFilingPermission(node.id);
  339. canUpload = Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_upload);
  340. canEdit = Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_edit_file);
  341. canFiling = Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_edit_dir);
  342. canLockFile = Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_lock_file);
  343. $('.js-can-upload').toggle(canUpload);
  344. $('.js-can-edit-dir').toggle(canFiling);
  345. }
  346. canUploadFiling(filingId) {
  347. const permission = this._getFilingPermission(filingId);
  348. return Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_upload);
  349. }
  350. canEditFiling(filingId) {
  351. const permission = this._getFilingPermission(filingId);
  352. return Boolean(permission.can_view) && !projectFileLocked && Boolean(permission.can_edit_file);
  353. }
  354. isFileLocked(file) {
  355. return Boolean(file) && Number(file.is_locked) === 1;
  356. }
  357. /**
  358. * 刷新文件数量提示
  359. */
  360. refreshFileCountHint() {
  361. const sum = _.sum(this.filingTree.nodes.filter(x => x.level === 1).map(x => x.total_file_count));
  362. $('#file-count').html(`文件总数:${sum}`);
  363. }
  364. /**
  365. * 刷新文件排序按钮
  366. */
  367. refreshFileOrderButton() {
  368. const orderBy = this.fileOrder.split('|');
  369. const field = orderBy[0], sort = orderBy[1];
  370. const buttons = $('[name=file-sort]');
  371. for (const b of buttons) {
  372. const curField = b.getAttribute('field');
  373. if (curField === field) {
  374. $(b).html(`<i class="fa fa-sort-amount-${sort}" aria-hidden="true"></i>`).attr('tag', `${curField}|${sort === 'asc' ? 'desc' : 'asc'}`);
  375. } else {
  376. $(b).html('<i class="fa fa-sort" aria-hidden="true">').attr('tag', `${curField}|desc`);
  377. }
  378. }
  379. }
  380. /**
  381. * 刷新分页
  382. */
  383. refreshPages() {
  384. if (!this.curFiling) return;
  385. this.curTotalPage = Math.ceil(this.curFiling.file_count / this.pageCount);
  386. this.curPage = Math.min(this.curTotalPage, Math.max(this.curPage, 1));
  387. $('#curPage').html(this.curPage);
  388. $('#curTotalPage').html(this.curTotalPage);
  389. if (this.curTotalPage > 1) {
  390. $('#showPage').show();
  391. } else {
  392. $('#showPage').hide();
  393. }
  394. }
  395. /**
  396. * 加载文件列表
  397. */
  398. async loadFiles(node, page) {
  399. if (!node.files) node.files = [];
  400. if (!node.file_count) return;
  401. const needFiles = Math.min(page * this.pageCount, node.file_count);
  402. if (node.files.length >= needFiles) return;
  403. const files = await postDataAsync('file/load', {
  404. filing_id: node.id,
  405. page,
  406. count: this.pageCount,
  407. order: this.fileOrder
  408. });
  409. files.forEach(x => {
  410. const file = node.files.find(f => f.id === x.id);
  411. if (file) {
  412. Object.assign(file, x);
  413. } else {
  414. node.files.push(x);
  415. }
  416. });
  417. }
  418. /**
  419. * 刷新文件表格
  420. */
  421. refreshFilesTable() {
  422. const html = [];
  423. const files = this.curFiling.files;
  424. if (!files || files.length === 0) {
  425. $('#file-list').html('');
  426. return;
  427. }
  428. const startIndex = (this.curPage - 1) * this.pageCount;
  429. const endIndex = this.curPage * this.pageCount;
  430. for (let i = startIndex; i < endIndex && i < files.length; i++) {
  431. const file = files[i];
  432. html.push(this._getFileHtml(file));
  433. }
  434. $('#file-list').html(html.join(''));
  435. }
  436. /**
  437. * 生成文件HTML
  438. */
  439. _getFileHtml(file) {
  440. const isLocked = this.isFileLocked(file);
  441. const canOperateFile = !isLocked && canEdit;
  442. const moveHtml = canOperateFile ?
  443. `<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>` : '';
  444. const editHtml = canOperateFile ?
  445. `<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>` : '';
  446. const viewHtml = file.viewpath ?
  447. `<a href="${file.viewpath}" class="dropdown-item text-primary" target="_blank"><i class="fa fa-eye fa-fw"></i> 预览</a>` : '';
  448. const downHtml =
  449. `<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>`;
  450. const delHtml = canOperateFile ?
  451. `<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>` : '';
  452. const lockId = `file-lock-${file.id}`;
  453. const lockHtml = canLockFile ?
  454. `<div class="custom-control custom-switch d-inline-block">
  455. <input type="checkbox" class="custom-control-input" name="file-lock" id="${lockId}" fid="${file.id}" ${isLocked ? 'checked' : ''}>
  456. <label class="custom-control-label" for="${lockId}"></label>
  457. </div>` : (isLocked ? '<i class="fa fa-lock text-danger" title="文件已锁定"></i>' : '');
  458. const html = [];
  459. html.push(`<tr fid="${file.id}">`);
  460. html.push(`<td class="text-center"><input type="checkbox" name="bd-check" fid="${file.id}"></td>`);
  461. 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>`);
  462. html.push(`<td class="text-center">${lockHtml}</td>`);
  463. html.push(`<td class="text-center">${file.user_name}</td>`);
  464. html.push(`<td class="text-center">${moment(file.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  465. html.push(`<td class="text-center">${file.fileext_str}</td>`);
  466. html.push(`<td class="text-center">
  467. <div class="dropdown">
  468. <a href="javascript: void(0);" class="dropdown-toggle text-primary" data-toggle="dropdown"><i class="fa fa-bars"></i></a>
  469. <div class="dropdown-menu">
  470. ${editHtml}${viewHtml}${moveHtml}${downHtml}${delHtml}
  471. </div>
  472. </div>
  473. </td>`);
  474. html.push('</tr>');
  475. return html.join('');
  476. }
  477. /**
  478. * 生成文件名显示HTML
  479. */
  480. _getFileNameHtml(file) {
  481. 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>`;
  482. }
  483. /**
  484. * 添加同级分类
  485. */
  486. addSiblingFiling(node) {
  487. const self = this;
  488. const treePid = node.tree_pid === -1 ? '-1' : this._findOriginalId(node.tree_pid);
  489. postData('filing/add', { tree_pid: treePid, tree_pre_id: node.id }, function(result) {
  490. filing.push(result);
  491. self._reloadFilingTree();
  492. });
  493. }
  494. /**
  495. * 添加子级分类
  496. */
  497. addChildFiling(node) {
  498. const self = this;
  499. postData('filing/add', { tree_pid: node.id }, function(result) {
  500. filing.push(result);
  501. self._reloadFilingTree();
  502. });
  503. }
  504. /**
  505. * 重新加载归档树
  506. */
  507. _reloadFilingTree() {
  508. const convertedData = this._convertData(filing);
  509. this.filingTree.loadDatas(convertedData);
  510. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
  511. this.refreshFileCountHint();
  512. }
  513. /**
  514. * 删除分类
  515. */
  516. delFiling(node, callback) {
  517. const self = this;
  518. const parent = this.filingTree.getParent(node);
  519. postData('filing/del', { id: node.id }, function(result) {
  520. // 更新 filing 数组:移除已删除的节点
  521. if (result && result.delete) {
  522. for (const delId of result.delete) {
  523. const idx = filing.findIndex(x => x.id === delId);
  524. if (idx >= 0) filing.splice(idx, 1);
  525. }
  526. }
  527. // 更新兄弟节点的 tree_order
  528. if (result && result.update) {
  529. for (const u of result.update) {
  530. const srcNode = filing.find(x => x.id === u.id);
  531. if (srcNode) srcNode.tree_order = u.tree_order;
  532. }
  533. }
  534. // 重新加载树
  535. self._reloadFilingTree();
  536. $('#file-view').hide();
  537. self.curFiling = null;
  538. if (callback) callback();
  539. });
  540. }
  541. /**
  542. * 重命名分类
  543. */
  544. async renameFiling(node, newName) {
  545. const result = await postDataAsync('filing/save', { id: node.id, name: newName });
  546. const srcNode = filing.find(x => x.id === node.id || x.id == node.id);
  547. if (srcNode) srcNode.name = newName;
  548. node.name = newName;
  549. const countHint = node.total_file_count > 0 ? `(${node.total_file_count})` : '';
  550. node.name = newName;
  551. const rowIndex = this.filingTree.nodes.indexOf(node);
  552. if (rowIndex >= 0) {
  553. SpreadJsObj.reLoadRowsData(this.sheet, [rowIndex]);
  554. }
  555. let parent = this.filingTree.getParent(node);
  556. while (parent) {
  557. const pIdx = this.filingTree.nodes.indexOf(parent);
  558. if (pIdx >= 0) SpreadJsObj.reLoadRowsData(this.sheet, [pIdx]);
  559. parent = this.filingTree.getParent(parent);
  560. }
  561. return result;
  562. }
  563. /**
  564. * 移动分类
  565. */
  566. moveFiling(node, newTreePid, newOrder, callback) {
  567. const self = this;
  568. const srcNode = filing.find(x => x.id === node.id || x.id == node.id);
  569. if (!srcNode) return;
  570. if (String(srcNode.tree_pid) === String(newTreePid) && Number(srcNode.tree_order) === newOrder) {
  571. if (callback) callback();
  572. return;
  573. }
  574. postData('filing/move', { id: node.id, tree_pid: newTreePid, tree_order: newOrder }, function(result) {
  575. srcNode.tree_pid = newTreePid;
  576. srcNode.tree_order = newOrder;
  577. self._reloadFilingTree();
  578. if (callback) callback();
  579. });
  580. }
  581. /**
  582. * 查找原始ID
  583. */
  584. _findOriginalId(treeId) {
  585. const node = this.filingTree.nodes.find(x => x.tree_id === treeId);
  586. return node ? node.id : null;
  587. }
  588. /**
  589. * 改变文件排序
  590. */
  591. changeFileOrder(fileOrder) {
  592. this.fileOrder = fileOrder;
  593. setLocalCache(this.fileOrderKey, fileOrder);
  594. this.refreshFileOrderButton();
  595. if (this.curFiling) {
  596. this.curFiling.files = [];
  597. this.setCurFiling(this.curFiling);
  598. }
  599. }
  600. /**
  601. * 上一页
  602. */
  603. prePage() {
  604. if (this.curPage === 1) return;
  605. this.curPage = this.curPage - 1;
  606. this.refreshPages();
  607. this.refreshFilesTable();
  608. }
  609. /**
  610. * 下一页
  611. */
  612. async nextPage() {
  613. if (this.curPage === this.curTotalPage) return;
  614. await this.loadFiles(this.curFiling, this.curPage + 1);
  615. this.curPage = this.curPage + 1;
  616. this.refreshPages();
  617. this.refreshFilesTable();
  618. }
  619. /**
  620. * 按层级显示
  621. */
  622. _showLevel(level) {
  623. if (level === 'last') {
  624. this.filingTree.expandByCustom(() => { return true; });
  625. } else {
  626. this.filingTree.expandByLevel(parseInt(level));
  627. }
  628. SpreadJsObj.refreshTreeRowVisible(this.sheet);
  629. }
  630. /**
  631. * 批量下载文件
  632. */
  633. batchDownloadFiles() {
  634. const self = this;
  635. const checkedFiles = $('input[name=bd-check]:checked');
  636. if (checkedFiles.length === 0) return;
  637. const files = [];
  638. checkedFiles.each(function() {
  639. const fid = $(this).attr('fid');
  640. const file = self.curFiling.files.find(f => f.id === fid);
  641. file && files.push(file);
  642. });
  643. if (files.length === 0) return;
  644. $('#batch-download').attr('disabled', 'true');
  645. AliOss.zipFiles(files, self.curFiling.name + '.zip', (fails) => {
  646. $('#batch-download').removeAttr('disabled');
  647. if (fails.length === 0) {
  648. toastr.success('下载成功');
  649. } else {
  650. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  651. }
  652. }, () => {
  653. $('#batch-download').removeAttr('disabled');
  654. toastr.error('批量下载失败');
  655. });
  656. }
  657. /**
  658. * 根据id查找归档节点
  659. */
  660. findFiling(id) {
  661. return this.filingTree.nodes.find(x => x.id === id || x.id == id);
  662. }
  663. /**
  664. * 获取当前归档完整路径
  665. */
  666. getCurFilingFullPath() {
  667. let cur = this.curFiling;
  668. const result = [];
  669. while (cur) {
  670. result.unshift(cur.name);
  671. cur = this.filingTree.getParent(cur);
  672. }
  673. return result.join('/');
  674. }
  675. /**
  676. * 生成行内编辑HTML
  677. */
  678. _getEditFileNameHtml(file) {
  679. const inputHtml = `<input type="text" class="form-control form-control-sm form-control-width" maxlength="100" value="${file.filename + file.fileext}" fid="${file.id}">`;
  680. 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>`;
  681. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  682. }
  683. /**
  684. * 重命名文件
  685. */
  686. renameFile(file, filename) {
  687. const self = this;
  688. const td = $(`td[fid=${file.id}]`);
  689. postData('file/save', { id: file.id, filename }, function(data) {
  690. const relaFiling = self.findFiling(file.filing_id);
  691. const relaFile = relaFiling.files.find(x => x.id === file.id);
  692. if (relaFile) {
  693. relaFile.filename = data.filename;
  694. relaFile.fileext = data.fileext;
  695. }
  696. file.filename = data.filename;
  697. file.fileext = data.fileext;
  698. td.html(self._getFileNameHtml(file));
  699. if (fileSearch) fileSearch.renameSearchFile(file.id, data);
  700. }, function() {
  701. td.html(self._getFileNameHtml(file));
  702. if (fileSearch) fileSearch.renameSearchFile(file.id);
  703. });
  704. }
  705. /**
  706. * 删除文件
  707. */
  708. delFiles(files, callback, hint) {
  709. const self = this;
  710. const del = function() {
  711. postData('file/del', { del: files }, async function(data) {
  712. const relaFiling = data.filing.id === self.curFiling.id
  713. ? self.curFiling : self.findFiling(data.filing.id);
  714. if (relaFiling && relaFiling.files) {
  715. for (const id of data.del) {
  716. const fIndex = relaFiling.files.findIndex(x => x.id === id);
  717. if (fIndex >= 0) relaFiling.files.splice(fIndex, 1);
  718. if (fileSearch) fileSearch.removeSearchFile(id);
  719. }
  720. }
  721. self.updateFilingFileCount(relaFiling, data.filing.file_count);
  722. if (data.filing.id === self.curFiling.id) {
  723. await self.loadFiles(self.curFiling, self.curPage);
  724. self.refreshPages();
  725. self.refreshFilesTable();
  726. }
  727. self.refreshFileCountHint();
  728. if (callback) callback();
  729. });
  730. };
  731. if (hint) {
  732. deleteAfterHint(del, hint);
  733. } else {
  734. del();
  735. }
  736. }
  737. /**
  738. * 更新归档文件计数
  739. */
  740. updateFilingFileCount(node, count) {
  741. if (!node) return;
  742. const differ = count - (node.file_count || 0);
  743. node.file_count = count;
  744. node.total_file_count = count;
  745. // 更新 SpreadJS 显示
  746. const rowIndex = this.filingTree.nodes.indexOf(node);
  747. if (rowIndex >= 0) {
  748. SpreadJsObj.reLoadRowsData(this.sheet, [rowIndex]);
  749. }
  750. // 递归更新父节点
  751. let parent = this.filingTree.getParent(node);
  752. while (parent) {
  753. parent.total_file_count = parent.total_file_count ? parent.total_file_count + differ : differ;
  754. const pIndex = this.filingTree.nodes.indexOf(parent);
  755. if (pIndex >= 0) {
  756. SpreadJsObj.reLoadRowsData(this.sheet, [pIndex]);
  757. }
  758. parent = this.filingTree.getParent(parent);
  759. }
  760. }
  761. /**
  762. * 移动文件
  763. */
  764. moveFile(file, filingId, callback) {
  765. if (file.filing_id === filingId) {
  766. callback();
  767. return;
  768. }
  769. const self = this;
  770. postData('file/move', { id: file.id, filingId: filingId }, function(data) {
  771. const orgFiling = self.findFiling(file.filing_id);
  772. if (orgFiling) {
  773. self.updateFilingFileCount(orgFiling, orgFiling.file_count - 1);
  774. const fIndex = orgFiling.files.findIndex(x => x.id === file.id);
  775. if (fIndex >= 0) orgFiling.files.splice(fIndex, 1);
  776. }
  777. const targetFiling = self.findFiling(filingId);
  778. if (targetFiling) {
  779. self.updateFilingFileCount(targetFiling, targetFiling.file_count + 1);
  780. }
  781. if (fileSearch) fileSearch.refreshSearchFile(data.file);
  782. callback();
  783. });
  784. }
  785. setFileLocked(file, isLocked, errorCallback) {
  786. const self = this;
  787. postData('file/lock', { id: file.id, is_locked: isLocked ? 1 : 0 }, function(data) {
  788. file.is_locked = Number(data.is_locked) === 1 ? 1 : 0;
  789. if (fileSearch) fileSearch.refreshSearchFile(data);
  790. self.refreshFilesTable();
  791. }, errorCallback);
  792. }
  793. /**
  794. * 引用文件
  795. */
  796. relaFiles(files, callback) {
  797. const self = this;
  798. postData('file/rela', { filing_id: this.curFiling.id, files: files }, function(data) {
  799. self.updateFilingFileCount(self.curFiling, data.filing.file_count);
  800. if (!self.curFiling.files) self.curFiling.files = [];
  801. self.curFiling.files.unshift(...data.files);
  802. self.refreshPages();
  803. self.refreshFilesTable();
  804. self.refreshFileCountHint();
  805. if (callback) callback();
  806. });
  807. }
  808. /**
  809. * 检查同名文件
  810. */
  811. checkFilesExist(files, callback) {
  812. const data = [];
  813. for (const file of files) {
  814. if (file === undefined) return;
  815. data.push(file.name);
  816. }
  817. postData('file/check', { filing_id: this.curFiling.id, files: data }, function(result) {
  818. callback(result);
  819. });
  820. }
  821. /**
  822. * 清除所有文件缓存
  823. */
  824. _clearAllFileCache() {
  825. for (const node of this.filingTree.nodes) {
  826. if (node.is_leaf && node.files) {
  827. node.files.length = 0;
  828. }
  829. }
  830. }
  831. /**
  832. * 获取所有有查看权限的资料目录ID。
  833. */
  834. getAllFilingId() {
  835. return this.filingTree.nodes.filter(node => {
  836. return Boolean(this._getFilingPermission(node.id).can_view);
  837. }).map(node => node.id);
  838. }
  839. /**
  840. * 获取当前节点及其子节点中有查看权限的资料目录ID。
  841. */
  842. getCurFilingId() {
  843. if (!this.curFiling) return [];
  844. const includedTreeIds = new Set([this.curFiling.tree_id]);
  845. const result = [];
  846. this.filingTree.nodes.forEach(node => {
  847. if (node.tree_id !== this.curFiling.tree_id && !includedTreeIds.has(node.tree_pid)) return;
  848. includedTreeIds.add(node.tree_id);
  849. if (this._getFilingPermission(node.id).can_view) result.push(node.id);
  850. });
  851. return result;
  852. }
  853. }
  854. // 初始化
  855. const filingSjs = new FilingSjs();
  856. // 首次进入空资料项目时,由拥有“管理目录”权限的用户选择初始化方式。
  857. if (needFilingInitialization) {
  858. const initializationDescription = {
  859. blank: '从空白目录开始创建资料目录',
  860. template: '从系统内置模板库中选取',
  861. project: '从系统中其他有管理目录权限的项目资料中选取',
  862. };
  863. const refreshInitializationType = function() {
  864. const initType = $('[name=filing-initialization-type]:checked').val();
  865. $('#filing-initialization-description').text(initializationDescription[initType] || '');
  866. $('#filing-initialization-template-wrap').toggle(initType === 'template');
  867. $('#filing-initialization-project-wrap').toggle(initType === 'project');
  868. };
  869. $('[name=filing-initialization-type]').on('change', refreshInitializationType);
  870. $('#filing-initialization-ok').on('click', function() {
  871. const button = $(this);
  872. const initType = $('[name=filing-initialization-type]:checked').val();
  873. const data = { init_type: initType };
  874. if (initType === 'template') {
  875. data.template_id = $('#filing-initialization-template').val();
  876. if (!data.template_id) {
  877. toastr.warning('请选择系统模板库');
  878. return;
  879. }
  880. }
  881. if (initType === 'project') {
  882. data.source_spid = $('#filing-initialization-project').val();
  883. if (!data.source_spid) {
  884. toastr.warning('请选择来源项目');
  885. return;
  886. }
  887. }
  888. button.prop('disabled', true);
  889. postData('filing/init', data, function() {
  890. window.location.reload();
  891. }, function() {
  892. button.prop('disabled', false);
  893. });
  894. });
  895. refreshInitializationType();
  896. $('#filing-initialization-modal').appendTo(document.body).modal('show');
  897. }
  898. /**
  899. * MoveFileObj - 移动文件弹窗(SpreadJS树选择目标目录)
  900. */
  901. class MoveFileObj {
  902. constructor() {
  903. const self = this;
  904. this.moveTree = null;
  905. this.spread = null;
  906. this.sheet = null;
  907. this.file = null;
  908. this.filingTree = createNewPathTree('base', {
  909. id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level',
  910. isLeaf: 'is_leaf', fullPath: 'full_path', rootId: -1,
  911. });
  912. this.spreadSetting = {
  913. cols: [
  914. {
  915. title: '分类名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 280, formatter: '@', cellType: 'tree',
  916. getValue: function(data) {
  917. return data.name;
  918. },
  919. getIcon: function(data) {
  920. return data.is_leaf ? 'file' : 'folder';
  921. },
  922. },
  923. ],
  924. emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21,
  925. headColWidth: [25], headerFont: '12px 微软雅黑', font: '12px 微软雅黑',
  926. readOnly: true, selectedBackColor: '#e8f4fd',
  927. };
  928. $('#move-file2-ok').click(function() {
  929. const node = SpreadJsObj.getSelectObject(self.sheet);
  930. if (!node) {
  931. toastr.warning('请选择目标分类');
  932. return;
  933. }
  934. if (!node.is_leaf) {
  935. toastr.warning('请选择最底层目标分类');
  936. return;
  937. }
  938. if (String(node.id) !== String(self.file.filing_id) && !filingSjs.canUploadFiling(node.id)) {
  939. toastr.warning('您没有目标分类的上传/引用权限');
  940. return;
  941. }
  942. filingSjs.moveFile(self.file, node.id, function() {
  943. $('#move-file2').modal('hide');
  944. filingSjs.refreshPages();
  945. filingSjs.refreshFilesTable();
  946. });
  947. });
  948. $('a[name=mf2-showLevel]').click(function() {
  949. const tag = $(this).attr('tag');
  950. setTimeout(() => {
  951. showWaitingView();
  952. self._expandByLevel(tag);
  953. closeWaitingView();
  954. }, 100);
  955. });
  956. }
  957. _expandByLevel(level) {
  958. const nodes = this.filingTree.nodes;
  959. if (level === 'last') {
  960. for (const node of nodes) {
  961. node.expanded = !node.is_leaf;
  962. }
  963. } else {
  964. const maxLevel = parseInt(level);
  965. for (const node of nodes) {
  966. node.expanded = !node.is_leaf && node.level < maxLevel;
  967. }
  968. }
  969. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
  970. }
  971. initMoveTree() {
  972. const convertedData = filingSjs._convertData(filing);
  973. this.filingTree.loadDatas(convertedData);
  974. if (this.spread) {
  975. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
  976. } else {
  977. this.spread = SpreadJsObj.createNewSpread($('#moveFile')[0]);
  978. this.sheet = this.spread.getActiveSheet();
  979. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  980. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
  981. }
  982. }
  983. show(file) {
  984. this.file = file;
  985. this.initMoveTree();
  986. $('#move-file2').modal('show');
  987. }
  988. }
  989. const moveFileObj = new MoveFileObj();
  990. /**
  991. * RelaFileLoader - 引用文件(标段树使用SpreadJS替代zTree)
  992. */
  993. class RelaFileLoader {
  994. constructor() {
  995. const self = this;
  996. this.curTender = null;
  997. this.curFiles = [];
  998. this.tenderFileType = [];
  999. this.tenderTree = null;
  1000. this.spread = null;
  1001. this.sheet = null;
  1002. this.tenderPathTree = createNewPathTree('base', {
  1003. id: 'tmt_id', pid: 'tmt_pid', order: 'sort', level: 'level',
  1004. isLeaf: 'is_leaf', fullPath: 'full_path', rootId: -1,
  1005. });
  1006. this.spreadSetting = {
  1007. cols: [{
  1008. title: '标段列表', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 280,
  1009. formatter: '@', cellType: 'tree',
  1010. getValue: function(data) {
  1011. return data.name;
  1012. },
  1013. getIcon: function(data) {
  1014. return data.source_node && data.source_node.tid ? 'file' : 'folder';
  1015. },
  1016. }],
  1017. emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21,
  1018. headColWidth: [25], headerFont: '12px 微软雅黑', font: '12px 微软雅黑',
  1019. readOnly: true, selectedBackColor: '#e8f4fd',
  1020. };
  1021. this.spread = SpreadJsObj.createNewSpread($('#rela-tender')[0]);
  1022. this.sheet = this.spread.getActiveSheet();
  1023. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1024. this.spread.bind(spreadNS.Events.SelectionChanged, async function(e, info) {
  1025. const node = SpreadJsObj.getSelectObject(self.sheet);
  1026. if (node && (!self.curTender || self.curTender.tmt_id !== node.tmt_id)) {
  1027. await self.setCurTender(node);
  1028. }
  1029. });
  1030. $('body').on('click', '[name=rf-check]', function() {
  1031. self.selectFile(this.getAttribute('rfid'), this.checked);
  1032. });
  1033. $('#tf-type').change(function() { self.selectTfType(this.value); });
  1034. $('#tf-sub-type').change(function() { self.selectTfSubType(this.value); });
  1035. $('#tf-stage').change(function() { self.selectTfStage(this.value); });
  1036. $('#tf-select').change(function() { self.selectTfId(this.value); });
  1037. }
  1038. _convertTenderData(data) {
  1039. const tenderPathTree = Tender2Tree.convert(data.category, data.tenders, null, null, function(node, source) {
  1040. _.assign(node, source);
  1041. }, data.selfCategoryLevel);
  1042. const sortedData = [...tenderPathTree.nodes].sort((a, b) => Number(a.level) - Number(b.level));
  1043. const result = [];
  1044. for (const node of sortedData) {
  1045. const parent = (node.tmt_pid === -1 || node.tmt_pid === '-1') ? undefined : result.find(x => x.tmt_id === node.tmt_pid);
  1046. if (!parent && node.tmt_pid !== -1 && node.tmt_pid !== '-1') continue;
  1047. const hasChild = tenderPathTree.nodes.some(x => x.tmt_pid === node.tmt_id);
  1048. result.push({
  1049. tmt_id: node.tmt_id, tmt_pid: parent ? parent.tmt_id : -1,
  1050. sort: node.sort || 0, level: node.level || 0,
  1051. is_leaf: !hasChild, full_path: '', name: node.name, source_node: node,
  1052. });
  1053. }
  1054. for (const node of result) { node._children = []; }
  1055. for (const node of result) {
  1056. if (node.tmt_pid !== -1) {
  1057. const parent = result.find(x => x.tmt_id === node.tmt_pid);
  1058. if (parent) parent._children.push(node);
  1059. }
  1060. }
  1061. const calcCount = (node) => {
  1062. if (node._children && node._children.length > 0) {
  1063. for (const child of node._children) calcCount(child);
  1064. node.total_file_count = node._children.reduce((sum, child) => sum + (child.total_file_count || 0), 0);
  1065. } else { node.total_file_count = 0; }
  1066. };
  1067. for (const root of result.filter(x => x.tmt_pid === -1)) calcCount(root);
  1068. for (const node of result) delete node._children;
  1069. return result;
  1070. }
  1071. async showRelaFile() {
  1072. $('#rela-filing-hint').html(`当前目录:${filingSjs.getCurFilingFullPath()}`);
  1073. if (!this.tenderTree) {
  1074. const data = await postDataAsync('file/rela/tender', {});
  1075. this._tenderRawData = data;
  1076. const convertedData = this._convertTenderData(data);
  1077. this.tenderPathTree.loadDatas(convertedData);
  1078. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tenderPathTree);
  1079. }
  1080. this.clearFileSelect();
  1081. this.refreshSelectHint();
  1082. if (this.tenderPathTree.nodes.length > 0) {
  1083. this.sheet.setActiveCell(0, 0);
  1084. await this.setCurTender(this.tenderPathTree.nodes[0]);
  1085. }
  1086. }
  1087. clearFileSelect() {
  1088. if (!this.tenderPathTree) return;
  1089. const recursiveFun = (nodes) => {
  1090. if (!nodes || nodes.length === 0) return;
  1091. for (const node of nodes) {
  1092. const x = node.source_node;
  1093. if (x.tid) {
  1094. x.selectFiles = [];
  1095. if (x.att) x.att.forEach(la => { la.checked = false; });
  1096. if (x.advance) x.advance.forEach(a => { if (a.files) a.files.forEach(aa => { aa.checked = false; }); });
  1097. if (x.stage) x.stage.forEach(s => { if (s.att) s.att.forEach(sa => { sa.checked = false; }); });
  1098. } else {
  1099. recursiveFun(this.tenderPathTree.getChildren(node));
  1100. }
  1101. }
  1102. };
  1103. const roots = this.tenderPathTree.nodes.filter(n => n.level === 1);
  1104. recursiveFun(roots);
  1105. }
  1106. refreshSelectHint() {
  1107. if (this.curTender && this.curTender.source_node.tid) {
  1108. $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
  1109. } else {
  1110. $('#cur-tender-hint').html('');
  1111. }
  1112. const nodes = this.tenderPathTree.nodes;
  1113. const selectTenders = nodes.filter(x => x.source_node.tid && x.source_node.selectFiles && x.source_node.selectFiles.length > 0);
  1114. if (selectTenders.length > 0) {
  1115. const count = selectTenders.reduce((rst, x) => rst + x.source_node.selectFiles.length, 0);
  1116. $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
  1117. } else {
  1118. $('#rela-file-hint').html('未选择标段、文件');
  1119. }
  1120. }
  1121. selectFile(fileId, isSelect) {
  1122. const file = this.curFiles.find(x => x.rf_id == fileId);
  1123. if (file) {
  1124. file.checked = isSelect;
  1125. if (isSelect) {
  1126. this.curTender.source_node.selectFiles.push(file);
  1127. } else {
  1128. const index = this.curTender.source_node.selectFiles.findIndex(x => x.rf_id === file.rf_id);
  1129. this.curTender.source_node.selectFiles.splice(index, 1);
  1130. }
  1131. this.refreshSelectHint();
  1132. }
  1133. }
  1134. refreshTenderFileSelectId() {
  1135. if (['change', 'change_apply', 'change_plan', 'change_project'].indexOf(this.rfType.type) >= 0) {
  1136. const type = this.tenderFileType.find(x => x.value === this.rfType.type);
  1137. const html = type.select.map(x => `<option value="${x.value}">${x.text}</option>`);
  1138. $('#tf-select').html(html.join('')).show();
  1139. this.rfType.selectId = type.select[0].value;
  1140. } else {
  1141. $('#tf-select').html('').hide();
  1142. }
  1143. }
  1144. refreshTenderFileStage() {
  1145. if (this.rfType.sub_type) {
  1146. const type = this.tenderFileType.find(x => x.value === this.rfType.type);
  1147. const subType = type.subType ? type.subType.find(x => x.value === this.rfType.sub_type) : null;
  1148. if (subType) {
  1149. this.rfType.stage = subType.stage[0].value;
  1150. const html = [];
  1151. for (const stage of subType.stage) html.push(`<option value="${stage.value}">${stage.text}</option>`);
  1152. $('#tf-stage').html(html.join('')).show();
  1153. } else { $('#tf-stage').html('').hide(); }
  1154. } else { $('#tf-stage').html('').hide(); }
  1155. }
  1156. refreshTenderFileSubType() {
  1157. const type = this.tenderFileType.find(x => x.value === this.rfType.type);
  1158. if (type && type.subType && type.subType.length > 0) {
  1159. this.rfType.sub_type = type.subType[0].value;
  1160. const html = [];
  1161. for (const tfst of type.subType) html.push(`<option value="${tfst.value}">${tfst.text}</option>`);
  1162. $('#tf-sub-type').html(html.join('')).show();
  1163. } else { $('#tf-sub-type').html('').hide(); }
  1164. }
  1165. refreshTenderFileType() {
  1166. const html = [];
  1167. for (const tft of this.tenderFileType) html.push(`<option value="${tft.value}">${tft.text}</option>`);
  1168. $('#tf-type').html(html.join(''));
  1169. }
  1170. refreshSelects(tender) {
  1171. this.tenderFileType = [];
  1172. if (tender.advance && tender.advance.length > 0) {
  1173. const advanceType = [];
  1174. tender.advance.forEach(x => {
  1175. let at = advanceType.find(y => y.value === x.type + '');
  1176. if (!at) { at = { value: x.type + '', text: x.type_str, stage: [] }; advanceType.push(at); }
  1177. at.stage.push({ value: x.id, text: `第${x.order}期` });
  1178. });
  1179. this.tenderFileType.push({ value: 'advance', text: '预付款', subType: advanceType });
  1180. }
  1181. if (tender.tid) this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
  1182. if (tender.stage && tender.stage.length > 0) {
  1183. const stages = tender.stage.map(x => ({ value: x.id, text: `第${x.order}期` }));
  1184. this.tenderFileType.push({
  1185. value: 'stage', text: '计量期',
  1186. subType: [
  1187. { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
  1188. { value: 'dealPay', text: '合同支付', stage: JSON.parse(JSON.stringify(stages)) },
  1189. { value: 'stageIm', text: '中间计量', stage: JSON.parse(JSON.stringify(stages)) },
  1190. ],
  1191. });
  1192. }
  1193. if (tender.change && tender.change.length > 0) {
  1194. this.tenderFileType.push({ value: 'change', text: '变更令', select: tender.change.map(x => ({ value: x.cid, text: x.code })) });
  1195. }
  1196. if (tender.change_plan && tender.change_plan.length > 0) {
  1197. this.tenderFileType.push({ value: 'change_plan', text: '变更方案', select: tender.change_plan.map(x => ({ value: x.id, text: x.code })) });
  1198. }
  1199. if (tender.change_apply && tender.change_apply.length > 0) {
  1200. this.tenderFileType.push({ value: 'change_apply', text: '变更申请', select: tender.change_apply.map(x => ({ value: x.id, text: x.code })) });
  1201. }
  1202. if (tender.change_project && tender.change_project.length > 0) {
  1203. this.tenderFileType.push({ value: 'change_project', text: '变更立项', select: tender.change_project.map(x => ({ value: x.id, text: x.code })) });
  1204. }
  1205. this.rfType = { type: tender.tid ? this.tenderFileType[0].value : '' };
  1206. this.refreshTenderFileType();
  1207. this.refreshTenderFileSubType();
  1208. this.refreshTenderFileStage();
  1209. this.refreshTenderFileSelectId();
  1210. }
  1211. async selectTfId(id) { this.rfType.selectId = id; await this.loadFiles(); this.refreshFileTable(); }
  1212. async selectTfStage(stage) { this.rfType.stage = stage; await this.loadFiles(); this.refreshFileTable(); }
  1213. async selectTfSubType(sub_type) { this.rfType.sub_type = sub_type; this.refreshTenderFileStage(); await this.loadFiles(); this.refreshFileTable(); }
  1214. async selectTfType(type) { this.rfType.type = type; this.refreshTenderFileSubType(); this.refreshTenderFileStage(); this.refreshTenderFileSelectId(); await this.loadFiles(); this.refreshFileTable(); }
  1215. refreshFileTable() {
  1216. const html = [];
  1217. const typeStr = [];
  1218. $('option:selected', '#rela-file').each((i, x) => { typeStr.push(x.innerText); });
  1219. for (const f of this.curFiles) {
  1220. html.push('<tr>');
  1221. const checked = f.checked ? 'checked' : '';
  1222. html.push(`<td><input type="checkbox" name="rf-check" rfid="${f.rf_id}" ${checked}></td>`);
  1223. html.push(`<td>${f.filename}${f.fileext}</td>`);
  1224. html.push(`<td>${typeStr.join(' - ')}</td>`);
  1225. html.push('</tr>');
  1226. }
  1227. $('#rf-files').html(html.join(''));
  1228. }
  1229. initFilesId(files) {
  1230. const tender_id = this.curTender.id;
  1231. const rfType = this.rfType;
  1232. files.forEach((f, i) => {
  1233. f.rf_id = `${tender_id}-${rfType.type}-${rfType.sub_type}-${rfType.stage}-${i}`;
  1234. f.rf_key = { tender_id, ...rfType, id: f.id };
  1235. });
  1236. }
  1237. async _loadRelaFiles(rfType) {
  1238. return await postDataAsync('file/rela/files', { tender_id: this.curTender.source_node.tid, ...rfType });
  1239. }
  1240. async _loadLedgerFile() {
  1241. if (!this.curTender.source_node.att) this.curTender.source_node.att = await this._loadRelaFiles(this.rfType);
  1242. this.curFiles = this.curTender.source_node.att;
  1243. }
  1244. async _loadStageFile() {
  1245. const stage = this.curTender.source_node.stage.find(x => x.id == this.rfType.stage);
  1246. if (!stage) { this.curFiles = []; return; }
  1247. if (!stage[this.rfType.sub_type]) stage[this.rfType.sub_type] = await this._loadRelaFiles(this.rfType);
  1248. this.curFiles = stage[this.rfType.sub_type];
  1249. }
  1250. async _loadAdvanceFile() {
  1251. const advance = this.curTender.source_node.advance.find(x => x.id == this.rfType.stage);
  1252. if (!advance) { this.curFiles = []; return; }
  1253. if (!advance.files) advance.files = await this._loadRelaFiles(this.rfType);
  1254. this.curFiles = advance.files;
  1255. }
  1256. async _loadChangeFile() {
  1257. const change = this.curTender.source_node.change.find(x => x.cid === this.rfType.selectId);
  1258. if (!change) { this.curFiles = []; return; }
  1259. if (!change.files) change.files = await this._loadRelaFiles(this.rfType);
  1260. this.curFiles = change.files;
  1261. }
  1262. async _loadChangePlanFile() {
  1263. const change = this.curTender.source_node.change_plan.find(x => x.id == this.rfType.selectId);
  1264. if (!change) { this.curFiles = []; return; }
  1265. if (!change.files) change.files = await this._loadRelaFiles(this.rfType);
  1266. this.curFiles = change.files;
  1267. }
  1268. async _loadChangeProjectFile() {
  1269. const change = this.curTender.source_node.change_project.find(x => x.id == this.rfType.selectId);
  1270. if (!change) { this.curFiles = []; return; }
  1271. if (!change.files) change.files = await this._loadRelaFiles(this.rfType);
  1272. this.curFiles = change.files;
  1273. }
  1274. async _loadChangeApplyFile() {
  1275. const change = this.curTender.source_node.change_apply.find(x => x.id == this.rfType.selectId);
  1276. if (!change) { this.curFiles = []; return; }
  1277. if (!change.files) change.files = await this._loadRelaFiles(this.rfType);
  1278. this.curFiles = change.files;
  1279. }
  1280. async loadFiles() {
  1281. switch (this.rfType.type) {
  1282. case 'ledger': await this._loadLedgerFile(); break;
  1283. case 'stage': await this._loadStageFile(); break;
  1284. case 'advance': await this._loadAdvanceFile(); break;
  1285. case 'change': await this._loadChangeFile(); break;
  1286. case 'change_plan': await this._loadChangePlanFile(); break;
  1287. case 'change_project': await this._loadChangeProjectFile(); break;
  1288. case 'change_apply': await this._loadChangeApplyFile(); break;
  1289. default: this.curFiles = [];
  1290. }
  1291. this.initFilesId(this.curFiles);
  1292. }
  1293. async setCurTender(node) {
  1294. this.curTender = node;
  1295. this.refreshSelects(node.source_node);
  1296. await this.loadFiles();
  1297. this.refreshSelectHint();
  1298. this.refreshFileTable();
  1299. }
  1300. getSelectRelaFile() {
  1301. const data = [];
  1302. for (const node of this.tenderPathTree.nodes) {
  1303. if (!node.source_node.selectFiles || node.source_node.selectFiles.length === 0) continue;
  1304. node.source_node.selectFiles.forEach(x => {
  1305. data.push({ filename: x.filename, fileext: x.fileext, filepath: x.filepath, filesize: x.filesize, rela_info: x.rf_key });
  1306. });
  1307. }
  1308. return data;
  1309. }
  1310. }
  1311. /**
  1312. * FileSearch - 文件搜索类
  1313. */
  1314. class FileSearch {
  1315. constructor() {
  1316. this.searchResult = [];
  1317. this._initSearch();
  1318. }
  1319. getOperateHtml(file) {
  1320. const locateHtml = `<a href="javascript: void(0);" class="mr-1" name="locate-search-file" fid="${file.id}"><i class="fa fa-crosshairs"></i></a>`;
  1321. const canOperateFile = !filingSjs.isFileLocked(file) && filingSjs.canEditFiling(file.filing_id);
  1322. 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>` : '';
  1323. const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
  1324. 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>`;
  1325. 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>` : '';
  1326. return `<div class="d-flex justify-content-between align-items-center table-file">${locateHtml}${editHtml}${viewHtml}${downHtml}${delHtml}</div>`;
  1327. }
  1328. getFileHtml(file) {
  1329. const html = [];
  1330. html.push(`<tr fid="search_${file.id}">`);
  1331. html.push(`<td name="filename" fid="search_${file.id}">${file.filename}${file.fileext}</td>`);
  1332. html.push(`<td class="text-center">${file.user_name}</td>`);
  1333. html.push(`<td class="text-center">${this.getOperateHtml(file)}</td>`);
  1334. html.push('</tr>');
  1335. return html.join('');
  1336. }
  1337. getResultHtml(result) {
  1338. this.searchResult = result;
  1339. const html = [];
  1340. for (const r of result) {
  1341. html.push(this.getFileHtml(r));
  1342. }
  1343. return html.join('');
  1344. }
  1345. getSearchFilter() {
  1346. const filter = $('#search-filter').val();
  1347. const filing_id = filter === 'all' ? filingSjs.getAllFilingId() : filingSjs.getCurFilingId();
  1348. return { filing_id };
  1349. }
  1350. getEditFileNameHtml(file) {
  1351. 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}">`;
  1352. 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>`;
  1353. return `<div class="d-flex justify-content-between align-items-center table-file"><div>${inputHtml}</div>${btnHtml}</div>`;
  1354. }
  1355. search() {
  1356. const self = this;
  1357. const searchData = this.getSearchFilter();
  1358. searchData.keyword = $('#search-keyword', '#search').val();
  1359. if (!searchData.keyword) {
  1360. toastr.warning('请输入查询的文件名称');
  1361. this.getResultHtml([]);
  1362. return;
  1363. }
  1364. postData('file/search', searchData, function(result) {
  1365. if (result.list.length === result.limit) toastr.warning(`最多查询${result.limit}个结果,请给出更准确的文件名称`);
  1366. $('#search-list').html(self.getResultHtml(result.list));
  1367. });
  1368. }
  1369. refreshSearchFile(file) {
  1370. const sfile = this.searchResult.find(x => x.id === file.id);
  1371. if (sfile) {
  1372. for (const prop in file) {
  1373. if (prop === 'id') continue;
  1374. sfile[prop] = file[prop];
  1375. }
  1376. const row = $(`tr[fid=search_${sfile.id}]`);
  1377. if (row.length > 0) row.replaceWith(this.getFileHtml(sfile));
  1378. }
  1379. }
  1380. removeSearchFile(fid) {
  1381. $(`tr[fid=search_${fid}]`, '#search').remove();
  1382. const index = this.searchResult.findIndex(x => x.id === fid);
  1383. if (index >= 0) this.searchResult.splice(index, 1);
  1384. }
  1385. renameSearchFile(fid, data) {
  1386. const file = this.searchResult.find(x => x.id === fid);
  1387. if (file) {
  1388. file.filename = data.filename;
  1389. file.fileext = data.fileext;
  1390. const td = $(`td[fid=search_${file.id}]`);
  1391. td.html(`${file.filename}${file.fileext}`);
  1392. }
  1393. }
  1394. _initSearch() {
  1395. const self = this;
  1396. $('input', '#search').bind('keydown', function(e) {
  1397. if (e.keyCode === 13) self.search();
  1398. });
  1399. $('button', '#search').bind('click', () => { self.search(); });
  1400. }
  1401. }
  1402. fileSearch = new FileSearch();
  1403. /**
  1404. * FilingPermission - 授权用户管理
  1405. */
  1406. class FilingPermission {
  1407. constructor(setting) {
  1408. this.setting = setting;
  1409. const self = this;
  1410. this.spread = SpreadJsObj.createNewSpread($(`${setting.spread}`)[0]);
  1411. this.sheet = this.spread.getActiveSheet();
  1412. this.spreadSetting = {
  1413. cols: [
  1414. { title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 200, formatter: '@', cellType: 'tree'},
  1415. { title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 45, cellType: 'checkbox' },
  1416. { title: '归档单位', colSpan: '1', rowSpan: '1', field: 'file_company', hAlign: 0, width: 80, formatter: '@', cellType: 'autoTip' },
  1417. ],
  1418. emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21,
  1419. headColWidth: [25], headerFont: '12px 微软雅黑', font: '12px 微软雅黑',
  1420. readOnly: true, selectedBackColor: '#fffacd',
  1421. };
  1422. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1423. this.permissionTree = createNewPathTree('base', {
  1424. id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level',
  1425. isLeaf: 'is_leaf', fullPath: 'full_path', rootId: -1,
  1426. });
  1427. this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
  1428. if (!info.sheet.zh_setting) return;
  1429. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  1430. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  1431. if (sheet.isEditing()) sheet.endEdit(true);
  1432. }
  1433. const col = info.sheet.zh_setting.cols[info.col];
  1434. if (col.field !== 'check') return;
  1435. const tree = self.permissionTree;
  1436. const node = tree.nodes[info.row];
  1437. const row = [info.row];
  1438. node.check = !node.check;
  1439. if (node.children && node.children.length > 0) {
  1440. const posterity = tree.getPosterity(node);
  1441. for (const p of posterity) {
  1442. p.check = node.check;
  1443. row.push(tree.nodes.indexOf(p));
  1444. }
  1445. }
  1446. if (!node.check) {
  1447. const parent = tree.getAllParents(node);
  1448. for (const p of parent) {
  1449. p.check = node.check;
  1450. row.push(tree.nodes.indexOf(p));
  1451. }
  1452. }
  1453. SpreadJsObj.reLoadRowsData(info.sheet, row);
  1454. });
  1455. this.spread.bind(spreadNS.Events.SelectionChanged, function(e, info) {
  1456. if (info.newSelections[0].col === 1) {
  1457. info.sheet.setSelection(info.oldSelections[0].row, info.oldSelections[0].col, info.oldSelections[0].rowCount, info.oldSelections[0].colCount);
  1458. SpreadJsObj.reloadRowsBackColor(info.sheet, [info.newSelections[0].row, info.oldSelections[0].row]);
  1459. } else {
  1460. const node = SpreadJsObj.getSelectObject(info.sheet);
  1461. self.setCurFiling(node.filing_type);
  1462. }
  1463. });
  1464. $(setting.modal).on('show.bs.modal', () => { self.loadPermission(); });
  1465. $(setting.modal).on('shown.bs.modal', () => { self.spread.refresh(); });
  1466. $(`${setting.modal}-ok`).click(() => { self.savePermission(); });
  1467. $('.book-list').on('click', 'dt', function() {
  1468. const idx = $(this).find('.acc-btn').attr('data-groupid');
  1469. const type = $(this).find('.acc-btn').attr('data-type');
  1470. if (type === 'hide') {
  1471. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  1472. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  1473. $(this).find('.acc-btn').attr('data-type', 'show');
  1474. });
  1475. } else {
  1476. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  1477. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  1478. $(this).find('.acc-btn').attr('data-type', 'hide');
  1479. });
  1480. }
  1481. return false;
  1482. });
  1483. $('dl').on('click', 'dd', function(e) {
  1484. const type = $(this).data('type');
  1485. if (type === 'all') {
  1486. const cid = parseInt($(this).data('id'));
  1487. const company = self.company.find(x => x.id === cid);
  1488. for (const u of company.users) {
  1489. if (u.filing_type.indexOf(self.curFiling) < 0) u.filing_type.push(self.curFiling);
  1490. }
  1491. } else {
  1492. const uid = $(this).data('id');
  1493. const pu = self.permissionUser.find(x => x.id === uid);
  1494. if (pu.filing_type.indexOf(self.curFiling) < 0) pu.filing_type.push(self.curFiling);
  1495. }
  1496. self.loadCurFiling();
  1497. e.stopPropagation();
  1498. });
  1499. $('#sync-filing').click(function() {
  1500. const selectFilingId = [];
  1501. self.permissionTree.nodes.forEach(x => {
  1502. if (x.check && (!x.children || x.children.length === 0)) selectFilingId.push(x.filing_type);
  1503. });
  1504. if (selectFilingId.length === 0) { toastr.warning('请先选择文档类别'); return; }
  1505. self.syncFiling(self.curFiling, selectFilingId);
  1506. toastr.success('同步成功');
  1507. self.permissionTree.nodes.forEach(x => { x.check = false; });
  1508. SpreadJsObj.reloadColData(self.sheet, 1);
  1509. $('#filing-select-all')[0].checked = false;
  1510. });
  1511. $('#batch-del-filing').click(() => {
  1512. const selectUser = $('[name=ftu-check]:checked');
  1513. if (selectUser.length === 0) { toastr.warning('请先选择用户'); return; }
  1514. const userId = [];
  1515. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  1516. self.delFiling(self.curFiling, userId);
  1517. self.loadCurFiling();
  1518. });
  1519. $('#batch-add-filing').click(() => {
  1520. const selectFilingId = [];
  1521. self.permissionTree.nodes.forEach(x => {
  1522. if (x.check && (!x.children || x.children.length === 0)) selectFilingId.push(x.filing_type);
  1523. });
  1524. if (selectFilingId.length === 0) { toastr.warning('请先选择文档类别'); return; }
  1525. const selectUser = $('[name=ftu-check]:checked');
  1526. if (selectUser.length === 0) { toastr.warning('请先选择用户'); return; }
  1527. const userId = [];
  1528. selectUser.each((i, x) => { userId.push(x.getAttribute('uid')); });
  1529. self.batchAddFiling(selectFilingId, userId);
  1530. self.loadCurFiling();
  1531. toastr.success('批量添加成功');
  1532. self.permissionTree.nodes.forEach(x => { x.check = false; });
  1533. SpreadJsObj.reloadColData(self.sheet, 1);
  1534. $('#filing-select-all')[0].checked = false;
  1535. });
  1536. $('body').on('click', '[name=del-filing]', function() {
  1537. const id = this.getAttribute('uid');
  1538. self.delFiling(self.curFiling, id);
  1539. self.loadCurFiling();
  1540. this.syncPermissionUserSelectedMarks();
  1541. });
  1542. $('#user-select-all').click(function() { $('input[uid]').attr('checked', this.checked); });
  1543. $('#filing-select-all').click(function() {
  1544. self.permissionTree.nodes.forEach(x => { x.check = this.checked; });
  1545. SpreadJsObj.reloadColData(self.sheet, 1);
  1546. });
  1547. }
  1548. analysisFiling(data) {
  1549. this.permissionUser = data;
  1550. this.permissionUser.forEach(x => { x.filing_type = x.filing_type ? x.filing_type.split(',') : []; });
  1551. this.company = [];
  1552. for (const pu of this.permissionUser) {
  1553. let c = this.company.find(x => x.company === pu.company);
  1554. if (!c) {
  1555. c = { id: this.company.length + 1, company: pu.company, users: [] };
  1556. this.company.push(c);
  1557. }
  1558. c.users.push(pu);
  1559. }
  1560. }
  1561. loadCurFiling() {
  1562. const html = [];
  1563. for (const f of this.permissionUser) {
  1564. if (f.filing_type.indexOf(this.curFiling) < 0) continue;
  1565. html.push('<tr>');
  1566. html.push(`<td><input uid="${f.id}" type="checkbox" name="ftu-check"></td>`);
  1567. html.push(`<td>${f.name}</td>`);
  1568. html.push(`<td>${moment(f.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
  1569. html.push(`<td>${f.file_permission}</td>`);
  1570. html.push(`<td><button class="btn btn-sm btn-outline-danger" uid="${f.id}" name="del-filing">移除</button></td>`);
  1571. html.push('</tr>');
  1572. }
  1573. $(this.setting.list).html(html.join(''));
  1574. $('#user-select-all')[0].checked = false;
  1575. this.syncPermissionUserSelectedMarks();
  1576. }
  1577. refreshBtn() {
  1578. const self = this;
  1579. const filing = this.permissionTree.nodes.find(x => x.filing_type === self.curFiling);
  1580. if (!filing || (filing.children && filing.children.length > 0)) {
  1581. $('#filing-add-user').hide();
  1582. $('#batch-del-filing').hide();
  1583. $('#batch-add-filing').hide();
  1584. $('#sync-filing').hide();
  1585. } else {
  1586. $('#filing-add-user').show();
  1587. $('#batch-del-filing').show();
  1588. $('#batch-add-filing').show();
  1589. $('#sync-filing').show();
  1590. }
  1591. }
  1592. setCurFiling(filingType) {
  1593. this.curFiling = filingType;
  1594. this.loadCurFiling();
  1595. this.refreshBtn();
  1596. }
  1597. loadPermissionUser() {
  1598. const html = [];
  1599. const currentFilingUserIds = new Set();
  1600. if (this.permissionUser && Array.isArray(this.permissionUser)) {
  1601. for (const f of this.permissionUser) {
  1602. if (f.filing_type && f.filing_type.indexOf(this.curFiling) >= 0) {
  1603. currentFilingUserIds.add(f.id);
  1604. }
  1605. }
  1606. }
  1607. for (const c of this.company) {
  1608. 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>`);
  1609. html.push(`<div class="dd-content" data-toggleid="${c.id}">`);
  1610. 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>`);
  1611. for (const u of c.users) {
  1612. const initialDisplayStyle = currentFilingUserIds.has(u.id) ? 'display:inline-block;' : 'display:none;';
  1613. html.push(`<dd class="border-bottom p-2 mb-0" data-id="${u.id}">`);
  1614. 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>`);
  1615. html.push(`<span class="text-muted">${u.role}</span>`);
  1616. html.push('</dd>');
  1617. }
  1618. html.push('</div>');
  1619. }
  1620. $('#puList').html(html.join(''));
  1621. }
  1622. syncPermissionUserSelectedMarks() {
  1623. const tableUserIds = new Set();
  1624. $(this.setting.list + ' tr').each(function() {
  1625. const $firstInput = $(this).find('input[name="ftu-check"]').first();
  1626. if ($firstInput.length) {
  1627. const uid = parseInt($firstInput.attr('uid'), 10);
  1628. if (!isNaN(uid)) tableUserIds.add(uid);
  1629. }
  1630. });
  1631. $('#puList dd[data-id]').each(function() {
  1632. const userId = parseInt($(this).data('id'), 10);
  1633. const $mark = $(this).find('.selected-mark');
  1634. if (!isNaN(userId) && $mark.length > 0 && $(this).data('type') !== 'all') {
  1635. if (tableUserIds.has(userId)) { $mark.show(); } else { $mark.hide(); }
  1636. }
  1637. });
  1638. }
  1639. _convertData(sourceTree) {
  1640. const data = [];
  1641. for (const node of sourceTree.nodes) {
  1642. if (!node.is_fixed) continue;
  1643. const parent = node.tree_pid === '-1' ? undefined : data.find(x => x.id === node.tree_pid);
  1644. const child = sourceTree.nodes.find(x => x.tree_pid === node.id);
  1645. data.push({
  1646. id: node.id,
  1647. tree_id: data.length + 1,
  1648. tree_pid: parent ? parent.tree_id : -1,
  1649. order: node.tree_order + 1,
  1650. level: node.tree_level,
  1651. is_leaf: !child || !child.is_fixed,
  1652. full_path: '',
  1653. name: node.name,
  1654. is_fixed: node.is_fixed,
  1655. filing_type: node.filing_type + '',
  1656. tips: node.tips,
  1657. file_company: node.file_company,
  1658. file_count: node.file_count,
  1659. });
  1660. }
  1661. return data;
  1662. }
  1663. loadPermission() {
  1664. this.permissionTree.loadDatas(this._convertData({nodes: filing}));
  1665. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.permissionTree);
  1666. const self = this;
  1667. postData('permission', {}, function(result) {
  1668. self.analysisFiling(result);
  1669. if (!self.curFiling) {
  1670. const node = SpreadJsObj.getSelectObject(self.sheet);
  1671. self.setCurFiling(node.filing_type);
  1672. } else {
  1673. self.loadCurFiling();
  1674. }
  1675. self.loadPermissionUser();
  1676. });
  1677. }
  1678. syncFiling(sourceId, targetIds) {
  1679. for (const pu of this.permissionUser) {
  1680. if (pu.filing_type.indexOf(sourceId) >= 0) {
  1681. targetIds.forEach(id => {
  1682. if (pu.filing_type.indexOf(id) < 0) pu.filing_type.push(id);
  1683. });
  1684. } else {
  1685. targetIds.forEach(id => {
  1686. if (pu.filing_type.indexOf(id) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(id), 1);
  1687. });
  1688. }
  1689. }
  1690. }
  1691. delFiling(filingId, userId) {
  1692. const userIds = userId instanceof Array ? userId : [userId];
  1693. for (const id of userIds) {
  1694. const pu = this.permissionUser.find(x => x.id === id);
  1695. if (!pu) continue;
  1696. if (pu.filing_type.indexOf(filingId) >= 0) pu.filing_type.splice(pu.filing_type.indexOf(filingId), 1);
  1697. }
  1698. }
  1699. batchAddFiling(filingIds, userId) {
  1700. for (const pu of this.permissionUser) {
  1701. if (userId.indexOf(pu.id) < 0) continue;
  1702. filingIds.forEach(fid => {
  1703. if (pu.filing_type.indexOf(fid) < 0) pu.filing_type.push(fid);
  1704. });
  1705. }
  1706. }
  1707. savePermission() {
  1708. const self = this;
  1709. const data = this.permissionUser.map(x => {
  1710. return { id: x.id, filing_type: x.filing_type.join(',') };
  1711. });
  1712. postData('permission/save', data, function(result) {
  1713. $(self.setting.modal).modal('hide');
  1714. });
  1715. }
  1716. }
  1717. /**
  1718. * 侧边工具栏展开/收起
  1719. */
  1720. const refreshSideLayout = function() {
  1721. filingSjs.spread.refresh();
  1722. if (fileReference) fileReference.spread.refresh();
  1723. };
  1724. const showSideTools = function(show) {
  1725. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1726. if (show) {
  1727. right.show();
  1728. autoFlashHeight();
  1729. const percent = 100 - right.outerWidth() / parent.width() * 100;
  1730. left.css('width', percent + '%');
  1731. } else {
  1732. left.css('width', '100%');
  1733. right.hide();
  1734. }
  1735. // 容器宽度变化后再刷新 SpreadJS,避免继续使用展开前的画布尺寸。
  1736. setTimeout(refreshSideLayout, 0);
  1737. };
  1738. // 展开收起侧边工具栏
  1739. $('a', '#side-menu').bind('click', function(e) {
  1740. e.preventDefault();
  1741. const tab = $(this), tabPanel = $(tab.attr('content'));
  1742. if (!tab.hasClass('active')) {
  1743. $('a', '#side-menu').removeClass('active');
  1744. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  1745. tab.addClass('active');
  1746. tabPanel.addClass('active');
  1747. showSideTools(tab.hasClass('active'));
  1748. if (tab.attr('content') === '#reference') {
  1749. if (!fileReference) {
  1750. fileReference = $.stdLib({
  1751. selector: '#reference',
  1752. stdType: 'reference',
  1753. libs: fileReferenceList,
  1754. treeSetting: {
  1755. id: 'template_id', pid: 'pid', order: 'order', level: 'level',
  1756. rootId: -1, keys: ['id', 'list_id', 'template_id'],
  1757. },
  1758. spreadSetting: {
  1759. cols: [
  1760. {title: '名称', field: 'name', hAlign: 0, width: 420, formatter: '@', cellType: 'tree', wordWrap: true},
  1761. {title: '备注', field: 'remark', hAlign: 1, width: 150, formatter: '@'}
  1762. ],
  1763. emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21,
  1764. headColWidth: [30], selectedBackColor: '#fffacd', readOnly: true,
  1765. localCache: { key: 'file_detail_reference', colWidth: true },
  1766. },
  1767. page: 'file',
  1768. });
  1769. }
  1770. fileReference.spread.refresh();
  1771. }
  1772. } else {
  1773. tab.removeClass('active');
  1774. tabPanel.removeClass('active');
  1775. showSideTools(tab.hasClass('active'));
  1776. }
  1777. });
  1778. // 左右拖拽分隔条
  1779. $.divResizer({
  1780. select: '#file-right-spr',
  1781. callback: function() { filingSjs.spread.refresh(); },
  1782. });
  1783. $.divResizer({
  1784. select: '#right-spr',
  1785. callback: refreshSideLayout,
  1786. });
  1787. // ========== 事件委托绑定 ==========
  1788. // 文件行内操作:鼠标悬停显示按钮
  1789. $('body').on('mouseenter', '.table-file', function() {
  1790. $(this).children('.btn-group-table').css('display', 'block');
  1791. });
  1792. $('body').on('mouseleave', '.table-file', function() {
  1793. $(this).children('.btn-group-table').css('display', 'none');
  1794. });
  1795. // 锁定或解锁单个文件
  1796. $('body').on('change', 'input[name=file-lock]', function() {
  1797. const lockSwitch = $(this);
  1798. const fid = this.getAttribute('fid');
  1799. const file = filingSjs.curFiling.files.find(x => x.id === fid);
  1800. if (!file) {
  1801. lockSwitch.prop('checked', !this.checked);
  1802. return;
  1803. }
  1804. const isLocked = this.checked;
  1805. lockSwitch.prop('disabled', true);
  1806. filingSjs.setFileLocked(file, isLocked, function() {
  1807. lockSwitch.prop('checked', !isLocked).prop('disabled', false);
  1808. });
  1809. });
  1810. // 单个删除文件
  1811. $('body').on('click', 'a[name=del-file]', function() {
  1812. const fid = this.getAttribute('fid');
  1813. const filename = $(`div[name=filename][fid=${fid}]`)[0].innerHTML;
  1814. filingSjs.delFiles([fid], null, `确认删除「${filename}」?`);
  1815. });
  1816. // 重命名文件 - 进入编辑模式
  1817. $('body').on('click', 'a[name=edit-file]', function() {
  1818. const check = $('[name=filename] input[fid]');
  1819. if (check.length > 0 && check[0].getAttribute('fid') === this.getAttribute('fid')) return;
  1820. const id = this.getAttribute('fid');
  1821. const file = filingSjs.curFiling.files.find(x => x.id === id);
  1822. $(`td[fid=${id}]`).html(filingSjs._getEditFileNameHtml(file));
  1823. });
  1824. // 重命名文件 - 确认
  1825. $('body').on('click', 'a[name=edit-file-ok]', function() {
  1826. const td = $(this).parent().parent().parent();
  1827. const fid = td.attr('fid');
  1828. const file = filingSjs.curFiling.files.find(x => x.id === fid);
  1829. if (!file) return;
  1830. const filename = $('input', td).val();
  1831. if (filename === file.filename + file.fileext) {
  1832. td.html(filingSjs._getFileNameHtml(file));
  1833. return;
  1834. }
  1835. filingSjs.renameFile(file, filename);
  1836. });
  1837. // 重命名文件 - 取消
  1838. $('body').on('click', 'a[name=edit-file-cancel]', function() {
  1839. const td = $(this).parent().parent().parent();
  1840. const fid = td.attr('fid');
  1841. const file = filingSjs.curFiling.files.find(x => x.id === fid);
  1842. if (!file) return;
  1843. td.html(filingSjs._getFileNameHtml(file));
  1844. });
  1845. // 移动文件
  1846. $('body').on('click', 'a[name=move-file]', function() {
  1847. const id = this.getAttribute('fid');
  1848. const file = filingSjs.curFiling.files.find(x => x.id === id);
  1849. moveFileObj.show(file);
  1850. });
  1851. // 搜索结果中删除文件
  1852. $('body').on('click', 'a[name=del-search-file]', function() {
  1853. const del = [this.getAttribute('fid')];
  1854. const filename = $('[name=filename]', $(this).closest('tr'))[0].innerHTML;
  1855. filingSjs.delFiles(del, null, `确认删除「${filename}」?`);
  1856. });
  1857. // 搜索结果中定位文件
  1858. $('body').on('click', 'a[name=locate-search-file]', function() {
  1859. const fid = this.getAttribute('fid');
  1860. const file = fileSearch.searchResult.find(x => x.id === fid);
  1861. if (!file) return;
  1862. const filingNode = filingSjs.findFiling(file.filing_id);
  1863. if (filingNode) {
  1864. const rowIndex = filingSjs.filingTree.nodes.indexOf(filingNode);
  1865. if (rowIndex >= 0) {
  1866. filingSjs.sheet.setActiveCell(rowIndex, 0);
  1867. filingSjs.setCurFiling(filingNode);
  1868. }
  1869. }
  1870. });
  1871. // 搜索结果中重命名文件
  1872. $('body').on('click', 'a[name=edit-search-file]', function() {
  1873. const id = this.getAttribute('fid');
  1874. const file = fileSearch.searchResult.find(x => x.id === id);
  1875. $(`td[fid=search_${id}]`).html(fileSearch.getEditFileNameHtml(file));
  1876. });
  1877. $('body').on('click', 'a[name=edit-search-file-ok]', function() {
  1878. const td = $(this).parent().parent().parent();
  1879. const fid = td.attr('fid').split('_')[1];
  1880. const file = fileSearch.searchResult.find(x => x.id === fid);
  1881. if (!file) return;
  1882. filingSjs.renameFile(file, $('input', td).val());
  1883. });
  1884. $('body').on('click', 'a[name=edit-search-file-cancel]', function() {
  1885. const td = $(this).parent().parent().parent();
  1886. const fid = td.attr('fid').split('_')[1];
  1887. const file = fileSearch.searchResult.find(x => x.id === fid);
  1888. if (!file) return;
  1889. td.html(`${file.filename}${file.fileext}`);
  1890. });
  1891. // ========== Modal 事件 ==========
  1892. // 上传文件弹窗显示时重置
  1893. $('#add-file').on('show.bs.modal', function() {
  1894. $('#filter-same')[0].checked = false;
  1895. $('#filter-same').parent().hide();
  1896. $('#upload-file-hint').hide();
  1897. $('#upload-file')[0].value = '';
  1898. if ($('#add-file-ok').hasClass('btn-warning')) $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary');
  1899. });
  1900. // 上传文件选择时检查同名
  1901. $('#upload-file').change(function() {
  1902. $('#add-file-ok').attr('disabled', true);
  1903. const input = $(this);
  1904. filingSjs.checkFilesExist(input[0].files, function(result) {
  1905. if (result.length === 0) {
  1906. $('#upload-file-hint').hide();
  1907. $('#add-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
  1908. $('#filter-same').parent().hide();
  1909. } else {
  1910. const msg = result[0] + (result.length > 1 ? `(等${result.length}个文件)`: '') + '</br>存在同名文件,请确认是否上传重复';
  1911. $('#upload-file-hint').html(msg).show();
  1912. $('#add-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
  1913. $('#filter-same').parent().show();
  1914. $('#filter-same').attr('filterFiles', result.join('$;$'));
  1915. }
  1916. });
  1917. });
  1918. // 覆盖上传文件确认(支持同名过滤)
  1919. $('#add-file-ok').off('click').on('click', function() {
  1920. const input = $('#upload-file');
  1921. const filter = $('#filter-same')[0].checked;
  1922. const filterFiles = filter ? $('#filter-same').attr('filterFiles').split('$;$') : [];
  1923. const files = input[0].files;
  1924. if (!files || files.length === 0) { toastr.error('未选择上传文件。'); return; }
  1925. const formData = new FormData();
  1926. formData.append('filing_id', filingSjs.curFiling.id);
  1927. let count = 0;
  1928. for (const file of files) {
  1929. if (filterFiles.indexOf(file.name) >= 0) continue;
  1930. if (file.size > 50 * 1024 * 1024) { toastr.error('上传文件大小超过50MB。'); return; }
  1931. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  1932. if (whiteList.indexOf(fileext) === -1) { toastr.error('仅支持造价文件、Office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。'); return; }
  1933. formData.append('size', file.size);
  1934. formData.append('file[]', file);
  1935. count++;
  1936. }
  1937. if (count === 0) { toastr.warning('没有可上传的文件'); return; }
  1938. postDataWithFile('file/upload', formData, function(data) {
  1939. filingSjs.updateFilingFileCount(filingSjs.curFiling, data.filing.file_count);
  1940. if (!filingSjs.curFiling.files) filingSjs.curFiling.files = [];
  1941. filingSjs.curFiling.files.unshift(...data.files);
  1942. filingSjs.refreshPages();
  1943. filingSjs.refreshFilesTable();
  1944. filingSjs.refreshFileCountHint();
  1945. $(input).val('');
  1946. $('#add-file').modal('hide');
  1947. });
  1948. });
  1949. // 大文件上传弹窗显示时重置
  1950. $('#add-big-file').on('show.bs.modal', function() {
  1951. $('#upload-big-file-hint').hide();
  1952. $('#upload-big-file')[0].value = '';
  1953. if ($('#add-big-file-ok').hasClass('btn-warning')) $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary');
  1954. });
  1955. // 大文件选择时检查同名
  1956. $('#upload-big-file').change(function() {
  1957. $('#add-big-file-ok').attr('disabled', true);
  1958. const input = $(this);
  1959. filingSjs.checkFilesExist(input[0].files, function(result) {
  1960. if (result.length === 0) {
  1961. $('#upload-big-file-hint').hide();
  1962. $('#add-big-file-ok').removeClass('btn-warning').addClass('btn-primary').attr('disabled', false);
  1963. } else {
  1964. $('#upload-big-file-hint').html('存在同名文件,请确认是否上传重复').show();
  1965. $('#add-big-file-ok').removeClass('btn-primary').addClass('btn-warning').attr('disabled', false);
  1966. }
  1967. });
  1968. });
  1969. // 覆盖大文件上传确认
  1970. $('#add-big-file-ok').off('click').on('click', function() {
  1971. const input = $('#upload-big-file');
  1972. const file = input[0].files[0];
  1973. if (!file) { toastr.error('未选择上传文件。'); return; }
  1974. if (file.size > 500 * 1024 * 1024) { toastr.error('上传文件大小超过500MB。'); return; }
  1975. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  1976. if (whiteList.indexOf(fileext) === -1) { toastr.error('仅支持造价文件、Office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。'); return; }
  1977. AliOss.uploadBigFile(file, 'file/upload/big', { filing_id: filingSjs.curFiling.id },
  1978. { progressObj: $('#upload-big-file-progress'), resumeObj: $('#add-big-file-resume'), stopObj: $('#add-big-file-stop') },
  1979. function(result) {
  1980. if (!filingSjs.curFiling.files) filingSjs.curFiling.files = [];
  1981. filingSjs.curFiling.files.unshift(...result.files);
  1982. filingSjs.updateFilingFileCount(filingSjs.curFiling, result.filing.file_count);
  1983. filingSjs.refreshPages();
  1984. filingSjs.refreshFilesTable();
  1985. filingSjs.refreshFileCountHint();
  1986. $(input).val('');
  1987. $('#add-big-file').modal('hide');
  1988. }
  1989. );
  1990. });
  1991. // 删除分类确认弹窗
  1992. $('#del-filing-ok').off('click').on('click', function() {
  1993. if (filingSjs.selectRemoveNode) {
  1994. filingSjs.delFiling(filingSjs.selectRemoveNode, function() {
  1995. $('#del-filing').modal('hide');
  1996. });
  1997. }
  1998. });
  1999. // 批量删除确认
  2000. $('#batch-del-file-ok').off('click').on('click', function() {
  2001. const del = [];
  2002. const checkes = $('[name=bd-check]:checked');
  2003. checkes.each(function() { del.push(this.getAttribute('fid')); });
  2004. filingSjs.delFiles(del, function() {
  2005. $('#batch-del-file').modal('hide');
  2006. });
  2007. });
  2008. // 覆盖批量删除按钮(增加权限检查)
  2009. $('#batch-del-file-btn').off('click').on('click', function() {
  2010. if (projectFileLocked) { toastr.error('管理员锁定中,暂无法删除文件'); return; }
  2011. if (!canEdit) { toastr.error('您没有当前目录的编辑文件权限'); return; }
  2012. const checkes = $('[name=bd-check]:checked');
  2013. if (checkes.length === 0) { toastr.warning('请选择要删除的文件'); return; }
  2014. for (const c of checkes) {
  2015. const fid = c.getAttribute('fid');
  2016. const file = filingSjs.curFiling.files.find(x => x.id === fid);
  2017. if (!file) continue;
  2018. if (filingSjs.isFileLocked(file)) {
  2019. toastr.error(`文件【${file.filename + file.fileext}】已锁定,无法删除`);
  2020. return;
  2021. }
  2022. }
  2023. $('#batch-del-file').modal('show');
  2024. });
  2025. // 覆盖批量下载(使用zip打包)
  2026. $('#batch-download').off('click').on('click', function() {
  2027. filingSjs.batchDownloadFiles();
  2028. });
  2029. // 覆盖移动文件确认
  2030. $('#move-file2-ok').off('click');
  2031. // 引用文件
  2032. const relaFileLoader = new RelaFileLoader();
  2033. $('#rela-file').on('show.bs.modal', function() {
  2034. relaFileLoader.showRelaFile(this.getAttribute('content'));
  2035. });
  2036. // 授权用户
  2037. const filingPermission = new FilingPermission({
  2038. modal: '#filing-permission',
  2039. list: '#filing-valid',
  2040. spread: '#permission-spread',
  2041. });
  2042. });