files.vue 22 KB

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