sceneGroupInEditor.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <div class="scene-group">
  3. <div
  4. class="top-bar"
  5. :class="isConfirmingDeletion ? '' : 'show-icons-on-hover'"
  6. @click="onClickTopBar"
  7. @dragstart="onDragStart"
  8. @dragenter.self="onDragEnter"
  9. @dragend="onDragEnd"
  10. @dragleave.self="onDragLeave"
  11. :draggable="isRenaming ? false : true"
  12. :style="{
  13. paddingLeft: topBarPaddingLeft,
  14. }"
  15. >
  16. <div class="drag-image" ref="drag-image">
  17. <i class="iconfont icon-editor_folder_off"></i>
  18. </div>
  19. <i
  20. class="iconfont icon-edit_input_arrow icon-expand"
  21. :class="isExpanded ? '' : 'collapsed'"
  22. ></i>
  23. <i
  24. v-show="isExpanded"
  25. class="iconfont icon-editor_folder_on folder_expanded"
  26. ></i>
  27. <i
  28. v-show="!isExpanded"
  29. class="iconfont icon-editor_folder_off folder_collapsed"
  30. ></i>
  31. <template v-if="!isRenaming">
  32. <span class="group-name" v-title="transTitle(groupNode.name)">
  33. <!-- {{
  34. $i18n.t(`zh_key.${groupNode.name}`).indexOf("zh_key") > -1
  35. ? groupNode.name
  36. : $i18n.t(`zh_key.${groupNode.name}`)
  37. }} -->
  38. {{ transTitle(groupNode.name) }}
  39. <!-- {{ groupLv1name(groupNode.name) }} -->
  40. </span>
  41. <i
  42. v-show="level === 1"
  43. class="iconfont icon-editor_list_add icon-add"
  44. v-tooltip="$i18n.t('navigation.add_two_group')"
  45. @click.stop="onRequestForAddGroup"
  46. >
  47. </i>
  48. <i
  49. class="iconfont icon-editor_list_image icon-image"
  50. v-tooltip="$i18n.t('navigation.add_pano_or_scene')"
  51. @click.stop="onRequestForAddScene"
  52. v-show="
  53. level === 2 ||
  54. (level === 1 &&
  55. (groupNode.children.length === 0 ||
  56. (groupNode.children.length === 1 &&
  57. (groupNode.children[0].name === '默认二级分组' ||
  58. groupNode.children[0].name ===
  59. $i18n.t('navigation.default_group_two')))))
  60. "
  61. >
  62. </i>
  63. <i
  64. class="iconfont icon-editor_list_edit icon-edit"
  65. v-tooltip="$i18n.t('navigation.rename')"
  66. @click.stop="onClickForRename"
  67. >
  68. </i>
  69. <i
  70. class="iconfont icon-editor_list_delete icon-delete"
  71. v-tooltip="$i18n.t('navigation.delete')"
  72. @click.stop="onRequestForDelete"
  73. >
  74. </i>
  75. <div class="deletion-confirm-wrap">
  76. <div
  77. class="deletion-confirm"
  78. :class="isConfirmingDeletion ? 'show' : 'hide'"
  79. v-clickoutside="onRequestForCancelDelete"
  80. @click.stop="onConfirmDelete"
  81. >
  82. {{ $i18n.t("navigation.delete") }}
  83. </div>
  84. </div>
  85. </template>
  86. <input
  87. v-if="isRenaming"
  88. class="group-title-input"
  89. v-model.trim="newName"
  90. ref="input-for-rename"
  91. maxlength="50"
  92. :placeholder="$i18n.t('navigation.enter_name')"
  93. @blur="onInputNewNameComplete"
  94. @keydown.enter="onInputEnter"
  95. @click.stop
  96. />
  97. </div>
  98. <div class="group-content" v-if="isExpanded">
  99. <template
  100. v-if="
  101. !(
  102. groupNode.children.length === 1 &&
  103. (groupNode.children[0].name === '默认二级分组' ||
  104. groupNode.children[0].name ===
  105. $i18n.t('navigation.default_group_two'))
  106. )
  107. "
  108. >
  109. <InsertPositionTip
  110. position-debug="1"
  111. :indentLevel="level + 1"
  112. :topologyLevel="level + 1"
  113. :parentNode="groupNode"
  114. :index="0"
  115. ></InsertPositionTip>
  116. <div v-for="(item, index) of groupNode.children" :key="item.id">
  117. <component
  118. :is="'SceneGroup'"
  119. ref="scene-group"
  120. v-if="!item.type"
  121. :groupNode="item"
  122. :level="level + 1"
  123. @renameScene="onRenameScene"
  124. @deleteScene="onDeleteScene"
  125. @renameGroup="onInnerGroupRename"
  126. @deleteGroup="onInnerGroupConfirmDelete"
  127. />
  128. <SceneInGroup
  129. v-else
  130. :style="{
  131. paddingLeft: sceneItemPaddingLeft,
  132. }"
  133. :sceneInfo="item"
  134. @rename="onRenameScene"
  135. @delete="onDeleteScene"
  136. />
  137. <InsertPositionTip
  138. position-debug="2"
  139. :indentLevel="level + 1"
  140. :topologyLevel="level + 1"
  141. :parentNode="groupNode"
  142. :index="index + 1"
  143. ></InsertPositionTip>
  144. </div>
  145. </template>
  146. <template v-else>
  147. <!-- 自动生成的默认二级分组不显示,里边的内容显示成直属于一级分组的效果。 -->
  148. <InsertPositionTip
  149. position-debug="3"
  150. :indentLevel="level + 1"
  151. :topologyLevel="level + 2"
  152. :parentNode="groupNode.children[0]"
  153. :index="0"
  154. ></InsertPositionTip>
  155. <div
  156. v-for="(item, index) of groupNode.children[0].children"
  157. :key="item.id"
  158. >
  159. <SceneInGroup
  160. :style="{
  161. paddingLeft: sceneItemPaddingLeft,
  162. }"
  163. :sceneInfo="item"
  164. @rename="onRenameScene"
  165. @delete="onDeleteScene"
  166. />
  167. <InsertPositionTip
  168. position-debug="4"
  169. :indentLevel="level + 1"
  170. :topologyLevel="level + 2"
  171. :parentNode="groupNode.children[0]"
  172. :index="index + 1"
  173. ></InsertPositionTip>
  174. </div>
  175. </template>
  176. </div>
  177. <div class="dialog" style="z-index: 2000" v-if="isShowSelectionWindow">
  178. <MaterialSelector
  179. :title="$i18n.t('gather.select_material')"
  180. @cancel="isShowSelectionWindow = false"
  181. @submit="onSubmitFromMaterialSelector"
  182. :selectableType="['pano', '3D']"
  183. :initialMaterialType="'pano'"
  184. :isMultiSelection="true"
  185. />
  186. </div>
  187. </div>
  188. </template>
  189. <script>
  190. import SceneInGroup from "@/components/sceneInGroupInEditor.vue";
  191. import MaterialSelector from "@/components/materialSelector.vue";
  192. import InsertPositionTip from "@/components/insertPositionTipInEditor.vue";
  193. import { mapGetters, mapMutations } from "vuex";
  194. import { isUpgradeAdapter } from "@/utils/fixVersion";
  195. export default {
  196. name: "SceneGroup",
  197. components: {
  198. SceneInGroup,
  199. MaterialSelector,
  200. InsertPositionTip,
  201. },
  202. props: {
  203. groupNode: {
  204. type: Object,
  205. required: true,
  206. },
  207. level: {
  208. type: Number,
  209. default: 1,
  210. },
  211. },
  212. data() {
  213. return {
  214. isExpanded: false,
  215. isRenaming: false,
  216. newName: "",
  217. isConfirmingDeletion: false,
  218. isShowSelectionWindow: false,
  219. dragEnterTimerId: null,
  220. };
  221. },
  222. computed: {
  223. transTitle() {
  224. return (name) => {
  225. switch (name) {
  226. case "默认一级分组":
  227. return this.$i18n.t("navigation.default_group_one");
  228. case "默认二级分组":
  229. return this.$i18n.t("navigation.default_group_two");
  230. case "一级分组":
  231. return this.$i18n.t("navigation.group_one");
  232. case "二级分组":
  233. return this.$i18n.t("navigation.group_two");
  234. default:
  235. return name;
  236. }
  237. };
  238. },
  239. groupLv1name() {
  240. return (name) => {
  241. return name && name.length
  242. ? name
  243. : this.$i18n.t("navigation.group_one");
  244. };
  245. },
  246. ...mapGetters({
  247. info: "info",
  248. dragInfo: "editorNavDragInfo",
  249. }),
  250. topBarPaddingLeft() {
  251. return 12 + (this.level - 1) * 12 + "px";
  252. },
  253. sceneItemPaddingLeft() {
  254. return 18 + this.level * 12 + "px";
  255. },
  256. },
  257. methods: {
  258. ...mapMutations({
  259. recordDragType: "setEditorNavDragType",
  260. recordDragNode: "setEditorNavDragNode",
  261. clearDragInfo: "clearEditorNavDragInfo",
  262. }),
  263. onClickTopBar() {
  264. if (this.isConfirmingDeletion) {
  265. return;
  266. }
  267. this.isExpanded = !this.isExpanded;
  268. },
  269. onRenameScene(...params) {
  270. this.$emit("renameScene", ...params);
  271. },
  272. onDeleteScene(...params) {
  273. this.$emit("deleteScene", ...params);
  274. },
  275. onRequestForAddGroup() {
  276. this.$emit("addGroup", this.groupNode.id);
  277. },
  278. onRequestForAddScene() {
  279. this.isShowSelectionWindow = true;
  280. },
  281. onClickForRename() {
  282. this.isRenaming = true;
  283. console.log(this.groupNode.name);
  284. if (this.groupNode.name == "默认二级分组") {
  285. this.newName = this.$i18n.t("navigation.default_group_two");
  286. } else if (this.groupNode.name == "一级分组") {
  287. this.newName = this.$i18n.t("navigation.group_one");
  288. } else {
  289. this.newName = this.groupNode.name;
  290. }
  291. this.$nextTick(() => {
  292. // this.$refs['input-for-rename'].focus()
  293. this.$refs["input-for-rename"].select();
  294. this.$refs["input-for-rename"].scrollIntoView({
  295. behavior: "smooth",
  296. });
  297. });
  298. },
  299. onInputNewNameComplete() {
  300. this.isRenaming = false;
  301. console.log(this.groupNode.name);
  302. if (!this.newName.trim()) {
  303. return;
  304. }
  305. if (this.newName !== this.groupNode.name) {
  306. this.$emit("renameGroup", this.groupNode.id, this.level, this.newName);
  307. }
  308. this.newName = "";
  309. },
  310. onInputEnter() {
  311. this.isRenaming = false; // 会导致input blur,进而触发onInputNewNameComplete
  312. },
  313. onInnerGroupRename(...params) {
  314. this.$emit("renameGroup", ...params);
  315. },
  316. onRequestForDelete() {
  317. this.isConfirmingDeletion = true;
  318. },
  319. onRequestForCancelDelete() {
  320. if (!this.isConfirmingDeletion) {
  321. return;
  322. }
  323. // 先保持isConfirmingDeletion不变,因为onClickTopBar可能要用到
  324. setTimeout(() => {
  325. this.isConfirmingDeletion = false;
  326. }, 0);
  327. },
  328. onConfirmDelete() {
  329. this.$emit("deleteGroup", this.groupNode.id, this.level);
  330. this.isConfirmingDeletion = false;
  331. },
  332. onInnerGroupConfirmDelete(...params) {
  333. this.$emit("deleteGroup", ...params);
  334. },
  335. onSubmitFromMaterialSelector(selected) {
  336. let newScenes = [];
  337. for (const item of selected) {
  338. if (item.materialType === "pano") {
  339. newScenes.push({
  340. icon: item.icon,
  341. sceneCode: item.sceneCode,
  342. sceneTitle: item.name,
  343. category:
  344. this.level === 1
  345. ? this.groupNode.children[0].id
  346. : this.groupNode.id,
  347. type: "pano",
  348. id: "s_" + this.$randomWord(true, 8, 8),
  349. });
  350. } else if (item.materialType === "3D") {
  351. console.log("item.num", item.num);
  352. newScenes.push({
  353. icon: item.thumb,
  354. sceneCode: item.num,
  355. sceneTitle: item.sceneName,
  356. category:
  357. this.level === 1
  358. ? this.groupNode.children[0].id
  359. : this.groupNode.id,
  360. type: "4dkk",
  361. version: isUpgradeAdapter(item.isUpgrade), // 'V3' OR 'V4'. 全景看看v1.3新增
  362. id: "s_" + this.$randomWord(true, 8, 8),
  363. });
  364. }
  365. }
  366. let allSuccess = true;
  367. newScenes.forEach((item, i) => {
  368. let temp = this.info.scenes.find((eachScene) => {
  369. return eachScene.sceneCode === item.sceneCode;
  370. });
  371. if (temp) {
  372. setTimeout(() => {
  373. this.$msg.message(
  374. `${
  375. item.type == "4dkk"
  376. ? this.$i18n.t("navigation.scene_name")
  377. : this.$i18n.t("navigation.pano")
  378. }${this.$i18n.t("navigation.already_exists", {
  379. msg: item.sceneTitle,
  380. })}`
  381. );
  382. }, i * 100);
  383. allSuccess = false;
  384. return;
  385. }
  386. this.info.scenes.push(item);
  387. });
  388. this.isShowSelectionWindow = false;
  389. if (allSuccess) {
  390. this.$msg.success(this.$i18n.t("gather.success"));
  391. }
  392. },
  393. onDragStart(e) {
  394. if (this.isRenaming) {
  395. return;
  396. }
  397. this.recordDragType(`topologyGroupLevel${this.level}`);
  398. this.recordDragNode(this.groupNode);
  399. e.dataTransfer.setDragImage(this.$refs["drag-image"], -10, -18);
  400. },
  401. onDragEnter(e) {
  402. if (
  403. e.target.contains(e.relatedTarget) ||
  404. (this.level === 2 && this.dragInfo.type.includes("Group"))
  405. ) {
  406. return;
  407. }
  408. this.dragEnterTimerId = setTimeout(() => {
  409. if (!this.isExpanded) {
  410. this.isExpanded = true;
  411. }
  412. }, 700);
  413. },
  414. onDragEnd() {
  415. this.clearDragInfo();
  416. clearTimeout(this.dragEnterTimerId);
  417. },
  418. onDragLeave(e) {
  419. if (e.target.contains(e.relatedTarget)) {
  420. return;
  421. }
  422. clearTimeout(this.dragEnterTimerId);
  423. },
  424. },
  425. mounted() {},
  426. destroyed() {},
  427. };
  428. </script>
  429. <style lang="less" scoped>
  430. .scene-group {
  431. .top-bar {
  432. position: relative;
  433. color: rgba(255, 255, 255, 0.6);
  434. height: 40px;
  435. border-radius: 4px;
  436. display: flex;
  437. align-items: center;
  438. margin-left: -12px;
  439. margin-right: -10px;
  440. padding-right: 10px;
  441. &:hover {
  442. background: #313131;
  443. > .group-name {
  444. width: 120px;
  445. }
  446. }
  447. &.show-icons-on-hover:hover {
  448. > .icon-add,
  449. .icon-image,
  450. .icon-edit,
  451. .icon-delete {
  452. display: block;
  453. }
  454. }
  455. > .drag-image {
  456. position: absolute;
  457. width: 40px;
  458. height: 40px;
  459. background: #313131;
  460. box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.5);
  461. border-radius: 4px;
  462. display: flex;
  463. justify-content: center;
  464. align-items: center;
  465. z-index: -1;
  466. i {
  467. font-size: 16px;
  468. }
  469. }
  470. > .icon-expand {
  471. display: inline-block;
  472. font-size: 12px;
  473. transform: scale(0.7);
  474. &.collapsed {
  475. display: inline-block;
  476. transform: scale(0.7) rotate(-90deg);
  477. }
  478. }
  479. > .folder_expanded {
  480. font-size: 16px;
  481. margin-left: 7px;
  482. }
  483. > .folder_collapsed {
  484. font-size: 16px;
  485. margin-left: 7px;
  486. }
  487. > .group-name {
  488. margin-left: 6px;
  489. display: inline-block;
  490. text-overflow: ellipsis;
  491. overflow: hidden;
  492. white-space: nowrap;
  493. flex: 1 1 auto;
  494. }
  495. > .icon-add {
  496. margin-left: 12px;
  497. display: none;
  498. cursor: pointer;
  499. &:hover {
  500. color: #0076f6;
  501. }
  502. }
  503. > .icon-image {
  504. margin-left: 12px;
  505. display: none;
  506. cursor: pointer;
  507. &:hover {
  508. color: #0076f6;
  509. }
  510. }
  511. > .icon-edit {
  512. margin-left: 12px;
  513. display: none;
  514. cursor: pointer;
  515. &:hover {
  516. color: #0076f6;
  517. }
  518. }
  519. > .icon-delete {
  520. margin-left: 12px;
  521. display: none;
  522. cursor: pointer;
  523. &:hover {
  524. color: #fa5555;
  525. }
  526. }
  527. > .deletion-confirm-wrap {
  528. position: absolute;
  529. top: 0;
  530. bottom: 0;
  531. right: 0;
  532. width: 44px;
  533. overflow: hidden;
  534. pointer-events: none;
  535. border-top-right-radius: 4px;
  536. border-bottom-right-radius: 4px;
  537. > .deletion-confirm {
  538. position: absolute;
  539. top: 0;
  540. bottom: 0;
  541. width: 100%;
  542. background: #fa5555;
  543. transition: right 0.3s;
  544. cursor: pointer;
  545. text-align: center;
  546. font-size: 12px;
  547. color: #fff;
  548. pointer-events: auto;
  549. &::after {
  550. content: "";
  551. height: 100%;
  552. vertical-align: middle;
  553. display: inline-block;
  554. }
  555. &.show {
  556. right: 0;
  557. }
  558. &.hide {
  559. right: -44px;
  560. }
  561. }
  562. }
  563. > .group-title-input {
  564. margin-left: 6px;
  565. flex: 1 1 auto;
  566. width: 1px;
  567. height: 30px;
  568. background: #1a1b1d;
  569. border-radius: 2px;
  570. border: 1px solid #404040;
  571. color: #fff;
  572. font-size: 14px;
  573. padding: 0 10px 0 16px;
  574. &:focus {
  575. border-color: #0076f6;
  576. }
  577. }
  578. }
  579. .group-content {
  580. }
  581. }
  582. </style>