editline1.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. /** 命令所属的场景类 */
  79. scene: null,
  80. view: null, // 实例化 view
  81. isCreated: false, //是否创建完成
  82. cmdStatus: "", //选中状态
  83. lineItem: null, //存放创建的Item
  84. lineWidth: 1,
  85. lineColor: "",
  86. lineType: "",
  87. options: [
  88. {
  89. value: "Solid",
  90. label: "实线"
  91. },
  92. {
  93. value: "Dashed",
  94. label: "虚线"
  95. },
  96. {
  97. value: "Dotted",
  98. label: "点"
  99. }
  100. ]
  101. };
  102. },
  103. /**
  104. * 页面挂载
  105. */
  106. mounted() {
  107. this.view = new SGraphView("edit_line");
  108. this.scene = new SGraphScene();
  109. this.view.scene = this.scene;
  110. },
  111. methods: {
  112. create() {
  113. this.cmdStatus = "create";
  114. this.scene.root.children = [];
  115. this.lineItem = new EditLineItem(null, []);
  116. this.lineItem.status = SItemStatus.Create;
  117. this.lineItem.connect("finishCreated", this, this.finishCreated);
  118. this.scene.addItem(this.lineItem);
  119. this.scene.grabItem = this.lineItem;
  120. this.view.update();
  121. },
  122. deleteItem() {
  123. this.cmdStatus = "";
  124. this.scene.removeItem(this.lineItem);
  125. this.lineItem = null;
  126. this.view.update();
  127. },
  128. edit() {
  129. if (this.lineItem) {
  130. if (this.lineItem.status == SItemStatus.Normal) {
  131. this.scene.grabItem = this.lineItem;
  132. this.lineItem.status = SItemStatus.Edit;
  133. this.cmdStatus = "edit";
  134. } else {
  135. this.lineItem.status = SItemStatus.Normal;
  136. this.scene.grabItem = null;
  137. this.cmdStatus = "";
  138. }
  139. }
  140. },
  141. eqDrawLine() {
  142. this.cmdStatus = "eqDrawLine";
  143. this.scene.root.children = [];
  144. this.lineItem = new EditLineItem(null, []);
  145. this.lineItem.verAndLeve = true;
  146. this.lineItem.status = SItemStatus.Create;
  147. this.lineItem.connect("finishCreated", this, this.finishCreated);
  148. this.scene.addItem(this.lineItem);
  149. this.scene.grabItem = this.lineItem;
  150. this.view.update();
  151. },
  152. // 改变线宽属性
  153. changeLineWidth(val) {
  154. if (this.lineItem) {
  155. this.lineWidth = val;
  156. this.lineItem.lineWidth = val;
  157. }
  158. },
  159. // 改变颜色
  160. changeColor(val) {
  161. if (this.lineItem) {
  162. this.lineColor = hexify(val);
  163. this.lineItem.strokeColor = this.lineColor;
  164. }
  165. },
  166. //改变线得类型
  167. changeType(val) {
  168. if (this.lineItem) {
  169. this.lineItem.lineStyle = SLineStyle[val];
  170. }
  171. },
  172. // 完成创建后的回调
  173. finishCreated() {
  174. this.cmdStatus = "";
  175. }
  176. },
  177. watch: {
  178. lineItem(val) {
  179. if (val) {
  180. this.lineWidth = val.lineWidth; // 线宽
  181. this.lineStyle = val.lineStyle; // 线条样式
  182. this.lineColor = val.strokeColor.value; // 线条填充色
  183. this.lineType = this.options[val.lineStyle].value;
  184. } else {
  185. this.lineWidth = 0;
  186. }
  187. }
  188. }
  189. };
  190. </script>
  191. <style scoped lang="less">
  192. .edit-line {
  193. width: 100%;
  194. height: 500px;
  195. .content {
  196. display: flex;
  197. justify-content: flex-start;
  198. .left {
  199. margin-right: 20px;
  200. }
  201. .line-property {
  202. width: 300px;
  203. margin-top: 20px;
  204. .always {
  205. width: 100%;
  206. height: 100%;
  207. }
  208. .always-item {
  209. display: flex;
  210. margin-top: 10px;
  211. justify-content: space-between;
  212. }
  213. }
  214. }
  215. .heightLight {
  216. color: #409eff;
  217. border-color: #c6e2ff;
  218. background-color: #ecf5ff;
  219. }
  220. }
  221. </style>