index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="draw">
  3. <canvas
  4. id="CANVAS"
  5. class="canvas"
  6. />
  7. <n-select
  8. v-model:value="check"
  9. :options="options"
  10. :render-label="renderLabel"
  11. @update:value="changeOption"
  12. />
  13. <label>
  14. 旋转角度º:
  15. <input type="number">
  16. </label>
  17. <n-button
  18. type="tertiary"
  19. block
  20. >
  21. 撤销
  22. </n-button>
  23. <n-button
  24. type="tertiary"
  25. block
  26. >
  27. 清空
  28. </n-button>
  29. <n-button
  30. type="info"
  31. block
  32. >
  33. 保存
  34. </n-button>
  35. </div>
  36. </template>
  37. <script setup lang='ts'>
  38. import { h, onMounted, ref } from 'vue'
  39. import { DrawCanvas } from './assets/js/draw'
  40. const drawCanvas = new DrawCanvas()
  41. const options = [
  42. {
  43. label: '边界线',
  44. icon: './assets/img/0.png',
  45. value: 0,
  46. w: 5,
  47. h: 3
  48. },
  49. {
  50. label: '灰岩',
  51. icon: './assets/img/1.png',
  52. value: 1,
  53. w: 10,
  54. h: 6
  55. },
  56. {
  57. label: '第四系全新统残坡积',
  58. icon: './assets/img/2.png',
  59. value: 2,
  60. w: 10,
  61. h: 6
  62. },
  63. {
  64. label: '第四系全新统崩坡积',
  65. icon: './assets/img/3.png',
  66. value: 3,
  67. w: 10,
  68. h: 6
  69. },
  70. {
  71. label: '震旦系上统灯影组',
  72. icon: './assets/img/4.png',
  73. value: 4,
  74. w: 10,
  75. h: 6
  76. },
  77. {
  78. label: '志留系中统石门坎组',
  79. icon: './assets/img/5.png',
  80. value: 5,
  81. w: 10,
  82. h: 6
  83. },
  84. {
  85. label: '寒武系中统西王庙组',
  86. icon: './assets/img/6.png',
  87. value: 6,
  88. w: 10,
  89. h: 6
  90. },
  91. {
  92. label: '粉砂岩',
  93. icon: './assets/img/7.png',
  94. value: 7,
  95. w: 10,
  96. h: 6
  97. },
  98. {
  99. label: '页岩',
  100. icon: './assets/img/8.png',
  101. value: 8,
  102. w: 10,
  103. h: 6
  104. },
  105. {
  106. label: '粉砂质泥岩',
  107. icon: './assets/img/9.png',
  108. value: 9,
  109. w: 10,
  110. h: 6
  111. },
  112. {
  113. label: '泥岩',
  114. icon: './assets/img/10.png',
  115. value: 10,
  116. w: 10,
  117. h: 6
  118. },
  119. {
  120. label: '断层破碎带',
  121. icon: './assets/img/11.png',
  122. value: 11,
  123. w: 10,
  124. h: 6
  125. },
  126. {
  127. label: '块石土',
  128. icon: './assets/img/12.png',
  129. value: 12,
  130. w: 10,
  131. h: 6
  132. },
  133. {
  134. label: '白云质灰岩',
  135. icon: './assets/img/13.png',
  136. value: 13,
  137. w: 10,
  138. h: 6
  139. },
  140. {
  141. label: '炭质页岩',
  142. icon: './assets/img/14.png',
  143. value: 14,
  144. w: 10,
  145. h: 6
  146. },
  147. {
  148. label: '推测地层界线',
  149. icon: './assets/img/15.png',
  150. value: 15,
  151. w: 10,
  152. h: 6
  153. },
  154. {
  155. label: '推测岩,土层界线',
  156. icon: './assets/img/16.png',
  157. value: 16,
  158. w: 10,
  159. h: 6
  160. },
  161. {
  162. label: '细砂岩',
  163. icon: './assets/img/17.png',
  164. value: 17,
  165. w: 10,
  166. h: 6
  167. },
  168. {
  169. label: '花岗闪长岩',
  170. icon: './assets/img/18.png',
  171. value: 18,
  172. w: 10,
  173. h: 6
  174. },
  175. {
  176. label: '千枚岩',
  177. icon: './assets/img/19.png',
  178. value: 19,
  179. w: 10,
  180. h: 6
  181. },
  182. {
  183. label: '钙质千枚岩',
  184. icon: './assets/img/20.png',
  185. value: 20,
  186. w: 10,
  187. h: 6
  188. },
  189. {
  190. label: '碳质板岩',
  191. icon: './assets/img/21.png',
  192. value: 21,
  193. w: 10,
  194. h: 6
  195. }
  196. ]
  197. const check = ref(0)
  198. const dicTypePath = {
  199. 2: 'M174.562965,0.513209692 C221.690071,-0.00711210434 258.74832,14.9447077 286.260378,35.6782336 C324.994127,64.8686054 344.820323,105.514125 347.165866,130.556406 C351.169981,173.306492 350.923005,204.505495 338.863366,216.40901 C332.465594,222.723955 293.34237,247.50004 156.505785,247.50004 C124.380762,247.273198 88.5993566,242.423806 60.1185245,235.625016 C31.7537688,228.853934 10.5049705,220.211836 7.77411598,212.201523 C0.968039201,195.148672 -3.37568328,153.116559 5.40190246,119.570011 C11.4412002,98.8625327 30.5685051,60.0564728 69.9004626,32.3721832 C95.541554,14.3243807 129.772401,1.00773417 174.562965,0.513209692 Z',
  200. 1: 'M69.4545878,34.6718448 C96.0319839,14.5464002 130.907219,-0.146079872 174.56443,0.522007913 C220.382312,1.22316053 255.607386,15.5063115 281.851378,35.1514114 C318.898628,62.8833568 338.052622,101.292047 343.850748,127.226896 C348.964999,150.102793 350.773132,170.630546 348.624737,186.798399 C346.628206,201.8234 341.223483,213.080679 331.813382,218.873688 C331.442887,219.101769 331.054704,219.344664 330.644655,219.601247 C319.902715,226.322867 294.07793,242.444674 177.407992,247.500112 C92.0383303,246.776789 19.7179823,226.018176 9.91797058,212.791135 C-0.632619328,198.551039 -1.84542038,163.783447 3.98419444,129.673937 C7.51590663,109.009626 28.7726098,65.4778309 69.4545878,34.6718448 Z',
  201. 0: 'M175.000036,0.5 C222.664535,0.5 265.865535,21.1909654 297.358963,54.7296453 C328.90593,88.3253418 348.705559,134.812441 349.476653,186.303442 L349.490723,188.280824 L349.5,247.5 L0.5,247.5 L0.5,188.283766 C0.787224943,136.359137 20.4197058,89.3998566 51.9881066,55.4283849 C83.5364037,21.4785471 127.005458,0.5 175.000036,0.5 Z'
  202. }
  203. function renderLabel(option: { icon: string | URL; label: string; }) {
  204. return h('div', {
  205. style: {
  206. display: 'flex',
  207. alignItems: 'center'
  208. }
  209. }, [
  210. h('img', {
  211. src: new URL(option.icon, import.meta.url).href,
  212. style: {
  213. width: '20px',
  214. height: '20px',
  215. marginRight: '5px'
  216. }
  217. }),
  218. h('div', {
  219. style: {
  220. fontSize: '14px'
  221. }
  222. }, { default: () => option.label })
  223. ])
  224. }
  225. function changeOption(v: null, option: { label: string; icon: string; value: number; w: number; h: number; }) {
  226. console.log('切换', v, option)
  227. drawCanvas._executionArr.type = v
  228. }
  229. onMounted(() => {
  230. document.title = 'H5 canvas画图'
  231. const canvas = document.getElementById('CANVAS')
  232. drawCanvas._init({
  233. canvas,
  234. dicTypePath: dicTypePath[0],
  235. callBack: () => {
  236. changeOption(null, options[check.value])
  237. }
  238. })
  239. })
  240. </script>
  241. <style lang="scss">
  242. .draw {
  243. max-width: 800px;
  244. min-width: 370px;
  245. margin: 0 auto;
  246. overflow: hidden;
  247. box-sizing: border-box;
  248. padding: 0 10px;
  249. .canvas {
  250. display: block;
  251. margin: 10px auto;
  252. width: 350px;
  253. height: 248px;
  254. }
  255. .n-button {
  256. margin-bottom: 10px;
  257. }
  258. label {
  259. display: block;
  260. font-size: 14px;
  261. margin: 10px 0;
  262. border: 1px solid rgba(196, 200, 206, 1);
  263. padding: 6px 10px;
  264. }
  265. label>input {
  266. border: none;
  267. outline: none;
  268. }
  269. }
  270. </style>./assets/js/draw.js