fileCenter.vue 20 KB

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