SharedList.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div class="body">
  3. <div id="header">
  4. <template v-if="this.selectedRowKeys.length === 0">个人云盘分享链接</template>
  5. <template v-else-if="this.selectedRowKeys.length === 1">
  6. <a-button type="primary" shape="round" icon="paper-clip"
  7. v-clipboard:copy="sharedCopyText"
  8. v-clipboard:success="handleCopyOk"
  9. >复制链接</a-button>
  10. &nbsp;
  11. <a-button type="primary" shape="round" icon="stop" @click="handleCancel">取消分享</a-button>
  12. </template>
  13. <template v-else>
  14. <a-button type="primary" shape="round" icon="stop" @click="handleCancel">取消分享</a-button>
  15. </template>
  16. </div>
  17. <div class="path">全部文件</div>
  18. <a-table
  19. :columns="columns"
  20. :data-source="tableData"
  21. :pagination="false"
  22. :rowKey="(record) => record.key"
  23. :row-selection="{selectedRowKeys:selectedRowKeys,onChange:onSelectChange}"
  24. :customRow="customRowFunc"
  25. >
  26. <template slot="name" slot-scope="text, record">
  27. <a-icon type="appstore"/>&nbsp;&nbsp;{{showName(record)}}
  28. </template>
  29. <template slot="status" slot-scope="text, record">
  30. <span v-if="record.key !== hoverKey">{{showDeadline(record)}}后过期</span>
  31. <div v-else>
  32. <a
  33. v-clipboard:copy="hoverCopyText"
  34. v-clipboard:success="handleCopyOk"
  35. ><a-icon type="paper-clip" />&nbsp;复制链接</a>&nbsp;&nbsp;&nbsp;
  36. <a @click="handleCancelKey"><a-icon type="stop" />&nbsp;取消分享</a>
  37. </div>
  38. </template>
  39. <template slot="looked" slot-scope="text, record">
  40. <span v-if="record.key !== hoverKey">{{text}}</span>
  41. </template>
  42. </a-table>
  43. </div>
  44. </template>
  45. <script>
  46. import moment from 'moment'
  47. import {sharedList,sharedCancel} from "@/api/api"
  48. import {makeSharedLink} from "@/utils/common"
  49. export default {
  50. name: 'sharedlist',
  51. data () {
  52. return {
  53. columns:[
  54. {title:'文件',width:'45%',scopedSlots: { customRender: 'name' }},
  55. {title:'分享时间',width:'20%',dataIndex: 'createTime', customRender: (text) => moment.unix(text).format('YYYY-MM-DD HH:mm:ss')},
  56. {title:'状态', width:'15%',scopedSlots: { customRender: 'status' }},
  57. {title:'浏览次数',dataIndex: 'looked',scopedSlots: { customRender: 'looked' }},
  58. ],
  59. selectedRowKeys:[],
  60. tableData:[],
  61. hoverKey:'',
  62. hoverCopyText:'',
  63. sharedCopyText:'',
  64. }
  65. },
  66. mounted () {
  67. this.getList();
  68. },
  69. methods: {
  70. onSelectChange (selectedRowKeys, selectedRows) {
  71. console.log(selectedRowKeys, selectedRows);
  72. this.selectedRowKeys = selectedRowKeys
  73. this.sharedCopyTextUpdate()
  74. },
  75. sharedCopyTextUpdate(){
  76. if (this.selectedRowKeys.length === 1){
  77. // 分享链接
  78. for (let record of this.tableData){
  79. if (record.key === this.selectedRowKeys[0]){
  80. this.sharedCopyText = makeSharedLink(record.route, record.sharedToken)
  81. break
  82. }
  83. }
  84. }
  85. },
  86. customRowFunc(record){
  87. return {
  88. props: {},
  89. on: { // 事件
  90. click: (event) => {
  91. //console.log(event);
  92. if (event.target.localName === 'a'){
  93. // 阻止事件
  94. return
  95. }
  96. let selectedIdx = this.selectedRowKeys.indexOf(record.key)
  97. if ( selectedIdx === -1 ){
  98. this.selectedRowKeys.push(record.key)
  99. }else{
  100. this.selectedRowKeys.splice(selectedIdx,1)
  101. }
  102. //console.log( selectedIdx ,this.selectedRowKeys,selectedIdx );
  103. this.sharedCopyTextUpdate()
  104. }, // 点击行
  105. dblclick: () => {},
  106. contextmenu: () => {},
  107. mouseenter: () => {
  108. this.hoverKey = record.key
  109. this.hoverCopyText = makeSharedLink(record.route, record.sharedToken)
  110. }, // 鼠标移入行
  111. mouseleave: () => {this.hoverKey = ''}
  112. },
  113. };
  114. },
  115. showName(record){
  116. let name = record.filename[0];
  117. if (record.filename.length > 1){
  118. name += "等"
  119. }
  120. return name
  121. },
  122. showDeadline(record){
  123. let start = moment.unix(record.createTime)
  124. let end = moment.unix(record.deadline)
  125. return end.to(start,true)
  126. },
  127. getList () {
  128. sharedList({}).then(res => {
  129. this.selectedRowKeys = []
  130. this.tableData = []
  131. for (let v in res){
  132. this.tableData.push(res[v]);
  133. }
  134. this.tableData.sort((a,b) =>{
  135. return a.createTime - b.createTime
  136. })
  137. //console.log(this.tableData);
  138. })
  139. },
  140. handleCancel(){
  141. if (this.selectedRowKeys.length == 0){
  142. return
  143. }
  144. sharedCancel({keys:this.selectedRowKeys})
  145. .then(()=>{
  146. this.$message.success(`分享已取消`);
  147. this.getList()
  148. })
  149. },
  150. handleCopyOk(){
  151. this.$message.success(`复制链接成功`);
  152. },
  153. handleCancelKey(){
  154. if (this.hoverKey === ''){
  155. return
  156. }
  157. sharedCancel({keys:[this.hoverKey]})
  158. .then(()=>{
  159. this.$message.success(`分享已取消`);
  160. this.getList()
  161. })
  162. }
  163. }
  164. }
  165. </script>
  166. <style>
  167. .body{
  168. padding:10px 30px;
  169. }
  170. #header{
  171. height:40px;
  172. line-height:40px;
  173. margin-bottom:10px;
  174. }
  175. .path{
  176. margin-bottom:10px;
  177. }
  178. /* 滚动条宽度 */
  179. ::-webkit-scrollbar {
  180. width: 7px;
  181. height: 10px;
  182. }
  183. /* 滚动条的滑块 */
  184. ::-webkit-scrollbar-thumb {
  185. background-color: #a1a3a9;
  186. border-radius: 3px;
  187. }
  188. </style>