materialSelector.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. <template>
  2. <div
  3. class="table-select"
  4. :class="isDarkTheme ? '' : 'bright'"
  5. >
  6. <span class="title">{{ title }}</span>
  7. <div class="close-btn"><i class="iconfont icon-pop-ups_shut-down" @click="$emit('cancle')"></i></div>
  8. <div class="material-tab">
  9. <a
  10. v-if="selectableType.includes('image')"
  11. class="material-tab-item"
  12. @click.prevent="currentMaterialType = 'image'"
  13. >
  14. <span :class="{ active: currentMaterialType === 'image' }" class="text">
  15. {{ $i18n.t(`gather.image`) }}
  16. </span>
  17. <div v-if="currentMaterialType === 'image'" class="bottom-line"></div>
  18. </a>
  19. <a
  20. v-if="selectableType.includes('pano')"
  21. class="material-tab-item"
  22. @click.prevent="currentMaterialType = 'pano'"
  23. >
  24. <span :class="{ active: currentMaterialType === 'pano' }" class="text">
  25. {{ $i18n.t(`gather.panorama`) }}
  26. </span>
  27. <div v-if="currentMaterialType === 'pano'" class="bottom-line"></div>
  28. </a>
  29. <a
  30. v-if="selectableType.includes('audio')"
  31. class="material-tab-item"
  32. @click.prevent="currentMaterialType = 'audio'"
  33. >
  34. <span :class="{ active: currentMaterialType === 'audio' }" class="text">
  35. {{ $i18n.t(`gather.audio`) }}
  36. </span>
  37. <div v-if="currentMaterialType === 'audio'" class="bottom-line"></div>
  38. </a>
  39. <a
  40. v-if="selectableType.includes('video')"
  41. class="material-tab-item"
  42. @click.prevent="currentMaterialType = 'video'"
  43. >
  44. <span :class="{ active: currentMaterialType === 'video' }" class="text">
  45. {{ $i18n.t(`gather.video`) }}
  46. </span>
  47. <div v-if="currentMaterialType === 'video'" class="bottom-line"></div>
  48. </a>
  49. <a
  50. v-if="selectableType.includes('3D')"
  51. class="material-tab-item"
  52. @click.prevent="currentMaterialType = '3D'"
  53. >
  54. <span :class="{ active: currentMaterialType === '3D' }" class="text">
  55. {{ $i18n.t(`gather.scene`) }}
  56. </span>
  57. <div v-if="currentMaterialType === '3D'" class="bottom-line"></div>
  58. </a>
  59. </div>
  60. <div
  61. class="filter"
  62. :class="{active: isSearchKeyInputActive}"
  63. >
  64. <input
  65. type="text"
  66. :placeholder="$i18n.t('gather.keywords')"
  67. v-model="searchKey"
  68. @focus="isSearchKeyInputActive = true"
  69. @blur="isSearchKeyInputActive = false"
  70. />
  71. <i v-if="!searchKey" class="iconfont icon-editor_search search-icon" />
  72. <i v-if="searchKey" @click="searchKey=''" class="iconfont icontoast_red clear-icon"></i>
  73. </div>
  74. <MaterialList
  75. v-if="selectableType.includes('pano')"
  76. v-show="currentMaterialType === 'pano'"
  77. :isDarkTheme="isDarkTheme"
  78. :currentMaterialType="currentMaterialType"
  79. :materialType="'pano'"
  80. :tableHeaderKeyList="['icon', 'name']"
  81. :isMultiSelection="isMultiSelection"
  82. :select="select"
  83. :searchKey="searchKey"
  84. :canUpload="true"
  85. :fileInputCustomCheck="checkPanoFileInput"
  86. :fileUploadLongPollingCb="panoUploadLongPolling"
  87. :fileUploadLongPollingStatusText="$i18n.t(`gather.cutting`)"
  88. :fileInputBtnTip="$i18n.t(`gather.pano_size`)"
  89. :fileInputFailString="$i18n.t(`gather.pano_fail`)"
  90. :fileInputLimitFailStr="$i18n.t(`gather.pano_limit`)"
  91. :fileInputAcceptType="'image/jpeg'"
  92. :fileInputMediaType="'image'"
  93. :fileInputLimit="120"
  94. @need-clear-filter="() => {searchKey = ''}"
  95. >
  96. <template
  97. v-slot:materialUploadSuccessIcon="slotProps"
  98. >
  99. <img
  100. :src="slotProps.uploadInfo.successInfo[slotProps.tableItemStructure.key] + (Number(slotProps.uploadInfo.fileSize) > 512 ? $imgsuffix : ``)"
  101. alt=""
  102. />
  103. </template>
  104. <template
  105. v-slot:materialUploadingIcon
  106. >
  107. <img
  108. src="@/assets/images/icons/upload-file-type-icon-image@2x.png"
  109. style="object-fit: contain;"
  110. alt=""
  111. >
  112. </template>
  113. <template
  114. v-slot:materialUploadFailIcon
  115. >
  116. <img
  117. src="@/assets/images/icons/upload-file-type-icon-image@2x.png"
  118. style="object-fit: contain;"
  119. | alt=""
  120. >
  121. </template>
  122. <template
  123. v-slot:materialIcon="slotProps"
  124. >
  125. <img
  126. :src="slotProps.materialInfo[slotProps.tableItemStructure.key] + (Number(slotProps.materialInfo.fileSize) > 512 ? $imgsuffix : ``)"
  127. alt=""
  128. />
  129. </template>
  130. </MaterialList>
  131. <MaterialList
  132. v-if="selectableType.includes('image')"
  133. v-show="currentMaterialType === 'image'"
  134. :isDarkTheme="isDarkTheme"
  135. :currentMaterialType="currentMaterialType"
  136. :materialType="'image'"
  137. :tableHeaderKeyList="['icon', 'name']"
  138. :isMultiSelection="isMultiSelection"
  139. :select="select"
  140. :searchKey="searchKey"
  141. :canUpload="true"
  142. :fileInputBtnTip="$i18n.t(`gather.img_size`)"
  143. :fileInputFailString="$i18n.t(`gather.img_fail`)"
  144. :fileInputLimitFailStr="$i18n.t(`gather.img_limit`)"
  145. :fileInputAcceptType="'image/png,image/jpeg'"
  146. :fileInputMediaType="'image'"
  147. :fileInputLimit="10"
  148. @need-clear-filter="() => {searchKey = ''}"
  149. >
  150. <template
  151. v-slot:materialUploadSuccessIcon="slotProps"
  152. >
  153. <img
  154. :src="slotProps.uploadInfo.successInfo[slotProps.tableItemStructure.key] + (Number(slotProps.uploadInfo.fileSize) > 512 ? $imgsuffix : ``)"
  155. alt=""
  156. />
  157. </template>
  158. <template
  159. v-slot:materialUploadingIcon
  160. >
  161. <img
  162. src="@/assets/images/icons/upload-file-type-icon-image@2x.png"
  163. style="object-fit: contain;"
  164. alt=""
  165. >
  166. </template>
  167. <template
  168. v-slot:materialUploadFailIcon
  169. >
  170. <img
  171. src="@/assets/images/icons/upload-file-type-icon-image@2x.png"
  172. style="object-fit: contain;"
  173. alt=""
  174. >
  175. </template>
  176. <template
  177. v-slot:materialIcon="slotProps"
  178. >
  179. <img
  180. :src="slotProps.materialInfo[slotProps.tableItemStructure.key] + (Number(slotProps.materialInfo.fileSize) > 512 ? $imgsuffix : ``)"
  181. alt=""
  182. />
  183. </template>
  184. </MaterialList>
  185. <MaterialList
  186. v-if="selectableType.includes('audio')"
  187. v-show="currentMaterialType === 'audio'"
  188. :isDarkTheme="isDarkTheme"
  189. :currentMaterialType="currentMaterialType"
  190. :materialType="'audio'"
  191. :tableHeaderKeyList="['ossPath', 'name']"
  192. :isMultiSelection="isMultiSelection"
  193. :select="select"
  194. :searchKey="searchKey"
  195. :canUpload="true"
  196. :fileInputBtnTip="$i18n.t(`gather.audio_size`)"
  197. :fileInputFailString="$i18n.t(`gather.audio_fail`)"
  198. :fileInputLimitFailStr="$i18n.t(`gather.audio_limit`)"
  199. :fileInputAcceptType="'audio/mp3'"
  200. :fileInputMediaType="'audio'"
  201. :fileInputLimit="20"
  202. @need-clear-filter="() => {searchKey = ''}"
  203. >
  204. <template
  205. v-slot:materialUploadSuccessIcon="slotProps"
  206. >
  207. <AudioIconCanPlay
  208. class="audio-player"
  209. :vKey="slotProps.uploadInfo.successInfo.id"
  210. :idleft="`_${$randomWord(true, 8, 8)}`"
  211. :idright="`_${$randomWord(true, 8, 8)}`"
  212. :myAudioUrl="slotProps.uploadInfo.successInfo.ossPath"
  213. />
  214. </template>
  215. <template
  216. v-slot:materialUploadingIcon
  217. >
  218. <img
  219. :src="require('@/assets/images/icons/upload-file-type-icon-audio@2x.png')"
  220. style="object-fit: contain;"
  221. alt=""
  222. >
  223. </template>
  224. <template
  225. v-slot:materialUploadFailIcon
  226. >
  227. <img
  228. :src="require('@/assets/images/icons/upload-file-type-icon-audio@2x.png')"
  229. style="object-fit: contain;"
  230. alt=""
  231. >
  232. </template>
  233. <template
  234. v-slot:materialIcon="slotProps"
  235. >
  236. <AudioIconCanPlay
  237. class="audio-player"
  238. :vKey="slotProps.materialInfo.id"
  239. :idleft="`_${$randomWord(true, 8, 8)}`"
  240. :idright="`_${$randomWord(true, 8, 8)}`"
  241. :myAudioUrl="slotProps.materialInfo.ossPath"
  242. />
  243. </template>
  244. </MaterialList>
  245. <MaterialList
  246. v-if="selectableType.includes('video')"
  247. v-show="currentMaterialType === 'video'"
  248. :isDarkTheme="isDarkTheme"
  249. :currentMaterialType="currentMaterialType"
  250. :materialType="'video'"
  251. :materialItemCustomProcess="(item) => {item.icon = process.env.VUE_APP_ORIGIN == 'aws' ? item.icon : (item.ossPath + '?x-oss-process=video/snapshot,t_0,f_jpg,w_89,h_50,m_fast,ar_auto');}"
  252. :tableHeaderKeyList="['icon', 'name']"
  253. :isMultiSelection="isMultiSelection"
  254. :select="select"
  255. :searchKey="searchKey"
  256. :canUpload="true"
  257. :fileInputBtnTip="$i18n.t(`gather.video_size`)"
  258. :fileInputFailString="$i18n.t(`gather.video_fail`)"
  259. :fileInputLimitFailStr="$i18n.t(`gather.video_limit`)"
  260. :fileInputAcceptType="'video/mp4'"
  261. :fileInputMediaType="'video'"
  262. :fileInputLimit="200"
  263. @need-clear-filter="() => {searchKey = ''}"
  264. >
  265. <template
  266. v-slot:materialUploadSuccessIcon="slotProps"
  267. >
  268. <img
  269. :src="slotProps.uploadInfo.successInfo[slotProps.tableItemStructure.key] + (Number(slotProps.uploadInfo.fileSize) > 512 ? $imgsuffix : ``)"
  270. alt=""
  271. />
  272. </template>
  273. <template
  274. v-slot:materialUploadingIcon
  275. >
  276. <img
  277. src="@/assets/images/icons/upload-file-type-icon-video@2x.png"
  278. style="object-fit: contain;"
  279. alt=""
  280. >
  281. </template>
  282. <template
  283. v-slot:materialUploadFailIcon
  284. >
  285. <img
  286. src="@/assets/images/icons/upload-file-type-icon-video@2x.png"
  287. style="object-fit: contain;"
  288. alt=""
  289. >
  290. </template>
  291. <template
  292. v-slot:materialIcon="slotProps"
  293. >
  294. <img
  295. :src="slotProps.materialInfo[slotProps.tableItemStructure.key] + (Number(slotProps.materialInfo.fileSize) > 512 ? $imgsuffix : ``)"
  296. alt=""
  297. />
  298. </template>
  299. </MaterialList>
  300. <MaterialList
  301. v-if="selectableType.includes('3D')"
  302. v-show="currentMaterialType === '3D'"
  303. :isDarkTheme="isDarkTheme"
  304. :currentMaterialType="currentMaterialType"
  305. :materialType="'3D'"
  306. :workId="workId"
  307. :tableHeaderKeyList="['thumb', 'sceneName']"
  308. :isMultiSelection="isMultiSelection"
  309. :select="select"
  310. :searchKey="searchKey"
  311. @need-clear-filter="() => {searchKey = ''}"
  312. >
  313. <template
  314. v-slot:materialIcon="slotProps"
  315. >
  316. <img
  317. :src="slotProps.materialInfo[slotProps.tableItemStructure.key] + (Number(slotProps.materialInfo.fileSize) > 512 ? $imgsuffix : ``)"
  318. alt=""
  319. />
  320. </template>
  321. </MaterialList>
  322. <div class="btns">
  323. <button
  324. class="ui-button"
  325. :class="isDarkTheme ? 'deepcancel' : 'cancel'"
  326. @click="$emit('cancle')"
  327. >{{ $i18n.t("gather.cancel") }}</button>
  328. <button class="ui-button submit" :class="{ disable: !select.length }" @click="onClickComfirm">
  329. {{ $i18n.t("gather.comfirm"), }}
  330. </button>
  331. </div>
  332. </div>
  333. </template>
  334. <script>
  335. import { mapMutations, } from "vuex";
  336. import MaterialList from "./materialListInMaterialSelector.vue";
  337. import AudioIconCanPlay from "@/components/audio/indexForEditor.vue";
  338. import { getImgWH, changeByteUnit } from "@/utils/file";
  339. import { debounce } from "@/utils/other.js"
  340. import {
  341. checkMStatus,
  342. } from "@/api";
  343. export default {
  344. components: {
  345. MaterialList,
  346. AudioIconCanPlay,
  347. },
  348. props: {
  349. isDarkTheme: {
  350. type: Boolean,
  351. default: true,
  352. },
  353. title: {
  354. default: '',
  355. type: String
  356. },
  357. selectableType: {
  358. type: Array,
  359. default: function() {
  360. return [
  361. 'image',
  362. 'pano',
  363. 'audio',
  364. 'video',
  365. '3D',
  366. ]
  367. },
  368. },
  369. initialMaterialType: {
  370. type: String,
  371. default: 'image',
  372. },
  373. isMultiSelection: {
  374. type: Boolean,
  375. default: false,
  376. },
  377. workId: {
  378. type: String,
  379. default: '',
  380. },
  381. },
  382. data () {
  383. return {
  384. select: [],
  385. isSearchKeyInputActive: false,
  386. searchKey: '', // 搜索关键词
  387. latestUsedSearchKey: '',
  388. currentMaterialType: this.initialMaterialType,
  389. }
  390. },
  391. watch: {
  392. },
  393. methods: {
  394. ...mapMutations([
  395. 'clearUploadStatusLists',
  396. ]),
  397. async checkPanoFileInput(eachFile, i) {
  398. let WHRate = null
  399. try {
  400. const { width, height } = await getImgWH(eachFile)
  401. WHRate = width / height
  402. } catch (e) {
  403. console.error('获取图像宽高失败:', e)
  404. setTimeout(() => {
  405. this.$msg({
  406. message: `“${eachFile.name}”${this.$i18n.t(`gather.pano_fail`)}`,
  407. type: "warning",
  408. });
  409. }, i * 100);
  410. return false
  411. }
  412. if (WHRate !== 2) {
  413. console.log('宽高比不对!');
  414. setTimeout(() => {
  415. this.$msg({
  416. message: `“${eachFile.name}”${this.$i18n.t(`gather.pano_fail`)}`,
  417. type: "warning",
  418. });
  419. }, i * 100);
  420. return false
  421. } else {
  422. console.log(WHRate);
  423. return true
  424. }
  425. },
  426. panoUploadLongPolling(uploadStatusList) {
  427. let needPollingTaskList = uploadStatusList.filter((item) => item.status === 'LOADING' && item.ifKnowProgress === false);
  428. if (needPollingTaskList.length > 0) {
  429. checkMStatus(
  430. {
  431. ids: needPollingTaskList.map((item) => item.backendId),
  432. islongpolling: true,
  433. },
  434. (res) => {
  435. // 1切图中,2失败,3成功
  436. res.data.forEach(eachRes => {
  437. if (eachRes.status === 2) {
  438. const index = uploadStatusList.findIndex(eachTask => eachTask.backendId === eachRes.id)
  439. if (index >= 0) {
  440. const targetItem = uploadStatusList[index]
  441. targetItem.status = 'FAIL'
  442. targetItem.statusText = this.$i18n.t(`gather.material_cutting_fail`)
  443. targetItem.ifKnowProgress = true
  444. }
  445. } else if (eachRes.status === 3) {
  446. const index = uploadStatusList.findIndex(eachTask => eachTask.backendId === eachRes.id)
  447. if (index >= 0) {
  448. const targetItem = uploadStatusList[index]
  449. targetItem.status = 'SUCCESS'
  450. if (eachRes.fileSize) {
  451. eachRes.fileSize = changeByteUnit(Number(eachRes.fileSize));
  452. } else {
  453. eachRes.fileSize = ''
  454. }
  455. targetItem.successInfo = eachRes
  456. }
  457. }
  458. });
  459. }
  460. );
  461. }
  462. },
  463. onClickComfirm: debounce(function () {
  464. this.$emit('submit', this.select)
  465. }, 250),
  466. },
  467. mounted() {
  468. this.clearUploadStatusLists()
  469. },
  470. }
  471. </script>
  472. <style lang="less" scoped>
  473. .table-select {
  474. position: absolute;
  475. z-index: 3;
  476. left: 50%;
  477. top: 50%;
  478. transform: translateX(-50%) translateY(-50%);
  479. width: 600px;
  480. height: 730px;
  481. background: #1A1B1D;
  482. border-radius: 4px;
  483. border: 1px solid #404040;
  484. padding: 26px;
  485. .title {
  486. font-size: 18px;
  487. color: rgba(255, 255, 255, 0.6);
  488. }
  489. .close-btn {
  490. display: inline-block;
  491. position: absolute;
  492. top: 26px;
  493. right: 20px;
  494. font-size: 12px;
  495. color: #969799;
  496. cursor: pointer;
  497. padding: 6px;
  498. }
  499. .material-tab {
  500. margin-top: 35px;
  501. > .material-tab-item {
  502. display: inline-block;
  503. margin-right: 20px;
  504. position: relative;
  505. cursor: pointer;
  506. > .text {
  507. font-size: 14px;
  508. font-family: MicrosoftYaHei;
  509. color: rgba(255, 255, 255, 0.6);
  510. &.active {
  511. color: #fff;
  512. }
  513. }
  514. > .bottom-line {
  515. position: absolute;
  516. left: 50%;
  517. transform: translateX(-50%);
  518. bottom: -4px;
  519. width: 16px;
  520. height: 2px;
  521. background: #0076F6;
  522. border-radius: 1px;
  523. }
  524. }
  525. }
  526. .filter {
  527. margin-top: 28px;
  528. width: 100%;
  529. height: 36px;
  530. background: #252526;
  531. border-radius: 2px;
  532. border: 1px solid #404040;
  533. position: relative;
  534. &.active {
  535. border: 1px solid @color;
  536. }
  537. > input {
  538. box-sizing: border-box;
  539. width: calc(100% - 42px);
  540. height: 100%;
  541. border: none;
  542. padding-left: 16px;
  543. background: transparent;
  544. color: #fff;
  545. outline: none;
  546. }
  547. > input::placeholder,
  548. textarea::placeholder {
  549. font-size: 14px;
  550. color: #505050 !important;
  551. }
  552. > .search-icon {
  553. position: absolute;
  554. top: 50%;
  555. transform: translateY(-50%);
  556. right: 18px;
  557. color: #404040;
  558. font-size: 20px;
  559. }
  560. > .clear-icon {
  561. position: absolute;
  562. top: 50%;
  563. transform: translateY(-50%);
  564. right: 18px;
  565. color: #404040;
  566. font-size: 20px;
  567. cursor: pointer;
  568. }
  569. }
  570. .btns {
  571. position: absolute;
  572. right: 26px;
  573. bottom: 26px;
  574. button:first-child {
  575. margin-right: 16px;
  576. }
  577. }
  578. }
  579. .table-select.bright {
  580. border: 1px solid #EBEDF0;
  581. background: #fff;
  582. .title {
  583. color: #323233;
  584. }
  585. .close-btn {
  586. }
  587. .material-tab {
  588. > .material-tab-item {
  589. > .text {
  590. color: #969799;
  591. &.active {
  592. color: #323233;
  593. }
  594. }
  595. > .bottom-line {
  596. }
  597. }
  598. }
  599. .filter {
  600. background: #F7F8FA;
  601. border: 1px solid #EBEDF0;
  602. > input {
  603. color: #323233;
  604. }
  605. > input::placeholder,
  606. textarea::placeholder {
  607. font-size: 14px;
  608. color: #C8C9CC !important;
  609. }
  610. > .search-icon {
  611. color: #C8C9CC;
  612. }
  613. > .clear-icon {
  614. color: #C8C9CC;
  615. }
  616. }
  617. .btns {
  618. }
  619. }
  620. </style>