| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <template>
- <wrapper
- fill
- margin
- padding
- background
- >
- <schema-table
- ref="table"
- :schema="schema"
- />
- <streaming-media-dialog
- ref="addDialog"
- @done="onAdded"
- />
- <preview-dialog ref="previewDialog" />
- </wrapper>
- </template>
- <script>
- import {
- State,
- AssetTagInfo,
- AssetTag,
- AssetType
- } from '@/constant'
- import {
- getAssetsByQuery,
- updateAsset,
- deleteAsset,
- deleteAssets
- } from '@/api/asset'
- import StreamingMediaDialog from './components/StreamingMediaDialog.vue'
- export default {
- components: {
- StreamingMediaDialog
- },
- computed: {
- schema () {
- return {
- props: {
- 'row-class-name': 'u-pointer'
- },
- listeners: {
- 'row-click': this.onToggleSelection,
- 'selection-change': this.onSelectionChange
- },
- list: getAssetsByQuery,
- transform: this.transformAsset,
- condition: { type: AssetType.STREAMING_MEDIA },
- buttons: [
- { type: 'add', on: this.addStreamingMedia },
- { type: 'del', on: this.onBatchDel }
- ],
- filters: [
- { key: 'tag', type: 'select', placeholder: '类型', options: [
- { value: AssetTag.AD, label: AssetTagInfo[AssetTag.AD] },
- { value: AssetTag.PUBLICITY, label: AssetTagInfo[AssetTag.PUBLICITY] },
- { value: AssetTag.LOCAL_PUBLICITY, label: AssetTagInfo[AssetTag.LOCAL_PUBLICITY] },
- { value: AssetTag.SHIM, label: AssetTagInfo[AssetTag.SHIM] }
- ] },
- { key: 'originalName', type: 'search', placeholder: '资源名称' }
- ],
- cols: [
- { type: 'selection' },
- { prop: 'tagInfo', type: 'refresh', width: 80, 'align': 'center' },
- { prop: 'file', label: '资源', type: 'asset', on: this.onView },
- { render: (data, h) => h('edit-input', {
- props: {
- value: `${data.originalName}`
- },
- on: { edit: val => this.onEdit(data, val) }
- }), 'class-name': 'c-edit-column', 'min-width': 120 },
- { prop: 'userName', label: '添加人员', 'align': 'center', width: 120 },
- { prop: 'createTime', label: '添加时间', 'align': 'center', width: 160 },
- { type: 'invoke', render: [
- { label: '查看', on: this.onView },
- { label: '删除', allow: this.canDel, on: this.onDel }
- ], width: 100 }
- ]
- }
- }
- },
- methods: {
- transformAsset (asset) {
- asset.tagInfo = AssetTagInfo[asset.tag]
- return asset
- },
- onView ({ file }) {
- this.$refs.previewDialog.show(file)
- },
- onDel (asset) {
- deleteAsset(asset).then(() => {
- this.$refs.table.decrease(1)
- })
- },
- addStreamingMedia () {
- this.$refs.addDialog.show()
- },
- onAdded (streamingMedia) {
- this.$refs.table.resetCondition(streamingMedia)
- },
- onEdit (asset, { newVal, oldVal }) {
- if (newVal === oldVal) {
- return
- }
- if (!newVal) {
- this.$message({
- type: 'warning',
- message: '请填写资源名称'
- })
- return
- }
- asset.originalName = newVal
- updateAsset({
- keyName: asset.keyName,
- originalName: newVal
- }).catch(() => {
- asset.originalName = oldVal
- })
- },
- onBatchDel () {
- if (this.$selectionItems?.length) {
- deleteAssets(this.$selectionItems.map(({ keyName }) => keyName)).then(() => {
- this.$refs.table.decrease(this.$selectionItems.length)
- this.$selectionItems = null
- })
- } else {
- this.$message({
- type: 'warning',
- message: '请先选择需要删除的资源'
- })
- }
- },
- onToggleSelection (row) {
- if (row.status !== State.DRAFT) {
- this.$refs.table.getInst().toggleRowSelection(row)
- }
- },
- onSelectionChange (val) {
- this.$selectionItems = val
- }
- }
- }
- </script>
|