editCirclePolyline.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="edit-line">
  3. <!-- 所有按钮 -->
  4. <div class="btn-list">
  5. <el-button
  6. :class="[cmdStatus=='create' ? 'heightLight' : '']"
  7. size="small"
  8. @click="create"
  9. >创建多边形
  10. </el-button>
  11. <el-tooltip class="item" effect="dark" content="双击 item 也可进入编辑状态" placement="top-start">
  12. <el-button
  13. :class="[cmdStatus=='edit' ? 'heightLight' : '']"
  14. size="small"
  15. @click="edit"
  16. >编辑多边形
  17. </el-button>
  18. </el-tooltip>
  19. <el-button
  20. :class="[cmdStatus=='deleteItem' ? 'heightLight' : '']"
  21. size="small"
  22. @click="deleteItem"
  23. >删除
  24. </el-button>
  25. <el-tooltip class="item" effect="dark" content="长按 Shoft 配合左键也可触发该功能" placement="top-start">
  26. <el-button
  27. :class="[cmdStatus=='eqDrawLine' ? 'heightLight' : '']"
  28. size="small"
  29. @click="eqDrawLine"
  30. >垂直水平绘制
  31. </el-button>
  32. </el-tooltip>
  33. </div>
  34. <div class="content">
  35. <div class="left">
  36. <canvas id="edit_polygon" width="700" height="460" tabindex="0"/>
  37. </div>
  38. <div class="line-property">
  39. <el-card shadow="always">
  40. <div slot="header" class="clearfix">
  41. <span>属性修改</span>
  42. </div>
  43. <div class="always-item">
  44. <span>边框宽:</span>
  45. <el-input-number
  46. size="small"
  47. v-model="lineWidth"
  48. @change="changeLineWidth"
  49. :min="1"
  50. :max="50"
  51. ></el-input-number>
  52. </div>
  53. <div class="always-item">
  54. <span>线类型:</span>
  55. <el-select
  56. style="width:130px"
  57. size="small"
  58. v-model="lineType"
  59. @change="changeType"
  60. placeholder="请选择"
  61. >
  62. <el-option
  63. v-for="item in options"
  64. :key="item.value"
  65. :label="item.label"
  66. :value="item.value"
  67. ></el-option>
  68. </el-select>
  69. </div>
  70. <div class="always-item">
  71. <span>线颜色:</span>
  72. <el-color-picker v-model="lineColor" @change="changeColor" show-alpha></el-color-picker>
  73. </div>
  74. <!-- <div class="always-item">
  75. <span>填充色:</span>
  76. <el-color-picker v-model="fillColor" @change="changeFillColor" show-alpha></el-color-picker>
  77. </div> -->
  78. </el-card>
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. import { SGraphScene, SGraphView, SLineStyle } from "@persagy-web/graph/";
  85. import { SItemStatus } from "@persagy-web/big/lib/enums/SItemStatus";
  86. import { SColor } from "@persagy-web/draw/";
  87. import { hexify } from "./../../../../public/until/rgbaUtil";
  88. import EditCirclePolylineItem from "../../../../../guides/edit/items/src/EditCirclePolylineItem";
  89. /**
  90. * 编辑折线示例
  91. *
  92. * @author 郝洁 <haojie@persagy.com>
  93. */
  94. export default {
  95. name: "EditPolylineItem",
  96. data() {
  97. return {
  98. /** 命令所属的场景类 */
  99. scene: null,
  100. view: null, //view实例
  101. isCreated: false, //是否创建完成
  102. cmdStatus: "", //选中状态
  103. polylineItem: null, //存放创建的Item
  104. lineWidth: 1, //border线宽
  105. lineColor: "", //border线颜色
  106. fillColor: "", //填充色
  107. lineType: "", //border线类型
  108. options: [
  109. {
  110. value: "Solid",
  111. label: "实线"
  112. },
  113. {
  114. value: "Dashed",
  115. label: "虚线"
  116. },
  117. {
  118. value: "Dotted",
  119. label: "点"
  120. }
  121. ]
  122. };
  123. },
  124. /**
  125. * 页面挂载
  126. */
  127. mounted() {
  128. this.view = new SGraphView("edit_polygon");
  129. this.scene = new SGraphScene();
  130. this.view.scene = this.scene;
  131. },
  132. methods: {
  133. create() {
  134. this.cmdStatus = "create";
  135. this.scene.root.children = [];
  136. this.polylineItem = new EditCirclePolylineItem(null, []);
  137. this.polylineItem.status = SItemStatus.Create;
  138. this.polylineItem.connect("finishCreated", this, this.finishCreated);
  139. this.scene.addItem(this.polylineItem);
  140. this.scene.grabItem = this.polylineItem;
  141. this.view.update();
  142. },
  143. deleteItem() {
  144. this.cmdStatus = "";
  145. this.scene.removeItem(this.polylineItem);
  146. this.polylineItem = null;
  147. this.view.update();
  148. },
  149. edit() {
  150. if (this.polylineItem) {
  151. if (this.polylineItem.status == SItemStatus.Normal) {
  152. this.scene.grabItem = this.polylineItem;
  153. this.polylineItem.status = SItemStatus.Edit;
  154. // this.polylineItem.verAndLeve = false;
  155. this.cmdStatus = "edit";
  156. } else {
  157. this.polylineItem.status = SItemStatus.Normal;
  158. this.scene.grabItem = null;
  159. this.cmdStatus = "";
  160. }
  161. }
  162. },
  163. eqDrawLine() {
  164. this.cmdStatus = "eqDrawLine";
  165. this.scene.root.children = [];
  166. this.polylineItem = new EditPolylineItem(null, []);
  167. this.polylineItem.verAndLeve = true;
  168. this.polylineItem.status = SItemStatus.Create;
  169. this.polylineItem.connect("finishCreated", this, this.finishCreated);
  170. this.polylineItem.moveable = true;
  171. this.scene.addItem(this.polylineItem);
  172. this.scene.grabItem = this.polylineItem;
  173. this.view.update();
  174. },
  175. // 改变线宽属性
  176. changeLineWidth(val) {
  177. if (this.polylineItem) {
  178. this.lineWidth = val;
  179. this.polylineItem.lineWidth = val;
  180. }
  181. },
  182. // 改变颜色
  183. changeColor(val) {
  184. if (this.polylineItem) {
  185. this.lineColor = hexify(val);
  186. this.polylineItem.strokeColor = new SColor(this.lineColor);
  187. }
  188. },
  189. // 改变填充颜色
  190. changeFillColor(val) {
  191. if (this.polylineItem) {
  192. this.fillColor = hexify(val);
  193. this.polylineItem.fillColor = new SColor(this.lineColor);
  194. }
  195. },
  196. //改变线得类型
  197. changeType(val) {
  198. if (this.polylineItem) {
  199. this.polylineItem.lineStyle = SLineStyle[val];
  200. }
  201. },
  202. // 完成创建后的回调
  203. finishCreated() {
  204. this.cmdStatus = "";
  205. }
  206. },
  207. watch: {
  208. polylineItem(val) {
  209. if (val) {
  210. this.lineWidth = val.lineWidth; // 线宽
  211. this.lineColor = val.strokeColor.value; // 线条填充色
  212. this.lineType = this.options[val.lineStyle].value;
  213. } else {
  214. this.lineWidth = 0;
  215. }
  216. }
  217. }
  218. };
  219. </script>
  220. <style scoped lang="less">
  221. .edit-line {
  222. width: 100%;
  223. height: 500px;
  224. .content {
  225. display: flex;
  226. justify-content: flex-start;
  227. .left {
  228. margin-right: 20px;
  229. }
  230. .line-property {
  231. width: 300px;
  232. margin-top: 20px;
  233. .always {
  234. width: 100%;
  235. height: 100%;
  236. }
  237. .always-item {
  238. display: flex;
  239. margin-top: 10px;
  240. justify-content: space-between;
  241. }
  242. }
  243. }
  244. .heightLight {
  245. color: #409eff;
  246. border-color: #c6e2ff;
  247. background-color: #ecf5ff;
  248. }
  249. }
  250. </style>