files.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <template>
  2. <drawer-tabs-container>
  3. <div class="project-task-file">
  4. <!-- 搜索 -->
  5. <Row v-if="!simple" class="sreachBox">
  6. <div class="item">
  7. <div class="item-2">
  8. <sreachTitle :val="keys.name">{{$L('文件名')}}</sreachTitle>
  9. <Input v-model="keys.name" :placeholder="$L('关键词')"/>
  10. </div>
  11. <div class="item-2">
  12. <sreachTitle :val="keys.username">{{$L('上传者')}}</sreachTitle>
  13. <Input v-model="keys.username" :placeholder="$L('用户名')"/>
  14. </div>
  15. </div>
  16. <div class="item item-button">
  17. <Button type="text" v-if="$A.objImplode(keys)!=''" @click="sreachTab(true)">{{$L('取消筛选')}}</Button>
  18. <Button type="primary" icon="md-search" :loading="loadIng > 0" @click="sreachTab">{{$L('搜索')}}</Button>
  19. </div>
  20. </Row>
  21. <!-- 按钮 -->
  22. <Row class="butBox" :style="`float:left;margin-top:-32px;${simple?'display:none':''}`">
  23. <Upload
  24. name="files"
  25. ref="upload"
  26. :action="actionUrl"
  27. :data="params"
  28. multiple
  29. :format="uploadFormat"
  30. :show-upload-list="false"
  31. :max-size="maxSize"
  32. :on-success="handleSuccess"
  33. :on-error="handleError"
  34. :on-format-error="handleFormatError"
  35. :on-exceeded-size="handleMaxSize"
  36. :before-upload="handleBeforeUpload">
  37. <Button :loading="loadIng > 0" type="primary" icon="ios-cloud-upload-outline" @click="">{{$L('上传文件')}}</Button>
  38. </Upload>
  39. </Row>
  40. <!-- 列表 -->
  41. <Table class="tableFill" ref="tableRef" :size="!simple?'default':'small'" :columns="columns" :data="lists" :loading="loadIng > 0" :no-data-text="noDataText" @on-sort-change="sortChange" stripe></Table>
  42. <!-- 分页 -->
  43. <Page v-if="lastPage > 1 || !simple" :simple="simple || windowMax768" class="pageBox" :total="listTotal" :current="listPage" :disabled="loadIng > 0" @on-change="setPage" @on-page-size-change="setPageSize" :page-size-opts="[10,20,30,50,100]" placement="top" show-elevator show-sizer show-total transfer></Page>
  44. </div>
  45. </drawer-tabs-container>
  46. </template>
  47. <style lang="scss" scoped>
  48. .project-task-file {
  49. margin: 0 12px;
  50. .tableFill {
  51. margin: 12px 0 20px;
  52. }
  53. }
  54. </style>
  55. <script>
  56. import Vue from 'vue'
  57. import VueClipboard from 'vue-clipboard2'
  58. import DrawerTabsContainer from "../../DrawerTabsContainer";
  59. Vue.use(VueClipboard)
  60. export default {
  61. name: 'ProjectTaskFiles',
  62. components: {DrawerTabsContainer},
  63. props: {
  64. projectid: {
  65. default: 0
  66. },
  67. taskid: {
  68. default: 0
  69. },
  70. canload: {
  71. type: Boolean,
  72. default: true
  73. },
  74. simple: {
  75. type: Boolean,
  76. default: false
  77. },
  78. },
  79. data() {
  80. return {
  81. keys: {},
  82. sorts: {key:'', order:''},
  83. loadYet: false,
  84. loadIng: 0,
  85. columns: [],
  86. lists: [],
  87. listPage: 1,
  88. listTotal: 0,
  89. lastPage: 0,
  90. noDataText: "",
  91. uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'],
  92. actionUrl: $A.apiUrl('project/files/upload'),
  93. params: {
  94. token: $A.getToken(),
  95. taskid: this.taskid,
  96. projectid: this.projectid
  97. },
  98. uploadList: [],
  99. maxSize: 204800
  100. }
  101. },
  102. mounted() {
  103. if (this.canload) {
  104. this.loadYet = true;
  105. this.getLists(true);
  106. }
  107. this.uploadList = this.$refs.upload.fileList;
  108. },
  109. watch: {
  110. projectid(val) {
  111. if (this.loadYet) {
  112. this.getLists(true);
  113. }
  114. this.$set(this.params, 'projectid', val);
  115. },
  116. taskid(val) {
  117. if (this.loadYet) {
  118. this.getLists(true);
  119. }
  120. this.$set(this.params, 'taskid', val);
  121. },
  122. canload(val) {
  123. if (val && !this.loadYet) {
  124. this.loadYet = true;
  125. this.getLists(true);
  126. }
  127. },
  128. uploadList(files) {
  129. files.forEach((file) => {
  130. if (typeof file.username === "undefined") {
  131. file.username = this.usrName;
  132. file.indate = Math.round(new Date().getTime()/1000);
  133. this.lists.unshift(file);
  134. this.$emit('change', 'up');
  135. }
  136. });
  137. }
  138. },
  139. methods: {
  140. initLanguage() {
  141. this.noDataText = this.$L("数据加载中.....");
  142. let columns = [];
  143. columns.push({
  144. "title": "",
  145. "width": 60,
  146. render: (h, params) => {
  147. if (!params.row.thumb) {
  148. return h('WLoading', {
  149. style: {
  150. width: "24px",
  151. height: "24px",
  152. verticalAlign: "middle",
  153. },
  154. });
  155. }
  156. let imgRender = h('img', {
  157. style: {
  158. width: "28px",
  159. height: "28px",
  160. display: "table"
  161. },
  162. attrs: {
  163. src: params.row.thumb
  164. },
  165. });
  166. if (['jpg', 'jpeg', 'png', 'gif'].indexOf(params.row.ext) !== -1) {
  167. return h('Tooltip', {
  168. props: {
  169. transfer: true,
  170. delay: 600,
  171. maxWidth: 600
  172. },
  173. }, [imgRender, h('div', {slot: 'content'}, [h('img', {
  174. style: {
  175. maxWidth: "360px",
  176. maxHeight: "360px",
  177. display: "table",
  178. margin: "3px 0"
  179. },
  180. attrs: {
  181. src: params.row.path
  182. },
  183. })])]);
  184. } else {
  185. return imgRender;
  186. }
  187. }
  188. });
  189. columns.push({
  190. "title": this.$L("文件名"),
  191. "key": 'name',
  192. "minWidth": 100,
  193. "tooltip": true,
  194. "sortable": true,
  195. render: (h, params) => {
  196. let arr = [h('span', params.row.name)];
  197. if (params.row.showProgress === true) {
  198. arr.push(h('Progress', {
  199. style: {
  200. display: 'block',
  201. marginTop: '-3px'
  202. },
  203. props: {
  204. percent: parseFloat($A.runNum(params.row.percentage || 100, 2)),
  205. },
  206. }));
  207. }
  208. return h('div', arr);
  209. },
  210. });
  211. columns.push({
  212. "title": this.$L("大小"),
  213. "key": 'size',
  214. "minWidth": 90,
  215. "maxWidth": 120,
  216. "align": "right",
  217. "sortable": true,
  218. render: (h, params) => {
  219. return h('span', $A.bytesToSize(params.row.size));
  220. },
  221. });
  222. if (!this.simple) {
  223. columns.push({
  224. "title": this.$L("下载次数"),
  225. "key": 'download',
  226. "align": "center",
  227. "sortable": true,
  228. "width": 100,
  229. });
  230. columns.push({
  231. "title": this.$L("上传者"),
  232. "key": 'username',
  233. "minWidth": 90,
  234. "maxWidth": 130,
  235. "sortable": true,
  236. render: (h, params) => {
  237. return h('UserView', {
  238. props: {
  239. username: params.row.username
  240. }
  241. });
  242. }
  243. });
  244. columns.push({
  245. "title": this.$L("上传时间"),
  246. "key": 'indate',
  247. "width": 160,
  248. "sortable": true,
  249. render: (h, params) => {
  250. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  251. }
  252. });
  253. }
  254. columns.push({
  255. "title": " ",
  256. "key": 'action',
  257. "align": 'right',
  258. "width": 120,
  259. render: (h, params) => {
  260. if (!params.row.id) {
  261. return null;
  262. }
  263. return h('div', [
  264. h('Tooltip', {
  265. props: { content: this.$L('下载'), transfer: true, delay: 600 },
  266. style: { position: 'relative' },
  267. }, [h('Icon', {
  268. props: { type: 'md-arrow-down', size: 16 },
  269. style: { margin: '0 3px', cursor: 'pointer' },
  270. }), h('a', {
  271. style: { position: 'absolute', top: '0', left: '0', right: '0', bottom: '0', 'zIndex': 1 },
  272. attrs: { href: $A.apiUrl('project/files/download?fileid=' + params.row.id), target: '_blank' },
  273. on: {
  274. click: () => {
  275. if (params.row.yetdown) {
  276. return;
  277. }
  278. params.row.yetdown = 1;
  279. this.$set(params.row, 'download', params.row.download + 1);
  280. }
  281. }
  282. })]),
  283. h('Tooltip', {
  284. props: { content: this.$L('重命名'), transfer: true, delay: 600 }
  285. }, [h('Icon', {
  286. props: { type: 'md-create', size: 16 },
  287. style: { margin: '0 3px', cursor: 'pointer' },
  288. on: {
  289. click: () => {
  290. this.renameFile(params.row);
  291. }
  292. }
  293. })]),
  294. h('Tooltip', {
  295. props: { content: this.$L('复制链接'), transfer: true, delay: 600 }
  296. }, [h('Icon', {
  297. props: { type: 'md-link', size: 16 },
  298. style: { margin: '0 3px', cursor: 'pointer', transform: 'rotate(-45deg)' },
  299. on: {
  300. click: () => {
  301. this.$copyText($A.apiUrl('project/files/download?fileid=' + params.row.id)).then(() => {
  302. this.$Message.success(this.$L('复制成功!'));
  303. }, () => {
  304. this.$Message.error(this.$L('复制失败!'));
  305. });
  306. }
  307. }
  308. })]),
  309. h('Tooltip', {
  310. props: { content: this.$L('删除'), transfer: true, delay: 600 }
  311. }, [h('Icon', {
  312. props: { type: 'md-trash', size: 16 },
  313. style: { margin: '0 3px', cursor: 'pointer' },
  314. on: {
  315. click: () => {
  316. this.deleteFile(params.row);
  317. }
  318. }
  319. })]),
  320. ]);
  321. }
  322. });
  323. this.columns = columns;
  324. },
  325. sreachTab(clear) {
  326. if (clear === true) {
  327. this.keys = {};
  328. }
  329. this.getLists(true);
  330. },
  331. sortChange(info) {
  332. this.sorts = {key:info.key, order:info.order};
  333. this.getLists(true);
  334. },
  335. setPage(page) {
  336. this.listPage = page;
  337. this.getLists();
  338. },
  339. setPageSize(size) {
  340. if (Math.max($A.runNum(this.listPageSize), 10) != size) {
  341. this.listPageSize = size;
  342. this.getLists();
  343. }
  344. },
  345. getLists(resetLoad) {
  346. if (resetLoad === true) {
  347. this.listPage = 1;
  348. }
  349. if (this.projectid == 0 && this.taskid == 0) {
  350. this.lists = [];
  351. this.listTotal = 0;
  352. this.noDataText = this.$L("没有相关的文件");
  353. return;
  354. }
  355. this.loadIng++;
  356. let whereData = $A.cloneData(this.keys);
  357. whereData.page = Math.max(this.listPage, 1);
  358. whereData.pagesize = Math.max($A.runNum(this.listPageSize), 10);
  359. whereData.projectid = this.projectid;
  360. whereData.taskid = this.taskid;
  361. whereData.sorts = this.sorts;
  362. this.noDataText = this.$L("数据加载中.....");
  363. $A.apiAjax({
  364. url: 'project/files/lists',
  365. data: whereData,
  366. complete: () => {
  367. this.loadIng--;
  368. },
  369. error: () => {
  370. this.noDataText = this.$L("数据加载失败!");
  371. },
  372. success: (res) => {
  373. if (res.ret === 1) {
  374. this.lists = res.data.lists;
  375. this.listTotal = res.data.total;
  376. this.lastPage = res.data.lastPage;
  377. this.noDataText = this.$L("没有相关的文件");
  378. } else {
  379. this.lists = [];
  380. this.listTotal = 0;
  381. this.lastPage = 0;
  382. this.noDataText = res.msg;
  383. }
  384. }
  385. });
  386. },
  387. renameFile(item) {
  388. this.renameValue = "";
  389. this.$Modal.confirm({
  390. render: (h) => {
  391. return h('div', [
  392. h('div', {
  393. style: {
  394. fontSize: '16px',
  395. fontWeight: '500',
  396. marginBottom: '20px',
  397. }
  398. }, this.$L('重命名文件名')),
  399. h('Input', {
  400. props: {
  401. value: this.renameValue,
  402. autofocus: true,
  403. placeholder: item.name || this.$L('请输入新的文件名称')
  404. },
  405. on: {
  406. input: (val) => {
  407. this.renameValue = val;
  408. }
  409. }
  410. })
  411. ])
  412. },
  413. loading: true,
  414. onOk: () => {
  415. if (this.renameValue) {
  416. let oldName = item.name;
  417. let newName = this.renameValue;
  418. if (!$A.rightExists(newName, '.' + item.ext)) {
  419. newName += '.' + item.ext;
  420. }
  421. this.$set(item, 'name', newName);
  422. $A.apiAjax({
  423. url: 'project/files/rename',
  424. data: {
  425. fileid: item.id,
  426. name: newName,
  427. },
  428. error: () => {
  429. this.$Modal.remove();
  430. this.$set(item, 'name', oldName);
  431. alert(this.$L('网络繁忙,请稍后再试!'));
  432. },
  433. success: (res) => {
  434. this.$Modal.remove();
  435. if (res.ret === 1) {
  436. this.$set(item, 'name', res.data.name);
  437. } else {
  438. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  439. this.$set(item, 'name', oldName);
  440. }
  441. }
  442. });
  443. } else {
  444. this.$Modal.remove();
  445. }
  446. },
  447. });
  448. },
  449. deleteFile(item) {
  450. this.$Modal.confirm({
  451. title: this.$L('删除文件'),
  452. content: this.$L('你确定要删除此文件吗?'),
  453. loading: true,
  454. onOk: () => {
  455. $A.apiAjax({
  456. url: 'project/files/delete',
  457. data: {
  458. fileid: item.id,
  459. },
  460. error: () => {
  461. this.$Modal.remove();
  462. alert(this.$L('网络繁忙,请稍后再试!'));
  463. },
  464. success: (res) => {
  465. this.$Modal.remove();
  466. this.lists.some((temp, index) => {
  467. if (temp.id == item.id) {
  468. this.lists.splice(index, 1);
  469. return true;
  470. }
  471. });
  472. setTimeout(() => {
  473. if (res.ret === 1) {
  474. this.$Message.success(res.msg);
  475. this.$emit('change', 'delete');
  476. } else {
  477. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  478. }
  479. }, 350);
  480. }
  481. });
  482. }
  483. });
  484. },
  485. uploadHandleClick() {
  486. this.$refs.upload.handleClick();
  487. },
  488. handleError (error, html, file) {
  489. //上传失败
  490. this.$Modal.warning({
  491. title: this.$L('上传失败'),
  492. content: this.$L('文件 % 上传失败,%', file.name, error)
  493. });
  494. this.$refs.upload.fileList.pop();
  495. this.lists.some((item, index) => {
  496. if (item.uid == file.uid) {
  497. this.lists.splice(index, 1);
  498. return true;
  499. }
  500. });
  501. this.$emit('change', 'error');
  502. },
  503. handleSuccess (res, file) {
  504. //上传完成
  505. if (res.ret === 1) {
  506. for (let key in res.data) {
  507. if (res.data.hasOwnProperty(key)) {
  508. file[key] = res.data[key];
  509. }
  510. }
  511. this.$emit('change', 'add');
  512. } else {
  513. this.$Modal.warning({
  514. title: this.$L('上传失败'),
  515. content: this.$L('文件 % 上传失败,%', file.name, res.msg)
  516. });
  517. this.$refs.upload.fileList.pop();
  518. this.lists.some((item, index) => {
  519. if (item.id == res.id) {
  520. this.lists.splice(index, 1);
  521. return true;
  522. }
  523. });
  524. this.$emit('change', 'error');
  525. }
  526. this.uploadList = this.$refs.upload.fileList;
  527. },
  528. handleFormatError (file) {
  529. //上传类型错误
  530. this.$Modal.warning({
  531. title: this.$L('文件格式不正确'),
  532. content: this.$L('文件 % 格式不正确,仅支持上传:%', file.name, this.uploadFormat.join(','))
  533. });
  534. },
  535. handleMaxSize (file) {
  536. //上传大小错误
  537. this.$Modal.warning({
  538. title: this.$L('超出文件大小限制'),
  539. content: this.$L('文件 % 太大,不能超过%。', file.name, $A.bytesToSize(this.maxSize * 1024))
  540. });
  541. },
  542. handleBeforeUpload () {
  543. //上传前判断
  544. this.params = {
  545. token: $A.getToken(),
  546. taskid: this.taskid,
  547. projectid: this.projectid
  548. };
  549. return true;
  550. },
  551. upload(file) {
  552. //手动传file
  553. if (this.handleBeforeUpload()) {
  554. this.$refs.upload.upload(file);
  555. }
  556. },
  557. }
  558. }
  559. </script>