right_toolbar.vue 9.8 KB

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