list.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div>
  3. <div class="flex-align-center flex-between border-bottom container normal-panel">
  4. <div class="flex-align-center">
  5. <slot name="upload"></slot>
  6. </div>
  7. <div class="flex-align-center">
  8. <el-input size="small" style="width:160px;margin-right:16px" prefix-icon="el-icon-search" v-model="params.content.where.condition" @keyup.enter.native="queryAttachment(params.content.pageNumber = 1)" @clear="queryAttachment(params.content.pageNumber = 1)" placeholder="搜索全部" clearable></el-input>
  9. <sort :sort="sort" @onSort="onSort"></sort>
  10. <i class="el-icon-refresh" style="margin-left:16px" @click="queryAttachment(params.content.where.condition = '')"></i>
  11. </div>
  12. </div>
  13. <div ref="ele" style="height:calc(100vh - 405px);overflow-y:scroll" class="container normal-panel">
  14. <el-row :gutter="10" class="folder-list">
  15. <el-col :span="3" v-for="folder in list" :key="folder.id">
  16. <div class="folder-item" :class="folder.ischeck?'checked':''">
  17. <el-checkbox v-show="folder.postfix !== 'FOLDER'" class="folder-checkbox" v-model="folder.ischeck" @change="onChange(folder)"></el-checkbox>
  18. <div @click.stop="folderDetails(folder)" class="img-panel">
  19. <img v-if="folder.postfix === 'DOC' || folder.postfix === 'DOCX'" src="../../../assets/file_icons/word.png" alt="">
  20. <img v-else-if="folder.postfix === 'PDF'" src="../../../assets/file_icons/PDF.png" alt="">
  21. <img v-else-if="folder.postfix === 'MP4' || folder.postfix === 'AVI'" src="../../../assets/file_icons/video.png" alt="">
  22. <img v-else-if="folder.postfix === 'XLS' || folder.postfix === 'XLSX'" src="../../../assets/file_icons/excel.png" alt="">
  23. <img v-else-if="folder.postfix === 'PNG' || folder.postfix === 'JPG'|| folder.postfix === 'JPEG'" src="../../../assets/file_icons/image.png" alt="">
  24. <img v-else-if="folder.postfix === 'PPT' || folder.postfix === 'PPTX'" src="../../../assets/file_icons/PPT.png" alt="">
  25. <img v-else-if="folder.postfix === 'FOLDER'" src="../../../assets/file_icons/folder.png" alt="">
  26. <img v-else src="../../../assets/file_icons/unknow.png" alt="">
  27. </div>
  28. <input v-if="folder.newfolder" type="text" v-model="folder.document" autofocus size="mini" @blur="changeFolderName(folder)">
  29. <p v-else>{{folder.document}}</p>
  30. </div>
  31. </el-col>
  32. </el-row>
  33. <div v-if="list.length === 0" class="flex-align-center" style="height:calc(100vh - 200px);justify-content:space-around">
  34. <el-empty description="暂无文件,请点击左上角的“上传”按钮添加"></el-empty>
  35. </div>
  36. </div>
  37. <div style="margin:16px 0;text-align:right">
  38. <el-pagination
  39. background
  40. small
  41. @size-change="handleSizeChange"
  42. @current-change="handleCurrentChange"
  43. :current-page="currentPage"
  44. :page-size="params.content.pageSize"
  45. layout="total, prev, pager, next, jumper"
  46. :total="total">
  47. </el-pagination>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. export default {
  53. props:['accept'],
  54. data () {
  55. return {
  56. params:{
  57. "classname": "system.attachment.MediaCenter",
  58. "method": "queryAttachment",
  59. "content": {
  60. "pageNumber": 1,
  61. "pageSize": 20,
  62. "where": {
  63. "condition":"",
  64. "parentid":''
  65. }
  66. }
  67. },
  68. list:[],
  69. sort:[],
  70. total:0,
  71. currentPage:0,
  72. }
  73. },
  74. methods:{
  75. // 排序
  76. onSort (sort) {
  77. this.params.content.sort = [sort]
  78. this.queryAttachment(this.params.content.where.parentid)
  79. },
  80. async queryAttachment (id) {
  81. this.params.content.where.parentid = id?id:0
  82. this.params.content.where.postfixs = this.accept?this.accept.split(","):[]
  83. const res = await this.$api.requested(this.params)
  84. res.data.map(e=>{
  85. e.postfix = e.postfix.toUpperCase()
  86. e.ischeck = false
  87. })
  88. this.list = res.data
  89. this.total = res.total
  90. this.currentPage = res.pageNumber
  91. this.sort = res.sort
  92. },
  93. handleSizeChange(val) {
  94. // console.log(`每页 ${val} 条`);
  95. this.params.content.pageSize = val
  96. this.queryAttachment(this.params.content.where.parentid)
  97. },
  98. handleCurrentChange(val) {
  99. // console.log(`当前页: ${val}`);
  100. this.params.content.pageNumber = val
  101. this.queryAttachment(this.params.content.where.parentid)
  102. },
  103. changeFolderName (folder) {
  104. this.$emit('onNameChange',folder)
  105. },
  106. onChange (folder) {
  107. let checkArray = []
  108. this.list.forEach((e,index)=>{
  109. if (e.ischeck === true) {
  110. checkArray.push(e)
  111. }
  112. })
  113. this.$emit('folderChecked',checkArray)
  114. },
  115. async folderDetails (folder) {
  116. event.stopPropagation();
  117. if (folder.postfix === 'FOLDER') {
  118. this.$emit('toFolderDetail',folder.attachmentid)
  119. }
  120. },
  121. restChecked () {
  122. this.list.forEach((e,index)=>{
  123. e.ischeck = false
  124. })
  125. }
  126. },
  127. mounted () {
  128. // 根据容器高度计算需要的数据条数
  129. var heightCss = window.getComputedStyle(this.$refs.ele).height
  130. this.params.content.pageSize = Math.ceil((heightCss.match(/\d+/g) / 114)) *12
  131. this.queryAttachment()
  132. },
  133. watch:{
  134. $route () {
  135. this.queryAttachment()
  136. // 路由发生变化的时候初始化选择数组
  137. this.$emit('folderChecked',[])
  138. }
  139. }
  140. }
  141. </script>
  142. <style>
  143. .folder-item {
  144. position: relative;
  145. padding:10px 5px;
  146. text-align: center;
  147. color:#333;
  148. margin-bottom: 15px;
  149. cursor: pointer;
  150. font-size: 14px;
  151. /* min-height: 110px; */
  152. }
  153. .folder-item p{
  154. line-height: 25px;
  155. width: calc(100% - 20px);
  156. padding: 0 10px;
  157. /* margin-top:10px; */
  158. word-break: break-all;
  159. text-overflow: ellipsis;
  160. display: -webkit-box;
  161. -webkit-box-orient: vertical;
  162. -webkit-line-clamp: 1; /* 这里是超出几行省略 */
  163. overflow: hidden;
  164. }
  165. .folder-item input{
  166. width: calc(100% - 8px);
  167. padding: 2px;
  168. margin-top:10px;
  169. }
  170. .img-panel {
  171. width: 64px;
  172. /* height: 64px; */
  173. margin:0 auto;
  174. text-align: center;
  175. }
  176. .img-panel > img{
  177. width: 80%;
  178. }
  179. .folder-checkbox{
  180. display: none;
  181. position: absolute;
  182. top:10px;
  183. left: 10px;
  184. }
  185. .checked{
  186. background: #f1f2f3;
  187. border-radius: 3px;
  188. }
  189. .checked .folder-checkbox {
  190. display: block;
  191. }
  192. .folder-item:hover .folder-checkbox {
  193. display: block;
  194. }
  195. .folder-item:hover {
  196. background: #f1f2f3;
  197. border-radius: 3px;
  198. }
  199. </style>
  200. <style scoped>
  201. .border-bottom{
  202. border-bottom: 1px solid #f1f2f3;
  203. }
  204. </style>