project.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <div class="datacenter-project hui-flex hui-content">
  3. <div class="work-document-title">
  4. <el-button type="primary" size="medium" v-if="parentId !== -1" @click="$refs.upload.reloadUpload()">
  5. <i class="iconfont huifont-shangchuan"></i>上传
  6. </el-button>
  7. <el-button type="info" size="medium" @click="insertFolder">
  8. <i class="el-icon-folder-add"></i>
  9. 新增文件夹
  10. </el-button>
  11. <el-button type="info" size="medium" @click="setDialog = true">
  12. <i class="el-icon-setting"></i>
  13. 设置
  14. </el-button>
  15. <el-button type="info" size="medium" @click="messageVisible = true">
  16. <i class="el-icon-bell"></i>
  17. 审核
  18. </el-button>
  19. <data-upload ref="upload" v-show="false" :parentId="parentId" type="project" @reload="init"></data-upload>
  20. </div>
  21. <div class="work-document-breadcrumb">
  22. <div v-if="parentId!==-1" class="breadcrumb-back" @click="$router.back(-1)">
  23. <span>返回上一级</span>
  24. </div>
  25. <div class="breadcrumb-line" v-if="parentId!==-1"></div>
  26. <el-breadcrumb separator-class="el-icon-arrow-right">
  27. <el-breadcrumb-item v-if="folderList.length === 0">全部文件</el-breadcrumb-item>
  28. <el-breadcrumb-item v-else :to="{ path: $router.path }">全部文件</el-breadcrumb-item>
  29. <el-breadcrumb-item v-for="(item,index) in folderList" :to="returnPath(index)"
  30. :key="item.id">{{item.name}}</el-breadcrumb-item>
  31. </el-breadcrumb>
  32. </div>
  33. <div class="hui-flex-box hui-table">
  34. <el-table :data="tableData" row-key="id" height="100%" border @row-click="clickRow">
  35. <el-table-column prop="name" label="文件夹名称">
  36. <template slot-scope="scope">
  37. <div class="work-document-name">
  38. <svg-icon v-if="scope.row.directory" name="dir" width="24" height="20"></svg-icon>
  39. <svg-icon v-else :name="iconName(scope.row.name)" width="24" height="20"></svg-icon>
  40. <span>{{scope.row.name}}</span>
  41. </div>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="操作" width="200">
  45. <template slot-scope="scope">
  46. <div class="hui-table-operation" @click.stop="()=>{}">
  47. <span class="table-operation" @click.stop="setPermission(scope.row)">
  48. 权限
  49. </span>
  50. <span class="table-operation" v-if="!scope.row.directory" @click.stop="download(scope.row)">
  51. 下载
  52. </span>
  53. <span class="table-operation"
  54. v-if="!scope.row.directory && isPreview(iconName(scope.row.name)).isPreview"
  55. @click.stop="preview(scope.row,isPreview(iconName(scope.row.name)).type)">
  56. 预览
  57. </span>
  58. <span class="table-operation" v-if="scope.row.directory"
  59. @click.stop="updateFolder(scope.row)">
  60. 重命名
  61. </span>
  62. <span class="table-operation" @click.stop="deleteItem(scope.row)">
  63. 删除
  64. </span>
  65. </div>
  66. </template>
  67. </el-table-column>
  68. <template slot="empty">
  69. <empty description="暂无数据"></empty>
  70. </template>
  71. </el-table>
  72. </div>
  73. <el-dialog title="设置" :visible.sync="dialogVisible" :append-to-body="true">
  74. <set-permission v-if="dialogVisible" @callback="callBack" :detail="detail"></set-permission>
  75. </el-dialog>
  76. <el-dialog :title="isUpdate?'编辑文件夹':'新建文件夹'" :visible.sync="formDialog" width="900px" :append-to-body="true">
  77. <folder-form v-if="formDialog" @callback="callBack" :parentId="parentId" :detail="detail"
  78. :isUpdate="isUpdate" type="project">
  79. </folder-form>
  80. </el-dialog>
  81. <el-dialog title="设置审核人" :visible.sync="setDialog" width="900px" :append-to-body="true">
  82. <set-approve v-if="setDialog" @callback="callBack" :type="1" title="设置审核人"></set-approve>
  83. </el-dialog>
  84. <el-dialog title="审核列表" :visible.sync="messageVisible" width="80%" :append-to-body="true">
  85. <message v-if="messageVisible" :option="{messageType:5,dataTypes:'1,2,3'}"></message>
  86. </el-dialog>
  87. <el-dialog title="预览" :visible.sync="fileVisible" width="900px" :append-to-body="true">
  88. <video v-if="previewType === 'video' && iframeSrc && fileVisible" :src="iframeSrc" width="100%"
  89. height="100%" style="background: #000;" controls>
  90. </video>
  91. <iframe v-if="previewType === 'pdf' && iframeSrc && fileVisible" :src="iframeSrc" frameborder="0"
  92. width="100%" height="100%">
  93. </iframe>
  94. <preview-excel v-if="previewType === 'excel' && iframeSrc && fileVisible" :loadUrl="iframeSrc">
  95. </preview-excel>
  96. <previewPPT v-if="previewType === 'ppt' && iframeSrc && fileVisible" :loadUrl="iframeSrc"></previewPPT>
  97. </el-dialog>
  98. <image-viewer v-if="isShow" :url-list="[imageUrl]" :on-close="()=>isShow = false"></image-viewer>
  99. </div>
  100. </template>
  101. <script>
  102. import {
  103. generateFileNodeProject,
  104. getProjectDirList,
  105. downloadFile,
  106. deleteProjectDir,
  107. deleteProjectFile,
  108. getProjectDirListByids,
  109. getSetApprove
  110. } from '@/httpApi/datacenter'
  111. import {
  112. projectPermission,
  113. downloadFileDom
  114. } from '@/uitls/datacenter'
  115. import setPermission from '@/components/datacenter/setPermission'
  116. import dataUpload from '@/components/datacenter/dataUpload'
  117. import folderForm from '@/components/datacenter/folderForm'
  118. import setApprove from '@/components/datacenter/setApprove'
  119. import message from '@/components/message/message'
  120. import imageViewer from 'element-ui/packages/image/src/image-viewer.vue';
  121. import previewExcel from '@/components/datacenter/previewExcel.vue'
  122. import previewPPT from '@/components/datacenter/previewPPT.vue'
  123. export default {
  124. data() {
  125. return {
  126. tableData: [],
  127. parentId: -1,
  128. dialogVisible: false,
  129. formDialog: false,
  130. isUpdate: false,
  131. detail: {},
  132. folderList: [],
  133. setDialog: false,
  134. messageVisible: false,
  135. iframeSrc: '',
  136. fileVisible: false,
  137. isShow: false,
  138. imageUrl: '',
  139. previewType: ''
  140. }
  141. },
  142. created() {
  143. this.init();
  144. },
  145. components: {
  146. setPermission,
  147. dataUpload,
  148. folderForm,
  149. setApprove,
  150. message,
  151. imageViewer,
  152. previewExcel,
  153. previewPPT
  154. },
  155. methods: {
  156. init() {
  157. if (this.$route.query.path) {
  158. let data = this.$route.query.path.split('/');
  159. this.parentId = data[data.length - 1];
  160. this.projectDirList();
  161. getProjectDirListByids(data).then(res => {
  162. if (res.state) {
  163. this.folderList = res.data;
  164. }
  165. })
  166. } else {
  167. this.folderList = [];
  168. this.parentId = -1;
  169. this.initProjectDir();
  170. }
  171. },
  172. initProjectDir() {
  173. generateFileNodeProject(this.$store.getters.project.id).then(res => {
  174. if (res.state) {
  175. this.tableData = res.data.sort((a, b) => b.directory - a.directory);
  176. }
  177. });
  178. },
  179. projectDirList() {
  180. getProjectDirList(this.parentId).then(res => {
  181. if (res.state) {
  182. this.tableData = res.data.sort((a, b) => b.directory - a.directory);
  183. }
  184. });
  185. },
  186. clickRow(data) {
  187. if (!data.directory) return;
  188. projectPermission({
  189. id: data.id,
  190. oldPermission: data.permissions,
  191. type: 'access',
  192. name: data.name,
  193. folderList: this.folderList
  194. }, () => {
  195. let path = this.$route.query.path;
  196. this.$router.push({
  197. path: this.$router.path,
  198. query: {
  199. path: !path ? String(data.id) : (path + '/' + data.id)
  200. }
  201. })
  202. });
  203. },
  204. returnPath(index) {
  205. if (index === (this.folderList.length - 1)) return ''
  206. let data = this.folderList.slice(0, (index + 1)).map(res => res.id);
  207. return {
  208. path: this.$router.path,
  209. query: {
  210. path: data.join('/')
  211. }
  212. }
  213. },
  214. download(data) {
  215. projectPermission({
  216. id: data.id,
  217. oldPermission: data.permissions || '1',
  218. type: 'fileDownload',
  219. name: data.name,
  220. folderList: this.folderList
  221. }, () => {
  222. downloadFile(0, data.id).then(res => {
  223. let fileName = data.name;
  224. downloadFileDom(res, fileName);
  225. });
  226. });
  227. },
  228. preview(data, type) {
  229. projectPermission({
  230. id: data.id,
  231. oldPermission: data.permissions || '1',
  232. type: 'fileView',
  233. name: data.name,
  234. folderList: this.folderList
  235. }, () => {
  236. this.previewFile(data, type);
  237. });
  238. },
  239. isPreview(filename) {
  240. let type = '',
  241. isPreview = false,
  242. imageBox = ['jpg', 'jpeg', 'png', 'gif', 'webp'],
  243. officeBox = ['docx', 'doc', 'xlsx', 'pptx'],
  244. videoBox = ['mp4', 'webm', 'ogg'];
  245. if (imageBox.filter(node => node === filename).length > 0) {
  246. type = 'image';
  247. isPreview = true;
  248. } else if (filename === 'pdf') {
  249. type = 'pdf';
  250. isPreview = true;
  251. } else if (officeBox.filter(node => node === filename).length > 0) {
  252. type = filename;
  253. isPreview = true;
  254. } else if (videoBox.filter(node => node === filename).length > 0) {
  255. type = 'video';
  256. isPreview = true;
  257. }
  258. return {
  259. isPreview: isPreview,
  260. type: type
  261. }
  262. },
  263. insertFolder() {
  264. this.isUpdate = false;
  265. this.formDialog = true;
  266. },
  267. callBack(type) {
  268. this.dialogVisible = false;
  269. this.formDialog = false;
  270. this.setDialog = false;
  271. if (type === 'init') this.init();
  272. },
  273. setPermission(data) {
  274. this.detail = data;
  275. this.dialogVisible = true;
  276. },
  277. updateFolder(data) {
  278. this.detail = data;
  279. this.isUpdate = true;
  280. this.formDialog = true;
  281. },
  282. deleteItem(data) {
  283. projectPermission({
  284. id: data.id,
  285. oldPermission: data.permissions || '1',
  286. type: data.directory ? 'delete' : 'fileDelete',
  287. name: data.name,
  288. folderList: this.folderList
  289. }, () => {
  290. data.directory ? deleteProjectDir(data.id).then(this.successFunc) : deleteProjectFile(data.id)
  291. .then(this.successFunc);
  292. });
  293. },
  294. successFunc(res) {
  295. if (res.state) {
  296. this.$message.success('操作成功');
  297. this.init();
  298. }
  299. },
  300. iconName(name) {
  301. let nameList = name.split('.');
  302. return nameList[nameList.length - 1].toLowerCase();
  303. },
  304. previewFile(data, type) {
  305. this.previewType = type;
  306. if (type === 'image') {
  307. this.imageUrl = data.node.url;
  308. this.isShow = true;
  309. } else if (type === 'video') {
  310. this.iframeSrc = data.node.url;
  311. this.fileVisible = true;
  312. } else if (type === 'pdf') {
  313. this.iframeSrc = `./pdf/web/viewer.html?file=${data.node.url}`;
  314. this.fileVisible = true;
  315. } else if (type === 'docx' || type === 'doc') {
  316. this.iframeSrc =
  317. `./pdf/web/viewer.html?file=https://www.waywish.com/file/fileNodeProject/${data.id}/renderPdf`;
  318. this.previewType = 'pdf';
  319. this.fileVisible = true;
  320. } else if (type === 'xlsx') {
  321. this.iframeSrc = data.node.url;
  322. this.previewType = 'excel';
  323. this.fileVisible = true;
  324. } else if (type === 'pptx') {
  325. this.iframeSrc = data.node.url;
  326. this.previewType = 'ppt';
  327. this.fileVisible = true;
  328. }
  329. }
  330. },
  331. watch: {
  332. $route() {
  333. this.tableData = [];
  334. this.init();
  335. }
  336. }
  337. }
  338. </script>
  339. <style lang="scss">
  340. .datacenter-project {
  341. width: 100%;
  342. height: 100%;
  343. padding: 20px 24px;
  344. border-radius: 8px;
  345. .work-document-title {
  346. padding-bottom: 20px;
  347. display: flex;
  348. align-items: center;
  349. .el-button {
  350. padding: 0 16px;
  351. margin: 0 !important;
  352. margin-right: 12px !important;
  353. }
  354. .el-button>span {
  355. display: flex;
  356. height: 32px;
  357. align-items: center;
  358. .el-icon-folder-add {
  359. font-size: 18px;
  360. margin-right: 5px;
  361. }
  362. .el-icon-setting,
  363. .el-icon-bell {
  364. margin-right: 3px;
  365. }
  366. }
  367. .button-icon {
  368. padding: 5px;
  369. font-size: 16px;
  370. }
  371. }
  372. .work-document-breadcrumb {
  373. display: flex;
  374. align-items: center;
  375. margin-bottom: 20px;
  376. height: 20px;
  377. .breadcrumb-back {
  378. max-width: 120px;
  379. cursor: pointer;
  380. display: flex;
  381. align-items: center;
  382. font-size: 14px;
  383. i {
  384. font-size: 18px;
  385. }
  386. }
  387. .breadcrumb-line {
  388. margin: 0 10px;
  389. width: 1px;
  390. background: $--color-common;
  391. height: 14px;
  392. }
  393. .el-breadcrumb {
  394. font-size: 14px;
  395. .el-breadcrumb__item {
  396. cursor: pointer;
  397. }
  398. }
  399. .el-breadcrumb__inner {
  400. color: $--color-common;
  401. opacity: 0.5;
  402. }
  403. .el-breadcrumb__inner.is-link,
  404. .el-breadcrumb__inner a {
  405. transition: none;
  406. font-weight: normal;
  407. opacity: 1;
  408. }
  409. }
  410. .hui-table {
  411. padding: 0;
  412. }
  413. .el-table {
  414. tr {
  415. cursor: pointer;
  416. }
  417. .cell {
  418. .work-document-name {
  419. display: flex;
  420. align-items: center;
  421. span {
  422. font-weight: bold;
  423. margin-left: 5px;
  424. }
  425. }
  426. }
  427. }
  428. }
  429. </style>