editimage.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="edit-line">
  3. <!-- 所有按钮 -->
  4. <div class="btn-list">
  5. <el-button :class="[cmdStatus=='create' ? 'heightLight' : '']" size="small" @click="create">添加</el-button>
  6. <el-button
  7. :class="[cmdStatus=='deleteItem' ? 'heightLight' : '']"
  8. size="small"
  9. @click="deleteItem"
  10. >删除
  11. </el-button>
  12. </div>
  13. <div class="content">
  14. <div class="left">
  15. <canvas id="edit_polygon" width="700" height="460" tabindex="0"/>
  16. </div>
  17. <div class="line-property">
  18. <el-card shadow="always">
  19. <div slot="header" class="clearfix">
  20. <span>属性修改</span>
  21. </div>
  22. <div class="always-item">
  23. <span>边框宽:</span>
  24. <el-input-number
  25. size="small"
  26. v-model="lineWidth"
  27. @change="changeLineWidth"
  28. :min="1"
  29. :max="50"
  30. ></el-input-number>
  31. </div>
  32. <div class="always-item">
  33. <span>图展示类型:</span>
  34. <el-select
  35. style="width:130px"
  36. size="small"
  37. v-model="showType"
  38. @change="changeType"
  39. placeholder="请选择"
  40. >
  41. <el-option
  42. v-for="item in options"
  43. :key="item.value"
  44. :label="item.label"
  45. :value="item.value"
  46. ></el-option>
  47. </el-select>
  48. </div>
  49. <div class="always-item">
  50. <span>线颜色:</span>
  51. <el-color-picker v-model="lineColor" @change="changeColor" show-alpha></el-color-picker>
  52. </div>
  53. <!-- <div class="always-item">
  54. <span>填充色:</span>
  55. <el-color-picker v-model="fillColor" @change="changeFillColor" show-alpha></el-color-picker>
  56. </div>-->
  57. </el-card>
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import { SGraphScene, SGraphView, SImageShowType } from "@persagy-web/graph/";
  64. import { SItemStatus } from "@persagy-web/big/lib/enums/SItemStatus";
  65. import { SColor } from "@persagy-web/draw/";
  66. //注: 开发者引入 SImageItem 包为: import {SImageItem} from "@persagy-web/edit/";
  67. import { EditImageItem } from "./../../../../../guides/edit/items/src/EditImageItem";
  68. import { hexify } from "./../../../../public/until/rgbaUtil";
  69. class SScene extends SGraphScene {
  70. cmdStatus = "";
  71. imageItem = null;
  72. /**
  73. * 构造函数
  74. */
  75. constructor() {
  76. super();
  77. }
  78. /**
  79. * 鼠标按下事件
  80. *
  81. * @param event 事件
  82. * @returns 是否处理
  83. */
  84. onMouseDown(event) {
  85. if (this.cmdStatus == "create" && this.imageItem) {
  86. this.imageItem.moveTo(event.x, event.y);
  87. this.addItem(this.imageItem);
  88. this.changeStatus("");
  89. } else {
  90. return super.onMouseDown(event);
  91. }
  92. }
  93. // 触发cmdStatus
  94. changeStatus() {
  95. }
  96. }
  97. export default {
  98. name: "EditPolylineItem",
  99. data() {
  100. return {
  101. scene: null, //场景
  102. view: null, //view实例
  103. isCreated: false, //是否创建完成
  104. cmdStatus: "", //选中状态
  105. imageItem: null, //存放创建的Item
  106. lineWidth: 1, //border线宽
  107. lineColor: "", //border线颜色
  108. fillColor: "", //填充色
  109. showType: "", //图展示类型
  110. options: [
  111. {
  112. value: "Full",
  113. label: "铺满"
  114. },
  115. {
  116. value: "AutoFit",
  117. label: "自适应"
  118. },
  119. {
  120. value: "Equivalency",
  121. label: "等比缩放"
  122. }
  123. ]
  124. };
  125. },
  126. mounted() {
  127. this.view = new SGraphView("edit_polygon");
  128. this.scene = new SScene();
  129. this.view.scene = this.scene;
  130. this.scene.changeStatus = this.changeStatus
  131. },
  132. methods: {
  133. create() {
  134. this.cmdStatus = "create";
  135. this.scene.root.children = [];
  136. this.imageItem = new EditImageItem(null);
  137. this.imageItem.url =
  138. "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1591685374103&di=cd5a56b2e3f5e12d7145b967afbcfb7a&imgtype=0&src=http%3A%2F%2Fcdn.duitang.com%2Fuploads%2Fitem%2F201408%2F05%2F20140805191039_cuTPn.jpeg";
  139. this.imageItem.width = 100;
  140. this.imageItem.height = 100;
  141. this.imageItem.moveable = true;
  142. this.scene.imageItem = this.imageItem;
  143. },
  144. deleteItem() {
  145. this.cmdStatus = "";
  146. this.scene.removeItem(this.imageItem);
  147. this.imageItem = null;
  148. this.view.update();
  149. },
  150. edit() {
  151. if (this.imageItem) {
  152. if (this.imageItem.status == SItemStatus.Normal) {
  153. this.scene.grabItem = this.imageItem;
  154. this.imageItem.status = SItemStatus.Edit;
  155. // this.imageItem.verAndLeve = false;
  156. this.cmdStatus = "edit";
  157. } else {
  158. this.imageItem.status = SItemStatus.Normal;
  159. this.scene.grabItem = null;
  160. this.cmdStatus = "";
  161. }
  162. }
  163. },
  164. eqDrawLine() {
  165. this.cmdStatus = "eqDrawLine";
  166. this.scene.root.children = [];
  167. // this.imageItem = new EditPolylineItem(null, []);
  168. this.imageItem.verAndLeve = true;
  169. this.imageItem.status = SItemStatus.Create;
  170. this.imageItem.connect("finishCreated", this, this.finishCreated);
  171. this.imageItem.moveable = true;
  172. this.scene.addItem(this.imageItem);
  173. this.view.update();
  174. },
  175. // 改变线宽属性
  176. changeLineWidth(val) {
  177. if (this.imageItem) {
  178. this.lineWidth = val;
  179. this.imageItem.lineWidth = val;
  180. }
  181. },
  182. // 改变颜色
  183. changeColor(val) {
  184. if (this.imageItem) {
  185. this.lineColor = hexify(val);
  186. this.imageItem.strokeColor = new SColor(this.lineColor);
  187. }
  188. },
  189. // 改变填充颜色
  190. changeFillColor(val) {
  191. if (this.imageItem) {
  192. this.fillColor = hexify(val);
  193. this.imageItem.fillColor = new SColor(this.lineColor);
  194. }
  195. },
  196. //改变图的展示类型
  197. changeType(val) {
  198. if (this.imageItem) {
  199. this.imageItem.showType = SImageShowType[val];
  200. }
  201. },
  202. // 完成创建后的回调
  203. changeStatus() {
  204. this.cmdStatus = "";
  205. }
  206. },
  207. watch: {
  208. imageItem(val) {
  209. // if (val) {
  210. // this.lineWidth = val.lineWidth; // 线宽
  211. this.showType = this.options[val.showType].value;
  212. // } else {
  213. // this.lineWidth = 0;
  214. // }
  215. },
  216. cmdStatus(val) {
  217. this.scene.cmdStatus = val;
  218. }
  219. }
  220. };
  221. </script>
  222. <style scoped lang="less">
  223. .edit-line {
  224. width: 100%;
  225. height: 500px;
  226. .content {
  227. display: flex;
  228. justify-content: flex-start;
  229. .left {
  230. margin-right: 20px;
  231. }
  232. .line-property {
  233. width: 300px;
  234. margin-top: 20px;
  235. .always {
  236. width: 100%;
  237. height: 100%;
  238. }
  239. .always-item {
  240. display: flex;
  241. margin-top: 10px;
  242. justify-content: space-between;
  243. }
  244. }
  245. }
  246. .heightLight {
  247. color: #409eff;
  248. border-color: #c6e2ff;
  249. background-color: #ecf5ff;
  250. }
  251. }
  252. </style>