MediaDesigner.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <el-tabs
  9. :value="active"
  10. class="c-tabs has-bottom-padding"
  11. @tab-click="onTabClick"
  12. >
  13. <el-tab-pane
  14. v-for="tab in tabs"
  15. :key="tab.value"
  16. :label="tab.label"
  17. :name="tab.value"
  18. />
  19. </el-tabs>
  20. <schema-table
  21. ref="table"
  22. :key="active"
  23. :schema="schema"
  24. @row-click="onToggleSelection"
  25. @selection-change="onSelectionChange"
  26. />
  27. <streaming-media-dialog
  28. ref="addDialog"
  29. @done="onAdded"
  30. />
  31. <preview-dialog ref="previewDialog" />
  32. </wrapper>
  33. </template>
  34. <script>
  35. import {
  36. State,
  37. AssetType,
  38. AssetTypeInfo,
  39. AssetTag,
  40. AssetTagInfo
  41. } from '@/constant'
  42. import {
  43. parseByte,
  44. getAIState
  45. } from '@/utils'
  46. import {
  47. getAssetsWithDel,
  48. updateAsset,
  49. deleteAsset,
  50. deleteAssets
  51. } from '@/api/asset'
  52. import StreamingMediaDialog from './components/StreamingMediaDialog.vue'
  53. export default {
  54. name: 'MediaDesigner',
  55. components: {
  56. StreamingMediaDialog
  57. },
  58. data () {
  59. return {
  60. active: `${State.AVAILABLE_ASSET}`,
  61. tabs: [
  62. { value: `${State.AVAILABLE_ASSET}`, label: '待审核' },
  63. { value: `${State.RESOLVED}`, label: '已审核' },
  64. { value: `${State.REJECTED}`, label: '已驳回' }
  65. ]
  66. }
  67. },
  68. computed: {
  69. schema () {
  70. const active = Number(this.active)
  71. const isRejected = active === State.REJECTED
  72. return {
  73. buttons: [
  74. { type: 'add', label: `新增${AssetTypeInfo[AssetType.STREAMING_MEDIA]}`, on: this.addStreamingMedia },
  75. { type: 'del', on: this.onBatchDel }
  76. ],
  77. condition: { status: active, ...this.$condition },
  78. list: getAssetsWithDel,
  79. transform: this.transform,
  80. filters: [
  81. { key: 'tag', type: 'select', placeholder: '类型', options: [
  82. { value: AssetTag.AD, label: AssetTagInfo[AssetTag.AD] },
  83. { value: AssetTag.PUBLICITY, label: AssetTagInfo[AssetTag.PUBLICITY] },
  84. { value: AssetTag.LOCAL_PUBLICITY, label: AssetTagInfo[AssetTag.LOCAL_PUBLICITY] },
  85. { value: AssetTag.SHIM, label: AssetTagInfo[AssetTag.SHIM] }
  86. ] },
  87. { key: 'type', type: 'select', placeholder: '资源类型', options: [
  88. { value: AssetType.IMAGE, label: AssetTypeInfo[AssetType.IMAGE] },
  89. { value: AssetType.VIDEO, label: AssetTypeInfo[AssetType.VIDEO] },
  90. { value: AssetType.STREAMING_MEDIA, label: AssetTypeInfo[AssetType.STREAMING_MEDIA] },
  91. { value: AssetType.AUDIO, label: AssetTypeInfo[AssetType.AUDIO] },
  92. { value: AssetType.PPT, label: AssetTypeInfo[AssetType.PPT] },
  93. { value: AssetType.PDF, label: AssetTypeInfo[AssetType.PDF] },
  94. { value: AssetType.DOC, label: AssetTypeInfo[AssetType.DOC] }
  95. ] },
  96. { key: 'originalName', type: 'search', placeholder: '资源名称' }
  97. ],
  98. cols: [
  99. { type: 'selection', selectable: row => row.del },
  100. { prop: 'tagInfo', type: 'refresh', width: 80 },
  101. { prop: 'typeName', label: '资源', align: 'center', width: 80 },
  102. { prop: 'file', label: '', type: 'asset', on: this.onView },
  103. { prop: 'name', ...active === State.AVAILABLE_ASSET
  104. ? {
  105. render: (data, h) => h('edit-input', {
  106. model: {
  107. value: data.name,
  108. callback (val) {
  109. data.name = typeof val === 'string' ? val.trim() : val
  110. }
  111. },
  112. on: {
  113. edit: () => this.onEdit(data)
  114. }
  115. }),
  116. 'class-name': 'c-edit-column'
  117. }
  118. : null, 'min-width': 100 },
  119. active === State.RESOLVED ? null : { prop: 'ai', label: 'AI审核', type: 'tag' },
  120. isRejected ? { prop: 'remark', label: '驳回原因', 'align': 'right', 'min-width': 120 } : null,
  121. isRejected ? null : { prop: 'size', label: '资源大小', 'align': 'right' },
  122. isRejected ? null : { prop: 'diff', label: '其他', 'align': 'right' },
  123. isRejected ? null : { prop: 'createTime', label: '上传时间', 'align': 'right' },
  124. { type: 'invoke', render: [
  125. { label: '查看', allow: ({ status }) => status !== State.DRAFT, on: this.onView },
  126. { label: '删除', allow: ({ del }) => del, on: this.onDel }
  127. ] }
  128. ]
  129. }
  130. }
  131. },
  132. methods: {
  133. onTabClick ({ name: active }) {
  134. if (this.active !== active) {
  135. const { tag, type, originalName } = this.$refs.table.getCondition()
  136. this.$condition = { tag, type, originalName }
  137. this.active = active
  138. this.$selectionItems = null
  139. }
  140. },
  141. transform (asset) {
  142. asset.tagInfo = AssetTagInfo[asset.tag]
  143. asset.typeName = AssetTypeInfo[asset.type]
  144. asset.name = asset.originalName
  145. asset.size = parseByte(asset.size)
  146. asset.ai = getAIState(asset)
  147. return asset
  148. },
  149. onView ({ status, file }) {
  150. if (status === State.DRAFT) {
  151. this.$message({
  152. type: 'warning',
  153. message: '文件正在解析中,请稍后再试'
  154. })
  155. return
  156. }
  157. this.$refs.previewDialog.show(file)
  158. },
  159. onEdit (asset) {
  160. if (!asset.name) {
  161. asset.name = asset.originalName
  162. return
  163. }
  164. if (asset.name === asset.originalName) {
  165. return
  166. }
  167. updateAsset({
  168. keyName: asset.keyName,
  169. originalName: asset.name
  170. }).then(
  171. () => {
  172. asset.originalName = asset.name
  173. },
  174. () => {
  175. asset.name = asset.originalName
  176. }
  177. )
  178. },
  179. onDel (asset) {
  180. deleteAsset(asset).then(() => {
  181. this.$refs.table.decrease(1)
  182. })
  183. },
  184. addStreamingMedia () {
  185. this.$refs.addDialog.show()
  186. },
  187. onAdded (streamingMedia) {
  188. if (Number(this.active) === State.AVAILABLE_ASSET) {
  189. this.$refs.table.resetCondition(streamingMedia)
  190. }
  191. },
  192. onBatchDel () {
  193. if (this.$selectionItems?.length) {
  194. deleteAssets(this.$selectionItems.map(({ keyName }) => keyName)).then(() => {
  195. this.$refs.table.decrease(this.$selectionItems.length)
  196. this.$selectionItems = null
  197. })
  198. } else {
  199. this.$message({
  200. type: 'warning',
  201. message: '请先选择需要删除的资源'
  202. })
  203. }
  204. },
  205. onToggleSelection (row) {
  206. this.$refs.table.getInst().toggleRowSelection(row)
  207. },
  208. onSelectionChange (val) {
  209. this.$selectionItems = val
  210. }
  211. }
  212. }
  213. </script>