list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <div class="white-box">
  3. <div class="filter-box">
  4. <el-table
  5. :key="tableKey"
  6. v-loading="listLoading"
  7. :data="list"
  8. border
  9. fit
  10. highlight-current-row
  11. style="width: 100%;"
  12. @selection-change="handleSelectionChange"
  13. >
  14. <el-table-column type="selection" width="55" />
  15. <el-table-column :label="$t('ad.adTitle')" prop="id" align="center" :class-name="getSortClass('id')">
  16. <template slot-scope="{row}">
  17. <span>{{ row.TITLE }}</span>
  18. </template>
  19. </el-table-column>
  20. <el-table-column :label="$t('ad.adLocation')" prop="id" align="center" :class-name="getSortClass('id')">
  21. <template :value="{allLocation}">
  22. <span>{{ allLocation.LOCATION_NAME }}</span>
  23. </template>
  24. </el-table-column>
  25. <el-table-column :label="$t('ad.type')" align="center"> <!-- 类型 -->
  26. <template slot-scope="{row}">
  27. <template v-if="row.TYPE === '1'">
  28. <el-tag type="success">External Links</el-tag> <!-- 外链 -->
  29. </template>
  30. <template v-else-if="row.TYPE === '2'">
  31. <el-tag>Article</el-tag> <!-- 文章 -->
  32. </template>
  33. </template>
  34. </el-table-column>
  35. <el-table-column :label="$t('ad.content')" prop="id" align="center" :class-name="getSortClass('id')">
  36. <template slot-scope="{row}">
  37. <div v-if="row.TYPE === '1'">
  38. <el-link type="primary" target="_blank" :href="getHref(row.CONTENT)">{{ row.CONTENT }}</el-link>
  39. </div><!-- 链接 -->
  40. <div v-else-if="row.TYPE === '2'">
  41. <router-link :to="`/article/detail/${row.CONTENT}`" target="_blank" style="cursor: pointer;">{{ getContent(row.CONTENT) }}</router-link>
  42. </div><!-- 文章 -->
  43. </template>
  44. </el-table-column>
  45. <el-table-column :label="$t('ad.sort')" prop="id" align="center" :class-name="getSortClass('id')">
  46. <template slot-scope="{row}">
  47. <el-input
  48. v-model="row.SORT"
  49. min="0"
  50. max="99"
  51. @change="handleChangeSort(row.ID, row.SORT)"
  52. @click.native.stop=""
  53. />
  54. </template>
  55. </el-table-column>
  56. <el-table-column :label="$t('ad.creator')" prop="id" align="center" :class-name="getSortClass('id')">
  57. <template slot-scope="{row}">
  58. <span>{{ row.CREATE_ADMIN_NAME }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column :label="$t('ad.createTime')" align="center">
  62. <template slot-scope="{row}">
  63. <span>{{ row.CREATED_AT | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column :label="$t('ad.modifiedBy')" prop="id" align="center" width="80" :class-name="getSortClass('id')">
  67. <template slot-scope="{row}">
  68. <span>{{ row.UPDATE_ADMIN_NAME }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column :label="$t('ad.modifiedTime')" align="center">
  72. <template slot-scope="{row}">
  73. <span>{{ tool.formatDate(row.UPDATED_AT) }}</span>
  74. </template>
  75. </el-table-column>
  76. <el-table-column :label="$t('ad.status')" align="center"> <!-- 类型 -->
  77. <template slot-scope="{row}">
  78. <template v-if="row.STATUS === '1'">
  79. <el-tag type="success">show</el-tag> <!-- 外链 -->
  80. </template>
  81. <template v-else>
  82. <el-tag>hide</el-tag> <!-- 文章 -->
  83. </template>
  84. </template>
  85. </el-table-column>
  86. <el-table-column :label="$t('ad.action')" align="center">
  87. <template slot-scope="{row}">
  88. <el-dropdown v-if="permission.hasPermission(`ad/ad-delete`) || permission.hasPermission(`ad/edit`)" size="small" trigger="click">
  89. <el-button type="primary" size="small" @click.stop="">
  90. {{ $t('ad.action') }}<i class="el-icon-arrow-down el-icon--right" />
  91. </el-button>
  92. <el-dropdown-menu slot="dropdown">
  93. <el-dropdown-item v-if="permission.hasPermission(`ad/edit`)" command="edit" @click.native="handleEdit(row)">{{ $t('common.edit') }}</el-dropdown-item>
  94. <el-dropdown-item v-if="permission.hasPermission(`ad/ad-delete`)" command="delete" @click.native="handleDeleteOne(row)">{{ $t('common.delete') }}</el-dropdown-item>
  95. <el-dropdown-item v-if="permission.hasPermission(`ad/ad-hide`)" command="hide" @click.native="handleHideOne(row)">{{ $t('ad.hide') }}</el-dropdown-item>
  96. <el-dropdown-item v-if="permission.hasPermission(`ad/ad-un-hide`)" command="un-hide" @click.native="handleUnHideOne(row)">{{ $t('ad.unhide') }}</el-dropdown-item>
  97. </el-dropdown-menu>
  98. </el-dropdown>
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. <div class="white-box-footer">
  103. <el-dropdown v-if="permission.hasPermission(`ad/ad-delete`)" size="small">
  104. <el-button type="primary" size="small">
  105. {{ $t('ad.selectData') }}<i class="el-icon-arrow-down el-icon--right" />
  106. </el-button>
  107. <el-dropdown-menu slot="dropdown">
  108. <el-dropdown-item command="delete" @click.native="handleMuliDel()">{{ $t('table.delete') }}</el-dropdown-item>
  109. <el-dropdown-item command="hide" @click.native="handleMultiHide()">{{ $t('ad.hide') }}</el-dropdown-item>
  110. <el-dropdown-item command="un-hide" @click.native="handleMultiUnHide()">{{ $t('ad.unhide') }}</el-dropdown-item>
  111. </el-dropdown-menu>
  112. </el-dropdown>
  113. <el-button v-if="permission.hasPermission(`ad/ad-delete`)" type="primary" size="small" icon="el-icon-plus" @click="handleAdd">{{ $t('ad.add') }}</el-button>
  114. <pagination v-show="total>0" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
  115. </div>
  116. </div>
  117. </div>
  118. </template>
  119. <script>
  120. import { fetchAdList, fetchChangeSort, fetchDelete, fetchHide, fetchUnhide } from '@/api/ad'
  121. import waves from '@/directive/waves' // waves directive
  122. import { parseTime } from '@/utils'
  123. import tool from '@/utils/tool'
  124. import permission from '@/utils/permission'
  125. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  126. import ElementUI from 'element-ui'
  127. const calendarTypeOptions = [
  128. { key: 'CN', display_name: 'China' },
  129. { key: 'US', display_name: 'USA' }
  130. ]
  131. // arr to obj, such as { CN : "China", US : "USA" }
  132. const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
  133. acc[cur.key] = cur.display_name
  134. return acc
  135. }, {})
  136. export default {
  137. name: 'ComplexTable',
  138. components: { Pagination },
  139. directives: { waves },
  140. filters: {
  141. statusFilter(status) {
  142. const statusMap = {
  143. published: 'success',
  144. draft: 'info',
  145. deleted: 'danger'
  146. }
  147. return statusMap[status]
  148. },
  149. typeFilter(type) {
  150. return calendarTypeKeyValue[type]
  151. }
  152. },
  153. data() {
  154. return {
  155. tableKey: 0,
  156. list: null,
  157. total: 0,
  158. loading: true,
  159. listLoading: true,
  160. tool: tool,
  161. permission: permission,
  162. multipleSelection: null,
  163. pageSize: 20,
  164. listQuery: {
  165. page: 1,
  166. pageSize: 20,
  167. adId: null
  168. },
  169. changeSort: {
  170. id: null,
  171. sort: null
  172. },
  173. sort: null,
  174. importanceOptions: [1, 2, 3],
  175. calendarTypeOptions,
  176. sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
  177. statusOptions: ['published', 'draft', 'deleted'],
  178. showReviewer: false,
  179. temp: {
  180. id: undefined,
  181. importance: 1,
  182. remark: '',
  183. timestamp: new Date(),
  184. title: '',
  185. type: '',
  186. status: 'published'
  187. },
  188. dialogFormVisible: false,
  189. dialogStatus: '',
  190. textMap: {
  191. update: 'Edit',
  192. create: 'Create'
  193. },
  194. dialogPvVisible: false,
  195. pvData: [],
  196. rules: {
  197. type: [{ required: true, message: 'type is required', trigger: 'change' }],
  198. timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
  199. title: [{ required: true, message: 'title is required', trigger: 'blur' }]
  200. },
  201. downloadLoading: false,
  202. allArticle: [],
  203. allLocation: {
  204. LOCATION_NAME: null
  205. }
  206. }
  207. },
  208. created() {
  209. this.getList()
  210. },
  211. methods: {
  212. handleSelectionChange(val) {
  213. this.multipleSelection = val
  214. },
  215. handleSizeChange (pageSize) {
  216. this.getList(this.currentPage, pageSize)
  217. },
  218. handleCurrentChange (page) {
  219. this.getList(page, this.pageSize)
  220. },
  221. getList(page, pageSize) {
  222. this.listLoading = true
  223. this.listQuery.adId = this.$route.params
  224. this.listQuery.page = (page === null || page == undefined) ? 1 : page
  225. this.listQuery.pageSize = (pageSize === null || pageSize == undefined) ? this.pageSize : pageSize
  226. fetchAdList(this.listQuery).then(response => {
  227. this.list = response.data.list
  228. this.total = response.data.totalCount
  229. this.allArticle = response.data.allArticle
  230. const ad_id = this.listQuery.adId.ID
  231. this.allLocation = response.data.allLocation[ad_id]
  232. this.pageSize = pageSize
  233. // Just to simulate the time of the request
  234. setTimeout(() => {
  235. this.listLoading = false
  236. }, 1.5 * 1000)
  237. })
  238. },
  239. handleFilter() {
  240. this.listQuery.page = 1
  241. this.getList()
  242. },
  243. resetTemp() {
  244. this.temp = {
  245. id: undefined,
  246. importance: 1,
  247. remark: '',
  248. timestamp: new Date(),
  249. title: '',
  250. status: 'published',
  251. type: ''
  252. }
  253. },
  254. handleView(row) {
  255. this.$router.push(`/ad/list/${row.ID}`)
  256. },
  257. formatJson(filterVal) {
  258. return this.list.map(v => filterVal.map(j => {
  259. if (j === 'timestamp') {
  260. return parseTime(v[j])
  261. } else {
  262. return v[j]
  263. }
  264. }))
  265. },
  266. getSortClass: function(key) {
  267. const sort = this.listQuery.sort
  268. return sort === `+${key}` ? 'ascending' : 'descending'
  269. },
  270. handleChangeSort(id, sort) {
  271. this.changeSort.id = id
  272. this.changeSort.sort = sort
  273. fetchChangeSort(this.changeSort).then(response => {
  274. setTimeout(() => {
  275. this.listLoading = false
  276. }, 1.5 * 1000)
  277. })
  278. },
  279. getContent(aid) {
  280. const titles = this.allArticle.filter(article => article.ID === aid).map(article => article.TITLE)
  281. return titles.length > 0 ? titles[0] : aid
  282. },
  283. getHref(link) {
  284. return link.indexOf('http') > -1 ? link : 'http://' + link
  285. },
  286. handleEdit(row) {
  287. this.$router.push({ path: `/ad/edit/${row.ID}` })
  288. },
  289. handleAdd() {
  290. this.$router.push({ path: `/ad/add` })
  291. },
  292. handleMuliDel() {
  293. this.handleDelete()
  294. },
  295. handleMultiHide() {
  296. this.handleHide()
  297. },
  298. handleHideOne(row) {
  299. this.handleHide(row.ID)
  300. },
  301. handleMultiUnHide() {
  302. this.handleUnhide()
  303. },
  304. handleDeleteOne(row) {
  305. this.handleDelete(row.ID)
  306. },
  307. handleDelete(id = null) {
  308. const obj = this
  309. obj.$confirm(this.$t('common.deleteSelectedData'), this.$t('common.notice'), { // 确定删除选定的数据?
  310. confirmButtonText: this.$t('common.confirm'), // 确定
  311. cancelButtonText: this.$t('common.cancel'), // 取消
  312. type: 'warning'
  313. }).then(() => {
  314. const selectedIds = []
  315. if (id === null) {
  316. for (const val of obj.multipleSelection) {
  317. selectedIds.push(val.ID)
  318. }
  319. } else {
  320. selectedIds.push(id)
  321. }
  322. fetchDelete({ selected: selectedIds }).then(response => {
  323. this.$message({
  324. message: response.data,
  325. type: 'success'
  326. })
  327. obj.getList(obj.currentPage, obj.pageSize)
  328. }).catch((error) => {
  329. ElementUI.Message({type: 'error', message: error.message, showClose: true, duration: 0})
  330. })
  331. })
  332. },
  333. handleHide(id = null) {
  334. const obj = this
  335. obj.$confirm(this.$t('common.hideSelectedData'), this.$t('common.notice'), { // 确定删除选定的数据?
  336. confirmButtonText: 'confirm', // 确定
  337. cancelButtonText: 'cancel', // 取消
  338. type: 'warning'
  339. }).then(() => {
  340. const selectedIds = []
  341. if (id === null) {
  342. for (const val of obj.multipleSelection) {
  343. selectedIds.push(val.ID)
  344. }
  345. } else {
  346. selectedIds.push(id)
  347. }
  348. fetchHide({ selected: selectedIds }).then(response => {
  349. this.$message({
  350. message: response.data,
  351. type: 'success'
  352. })
  353. obj.getList(obj.currentPage, obj.pageSize)
  354. }).catch((error) => {
  355. ElementUI.Message({type: 'error', message: error.message, showClose: true, duration: 0})
  356. })
  357. })
  358. },
  359. handleUnHideOne(row) {
  360. this.handleUnhide(row.ID)
  361. },
  362. handleUnhide(id = null) {
  363. const obj = this
  364. obj.$confirm(this.$t('common.unHideSelectedData'), this.$t('common.notice'), { // 确定删除选定的数据?
  365. confirmButtonText: 'confirm', // 确定
  366. cancelButtonText: 'cancel', // 取消
  367. type: 'warning'
  368. }).then(() => {
  369. const selectedIds = []
  370. if (id === null) {
  371. for (const val of obj.multipleSelection) {
  372. selectedIds.push(val.ID)
  373. }
  374. } else {
  375. selectedIds.push(id)
  376. }
  377. fetchUnhide({ selected: selectedIds }).then(response => {
  378. this.$message({
  379. message: response.data,
  380. type: 'success'
  381. })
  382. obj.getList(obj.currentPage, obj.pageSize)
  383. }).catch((error) => {
  384. ElementUI.Message({type: 'error', message: error.message, showClose: true, duration: 0})
  385. })
  386. })
  387. }
  388. }
  389. }
  390. </script>