sceneGroupInEditor.vue 13 KB

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