main.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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,
  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. getPage() {
  150. this.loading = true
  151. if (this.objData.type === 'news' && this.newsType === '1') { // 【图文】+ 【已发布】
  152. this.getFreePublishPage();
  153. } else if (this.objData.type === 'news' && this.newsType === '2') { // 【图文】+ 【草稿】
  154. this.getDraftPage();
  155. } else { // 【素材】
  156. this.getMaterialPage();
  157. }
  158. },
  159. getMaterialPage() {
  160. getMaterialPage({
  161. ...this.queryParams,
  162. type: this.objData.type
  163. }).then(response => {
  164. this.list = response.data.list
  165. this.total = response.data.total
  166. }).finally(() => {
  167. this.loading = false
  168. })
  169. },
  170. getFreePublishPage() {
  171. getFreePublishPage(this.queryParams).then(response => {
  172. // 将 thumbUrl 转成 picUrl,保证 wx-news 组件可以预览封面
  173. response.data.list.forEach(item => {
  174. const newsItem = item.content.newsItem;
  175. newsItem.forEach(article => {
  176. article.picUrl = article.thumbUrl;
  177. })
  178. })
  179. this.list = response.data.list
  180. this.total = response.data.total
  181. }).finally(() => {
  182. this.loading = false
  183. })
  184. },
  185. getDraftPage() {
  186. getDraftPage((this.queryParams)).then(response => {
  187. // 将 thumbUrl 转成 picUrl,保证 wx-news 组件可以预览封面
  188. response.data.list.forEach(item => {
  189. const newsItem = item.content.newsItem;
  190. newsItem.forEach(article => {
  191. article.picUrl = article.thumbUrl;
  192. })
  193. })
  194. this.list = response.data.list
  195. this.total = response.data.total
  196. }).finally(() => {
  197. this.loading = false
  198. })
  199. }
  200. }
  201. };
  202. </script>
  203. <style lang="scss" scoped>
  204. /*瀑布流样式*/
  205. .waterfall {
  206. width: 100%;
  207. column-gap:10px;
  208. column-count: 5;
  209. margin: 0 auto;
  210. }
  211. .waterfall-item {
  212. padding: 10px;
  213. margin-bottom: 10px;
  214. break-inside: avoid;
  215. border: 1px solid #eaeaea;
  216. }
  217. .material-img {
  218. width: 100%;
  219. }
  220. p {
  221. line-height: 30px;
  222. }
  223. @media (min-width: 992px) and (max-width: 1300px) {
  224. .waterfall {
  225. column-count: 3;
  226. }
  227. p {
  228. color:red;
  229. }
  230. }
  231. @media (min-width: 768px) and (max-width: 991px) {
  232. .waterfall {
  233. column-count: 2;
  234. }
  235. p {
  236. color: orange;
  237. }
  238. }
  239. @media (max-width: 767px) {
  240. .waterfall {
  241. column-count: 1;
  242. }
  243. }
  244. /*瀑布流样式*/
  245. </style>