main.vue 7.7 KB

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