media.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div class="com-main com-width-1400 com-margin-auto">
  3. <el-breadcrumb separator-class="el-icon-arrow-right">
  4. <el-breadcrumb-item :to="{ path: '/' }">Home</el-breadcrumb-item>
  5. <el-breadcrumb-item> Media Centre</el-breadcrumb-item>
  6. </el-breadcrumb>
  7. <ul class="flex around tab">
  8. <li v-for="(item, index) in list" :key="index" :class="{ active: index === curTab }" @click="selTab(index)">
  9. {{ item.typeName }}
  10. </li>
  11. </ul>
  12. <el-input v-model="keyword" placeholder="Search" @keyup.enter.native="getList" @clear="getList" clearable>
  13. <i slot="suffix" class="el-input__icon el-icon-search" @click="getList"></i>
  14. </el-input>
  15. <div v-if="listLoading" v-loading="true" slot="spinner" element-loading-text="Loading"
  16. element-loading-spinner="el-icon-loading" class="com-loading">
  17. </div>
  18. <div class="item" v-else>
  19. <section v-if="comCurObj.total">
  20. <ul>
  21. <media-card v-for="item in comCurObj.data" :key="item.id" :cardData="item" @labelEvent="receveLabel"
  22. @leftBtnEvent="openDialog(item)"
  23. @rightBtnEvent="download(item)"></media-card>
  24. </ul>
  25. <pagination v-show="comCurObj.total > 0" :total="comCurObj.total" :page.sync="comCurObj.page"
  26. :limit.sync="limit" @pagination="getList" />
  27. </section>
  28. <el-empty description="No Data" v-else></el-empty>
  29. </div>
  30. <el-dialog :lock-scroll="false" :visible.sync="dialogVisible" width="1000px">
  31. <media-card :cardData="cardData" :toggle=true @labelEvent="receveLabel" @rightBtnEvent="download(cardData)"></media-card>
  32. </el-dialog>
  33. </div>
  34. </template>
  35. <script>
  36. import debounce from 'lodash.debounce'
  37. export default {
  38. data() {
  39. return {
  40. list: [
  41. { id: 0, typeName: 'All Content' },
  42. { id: 3, typeName: 'EDM' },
  43. { id: 1, typeName: 'Images' },
  44. { id: 4, typeName: 'Catalogues' },
  45. { id: 8, typeName: 'Email Signature' },
  46. { id: 5, typeName: 'Videos' },
  47. { id: 7, typeName: 'News' },
  48. { id: 2, typeName: 'Social Media' },
  49. { id: 6, typeName: 'New Products Mailer' },
  50. ],
  51. curTab: 0,
  52. keyword: '',
  53. limit: 20,
  54. listLoading: true,
  55. cardData: {},
  56. dialogVisible: false,
  57. getDebList: null,
  58. }
  59. },
  60. async created() {
  61. await this.getList()
  62. this.getDebList = debounce(this.getList, 500);
  63. },
  64. watch: {
  65. keyword(newValue, oldValue) {
  66. if (newValue != oldValue) {
  67. window.scrollTo({ top: 0, behavior: 'smooth' });
  68. this.getDebList()
  69. this.dialogVisible = false;
  70. }
  71. },
  72. },
  73. computed: {
  74. comCurObj() {
  75. return this.list[this.curTab]
  76. }
  77. },
  78. methods: {
  79. getList() {
  80. this.listLoading = true
  81. let params = {
  82. keyword: this.keyword,
  83. page: this.comCurObj.page || 1,
  84. limit: this.limit,
  85. }
  86. this.curTab && (params.type = this.comCurObj?.id)
  87. this.$axios
  88. .get('/api//data/list', {
  89. params
  90. })
  91. .then(res => {
  92. if (res.code == 1) {
  93. const { data, total } = res.result
  94. this.comCurObj.data = data.map(i => {
  95. const mapLabel = i.datalabel.map(o => o.name)
  96. const obj = this.list.find(item => item.id === i.type)
  97. const typeName = this.curTab === 0 ? obj?.typeName : this.comCurObj?.typeName
  98. return { ...i, mapLabel, typeName }
  99. })
  100. this.comCurObj.total = total
  101. this.listLoading = false
  102. }
  103. if (process.client) {
  104. this.$nextTick(() => {
  105. window.scroll(0, 0)
  106. })
  107. }
  108. })
  109. .catch(() => {
  110. this.listLoading = false
  111. })
  112. },
  113. selTab(i) {
  114. this.curTab = i
  115. this.$set(this.comCurObj, 'page', 1)
  116. this.getList()
  117. },
  118. openDialog(data) {
  119. this.cardData = data;
  120. this.dialogVisible = true;
  121. },
  122. download(item) {
  123. if (!item.media_url) {
  124. this.$message.error('No File')
  125. return
  126. }
  127. var urlStr = item.media_url.match('[^/]+(?!.*/)')[0]
  128. this.$utils.downloadXhr(item.media_url, urlStr)
  129. },
  130. receveLabel(l){
  131. this.keyword = l
  132. }
  133. },
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .tab {
  138. margin-bottom: 20px;
  139. border-bottom: 1.5px solid #eee;
  140. overflow-x: auto;
  141. white-space: nowrap;
  142. li {
  143. position: relative;
  144. font-size: 16px;
  145. color: #00213b;
  146. text-align: center;
  147. padding: 0 15px 10px;
  148. cursor: pointer;
  149. &::after {
  150. content: '';
  151. position: absolute;
  152. bottom: 0;
  153. left: 50%;
  154. width: 0;
  155. height: 2px;
  156. background-color: #e90000;
  157. transition: width 0.3s ease, left 0.3s ease;
  158. transform: translateX(-50%);
  159. }
  160. &.active {
  161. font-weight: bold;
  162. }
  163. &.active::after {
  164. width: 100%;
  165. left: 50%;
  166. }
  167. }
  168. }
  169. :deep(.el-input) {
  170. .el-input__inner {
  171. border-radius: 18px;
  172. }
  173. i {
  174. cursor: pointer;
  175. }
  176. }
  177. :deep(.el-dialog__header) {
  178. padding: 0;
  179. .el-dialog__headerbtn {
  180. top: 5px;
  181. right: 5px;
  182. }
  183. }
  184. :deep(.el-dialog__body) {
  185. padding: 20px;
  186. }
  187. .item {
  188. margin: 20px auto;
  189. ul {
  190. width: 100%;
  191. display: grid;
  192. grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  193. grid-gap: 30px;
  194. }
  195. }
  196. :deep(.el-pagination.is-background) {
  197. .el-pager {
  198. li.number {
  199. background-color: #f8f8f8;
  200. border-radius: 50%;
  201. color: #a7a7a7;
  202. }
  203. li:not(.disabled).active {
  204. background-color: #00213b;
  205. color: #d4d7da;
  206. }
  207. }
  208. .btn-prev,
  209. .btn-next {
  210. border-radius: 50%;
  211. background-color: #fff;
  212. .el-icon-arrow-left:before {
  213. content: '';
  214. }
  215. .el-icon-arrow-right:before {
  216. content: '';
  217. }
  218. }
  219. }
  220. </style>