index.vue 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. <template>
  2. <div>
  3. <confirm-dialog
  4. ref="dialog"
  5. size="xl fixed"
  6. title="编辑模板"
  7. append-to-body
  8. @closed="onClosed"
  9. @confirm="onConfirm"
  10. >
  11. <template #default>
  12. <div class="l-flex__auto l-flex">
  13. <div class="l-flex__none l-flex--col c-viewer__asserts">
  14. <div class="l-flex__none l-flex--row c-viewer__count has-padding--h">
  15. <span class="l-flex__auto u-color--black u-font-size u-bold">
  16. 资源
  17. </span>
  18. <span class="l-flex__none u-color--info u-font-size--xs">
  19. {{ count }}
  20. </span>
  21. </div>
  22. <el-scrollbar
  23. class="l-flex__fill l-flex--col c-viewer__scrollbar"
  24. native
  25. >
  26. <div class="c-viewer__list">
  27. <div
  28. v-for="widget in layers"
  29. ref="widgetElements"
  30. :key="widget.id"
  31. class="c-sibling-item--v o-layer"
  32. :class="{ active: widget.id === selectedWidgetId }"
  33. @click="onWidgetClick(widget, $event)"
  34. >
  35. <widget-shortcut
  36. :widget="widget"
  37. @view="onView"
  38. />
  39. </div>
  40. <!-- 背景的设置-->
  41. <!-- <div-->
  42. <!-- v-if="hasRootAssets"-->
  43. <!-- ref="rootElement"-->
  44. <!-- key="root"-->
  45. <!-- class="c-sibling-item&#45;&#45;v o-layer"-->
  46. <!-- :class="{ active: !selectedWidgetId }"-->
  47. <!-- @click="onRootClick"-->
  48. <!-- >-->
  49. <!-- <widget-shortcut-->
  50. <!-- :widget="node"-->
  51. <!-- :custom-style="backgroundStyles"-->
  52. <!-- source-key="bgm"-->
  53. <!-- background-->
  54. <!-- @view="onView"-->
  55. <!-- />-->
  56. <!-- </div>-->
  57. </div>
  58. </el-scrollbar>
  59. </div>
  60. <div
  61. v-if="isMedia"
  62. class="l-flex__auto l-flex"
  63. >
  64. <directory-tree
  65. class="l-flex__none c-sibling-item c-sidebar u-width--md"
  66. style="display:none;"
  67. :class="{ mask: isStream }"
  68. :option="directoryOption"
  69. @change="onAssetDirectoryChanged"
  70. />
  71. <grid-table
  72. ref="table"
  73. class="l-flex__none c-sibling-item far"
  74. style="width: 496px;"
  75. size="large"
  76. :schema="schema"
  77. :custom="isDir"
  78. @changed="onTableRefresh"
  79. >
  80. <template #header>
  81. <template v-if="isDir">
  82. <div class="l-flex__fill l-flex--row u-height">
  83. <i
  84. class="l-flex__none o-icon o-icon--hover el-icon-arrow-left u-bold u-pointer"
  85. @click="fileDir = null"
  86. />
  87. <div class="l-flex__fill u-ellipsis u-bold">
  88. {{ fileDir.name }}
  89. </div>
  90. </div>
  91. </template>
  92. </template>
  93. <grid-table-item v-slot="item">
  94. <media-card
  95. :asset="item"
  96. @click="onToggleAsset"
  97. >
  98. <el-checkbox
  99. v-model="item.selected"
  100. class="o-card__checkbox"
  101. />
  102. <i
  103. class="o-card__play el-icon-video-play has-active"
  104. @click.stop="onViewAsset(item)"
  105. />
  106. <i
  107. v-if="item.file.files"
  108. class="o-card__grid el-icon-s-grid has-active"
  109. @click.stop="onViewDir(item)"
  110. />
  111. <div
  112. v-else
  113. class="o-card__info u-font-size--xs"
  114. >
  115. {{ item.diff }}
  116. </div>
  117. </media-card>
  118. </grid-table-item>
  119. <div
  120. v-if="isDir"
  121. class="l-flex__auto c-sibling-item--v u-overflow-y--auto"
  122. >
  123. <div class="l-flex__none l-grid large">
  124. <media-card
  125. v-for="file in fileDir.files"
  126. :key="file.keyName"
  127. :asset="file"
  128. @click="onToggleAsset"
  129. >
  130. <el-checkbox
  131. v-model="file.selected"
  132. class="o-card__checkbox"
  133. />
  134. <i
  135. class="o-card__play el-icon-video-play has-active"
  136. @click.stop="onViewAsset(file)"
  137. />
  138. </media-card>
  139. </div>
  140. </div>
  141. </grid-table>
  142. <div class="l-flex__none l-flex--row c-transfer-area">
  143. <el-button
  144. type="primary"
  145. size="mini"
  146. :disabled="!hasSelectionAssets"
  147. @click="onAddAssets"
  148. >
  149. <i class="el-icon-arrow-right" />
  150. </el-button>
  151. </div>
  152. <div class="l-flex__fill l-flex--col">
  153. <template v-if="assets.length">
  154. <div class="l-flex__none l-flex--row right c-sibling-item--v u-font-size--sm u-color-black u-bold">
  155. <div class="c-sibling-item">
  156. {{ resourceSize }}
  157. </div>
  158. <div class="c-sibling-item">
  159. {{ statistics }}
  160. </div>
  161. </div>
  162. <div
  163. v-if="options.durationEditable"
  164. class="l-flex__none l-flex--row right c-sibling-item--v"
  165. >
  166. <div class="c-sibling-item u-color--info u-font-size--sm">
  167. 图片统一上播时长(s)
  168. </div>
  169. <el-input-number
  170. v-model="duration"
  171. class="c-sibling-item u-width--xs"
  172. size="small"
  173. title="上播时长(s)"
  174. controls-position="right"
  175. :min="1"
  176. :max="86400"
  177. step-strictly
  178. />
  179. <div
  180. class="c-sibling-item near o-button"
  181. @click="onSetImageDuration"
  182. >
  183. 设置
  184. </div>
  185. </div>
  186. <draggable
  187. v-model="assets"
  188. class="l-flex__fill c-sibling-item--v u-font-size--sm u-overflow-y--auto"
  189. handle=".mover"
  190. animation="300"
  191. @change="onDragChange"
  192. @end="onDragEnd"
  193. >
  194. <div
  195. v-for="(asset, index) in assets"
  196. :key="asset.key"
  197. class="l-flex--row c-sibling-item--v near"
  198. >
  199. <el-input
  200. ref="input"
  201. v-model="inputValues[index]"
  202. :value="index"
  203. class="l-flex__none c-sibling-item u-width--3xs o-draggable-input"
  204. @focus="clearInput(index)"
  205. @blur="restoreInput(index, asset)"
  206. @keyup.enter.native="onTargetIndexInput(index, asset)"
  207. />
  208. <draggable-item
  209. class="l-flex__fill c-sibling-item near"
  210. :item="asset"
  211. @view="onViewAsset"
  212. @del="onDelAsset(index)"
  213. />
  214. </div>
  215. </draggable>
  216. </template>
  217. <el-empty
  218. v-else
  219. class="l-flex__auto l-flex--row center"
  220. description="请添加资源"
  221. />
  222. </div>
  223. </div>
  224. <div
  225. v-else
  226. class="l-flex__auto l-flex--col"
  227. style="margin-left: 16px;"
  228. >
  229. <toolbar
  230. style="border-bottom: 1px solid #ccc"
  231. mode="simple"
  232. :editor="editor"
  233. :default-config="toolbarConfig"
  234. />
  235. <editor
  236. v-model="selectedWidget.text"
  237. mode="simple"
  238. style="height: 500px; overflow: hidden;"
  239. :default-config="editorConfig"
  240. @onCreated="onEditorCreated"
  241. @customPaste="onCustomPaste"
  242. />
  243. </div>
  244. <!-- 放在底层,用截图封面图片-->
  245. <div
  246. ref="canvas"
  247. style="position: absolute;top:20px;left: 20px;z-index: -1;"
  248. class="l-flex__none"
  249. :style="canvasStyles"
  250. >
  251. <div
  252. class="c-viewer__canvas has-bg"
  253. :style="[transformStyles, styles]"
  254. >
  255. <div
  256. class="c-viewer__background has-bg"
  257. :style="backgroundStyles"
  258. />
  259. <widget
  260. v-for="item in widgets"
  261. :key="item.id"
  262. :node="item"
  263. />
  264. </div>
  265. </div>
  266. </div>
  267. </template>
  268. </confirm-dialog>
  269. <preview-dialog
  270. ref="previewDialog"
  271. @closed="onClosedPreview"
  272. />
  273. </div>
  274. </template>
  275. <script>
  276. import {
  277. State,
  278. AssetTag,
  279. AssetTagInfo,
  280. AssetType,
  281. AssetTypeInfo
  282. } from '@/constant'
  283. import {
  284. parseDuration,
  285. getAssetDuration
  286. } from '@/utils'
  287. import { getAssetsByQuery } from '@/api/asset'
  288. import Draggable from 'vuedraggable'
  289. import {
  290. getTemplateProgram, updateProgramDraft
  291. } from '@/api/program'
  292. import { WidgetType } from '@/views/screen/material/program/ast/core/constant'
  293. import WidgetShortcut from '@/views/screen/material/program/ast/components/WidgetShortcut'
  294. import {
  295. Editor,
  296. Toolbar
  297. } from '@wangeditor/editor-for-vue'
  298. import '@wangeditor/editor/dist/css/style.css'
  299. import domToImage from 'dom-to-image'
  300. import mixin2 from '@/views/screen/material/program/ast/mixin2'
  301. import Widget from '@/views/screen/material/program/ast/core/widget/WidgetViewer'
  302. import {
  303. fix, getDuration, getUsedAssets, toJSON
  304. } from '@/views/screen/material/program/ast/core/utils'
  305. export default {
  306. name: 'TemplateAssetChooseDialog',
  307. components: {
  308. Draggable,
  309. WidgetShortcut,
  310. Editor,
  311. Toolbar,
  312. Widget
  313. },
  314. mixins: [mixin2],
  315. props: {
  316. title: {
  317. type: String,
  318. default: ''
  319. },
  320. transform: {
  321. type: Function,
  322. default: null
  323. },
  324. choosen: {
  325. type: Function,
  326. default: null
  327. }
  328. },
  329. data () {
  330. return {
  331. snapping: false,
  332. canvasStyles: null,
  333. inputValues: [],
  334. lastIndex: 0,
  335. types: [],
  336. directoryOption: null,
  337. fileDir: null,
  338. assets: [],
  339. tableAssets: [],
  340. duration: 10,
  341. options: {},
  342. isStream: false,
  343. selectedWidget: null, //
  344. program: null,
  345. isMedia: true,
  346. editor: null,
  347. richHtml: '',
  348. toolbarConfig: {
  349. toolbarKeys: [
  350. 'headerSelect',
  351. '|',
  352. 'bold',
  353. // 'color',
  354. // '|',
  355. // 'fontSize',
  356. // 'lineHeight',
  357. '|',
  358. 'justifyLeft',
  359. 'justifyCenter',
  360. 'justifyRight'
  361. ]
  362. },
  363. editorConfig: {
  364. placeholder: '请输入内容...'
  365. }
  366. }
  367. },
  368. computed: {
  369. // dialogTitle () {
  370. // return this.title || (this.types.length > 1 ? '请选择资源' : `请选择${AssetTypeInfo[this.types[0]]}`)
  371. // },
  372. layers () {
  373. return this.widgets.filter(this.hasAssets).slice().reverse()
  374. },
  375. count () {
  376. if (this.node) {
  377. return this.layers.length
  378. }
  379. return 0
  380. },
  381. selectedWidgetId () {
  382. return this.selectedWidget?.id
  383. },
  384. hasRootAssets () {
  385. if (this.node) {
  386. const { backgroundImage, bgm } = this.node
  387. return backgroundImage.length > 0 || bgm.length > 0
  388. }
  389. return false
  390. },
  391. schema () {
  392. return {
  393. pagination: {
  394. layout: 'prev,pager,next'
  395. },
  396. list: this.getAssetsByQuery,
  397. transform: this.transformAsset,
  398. condition: {
  399. pageSize: 18,
  400. status: State.AVAILABLE,
  401. tag: '',
  402. type: this.types.length > 1 ? '' : this.types[0]
  403. },
  404. filters: [
  405. {
  406. key: 'tag', type: 'select', options: [
  407. { value: AssetTag.AD, label: AssetTagInfo[AssetTag.AD] },
  408. { value: AssetTag.PUBLICITY, label: AssetTagInfo[AssetTag.PUBLICITY] },
  409. { value: AssetTag.LOCAL_PUBLICITY, label: AssetTagInfo[AssetTag.LOCAL_PUBLICITY] },
  410. { value: AssetTag.SHIM, label: AssetTagInfo[AssetTag.SHIM] }
  411. ], placeholder: '资源分类'
  412. },
  413. this.types.length > 1
  414. ? {
  415. key: 'type', type: 'select', options: this.types.map(type => {
  416. return {
  417. value: type,
  418. label: AssetTypeInfo[type]
  419. }
  420. }), placeholder: '资源类型'
  421. }
  422. : null,
  423. { key: 'originalName', type: 'search', placeholder: '资源名称' }
  424. ].filter(Boolean),
  425. isStream: false
  426. }
  427. },
  428. isDir () {
  429. return !!this.fileDir
  430. },
  431. hasSelectionAssets () {
  432. return this.isDir
  433. ? this.fileDir.files.some(({ selected }) => selected)
  434. : this.tableAssets.some(({ selected }) => selected)
  435. },
  436. statistics () {
  437. const length = this.assets.length
  438. return `共${length}条,总时长 ${parseDuration(this.assets.reduce((total, { duration }) => total + duration, 0), false)}`
  439. },
  440. resourceSize () {
  441. const uniqueAssets = Array.from(new Set(this.assets.map(asset => asset.keyName)))
  442. .map(keyName => this.assets.find(asset => asset.keyName === keyName))
  443. const totalSizeMB = (uniqueAssets.reduce((total, item) => total + parseInt(item.size), 0) / (1024 * 1024))
  444. if (totalSizeMB >= 1024) {
  445. const totalSizeGB = totalSizeMB / 1024
  446. return `资源包大小: ${totalSizeGB.toFixed(2)} GB`
  447. }
  448. return `资源包大小: ${totalSizeMB.toFixed(2)} MB`
  449. },
  450. mediaTypes () {
  451. return this.types.filter(type => type !== AssetType.STREAMING_MEDIA)
  452. }
  453. },
  454. watch: {
  455. selectedWidget () {
  456. this.node && setTimeout(() => {
  457. if (this.selectedWidget) {
  458. this.$refs.widgetElements?.find(element => element.classList.contains('active'))
  459. ?.scrollIntoView({ behavior: 'smooth', block: 'start' })
  460. } else if (this.hasRootAssets) {
  461. this.$refs.rootElement.scrollIntoView({ behavior: 'smooth', block: 'start' })
  462. }
  463. })
  464. }
  465. },
  466. mounted () {
  467. this.types = [AssetType.IMAGE, AssetType.VIDEO, AssetType.PPT, AssetType.DOC, AssetType.PDF]
  468. this.updateInputValues()
  469. },
  470. methods: {
  471. checkRatio () {
  472. if (this.canvasStyles) {
  473. return
  474. }
  475. const { width, height } = this.node
  476. if (width <= 960 && height <= 540) {
  477. this.canvasStyles = {}
  478. } else {
  479. const wScale = 960 / width
  480. const hScale = 540 / height
  481. this.scale = Math.min(wScale, hScale) * 100 | 0
  482. if (wScale <= hScale) {
  483. this.canvasStyles = {
  484. width: '960px',
  485. height: `${height * wScale}px`
  486. }
  487. } else {
  488. this.canvasStyles = {
  489. width: `${width * hScale}px`,
  490. height: '540px'
  491. }
  492. }
  493. }
  494. },
  495. async test () {
  496. const base64 = await this.snap()
  497. if (base64) {
  498. const result = /^data:(.+);base64,(.+)$/.exec(base64)
  499. console.log('base64:', result[0])
  500. this.imageBase64 = result[0]
  501. }
  502. },
  503. snap () {
  504. this.snapping = true
  505. return domToImage.toJpeg(this.$refs.canvas, {
  506. filter (node) {
  507. const { tagName } = node
  508. if (tagName === 'CANVAS') {
  509. return /^data:.+;base64,.+/.test(node.toDataURL())
  510. }
  511. return tagName !== 'VIDEO' && tagName !== 'IFRAME'
  512. },
  513. width: this.node.width * this.scale / 100 | 0,
  514. height: this.node.height * this.scale / 100 | 0,
  515. quality: 0.1
  516. }).finally(() => {
  517. this.snapping = false
  518. })
  519. },
  520. onEditorCreated (editor) {
  521. this.editor = Object.seal(editor)
  522. },
  523. onCustomPaste (editor, event, callback) {
  524. // 返回 true ,继续默认的粘贴行为
  525. callback(true)
  526. this.$nextTick(() => {
  527. editor.setHtml(editor.getHtml()
  528. .replace(/text-indent[^;]+;/g, ''))
  529. })
  530. },
  531. onRichConfirm (done) {
  532. this.widget[this.widgetAttr.key] = this.richHtml
  533. done()
  534. },
  535. onDragChange () {
  536. console.log('onDragChange', this.assets)
  537. },
  538. onDragEnd () {
  539. console.log('onDragEnd:', this.assets)
  540. const sources = this.assets.map(this.transformAssetToData)
  541. this.selectedWidget.sources = sources
  542. },
  543. clearInput (index) {
  544. this.$set(this.inputValues, index, '')
  545. },
  546. restoreInput (index, asset) {
  547. if (this.inputValues[index] === '') {
  548. this.$set(this.inputValues, index, String(index + 1))
  549. } else {
  550. this.onTargetIndexInput(index, asset)
  551. }
  552. this.sortAssets()
  553. },
  554. sortAssets () {
  555. const inputValues = this.inputValues
  556. this.assets.sort((a, b) => {
  557. const indexA = parseInt(inputValues[this.assets.indexOf(a)])
  558. const indexB = parseInt(inputValues[this.assets.indexOf(b)])
  559. return indexA - indexB
  560. })
  561. this.updateInputValues()
  562. console.log('sortAssets', this.assets)
  563. },
  564. onTargetIndexInput (index, asset) {
  565. const inputValue = this.inputValues[index]
  566. let targetIndex = parseInt(inputValue) - 1
  567. if (isNaN(targetIndex)) {
  568. targetIndex = index
  569. }
  570. if (targetIndex < 0) {
  571. targetIndex = 0
  572. } else if (targetIndex >= this.assets.length) {
  573. targetIndex = this.assets.length - 1
  574. }
  575. this.assets.splice(index, 1)
  576. this.assets.splice(targetIndex, 0, asset)
  577. this.updateInputValues()
  578. },
  579. updateInputValues () {
  580. for (let i = 0; i < this.assets.length; i++) {
  581. const inputValue = (i + 1).toString()
  582. this.inputValues[i] = inputValue
  583. }
  584. },
  585. show (id) {
  586. const loading = this.$showLoading()
  587. getTemplateProgram(id)
  588. .then(({ data }) => {
  589. try {
  590. console.log('showProgram', data)
  591. console.log('itemJsonStr', JSON.parse(data.itemJsonStr))
  592. const { id, status, name, resolutionRatio, itemJsonStr } = data
  593. const [width, height] = resolutionRatio.split('x')
  594. if (!width || !height) {
  595. this.showMessage('error', '布局分辨率异常,请联系管理员')
  596. return
  597. }
  598. this.program = {
  599. id, status, name, resolutionRatio,
  600. detail: {
  601. width: Number(width),
  602. height: Number(height),
  603. ...JSON.parse(itemJsonStr)
  604. }
  605. }
  606. console.log('progam', this.program)
  607. this.initCanvas(this.program.detail)
  608. this.checkRatio()
  609. // 默认选中第一个
  610. const widget = this.layers[0]
  611. this.chooseWidget(widget)
  612. this.$refs.dialog.show()
  613. } catch (e) {
  614. console.log('catch:', e)
  615. this.showMessage('error', '布局解析失败')
  616. }
  617. })
  618. .finally(() => {
  619. this.$closeLoading(loading)
  620. })
  621. },
  622. showMessage (type, message) {
  623. this.$message({
  624. type,
  625. message
  626. })
  627. },
  628. // 使用右侧的文本编辑器
  629. showText (widget) {
  630. this.isMedia = false
  631. this.richHtml = widget.text
  632. },
  633. // 使用右侧图片视频选择器
  634. showMediaChoose (widget) {
  635. console.log('showMediaChoose', widget)
  636. const assets = widget.sources
  637. this.options = {
  638. duration: widget.interval || 10,
  639. durationEditable: !widget.sameInterval
  640. }
  641. this.assets = assets?.map(this.defaultTransform) || []
  642. this.updateInputValues()
  643. },
  644. defaultTransform (asset) {
  645. const data = this.transform ? this.transform(asset, this.options) : { ...asset }
  646. if (!data.key) {
  647. data.key = `${Date.now()}_${Math.random()
  648. .toString(16)
  649. .slice(2)}`
  650. }
  651. return data
  652. },
  653. onClosedPreview () {
  654. console.log('onClosedPreview')
  655. },
  656. onClosed () {
  657. this.fileDir = null
  658. this.assets = []
  659. this.tableAssets = []
  660. },
  661. onAssetDirectoryChanged (directory) {
  662. console.log('directory', directory)
  663. this.directoryOption = directory
  664. this.$emit('directory-changed', directory)
  665. // this.$refs.table?.pageTo(1)
  666. },
  667. getAssetsByQuery (params) {
  668. console.log('getAssetsByQuery', params)
  669. const { type, ...options } = params
  670. if (type === AssetType.STREAMING_MEDIA) {
  671. this.isStream = true
  672. return getAssetsByQuery({
  673. ...options,
  674. type
  675. })
  676. }
  677. this.isStream = false
  678. if (!this.directoryOption) {
  679. return Promise.resolve({ data: [] })
  680. }
  681. const { root, id, group: { path } } = this.directoryOption
  682. return getAssetsByQuery({
  683. ...options,
  684. ...(root
  685. ? { org: path }
  686. : { treeId: id, queryRelation: '1' }),
  687. typeList: type ? [type] : [...this.mediaTypes]
  688. })
  689. },
  690. transformAsset ({ tag, type, originalName, keyName, duration, size, md5, file, diff }) {
  691. return {
  692. tag,
  693. type,
  694. name: originalName,
  695. keyName,
  696. size,
  697. md5,
  698. duration,
  699. selected: false,
  700. file,
  701. diff
  702. }
  703. },
  704. transformAssetToData ({ tag, type, name, keyName, duration, size, md5, file }) {
  705. const source = {
  706. tag,
  707. type,
  708. name,
  709. keyName,
  710. size,
  711. md5,
  712. duration
  713. }
  714. if (file.thumb && keyName !== file.thumb) {
  715. source.thumb = file.thumb
  716. }
  717. return source
  718. },
  719. onTableRefresh (assets) {
  720. this.tableAssets = assets
  721. },
  722. onChoosenAsset (asset) {
  723. console.log('onChoosenAsset', asset)
  724. if (this.choosen) {
  725. this.choosen(asset)
  726. .then(() => {
  727. this.$refs.dialog.hide()
  728. })
  729. } else {
  730. this.$refs.dialog.hide()
  731. }
  732. },
  733. onToggleAsset (asset) {
  734. asset.selected = !asset.selected
  735. },
  736. onViewAsset ({ file }) {
  737. // this.$emit('view', asset)
  738. this.onView(file)
  739. },
  740. onViewDir ({ name, file: { files } }) {
  741. this.fileDir = {
  742. name,
  743. files: files.map(({ tag, type, keyName, size, md5, sort }) => {
  744. return {
  745. tag,
  746. type,
  747. name: `第${sort + 1}页`,
  748. keyName,
  749. size,
  750. md5,
  751. sort,
  752. selected: false,
  753. file: {
  754. type,
  755. url: keyName
  756. }
  757. }
  758. })
  759. }
  760. },
  761. onAddAssets () {
  762. if (this.isDir) {
  763. this.onAddDirAssets(this.fileDir)
  764. return
  765. }
  766. this.tableAssets.forEach(asset => {
  767. if (asset.selected) {
  768. if (asset.file.files) {
  769. this.onAddDirAssets({
  770. name: asset.name,
  771. files: asset.file.files
  772. }, true)
  773. } else {
  774. this.onAddAsset(asset)
  775. }
  776. asset.selected = false
  777. }
  778. })
  779. },
  780. onAddAsset (asset) {
  781. const { duration, durationEditable } = this.options
  782. console.log('this.options.', this.options)
  783. const { tag, type, name, keyName, size, md5, file } = asset
  784. this.assets.push({
  785. tag,
  786. type,
  787. keyName,
  788. name,
  789. size,
  790. md5,
  791. file,
  792. duration: getAssetDuration(asset, duration),
  793. key: `${Date.now()}_${Math.random()
  794. .toString(16)
  795. .slice(2)}`,
  796. disabled: !durationEditable || type === AssetType.VIDEO || type === AssetType.AUDIO,
  797. info: `${AssetTagInfo[tag]} ${AssetTypeInfo[type]}`
  798. })
  799. // 将先的资源传给sources,左侧更新UI
  800. const sources = this.assets.map(this.transformAssetToData)
  801. this.selectedWidget.sources = sources
  802. this.updateInputValues()
  803. },
  804. onAddDirAssets (fileDir, force) {
  805. const { name: dirName, files } = fileDir
  806. files.forEach(asset => {
  807. if (force) {
  808. this.onAddDirAsset(asset, dirName)
  809. } else if (asset.selected) {
  810. this.onAddDirAsset(asset, dirName)
  811. asset.selected = false
  812. }
  813. })
  814. },
  815. onAddDirAsset (asset, dirName) {
  816. const { duration, durationEditable } = this.options
  817. const { tag, type, keyName, size, md5, sort } = asset
  818. this.assets.push({
  819. tag,
  820. type,
  821. keyName,
  822. name: `${dirName}第${sort + 1}页`,
  823. size,
  824. md5,
  825. duration,
  826. disabled: !durationEditable,
  827. key: `${Date.now()}_${Math.random()
  828. .toString(16)
  829. .slice(2)}`,
  830. info: `${AssetTagInfo[tag]} ${AssetTypeInfo[type]}`,
  831. file: {
  832. type,
  833. url: keyName
  834. }
  835. })
  836. },
  837. onDelAsset (index) {
  838. this.assets.splice(index, 1)
  839. this.selectedWidget.sources = this.assets
  840. },
  841. onConfirm (done) {
  842. // 检查资源
  843. const { ready, message } = fix(this.node)
  844. if (!ready) {
  845. this.$message({
  846. type: 'error',
  847. message
  848. })
  849. return
  850. }
  851. // 输入名字
  852. this.$prompt(
  853. '<p class="u-color--black u-font-size--sm u-bold">请输入节目名称</p>',
  854. '保存节目',
  855. {
  856. dangerouslyUseHTMLString: true,
  857. closeOnClickModal: false,
  858. inputValue: '模板名字',
  859. inputPlaceholder: '请输入节目名称',
  860. inputPattern: /^.{0,30}$/,
  861. inputErrorMessage: '最多30个字符',
  862. confirmButtonText: '保存',
  863. cancelButtonText: '取消'
  864. }
  865. ).then(({ value }) => {
  866. console.log('value', value)
  867. const loading = this.$showLoading()
  868. setTimeout(() => {
  869. // 不太确定这个options的作用
  870. this._save({ name: value, generate: true }, done).finally(() => {
  871. this.$closeLoading(loading)
  872. })
  873. }, 100)
  874. }).catch(() => {
  875. console.log('cancel')
  876. })
  877. },
  878. // 这里参照的是src/views/screen/material/program/ast/Designer.vue
  879. async _save (options, done) {
  880. console.log('options', options)
  881. try {
  882. const base64 = await this.snap()
  883. console.log('base64:', base64)
  884. const result = await updateProgramDraft({
  885. id: this.program.id,
  886. duration: getDuration(this.node),
  887. itemJsonStr: JSON.stringify(toJSON(this.node)),
  888. keyNameList: getUsedAssets(this.node),
  889. base64,
  890. ...options
  891. })
  892. if (result) {
  893. this.$message({
  894. type: 'success',
  895. message: '保存成功'
  896. })
  897. // 关闭
  898. done()
  899. } else {
  900. this.$message({
  901. type: 'warning',
  902. message: '保存失败'
  903. })
  904. }
  905. } catch (e) {
  906. console.warn(e)
  907. this.$message({
  908. type: 'warning',
  909. message: '保存失败'
  910. })
  911. }
  912. },
  913. onSetImageDuration () {
  914. const duration = this.duration
  915. this.assets.forEach(asset => {
  916. const { type, disabled } = asset
  917. if (!disabled && type === AssetType.IMAGE) {
  918. asset.duration = duration
  919. }
  920. })
  921. },
  922. hasAssets (widget) {
  923. switch (widget.type) {
  924. case WidgetType.MEDIA:
  925. case WidgetType.IMAGE:
  926. case WidgetType.VIDEO:
  927. case WidgetType.TEXT:
  928. return true
  929. default:
  930. return false
  931. }
  932. },
  933. onView (source) {
  934. // this.$muted = this.muted
  935. // switch (source.type) {
  936. // case AssetType.VIDEO:
  937. // case AssetType.AUDIO:
  938. // if (!this.muted) {
  939. // this.muted = true
  940. // }
  941. // break
  942. // default:
  943. // break
  944. // }
  945. console.log('onView:', source)
  946. this.$refs.previewDialog.show(source)
  947. },
  948. onWidgetClick (widget, evt) {
  949. console.log('onWidgetClick', widget)
  950. evt.stopPropagation()
  951. this.chooseWidget(widget)
  952. },
  953. chooseWidget (widget) {
  954. if (!this.selectedWidget || this.selectedWidget !== widget) {
  955. this.selectedWidget = widget
  956. console.log('selectedWidget:', widget)
  957. if (this.selectedWidget.type === 'CText') {
  958. this.isMedia = false
  959. this.showText(widget)
  960. } else {
  961. this.isMedia = true
  962. this.showMediaChoose(widget)
  963. }
  964. }
  965. }
  966. }
  967. }
  968. </script>
  969. <style lang="scss" scoped>
  970. .c-viewer {
  971. &__header {
  972. height: $height--md;
  973. line-height: 1;
  974. }
  975. &__wrapper {
  976. position: absolute;
  977. top: 0;
  978. left: $spacing;
  979. right: $font-size--xl + 2 * $padding--lg;
  980. height: 100%;
  981. }
  982. &__asserts {
  983. width: 160px;
  984. border-right: 1px solid $border;
  985. background-color: #fff;
  986. }
  987. &__count {
  988. height: $height--md;
  989. line-height: 1;
  990. background-color: #e8eaee;
  991. }
  992. &__scrollbar {
  993. ::v-deep {
  994. .el-scrollbar__wrap {
  995. flex: 1 1 0;
  996. min-height: 0;
  997. margin-bottom: 0 !important;
  998. }
  999. }
  1000. }
  1001. &__list {
  1002. padding: $padding;
  1003. }
  1004. &__canvas {
  1005. position: relative;
  1006. background-color: #000;
  1007. overflow: hidden;
  1008. }
  1009. &__background {
  1010. position: absolute;
  1011. top: 0;
  1012. left: 0;
  1013. right: 0;
  1014. bottom: 0;
  1015. background-color: currentColor;
  1016. z-index: -1;
  1017. }
  1018. }
  1019. .mask {
  1020. position: relative;
  1021. &::after {
  1022. content: "";
  1023. position: absolute;
  1024. top: 0;
  1025. left: 0;
  1026. right: $spacing;
  1027. bottom: 0;
  1028. background-color: rgba(#000, 0.6);
  1029. }
  1030. }
  1031. .o-card {
  1032. &__checkbox {
  1033. position: absolute;
  1034. top: 10px;
  1035. left: 10px;
  1036. pointer-events: none;
  1037. z-index: 9;
  1038. }
  1039. &__play {
  1040. position: absolute;
  1041. top: 50%;
  1042. left: 50%;
  1043. padding: 2px;
  1044. font-size: 24px;
  1045. border-radius: 50%;
  1046. background-color: rgba(#000, 0.4);
  1047. transform: translate(-50%, -50%);
  1048. }
  1049. &__grid {
  1050. position: absolute;
  1051. top: 10px;
  1052. right: 10px;
  1053. font-size: 18px;
  1054. z-index: 9;
  1055. }
  1056. &__info {
  1057. position: absolute;
  1058. top: 10px;
  1059. right: 10px;
  1060. z-index: 9;
  1061. }
  1062. }
  1063. .c-transfer-area {
  1064. padding: 0 $spacing;
  1065. margin: 0 $spacing;
  1066. border-left: 1px solid $border;
  1067. border-right: 1px solid $border;
  1068. }
  1069. .c-transfer-area {
  1070. padding: 0 $spacing;
  1071. margin: 0 $spacing;
  1072. border-left: 1px solid $border;
  1073. border-right: 1px solid $border;
  1074. }
  1075. .c-textfield-area {
  1076. padding: 0 $spacing;
  1077. margin: 0 $spacing;
  1078. border-left: 1px solid $border;
  1079. }
  1080. .o-draggable-input {
  1081. ::v-deep .el-input__inner {
  1082. text-align: center;
  1083. padding: 0 $padding--sm;
  1084. }
  1085. }
  1086. .o-layer {
  1087. color: $black;
  1088. user-select: none;
  1089. border-radius: $radius;
  1090. background-color: #f4f7f8;
  1091. overflow: hidden;
  1092. cursor: pointer;
  1093. &.active {
  1094. color: #fff;
  1095. outline: 2px solid $blue;
  1096. background-color: $blue;
  1097. }
  1098. }
  1099. </style>