main.vue 8.0 KB

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