mixin.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. import {
  2. getDocumentList,
  3. packDownload,
  4. resetFileName,
  5. batchDelete,
  6. trash,
  7. recovery,
  8. trashDelete,
  9. folderTree,
  10. folderMove,
  11. addFolder,
  12. shareFolder,
  13. shareFolderList,
  14. shareTome,
  15. shareUser,
  16. shareAdjustment,
  17. cancelShare,
  18. fileDetail
  19. } from "@/api/workFlow/document";
  20. import resources from "@/libs/resources.js";
  21. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  22. const wordTypeList = ['doc', 'docx'];
  23. const excelTypeList = ['xls', 'xlsx'];
  24. const pptTypeList = ['ppt', 'pptx'];
  25. const pdfTypeList = ['pdf'];
  26. const zipTypeList = ['rar', 'zip', 'arj', 'z', '7z'];
  27. const txtTypeList = ['txt', 'log'];
  28. const codeTypeList = ['html', 'cs', 'xml'];
  29. const imgTypeList = ['png', 'jpg', 'jpeg', 'bmp', 'gif'];
  30. const videoTypeList = ['avi', 'wmv', 'mpg', 'mpeg', 'mov', 'rm', 'ram', 'swf', 'flv', 'mp4', 'mp3', 'wma', 'avi', 'rm',
  31. 'rmvb', 'flv', 'mpg', 'mkv'
  32. ];
  33. const previewTypeList = [...wordTypeList, ...excelTypeList, ...pptTypeList, ...pdfTypeList];
  34. export default {
  35. mixins: [MescrollMixin],
  36. data() {
  37. return {
  38. usersSelectValue: '',
  39. isDetail: true,
  40. showApply: false,
  41. folderTreeList: [],
  42. modalValue: '',
  43. keyword: '',
  44. current: 0,
  45. show: false,
  46. slide: '',
  47. slide2: '',
  48. changeStyle: true,
  49. checkedAll: false,
  50. parentId: 0,
  51. wordImg: resources.document.wordImg,
  52. excelImg: resources.document.excelImg,
  53. pptImg: resources.document.pptImg,
  54. pdfImg: resources.document.pdfImg,
  55. rarImg: resources.document.rarImg,
  56. txtImg: resources.document.txtImg,
  57. codeImg: resources.document.codeImg,
  58. imageImg: resources.document.imageImg,
  59. audioImg: resources.document.audioImg,
  60. blankImg: resources.document.blankImg,
  61. folderImg: resources.document.folderImg,
  62. downOption: {
  63. use: true,
  64. auto: true,
  65. },
  66. upOption: {
  67. page: {
  68. num: 0,
  69. size: 50,
  70. time: null,
  71. },
  72. empty: {
  73. use: true,
  74. icon: resources.message.nodata,
  75. tip: this.$t('common.noData'),
  76. fixed: false,
  77. top: "560rpx",
  78. },
  79. textNoMore: this.$t('app.apply.noMoreData'),
  80. toTop: {
  81. bottom: 200,
  82. right: 80
  83. }
  84. },
  85. selectFolder: {},
  86. moveId: '',
  87. selectFiles: [],
  88. modalType: 'restName',
  89. showAddSelect: false,
  90. selector: [{
  91. fullName: '新建文件夹',
  92. id: 1,
  93. icon: 'icon-ym icon-ym-add-folder'
  94. },
  95. {
  96. fullName: '上传文件',
  97. id: 2,
  98. icon: 'icon-ym icon-ym-generator-menu'
  99. }
  100. ],
  101. isDetail: false
  102. }
  103. },
  104. computed: {
  105. baseURL() {
  106. return this.define.baseURL
  107. },
  108. modalTitle() {
  109. return this.modalType === 'restName' ? '重命名文件' : '新建文件夹'
  110. }
  111. },
  112. methods: {
  113. onCallback(e) {
  114. this.$u.toast(e.msg)
  115. setTimeout(() => {
  116. this.showAddSelect = false
  117. this.resetList()
  118. }, 1000)
  119. },
  120. addSelect(item) {
  121. if (item == 'add') {
  122. this.showAddSelect = false
  123. this.$refs.inputDialog.open('center')
  124. this.modalType = 'addFolder'
  125. }
  126. },
  127. addFolder() {
  128. this.modalValue = ''
  129. this.showAddSelect = true
  130. },
  131. shareSubmit(e) {
  132. let method = this.current === 1 ? shareAdjustment : shareFolder;
  133. let data = {
  134. ids: this.selectFiles,
  135. userIds: e
  136. }
  137. method(data).then(res => {
  138. this.resetList()
  139. })
  140. },
  141. upCallback(page) {
  142. let method;
  143. switch (this.current) {
  144. case 1:
  145. method = shareFolderList
  146. break;
  147. case 3:
  148. method = trash
  149. break;
  150. case 2:
  151. method = shareTome
  152. break;
  153. default:
  154. method = getDocumentList
  155. break;
  156. }
  157. let query = {
  158. keyword: this.keyword,
  159. parentId: this.parentId
  160. };
  161. method(query).then(res => {
  162. this.documentList = [];
  163. this.selectFiles = []
  164. const list = res.data.list.map(o => ({
  165. ...o,
  166. time: o.deleteTime || o.creatorTime || o.shareTime
  167. }));
  168. this.documentList = this.documentList.concat(list);
  169. this.mescroll.endSuccess(list.length);
  170. })
  171. },
  172. downLoad(id) {
  173. let data = {
  174. ids: id ? id : this.selectFiles
  175. }
  176. packDownload(data).then(res => {
  177. // #ifdef H5
  178. const fileUrl = this.baseURL + res.data.url + '&name=' + encodeURI(res.data.name);
  179. window.location.href = fileUrl;
  180. // #endif
  181. // #ifdef MP
  182. this.previewFile(res.data)
  183. // #endif
  184. // #ifdef APP
  185. this.downloadFile(res.data.url);
  186. // #endif
  187. })
  188. },
  189. handelClick(item) {
  190. this.moveId = item.id == '-1' ? 0 : item.id
  191. },
  192. checkboxChange(e) {
  193. if (e.length) {
  194. this.slide = 'slide-up'
  195. this.slide2 = 'slide-up2'
  196. this.show = true
  197. } else {
  198. this.slide = 'slide-down'
  199. this.slide2 = 'slide-down2'
  200. }
  201. this.selectOperation(e)
  202. },
  203. change(e) {
  204. this.current = e
  205. this.parentId = 0
  206. this.resetList()
  207. },
  208. bottomfun(type) {
  209. if (type === 'down') this.downLoad()
  210. if (type === 'restName') {
  211. fileDetail(this.selectFiles[0]).then(res => {
  212. this.modalValue = res?.data?.fullName || ''
  213. this.modalType = 'restName'
  214. this.$refs.inputDialog.open()
  215. })
  216. }
  217. if (type === 'checkAll') this.checkedAllFun()
  218. if (type === 'revert') this.recoveryOrDelete(type)
  219. if (type === 'delete') this.recoveryOrDelete(type)
  220. if (type === 'share') {
  221. if (this.current == 1) return this.shareUser()
  222. this.usersSelectValue = ''
  223. this.$nextTick(() => {
  224. this.$refs.JnpfUsersSelect.openSelect()
  225. })
  226. }
  227. if (type === 'shareCancel') return this.cancelShare()
  228. if (type === 'move') this.getFolderTree()
  229. if (type === 'cancel') {
  230. this.selectFiles = []
  231. this.selectOperation(this.selectFiles)
  232. }
  233. },
  234. cancelShare() {
  235. uni.showModal({
  236. title: '提示',
  237. content: '您确定要取消共享, 是否继续?',
  238. success: (res) => {
  239. if (res.confirm) {
  240. cancelShare({
  241. ids: this.selectFiles
  242. }).then(res => {
  243. this.$u.toast(res.msg)
  244. this.resetList()
  245. })
  246. }
  247. }
  248. });
  249. },
  250. shareUser() {
  251. shareUser(this.selectFiles[0]).then(res => {
  252. let list = res.data.list || []
  253. const ids = list.map(item => item.shareUserId);
  254. this.usersSelectValue = ids
  255. this.$nextTick(() => {
  256. this.$refs.JnpfUsersSelect.openSelect()
  257. })
  258. })
  259. },
  260. folderMove() {
  261. let data = {
  262. ids: this.selectFiles,
  263. id: this.moveId
  264. }
  265. folderMove(data).then(res => {
  266. this.selectFiles = []
  267. this.close()
  268. this.resetList()
  269. })
  270. },
  271. downloadFile(url) {
  272. uni.downloadFile({
  273. url: this.baseURL + url,
  274. success: res => {
  275. if (res.statusCode === 200) {
  276. uni.saveFile({
  277. tempFilePath: res.tempFilePath,
  278. success: red => {
  279. uni.showToast({
  280. icon: 'none',
  281. mask: true,
  282. title: '文件已保存:' + red.savedFilePath, //保存路径
  283. duration: 3000,
  284. });
  285. setTimeout(() => {
  286. uni.openDocument({
  287. filePath: red.savedFilePath,
  288. success: ress => {},
  289. fail(err) {}
  290. });
  291. }, 500)
  292. }
  293. });
  294. }
  295. }
  296. });
  297. },
  298. iconClick() {
  299. if (this.documentList.length) this.changeStyle = !this.changeStyle
  300. },
  301. previewFile(item) {
  302. let fileTypes = ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx']
  303. let url = item.url
  304. let fileType = url.split('.')[1]
  305. if (fileTypes.includes(fileType)) {
  306. uni.downloadFile({
  307. url: this.baseURL + url,
  308. success: (res) => {
  309. let filePath = res.tempFilePath;
  310. uni.openDocument({
  311. filePath: encodeURI(filePath),
  312. showMenu: true,
  313. fileType: fileType,
  314. success: (res) => {
  315. console.log('打开文档成功');
  316. },
  317. fail(err) {
  318. console.log('小程序', err);
  319. }
  320. });
  321. }
  322. });
  323. } else {
  324. this.$u.toast(
  325. '该文件类型无法打开'
  326. )
  327. }
  328. },
  329. close() {
  330. this.showApply = false
  331. },
  332. checkedAllFun() {
  333. this.checkedAll = !this.checkedAll
  334. this.selectFiles = [];
  335. this.documentList.forEach(o => {
  336. if (this.checkedAll) {
  337. this.$set(o, 'checked', true)
  338. this.selectFiles.push(o.id);
  339. } else {
  340. this.$set(o, 'checked', false)
  341. this.selectFiles = [];
  342. }
  343. })
  344. },
  345. goDetail(e) {
  346. if (e.type == 0 && this.current != 3) {
  347. if (!this.isDetail) {
  348. let item = {
  349. current: this.current,
  350. changeStyle: this.changeStyle,
  351. ...e
  352. }
  353. this.selectFiles = []
  354. this.selectOperation()
  355. uni.navigateTo({
  356. url: './detail?config=' + JSON.stringify(item),
  357. });
  358. } else {
  359. this.parentId = e.id
  360. this.setTitle(e.fullName)
  361. this.pushTreeStack(e);
  362. this.resetList()
  363. }
  364. } else {
  365. if (imgTypeList.includes(e.isPreview)) {
  366. const images = this.baseURL + e.uploaderUrl;
  367. uni.previewImage({
  368. urls: [images],
  369. success: () => {},
  370. fail: () => {
  371. uni.showToast({
  372. title: '预览图片失败',
  373. icon: 'none'
  374. });
  375. }
  376. });
  377. }
  378. if (this.current !== 3) this.downLoad([e.id])
  379. }
  380. },
  381. selectOperation(value) {
  382. let items = this.documentList;
  383. this.selectFiles = value || [];
  384. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  385. const item = items[i]
  386. if (this.selectFiles.includes(item.id)) {
  387. this.$set(item, 'checked', true)
  388. } else {
  389. this.$set(item, 'checked', false)
  390. }
  391. }
  392. },
  393. getRecordImg(ext) {
  394. if (!ext) return this.folderImg;
  395. if (ext) ext = ext.replace('.', '');
  396. if (wordTypeList.includes(ext)) return this.wordImg;
  397. if (excelTypeList.includes(ext)) return this.excelImg;
  398. if (pptTypeList.includes(ext)) return this.pptImg;
  399. if (pdfTypeList.includes(ext)) return this.pdfImg;
  400. if (zipTypeList.includes(ext)) return this.rarImg;
  401. if (txtTypeList.includes(ext)) return this.txtImg;
  402. if (codeTypeList.includes(ext)) return this.codeImg;
  403. if (imgTypeList.includes(ext)) return this.imageImg;
  404. if (videoTypeList.includes(ext)) return this.audioImg;
  405. return this.blankImg;
  406. },
  407. getFolderTree() {
  408. let data = {
  409. ids: this.selectFiles
  410. }
  411. folderTree(data).then(res => {
  412. this.showApply = true
  413. this.folderTreeList = JSON.parse(JSON.stringify(res.data.list)) || []
  414. const loop = (list, parent) => {
  415. list.forEach(o => {
  416. o.icon = 'icon-ym icon-ym-folder';
  417. if (o && o.children && Array.isArray(o.children)) {
  418. loop(o.children, o)
  419. }
  420. })
  421. }
  422. loop(this.folderTreeList)
  423. })
  424. },
  425. recoveryOrDelete(type) {
  426. let data = {
  427. ids: this.selectFiles
  428. }
  429. let content = '确定要还原选中的文件吗'
  430. let method = recovery
  431. if (type !== 'revert') {
  432. content = '删除后,放入回收站!'
  433. method = batchDelete
  434. if (type === 'delete' && this.current == 3) {
  435. content = '删除后数据无法恢复'
  436. method = trashDelete
  437. }
  438. }
  439. uni.showModal({
  440. title: '提示',
  441. content,
  442. success: (res) => {
  443. if (res.confirm) {
  444. method(data).then(res => {
  445. this.$u.toast(res.msg)
  446. setTimeout(() => {
  447. this.$nextTick(() => {
  448. this.documentList = [];
  449. this.selectFiles = []
  450. this.mescroll.resetUpScroll();
  451. })
  452. }, 1000)
  453. })
  454. }
  455. }
  456. });
  457. },
  458. /* 新建文件 */
  459. handleAddFolder() {
  460. let item = {
  461. id: '',
  462. parentId: this.parentId,
  463. type: 0,
  464. fullName: this.modalValue
  465. }
  466. addFolder(item).then(res => {
  467. this.modalType = 'restName'
  468. this.closeDialog()
  469. this.resetList()
  470. })
  471. },
  472. /* 重命名 */
  473. closeDialog() {
  474. this.$refs.inputDialog.close()
  475. },
  476. restName(e) {
  477. let txt = this.modalType === 'addFolder' ? '文件夹名称不能为空' : '文件名不能为空'
  478. if (!this.modalValue) return this.$u.toast(txt)
  479. if (this.modalType === 'addFolder') return this.handleAddFolder()
  480. if (this.modalType === 'restName') return this.handleRestName()
  481. },
  482. handleRestName() {
  483. let item = {}
  484. this.documentList.forEach(o => {
  485. if (o.id === this.selectFiles[0]) item = {
  486. id: o.id,
  487. parentId: this.parentId,
  488. type: o.type,
  489. fullName: this.modalValue
  490. }
  491. })
  492. resetFileName(item).then(res => {
  493. this.selectFiles = []
  494. this.closeDialog()
  495. this.resetList()
  496. })
  497. },
  498. resetList() {
  499. this.$nextTick(() => {
  500. this.selectFiles = []
  501. this.documentList = [];
  502. this.mescroll.resetUpScroll();
  503. })
  504. },
  505. }
  506. }