editline1.vue 8.1 KB

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