util.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import store from '@/store';
  2. import vue from 'vue';
  3. const userId = store.state.user.info.userId;
  4. const userName = store.state.user.info.name;
  5. export function isCreateUserId(row) {
  6. if (vue.prototype.$hasPermission('fm:doc:viewAll')) {
  7. return true;
  8. }
  9. return userId == row?.createUserId;
  10. }
  11. export function isPower(data = {}, power, selection = []) {
  12. if (!data.id && selection.length == 0) {
  13. return false;
  14. }
  15. if (
  16. //文件查看浏览权限
  17. vue.prototype.$hasPermission('fm:doc:viewAll')
  18. ) {
  19. return true;
  20. }
  21. if (power == 'add' && data.userAuthority.length == 0) {
  22. return true;
  23. }
  24. if (power == 'checkEnter' && data?.checkOutUserId != userId) {
  25. //检入特殊处理
  26. return false;
  27. }
  28. if (selection.length > 0) {
  29. //多选情况处理
  30. let _isPower = true;
  31. let userAuthorityS = [];
  32. let createUserIdS = selection
  33. .map((item) => item.createUserId)
  34. .filter((createUserId) => createUserId == userId);
  35. if (createUserIdS.length == selection.length || userName == 'admin') {
  36. //创建人/admin所有权限
  37. return true;
  38. }
  39. selection.forEach((val) => {
  40. const powerObj = val.userAuthority.find((item) => item.id == userId);
  41. if (powerObj) {
  42. userAuthorityS.push(powerObj);
  43. }
  44. });
  45. if (userAuthorityS.length == 0) {
  46. _isPower = false;
  47. }
  48. userAuthorityS.forEach((item) => {
  49. if (item[power] != '1') {
  50. _isPower = false;
  51. }
  52. });
  53. return _isPower;
  54. }
  55. if (data.createUserId == userId || userName == 'admin') {
  56. //创建人/admin所有权限
  57. return true;
  58. }
  59. if (!power) {
  60. return false;
  61. }
  62. const powerObj = data.userAuthority?.find((item) => item.id == userId);
  63. if (powerObj) {
  64. return powerObj[power] == '1';
  65. }
  66. }
  67. export function isCheckOut(data = {}) {
  68. //检出判断
  69. if (data?.checkOutStatus == 1 && userId != data.checkOutUserId) {
  70. return true;
  71. }
  72. }
  73. export function setFolderList(data) {
  74. //递归过滤文件夹权限
  75. data.forEach((item) => {
  76. item['disabled'] = !isPower(item, 'add');
  77. if (item.sonDirectoryList && item.sonDirectoryList.length > 0) {
  78. setFolderList(item.sonDirectoryList);
  79. }
  80. });
  81. }
  82. export function setFileUrl(row) {
  83. let file = row.storagePath[0];
  84. let fileNames = file.storePath.split('/');
  85. let url =
  86. window.location.origin +
  87. '/api/main/file/getFile?objectName=' +
  88. file.storePath +
  89. '&fullfilename=' +
  90. fileNames[fileNames.length - 1];
  91. return '/kkfile/onlinePreview?url=' + btoa(url);
  92. }
  93. export function getFileType() {
  94. return [
  95. 'par',
  96. 'asm',
  97. 'psm',
  98. 'dft',
  99. 'sldprt',
  100. 'sldasm',
  101. 'ipt',
  102. ' iam',
  103. 'prt',
  104. '3dxml',
  105. 'CATPart',
  106. 'CATProduct',
  107. 'cgr',
  108. 'model',
  109. 'exp',
  110. 'session',
  111. 'x_t',
  112. 'xmt_txt',
  113. 'x_b',
  114. 'xmp_bin',
  115. 'xmp_txt',
  116. 'sat',
  117. '.sab',
  118. '.igs',
  119. 'iges',
  120. 'stp',
  121. 'step',
  122. 'jt',
  123. 'xcgm',
  124. '3dm',
  125. 'stl',
  126. 'obj',
  127. '3mf',
  128. 'fbx',
  129. 'vda',
  130. 'dxf',
  131. 'dwg',
  132. 'idf',
  133. 'idb',
  134. 'emn',
  135. 'brd'
  136. ];
  137. }
  138. export function fileStatus(status) {
  139. return status == 1
  140. ? '发布中'
  141. : status == 2
  142. ? '已发布'
  143. : status == 3
  144. ? '已归档'
  145. : status == 4
  146. ? '已废止'
  147. : '';
  148. // if (fileType == 2) {
  149. // return status == 1 ? '已发布' : '未发布';
  150. // }
  151. // if (fileType === 0) {
  152. // if (lcyStatus == 2) {
  153. // return '已归档'
  154. // }
  155. // if (lcyStatus == 3) {
  156. // return '已发布'
  157. // }
  158. // if (lcyStatus == 4) {
  159. // return '已废止'
  160. // }
  161. // }
  162. }