article-list.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div class="app-container">
  3. <el-table
  4. :key="tableKey"
  5. v-loading="listLoading"
  6. :data="list"
  7. fit
  8. highlight-current-row
  9. >
  10. <el-table-column align="center" :label="$t('article.title')" prop="TITLE">
  11. <template slot-scope="{row}">
  12. <span @click="handleArticle(row.ID)">
  13. <el-link type="primary" href="#" target="_self" >{{ row.TITLE }}</el-link>
  14. </span>
  15. </template>
  16. </el-table-column>
  17. <el-table-column align="center" :label="$t('article.category')" prop="CATE_NAME" v-if="['windows', 'linux'].includes(system)">
  18. <template slot-scope="{row}">
  19. {{ row.CATE_NAME }}
  20. </template>
  21. </el-table-column>
  22. <el-table-column align="center" :label="$t('article.createTime')" prop="CREATED_AT">
  23. <template slot-scope="{row}">
  24. <span>{{ tool.convertToNigeriaDayTime(row.CREATED_AT) }}</span>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
  29. <el-dialog title="" :visible.sync="dialog" :width="screenWidth" v-loading="loading" center style="margin-top: -80px;">
  30. <div class="white-box" style="margin-top: -20px; padding: 0;">
  31. <div class="white-box-title" style="text-align: center">
  32. <h1>{{ article.TITLE }}</h1>
  33. <span>{{ tool.convertToNigeriaTime(article.CREATED_AT) }}</span>
  34. </div>
  35. <div v-html="article.CONTENT" class="white-box-content">
  36. </div>
  37. </div>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <script>
  42. import {fetchArticleList, fetchArticleOne} from '@/api/article'
  43. import waves from '@/directive/waves'
  44. import Pagination from '@/components/Pagination'
  45. import {formatAmount, getOperatingSystem, getScreenWidth} from "@/utils"
  46. import tool from "@/utils/tool";
  47. export default {
  48. name: 'ArticleList',
  49. computed: {
  50. tool() {
  51. return tool
  52. }
  53. },
  54. components: { Pagination },
  55. directives: { waves },
  56. data() {
  57. return {
  58. tableKey: 0,
  59. list: null,
  60. total: 0,
  61. listLoading: true,
  62. category: {},
  63. listQuery: {
  64. page: 1,
  65. pageSize: 20
  66. },
  67. loading: false,
  68. dialog: false,
  69. article: {
  70. ID: '',
  71. CID: '',
  72. TITLE: '',
  73. CONTENT: '',
  74. CREATED_AT: '',
  75. },
  76. screenWidth: getScreenWidth() > 600 ? '70%' : getScreenWidth() + 'px',
  77. labelPosition: getScreenWidth() > 600 ? 'right' : 'top',
  78. system: getOperatingSystem(),
  79. }
  80. },
  81. created() {
  82. this.getList()
  83. },
  84. methods: {
  85. getList() {
  86. this.listLoading = true
  87. fetchArticleList(this.listQuery).then(response => {
  88. this.list = response.data.list
  89. this.total = +response.data.totalCount
  90. this.category = response.data.allCategory
  91. this.list.forEach(item => {
  92. item.CATE_NAME = this.category[item.CID].CATE_NAME ?? ''
  93. })
  94. setTimeout(() => {
  95. this.listLoading = false
  96. }, 0.5 * 1000)
  97. })
  98. },
  99. handleArticle(id) {
  100. this.loading = true
  101. this.listLoading = true
  102. fetchArticleOne(id).then(response => {
  103. this.article = response.data
  104. this.dialog = true
  105. this.listLoading = false
  106. setTimeout(() => {
  107. this.loading = false
  108. }, 0.5 * 1000)
  109. })
  110. },
  111. }
  112. }
  113. </script>
  114. <style scoped>
  115. .white-box-title span{color: #999}
  116. .white-box-content{font-size: 16px;padding: 15px 0;line-height: 2;}
  117. </style>