files.vue 18 KB

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