index_success1.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. <template>
  2. <div id="outerDiv" class="development_stage" v-loading="loadingInfo.isLoading">
  3. <head-component :headinfo=headinfo></head-component>
  4. <div class="page-content page-background">
  5. <canvas width="1920" height="980" style="background-color: #000000;"
  6. id="can"></canvas>
  7. </div>
  8. <div style="position: absolute;top:150px;right: 150px" v-show="!loading">
  9. <el-button @click="changePaintState">{{paintStateFlagText}}</el-button>
  10. <el-button @click="clear">清空</el-button>
  11. <el-button @click="save(null)">保存</el-button>
  12. <el-button @click="finishRepaint('new')">绘制完成</el-button>
  13. </div>
  14. </div>
  15. </template>
  16. <script setup>
  17. import headComponent from '@/views/xjc-integratedmachine/components/head_component.vue'
  18. import {newRainbow, saveRainbow, finish} from '@/api/xjc-integratedmachine/wakeup/rainbow.js'
  19. const loading = ref(true)
  20. const headinfo = ref({})
  21. import {onMounted} from 'vue'
  22. import * as echarts from "echarts";
  23. import html2canvas from 'html2canvas';
  24. import {ElMessage} from 'element-plus'
  25. const backgroundImage = new Image();
  26. // backgroundImage.src = 'http://192.168.3.100/screenshot.png'; // 替换为你的背景图片路径
  27. let CENTER_X = 960;
  28. let CENTER_Y = 980;
  29. let startMouse = {x: 0, y: 0};
  30. let moveMouse = {x: 0, y: 0};
  31. // 画笔橡皮擦状态,true画笔,false橡皮
  32. let paintStateFlag = true;
  33. let paintStateFlagText = ref('画笔');
  34. // 第一个职业
  35. let startAngle11 = 0;
  36. let startAngle12 = 0;
  37. let startAngle13 = 0;
  38. // 第二个职业
  39. let startAngle21 = 0;
  40. let startAngle22 = 0;
  41. let startAngle23 = 0;
  42. // 第三个职业
  43. let startAngle31 = 0;
  44. let startAngle32 = 0;
  45. let startAngle33 = 0;
  46. // 第四个职业
  47. let startAngle41 = 0;
  48. let startAngle42 = 0;
  49. let startAngle43 = 0;
  50. // 第五个职业
  51. let startAngle51 = 0;
  52. let startAngle52 = 0;
  53. let startAngle53 = 0;
  54. // 第六个职业
  55. let startAngle61 = 0;
  56. let startAngle62 = 0;
  57. let startAngle63 = 0;
  58. // 第七个职业
  59. let startAngle71 = 0;
  60. let startAngle72 = 0;
  61. let startAngle73 = 0;
  62. let raduisColor = ["#000000",
  63. "#ffc300", "#f72585", "#4cc9f0", "#a000ff", "#ffc9f6", "#9de617"
  64. ]
  65. let radiusHalf = new Map(
  66. [
  67. ["startAngle11", [10, 50]],
  68. ["startAngle12", [50, 90]],
  69. ["startAngle13", [90, 130]],
  70. ["startAngle21", [145, 185]],
  71. ["startAngle22", [185, 225]],
  72. ["startAngle23", [225, 265]],
  73. ["startAngle31", [280, 320]],
  74. ["startAngle32", [320, 360]],
  75. ["startAngle33", [360, 400]],
  76. ["startAngle41", [415, 455]],
  77. ["startAngle42", [455, 495]],
  78. ["startAngle43", [495, 535]],
  79. ["startAngle51", [550, 590]],
  80. ["startAngle52", [590, 630]],
  81. ["startAngle53", [630, 670]],
  82. ["startAngle61", [685, 725]],
  83. ["startAngle62", [725, 765]],
  84. ["startAngle63", [765, 805]]
  85. ]
  86. )
  87. // 所有轨道绘画限制
  88. let paintFlagList = [
  89. false, false, false,
  90. false, false, false,
  91. false, false, false,
  92. false, false, false,
  93. false, false, false,
  94. false, false, false]
  95. let undoList = []; // 用于保存所有操作,用于撤销和重做
  96. let redoList = []; // 用于保存所有撤销的操作,用于重做
  97. function changes() {
  98. can.addEventListener('touchstart', function (el) {
  99. let rect = el.target.getBoundingClientRect();
  100. startMouse.x = el.touches[0].pageX - rect.left;
  101. startMouse.y = el.touches[0].pageY - rect.top;
  102. calcStartRadius();
  103. can.addEventListener('touchmove', function (e) {
  104. moveMouse.x = startMouse.x;
  105. moveMouse.y = startMouse.y;
  106. startMouse.x = e.targetTouches[0].pageX - this.offsetLeft;
  107. startMouse.y = e.targetTouches[0].pageY - this.offsetTop;
  108. if (startMouse.x !== moveMouse.x && startMouse.y !== moveMouse.y) {
  109. return;
  110. }
  111. calcEndRadius();
  112. //计算是否超出本轨道
  113. let sum = Math.pow(moveMouse.x - CENTER_X, 2) + Math.pow(CENTER_Y - moveMouse.y, 2);
  114. let key = form.value.picData[form.value.picData.length - 1].angle
  115. let value = radiusHalf.get(key)
  116. let min = Math.pow(value[0], 2)
  117. let max = Math.pow(value[1], 2)
  118. if (sum < min || sum > max) {
  119. recordEnd()
  120. return;
  121. }
  122. })
  123. })
  124. can.addEventListener('touchend', function (e) {
  125. can.onmousemove = null;
  126. //获取结束点
  127. recordEnd()
  128. })
  129. }
  130. function recordEnd() {
  131. let endAngle = calcEndRadius();
  132. form.value.picData[form.value.picData.length - 1].endAngle = endAngle;
  133. }
  134. /*计算起始点*/
  135. function calcStartRadius() {
  136. let data = {startAngle: 0, angle: ''}
  137. data.paintStateFlag = paintStateFlag
  138. let sum = Math.pow(startMouse.x - CENTER_X, 2) + Math.pow(CENTER_Y - startMouse.y, 2);
  139. // 第一个职业
  140. if (sum < Math.pow(50, 2) && sum > Math.pow(10, 2)) {
  141. startAngle11 = calcAngle();
  142. data.startAngle = startAngle11
  143. data.angle = 'startAngle11'
  144. calcPaintCircleFlag(0)
  145. } else if (sum < Math.pow(90, 2) && sum > Math.pow(50, 2)) {
  146. startAngle12 = calcAngle();
  147. data.startAngle = startAngle12
  148. data.angle = 'startAngle12'
  149. calcPaintCircleFlag(1)
  150. } else if (sum < Math.pow(130, 2) && sum > Math.pow(90, 2)) {
  151. startAngle13 = calcAngle();
  152. data.startAngle = startAngle13
  153. data.angle = 'startAngle13'
  154. calcPaintCircleFlag(2)
  155. }
  156. // 第二个职业
  157. else if (sum < Math.pow(185, 2) && sum > Math.pow(145, 2)) {
  158. startAngle21 = calcAngle();
  159. data.startAngle = startAngle21
  160. data.angle = 'startAngle21'
  161. calcPaintCircleFlag(3)
  162. } else if (sum < Math.pow(225, 2) && sum > Math.pow(185, 2)) {
  163. startAngle22 = calcAngle();
  164. data.startAngle = startAngle22
  165. data.angle = 'startAngle22'
  166. calcPaintCircleFlag(4)
  167. } else if (sum < Math.pow(265, 2) && sum > Math.pow(225, 2)) {
  168. startAngle23 = calcAngle();
  169. data.startAngle = startAngle23
  170. data.angle = 'startAngle23'
  171. calcPaintCircleFlag(5)
  172. }
  173. // 第三个职业
  174. else if (sum < Math.pow(320, 2) && sum > Math.pow(280, 2)) {
  175. startAngle31 = calcAngle();
  176. data.startAngle = startAngle31
  177. data.angle = 'startAngle31'
  178. calcPaintCircleFlag(6)
  179. } else if (sum < Math.pow(360, 2) && sum > Math.pow(320, 2)) {
  180. startAngle32 = calcAngle();
  181. data.startAngle = startAngle32
  182. data.angle = 'startAngle32'
  183. calcPaintCircleFlag(7)
  184. } else if (sum < Math.pow(400, 2) && sum > Math.pow(360, 2)) {
  185. startAngle33 = calcAngle();
  186. data.startAngle = startAngle33
  187. data.angle = 'startAngle33'
  188. calcPaintCircleFlag(8)
  189. }
  190. // 第四个职业
  191. else if (sum < Math.pow(455, 2) && sum > Math.pow(415, 2)) {
  192. startAngle41 = calcAngle();
  193. data.startAngle = startAngle41
  194. data.angle = 'startAngle41'
  195. calcPaintCircleFlag(9)
  196. } else if (sum < Math.pow(495, 2) && sum > Math.pow(455, 2)) {
  197. startAngle42 = calcAngle();
  198. data.startAngle = startAngle42
  199. data.angle = 'startAngle42'
  200. calcPaintCircleFlag(10)
  201. } else if (sum < Math.pow(535, 2) && sum > Math.pow(495, 2)) {
  202. startAngle43 = calcAngle();
  203. data.startAngle = startAngle43
  204. data.angle = 'startAngle43'
  205. calcPaintCircleFlag(11)
  206. }
  207. // 第五个职业
  208. else if (sum < Math.pow(590, 2) && sum > Math.pow(550, 2)) {
  209. startAngle51 = calcAngle();
  210. data.startAngle = startAngle51
  211. data.angle = 'startAngle51'
  212. calcPaintCircleFlag(12)
  213. } else if (sum < Math.pow(630, 2) && sum > Math.pow(590, 2)) {
  214. startAngle52 = calcAngle();
  215. data.startAngle = startAngle52
  216. data.angle = 'startAngle52'
  217. calcPaintCircleFlag(13)
  218. } else if (sum < Math.pow(670, 2) && sum > Math.pow(630, 2)) {
  219. startAngle53 = calcAngle();
  220. data.startAngle = startAngle53
  221. data.angle = 'startAngle53'
  222. calcPaintCircleFlag(14)
  223. }
  224. // 第六个职业
  225. else if (sum < Math.pow(725, 2) && sum > Math.pow(685, 2)) {
  226. startAngle61 = calcAngle();
  227. data.startAngle = startAngle61
  228. data.angle = 'startAngle61'
  229. calcPaintCircleFlag(15)
  230. } else if (sum < Math.pow(765, 2) && sum > Math.pow(725, 2)) {
  231. startAngle62 = calcAngle();
  232. data.startAngle = startAngle62
  233. data.angle = 'startAngle62'
  234. calcPaintCircleFlag(16)
  235. } else if (sum < Math.pow(805, 2) && sum > Math.pow(765, 2)) {
  236. startAngle63 = calcAngle();
  237. data.startAngle = startAngle63
  238. data.angle = 'startAngle63'
  239. calcPaintCircleFlag(17)
  240. }
  241. if(data.startAngle == 0){
  242. alert("起点角度记录不完整")
  243. }else if(data.angle == ''){
  244. alert("起点轨道记录不完整")
  245. }else{
  246. form.value.picData.push(data)
  247. }
  248. }
  249. /**
  250. * 只有起始点所在轨道可以绘制
  251. **/
  252. function calcPaintCircleFlag(index) {
  253. paintFlagList = [
  254. false, false, false,
  255. false, false, false,
  256. false, false, false,
  257. false, false, false,
  258. false, false, false,
  259. false, false, false]
  260. paintFlagList[index] = true
  261. }
  262. /*计算终点*/
  263. function calcEndRadius() {
  264. let sum = Math.pow(moveMouse.x - CENTER_X, 2) + Math.pow(CENTER_Y - moveMouse.y, 2);
  265. let ret = calcAngle();
  266. // 第一个职业
  267. if (sum < Math.pow(50, 2) && sum > Math.pow(10, 2)) {
  268. if (paintFlagList[0]) {
  269. if (paintStateFlag) {
  270. paint(raduisColor[1], 30, startAngle11, ret);
  271. } else {
  272. paint(raduisColor[0], 30, startAngle11, ret);
  273. paint(raduisColor[0], 70, startAngle11, ret);
  274. paint(raduisColor[0], 110, startAngle11, ret);
  275. }
  276. }
  277. } else if (sum < Math.pow(90, 2) && sum > Math.pow(50, 2)) {
  278. if (paintFlagList[1]) {
  279. if (paintStateFlag) {
  280. paint(raduisColor[1], 30, startAngle12, ret);
  281. paint(raduisColor[1], 70, startAngle12, ret);
  282. } else {
  283. paint(raduisColor[0], 70, startAngle12, ret);
  284. paint(raduisColor[0], 110, startAngle12, ret);
  285. }
  286. }
  287. } else if (sum < Math.pow(130, 2) && sum > Math.pow(90, 2)) {
  288. if (paintFlagList[2]) {
  289. if (paintStateFlag) {
  290. paint(raduisColor[1], 30, startAngle13, ret);
  291. paint(raduisColor[1], 70, startAngle13, ret);
  292. paint(raduisColor[1], 110, startAngle13, ret);
  293. } else {
  294. paint(raduisColor[0], 110, startAngle13, ret);
  295. }
  296. }
  297. }
  298. // 第二个职业
  299. else if (sum < Math.pow(185, 2) && sum > Math.pow(145, 2)) {
  300. if (paintFlagList[3]) {
  301. if (paintStateFlag) {
  302. paint(raduisColor[2], 165, startAngle21, ret);
  303. } else {
  304. paint(raduisColor[0], 165, startAngle21, ret);
  305. paint(raduisColor[0], 205, startAngle21, ret);
  306. paint(raduisColor[0], 245, startAngle21, ret);
  307. }
  308. }
  309. } else if (sum < Math.pow(225, 2) && sum > Math.pow(185, 2)) {
  310. if (paintFlagList[4]) {
  311. if (paintStateFlag) {
  312. paint(raduisColor[2], 165, startAngle22, ret);
  313. paint(raduisColor[2], 205, startAngle22, ret);
  314. } else {
  315. paint(raduisColor[0], 205, startAngle22, ret);
  316. paint(raduisColor[0], 245, startAngle22, ret);
  317. }
  318. }
  319. } else if (sum < Math.pow(265, 2) && sum > Math.pow(225, 2)) {
  320. if (paintFlagList[5]) {
  321. if (paintStateFlag) {
  322. paint(raduisColor[2], 165, startAngle23, ret);
  323. paint(raduisColor[2], 205, startAngle23, ret);
  324. paint(raduisColor[2], 245, startAngle23, ret);
  325. } else {
  326. paint(raduisColor[0], 245, startAngle23, ret);
  327. }
  328. }
  329. }
  330. //第三个职业
  331. else if (sum < Math.pow(320, 2) && sum > Math.pow(280, 2)) {
  332. if (paintFlagList[6]) {
  333. if (paintStateFlag) {
  334. paint(raduisColor[3], 300, startAngle31, ret);
  335. } else {
  336. paint(raduisColor[0], 300, startAngle31, ret);
  337. paint(raduisColor[0], 340, startAngle31, ret);
  338. paint(raduisColor[0], 380, startAngle31, ret);
  339. }
  340. }
  341. } else if (sum < Math.pow(360, 2) && sum > Math.pow(320, 2)) {
  342. if (paintFlagList[7]) {
  343. if (paintStateFlag) {
  344. paint(raduisColor[3], 300, startAngle31, ret);
  345. paint(raduisColor[3], 340, startAngle31, ret);
  346. } else {
  347. paint(raduisColor[0], 340, startAngle32, ret);
  348. paint(raduisColor[0], 380, startAngle32, ret);
  349. }
  350. }
  351. } else if (sum < Math.pow(400, 2) && sum > Math.pow(360, 2)) {
  352. if (paintFlagList[8]) {
  353. if (paintStateFlag) {
  354. paint(raduisColor[3], 300, startAngle33, ret);
  355. paint(raduisColor[3], 340, startAngle33, ret);
  356. paint(raduisColor[3], 380, startAngle33, ret);
  357. } else {
  358. paint(raduisColor[0], 380, startAngle33, ret);
  359. }
  360. }
  361. }
  362. //第四个职业
  363. else if (sum < Math.pow(455, 2) && sum > Math.pow(415, 2)) {
  364. if (paintFlagList[9]) {
  365. if (paintStateFlag) {
  366. paint(raduisColor[4], 435, startAngle41, ret);
  367. } else {
  368. paint(raduisColor[0], 435, startAngle41, ret);
  369. paint(raduisColor[0], 475, startAngle41, ret);
  370. paint(raduisColor[0], 515, startAngle41, ret);
  371. }
  372. }
  373. } else if (sum < Math.pow(495, 2) && sum > Math.pow(455, 2)) {
  374. if (paintFlagList[10]) {
  375. if (paintStateFlag) {
  376. paint(raduisColor[4], 435, startAngle42, ret);
  377. paint(raduisColor[4], 475, startAngle42, ret);
  378. } else {
  379. paint(raduisColor[0], 475, startAngle42, ret);
  380. paint(raduisColor[0], 515, startAngle42, ret);
  381. }
  382. }
  383. } else if (sum < Math.pow(535, 2) && sum > Math.pow(495, 2)) {
  384. if (paintFlagList[11]) {
  385. if (paintStateFlag) {
  386. paint(raduisColor[4], 435, startAngle43, ret);
  387. paint(raduisColor[4], 475, startAngle43, ret);
  388. paint(raduisColor[4], 515, startAngle43, ret);
  389. } else {
  390. paint(raduisColor[0], 515, startAngle43, ret);
  391. }
  392. }
  393. }
  394. //第五个职业
  395. else if (sum < Math.pow(590, 2) && sum > Math.pow(550, 2)) {
  396. if (paintFlagList[12]) {
  397. if (paintStateFlag) {
  398. paint(raduisColor[5], 570, startAngle51, ret);
  399. } else {
  400. paint(raduisColor[0], 570, startAngle51, ret);
  401. paint(raduisColor[0], 610, startAngle51, ret);
  402. paint(raduisColor[0], 650, startAngle51, ret);
  403. }
  404. }
  405. } else if (sum < Math.pow(630, 2) && sum > Math.pow(590, 2)) {
  406. if (paintFlagList[13]) {
  407. if (paintStateFlag) {
  408. paint(raduisColor[5], 570, startAngle52, ret);
  409. paint(raduisColor[5], 610, startAngle52, ret);
  410. } else {
  411. paint(raduisColor[0], 610, startAngle52, ret);
  412. paint(raduisColor[0], 650, startAngle52, ret);
  413. }
  414. }
  415. } else if (sum < Math.pow(670, 2) && sum > Math.pow(630, 2)) {
  416. if (paintFlagList[14]) {
  417. if (paintStateFlag) {
  418. paint(raduisColor[5], 570, startAngle53, ret);
  419. paint(raduisColor[5], 610, startAngle53, ret);
  420. paint(raduisColor[5], 650, startAngle53, ret);
  421. } else {
  422. paint(raduisColor[0], 650, startAngle53, ret);
  423. }
  424. }
  425. }
  426. //第六个职业
  427. else if (sum < Math.pow(725, 2) && sum > Math.pow(685, 2)) {
  428. if (paintFlagList[15]) {
  429. if (paintStateFlag) {
  430. paint(raduisColor[6], 705, startAngle61, ret);
  431. } else {
  432. paint(raduisColor[0], 705, startAngle61, ret);
  433. paint(raduisColor[0], 745, startAngle61, ret);
  434. paint(raduisColor[0], 785, startAngle61, ret);
  435. }
  436. }
  437. } else if (sum < Math.pow(765, 2) && sum > Math.pow(725, 2)) {
  438. if (paintFlagList[16]) {
  439. if (paintStateFlag) {
  440. paint(raduisColor[6], 705, startAngle62, ret);
  441. paint(raduisColor[6], 745, startAngle62, ret);
  442. } else {
  443. paint(raduisColor[0], 745, startAngle62, ret);
  444. paint(raduisColor[0], 785, startAngle62, ret);
  445. }
  446. }
  447. } else if (sum < Math.pow(805, 2) && sum > Math.pow(765, 2)) {
  448. if (paintFlagList[17]) {
  449. if (paintStateFlag) {
  450. paint(raduisColor[6], 705, startAngle63, ret);
  451. paint(raduisColor[6], 745, startAngle63, ret);
  452. paint(raduisColor[6], 785, startAngle63, ret);
  453. } else {
  454. paint(raduisColor[0], 785, startAngle63, ret);
  455. }
  456. }
  457. }
  458. return ret;
  459. }
  460. /*计算角度0-180度*/
  461. function calcAngle() {
  462. let number = Math.atan2(Math.abs(CENTER_Y - startMouse.y), CENTER_X - startMouse.x);
  463. let ret = number * 180 / Math.PI; //弧度转角度,方便调试
  464. if (ret > 360) {
  465. ret -= 360;
  466. }
  467. if (ret < 0) {
  468. ret += 450;
  469. }
  470. let num = ret * Math.PI / 180 + Math.PI;
  471. return num;
  472. }
  473. let can = "";
  474. let context = "";
  475. function init() {
  476. can = document.getElementById('can');
  477. context = can.getContext('2d');
  478. }
  479. function arc(num) {
  480. context.lineWidth = 1;
  481. context.setLineDash([]);
  482. context.strokeStyle = '#ffffff'
  483. context.beginPath();
  484. context.arc(CENTER_X, CENTER_Y, num, Math.PI, 2 * Math.PI, false);
  485. context.stroke();
  486. }
  487. function arcDashed(num) {
  488. context.lineWidth = 1;
  489. context.setLineDash([]);
  490. context.strokeStyle = '#ffffff'
  491. context.beginPath();
  492. context.arc(CENTER_X, CENTER_Y, num, Math.PI, 2 * Math.PI, false);
  493. context.stroke();
  494. }
  495. function paint(color, radius, startAngle, endAngle) {
  496. // 结束角度不能小于起始角度
  497. if (endAngle <= startAngle) {
  498. // ElMessage.error("只能顺时针画")
  499. return;
  500. }
  501. context.setLineDash([]);
  502. context.lineWidth = 37;
  503. context.strokeStyle = color;
  504. context.beginPath();
  505. context.arc(CENTER_X, CENTER_Y, radius, startAngle, endAngle, false);
  506. context.stroke();
  507. }
  508. function reset() {
  509. paintStateFlag = true;
  510. paintStateFlagText.value = '画笔'
  511. }
  512. function changePaintState() {
  513. if (paintStateFlag) {
  514. paintStateFlag = false;
  515. paintStateFlagText.value = '橡皮擦'
  516. } else {
  517. paintStateFlag = true;
  518. paintStateFlagText.value = '画笔'
  519. }
  520. }
  521. function eraserState() {
  522. paintStateFlag = false;
  523. }
  524. function clear() {
  525. context.clearRect(0, 0, can.width, can.height);
  526. drawBackground();
  527. }
  528. function drawBackground() {
  529. let radius = 10;
  530. arc(radius);
  531. for (let i = 1; i < 24; i++) {
  532. radius = drawBackgroundOne(radius, i);
  533. // arc(radius);
  534. if (i % 4 == 0) {
  535. arc(radius);
  536. } else {
  537. arcDashed(radius)
  538. }
  539. }
  540. }
  541. function drawBackgroundOne(innerRadius, i) {
  542. if (i % 4 == 0) {
  543. return innerRadius + 15;
  544. } else {
  545. return innerRadius + 40;
  546. }
  547. }
  548. // function save() {
  549. // html2canvas(can).then(canvas => {
  550. // const link = document.createElement('a');
  551. // link.download = 'screenshot.png';
  552. // link.href = canvas.toDataURL();
  553. // link.click();
  554. // document.body.removeChild(link); // 清理创建的链接
  555. // });
  556. // // capturePage()
  557. // }
  558. const content = ref(null);
  559. const canvas = ref(null);
  560. import {uploadFile} from '@/utils/request.js'
  561. async function capturePage(type) {
  562. const element = document.getElementById('can');
  563. await html2canvas(element, {
  564. allowTaint: true,
  565. useCORS: true,
  566. scale: 1, // 缩放比例,可以设置为更高分辨率
  567. logging: true, // 启用日志
  568. backgroundColor: '#ffffff' // 背景颜色
  569. }).then(canvas => {
  570. canvas.toBlob(async blob => {
  571. const formData = new FormData();
  572. formData.append('file', blob, 'screenshot.png');
  573. await uploadFile('/file/upload', formData).then(resp => {
  574. form.value.picUrl = resp.url
  575. saveAllData(type)
  576. })
  577. })
  578. })
  579. }
  580. const form = ref({})
  581. function initRainbow(rFrom) {
  582. loading.value = true
  583. newRainbow(rFrom).then(resp => {
  584. form.value.id = resp.id
  585. if (resp.picData != null && resp.picData != '') {
  586. form.value.picData = JSON.parse(resp.picData);
  587. } else {
  588. form.value.picData = []
  589. }
  590. loading.value = false
  591. backShow(form.value.picData)
  592. })
  593. }
  594. function backShow(picData) {
  595. if (picData.length == 0) {
  596. //清空
  597. } else {
  598. //根据数据重绘
  599. picData.forEach(function (item, index) {
  600. repaint(item)
  601. })
  602. }
  603. }
  604. function repaint(item) {
  605. let paintStateFlag = item.paintStateFlag
  606. //第几职业
  607. let angleNum = item.angle.substr(10, 1)
  608. let color = raduisColor[parseInt(angleNum)]
  609. //第几轨道
  610. let angleCount = item.angle.substr(11, 1)
  611. let startAngle = item.startAngle;
  612. let endAngle = item.endAngle;
  613. let radius = radiusHalf.get(item.angle);
  614. let min = radius[0];
  615. let max = radius[1];
  616. let middle = min + (max - min) / 2
  617. // console.log(item.angle,"=======",radius,"mmmmm",middle)
  618. // console.log("count:",angleCount,"middle:",middle)
  619. if(paintStateFlag == true){
  620. if(angleCount == 1){
  621. paint(color, middle, startAngle, endAngle);
  622. }else if(angleCount == 2){
  623. paint(color, middle, startAngle, endAngle);
  624. paint(color, middle-40, startAngle, endAngle);
  625. }else if(angleCount == 3){
  626. paint(color, middle, startAngle, endAngle);
  627. paint(color, middle-40, startAngle, endAngle);
  628. paint(color, middle-80, startAngle, endAngle);
  629. }
  630. }else{
  631. if(angleCount == 1){
  632. paint(raduisColor[0], middle, startAngle, endAngle);
  633. paint(raduisColor[0], middle+40, startAngle, endAngle);
  634. paint(raduisColor[0], middle+80, startAngle, endAngle);
  635. }else if(angleCount == 2){
  636. paint(raduisColor[0], middle, startAngle, endAngle);
  637. paint(raduisColor[0], middle+40, startAngle, endAngle);
  638. }else if(angleCount == 3){
  639. paint(raduisColor[0], middle, startAngle, endAngle);
  640. }
  641. }
  642. }
  643. function saveAllData(type) {
  644. if (form.value.picData.length > 0) {
  645. form.value.picDataArray = form.value.picData
  646. form.value.picData = null
  647. saveRainbow(form.value).then(resp => {
  648. loadingInfo.value.isLoading = false
  649. initRainbow({
  650. type: type
  651. });
  652. })
  653. } else {
  654. loadingInfo.value.isLoading = false
  655. }
  656. }
  657. const loadingInfo = ref({
  658. isLoading: false,
  659. text: ' '
  660. })
  661. function save(type) {
  662. loadingInfo.value.isLoading = true
  663. loadingInfo.value.text = "正在保存图片"
  664. //截屏
  665. capturePage(type)
  666. reset()
  667. }
  668. function finishRepaint(type) {
  669. save(type)
  670. }
  671. onMounted(() => {
  672. init();
  673. changes();
  674. initRainbow({type: null});
  675. drawBackground();
  676. });
  677. </script>
  678. <style scoped lang="scss">
  679. //body,html{
  680. // overflow: hidden;
  681. //}
  682. p {
  683. margin: 0;
  684. padding: 0;
  685. }
  686. .development_stage {
  687. background: url('@/assets/images/login/login-home-background.png') no-repeat;
  688. background-size: 1920px 1080px;
  689. z-index: 10;
  690. width: 100%;
  691. height: 1080px;
  692. }
  693. .page-content {
  694. display: flex;
  695. justify-content: center;
  696. padding-top: 100px;
  697. }
  698. .page-background {
  699. /*padding-top: 100px;*/
  700. /*margin-top: 60px;*/
  701. /*height: 980px;*/
  702. width: 100%;
  703. /*background-color: #000000;*/
  704. /*border: solid red 1px;*/
  705. }
  706. .bg-color-style1 {
  707. background: #FFFFFF;
  708. }
  709. </style>