groupSettings.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. throw('一级分组列表中没有找到要删除的二级分组!')
  182. }
  183. // 删除catalogRoot[x].children中那个二级分组条目
  184. this.info.catalogRoot[belongGroupIdxLevel1].children.splice(targetGroupIdxLevel2, 1)
  185. // 删除catalogs中那个二级分组条目
  186. const targetIdx = this.info.catalogs.findIndex((item) => {
  187. return item.id === groupId
  188. })
  189. if (targetIdx < 0) {
  190. throw('二级分组列表中没有找到要删除的二级分组!')
  191. }
  192. this.info.catalogs.splice(targetIdx, 1)
  193. // 删除场景列表中属于要删除的二级分组的那些场景
  194. this.info.scenes = this.info.scenes.filter((item) => {
  195. return item.category !== groupId
  196. })
  197. // 如果所属一级分组中没有任何二级分组了,则新增一个默认二级分组
  198. if (this.info.catalogRoot[belongGroupIdxLevel1].children.length === 0) {
  199. let newGroupLevel2Id = 'c_' + this.$randomWord(true, 8, 8)
  200. this.info.catalogRoot[belongGroupIdxLevel1].children.push(newGroupLevel2Id)
  201. this.info.catalogs.push({
  202. id: newGroupLevel2Id,
  203. name: '默认二级分组',
  204. })
  205. }
  206. return
  207. }
  208. const backup = deepClone(this.info)
  209. try {
  210. if (groupLevel === 1) {
  211. if (this.info.catalogRoot.length === 1) {
  212. return this.$alert({
  213. content: "请至少保留一个分组",
  214. ok: () => {
  215. return
  216. },
  217. })
  218. }
  219. const targetGroupIdx = this.info.catalogRoot.findIndex((groupLevel1) => {
  220. return groupLevel1.id === groupId
  221. })
  222. if (targetGroupIdx < 0) {
  223. throw('没有找到要删除的一级分组!')
  224. }
  225. // 删除该一级分组下的所有二级分组及属于这些二级分组的场景
  226. for (const childId of this.info.catalogRoot[targetGroupIdx].children) {
  227. deleteGroupLevel2(childId)
  228. }
  229. // 删除该一级分组
  230. this.info.catalogRoot.splice(targetGroupIdx, 1)
  231. } else if (groupLevel === 2) {
  232. deleteGroupLevel2(groupId)
  233. } else {
  234. throw('group level invalid!');
  235. }
  236. // 酌情清空初始场景设置
  237. this.delFirstScene()
  238. this.$msg.success("删除成功")
  239. } catch(e) {
  240. console.error(e);
  241. this.$msg.error('删除失败')
  242. this.$store.commit("SetInfo", backup)
  243. }
  244. },
  245. delFirstScene(){
  246. if (this.info.firstScene) {
  247. let firIdx = this.info.scenes.find(item=>{
  248. return item.sceneCode == this.info.firstScene.sceneCode
  249. });
  250. !firIdx&&(this.info.firstScene='')
  251. }
  252. },
  253. },
  254. mounted() {
  255. this.$bus.on('getActive',data=>{
  256. if (data.type == 1) {
  257. this.taboneActive = data.willActive
  258. } else{
  259. this.tabtowActive = data.willActive
  260. }
  261. })
  262. },
  263. };
  264. </script>
  265. <style lang="less" scoped>
  266. .group-settings {
  267. display: flex;
  268. flex-direction: column;
  269. background: #252526;
  270. position: relative;
  271. > .ui-title-big {
  272. margin-top: 24px;
  273. margin-left: 20px;
  274. margin-right: 20px;
  275. margin-bottom: 0;
  276. flex: 0 0 auto;
  277. > .tool-tip-for-editor {
  278. font-size: 12px;
  279. cursor: default;
  280. position: relative;
  281. top: -1px;
  282. font-weight: normal;
  283. }
  284. }
  285. > .create-group-btn {
  286. margin-top: 24px;
  287. margin-left: 20px;
  288. margin-right: 20px;
  289. flex: 0 0 auto;
  290. > i {
  291. font-size: 14px;
  292. }
  293. }
  294. > .scene-group-wrap {
  295. flex: 1 1 auto;
  296. height: 1px;
  297. overflow: auto;
  298. margin-top: 24px;
  299. padding-left: 20px;
  300. padding-right: 20px;
  301. }
  302. .ui-message {
  303. > .ui-message-main {
  304. > .name-input {
  305. height: 36px;
  306. background: #252526;
  307. border-radius: 2px;
  308. border: 1px solid #404040;
  309. color: #fff;
  310. font-size: 14px;
  311. padding: 0 16px;
  312. letter-spacing: 1px;
  313. width: 100%;
  314. &:focus {
  315. border-color: #0076F6;
  316. }
  317. }
  318. }
  319. }
  320. }
  321. </style>