fileCenter.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <section >
  3. <div :style="'background:#f7f7f7;padding:10px 50px;height:'+tableHeight+'px;'">
  4. <!--工具条-->
  5. <!-- <el-col :span="24" class="toolbar" style="padding-bottom: 0px;background:#fff;border-bottom:1px solid #f7f7f7;">
  6. <el-form :inline="true">
  7. <el-form-item label="文件库">
  8. </el-form-item>
  9. <el-form-item style="float:right;">
  10. <el-link type="primary" :underline="false" @click="createFolder()"><i class="el-icon-folder-add"></i><span style="margin-left:5px;">创建文件夹</span></el-link>
  11. <el-upload ref="upload" action="#" :http-request="uploadFile" :show-file-list="false" :limit="1" style="display:inline-block;">
  12. <el-link type="primary" :underline="false" style="margin-left:10px;"><i class="iconfont firerock-iconshangchuan"></i><span style="margin-left:5px;">文件上传</span></el-link>
  13. </el-upload>
  14. </el-form-item>
  15. </el-form>
  16. </el-col> -->
  17. <div style="padding: 20px;background:#fff;border-bottom:1px solid #ddd;font-weight:500;font-size:15px;">
  18. <span @click="viewFolder(null)">文件库</span>
  19. <span v-for="path in pathList" :key="path.id" @click="viewFolder(path)"> / {{path.documentName}}</span>
  20. <span style="float:right;">
  21. <el-link type="primary" :underline="false" @click="createFolder"><i class="el-icon-folder-add"></i><span style="margin-left:5px;">创建文件夹</span></el-link>
  22. <el-upload ref="upload" action="#" :http-request="uploadFile" :show-file-list="false" :limit="1" style="display:inline-block;">
  23. <el-link type="primary" :underline="false" style="margin-left:10px;"><i class="iconfont firerock-iconshangchuan"></i><span style="margin-left:5px;">文件上传</span></el-link>
  24. </el-upload>
  25. </span>
  26. </div>
  27. <div>
  28. <el-col :span="6" style="border-right: 1px solid #EBEEF5;">
  29. <el-table :data="recentFiles" highlight-current-row :height="tableHeight">
  30. <el-table-column prop="documentName" label="近期文件" sortable="true">
  31. <template slot-scope="scope">
  32. <!-- <el-link @click.stop.native="viewOnline(scope.row)"> -->
  33. <i v-if="scope.row.documentType == -1" class="iconfont firerock-iconfile fileTypeIcon"></i>
  34. <i v-if="scope.row.documentType != -1" :class="docTypeList[scope.row.documentType]+' fileTypeIcon'" ></i>
  35. <span style="margin-left:8px;color:#262626;" >{{scope.row.documentName}}</span>
  36. <!-- <span style="margin-left:8px;color:#262626;" @click="viewOnline(scope.row)">{{scope.row.documentName}}</span> -->
  37. <!-- </el-link> -->
  38. </template>
  39. </el-table-column>
  40. <el-table-column width="60" >
  41. <template slot-scope="scope">
  42. <el-button icon="el-icon-download" circle size="mini" style="margin-left:10px;" @click.stop.native="downloadByA(scope.row)"></el-button>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. </el-col>
  47. <el-col :span="18" >
  48. <el-table :data="list" highlight-current-row :height="tableHeight" style="width: 100%;" @row-click="rowClick" @cell-mouse-enter="cursorOver" >
  49. <!-- <el-table-column prop="folder" ></el-table-column> -->
  50. <el-table-column prop="documentName" label="名称" >
  51. <template slot-scope="scope" >
  52. <div v-if="scope.row.isFolder==1">
  53. <i class="el-icon-folder fileTypeIcon"></i><span style="margin-left:8px;color:#262626;" >{{scope.row.documentName}}</span>
  54. </div>
  55. <div v-if="scope.row.isFolder==0">
  56. <!-- <el-link @click.stop.native="viewOnline(scope.row)"> -->
  57. <i v-if="scope.row.documentType == -1" class="iconfont firerock-iconfile fileTypeIcon"></i>
  58. <i v-if="scope.row.documentType != -1" :class="docTypeList[scope.row.documentType]+' fileTypeIcon'"></i>
  59. <span style="margin-left:8px;color:#262626;" >{{scope.row.documentName}}</span>
  60. <!-- </el-link> -->
  61. </div>
  62. </template>
  63. </el-table-column>
  64. <el-table-column prop="size" label="大小" width="100">
  65. <template slot-scope="scope">
  66. {{scope.row.isFolder==0?scope.row.size:"-"}}
  67. </template>
  68. </el-table-column>
  69. <el-table-column prop="creatorName" label="创建者" width="100"></el-table-column>
  70. <el-table-column prop="indate" label="创建时间" sortable="true" width="100"></el-table-column>
  71. <el-table-column width="140">
  72. <template slot-scope="scope" >
  73. <div v-show="currentDataId == scope.row.id">
  74. <el-button v-if="scope.row.isFolder == 0" icon="el-icon-download" circle size="mini" @click.stop.native="downloadByA(scope.row)"></el-button>
  75. <el-button icon="el-icon-edit" circle size="mini" style="margin-left:10px;" @click.stop.native="showEditName(scope.row)"></el-button>
  76. <el-button icon="el-icon-delete" circle size="mini" style="margin-left:10px;" @click.stop.native="deleteItem(scope.row)"></el-button>
  77. </div>
  78. </template>
  79. </el-table-column>
  80. </el-table>
  81. </el-col>
  82. </div>
  83. <!--新增界面-->
  84. <el-dialog title="文件上传" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
  85. <el-form ref="form1" :model="addForm" :rules="rules" label-width="120px">
  86. <el-form-item label="截止日期" prop="planEndDate">
  87. <el-date-picker v-model="addForm.planEndDate" v-if="user.company.packageProject==1"
  88. :editable="false"
  89. format="yyyy-MM-dd"
  90. value-format="yyyy-MM-dd"
  91. :clearable="false" type="date"
  92. placeholder="选择日期"></el-date-picker>
  93. </el-form-item>
  94. </el-form>
  95. <div slot="footer" class="dialog-footer">
  96. <el-button @click.native="addFormVisible = false">取消</el-button>
  97. <el-button type="primary" @click="submitInsert" :loading="addLoading">提交</el-button>
  98. </div>
  99. </el-dialog>
  100. <!-- 文件夹弹出框 -->
  101. <el-dialog title="新增/修改文件夹" v-if="addFolderDialog" :visible.sync="addFolderDialog" :close-on-click-modal="false" customClass="customWidth" width="300px">
  102. <el-form ref="form2" :model="folderForm" :rules="rules" >
  103. <el-form-item prop="documentName">
  104. <el-input v-model="folderForm.documentName" placeholder="请输入文件夹名称" maxlength="25"
  105. show-word-limit clearable></el-input>
  106. </el-form-item>
  107. </el-form>
  108. <div slot="footer" class="dialog-footer">
  109. <el-button type="primary" @click="addFolder" style="width:100%;" >保存</el-button>
  110. </div>
  111. </el-dialog>
  112. </div>
  113. </section>
  114. </template>
  115. <style scoped>
  116. .fileTypeIcon {
  117. color:#20a0ff;font-size:20px;
  118. }
  119. </style>
  120. <script>
  121. import util from "../../common/js/util";
  122. export default {
  123. data() {
  124. return {
  125. pathList:[],
  126. currentDataId: null,
  127. docTypeList:["iconfont firerock-iconJPG","iconfont firerock-iconword","iconfont firerock-icontxt"
  128. ,"iconfont firerock-iconex","iconfont firerock-iconZip","iconfont firerock-iconvideo"
  129. ,"iconfont firerock-iconaudio","iconfont firerock-iconPDF"],
  130. rules: {
  131. documentName: [{ required: true, message: "请输入文件夹名称", trigger: "blur" }],
  132. },
  133. folderForm:{},
  134. addFolderDialog: false,
  135. moveToTrashDialog:false,
  136. list:[],
  137. parentFid:null,
  138. upLoading:false,
  139. keyword:null,
  140. user: JSON.parse(sessionStorage.getItem("user")),
  141. recentFiles: [],
  142. addFormVisible: false,
  143. addLoading: false,
  144. curProjectId:null,
  145. title: "",
  146. addForm: {
  147. },
  148. };
  149. },
  150. methods: {
  151. cursorOver(row, column, cell, event) {
  152. this.currentDataId = row.id;
  153. },
  154. viewOnline(row) {
  155. this.http.post('/pdf-file/getProjectFile', {fileId: row.id},
  156. res => {
  157. if (res.code == "ok") {
  158. console.log(res.data+'----'+row.documentName);
  159. let routeUrl = this.$router.resolve({
  160. path: "/viewonline",
  161. params: {serverFname:res.data, fileName:row.documentName}
  162. });
  163. sessionStorage.setItem("serverFname",res.data);
  164. sessionStorage.setItem("fileName",row.documentName);
  165. console.log(routeUrl.href);
  166. window.open(routeUrl.href, '_blank');
  167. } else {
  168. this.$message({
  169. message: res.msg,
  170. type: 'error'
  171. });
  172. }
  173. }, error => {
  174. this.$message({
  175. message: error,
  176. type: 'error'
  177. });
  178. })
  179. },
  180. deleteItem(row) {
  181. this.$confirm("确认要移到回收站吗?", "提示", {
  182. //type: 'warning'
  183. }).then(() => {
  184. this.http.post('/document/delete', row,
  185. res => {
  186. if (res.code == "ok") {
  187. this.addFolderDialog = false;
  188. this.getRecentList();
  189. this.getList();
  190. } else {
  191. this.$message({
  192. message: res.msg,
  193. type: "error"
  194. });
  195. }
  196. },
  197. error => {
  198. this.$message({
  199. message: error,
  200. type: "error"
  201. });
  202. });
  203. });
  204. },
  205. viewFolder(item) {
  206. var list = [];
  207. if (item == null) {
  208. //查看根目录
  209. this.parentFid = null;
  210. } else {
  211. this.parentFid = item.id;
  212. for (var i=0;i<this.pathList.length; i++) {
  213. list.push(this.pathList[i]);
  214. if (this.pathList[i].id == item.id) {
  215. break;
  216. }
  217. }
  218. }
  219. console.log('list===='+list);
  220. this.pathList = list;
  221. this.getList();
  222. },
  223. rowClick(row, column, event) {
  224. if (row.isFolder==1) {
  225. //进入子目录
  226. this.parentFid = row.id;
  227. this.pathList.push(row);
  228. this.getList();
  229. } else {
  230. //直接查看,在线打开
  231. }
  232. },
  233. addFolder() {
  234. this.$refs.form2.validate(valid => {
  235. if (valid) {
  236. this.http.post('/document/createDocument', this.folderForm,
  237. res => {
  238. if (res.code == "ok") {
  239. this.addFolderDialog = false;
  240. this.getRecentList();
  241. this.getList();
  242. } else {
  243. this.$message({
  244. message: res.msg,
  245. type: "error"
  246. });
  247. }
  248. },
  249. error => {
  250. this.$message({
  251. message: error,
  252. type: "error"
  253. });
  254. });
  255. }
  256. });
  257. },
  258. showEditName(row) {
  259. this.addFolderDialog = true;
  260. this.folderForm = JSON.parse(JSON.stringify(row));
  261. },
  262. createFolder(){
  263. this.addFolderDialog = true;
  264. this.folderForm = {projectId: this.curProjectId, folderId: this.parentFid,isFolder: 1};
  265. },
  266. openWin(url) {
  267. var el = document.createElement("a");
  268. document.body.appendChild(el);
  269. el.href = encodeURI(url);
  270. el.target = '_blank';
  271. el.click();
  272. document.body.removeChild(el);
  273. },
  274. downloadByA(row) {
  275. const a = document.createElement('a'); // 创建a标签
  276. a.setAttribute('download', row.documentName);// download属性
  277. a.setAttribute('href', row.url);// href链接
  278. a.click();// 自执行点击事件
  279. a.remove();
  280. },
  281. //上传
  282. uploadFile(params) {
  283. this.upLoading = true;
  284. var fileObj = params.file;
  285. var form = new FormData();
  286. form.append("projectId",this.curProjectId);
  287. form.append("file", fileObj);
  288. if (this.parentFid != null) {
  289. form.append("folderId", this.parentFid);
  290. }
  291. this.http.uploadFile('/document/uploadDocument', form , res => {
  292. this.upLoading = false;
  293. this.$refs.upload.clearFiles();
  294. if (res.code == "ok") {
  295. this.$message({
  296. message: "上传成功",
  297. type: 'success'
  298. });
  299. this.getList();
  300. this.getRecentList();
  301. } else {
  302. this.$message({
  303. message: res.msg,
  304. type: 'error'
  305. });
  306. }
  307. }, error => {
  308. this.upLoading = false;
  309. this.$refs.upload.clearFiles();
  310. this.$message({
  311. message: error,
  312. type: 'error'
  313. });
  314. })
  315. },
  316. //下载
  317. dowloadFile(row) {
  318. this.http.post(this.port.project.dowloadFile, {
  319. id: row.id
  320. } , res => {
  321. this.getOperList();
  322. }, error => {
  323. })
  324. },
  325. //获取近期文件
  326. getRecentList() {
  327. this.http.post('/document/recentlyList', {
  328. projectId: this.curProjectId,
  329. },
  330. res => {
  331. if (res.code == "ok") {
  332. this.recentFiles = res.data;
  333. } else {
  334. this.$message({
  335. message: res.msg,
  336. type: "error"
  337. });
  338. }
  339. },
  340. error => {
  341. this.$message({
  342. message: error,
  343. type: "error"
  344. });
  345. });
  346. },
  347. getUsers() {
  348. this.http.post(this.port.manage.list, {
  349. departmentId: -1,
  350. pageIndex: 1,
  351. pageSize: 99999
  352. },
  353. res => {
  354. if (res.code == "ok") {
  355. this.users = res.data.records;
  356. } else {
  357. this.$message({
  358. message: res.msg,
  359. type: "error"
  360. });
  361. }
  362. },
  363. error => {
  364. this.$message({
  365. message: error,
  366. type: "error"
  367. });
  368. });
  369. },
  370. //获取列表
  371. getList() {
  372. this.listLoading = true;
  373. this.http.post('/document/allList', {
  374. projectId: this.curProjectId,
  375. parentFid: this.parentFid
  376. },
  377. res => {
  378. this.listLoading = false;
  379. if (res.code == "ok") {
  380. this.list = res.data;
  381. } else {
  382. this.$message({
  383. message: res.msg,
  384. type: "error"
  385. });
  386. }
  387. },
  388. error => {
  389. this.listLoading = false;
  390. this.$message({
  391. message: error,
  392. type: "error"
  393. });
  394. });
  395. },
  396. refreshPage() {
  397. this.curProjectId = parseInt(this.$route.params.id);
  398. this.getRecentList();
  399. this.getList();
  400. }
  401. },
  402. created() {
  403. console.log('created===');
  404. let height = window.innerHeight;
  405. this.tableHeight = height - 190;
  406. const that = this;
  407. window.onresize = function temp() {
  408. that.tableHeight = window.innerHeight - 190;
  409. };
  410. },
  411. mounted() {
  412. console.log('mounted===');
  413. this.curProjectId = parseInt(this.$route.params.id);
  414. this.getRecentList();
  415. this.getList();
  416. this.getUsers();
  417. }
  418. };
  419. </script>