index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <div>
  3. <setting @select="handleInitScene"></setting>
  4. <toolbar
  5. @catalog="data=>activeCataLog = data"
  6. @addPano="onAddPano"
  7. @addGroup="onAddGroup"
  8. @addScene="onAddScene"
  9. @rename="onRename"
  10. ></toolbar>
  11. <popup v-show="showAddGroup" :can-close="false">
  12. <div class="ui-message ui-message-confirm dark" style="width: 400px">
  13. <div class="ui-message-header">
  14. <span>{{
  15. currentTabAtri.oper == "add"
  16. ? `新增${currentTabAtri.type == 1 ? "一" : "二"}级分组`
  17. : `重命名${currentTabAtri.type == 1 ? "一" : "二"}级分组`
  18. }}</span>
  19. <span @click="showAddGroup = false">
  20. <i class="iconfont icon_close"></i>
  21. </span>
  22. </div>
  23. <div class="ui-message-main re-name">
  24. <div>
  25. <input
  26. class="ui-input"
  27. type="text"
  28. maxlength="15"
  29. placeholder="请输入分组名,限15个字"
  30. v-model="currentTabAtri.name"
  31. />
  32. </div>
  33. </div>
  34. <div class="ui-message-footer">
  35. <button class="ui-button cancel" @click="showAddGroup = false">
  36. 取消
  37. </button>
  38. <button
  39. class="ui-button submit"
  40. :class="{ disable: !currentTabAtri.name }"
  41. @click="handleAddGroup()"
  42. >
  43. 确定
  44. </button>
  45. </div>
  46. </div>
  47. </popup>
  48. <popup v-show="showRename" :can-close="false">
  49. <div class="ui-message ui-message-confirm dark" style="width: 400px">
  50. <div class="ui-message-header">
  51. <span>重命名</span>
  52. <span @click="handleRenameClose">
  53. <i class="iconfont icon_close"></i>
  54. </span>
  55. </div>
  56. <div class="ui-message-main re-name">
  57. <div>
  58. <input
  59. class="ui-input"
  60. type="text"
  61. maxlength="50"
  62. placeholder="输入名字"
  63. v-model="reNameItem.sceneTitle"
  64. />
  65. </div>
  66. </div>
  67. <div class="ui-message-footer">
  68. <button class="ui-button cancel" @click="handleRenameClose">
  69. 取消
  70. </button>
  71. <button
  72. class="ui-button submit"
  73. :class="{ disable: !reNameItem.sceneTitle }"
  74. @click="handleRename()"
  75. >
  76. 确定
  77. </button>
  78. </div>
  79. </div>
  80. </popup>
  81. <div class="dialog" style="z-index: 2000" v-if="showList">
  82. <Table
  83. :list="type == 'scene' ? sceneList : panoList"
  84. :tabHeader="$MAPTABLEHEADER[type]"
  85. @updateList="update"
  86. @cancle="showList = false"
  87. :title="type == 'scene' ? '选择三维场景' : '选择全景图'"
  88. :primaryKey="type == 'scene' ? 'num' : 'id'"
  89. @changeCurrent="changeCurrent"
  90. :paging="paging"
  91. @submit="handleSelect"
  92. >
  93. </Table>
  94. </div>
  95. </div>
  96. </template>
  97. <script>
  98. import Setting from "./Setting";
  99. import Toolbar from "./Toolbar";
  100. import Popup from "@/components/shared/popup";
  101. import {
  102. getSceneList,
  103. getMaterialList,
  104. } from "@/api";
  105. import Table from "@/components/tableSelect.vue";
  106. import { mapGetters } from "vuex";
  107. import { savePanoToWorks } from "@/api";
  108. import { changeByteUnit } from '@/utils/file'
  109. export default {
  110. name: "home",
  111. components: {
  112. Setting,
  113. Toolbar,
  114. Popup,
  115. Table,
  116. },
  117. computed: {
  118. ...mapGetters({
  119. sceneList: "sceneList",
  120. info: "info",
  121. backupInfo: "backupInfo"
  122. }),
  123. },
  124. data() {
  125. return {
  126. activeCataLog: "",
  127. type: "scene",
  128. currentTabAtri: "",
  129. showAddGroup: false,
  130. showRename: false,
  131. showList: false,
  132. showInitScene: true,
  133. reNameItem: {
  134. id: "",
  135. sceneTitle: "",
  136. },
  137. key: "",
  138. paging: {
  139. pageSize: 8,
  140. pageNum: 1,
  141. total: 0,
  142. showSize: 4,
  143. current: 1,
  144. },
  145. panoList: [],
  146. };
  147. },
  148. mounted() {},
  149. watch: {
  150. "paging.pageNum": function () {
  151. this.type == "scene" ? this.getSceneList() : this.getMaterialList();
  152. },
  153. showList(newVal) {
  154. if (!newVal) {
  155. this.paging = {
  156. pageSize: 8,
  157. pageNum: 1,
  158. total: 0,
  159. showSize: 4,
  160. current: 1,
  161. };
  162. }
  163. },
  164. },
  165. methods: {
  166. handleInitScene() {
  167. this.showInitScene = true;
  168. },
  169. update(data) {
  170. this.key = data;
  171. this.type == "scene" ? this.getSceneList() : this.getMaterialList();
  172. },
  173. handleSelect(data) {
  174. let params = ''
  175. if (this.type == "scene") {
  176. params = data.map((item) => {
  177. return {
  178. icon: item.thumb,
  179. sceneCode: item.num,
  180. sceneTitle: item.sceneName,
  181. type: "4dkk",
  182. category:this.activeCataLog.id,
  183. id:'s_'+this.$randomWord(true,8,8)
  184. };
  185. });
  186. } else {
  187. params = data.map((item) => {
  188. return {
  189. icon: item.icon,
  190. sceneCode: item.sceneCode,
  191. sceneTitle: item.name,
  192. category:this.activeCataLog.id,
  193. type: "pano",
  194. id:'s_'+this.$randomWord(true,8,8)
  195. };
  196. });
  197. }
  198. params.forEach((item,i) => {
  199. let temp = this.info.scenes.find(sub=>sub.sceneCode == item.sceneCode)
  200. if (temp) {
  201. console.log(this.$msg);
  202. setTimeout(() => {
  203. this.$msg.message(`${item.type=='4dkk'?'场景':'全景图'}${item.sceneTitle}已存在,不可重复添加`);
  204. }, i*100);
  205. return
  206. }
  207. !temp&&this.info.scenes.push(item)
  208. });
  209. this.$bus.emit('scenesChange')
  210. this.$store.commit("SetInfo", this.info);
  211. this.showList = false;
  212. },
  213. changeCurrent(data) {
  214. this.paging.pageNum = data;
  215. },
  216. savePanoToWorks(data) {
  217. savePanoToWorks(data, () => {
  218. this.$bus.emit("refresh");
  219. });
  220. },
  221. onRename(data) {
  222. this.reNameItem = data;
  223. this.showRename = true;
  224. },
  225. handleRenameClose(){
  226. this.showRename = false
  227. this.$bus.emit('scenesChange')
  228. this.$store.commit("SetInfo", this.backupInfo);
  229. },
  230. handleRename() {
  231. if (!this.reNameItem.sceneTitle.trim()) {
  232. return this.$alert({ content: "请输入名字" });
  233. }
  234. this.$msg.success("重命名成功")
  235. this.$store.commit("SetInfo", this.info);
  236. this.showRename = false;
  237. },
  238. onAddGroup(data) {
  239. this.showAddGroup = true;
  240. this.currentTabAtri = { ...data, name: data.item.name || "" };
  241. },
  242. handleAddGroup() {
  243. if (!this.currentTabAtri.name.trim()) {
  244. return this.$alert({ content: "请输入名字" });
  245. }
  246. let willActive = ''
  247. let tmp = this.currentTabAtri.item;
  248. if (this.currentTabAtri.oper == "edit") {
  249. tmp.name = this.currentTabAtri.name;
  250. } else {
  251. if (this.currentTabAtri.type == 1) {
  252. let id = 'c_'+this.$randomWord(true,8,8)
  253. willActive = {
  254. id: 'r_'+this.$randomWord(true,8,8),
  255. name: this.currentTabAtri.name,
  256. children: [id],
  257. }
  258. this.info.catalogRoot.push(willActive);
  259. this.info.catalogs.push({
  260. id,
  261. name: '默认二级分组',
  262. });
  263. console.log(this.info.catalogs);
  264. }
  265. if (this.currentTabAtri.type == 2) {
  266. let id = 'c_'+this.$randomWord(true,8,8)
  267. let item = this.info.catalogRoot.find(
  268. (item) => item.id == tmp.parentId
  269. );
  270. item.children.push(id);
  271. willActive = {
  272. id,
  273. name: this.currentTabAtri.name,
  274. }
  275. this.info.catalogs.push(willActive);
  276. }
  277. }
  278. this.$bus.emit('scenesChange')
  279. this.$store.commit("SetInfo", this.info);
  280. this.$msg.success("操作成功")
  281. this.showAddGroup = false;
  282. if (this.currentTabAtri.oper != "edit") {
  283. this.$bus.emit('getActive',{
  284. type:this.currentTabAtri.type,
  285. willActive
  286. })
  287. }
  288. },
  289. onAddScene() {
  290. this.type = "scene";
  291. this.getSceneList();
  292. this.showList = true;
  293. },
  294. onAddPano() {
  295. this.type = "pano";
  296. this.getMaterialList();
  297. this.showList = true;
  298. },
  299. getSceneList() {
  300. getSceneList(
  301. {
  302. pageNum: this.paging.pageNum,
  303. pageSize: this.paging.pageSize,
  304. searchKey: this.key,
  305. },
  306. (data) => {
  307. let { list, total } = data.data.data;
  308. this.paging.total = total;
  309. this.$store.commit("SetSceneList", list);
  310. }
  311. );
  312. },
  313. getMaterialList() {
  314. getMaterialList(
  315. {
  316. pageNum: this.paging.pageNum,
  317. pageSize: this.paging.pageSize,
  318. searchKey: this.key,
  319. type: this.type,
  320. urlSelect: true,
  321. },
  322. (data) => {
  323. this.paging.pageNum = data.data.pageNum;
  324. this.paging.pageSize = data.data.pageSize;
  325. this.paging.total = data.data.total;
  326. this.panoList = data.data.list.map(i=>{
  327. i.fileSize = changeByteUnit(Number(i.fileSize))
  328. i.createTime = i.createTime.substring(0,i.createTime.length-3)
  329. i.updateTime = i.updateTime.substring(0,i.updateTime.length-3)
  330. return i
  331. })
  332. }
  333. );
  334. },
  335. },
  336. };
  337. </script>
  338. <style lang="less" scoped>
  339. .dialog {
  340. position: fixed;
  341. z-index: 30;
  342. left: 0;
  343. top: 0;
  344. width: 100%;
  345. height: 100%;
  346. background-color: rgba(0, 0, 0, 0.5);
  347. }
  348. .pano-con {
  349. height: auto;
  350. background: none;
  351. padding: 10px 0;
  352. .ui-remark {
  353. padding-left: 10px;
  354. }
  355. > ul {
  356. > li {
  357. cursor: pointer;
  358. }
  359. }
  360. }
  361. .re-name {
  362. width: 80%;
  363. margin: 40px auto;
  364. }
  365. .add-vr {
  366. text-align: left;
  367. .ui-remark {
  368. margin: 10px 0;
  369. }
  370. }
  371. </style>