sceneGroupInEditor.vue 13 KB

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