editimage.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. /**
  70. * 编辑图片场景类
  71. *
  72. * @author 韩耀龙 <hanyaolong@persagy.com>
  73. */
  74. class SScene extends SGraphScene {
  75. /** 命令状态 */
  76. cmdStatus = "";
  77. /** 绘制图片 Item */
  78. imageItem = null;
  79. /**
  80. * 构造函数
  81. */
  82. constructor() {
  83. super();
  84. }
  85. /**
  86. * 鼠标按下事件
  87. *
  88. * @param event 事件
  89. * @returns 是否处理
  90. */
  91. onMouseDown(event) {
  92. if (this.cmdStatus == "create" && this.imageItem) { // 创建状态并且 Image 图片存在
  93. //todo 缺少注释
  94. this.imageItem.moveTo(event.x, event.y);
  95. this.addItem(this.imageItem);
  96. this.changeStatus("");
  97. } else {
  98. return super.onMouseDown(event);
  99. }
  100. }
  101. /**
  102. * 改变状态
  103. */
  104. changeStatus() {
  105. // todo 未完成
  106. }
  107. }
  108. export default {
  109. name: "EditPolylineItem",
  110. data() {
  111. return {
  112. scene: null, //场景
  113. view: null, //view实例
  114. isCreated: false, //是否创建完成
  115. cmdStatus: "", //选中状态
  116. imageItem: null, //存放创建的Item
  117. lineWidth: 1, //border线宽
  118. lineColor: "", //border线颜色
  119. fillColor: "", //填充色
  120. showType: "", //图展示类型
  121. options: [
  122. {
  123. value: "Full",
  124. label: "铺满"
  125. },
  126. {
  127. value: "AutoFit",
  128. label: "自适应"
  129. },
  130. {
  131. value: "Equivalency",
  132. label: "等比缩放"
  133. }
  134. ]
  135. };
  136. },
  137. /**
  138. * 页面挂载
  139. */
  140. mounted() {
  141. this.view = new SGraphView("edit_polygon");
  142. this.scene = new SScene();
  143. this.view.scene = this.scene;
  144. this.scene.changeStatus = this.changeStatus
  145. },
  146. methods: {
  147. /**
  148. * 创建对象
  149. */
  150. create() {
  151. this.cmdStatus = "create";
  152. this.scene.root.children = [];
  153. this.imageItem = new EditImageItem(null);
  154. this.imageItem.url =
  155. "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";
  156. this.imageItem.width = 100;
  157. this.imageItem.height = 100;
  158. this.imageItem.moveable = true;
  159. this.scene.imageItem = this.imageItem;
  160. },
  161. deleteItem() {
  162. this.cmdStatus = "";
  163. this.scene.removeItem(this.imageItem);
  164. this.imageItem = null;
  165. this.view.update();
  166. },
  167. edit() {
  168. if (this.imageItem) {
  169. if (this.imageItem.status == SItemStatus.Normal) {
  170. this.scene.grabItem = this.imageItem;
  171. this.imageItem.status = SItemStatus.Edit;
  172. // this.imageItem.verAndLeve = false;
  173. this.cmdStatus = "edit";
  174. } else {
  175. this.imageItem.status = SItemStatus.Normal;
  176. this.scene.grabItem = null;
  177. this.cmdStatus = "";
  178. }
  179. }
  180. },
  181. eqDrawLine() {
  182. this.cmdStatus = "eqDrawLine";
  183. this.scene.root.children = [];
  184. // this.imageItem = new EditPolylineItem(null, []);
  185. this.imageItem.verAndLeve = true;
  186. this.imageItem.status = SItemStatus.Create;
  187. this.imageItem.connect("finishCreated", this, this.finishCreated);
  188. this.imageItem.moveable = true;
  189. this.scene.addItem(this.imageItem);
  190. this.view.update();
  191. },
  192. // 改变线宽属性
  193. changeLineWidth(val) {
  194. if (this.imageItem) {
  195. this.lineWidth = val;
  196. this.imageItem.lineWidth = val;
  197. }
  198. },
  199. // 改变颜色
  200. changeColor(val) {
  201. if (this.imageItem) {
  202. this.lineColor = hexify(val);
  203. this.imageItem.strokeColor = new SColor(this.lineColor);
  204. }
  205. },
  206. // 改变填充颜色
  207. changeFillColor(val) {
  208. if (this.imageItem) {
  209. this.fillColor = hexify(val);
  210. this.imageItem.fillColor = new SColor(this.lineColor);
  211. }
  212. },
  213. //改变图的展示类型
  214. changeType(val) {
  215. if (this.imageItem) {
  216. this.imageItem.showType = SImageShowType[val];
  217. }
  218. },
  219. // 完成创建后的回调
  220. changeStatus() {
  221. this.cmdStatus = "";
  222. }
  223. },
  224. watch: {
  225. imageItem(val) {
  226. // if (val) {
  227. // this.lineWidth = val.lineWidth; // 线宽
  228. this.showType = this.options[val.showType].value;
  229. // } else {
  230. // this.lineWidth = 0;
  231. // }
  232. },
  233. cmdStatus(val) {
  234. this.scene.cmdStatus = val;
  235. }
  236. }
  237. };
  238. </script>
  239. <style scoped lang="less">
  240. .edit-line {
  241. width: 100%;
  242. height: 500px;
  243. .content {
  244. display: flex;
  245. justify-content: flex-start;
  246. .left {
  247. margin-right: 20px;
  248. }
  249. .line-property {
  250. width: 300px;
  251. margin-top: 20px;
  252. .always {
  253. width: 100%;
  254. height: 100%;
  255. }
  256. .always-item {
  257. display: flex;
  258. margin-top: 10px;
  259. justify-content: space-between;
  260. }
  261. }
  262. }
  263. .heightLight {
  264. color: #409eff;
  265. border-color: #c6e2ff;
  266. background-color: #ecf5ff;
  267. }
  268. }
  269. </style>