index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="white-box">
  3. <el-table
  4. :key="tableKey"
  5. v-loading="listLoading"
  6. :data="list"
  7. border
  8. fit
  9. highlight-current-row
  10. style="width: 100%;"
  11. >
  12. <el-table-column :label="$t('ad.ad')" prop="id" align="center" :class-name="getSortClass('id')">
  13. <template slot-scope="{row}">
  14. <span>{{ row.LOCATION_NAME }}</span>
  15. </template>
  16. </el-table-column>
  17. <el-table-column :label="$t('ad.description')" prop="id" align="center" :class-name="getSortClass('id')">
  18. <template slot-scope="{row}">
  19. <span>{{ row.REMARK }}</span>
  20. </template>
  21. </el-table-column>
  22. <el-table-column :label="$t('ad.type')" align="center"> <!-- 类型 -->
  23. <template slot-scope="{row}">
  24. <template v-if="row.TYPE === '1'">
  25. <el-tag type="success">Slideshow</el-tag> <!-- 外链 -->
  26. </template>
  27. <template v-else-if="row.TYPE === '2'">
  28. <el-tag>Image</el-tag> <!-- 文章 -->
  29. </template>
  30. </template>
  31. </el-table-column>
  32. <el-table-column :label="$t('ad.creator')" prop="id" align="center" width="80" :class-name="getSortClass('id')">
  33. <template slot-scope="{row}">
  34. <span>{{ row.CREATE_ADMIN_NAME }}</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column :label="$t('ad.createTime')" align="center">
  38. <template slot-scope="{row}">
  39. <span>{{ row.CREATED_AT | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
  40. </template>
  41. </el-table-column>
  42. <el-table-column :label="$t('ad.action')" align="center" class-name="small-padding fixed-width">
  43. <template slot-scope="{row}">
  44. <el-button type="primary" size="mini" @click="handleView(row)">
  45. {{ $t('ad.view') }}
  46. </el-button>
  47. <!-- <router-link :to="'/ad/list/'+ row.id" class="link-type">
  48. <el-button type="primary" size="small" icon="el-icon-edit">
  49. {{ $t('ad.view') }}
  50. </el-button>
  51. </router-link> -->
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  56. </div>
  57. </div></template>
  58. <script>
  59. import { fetchList } from '@/api/ad'
  60. import waves from '@/directive/waves' // waves directive
  61. import { parseTime } from '@/utils'
  62. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  63. const calendarTypeOptions = [
  64. { key: 'CN', display_name: 'China' },
  65. { key: 'US', display_name: 'USA' }
  66. ]
  67. // arr to obj, such as { CN : "China", US : "USA" }
  68. const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
  69. acc[cur.key] = cur.display_name
  70. return acc
  71. }, {})
  72. export default {
  73. name: 'ComplexTable',
  74. components: { Pagination },
  75. directives: { waves },
  76. filters: {
  77. statusFilter(status) {
  78. const statusMap = {
  79. published: 'success',
  80. draft: 'info',
  81. deleted: 'danger'
  82. }
  83. return statusMap[status]
  84. },
  85. typeFilter(type) {
  86. return calendarTypeKeyValue[type]
  87. }
  88. },
  89. data() {
  90. return {
  91. tableKey: 0,
  92. list: null,
  93. total: 0,
  94. listLoading: true,
  95. listQuery: {
  96. page: 1,
  97. limit: 20
  98. },
  99. importanceOptions: [1, 2, 3],
  100. calendarTypeOptions,
  101. sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
  102. statusOptions: ['published', 'draft', 'deleted'],
  103. showReviewer: false,
  104. temp: {
  105. id: undefined,
  106. importance: 1,
  107. remark: '',
  108. timestamp: new Date(),
  109. title: '',
  110. type: '',
  111. status: 'published'
  112. },
  113. dialogFormVisible: false,
  114. dialogStatus: '',
  115. textMap: {
  116. update: 'Edit',
  117. create: 'Create'
  118. },
  119. dialogPvVisible: false,
  120. pvData: [],
  121. rules: {
  122. type: [{ required: true, message: 'type is required', trigger: 'change' }],
  123. timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
  124. title: [{ required: true, message: 'title is required', trigger: 'blur' }]
  125. },
  126. downloadLoading: false
  127. }
  128. },
  129. created() {
  130. this.getList()
  131. },
  132. methods: {
  133. getList() {
  134. this.listLoading = true
  135. fetchList(this.listQuery).then(response => {
  136. this.list = response.data.list
  137. this.total = response.data.totalCount
  138. // Just to simulate the time of the request
  139. setTimeout(() => {
  140. this.listLoading = false
  141. }, 1.5 * 1000)
  142. })
  143. },
  144. handleFilter() {
  145. this.listQuery.page = 1
  146. this.getList()
  147. },
  148. resetTemp() {
  149. this.temp = {
  150. id: undefined,
  151. importance: 1,
  152. remark: '',
  153. timestamp: new Date(),
  154. title: '',
  155. status: 'published',
  156. type: ''
  157. }
  158. },
  159. handleView(row) {
  160. this.$router.push(`/ad/list/${row.ID}`)
  161. },
  162. formatJson(filterVal) {
  163. return this.list.map(v => filterVal.map(j => {
  164. if (j === 'timestamp') {
  165. return parseTime(v[j])
  166. } else {
  167. return v[j]
  168. }
  169. }))
  170. },
  171. getSortClass: function(key) {
  172. const sort = this.listQuery.sort
  173. return sort === `+${key}` ? 'ascending' : 'descending'
  174. }
  175. }
  176. }
  177. </script>