articles.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <view class="app-page" :class="{ 'is-balck grey-darken-6': isBlackTheme }">
  3. <!-- 顶部切换 -->
  4. <view class="e-fixed shadow-2">
  5. <tm-search v-model="queryParams.keyword" :round="24" :shadow="0" color="light-blue" insert-color="light-blue" :clear="true">
  6. <view slot="right" class="flex flex-center">
  7. <tm-pickers title="请选择分类" :default-value="category.selected" :list="category.list" rang-key="name" btn-color="blue" @confirm="fnOnCategoryConfirm">
  8. <text class="iconfont icon-filter text-size-lg text-grey-darken-2"></text>
  9. </tm-pickers>
  10. <text class="ml-16 text-size-g" style="min-width: 70rpx;" @click="fnOnSearch">搜索</text>
  11. </view>
  12. </tm-search>
  13. <tm-tabs color="light-blue" :shadow="0" v-model="tab.activeIndex" :list="tab.list" align="center" @change="fnOnTabChange"></tm-tabs>
  14. </view>
  15. <!-- 占位区域 -->
  16. <view style="width: 100vw;height: 184rpx;"></view>
  17. <!-- 加载区域 -->
  18. <view v-if="loading != 'success'" class="loading-wrap pa-24">
  19. <tm-skeleton model="listAvatr"></tm-skeleton>
  20. <tm-skeleton model="listAvatr"></tm-skeleton>
  21. <tm-skeleton model="listAvatr"></tm-skeleton>
  22. <tm-skeleton model="listAvatr"></tm-skeleton>
  23. </view>
  24. <!-- 内容区域 -->
  25. <view v-else class="app-page-content pl-24 pr-24">
  26. <view v-if="dataList.length == 0" class="content-empty flex flex-center">
  27. <!-- 空布局 -->
  28. <tm-empty icon="icon-shiliangzhinengduixiang-" label="该分类下暂无数据"></tm-empty>
  29. </view>
  30. <block v-else>
  31. <block v-for="(article, index) in dataList" :key="index">
  32. <tm-translate animation-name="fadeUp" :wait="(index + 1) * 50">
  33. <!-- 文章卡片 -->
  34. <view class="article-card mt-24 bg-white pa-24 round-3">
  35. <view class="thumbnail round-2" @click="fnToArticleDetail(article)">
  36. <image v-if="article.hasThumbnail" class="thumbnail-img round-2" :src="article.thumbnail" mode="aspectFill"></image>
  37. <view v-else class="thumbnail-not round-2 flex flex-center text-grey-darken-2">无封面图</view>
  38. </view>
  39. <view class="title mt-16 text-bg-gradient-blue-accent">{{ article.title }}</view>
  40. <view class="summary mt-16 text-grey-darken-2 text-size-m">{{ article.summary }}</view>
  41. <view class="flex mt-12 flex-start desc-box text-size-m">
  42. <view class="label text-grey-darken-2">分类:</view>
  43. <view class="value">
  44. <block v-if="article.categories.length != 0">
  45. <tm-tags v-for="(category, categoryIndex) in article.categories" :key="category.slug" color="light-blue" size="s" model="text">
  46. {{ category.name }}
  47. </tm-tags>
  48. </block>
  49. <text v-else class="ml-12 text-grey-darken-2">未选择分类</text>
  50. </view>
  51. </view>
  52. <view class="flex flex-start desc-box text-size-m" :class="{ 'mt-12': article.tags.length == 0 }">
  53. <view class="label text-grey-darken-2">标签:</view>
  54. <view class="value">
  55. <block v-if="article.tags.length != 0">
  56. <tm-tags v-for="(tag, tagIndex) in article.tags" :key="tag.slug" color="orange" size="s" model="text">{{ tag.name }}</tm-tags>
  57. </block>
  58. <text v-else class="ml-12 text-grey-darken-2 ">未选择标签</text>
  59. </view>
  60. </view>
  61. <view class="flex flex-start desc-box text-size-m" :class="{ 'mt-12': article.tags.length == 0 }">
  62. <view class="label text-grey-darken-2">状态:</view>
  63. <view class="value">
  64. <tm-tags v-if="article.status == 'PUBLISHED'" color="green" size="s" model="text">已发布(访客可见)</tm-tags>
  65. <tm-tags v-else-if="article.status == 'INTIMATE'" color="light-blue" size="s" model="text">私密(访客不可见)</tm-tags>
  66. <tm-tags v-else-if="article.status == 'DRAFT'" color="blue-grey" size="s" model="text">草稿(未发布)</tm-tags>
  67. <tm-tags v-else-if="article.status == 'RECYCLE'" color="deep-orange" size="s" model="text">回收站</tm-tags>
  68. </view>
  69. </view>
  70. <view class="flex mt-12 flex-start desc-box text-size-m">
  71. <view class="label text-grey-darken-2">日期:</view>
  72. <view class="value ml-12 text-grey-darken-2">{{ $tm.dayjs(article.createTime).format('YYYY年MM月DD日 HH点mm分ss秒') }}</view>
  73. </view>
  74. <view class="flex mt-12 flex-start desc-box text-size-m ">
  75. <view class="label text-grey-darken-2">统计:</view>
  76. <view class="value ml-12 text-grey-darken-2">
  77. <text class="">
  78. <text class="text-size-m text-weight-b text-bg-gradient-blue-accent">{{ article.wordCount }}</text>
  79. <text class="ml-6 text-size-s">字</text>
  80. </text>
  81. <text class="ml-20">
  82. <text class="text-size-m text-weight-b text-bg-gradient-light-blue-accent">{{ article.visits }}</text>
  83. <text class="ml-6 text-size-s">浏览</text>
  84. </text>
  85. <text class="ml-20">
  86. <text class="text-size-m text-weight-b text-bg-gradient-cyan-accent">{{ article.likes }}</text>
  87. <text class="ml-6 text-size-s">点赞</text>
  88. </text>
  89. <text class="ml-20">
  90. <text class="text-size-m text-weight-b text-bg-gradient-blue-grey-accent">{{ article.commentCount }}</text>
  91. <text class="ml-6 text-size-s">评论</text>
  92. </text>
  93. </view>
  94. </view>
  95. <view class="foot flex flex-between mt-20 pt-24 desc-box text-size-m">
  96. <tm-button theme="light-blue" :shadow="0" block :width="200" :height="60" size="m" @click="fnOnEditArticle(article)">编辑</tm-button>
  97. <tm-button theme="red" :shadow="0" block :width="200" :height="60" size="m" @click="fnOnDelArticle(article, index)">删除</tm-button>
  98. <tm-button theme="blue-grey" :shadow="0" block :width="200" :height="60" size="m" @click="fnOnSetArticle(article, index)">设置</tm-button>
  99. </view>
  100. </view>
  101. </tm-translate>
  102. </block>
  103. <tm-flotbutton @click="fnToTopPage" :offset="[16, 80]" color="bg-gradient-light-blue-accent" size="m" icon="icon-angle-up"></tm-flotbutton>
  104. <tm-flotbutton :show-text="true" color="bg-gradient-orange-accent" @click="fnOnAddArticle()"></tm-flotbutton>
  105. <view class="load-text">{{ loadMoreText }}</view>
  106. </block>
  107. </view>
  108. </view>
  109. </template>
  110. <script>
  111. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  112. import tmSearch from '@/tm-vuetify/components/tm-search/tm-search.vue';
  113. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  114. import tmTabs from '@/tm-vuetify/components/tm-tabs/tm-tabs.vue';
  115. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  116. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  117. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  118. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  119. import tmPickers from '@/tm-vuetify/components/tm-pickers/tm-pickers.vue';
  120. export default {
  121. components: {
  122. tmSkeleton,
  123. tmSearch,
  124. tmTranslate,
  125. tmTabs,
  126. tmFlotbutton,
  127. tmEmpty,
  128. tmTags,
  129. tmButton,
  130. tmPickers
  131. },
  132. data() {
  133. return {
  134. isBlackTheme: false,
  135. loading: 'loading',
  136. tab: {
  137. activeIndex: 0,
  138. list: ['全部', '已发布', '私密', '草稿', '回收站']
  139. },
  140. queryParams: {
  141. size: 10,
  142. page: 0,
  143. status: '',
  144. keyword: '',
  145. categoryId: undefined
  146. },
  147. cache: {
  148. dataList: [],
  149. total: 0
  150. },
  151. isLoadMore: false,
  152. loadMoreText: '加载中...',
  153. result: {},
  154. dataList: [],
  155. category: {
  156. loading: 'loading',
  157. show: false,
  158. list: [],
  159. selected: [0]
  160. }
  161. };
  162. },
  163. onLoad() {
  164. this.fnSetPageTitle('文章管理');
  165. this.fnGetCategoryList();
  166. },
  167. created() {
  168. this.fnGetData();
  169. uni.$on('refresh-article-list', () => {
  170. this.isLoadMore = false;
  171. this.queryParams.page = 0;
  172. this.fnGetData();
  173. });
  174. },
  175. onPullDownRefresh() {
  176. this.isLoadMore = false;
  177. this.queryParams.page = 0;
  178. this.fnGetData();
  179. },
  180. onReachBottom(e) {
  181. if (this.result.hasNext) {
  182. this.queryParams.page += 1;
  183. this.isLoadMore = true;
  184. this.fnGetData();
  185. } else {
  186. uni.showToast({
  187. icon: 'none',
  188. title: '没有更多数据了'
  189. });
  190. }
  191. },
  192. methods: {
  193. fnOnTabChange(index) {
  194. this.dataList = [];
  195. const _status = {
  196. 0: '',
  197. 1: 'PUBLISHED',
  198. 2: 'INTIMATE',
  199. 3: 'DRAFT',
  200. 4: 'RECYCLE'
  201. };
  202. this.queryParams.status = _status[index];
  203. this.queryParams.page = 0;
  204. this.fnToTopPage();
  205. this.fnGetData();
  206. },
  207. // 获取分类列表
  208. fnGetCategoryList() {
  209. this.category.loading = 'loading';
  210. this.$httpApi.admin
  211. .getCategoryList()
  212. .then(res => {
  213. if (res.status == 200) {
  214. let _list = res.data;
  215. _list.unshift({ id: undefined, name: '全部' });
  216. this.category.list = _list;
  217. this.category.loading = 'success';
  218. } else {
  219. this.category.loading = 'error';
  220. }
  221. })
  222. .catch(err => {
  223. this.category.loading = 'error';
  224. });
  225. },
  226. // 显示分类选择
  227. fnOnCategoryConfirm(e) {
  228. this.category.selected = [e[0].index];
  229. this.queryParams.categoryId = e[0].data.id;
  230. },
  231. fnOnSearch() {
  232. this.queryParams.page = 0;
  233. this.isLoadMore = false;
  234. this.fnToTopPage();
  235. this.fnGetData();
  236. },
  237. fnGetData() {
  238. uni.showLoading({
  239. mask: true,
  240. title: '加载中...'
  241. });
  242. // 设置状态为加载中
  243. if (!this.isLoadMore) {
  244. this.loading = 'loading';
  245. }
  246. this.loadMoreText = '加载中...';
  247. this.$httpApi.admin
  248. .getPostsByPage(this.queryParams)
  249. .then(res => {
  250. console.log('请求结果:');
  251. console.log(res);
  252. if (res.status == 200) {
  253. // 处理数据
  254. this.result = res.data;
  255. const _dataList = res.data.content.map(item => {
  256. item.hasThumbnail = item.thumbnail != '';
  257. if (item.thumbnail) {
  258. item.thumbnail = this.$utils.checkThumbnailUrl(item.thumbnail);
  259. }
  260. return item;
  261. });
  262. if (this.isLoadMore) {
  263. this.dataList = this.dataList.concat(_dataList);
  264. } else {
  265. this.dataList = _dataList;
  266. }
  267. this.loading = 'success';
  268. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  269. } else {
  270. this.loading = 'error';
  271. this.loadMoreText = '呜呜,加载失败了~';
  272. }
  273. })
  274. .catch(err => {
  275. console.error(err);
  276. this.loading = 'error';
  277. this.loadMoreText = '加载失败,请下拉刷新!';
  278. })
  279. .finally(() => {
  280. setTimeout(() => {
  281. uni.hideLoading();
  282. uni.stopPullDownRefresh();
  283. }, 800);
  284. });
  285. },
  286. // 跳转文章详情(预览)
  287. fnToArticleDetail(article) {
  288. uni.navigateTo({
  289. url: '/pagesA/article-detail/article-detail?articleId=' + article.id,
  290. animationType: 'slide-in-right'
  291. });
  292. },
  293. // 新增
  294. fnOnAddArticle() {
  295. this.$Router.push({ path: '/pagesB/articles/article-edit', query: {} });
  296. },
  297. // 文章编辑
  298. fnOnEditArticle(article) {
  299. this.$Router.push({ path: '/pagesB/articles/article-edit', query: { postsId: article.id } });
  300. },
  301. // 设置文章信息
  302. fnOnSetArticle(article, index) {
  303. this.$Router.push({ path: '/pagesB/articles/article-setting', query: { postsId: article.id, postTitle: article.title, isEdit: 1, from: 'list' } });
  304. },
  305. // 删除文章
  306. fnOnDelArticle(article, index) {
  307. uni.$eShowModal({
  308. title: '提示',
  309. content: '是否确定要删除该文章?',
  310. showCancel: true,
  311. cancelText: '否',
  312. cancelColor: '#999999',
  313. confirmText: '是',
  314. confirmColor: '#03a9f4'
  315. })
  316. .then(res => {
  317. uni.showLoading({
  318. mask: true,
  319. title: '删除中...'
  320. });
  321. this.$httpApi.admin
  322. .deletePostsByIds([article.id])
  323. .then(res => {
  324. if (res.status == 200) {
  325. uni.$tm.toast('文章已删除成功!');
  326. this.dataList.splice(index, 1);
  327. } else {
  328. uni.$tm.toast('操作失败,请重试!');
  329. }
  330. })
  331. .catch(err => {
  332. uni.$tm.toast('操作失败,请重试!');
  333. });
  334. })
  335. .catch(err => {});
  336. }
  337. }
  338. };
  339. </script>
  340. <style lang="scss" scoped>
  341. .app-page {
  342. width: 100vw;
  343. min-height: 100vh;
  344. display: flex;
  345. flex-direction: column;
  346. padding-bottom: 24rpx;
  347. background-color: #fafafd;
  348. &.is-balck {
  349. background-color: #212121;
  350. }
  351. }
  352. .app-page-content {
  353. box-sizing: border-box;
  354. .content-empty {
  355. height: 60vh;
  356. }
  357. }
  358. .article-card {
  359. box-sizing: border-box;
  360. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.05);
  361. .thumbnail {
  362. width: 100%;
  363. height: 280rpx;
  364. &-img {
  365. width: 100%;
  366. height: 100%;
  367. background-color: rgba(0, 0, 0, 0.03);
  368. }
  369. &-not {
  370. width: 100%;
  371. height: 100%;
  372. background-color: rgba(0, 0, 0, 0.03);
  373. }
  374. }
  375. .title {
  376. overflow: hidden;
  377. white-space: nowrap;
  378. text-overflow: ellipsis;
  379. word-wrap: break-word;
  380. word-break: break-all;
  381. }
  382. .summary {
  383. display: -webkit-box;
  384. -webkit-box-orient: vertical;
  385. -webkit-line-clamp: 3;
  386. overflow: hidden;
  387. word-wrap: break-word;
  388. word-break: break-all;
  389. }
  390. .foot {
  391. box-sizing: border-box;
  392. border-top: 2rpx solid rgba(0, 0, 0, 0.03);
  393. }
  394. }
  395. </style>