main.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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="getMaterialPage"/>
  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.articles">
  84. <WxNews :objData="item.content.articles"></WxNews>
  85. <el-row class="ope-row">
  86. <el-button size="mini" type="success" @click="selectMaterial(item)">选择<i class="el-icon-circle-check el-icon--right"></i></el-button>
  87. </el-row>
  88. </div>
  89. </div>
  90. <div v-if="list.length <=0 && !loading" class="el-table__empty-block">
  91. <span class="el-table__empty-text">暂无数据</span>
  92. </div>
  93. <span slot="footer" class="dialog-footer">
  94. <el-pagination
  95. @size-change="sizeChange"
  96. :current-page.sync="page.currentPage"
  97. :page-sizes="[10, 20]"
  98. :page-size="page.pageSize"
  99. layout="total, sizes, prev, pager, next, jumper"
  100. :total="page.total"
  101. class="pagination"
  102. >
  103. </el-pagination>
  104. </span>
  105. </div>
  106. </template>
  107. <script>
  108. // import { tableOptionVoice } from '@/const/crud/wxmp/wxmaterial_voice'
  109. // import { tableOptionVideo } from '@/const/crud/wxmp/wxmaterial_video'
  110. import WxNews from '@/views/mp/components/wx-news/main.vue';
  111. import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue';
  112. import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue';
  113. import { getMaterialPage } from "@/api/mp/material";
  114. export default {
  115. name: "wxMaterialSelect",
  116. components: {
  117. WxNews,
  118. WxVoicePlayer,
  119. WxVideoPlayer
  120. },
  121. props: {
  122. objData: {
  123. type: Object,
  124. required: true
  125. },
  126. newsType:{ // 图文类型:1、已发布图文;2、草稿箱图文
  127. type: String,
  128. default: "1"
  129. },
  130. },
  131. data() {
  132. return {
  133. // 遮罩层
  134. loading: false,
  135. // 总条数
  136. total: 0,
  137. // 数据列表
  138. list: [],
  139. // 查询参数
  140. queryParams: {
  141. pageNo: 1,
  142. pageSize: 10,
  143. },
  144. // tableOptionVoice: tableOptionVoice,
  145. // tableOptionVideo: tableOptionVideo,
  146. }
  147. },
  148. created() {
  149. this.getPage(this.page)
  150. },
  151. methods:{
  152. selectMaterial(item){
  153. this.$emit('selectMaterial', item)
  154. },
  155. getPage(page, params) {
  156. this.loading = true
  157. if(this.objData.type == 'news'){ // 【图文】
  158. if(this.newsType == '1'){
  159. getPageNews(Object.assign({
  160. current: page.currentPage,
  161. size: page.pageSize,
  162. appId:this.appId,
  163. }, params)).then(response => {
  164. let tableData = response.data.items
  165. tableData.forEach(item => {
  166. item.mediaId = item.articleId
  167. item.content.articles = item.content.newsItem
  168. })
  169. this.list = tableData
  170. this.page.total = response.data.totalCount
  171. this.page.currentPage = page.currentPage
  172. this.page.pageSize = page.pageSize
  173. this.loading = false
  174. })
  175. }else if(this.newsType == '2'){
  176. getPageNewsDraft(Object.assign({
  177. current: page.currentPage,
  178. size: page.pageSize,
  179. appId:this.appId,
  180. }, params)).then(response => {
  181. let tableData = response.data.items
  182. tableData.forEach(item => {
  183. item.mediaId = item.mediaId
  184. item.content.articles = item.content.newsItem
  185. })
  186. this.list = tableData
  187. this.page.total = response.data.totalCount
  188. this.page.currentPage = page.currentPage
  189. this.page.pageSize = page.pageSize
  190. this.loading = false
  191. })
  192. }
  193. } else { // 【素材】
  194. this.getMaterialPage();
  195. }
  196. },
  197. getMaterialPage() {
  198. getMaterialPage({
  199. ...this.queryParams,
  200. type: this.objData.type
  201. }).then(response => {
  202. this.list = response.data.list
  203. this.total = response.data.total
  204. }).finally(() => {
  205. this.loading = false
  206. })
  207. },
  208. sizeChange(val) {
  209. this.page.currentPage = 1
  210. this.page.pageSize = val
  211. this.getPage(this.page)
  212. },
  213. currentChange(val) {
  214. this.page.currentPage = val
  215. this.getPage(this.page)
  216. },
  217. /**
  218. * 刷新回调
  219. */
  220. refreshChange(page) {
  221. this.getPage(this.page)
  222. }
  223. }
  224. };
  225. </script>
  226. <style lang="scss" scoped>
  227. /*瀑布流样式*/
  228. .waterfall {
  229. width: 100%;
  230. column-gap:10px;
  231. column-count: 5;
  232. margin: 0 auto;
  233. }
  234. .waterfall-item {
  235. padding: 10px;
  236. margin-bottom: 10px;
  237. break-inside: avoid;
  238. border: 1px solid #eaeaea;
  239. }
  240. .material-img {
  241. width: 100%;
  242. }
  243. p {
  244. line-height: 30px;
  245. }
  246. @media (min-width: 992px) and (max-width: 1300px) {
  247. .waterfall {
  248. column-count: 3;
  249. }
  250. p {
  251. color:red;
  252. }
  253. }
  254. @media (min-width: 768px) and (max-width: 991px) {
  255. .waterfall {
  256. column-count: 2;
  257. }
  258. p {
  259. color: orange;
  260. }
  261. }
  262. @media (max-width: 767px) {
  263. .waterfall {
  264. column-count: 1;
  265. }
  266. }
  267. /*瀑布流样式*/
  268. </style>