fileCenter.vue 19 KB

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