right_toolbar.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div id="right_toolbar">
  3. <!-- 右侧侧编辑器 -->
  4. <a-tabs class="atabless" default-active-key="1" @change="callback">
  5. <a-tab-pane key="1" tab="属性">
  6. <div class="property">
  7. <ul class="position">
  8. <li v-for="(item,i) in msgList" :key="i">
  9. <a-input
  10. :disabled="item.disable"
  11. @change="changeStatus(item)"
  12. size="small"
  13. v-model="item.msg"
  14. placeholder
  15. :suffix="item.unit"
  16. />
  17. </li>
  18. <li @click="lockItem" :title="isLock?'锁定':'解锁'">
  19. <Icon style="vertical-align: middle;" :name="isLock?'lock':'unlock'" />
  20. </li>
  21. </ul>
  22. <attrSelect v-show="attrType" :type="attrType" :focusItemList="focusItemList" />
  23. </div>
  24. </a-tab-pane>
  25. <a-tab-pane key="2" tab="元素" force-render>
  26. <div class="element">
  27. <a-input-search placeholder="搜索" style="margin-bottom: 12px;" v-model="key" @search="onSearch" />
  28. <ul class="element-list">
  29. <li v-for="ele in elementData" :key="ele.id" @click="clickElement(ele)" v-show="key?ele.name.search(key) != -1:true">
  30. <el-image style="width: 45px; height: 26px; margin-top: 6px;" :src="ele.data.Properties.IconUrl" fit="contain"></el-image>
  31. <span class="element-name">{{ele.name}}</span>
  32. </li>
  33. </ul>
  34. </div>
  35. </a-tab-pane>
  36. </a-tabs>
  37. </div>
  38. </template>
  39. <script>
  40. import attrSelect from "@/components/edit/attr_select";
  41. import bus from "@/bus";
  42. import bus2 from "@/bus2";
  43. import { SImageMarkerItem } from "@/lib/items/SImageMarkerItem";
  44. import { SImageLegendItem } from "@/lib/items/SImageLegendItem";
  45. const msgList = [
  46. {
  47. msg: "",
  48. disable: false,
  49. name: "X",
  50. unit: "x"
  51. },
  52. {
  53. msg: "",
  54. disable: false,
  55. name: "Y",
  56. unit: "y"
  57. },
  58. {
  59. msg: "0",
  60. disable: true,
  61. name: "Angle",
  62. unit: "°"
  63. },
  64. {
  65. msg: "",
  66. disable: true,
  67. name: "Width",
  68. unit: "w"
  69. },
  70. {
  71. msg: "",
  72. disable: true,
  73. name: "Height",
  74. unit: "h"
  75. }
  76. ];
  77. // import Select from "@/components/Select/Select.vue";
  78. export default {
  79. props: {
  80. focusItemList: {
  81. type: Object,
  82. default: function() {
  83. return [];
  84. },
  85. required: false
  86. }
  87. },
  88. components: {
  89. attrSelect
  90. },
  91. created() {
  92. this.listenElementData();
  93. },
  94. data() {
  95. return {
  96. msgList,
  97. attrType: "",
  98. elementData: [],
  99. key: "",
  100. isLock: true,
  101. aspectRatio: 1,// 元素宽高比
  102. };
  103. },
  104. methods: {
  105. // 获取元素数据
  106. listenElementData() {
  107. bus2.$off('elementDataChange')
  108. bus2.$on("elementDataChange", val => {
  109. this.elementData = [];
  110. if (val.Nodes.length) {
  111. this.elementData = this.elementData.concat(val.Nodes);
  112. }
  113. if (val.Markers.length) {
  114. this.elementData = this.elementData.concat(val.Markers);
  115. }
  116. if (val.Relations.length) {
  117. this.elementData = this.elementData.concat(val.Relations);
  118. }
  119. console.log(this.elementData);
  120. });
  121. },
  122. callback(key) {
  123. console.log(key);
  124. },
  125. // 元素检索
  126. onSearch(key) {
  127. console.log(key);
  128. },
  129. // 切换锁状态
  130. lockItem() {
  131. this.isLock = !this.isLock;
  132. if (this.isLock) {
  133. let width,height;
  134. this.msgList.forEach(item => {
  135. if (item.name == "Width") {
  136. width = item.msg;
  137. } else if (item.name == "Height") {
  138. height = item.msg;
  139. }
  140. });
  141. this.aspectRatio = width / height;
  142. }
  143. },
  144. // 改变状态
  145. changeStatus(item) {
  146. if (item.name == "Width") {
  147. if (this.isLock) {
  148. const height = item.msg / this.aspectRatio;
  149. this.msgList.find(item => {
  150. return item.name == "Height"
  151. }).msg = height;
  152. bus.$emit("itemHeight", height);
  153. }
  154. bus.$emit("itemWidth", item.msg);
  155. } else if (item.name == "Height") {
  156. if (this.isLock) {
  157. const width = item.msg * this.aspectRatio;
  158. this.msgList.find(item => {
  159. return item.name == "Width"
  160. }).msg = width;
  161. bus.$emit("itemWidth", width);
  162. }
  163. bus.$emit("itemHeight", item.msg);
  164. } else if (item.name == "X" || item.name == "Y") {
  165. let x,
  166. y = "";
  167. this.msgList.forEach(t => {
  168. if (t.name == "X") {
  169. x = t.msg;
  170. } else if (t.name == "Y") {
  171. y = t.msg;
  172. }
  173. });
  174. bus.$emit("itemPositon", x, y);
  175. } else if (item.name == 'Angle') {
  176. if (item.msg.length > 0 && !isNaN(Number(item.msg))) {
  177. if (item.msg > 360) {
  178. item.msg = 360
  179. }
  180. if (item.msg < -360) {
  181. item.msg = -360
  182. }
  183. bus.$emit('itemAngle', item.msg)
  184. }
  185. }
  186. },
  187. // 点击选中元素
  188. clickElement(ele){
  189. bus.$emit('toggleItem',ele)
  190. }
  191. },
  192. watch: {
  193. focusItemList: function(newVal) {
  194. this.attrType = newVal.itemType;
  195. if (newVal.itemList.length !== 1) {
  196. this.msgList.forEach(item => {
  197. if (item.name == "X") {
  198. item.msg = 0;
  199. }
  200. if (item.name == "Y") {
  201. item.msg = 0;
  202. }
  203. if (item.name == "Width") {
  204. item.msg = 0;
  205. }
  206. if (item.name == "Height") {
  207. item.msg = 0;
  208. }
  209. if (item.name == 'Angle') {
  210. item.msg = '0'
  211. }
  212. });
  213. this.aspectRatio = 1;
  214. } else {
  215. // 属性输入框宽高显示的数值
  216. let inputW,inputH;
  217. this.msgList.forEach(item => {
  218. const Item = newVal.itemList[0];
  219. const width = Item.boundingRect().width;
  220. const height = Item.boundingRect().height;
  221. if (item.name == "X") {
  222. item.msg = Item.mapToScene(
  223. Item.boundingRect().left,
  224. Item.boundingRect().top
  225. ).x;
  226. }
  227. if (item.name == "Y") {
  228. item.msg = Item.mapToScene(
  229. Item.boundingRect().left,
  230. Item.boundingRect().top
  231. ).y;
  232. }
  233. if (item.name == "Width") {
  234. item.msg = width;
  235. // Icon显示图片宽
  236. if (Item instanceof SImageLegendItem) {
  237. item.msg = Item.img.width;
  238. }
  239. // 针对图片及Icon
  240. if (Item instanceof SImageMarkerItem || Item instanceof SImageLegendItem) {
  241. item.disable = false;
  242. } else {
  243. item.disable = true;
  244. }
  245. inputW = item.msg;
  246. }
  247. if (item.name == "Height") {
  248. item.msg = height;
  249. // Icon显示图片高
  250. if (Item instanceof SImageLegendItem) {
  251. item.msg = Item.img.height;
  252. }
  253. // 针对图片及Icon
  254. if (Item instanceof SImageMarkerItem || Item instanceof SImageLegendItem) {
  255. item.disable = false;
  256. } else {
  257. item.disable = true;
  258. }
  259. inputH = item.msg;
  260. }
  261. if (item.name == "Angle") {
  262. if (Item instanceof SImageLegendItem) {
  263. item.disable = false
  264. } else {
  265. item.disable = true
  266. }
  267. item.msg = Item.img.rotate
  268. }
  269. });
  270. this.aspectRatio = inputW / inputH;
  271. }
  272. }
  273. }
  274. };
  275. </script>
  276. <style lang="less" scoped>
  277. ul,
  278. li {
  279. margin: 0;
  280. padding: 0;
  281. list-style: none;
  282. }
  283. #right_toolbar {
  284. width: 280px;
  285. height: 100%;
  286. background: rgba(255, 255, 255, 1);
  287. box-shadow: 1px 2px 10px 0px rgba(0, 0, 0, 0.11);
  288. .atabless {
  289. height: 100%;
  290. width: 100%;
  291. }
  292. .property {
  293. width: 100%;
  294. height: 100%;
  295. .formatting {
  296. display: flex;
  297. height: 50px;
  298. padding: 0 12px 0 12px;
  299. box-sizing: border-box;
  300. align-items: center;
  301. justify-content: space-around;
  302. li {
  303. width: 16px;
  304. height: 16px;
  305. cursor: pointer;
  306. img {
  307. width: 16px;
  308. height: 16px;
  309. }
  310. }
  311. }
  312. .position {
  313. display: flex;
  314. padding: 0 12px 30px 12px;
  315. box-sizing: border-box;
  316. display: flex;
  317. border-bottom: 1px solid #c3c7cb;
  318. flex-wrap: wrap;
  319. li {
  320. margin-top: 10px;
  321. width: 30%;
  322. margin-right: 8px;
  323. .lock {
  324. width: 16px;
  325. height: 16px;
  326. cursor: pointer;
  327. }
  328. }
  329. }
  330. }
  331. .element {
  332. margin: 0 12px 0 12px;
  333. height: 100%;
  334. .element-list {
  335. height: calc(100% - 44px);
  336. overflow-y: auto;
  337. box-sizing: border-box;
  338. li {
  339. width: 100%;
  340. height: 38px;
  341. line-height: 38px;
  342. padding-left: 12px;
  343. box-sizing: border-box;
  344. color: #1f2429;
  345. cursor: pointer;
  346. .element-name {
  347. display: inline-block;
  348. vertical-align: top;
  349. line-height: 38px;
  350. width: calc(100% - 45px);
  351. height: 100%;
  352. overflow: hidden;
  353. white-space: nowrap;
  354. text-overflow: ellipsis;
  355. }
  356. &:hover {
  357. background: #f5f6f7;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. /deep/ .ant-tabs .ant-tabs-top-content.ant-tabs-content-animated {
  364. height: calc(100% - 60px);
  365. }
  366. </style>