editPolygon.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. //注: 开发者引入 EditPolygonItem 包为: import {EditPolygonItem} from "@persagy-web/edit/";
  88. import { EditPolygonItem } from "./../../../../../guides/edit/items/src/EditPolygonItem";
  89. import { hexify } from "./../../../../public/until/rgbaUtil";
  90. export default {
  91. name: "editpolygon",
  92. data() {
  93. return {
  94. scene: null, //场景
  95. view: null, //view实例
  96. isCreated: false, //是否创建完成
  97. cmdStatus: "", //选中状态
  98. polygonItem: null, //存放创建的Item
  99. lineWidth: 1, //border线宽
  100. lineColor: "", //border线颜色
  101. fillColor: "", //填充色
  102. lineType: "", //border线类型
  103. options: [
  104. {
  105. value: "Solid",
  106. label: "实线"
  107. },
  108. {
  109. value: "Dashed",
  110. label: "虚线"
  111. },
  112. {
  113. value: "Dotted",
  114. label: "点"
  115. }
  116. ]
  117. };
  118. },
  119. mounted() {
  120. this.view = new SGraphView("edit_polygon");
  121. this.scene = new SGraphScene();
  122. this.view.scene = this.scene;
  123. },
  124. methods: {
  125. create() {
  126. this.cmdStatus = "create";
  127. this.scene.root.children = [];
  128. this.polygonItem = new EditPolygonItem(null);
  129. this.polygonItem.status = SItemStatus.Create;
  130. this.polygonItem.connect("finishCreated", this, this.finishCreated);
  131. this.scene.addItem(this.polygonItem);
  132. this.scene.grabItem = this.polygonItem;
  133. this.view.update();
  134. },
  135. deleteItem() {
  136. this.cmdStatus = "";
  137. this.scene.removeItem(this.polygonItem);
  138. this.polygonItem = null;
  139. this.view.update();
  140. },
  141. edit() {
  142. if (this.polygonItem) {
  143. if (this.polygonItem.status == SItemStatus.Normal) {
  144. this.scene.grabItem = this.polygonItem;
  145. this.polygonItem.status = SItemStatus.Edit;
  146. // this.polygonItem.verAndLeve = false;
  147. this.cmdStatus = "edit";
  148. } else {
  149. this.polygonItem.status = SItemStatus.Normal;
  150. this.scene.grabItem = null;
  151. this.cmdStatus = "";
  152. }
  153. }
  154. },
  155. eqDrawLine() {
  156. this.cmdStatus = "eqDrawLine";
  157. this.scene.root.children = [];
  158. this.polygonItem = new EditPolygonItem(null, []);
  159. this.polygonItem.verAndLeve = true;
  160. this.polygonItem.status = SItemStatus.Create;
  161. this.polygonItem.connect("finishCreated", this, this.finishCreated);
  162. this.polygonItem.moveable = true;
  163. this.scene.addItem(this.polygonItem);
  164. this.scene.grabItem = this.polygonItem;
  165. this.view.update();
  166. },
  167. // 改变线宽属性
  168. changeLineWidth(val) {
  169. if (this.polygonItem) {
  170. this.lineWidth = val;
  171. this.polygonItem.lineWidth = val;
  172. }
  173. },
  174. // 改变颜色
  175. changeColor(val) {
  176. if (this.polygonItem) {
  177. this.lineColor = hexify(val);
  178. this.polygonItem.strokeColor = new SColor(this.lineColor);
  179. }
  180. },
  181. // 改变填充颜色
  182. changeFillColor(val) {
  183. if (this.polygonItem) {
  184. this.fillColor = hexify(val);
  185. this.polygonItem.fillColor = new SColor(this.lineColor);
  186. }
  187. },
  188. //改变线得类型
  189. changeType(val) {
  190. if (this.polygonItem) {
  191. this.polygonItem.lineStyle = SLineStyle[val];
  192. }
  193. },
  194. // 完成创建后的回调
  195. finishCreated() {
  196. this.cmdStatus = "";
  197. }
  198. },
  199. watch: {
  200. polygonItem(val) {
  201. if (val) {
  202. this.lineWidth = val.lineWidth; // 线宽
  203. this.lineStyle = val.lineStyle; // 线条样式
  204. this.lineColor = val.strokeColor.value; // 线条填充色
  205. this.fillColor = val.fillColor.value; // 线条填充色
  206. this.lineType = this.options[val.lineStyle].value;
  207. } else {
  208. this.lineWidth = 0;
  209. }
  210. }
  211. }
  212. };
  213. </script>
  214. <style scoped lang="less">
  215. .edit-line {
  216. width: 100%;
  217. height: 500px;
  218. .content {
  219. display: flex;
  220. justify-content: flex-start;
  221. .left {
  222. margin-right: 20px;
  223. }
  224. .line-property {
  225. width: 300px;
  226. margin-top: 20px;
  227. .always {
  228. width: 100%;
  229. height: 100%;
  230. }
  231. .always-item {
  232. display: flex;
  233. margin-top: 10px;
  234. justify-content: space-between;
  235. }
  236. }
  237. }
  238. .heightLight {
  239. color: #409eff;
  240. border-color: #c6e2ff;
  241. background-color: #ecf5ff;
  242. }
  243. }
  244. </style>