groupSettings.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="group-settings" app-border dir-right>
  3. <div class="ui-title-big">场景导航
  4. <i class="iconfont icon-material_prompt tool-tip-for-editor" v-tooltip="'场景素材包括全景图和三维场景,您可自定义分组及场景的排列顺序。'">
  5. </i>
  6. </div>
  7. <button class="ui-button create-group-btn"
  8. @click="onRequestForAddLevel1Group"
  9. >
  10. <i class="iconfont icon-editor_add"></i>
  11. 新增分组
  12. </button>
  13. <div class="scene-group-wrap">
  14. <InsertPositionTip position-debug="-1" :index="0"></InsertPositionTip>
  15. <div
  16. v-for="(item, index) of catalogTopology"
  17. :key=item.id
  18. >
  19. <SceneGroupInEditor
  20. :groupNode="item"
  21. :level="1"
  22. @addGroup="onRequestForAddGroupLevel2"
  23. @renameScene="onRenameScene"
  24. @deleteScene="onDeleteScene"
  25. @renameGroup="onRenameGroup"
  26. @deleteGroup="onDeleteGroup"
  27. />
  28. <InsertPositionTip position-debug="0" :index="index + 1"></InsertPositionTip>
  29. </div>
  30. </div>
  31. <popup v-if="addGroupLevel" :canClose="false">
  32. <div class="ui-message ui-message-confirm dark add-group-window">
  33. <div class="ui-message-header">
  34. <span>新增{{addGroupLevel === 1 ? '一' : addGroupLevel === 2 ? '二' : ''}}级分组</span>
  35. <span @click="addGroupLevel = 0">
  36. <i class="iconfont icon_close"></i>
  37. </span>
  38. </div>
  39. <div class="ui-message-main">
  40. <input
  41. class="name-input"
  42. placeholder="请输入分组名称,限15个字"
  43. v-model.trim="newGroupName"
  44. maxlength="15"
  45. @keydown.enter="newGroupName && onConfirmAddingGroup()"
  46. >
  47. </div>
  48. <div class="ui-message-footer">
  49. <button class="ui-button deepcancel" @click="addGroupLevel = 0">
  50. 取消
  51. </button>
  52. <button
  53. class="ui-button submit"
  54. :class="{disable: !newGroupName}"
  55. @click="onConfirmAddingGroup"
  56. >
  57. 确定
  58. </button>
  59. </div>
  60. </div>
  61. </popup>
  62. </div>
  63. </template>
  64. <script>
  65. import SceneGroupInEditor from "@/components/sceneGroupInEditor.vue";
  66. import { mapGetters } from "vuex";
  67. import { deepClone } from "@/utils/other.js";
  68. import Popup from "@/components/shared/popup/index.vue";
  69. import InsertPositionTip from "@/components/insertPositionTipInEditor.vue";
  70. export default {
  71. components: {
  72. SceneGroupInEditor,
  73. Popup,
  74. InsertPositionTip,
  75. },
  76. computed: {
  77. ...mapGetters({
  78. info: "info",
  79. catalogTopology: 'catalogTopology',
  80. }),
  81. },
  82. data() {
  83. return {
  84. addGroupLevel: 0, // 0: 没有在新增分组;1:在新增一级分组;2:在新增二级分组
  85. newGroupName: '',
  86. parentGroupId: '',
  87. };
  88. },
  89. watch: {
  90. },
  91. methods: {
  92. onRequestForAddLevel1Group() {
  93. this.newGroupName = ''
  94. this.addGroupLevel = 1
  95. },
  96. onConfirmAddingGroup() {
  97. if (this.addGroupLevel === 1) {
  98. let newGroupLevel2Id = 'c_' + this.$randomWord(true, 8, 8)
  99. const newGroupLevel1 = {
  100. id: 'r_' + this.$randomWord(true, 8, 8),
  101. name: this.newGroupName,
  102. children: [newGroupLevel2Id],
  103. }
  104. this.info.catalogRoot.push(newGroupLevel1)
  105. this.info.catalogs.push({
  106. id: newGroupLevel2Id,
  107. name: '默认二级分组',
  108. })
  109. } else if (this.addGroupLevel === 2) {
  110. let id = 'c_' + this.$randomWord(true, 8, 8)
  111. let parent = this.info.catalogRoot.find((item) => {
  112. return item.id === this.parentGroupId
  113. })
  114. parent.children.push(id);
  115. const newGroupLevel2 = {
  116. id,
  117. name: this.newGroupName,
  118. }
  119. this.info.catalogs.push(newGroupLevel2);
  120. }
  121. this.$msg.success("操作成功")
  122. this.newGroupName = ''
  123. this.parentGroupId = ''
  124. this.addGroupLevel = 0
  125. },
  126. onRequestForAddGroupLevel2(parentGroupId) {
  127. this.addGroupLevel = 2
  128. this.parentGroupId = parentGroupId
  129. },
  130. onRenameScene(sceneId, newName) {
  131. const renameTarget = this.info.scenes.find((item) => {
  132. return item.id === sceneId
  133. })
  134. renameTarget.sceneTitle = newName
  135. },
  136. onDeleteScene(sceneId) {
  137. const deleteTargetIdx = this.info.scenes.findIndex((item) => {
  138. return item.id === sceneId
  139. })
  140. this.info.scenes.splice(deleteTargetIdx, 1)
  141. this.delFirstScene()
  142. this.$msg.success("删除成功")
  143. },
  144. onRenameGroup(groupId, level, newName) {
  145. if (level === 1) {
  146. const target = this.info.catalogRoot.find((item) => {
  147. return item.id === groupId
  148. })
  149. target.name = newName
  150. this.$msg.success('操作成功')
  151. } else if (level === 2) {
  152. const target = this.info.catalogs.find((item) => {
  153. return item.id === groupId
  154. })
  155. target.name = newName
  156. this.$msg.success('操作成功')
  157. } else {
  158. console.error('invalid level!');
  159. }
  160. },
  161. onDeleteGroup(groupId, groupLevel) {
  162. const deleteGroupLevel2 = (groupId) => {
  163. // 要删除的二级分组在catalogRoot[x].children中的索引
  164. let targetGroupIdxLevel2 = null
  165. // 要删除的二级分组所属的一级分组在catalogRoot中的索引
  166. let belongGroupIdxLevel1 = null
  167. // 确定上边两个变量的取值
  168. for (const [groupIdxLevel1, groupLevel1] of this.info.catalogRoot.entries()) {
  169. for (const [groupIdxLevel2, childId] of groupLevel1.children.entries()) {
  170. if (childId === groupId) {
  171. targetGroupIdxLevel2 = groupIdxLevel2
  172. break
  173. }
  174. }
  175. if (targetGroupIdxLevel2 !== null) {
  176. belongGroupIdxLevel1 = groupIdxLevel1
  177. break
  178. }
  179. }
  180. if (targetGroupIdxLevel2 === null || belongGroupIdxLevel1 === null) {
  181. console.log(targetGroupIdxLevel2, belongGroupIdxLevel1);
  182. throw('一级分组列表中没有找到要删除的二级分组!')
  183. }
  184. // 删除catalogRoot[x].children中那个二级分组条目
  185. this.info.catalogRoot[belongGroupIdxLevel1].children.splice(targetGroupIdxLevel2, 1)
  186. // 删除catalogs中那个二级分组条目
  187. const targetIdx = this.info.catalogs.findIndex((item) => {
  188. return item.id === groupId
  189. })
  190. if (targetIdx < 0) {
  191. throw('二级分组列表中没有找到要删除的二级分组!')
  192. }
  193. this.info.catalogs.splice(targetIdx, 1)
  194. // 删除场景列表中属于要删除的二级分组的那些场景
  195. this.info.scenes = this.info.scenes.filter((item) => {
  196. return item.category !== groupId
  197. })
  198. // 如果所属一级分组中没有任何二级分组了,则新增一个默认二级分组
  199. if (this.info.catalogRoot[belongGroupIdxLevel1].children.length === 0) {
  200. let newGroupLevel2Id = 'c_' + this.$randomWord(true, 8, 8)
  201. this.info.catalogRoot[belongGroupIdxLevel1].children.push(newGroupLevel2Id)
  202. this.info.catalogs.push({
  203. id: newGroupLevel2Id,
  204. name: '默认二级分组',
  205. })
  206. }
  207. return
  208. }
  209. const backup = deepClone(this.info)
  210. try {
  211. if (groupLevel === 1) {
  212. if (this.info.catalogRoot.length === 1) {
  213. return this.$alert({
  214. content: "请至少保留一个分组",
  215. ok: () => {
  216. return
  217. },
  218. })
  219. }
  220. const targetGroupIdx = this.info.catalogRoot.findIndex((groupLevel1) => {
  221. return groupLevel1.id === groupId
  222. })
  223. if (targetGroupIdx < 0) {
  224. throw('没有找到要删除的一级分组!')
  225. }
  226. // 删除该一级分组下的所有二级分组及属于这些二级分组的场景
  227. for (const childId of this.info.catalogRoot[targetGroupIdx].children) {
  228. deleteGroupLevel2(childId)
  229. }
  230. // 删除该一级分组
  231. this.info.catalogRoot.splice(targetGroupIdx, 1)
  232. } else if (groupLevel === 2) {
  233. deleteGroupLevel2(groupId)
  234. } else {
  235. throw('group level invalid!');
  236. }
  237. // 酌情清空初始场景设置
  238. this.delFirstScene()
  239. this.$msg.success("删除成功")
  240. } catch(e) {
  241. console.error(e);
  242. this.$msg.error('删除失败')
  243. this.$store.commit("SetInfo", backup)
  244. }
  245. },
  246. delFirstScene(){
  247. if (this.info.firstScene) {
  248. let firIdx = this.info.scenes.find(item=>{
  249. return item.sceneCode == this.info.firstScene.sceneCode
  250. });
  251. !firIdx&&(this.info.firstScene='')
  252. }
  253. },
  254. },
  255. mounted() {
  256. this.$bus.on('getActive',data=>{
  257. if (data.type == 1) {
  258. this.taboneActive = data.willActive
  259. } else{
  260. this.tabtowActive = data.willActive
  261. }
  262. })
  263. },
  264. };
  265. </script>
  266. <style lang="less" scoped>
  267. .group-settings {
  268. display: flex;
  269. flex-direction: column;
  270. background: #252526;
  271. position: relative;
  272. > .ui-title-big {
  273. margin-top: 24px;
  274. margin-left: 20px;
  275. margin-right: 20px;
  276. margin-bottom: 0;
  277. flex: 0 0 auto;
  278. > .tool-tip-for-editor {
  279. font-size: 12px;
  280. cursor: default;
  281. position: relative;
  282. top: -1px;
  283. font-weight: normal;
  284. }
  285. }
  286. > .create-group-btn {
  287. margin-top: 24px;
  288. margin-left: 20px;
  289. margin-right: 20px;
  290. flex: 0 0 auto;
  291. > i {
  292. font-size: 14px;
  293. }
  294. }
  295. > .scene-group-wrap {
  296. flex: 1 1 auto;
  297. height: 1px;
  298. overflow: auto;
  299. margin-top: 24px;
  300. padding-left: 20px;
  301. padding-right: 20px;
  302. }
  303. .ui-message {
  304. > .ui-message-main {
  305. > .name-input {
  306. height: 36px;
  307. background: #252526;
  308. border-radius: 2px;
  309. border: 1px solid #404040;
  310. color: #fff;
  311. font-size: 14px;
  312. padding: 0 16px;
  313. letter-spacing: 1px;
  314. width: 100%;
  315. &:focus {
  316. border-color: #0076F6;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. </style>