fileCenter.vue 18 KB

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