mixin.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import {
  2. getAssetsWithDel,
  3. updateAsset,
  4. deleteAsset,
  5. submitAsset
  6. } from '@/api/asset'
  7. import {
  8. State,
  9. AssetType
  10. } from '@/constant'
  11. import {
  12. createListOptions,
  13. parseByte,
  14. parseDuration
  15. } from '@/utils'
  16. export default {
  17. props: {
  18. status: {
  19. type: Number,
  20. default: State.AVAILABLE_ASSET
  21. }
  22. },
  23. data () {
  24. return {
  25. type: AssetType.IMAGE,
  26. active: `${this.status}`,
  27. [AssetType.IMAGE]: {
  28. [State.AVAILABLE_ASSET]: createListOptions({ type: AssetType.IMAGE, status: State.AVAILABLE_ASSET }),
  29. [State.RESOLVED]: createListOptions({ type: AssetType.IMAGE, status: State.RESOLVED, originalName: '' }),
  30. [State.REJECTED]: createListOptions({ type: AssetType.IMAGE, status: State.REJECTED })
  31. },
  32. [AssetType.VIDEO]: {
  33. [State.AVAILABLE_ASSET]: createListOptions({ type: AssetType.VIDEO, status: State.AVAILABLE_ASSET }),
  34. [State.RESOLVED]: createListOptions({ type: AssetType.VIDEO, status: State.RESOLVED, originalName: '' }),
  35. [State.REJECTED]: createListOptions({ type: AssetType.VIDEO, status: State.REJECTED })
  36. },
  37. [AssetType.AUDIO]: {
  38. [State.AVAILABLE_ASSET]: createListOptions({ type: AssetType.AUDIO, status: State.AVAILABLE_ASSET }),
  39. [State.RESOLVED]: createListOptions({ type: AssetType.AUDIO, status: State.RESOLVED, originalName: '' }),
  40. [State.REJECTED]: createListOptions({ type: AssetType.AUDIO, status: State.REJECTED })
  41. }
  42. }
  43. },
  44. computed: {
  45. schema () {
  46. return {
  47. list: getAssetsWithDel,
  48. transform: this.transform,
  49. filters: this.active === `${State.RESOLVED}`
  50. ? [
  51. { key: 'originalName', type: 'search', placeholder: '媒资名称' }
  52. ]
  53. : [],
  54. cols: [
  55. { prop: 'file', type: 'asset', on: this.onViewAsset },
  56. { prop: 'name', 'min-width': 100, render: this.active === `${State.AVAILABLE_ASSET}`
  57. ? (data, h) => data.del
  58. ? h('edit-input', {
  59. model: {
  60. value: data.name,
  61. callback (val) {
  62. data.name = typeof val === 'string' ? val.trim() : val
  63. }
  64. },
  65. on: {
  66. edit: () => this.onEdit(data)
  67. }
  68. })
  69. : data.name
  70. : null },
  71. this.active === `${State.REJECTED}` ? { prop: 'remark', label: '驳回原因' } : null,
  72. this.isImage ? null : { prop: 'duration', label: '时长' },
  73. { prop: 'size', label: '文件大小' },
  74. { prop: 'createTime', label: '上传时间' },
  75. { prop: 'ai', label: 'AI审核', type: 'tag', width: 100 },
  76. { type: 'invoke', align: 'center', width: 140, render: [
  77. { label: '查看', on: this.onView },
  78. // canEdit ? { label: '提交', on: this.onSubmit } : null,
  79. { label: '删除', render ({ del }) { return del }, on: this.onDel }
  80. ] }
  81. ]
  82. }
  83. },
  84. currOptions: {
  85. get () {
  86. return this[this.type][this.active]
  87. },
  88. set (val) {
  89. this[this.type][this.active] = val
  90. }
  91. },
  92. isImage () {
  93. return this.type === AssetType.IMAGE
  94. },
  95. isVideo () {
  96. return this.type === AssetType.VIDEO
  97. },
  98. isAudio () {
  99. return this.type === AssetType.AUDIO
  100. }
  101. },
  102. methods: {
  103. adjustHeader ({ column }) {
  104. return column.property === 'name' && this.isAudio ? 'o-media-name' : ''
  105. },
  106. transform (asset) {
  107. asset.name = asset.originalName
  108. asset.file = {
  109. type: asset.type,
  110. url: asset.keyName,
  111. thumbnail: asset.thumbnail
  112. }
  113. asset.duration = parseDuration(asset.duration)
  114. asset.size = parseByte(asset.size)
  115. asset.ai = this.getAIState(asset)
  116. return asset
  117. },
  118. getAIState ({ aiAuditState: status, aiAuditMsg: msg }) {
  119. switch (status) {
  120. case 1:
  121. return {
  122. type: 'danger',
  123. label: '不合规'
  124. }
  125. case 2:
  126. return {
  127. type: 'warning',
  128. label: '疑似',
  129. msg
  130. }
  131. case 3:
  132. return {
  133. type: 'info',
  134. label: '审核失败',
  135. msg
  136. }
  137. case 4:
  138. case 5:
  139. case 6:
  140. return {
  141. type: 'primmary',
  142. label: '审核中'
  143. }
  144. case 7:
  145. return {
  146. type: 'success',
  147. label: '通过'
  148. }
  149. case 8:
  150. return {
  151. type: 'info',
  152. label: '无法审核',
  153. msg
  154. }
  155. case 9:
  156. return {
  157. type: 'info',
  158. label: '未开启'
  159. }
  160. default:
  161. return null
  162. }
  163. },
  164. to (type) {
  165. if (this.type !== AssetType[type]) {
  166. this.type = null
  167. this.$nextTick(() => {
  168. this.type = AssetType[type]
  169. })
  170. }
  171. },
  172. onView ({ file }) {
  173. this.onViewAsset(file)
  174. },
  175. onViewAsset (asset) {
  176. this.$refs.previewDialog.show(asset)
  177. },
  178. onEdit (asset) {
  179. if (!asset.name) {
  180. asset.name = asset.originalName
  181. return
  182. }
  183. if (asset.name === asset.originalName) {
  184. return
  185. }
  186. updateAsset({
  187. keyName: asset.keyName,
  188. originalName: asset.name
  189. }).then(
  190. () => {
  191. asset.originalName = asset.name
  192. },
  193. () => {
  194. asset.name = asset.originalName
  195. }
  196. )
  197. },
  198. onSubmit (asset) {
  199. submitAsset(asset).then(() => {
  200. this.$refs.table.decrease(1)
  201. })
  202. },
  203. onDel (asset) {
  204. deleteAsset(asset).then(() => {
  205. this.$refs.table.decrease(1)
  206. })
  207. }
  208. }
  209. }