files.vue 21 KB

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