sceneGroupInEditor.vue 16 KB

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