main.vue 8.3 KB

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