articles.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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="calcAniWait(index)">
  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. hasNext:false,
  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.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.fnResetSetAniWaitIndex();
  229. this.category.selected = [e[0].index];
  230. this.queryParams.categoryId = e[0].data.id;
  231. },
  232. fnOnSearch() {
  233. this.fnResetSetAniWaitIndex();
  234. this.queryParams.page = 0;
  235. this.isLoadMore = false;
  236. this.fnToTopPage();
  237. this.fnGetData();
  238. },
  239. fnGetData() {
  240. uni.showLoading({
  241. mask: true,
  242. title: '加载中...'
  243. });
  244. // 设置状态为加载中
  245. if (!this.isLoadMore) {
  246. this.loading = 'loading';
  247. }
  248. this.loadMoreText = '加载中...';
  249. this.$httpApi.admin
  250. .getPostsByPage(this.queryParams)
  251. .then(res => {
  252. console.log('请求结果:');
  253. console.log(res);
  254. if (res.status == 200) {
  255. // 处理数据
  256. this.result = res.data;
  257. const _dataList = res.data.content.map(item => {
  258. item.hasThumbnail = item.thumbnail != '';
  259. if (item.thumbnail) {
  260. item.thumbnail = this.$utils.checkThumbnailUrl(item.thumbnail);
  261. }
  262. return item;
  263. });
  264. if (this.isLoadMore) {
  265. this.dataList = this.dataList.concat(_dataList);
  266. } else {
  267. this.dataList = _dataList;
  268. }
  269. this.loading = 'success';
  270. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  271. } else {
  272. this.loading = 'error';
  273. this.loadMoreText = '呜呜,加载失败了~';
  274. }
  275. })
  276. .catch(err => {
  277. console.error(err);
  278. this.loading = 'error';
  279. this.loadMoreText = '加载失败,请下拉刷新!';
  280. })
  281. .finally(() => {
  282. setTimeout(() => {
  283. uni.hideLoading();
  284. uni.stopPullDownRefresh();
  285. }, 800);
  286. });
  287. },
  288. // 跳转文章详情(预览)
  289. fnToArticleDetail(article) {
  290. uni.navigateTo({
  291. url: '/pagesA/article-detail/article-detail?articleId=' + article.id,
  292. animationType: 'slide-in-right'
  293. });
  294. },
  295. // 新增
  296. fnOnAddArticle() {
  297. this.$Router.push({ path: '/pagesB/articles/article-edit', query: {} });
  298. },
  299. // 文章编辑
  300. fnOnEditArticle(article) {
  301. this.$Router.push({ path: '/pagesB/articles/article-edit', query: { postsId: article.id } });
  302. },
  303. // 设置文章信息
  304. fnOnSetArticle(article, index) {
  305. this.$Router.push({ path: '/pagesB/articles/article-setting', query: { postsId: article.id, postTitle: article.title, isEdit: 1, from: 'list' } });
  306. },
  307. // 删除文章
  308. fnOnDelArticle(article, index) {
  309. uni.$eShowModal({
  310. title: '提示',
  311. content: '是否确定要删除该文章?',
  312. showCancel: true,
  313. cancelText: '否',
  314. cancelColor: '#999999',
  315. confirmText: '是',
  316. confirmColor: '#03a9f4'
  317. })
  318. .then(res => {
  319. uni.showLoading({
  320. mask: true,
  321. title: '删除中...'
  322. });
  323. this.$httpApi.admin
  324. .deletePostsByIds([article.id])
  325. .then(res => {
  326. if (res.status == 200) {
  327. uni.$tm.toast('文章已删除成功!');
  328. this.dataList.splice(index, 1);
  329. } else {
  330. uni.$tm.toast('操作失败,请重试!');
  331. }
  332. })
  333. .catch(err => {
  334. uni.$tm.toast('操作失败,请重试!');
  335. });
  336. })
  337. .catch(err => {});
  338. }
  339. }
  340. };
  341. </script>
  342. <style lang="scss" scoped>
  343. .app-page {
  344. width: 100vw;
  345. min-height: 100vh;
  346. display: flex;
  347. flex-direction: column;
  348. padding-bottom: 24rpx;
  349. background-color: #fafafd;
  350. &.is-balck {
  351. background-color: #212121;
  352. }
  353. }
  354. .app-page-content {
  355. box-sizing: border-box;
  356. .content-empty {
  357. height: 60vh;
  358. }
  359. }
  360. .article-card {
  361. box-sizing: border-box;
  362. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.05);
  363. .thumbnail {
  364. width: 100%;
  365. height: 280rpx;
  366. &-img {
  367. width: 100%;
  368. height: 100%;
  369. background-color: rgba(0, 0, 0, 0.03);
  370. }
  371. &-not {
  372. width: 100%;
  373. height: 100%;
  374. background-color: rgba(0, 0, 0, 0.03);
  375. }
  376. }
  377. .title {
  378. overflow: hidden;
  379. white-space: nowrap;
  380. text-overflow: ellipsis;
  381. word-wrap: break-word;
  382. word-break: break-all;
  383. }
  384. .summary {
  385. display: -webkit-box;
  386. -webkit-box-orient: vertical;
  387. -webkit-line-clamp: 3;
  388. overflow: hidden;
  389. word-wrap: break-word;
  390. word-break: break-all;
  391. }
  392. .foot {
  393. box-sizing: border-box;
  394. border-top: 2rpx solid rgba(0, 0, 0, 0.03);
  395. }
  396. }
  397. </style>