index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <content-wrap>
  3. <doc-alert title="公众号图文" url="https://doc.iocoder.cn/mp/article/" />
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. size="small"
  9. :inline="true"
  10. v-show="showSearch"
  11. label-width="68px"
  12. >
  13. <el-form-item label="公众号" prop="accountId">
  14. <el-select v-model="queryParams.accountId" placeholder="请选择公众号">
  15. <el-option
  16. v-for="item in accounts"
  17. :key="parseInt(item.id)"
  18. :label="item.name"
  19. :value="parseInt(item.id)"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" :icon="Search" @click="handleQuery">搜索</el-button>
  25. <el-button :icon="Refresh" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <!-- 列表 -->
  29. <div class="waterfall" v-loading="loading">
  30. <div
  31. v-show="item.content && item.content.newsItem"
  32. class="waterfall-item"
  33. v-for="item in list"
  34. :key="item.articleId"
  35. >
  36. <wx-news :articles="item.content.newsItem" />
  37. <!-- 操作 -->
  38. <el-row justify="center" class="ope-row">
  39. <el-button
  40. type="danger"
  41. :icon="Delete"
  42. circle
  43. @click="handleDelete(item)"
  44. v-hasPermi="['mp:free-publish:delete']"
  45. />
  46. </el-row>
  47. </div>
  48. </div>
  49. <!-- 分页组件 -->
  50. <pagination
  51. v-show="total > 0"
  52. :total="total"
  53. v-model:page="queryParams.pageNo"
  54. v-model:limit="queryParams.pageSize"
  55. @pagination="getList"
  56. />
  57. </content-wrap>
  58. </template>
  59. <script setup lang="ts" name="freePublish">
  60. import { getFreePublishPage, deleteFreePublish } from '@/api/mp/freePublish'
  61. import { getSimpleAccounts } from '@/api/mp/account'
  62. import WxNews from '@/views/mp/components/wx-news/main.vue'
  63. import { Delete, Search, Refresh } from '@element-plus/icons-vue'
  64. const message = useMessage() // 消息弹窗
  65. const queryParams = reactive({
  66. total: 0, // 总页数
  67. currentPage: 1, // 当前页数
  68. pageNo: 1, // 当前页数
  69. accountId: undefined, // 当前页数
  70. queryParamsSize: 10 // 每页显示多少条
  71. })
  72. const loading = ref(false) // 列表的加载中
  73. const showSearch = ref(true) // 列表的加载中
  74. const total = ref(0) // 列表的总页数
  75. const list = ref([]) // 列表的数据
  76. const accounts = ref([]) // 列表的数据
  77. const queryFormRef = ref() // 搜索的表单
  78. /** 查询列表 */
  79. const getList = async () => {
  80. // 如果没有选中公众号账号,则进行提示。
  81. if (!queryParams.accountId) {
  82. message.error('未选中公众号,无法查询已发表图文')
  83. return false
  84. }
  85. loading.value = true
  86. getFreePublishPage(queryParams)
  87. .then((data) => {
  88. console.log(data)
  89. // 将 thumbUrl 转成 picUrl,保证 wx-news 组件可以预览封面
  90. data.list.forEach((item) => {
  91. console.log(item)
  92. const newsItem = item.content.newsItem
  93. newsItem.forEach((article) => {
  94. article.picUrl = article.thumbUrl
  95. })
  96. })
  97. list.value = data.list
  98. total.value = data.total
  99. })
  100. .finally(() => {
  101. loading.value = false
  102. })
  103. }
  104. /** 搜索按钮操作 */
  105. const handleQuery = async () => {
  106. queryParams.pageNo = 1
  107. getList()
  108. }
  109. /** 重置按钮操作 */
  110. const resetQuery = async () => {
  111. queryFormRef.value.resetFields()
  112. // 默认选中第一个
  113. if (accounts.value.length > 0) {
  114. queryParams.accountId = accounts[0].id
  115. }
  116. handleQuery()
  117. }
  118. /** 删除按钮操作 */
  119. const handleDelete = async (item) => {
  120. {
  121. const articleId = item.articleId
  122. const accountId = queryParams.accountId
  123. message
  124. .confirm('删除后用户将无法访问此页面,确定删除?')
  125. .then(function () {
  126. return deleteFreePublish(accountId, articleId)
  127. })
  128. .then(() => {
  129. getList()
  130. message.success('删除成功')
  131. })
  132. .catch(() => {})
  133. }
  134. }
  135. onMounted(() => {
  136. getSimpleAccounts().then((response) => {
  137. accounts.value = response
  138. // 默认选中第一个
  139. if (accounts.value.length > 0) {
  140. queryParams.accountId = accounts.value[0]['id']
  141. }
  142. // 加载数据
  143. getList()
  144. })
  145. })
  146. </script>
  147. <style lang="scss" scoped>
  148. .pagination {
  149. float: right;
  150. margin-right: 25px;
  151. }
  152. .add_but {
  153. padding: 10px;
  154. }
  155. .ope-row {
  156. margin-top: 5px;
  157. text-align: center;
  158. border-top: 1px solid #eaeaea;
  159. padding-top: 5px;
  160. }
  161. .item-name {
  162. font-size: 12px;
  163. overflow: hidden;
  164. text-overflow: ellipsis;
  165. white-space: nowrap;
  166. text-align: center;
  167. }
  168. .el-upload__tip {
  169. margin-left: 5px;
  170. }
  171. /*新增图文*/
  172. .left {
  173. display: inline-block;
  174. width: 35%;
  175. vertical-align: top;
  176. margin-top: 200px;
  177. }
  178. .right {
  179. display: inline-block;
  180. width: 60%;
  181. margin-top: -40px;
  182. }
  183. .avatar-uploader {
  184. width: 20%;
  185. display: inline-block;
  186. }
  187. .avatar-uploader .el-upload {
  188. border-radius: 6px;
  189. cursor: pointer;
  190. position: relative;
  191. overflow: hidden;
  192. text-align: unset !important;
  193. }
  194. .avatar-uploader .el-upload:hover {
  195. border-color: #165dff;
  196. }
  197. .avatar-uploader-icon {
  198. border: 1px solid #d9d9d9;
  199. font-size: 28px;
  200. color: #8c939d;
  201. width: 120px;
  202. height: 120px;
  203. line-height: 120px;
  204. text-align: center;
  205. }
  206. .avatar {
  207. width: 230px;
  208. height: 120px;
  209. }
  210. .avatar1 {
  211. width: 120px;
  212. height: 120px;
  213. }
  214. .digest {
  215. width: 60%;
  216. display: inline-block;
  217. vertical-align: top;
  218. }
  219. /*新增图文*/
  220. /*瀑布流样式*/
  221. .waterfall {
  222. width: 100%;
  223. column-gap: 10px;
  224. column-count: 5;
  225. margin: 0 auto;
  226. }
  227. .waterfall-item {
  228. padding: 10px;
  229. margin-bottom: 10px;
  230. break-inside: avoid;
  231. border: 1px solid #eaeaea;
  232. }
  233. p {
  234. line-height: 30px;
  235. }
  236. @media (min-width: 992px) and (max-width: 1300px) {
  237. .waterfall {
  238. column-count: 3;
  239. }
  240. p {
  241. color: red;
  242. }
  243. }
  244. @media (min-width: 768px) and (max-width: 991px) {
  245. .waterfall {
  246. column-count: 2;
  247. }
  248. p {
  249. color: orange;
  250. }
  251. }
  252. @media (max-width: 767px) {
  253. .waterfall {
  254. column-count: 1;
  255. }
  256. }
  257. /*瀑布流样式*/
  258. .news-main {
  259. background-color: #ffffff;
  260. width: 100%;
  261. margin: auto;
  262. height: 120px;
  263. }
  264. .news-content {
  265. background-color: #acadae;
  266. width: 100%;
  267. height: 120px;
  268. position: relative;
  269. }
  270. .news-content-title {
  271. display: inline-block;
  272. font-size: 15px;
  273. color: #ffffff;
  274. position: absolute;
  275. left: 0px;
  276. bottom: 0px;
  277. background-color: black;
  278. width: 98%;
  279. padding: 1%;
  280. opacity: 0.65;
  281. overflow: hidden;
  282. text-overflow: ellipsis;
  283. white-space: nowrap;
  284. height: 25px;
  285. }
  286. .news-main-item {
  287. background-color: #ffffff;
  288. padding: 5px 0px;
  289. border-top: 1px solid #eaeaea;
  290. width: 100%;
  291. margin: auto;
  292. }
  293. .news-content-item {
  294. position: relative;
  295. margin-left: -3px;
  296. }
  297. .news-content-item-title {
  298. display: inline-block;
  299. font-size: 12px;
  300. width: 70%;
  301. }
  302. .news-content-item-img {
  303. display: inline-block;
  304. width: 25%;
  305. background-color: #acadae;
  306. }
  307. .input-tt {
  308. padding: 5px;
  309. }
  310. .activeAddNews {
  311. border: 5px solid #2bb673;
  312. }
  313. .news-main-plus {
  314. width: 280px;
  315. text-align: center;
  316. margin: auto;
  317. height: 50px;
  318. }
  319. .icon-plus {
  320. margin: 10px;
  321. font-size: 25px;
  322. }
  323. .select-item {
  324. width: 60%;
  325. padding: 10px;
  326. margin: 0 auto 10px auto;
  327. border: 1px solid #eaeaea;
  328. }
  329. .father .child {
  330. display: none;
  331. text-align: center;
  332. position: relative;
  333. bottom: 25px;
  334. }
  335. .father:hover .child {
  336. display: block;
  337. }
  338. .thumb-div {
  339. display: inline-block;
  340. width: 30%;
  341. text-align: center;
  342. }
  343. .thumb-but {
  344. margin: 5px;
  345. }
  346. .material-img {
  347. width: 100%;
  348. height: 100%;
  349. }
  350. </style>