index.vue 7.5 KB

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