main.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!--
  2. - Copyright (C) 2018-2019
  3. - All rights reserved, Designed By www.joolun.com
  4. 芋道源码:
  5. ① 移除 avue 组件,使用 ElementUI 原生组件
  6. -->
  7. <template>
  8. <div class="pb-30px">
  9. <!-- 类型:image -->
  10. <div v-if="props.type === 'image'">
  11. <div class="waterfall" v-loading="loading">
  12. <div class="waterfall-item" v-for="item in list" :key="item.mediaId">
  13. <img class="material-img" :src="item.url" />
  14. <p class="item-name">{{ item.name }}</p>
  15. <el-row class="ope-row">
  16. <el-button type="success" @click="selectMaterialFun(item)">
  17. 选择
  18. <Icon icon="ep:circle-check" />
  19. </el-button>
  20. </el-row>
  21. </div>
  22. </div>
  23. <!-- 分页组件 -->
  24. <Pagination
  25. :total="total"
  26. v-model:page="queryParams.pageNo"
  27. v-model:limit="queryParams.pageSize"
  28. @pagination="getMaterialPageFun"
  29. />
  30. </div>
  31. <!-- 类型:voice -->
  32. <div v-else-if="props.type === 'voice'">
  33. <!-- 列表 -->
  34. <el-table v-loading="loading" :data="list">
  35. <el-table-column label="编号" align="center" prop="mediaId" />
  36. <el-table-column label="文件名" align="center" prop="name" />
  37. <el-table-column label="语音" align="center">
  38. <template #default="scope">
  39. <WxVoicePlayer :url="scope.row.url" />
  40. </template>
  41. </el-table-column>
  42. <el-table-column
  43. label="上传时间"
  44. align="center"
  45. prop="createTime"
  46. width="180"
  47. :formatter="dateFormatter"
  48. />
  49. <el-table-column label="操作" align="center" fixed="right">
  50. <template #default="scope">
  51. <el-button type="primary" link @click="selectMaterialFun(scope.row)"
  52. >选择
  53. <Icon icon="ep:plus" />
  54. </el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <!-- 分页组件 -->
  59. <Pagination
  60. :total="total"
  61. v-model:page="queryParams.pageNo"
  62. v-model:limit="queryParams.pageSize"
  63. @pagination="getPage"
  64. />
  65. </div>
  66. <!-- 类型:video -->
  67. <div v-else-if="props.type === 'video'">
  68. <!-- 列表 -->
  69. <el-table v-loading="loading" :data="list">
  70. <el-table-column label="编号" align="center" prop="mediaId" />
  71. <el-table-column label="文件名" align="center" prop="name" />
  72. <el-table-column label="标题" align="center" prop="title" />
  73. <el-table-column label="介绍" align="center" prop="introduction" />
  74. <el-table-column label="视频" align="center">
  75. <template #default="scope">
  76. <WxVideoPlayer :url="scope.row.url" />
  77. </template>
  78. </el-table-column>
  79. <el-table-column
  80. label="上传时间"
  81. align="center"
  82. prop="createTime"
  83. width="180"
  84. :formatter="dateFormatter"
  85. />
  86. <el-table-column
  87. label="操作"
  88. align="center"
  89. fixed="right"
  90. class-name="small-padding fixed-width"
  91. >
  92. <template #default="scope">
  93. <el-button type="primary" link @click="selectMaterialFun(scope.row)"
  94. >选择
  95. <Icon icon="akar-icons:circle-plus" />
  96. </el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <!-- 分页组件 -->
  101. <Pagination
  102. :total="total"
  103. v-model:page="queryParams.pageNo"
  104. v-model:limit="queryParams.pageSize"
  105. @pagination="getMaterialPageFun"
  106. />
  107. </div>
  108. <!-- 类型:news -->
  109. <div v-else-if="props.type === 'news'">
  110. <div class="waterfall" v-loading="loading">
  111. <div class="waterfall-item" v-for="item in list" :key="item.mediaId">
  112. <div v-if="item.content && item.content.newsItem">
  113. <WxNews :articles="item.content.newsItem" />
  114. <el-row class="ope-row">
  115. <el-button type="success" @click="selectMaterialFun(item)">
  116. 选择
  117. <Icon icon="ep:circle-check" />
  118. </el-button>
  119. </el-row>
  120. </div>
  121. </div>
  122. </div>
  123. <!-- 分页组件 -->
  124. <Pagination
  125. :total="total"
  126. v-model:page="queryParams.pageNo"
  127. v-model:limit="queryParams.pageSize"
  128. @pagination="getMaterialPageFun"
  129. />
  130. </div>
  131. </div>
  132. </template>
  133. <script lang="ts" setup name="WxMaterialSelect">
  134. import WxNews from '@/views/mp/components/wx-news'
  135. import WxVoicePlayer from '@/views/mp/components/wx-voice-play'
  136. import WxVideoPlayer from '@/views/mp/components/wx-video-play'
  137. import { NewsType } from './types'
  138. import * as MpMaterialApi from '@/api/mp/material'
  139. import * as MpFreePublishApi from '@/api/mp/freePublish'
  140. import * as MpDraftApi from '@/api/mp/draft'
  141. import { dateFormatter } from '@/utils/formatTime'
  142. const props = withDefaults(
  143. defineProps<{
  144. type: string
  145. accountId: number
  146. newsType?: NewsType
  147. }>(),
  148. {
  149. newsType: NewsType.Published
  150. }
  151. )
  152. const emit = defineEmits(['select-material'])
  153. // 遮罩层
  154. const loading = ref(false)
  155. // 总条数
  156. const total = ref(0)
  157. // 数据列表
  158. const list = ref<any[]>([])
  159. // 查询参数
  160. const queryParams = reactive({
  161. pageNo: 1,
  162. pageSize: 10,
  163. accountId: props.accountId
  164. })
  165. const selectMaterialFun = (item) => {
  166. emit('select-material', item)
  167. }
  168. const getPage = async () => {
  169. loading.value = true
  170. try {
  171. if (props.type === 'news' && props.newsType === NewsType.Published) {
  172. // 【图文】+ 【已发布】
  173. await getFreePublishPageFun()
  174. } else if (props.type === 'news' && props.newsType === NewsType.Draft) {
  175. // 【图文】+ 【草稿】
  176. await getDraftPageFun()
  177. } else {
  178. // 【素材】
  179. await getMaterialPageFun()
  180. }
  181. } finally {
  182. loading.value = false
  183. }
  184. }
  185. const getMaterialPageFun = async () => {
  186. const data = await MpMaterialApi.getMaterialPage({
  187. ...queryParams,
  188. type: props.type
  189. })
  190. list.value = data.list
  191. total.value = data.total
  192. }
  193. const getFreePublishPageFun = async () => {
  194. const data = await MpFreePublishApi.getFreePublishPage(queryParams)
  195. data.list.forEach((item: any) => {
  196. const articles = item.content.newsItem
  197. articles.forEach((article: any) => {
  198. article.picUrl = article.thumbUrl
  199. })
  200. })
  201. list.value = data.list
  202. total.value = data.total
  203. }
  204. const getDraftPageFun = async () => {
  205. const data = await MpDraftApi.getDraftPage(queryParams)
  206. data.list.forEach((draft: any) => {
  207. const articles = draft.content.newsItem
  208. articles.forEach((article: any) => {
  209. article.picUrl = article.thumbUrl
  210. })
  211. })
  212. list.value = data.list
  213. total.value = data.total
  214. }
  215. onMounted(async () => {
  216. getPage()
  217. })
  218. </script>
  219. <style lang="scss" scoped>
  220. @media (min-width: 992px) and (max-width: 1300px) {
  221. .waterfall {
  222. column-count: 3;
  223. }
  224. p {
  225. color: red;
  226. }
  227. }
  228. @media (min-width: 768px) and (max-width: 991px) {
  229. .waterfall {
  230. column-count: 2;
  231. }
  232. p {
  233. color: orange;
  234. }
  235. }
  236. @media (max-width: 767px) {
  237. .waterfall {
  238. column-count: 1;
  239. }
  240. }
  241. .waterfall {
  242. width: 100%;
  243. column-gap: 10px;
  244. column-count: 5;
  245. margin: 0 auto;
  246. }
  247. .waterfall-item {
  248. padding: 10px;
  249. margin-bottom: 10px;
  250. break-inside: avoid;
  251. border: 1px solid #eaeaea;
  252. }
  253. .material-img {
  254. width: 100%;
  255. }
  256. p {
  257. line-height: 30px;
  258. }
  259. </style>