Information.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div v-if="visible" class="home-info-container">
  3. <el-card>
  4. <div slot="header" class="clearfix">
  5. <span class="info-title">消息通知</span>
  6. <i class="el-icon-close info-close-btn" @click="close" />
  7. </div>
  8. <el-table
  9. v-loading="loading"
  10. :data="tableData"
  11. :show-header="false"
  12. stripe
  13. size="mini"
  14. height="300"
  15. style="width: 100%;"
  16. @cell-click="cellClick"
  17. >
  18. <el-table-column prop="title" label="标题" show-overflow-tooltip />
  19. </el-table>
  20. <div class="info-footer" @click="showMore"><span class="info-more-btn">点击查看更多</span></div>
  21. </el-card>
  22. </div>
  23. </template>
  24. <script>
  25. import { hasValidRecords } from '@/utils/convert'
  26. import { fetchTableList } from '@/api/info'
  27. export default {
  28. name: 'HomeInfo',
  29. props: {},
  30. data() {
  31. return {
  32. // dialog
  33. visible: false,
  34. // table
  35. current: 1,
  36. size: 50,
  37. tableData: [],
  38. // others
  39. loading: false
  40. }
  41. },
  42. created() {
  43. this.searchTable()
  44. },
  45. methods: {
  46. open(message) {
  47. this.visible = true
  48. this.tableData.unshift(message)
  49. },
  50. close() {
  51. this.visible = false
  52. },
  53. // 点击搜索按钮
  54. searchTable() {
  55. this.current = 1
  56. this.getTablelist()
  57. },
  58. // 获取table数据
  59. getTablelist() {
  60. this.loading = true
  61. const params = {
  62. current: this.current,
  63. size: this.size,
  64. delFlag: 0
  65. }
  66. fetchTableList(params).then(response => {
  67. this.loading = false
  68. if (hasValidRecords(response)) {
  69. this.tableData = response.data.records
  70. this.total = response.data.total
  71. } else {
  72. this.tableData = []
  73. this.total = 0
  74. }
  75. }).catch(error => {
  76. console.log(error)
  77. this.loading = false
  78. this.$message({
  79. type: 'error',
  80. duration: 0,
  81. showClose: true,
  82. message: '获取消息列表出错: ' + error.message
  83. })
  84. })
  85. },
  86. cellClick(row, column, cell) {
  87. },
  88. showMore() {
  89. this.visible = false
  90. this.$router.push('/info')
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .home-info-container {
  97. position: fixed;
  98. left: 20px;
  99. bottom: 10px;
  100. width: 400px;
  101. z-index: 1500;
  102. ::v-deep {
  103. .el-card__header {
  104. padding: 10px 10px 10px 20px;
  105. background-color: #0056dd;
  106. }
  107. .el-card__body {
  108. padding: 0;
  109. }
  110. .el-table td {
  111. padding-left: 10px;
  112. }
  113. }
  114. .info-title {
  115. color: #ffffff;
  116. }
  117. .info-close-btn {
  118. float: right;
  119. cursor: pointer;
  120. color: #ffffff;
  121. }
  122. .info-footer {
  123. height: 30px;
  124. line-height: 30px;
  125. font-size: 15px;
  126. text-align: center;
  127. padding-right: 20px;
  128. }
  129. .info-more-btn {
  130. cursor: pointer;
  131. }
  132. }
  133. </style>