top_toolbar.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <div id="top_toolbar">
  3. <!-- 顶部编辑器 -->
  4. <div class="tit">
  5. <!-- <a-icon type="left" /> -->
  6. {{this.urlMsg.floorName}}
  7. </div>
  8. <div class="tool">
  9. <ul>
  10. <li @click="saveMsg">
  11. <img class="lock" :src="require(`./../../assets/images/t-save.png`)" alt />
  12. <span>保存</span>
  13. </li>
  14. <li @click="undo">
  15. <img class="lock" :src="require(`./../../assets/images/undo.png`)" alt />
  16. <span>撤销</span>
  17. </li>
  18. <li @click="redo">
  19. <img class="lock" :src="require(`./../../assets/images/redo.png`)" alt />
  20. <span>重做</span>
  21. </li>
  22. <li class="zoom-window">
  23. <div>
  24. <img class="lock" @click="handleScale(-1)" :src="require(`./../../assets/images/缩小.png`)" alt />
  25. <span class="percentage">{{scalePercent}}</span>
  26. <img class="lock" @click="handleScale(1)" :src="require(`./../../assets/images/放大 amplification.png`)" alt />
  27. </div>
  28. <span>缩放窗口</span>
  29. </li>
  30. <li>
  31. <a-dropdown :trigger="['click']">
  32. <div class="ant-dropdown-link dropdown-flex" @click="e => e.preventDefault()">
  33. <div>
  34. <img class="lock" :src="require(`./../../assets/images/t-format.png`)" alt />
  35. <div>对齐</div>
  36. </div>
  37. <a-icon type="caret-down" class="down-icon" />
  38. </div>
  39. <a-menu slot="overlay">
  40. <a-menu-item :disabled='item.disable' v-for="item in alignmentOptions" :key="item.value" @click="changeAlignItem(item.value)">
  41. <img style="width: 16px;margin-right: 5px;" :src="require(`./../../assets/images/`+item.img+`.png`)" alt />
  42. <span>{{item.label}}</span>
  43. </a-menu-item>
  44. </a-menu>
  45. </a-dropdown>
  46. </li>
  47. <!-- <li>
  48. <a-icon type="edit" />
  49. <span>图层</span>
  50. </li>
  51. <li>
  52. <a-icon type="edit" />
  53. <span>组合</span>
  54. </li>
  55. <li>
  56. <a-icon type="edit" />
  57. <span>打散</span>
  58. </li>-->
  59. <li @click="lockItem">
  60. <Icon :name="isLock?'lock':'unlock'" />
  61. <span>{{!isLock?"解锁":"锁定"}}</span>
  62. </li>
  63. <li @click="deleteItem">
  64. <img class="lock" :src="require(`./../../assets/images/delete.png`)" alt />
  65. <span>删除</span>
  66. </li>
  67. </ul>
  68. </div>
  69. <div class="btn-list">
  70. <div class="btn-list-item" @click="publishMap">
  71. <Icon name="release" />
  72. <span>发布</span>
  73. </div>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import bus from "@/bus";
  79. import { SGraphLayoutType } from "@saga-web/graph/lib";
  80. import systym from "./codeMapSystem.js";
  81. import { MessageBox } from 'element-ui';
  82. export default {
  83. data() {
  84. return {
  85. isLock: false, //是否锁定
  86. focusItem: null,
  87. alignmentOptions: [
  88. //对齐数据
  89. {
  90. value: SGraphLayoutType.Left,
  91. label: "左对齐",
  92. img: "t-left",
  93. disable:true,
  94. },
  95. {
  96. value: SGraphLayoutType.Right,
  97. label: "右对齐",
  98. img: "t-right",
  99. disable:true,
  100. },
  101. {
  102. value: SGraphLayoutType.Top,
  103. label: "顶对齐",
  104. img: "t-top",
  105. disable:true,
  106. },
  107. {
  108. value: SGraphLayoutType.Bottom,
  109. label: "底对齐",
  110. img: "t-bottom",
  111. disable:true,
  112. },
  113. {
  114. value: SGraphLayoutType.Center,
  115. label: "水平居中对齐",
  116. img: "t-center",
  117. disable:true,
  118. },
  119. {
  120. value: SGraphLayoutType.Middle,
  121. label: "垂直居中对齐",
  122. img: "t-topandbottm",
  123. disable:true,
  124. },
  125. {
  126. value: SGraphLayoutType.Vertical,
  127. label: "垂直分布",
  128. img: "t-vertical",
  129. disable:true,
  130. },
  131. {
  132. value: SGraphLayoutType.Horizontal,
  133. label: "水平分布",
  134. img: "t-level",
  135. disable:true,
  136. }
  137. ],
  138. scale: 0.5, //底图缩放比例
  139. initScale: 0.5, //初始 底图缩放比例
  140. baseScale: 1.0, //底图基础缩放比例,由底图加载完成后,传入进来
  141. scaleStep: 0.05, // +-缩放步进
  142. };
  143. },
  144. computed: {
  145. // 缩放比例显示文本
  146. scalePercent() {
  147. const scalePercent = (this.scale * 100).toFixed(0) > 9999? 9999 : (this.scale * 100).toFixed(0);
  148. return scalePercent + '%'
  149. }
  150. },
  151. methods: {
  152. /**
  153. * @name getInitScale
  154. * @description 获取底图加载完成后的,初始化的缩放比例initScale,设置为baseScale
  155. */
  156. getInitScale() {
  157. bus.$on('initScale', baseScale => {
  158. this.baseScale = Number(baseScale || 1)
  159. })
  160. },
  161. /**
  162. * @name getMouseScale
  163. * @description 滚轮滚动,导致的底图缩放比例 逻辑处理
  164. */
  165. getMouseScale() {
  166. // zoom 为缩放后改变的比例
  167. bus.$on('mouseScale', zoom => {
  168. this.scale = Number((zoom * this.initScale).toFixed(2))
  169. })
  170. },
  171. /**
  172. * @name handleScale
  173. * @param { Number } type -1:点击 - 缩小底图; 1:点击 + 放大底图
  174. * @description 点击 -+ 缩放底图
  175. */
  176. handleScale(type) {
  177. // +-按钮禁用处理
  178. let flag = true
  179. // 设置缩放范围 0.05 ~ 100
  180. if ((type < 0 && this.scale <= 0.05) || (type > 0 && this.scale >= 100)) {
  181. flag = false
  182. } else {
  183. flag = true
  184. }
  185. if (!flag) {
  186. return false
  187. }
  188. // emit 缩放比例 this.scale / oldScale
  189. const oldScale = this.scale
  190. this.scale = Number((oldScale + type * this.scaleStep).toFixed(2))
  191. bus.$emit('changeScale', this.scale / oldScale)
  192. },
  193. FocusItemChanged(itemMsg) {
  194. this.focusItem = null;
  195. this.alignmentOptions.forEach(el=>{
  196. el.disable = true
  197. })
  198. if (itemMsg.itemList.length == 1) {
  199. this.isLock = itemMsg.itemList[0].moveable;
  200. this.focusItem = itemMsg.itemList[0];
  201. }else if (itemMsg.itemList.length > 1) {
  202. this.alignmentOptions.forEach(el=>{
  203. el.disable = false
  204. })
  205. }
  206. },
  207. lockItem() {
  208. if (this.focusItem) {
  209. this.isLock = !this.isLock;
  210. this.focusItem.moveable = this.isLock;
  211. } else {
  212. this.$message.error("请选择指定对象!", 1);
  213. }
  214. },
  215. saveMsg() {
  216. // this.$message.success("保存成功!", 1);
  217. bus.$emit("saveMsgItem");
  218. },
  219. // 删除item
  220. deleteItem() {
  221. bus.$emit("deleiteItem");
  222. // if (this.focusItem) {
  223. // bus.$emit("deleiteItem");
  224. // this.$message.success("删除成功", 1);
  225. // } else {
  226. // this.$message.error("请选择指定对象!", 1);
  227. // }
  228. },
  229. // 发布图例
  230. publishMap(){
  231. MessageBox.confirm('确认后即发布到平台?', '提示', {
  232. confirmButtonText: '确认',
  233. cancelButtonText: '取消',
  234. type: 'warning'
  235. }).then(() => {
  236. bus.$emit("publishMap");
  237. }).catch(() => {
  238. });
  239. },
  240. // 对齐item
  241. changeAlignItem(val) {
  242. bus.$emit("changeAlignItem", val);
  243. },
  244. // 撤销
  245. undo(){
  246. bus.$emit("changeUndo");
  247. },
  248. // 重做
  249. redo(){
  250. bus.$emit("changeRedo");
  251. }
  252. },
  253. async mounted() {
  254. bus.$on("FocusItemChanged", itemMsg => {
  255. console.log("itemMsg", itemMsg);
  256. this.FocusItemChanged(itemMsg);
  257. });
  258. // 获取底图加载完成后的初始sacle
  259. await this.getInitScale()
  260. // 监听滚轮 底图缩放比例
  261. this.getMouseScale()
  262. },
  263. created() {
  264. const href = window.location.href;
  265. // 路由
  266. // const route = href.split("?")[0];
  267. // 参数处理
  268. let params = href.split("?")[1];
  269. if (!params) {
  270. // 参数有问题
  271. return false;
  272. }
  273. params = decodeURIComponent(params);
  274. // params = "categoryId=NTXT&ProjectID=5&BuildingID=1&FloorID=1"; // mock 参数
  275. const paramsArr = params.split("&");
  276. console.log("paramsArr", paramsArr);
  277. const obj = {};
  278. paramsArr.map(item => {
  279. const arr = item.split("=");
  280. obj[arr[0]] = arr[1];
  281. });
  282. this.urlMsg = obj;
  283. const FloorName = this.urlMsg.FloorName ? this.urlMsg.FloorName:'';
  284. this.urlMsg.floorName = systym[this.urlMsg.categoryId] + '-' + FloorName;
  285. }
  286. };
  287. </script>
  288. <style lang="less" scoped>
  289. ul,
  290. li {
  291. /*margin: 0;*/
  292. /*padding: 0;*/
  293. list-style: none;
  294. }
  295. #top_toolbar {
  296. width: 100%;
  297. height: 60px;
  298. background: rgba(255, 255, 255, 1);
  299. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  300. display: flex;
  301. align-items: center;
  302. justify-content: space-between;
  303. padding: 0 24px 0 24px;
  304. .tit {
  305. // flex: 1;
  306. font-size: 18px;
  307. font-weight: bold;
  308. color: #1f2429;
  309. }
  310. .tool {
  311. ul {
  312. display: flex;
  313. li {
  314. display: flex;
  315. justify-content: center;
  316. flex-direction: column;
  317. /*width: 62px;*/
  318. padding: 0 7px;
  319. margin-left: 7px;
  320. font-size: 12px;
  321. align-items: center;
  322. text-align: center;
  323. cursor: pointer;
  324. img {
  325. width: 16px;
  326. height: 16px;
  327. }
  328. .percentage {
  329. display: inline-block;
  330. width: 35px;
  331. border-bottom: 1px solid #c3c7cb;
  332. margin: 0 13px;
  333. font-size: 14px;
  334. }
  335. .dropdown-flex {
  336. display: flex;
  337. align-items: center;
  338. .down-icon {
  339. margin-left: 12px;
  340. }
  341. }
  342. }
  343. li:hover {
  344. background: #f5f6f7;
  345. border-radius: 2px;
  346. }
  347. .zoom-window {
  348. border-left: 1px solid #8d9399;
  349. border-right: 1px solid #8d9399;
  350. }
  351. }
  352. }
  353. .btn-list {
  354. display: flex;
  355. align-items: center;
  356. justify-content: center;
  357. width: 72px;
  358. .btn-list-item {
  359. display: flex;
  360. justify-content: center;
  361. flex-direction: column;
  362. span {
  363. font-size: 12px;
  364. }
  365. cursor: pointer;
  366. }
  367. }
  368. .btn-list:hover{
  369. background: #f5f6f7;
  370. border-radius: 2px;
  371. }
  372. }
  373. /deep/ .ant-dropdown-menu-item {
  374. display: flex;
  375. align-items: center;
  376. }
  377. </style>