index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <schema-table
  9. ref="table"
  10. :schema="schema"
  11. />
  12. <streaming-media-dialog
  13. ref="addDialog"
  14. @done="onAdded"
  15. />
  16. <preview-dialog ref="previewDialog" />
  17. </wrapper>
  18. </template>
  19. <script>
  20. import {
  21. State,
  22. AssetTagInfo,
  23. AssetTag,
  24. AssetType
  25. } from '@/constant'
  26. import {
  27. getAssetsByQuery,
  28. updateAsset,
  29. deleteAsset,
  30. deleteAssets
  31. } from '@/api/asset'
  32. import StreamingMediaDialog from './components/StreamingMediaDialog.vue'
  33. export default {
  34. components: {
  35. StreamingMediaDialog
  36. },
  37. computed: {
  38. schema () {
  39. return {
  40. props: {
  41. 'row-class-name': 'u-pointer'
  42. },
  43. listeners: {
  44. 'row-click': this.onToggleSelection,
  45. 'selection-change': this.onSelectionChange
  46. },
  47. list: getAssetsByQuery,
  48. transform: this.transformAsset,
  49. condition: { type: AssetType.STREAMING_MEDIA },
  50. buttons: [
  51. { type: 'add', on: this.addStreamingMedia },
  52. { type: 'del', on: this.onBatchDel }
  53. ],
  54. filters: [
  55. { key: 'tag', type: 'select', placeholder: '类型', options: [
  56. { value: AssetTag.AD, label: AssetTagInfo[AssetTag.AD] },
  57. { value: AssetTag.PUBLICITY, label: AssetTagInfo[AssetTag.PUBLICITY] },
  58. { value: AssetTag.LOCAL_PUBLICITY, label: AssetTagInfo[AssetTag.LOCAL_PUBLICITY] },
  59. { value: AssetTag.SHIM, label: AssetTagInfo[AssetTag.SHIM] }
  60. ] },
  61. { key: 'originalName', type: 'search', placeholder: '资源名称' }
  62. ],
  63. cols: [
  64. { type: 'selection' },
  65. { prop: 'tagInfo', type: 'refresh', width: 80, 'align': 'center' },
  66. { prop: 'file', label: '资源', type: 'asset', on: this.onView },
  67. { render: (data, h) => h('edit-input', {
  68. props: {
  69. value: `${data.originalName}`
  70. },
  71. on: { edit: val => this.onEdit(data, val) }
  72. }), 'class-name': 'c-edit-column', 'min-width': 120 },
  73. { prop: 'userName', label: '添加人员', 'align': 'center', width: 120 },
  74. { prop: 'createTime', label: '添加时间', 'align': 'center', width: 160 },
  75. { type: 'invoke', render: [
  76. { label: '查看', on: this.onView },
  77. { label: '删除', allow: this.canDel, on: this.onDel }
  78. ], width: 100 }
  79. ]
  80. }
  81. }
  82. },
  83. methods: {
  84. transformAsset (asset) {
  85. asset.tagInfo = AssetTagInfo[asset.tag]
  86. return asset
  87. },
  88. onView ({ file }) {
  89. this.$refs.previewDialog.show(file)
  90. },
  91. onDel (asset) {
  92. deleteAsset(asset).then(() => {
  93. this.$refs.table.decrease(1)
  94. })
  95. },
  96. addStreamingMedia () {
  97. this.$refs.addDialog.show()
  98. },
  99. onAdded (streamingMedia) {
  100. this.$refs.table.resetCondition(streamingMedia)
  101. },
  102. onEdit (asset, { newVal, oldVal }) {
  103. if (newVal === oldVal) {
  104. return
  105. }
  106. if (!newVal) {
  107. this.$message({
  108. type: 'warning',
  109. message: '请填写资源名称'
  110. })
  111. return
  112. }
  113. asset.originalName = newVal
  114. updateAsset({
  115. keyName: asset.keyName,
  116. originalName: newVal
  117. }).catch(() => {
  118. asset.originalName = oldVal
  119. })
  120. },
  121. onBatchDel () {
  122. if (this.$selectionItems?.length) {
  123. deleteAssets(this.$selectionItems.map(({ keyName }) => keyName)).then(() => {
  124. this.$refs.table.decrease(this.$selectionItems.length)
  125. this.$selectionItems = null
  126. })
  127. } else {
  128. this.$message({
  129. type: 'warning',
  130. message: '请先选择需要删除的资源'
  131. })
  132. }
  133. },
  134. onToggleSelection (row) {
  135. if (row.status !== State.DRAFT) {
  136. this.$refs.table.getInst().toggleRowSelection(row)
  137. }
  138. },
  139. onSelectionChange (val) {
  140. this.$selectionItems = val
  141. }
  142. }
  143. }
  144. </script>