index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <template>
  2. <div class="panorama con">
  3. <div class="top">
  4. <crumbs :list="folderPath" @click-path="onClickPath" />
  5. </div>
  6. <div class="second-line">
  7. <div class="btn">
  8. <button @mouseover.stop="showList = true" @click="onUploadFile" class="ui-button submit">
  9. <span>{{ upload_material }}</span>
  10. <i class="iconfont icon-material_prompt hover-tips hover-tips-upload-icon">
  11. <div>
  12. <div class="remark">{{ pano_size }}</div>
  13. </div>
  14. </i>
  15. <upload ref="uploadFile" :failString="pano_fail" :limitFailStr="pano_limit" accept-type=".jpg"
  16. media-type="image" :limit="120" @file-change="onFileChange"></upload>
  17. </button>
  18. </div>
  19. <button
  20. class="ui-button submit"
  21. @click="isShowNewFolder = true"
  22. >
  23. {{$i18n.t(`gather.new_folder`)}}
  24. </button>
  25. <button
  26. class="ui-button cancel"
  27. :class="{disable: selectedList.length === 0}"
  28. @click="onClickMoveFolder"
  29. >
  30. {{$i18n.t(`gather.move_folder`)}}
  31. </button>
  32. <div class="filter">
  33. <div :class="{ active: isFilterFocus }" @focusin="onFilterFocus" @focusout="onFilterBlur">
  34. <i class="iconfont icon-works_search search"></i>
  35. <input type="text" v-model="searchKey" :placeholder="serch_material" />
  36. <i v-if="searchKey" @click="searchKey = ''" class="iconfont icontoast_red del"></i>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="list">
  41. <tableList
  42. @selection-change="
  43. (data) => {
  44. selectedList = data;
  45. }
  46. "
  47. @request-more-data="getMoreMaterialItem"
  48. :canRequestMoreData="hasMoreData && !isRequestingMoreData"
  49. :header="tabHeader"
  50. :showLine="true"
  51. :selection="true"
  52. :data="list"
  53. class="table-list"
  54. ref="table-list"
  55. >
  56. <!-- 插到tableList组件各个header插槽,并通过插槽的headerItem作用域拿到表头各项 -->
  57. <div slot-scope="{ headerItem }" slot="header">
  58. {{ headerItem.name && $i18n.t(`zh_key.${headerItem.name}`) }}
  59. </div>
  60. <!-- 内容各单元格 -->
  61. <div slot-scope="{ itemData, lineData, headerItem }" slot="tableItem" style="width: 100%">
  62. <!-- 操作型单元格 -->
  63. <div class="handle" v-if="headerItem.canclick">
  64. <i
  65. v-if="lineData.type !== 'dir'"
  66. class="iconfont icon-material_operation_image hover-tips"
  67. @click="(showCover = true), (popupItem = lineData)"
  68. >
  69. <div>
  70. <div class="remark">{{ edit_cover }}</div>
  71. </div>
  72. </i>
  73. <i
  74. class="iconfont icon-material_operation_editor hover-tips"
  75. @click="onClickRename(lineData)"
  76. >
  77. <div>
  78. <div class="remark">{{ rename }}</div>
  79. </div>
  80. </i>
  81. <i
  82. class="iconfont icon-material_operation_delete hover-tips-warn"
  83. @click="del(lineData)"
  84. >
  85. <div>
  86. <div class="remark">{{ deltips }}</div>
  87. </div>
  88. </i>
  89. </div>
  90. <!-- 图片型单元格 -->
  91. <div
  92. v-else-if="headerItem.type == 'image' && lineData.type !== 'dir'"
  93. class="img"
  94. @click="previewImage(lineData)"
  95. >
  96. <img :src="itemData + (Number(lineData.fileSize) > 512 ? $imgsuffix : '')"
  97. alt="" />
  98. </div>
  99. <div
  100. v-else-if="headerItem.type == 'image' && lineData.type === 'dir'"
  101. class="img dirIcon"
  102. >
  103. <img
  104. :src="require('@/assets/images/icons/folder-blue.png')"
  105. alt=""
  106. @click="onClickFolder(lineData)"
  107. />
  108. </div>
  109. <span
  110. v-else-if="headerItem.key == 'name' && lineData.type !== 'dir'"
  111. class="textItem"
  112. style="cursor: pointer;"
  113. @click="previewImage(lineData)"
  114. >
  115. {{ itemData || "-" }}
  116. </span>
  117. <span
  118. v-else-if="headerItem.key === 'name' && lineData.type === 'dir'"
  119. class="textItem dirName"
  120. @click="onClickFolder(lineData)"
  121. >
  122. {{ itemData || "-" }}
  123. </span>
  124. <!-- 文字型单元格 -->
  125. <span
  126. v-else
  127. class="textItem"
  128. >
  129. {{ itemData || "-" }}
  130. </span>
  131. </div>
  132. </tableList>
  133. <UploadTaskList class="upload-task-list" fileType="IMAGE" :taskList="uploadListForUI" :targetFolderId="currentFolderId" @cancel-task="onCancelTask">
  134. </UploadTaskList>
  135. <div class="total-number" v-if="list.length !== 0 || hasMoreData">{{ had_load }}</div>
  136. <div class="nodata" v-if="list.length == 0 && !hasMoreData && lastestUsedSearchKey">
  137. <img :src="$noresult" alt="" />
  138. <span>{{ no_serch_result }}</span>
  139. </div>
  140. <div class="nodata" v-if="list.length == 0 && !hasMoreData && !lastestUsedSearchKey">
  141. <img :src="config.empty" alt="" />
  142. <span>{{ no_material_result }}</span>
  143. <button @click="$refs.uploadFile.click()" class="upload-btn-in-table">{{ upload_material }}</button>
  144. </div>
  145. </div>
  146. <CreateFolder
  147. v-if="isShowNewFolder"
  148. :validate=validateNewFolderName
  149. @close="isShowNewFolder = false"
  150. @submit="onSubmitNewFolder"
  151. />
  152. <RenameFolder
  153. v-if="isShowRenameFolder"
  154. :oldName="popupItem.name"
  155. :validate=validateRenameFolderName
  156. @close="isShowRenameFolder = false"
  157. @submit="onSubmitRenameFolder"
  158. />
  159. <MoveFolder
  160. v-if="isShowMoveFolder"
  161. :folderTree="folderTree"
  162. :selectedList="selectedList"
  163. @close="isShowMoveFolder = false"
  164. @submit="onSubmitMoveFolder"
  165. />
  166. <rename
  167. v-if="showRename"
  168. :item="popupItem"
  169. @rename="handleRename"
  170. @close="showRename = false"
  171. />
  172. <preview
  173. ref="image-previewer"
  174. :sceneCodeList="list.map(item => item.sceneCode)"
  175. :imageTitleList="list.map(item => item.name)"
  176. @click-delete="onClickDeleteInPreview"
  177. />
  178. <cover
  179. @panocover="handlePanoCover"
  180. :item="popupItem"
  181. v-if="showCover"
  182. @close="showCover = false"
  183. />
  184. </div>
  185. </template>
  186. <script>
  187. import config from "@/config";
  188. import tableList from "@/components/table/index.vue";
  189. import crumbs from "@/components/crumbs/index.vue";
  190. import { data } from "./pano";
  191. import rename from "../popup/rename";
  192. import preview from "../popup/panoImagePreviewer.vue";
  193. import cover from "../popup/cover";
  194. import Upload from "@/components/shared/uploads/UploadMultiple";
  195. import { getImgWH, changeByteUnit } from "@/utils/file";
  196. import UploadTaskList from "../components/uploadList1.1.0.vue";
  197. import { debounce } from "@/utils/other.js"
  198. import { mapState } from 'vuex';
  199. import { i18n } from "@/lang"
  200. import folderMixinFactory from "../folderMixinFactory.js";
  201. import {
  202. getMaterialList,
  203. uploadMaterial,
  204. editMaterial,
  205. delMaterial,
  206. uploadCover,
  207. checkMStatus,
  208. checkUserSize
  209. } from "@/api";
  210. const TYPE = "pano";
  211. const LONG_POLLING_INTERVAL = 5;
  212. const folderMixin = folderMixinFactory(TYPE)
  213. export default {
  214. mixins: [
  215. folderMixin,
  216. ],
  217. name: 'Pano',
  218. components: {
  219. tableList,
  220. crumbs,
  221. rename,
  222. cover,
  223. preview,
  224. Upload,
  225. UploadTaskList,
  226. },
  227. data() {
  228. return {
  229. upload_material: i18n.t("gather.upload_material"),
  230. serch_material: i18n.t("gather.serch_material"),
  231. no_serch_result: i18n.t("gather.no_serch_result"),
  232. no_material_result: i18n.t("gather.no_material_result"),
  233. pano_size: i18n.t("gather.pano_size"),
  234. pano_fail: i18n.t("gather.pano_fail"),
  235. pano_limit: i18n.t("gather.pano_limit"),
  236. edit_cover: i18n.t("gather.edit_cover"),
  237. rename: i18n.t("gather.rename"),
  238. deltips: i18n.t("gather.delete"),
  239. config,
  240. showRename: false,
  241. showCover: false,
  242. showList: false,
  243. popupItem: null,
  244. tabHeader: data,
  245. // 因为searchKey的变化经过debounce、异步请求的延时,才会反映到数据列表的变化上,所以是否显示、显示哪种无数据提示,也要等到数据列表变化后,根据数据列表是否为空,以及引发本次变化的那个searchKey瞬时值来决定。本变量就是用来保存那个瞬时值。
  246. lastestUsedSearchKey: '',
  247. isFilterFocus: false,
  248. searchKey: "",
  249. list: [],
  250. hasMoreData: true,
  251. isRequestingMoreData: false,
  252. };
  253. },
  254. computed: {
  255. ...mapState({
  256. uploadListForUI: 'uploadStatusListPano',
  257. }),
  258. needLongPolling() {
  259. return this.uploadListForUI.some((item) => {
  260. return item.status === 'LOADING' && item.ifKnowProgress === false
  261. })
  262. },
  263. had_load() {
  264. return i18n.t("gather.had_load", { msg: this.list.length })
  265. }
  266. },
  267. mounted() {
  268. },
  269. watch: {
  270. needLongPolling: {
  271. handler: function (newVal) {
  272. if (!newVal) {
  273. this.clearinter();
  274. } else {
  275. this.clearinter();
  276. this.interval = setInterval(() => {
  277. this._checkMStatus();
  278. }, LONG_POLLING_INTERVAL * 1000);
  279. }
  280. },
  281. immediate: true,
  282. },
  283. searchKey: {
  284. handler: function () {
  285. this.refreshListDebounced()
  286. },
  287. immediate: false,
  288. },
  289. },
  290. methods: {
  291. onUploadFile() {
  292. checkUserSize({}, (data) => {
  293. //判断已用是否大于3G
  294. if ((data.data / 1024 / 1024) > 3) {
  295. this.$alert({ content: i18n.t("tips_code.FAILURE_3024") });
  296. } else {
  297. this.$refs.uploadFile.click()
  298. }
  299. })
  300. },
  301. onFilterFocus() {
  302. this.isFilterFocus = true
  303. },
  304. onFilterBlur() {
  305. this.isFilterFocus = false
  306. },
  307. refreshListDebounced: debounce(function () {
  308. this.list = []
  309. this.isRequestingMoreData = false
  310. this.hasMoreData = true
  311. this.$refs['table-list'].requestMoreData()
  312. }, 700, true),
  313. clearinter() {
  314. this.interval && clearInterval(this.interval);
  315. this.interval = null;
  316. },
  317. handleRename(newName) {
  318. editMaterial(
  319. {
  320. id: this.popupItem.id,
  321. name: newName,
  322. },
  323. () => {
  324. this.$msg.success(i18n.t("gather.edit_success"));
  325. const index = this.list.findIndex((eachItem) => {
  326. return eachItem.id === this.popupItem.id
  327. })
  328. if (index >= 0) {
  329. this.list[index].name = newName
  330. } else {
  331. console.error('在素材列表里没找到要重命名的那一项!');
  332. }
  333. this.showRename = false;
  334. this.popupItem = null;
  335. }
  336. );
  337. },
  338. handlePanoCover(data) {
  339. if (data.indexOf("http") > -1) {
  340. this.showCover = false;
  341. this.popupItem = "";
  342. return;
  343. }
  344. uploadCover({ file: data, filename: "cover.jpg" }, (res) => {
  345. if (res.code == 0) {
  346. editMaterial(
  347. {
  348. id: this.popupItem.id,
  349. icon: res.data,
  350. },
  351. () => {
  352. this.$msg.success(i18n.t("gather.setting_success"));
  353. const index = this.list.findIndex((eachItem) => {
  354. return eachItem.id === this.popupItem.id
  355. })
  356. if (index >= 0) {
  357. this.isRequestingMoreData = true
  358. const lastestUsedSearchKey = this.searchKey
  359. getMaterialList(
  360. {
  361. pageNum: index + 1,
  362. pageSize: 1,
  363. type: TYPE,
  364. },
  365. (data) => {
  366. const newData = data.data.list.map((i) => {
  367. i.fileSize = changeByteUnit(Number(i.fileSize));
  368. return i;
  369. });
  370. this.list.splice(index, 1, newData[0])
  371. this.showCover = false;
  372. this.popupItem = "";
  373. this.isRequestingMoreData = false
  374. this.lastestUsedSearchKey = lastestUsedSearchKey
  375. },
  376. () => {
  377. this.isRequestingMoreData = false
  378. this.lastestUsedSearchKey = lastestUsedSearchKey
  379. this.showCover = false;
  380. this.popupItem = "";
  381. }
  382. )
  383. } else {
  384. console.error('在素材列表里没找到要编辑封面的那一项!');
  385. this.showCover = false;
  386. this.popupItem = "";
  387. }
  388. }
  389. );
  390. }
  391. });
  392. },
  393. _checkMStatus() {
  394. let needPollingTaskList = this.uploadListForUI.filter((item) => item.status === 'LOADING' && item.ifKnowProgress === false);
  395. if (needPollingTaskList.length > 0) {
  396. checkMStatus(
  397. {
  398. ids: needPollingTaskList.map((item) => item.backendId),
  399. islongpolling: true,
  400. },
  401. (res) => {
  402. // 1切图中,2失败,3成功
  403. res.data.forEach(eachRes => {
  404. if (eachRes.status === 2) {
  405. const index = this.uploadListForUI.findIndex(eachTask => eachTask.backendId === eachRes.id)
  406. index >= 0 && (this.uploadListForUI[index].status = 'FAIL')
  407. index >= 0 && (this.uploadListForUI[index].statusText = this.$msg.success(i18n.t("gather.material_cutting_fail")))
  408. } else if (eachRes.status === 3) {
  409. const index = this.uploadListForUI.findIndex(eachTask => eachTask.backendId === eachRes.id)
  410. index >= 0 && (this.uploadListForUI.splice(index, 1))
  411. index >= 0 && this.refreshListDebounced()
  412. }
  413. });
  414. }
  415. );
  416. }
  417. },
  418. onClickRename(lineData) {
  419. this.popupItem = lineData
  420. if (lineData.type !== 'dir') {
  421. this.showRename = true
  422. } else {
  423. this.isShowRenameFolder = true
  424. }
  425. },
  426. del(item) {
  427. this.$confirm({
  428. title: i18n.t("gather.delete_material"),
  429. content: i18n.t("gather.comfirm_delete_material"),
  430. okText: i18n.t("gather.delete"),
  431. ok: () => {
  432. delMaterial(item.id, () => {
  433. this.$msg.success(i18n.t("gather.delete_success"));
  434. this.isRequestingMoreData = true
  435. const lastestUsedSearchKey = this.searchKey
  436. getMaterialList(
  437. {
  438. pageNum: this.list.length + 1,
  439. pageSize: 1,
  440. searchKey: this.searchKey,
  441. type: TYPE,
  442. },
  443. (data) => {
  444. const index = this.list.findIndex((eachItem) => {
  445. return eachItem.id === item.id
  446. })
  447. if (index >= 0) {
  448. this.list.splice(index, 1)
  449. const newData = data.data.list.map((i) => {
  450. i.fileSize = changeByteUnit(Number(i.fileSize));
  451. return i;
  452. });
  453. this.list = this.list.concat(newData)
  454. if (this.list.length === data.data.total) {
  455. this.hasMoreData = false
  456. }
  457. if (this.list.length === 0) {
  458. this.$refs['image-previewer'].onClickClose()
  459. }
  460. } else {
  461. console.error('在素材列表里没找到要删除的那一项!');
  462. }
  463. this.isRequestingMoreData = false
  464. this.lastestUsedSearchKey = lastestUsedSearchKey
  465. },
  466. () => {
  467. this.isRequestingMoreData = false
  468. this.lastestUsedSearchKey = lastestUsedSearchKey
  469. }
  470. )
  471. });
  472. },
  473. });
  474. },
  475. previewImage(targetItem) {
  476. const index = this.list.findIndex((eachItem) => {
  477. return eachItem.id === targetItem.id
  478. })
  479. this.$refs['image-previewer'].show(index)
  480. },
  481. onFileChange(e) {
  482. e.files.forEach(async (eachFile, i) => {
  483. if (
  484. eachFile.type.indexOf("jpeg") <= -1
  485. ) {
  486. setTimeout(() => {
  487. this.$msg({
  488. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  489. type: "warning",
  490. });
  491. }, i * 100);
  492. return;
  493. }
  494. if (eachFile.name.substring(0, eachFile.name.lastIndexOf(".")).length > 50) {
  495. setTimeout(() => {
  496. this.$msg({
  497. message: `“${eachFile.name}”${i18n.t("gather.too_long_word")}`,
  498. type: "warning",
  499. });
  500. }, i * 100);
  501. return;
  502. }
  503. let WHRate = null
  504. try {
  505. const { width, height } = await getImgWH(eachFile)
  506. WHRate = width / height
  507. } catch (e) {
  508. console.error('获取图像宽高失败:', e)
  509. setTimeout(() => {
  510. this.$msg({
  511. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  512. type: "warning",
  513. });
  514. }, i * 100);
  515. return
  516. }
  517. if (WHRate !== 2) {
  518. setTimeout(() => {
  519. this.$msg({
  520. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  521. type: "warning",
  522. });
  523. }, i * 100);
  524. return
  525. }
  526. let itemInUploadList = {
  527. title: eachFile.name,
  528. ifKnowProgress: true,
  529. progress: 0,
  530. status: 'LOADING',
  531. statusText: i18n.t("gather.uploading_material"),
  532. uid: `u_${this.$randomWord(true, 8, 8)}`,
  533. abortHandler: null,
  534. backendId: '',
  535. parentFolderId: this.currentFolderId,
  536. };
  537. itemInUploadList.abortHandler = uploadMaterial(
  538. {
  539. dirId: this.currentFolderId,
  540. file: eachFile,
  541. tempId: itemInUploadList.uid,
  542. type: TYPE,
  543. },
  544. (response) => { // 上传成功
  545. itemInUploadList.statusText = i18n.t("gather.cutting")
  546. itemInUploadList.ifKnowProgress = false
  547. itemInUploadList.backendId = response.data.id
  548. },
  549. (err) => {
  550. if (err.statusText === 'abort') { // 用户取消了上传任务。
  551. const index = this.uploadListForUI.findIndex((eachItem) => {
  552. return eachItem.uid === itemInUploadList.uid
  553. })
  554. this.uploadListForUI.splice(index, 1)
  555. } else {
  556. itemInUploadList.status = 'FAIL'
  557. itemInUploadList.statusText = i18n.t("gather.material_upload_fail")
  558. }
  559. },
  560. (progress) => {
  561. itemInUploadList.progress = progress
  562. }
  563. )
  564. this.uploadListForUI.push(itemInUploadList);
  565. })
  566. },
  567. onCancelTask(uid) {
  568. const index = this.uploadListForUI.findIndex((eachItem) => {
  569. return eachItem.uid === uid
  570. })
  571. if (this.uploadListForUI[index].status === 'LOADING') {
  572. this.uploadListForUI[index].abortHandler.abort()
  573. } else {
  574. this.uploadListForUI.splice(index, 1)
  575. }
  576. },
  577. getMoreMaterialItem(islongpolling = null) {
  578. this.isRequestingMoreData = true
  579. const lastestUsedSearchKey = this.searchKey
  580. getMaterialList(
  581. {
  582. dirId: this.currentFolderId,
  583. pageNum: Math.floor(this.list.length / config.PAGE_SIZE) + 1,
  584. pageSize: config.PAGE_SIZE,
  585. searchKey: this.searchKey,
  586. type: TYPE,
  587. islongpolling
  588. },
  589. (data) => {
  590. const newData = data.data.list.map((i) => {
  591. if (i.type !== 'dir') {
  592. i.fileSize = changeByteUnit(Number(i.fileSize));
  593. }
  594. return i;
  595. });
  596. this.list = this.list.concat(newData)
  597. if (this.list.length === data.data.total) {
  598. this.hasMoreData = false
  599. }
  600. this.isRequestingMoreData = false
  601. this.lastestUsedSearchKey = lastestUsedSearchKey
  602. },
  603. () => {
  604. this.isRequestingMoreData = false
  605. this.lastestUsedSearchKey = lastestUsedSearchKey
  606. }
  607. );
  608. },
  609. onClickDeleteInPreview(index) {
  610. this.del(this.list[index])
  611. },
  612. },
  613. };
  614. </script>
  615. <style lang="less" scoped>
  616. </style>
  617. <style lang="less" scoped>
  618. @import "../style.less";
  619. </style>