sign.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. <template>
  2. <view class="sign">
  3. <view class="wrapper">
  4. <view class="handBtn">
  5. <!-- <image @click="selectColorEvent('black','#1A1A1A')" :src="selectColor === 'black' ? '../static/other/color_black_selected.png' : '../static/other/color_black.png'"
  6. :class="[selectColor === 'black' ? 'color_select' : '', 'black-select']"></image>
  7. <image @click="selectColorEvent('red','#ca262a')" :src="selectColor === 'red' ? '../static/other/color_red_selected.png' : '../static/other/color_red.png'"
  8. :class="[selectColor === 'red' ? 'color_select' : '', 'black-select']"></image> -->
  9. <!-- <button @click="retDraw" class="delBtn">重写</button>
  10. <button @click="saveCanvasAsImg" class="saveBtn">保存</button>
  11. <button @click="previewCanvasImg" class="previewBtn">预览</button>
  12. <button @click="uploadCanvasImg" class="uploadBtn">上传</button>
  13. <button @click="subCanvas" class="subBtn">完成</button> -->
  14. <view class="signtit">请在上方空白处书写您的签名</view>
  15. <view class="sinbtns bgb" @click="retDraw">清除重写</view>
  16. <view class="sinbtns bga" @click="saveCanvasAsImg">提交签名</view>
  17. </view>
  18. <view class="handCenter">
  19. <canvas class="handWriting" :disable-scroll="true" @touchstart="uploadScaleStart" @touchmove="uploadScaleMove"
  20. @touchend="uploadScaleEnd" canvas-id="handWriting"></canvas>
  21. </view>
  22. <!-- <view class="handRight">
  23. <view class="handTitle">请签名</view>
  24. </view> -->
  25. </view>
  26. <!-- 旋转图片canvas -->
  27. <canvas canvas-id="hcamCacnvs" style="position:absolute;top:-2000%;" class="canvsborder"></canvas>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. canvasName: 'handWriting',
  35. ctx: '',
  36. canvasWidth: 0,
  37. canvasHeight: 0,
  38. transparent: 1, // 透明度
  39. selectColor: 'black',
  40. lineColor: '#1A1A1A', // 颜色
  41. lineSize: 1.5, // 笔记倍数
  42. lineMin: 0.5, // 最小笔画半径
  43. lineMax: 4, // 最大笔画半径
  44. pressure: 1, // 默认压力
  45. smoothness: 60, //顺滑度,用60的距离来计算速度
  46. currentPoint: {},
  47. currentLine: [], // 当前线条
  48. firstTouch: true, // 第一次触发
  49. radius: 1, //画圆的半径
  50. cutArea: {
  51. top: 0,
  52. right: 0,
  53. bottom: 0,
  54. left: 0
  55. }, //裁剪区域
  56. bethelPoint: [], //保存所有线条 生成的贝塞尔点;
  57. lastPoint: 0,
  58. chirography: [], //笔迹
  59. currentChirography: {}, //当前笔迹
  60. linePrack: [] //划线轨迹 , 生成线条的实际点
  61. };
  62. },
  63. onLoad() {
  64. let canvasName = this.canvasName;
  65. let ctx = wx.createCanvasContext(canvasName);
  66. this.ctx = ctx;
  67. var query = wx.createSelectorQuery();
  68. query
  69. .select('.handCenter')
  70. .boundingClientRect(rect => {
  71. this.canvasWidth = rect.width;
  72. this.canvasHeight = rect.height;
  73. /* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
  74. this.setCanvasBg('#fff');
  75. })
  76. .exec();
  77. },
  78. methods: {
  79. // 笔迹开始
  80. uploadScaleStart(e) {
  81. if (e.type != 'touchstart') return false;
  82. let ctx = this.ctx;
  83. ctx.setFillStyle(this.lineColor); // 初始线条设置颜色
  84. ctx.setGlobalAlpha(this.transparent); // 设置半透明
  85. let currentPoint = {
  86. x: e.touches[0].x,
  87. y: e.touches[0].y
  88. };
  89. let currentLine = this.currentLine;
  90. currentLine.unshift({
  91. time: new Date().getTime(),
  92. dis: 0,
  93. x: currentPoint.x,
  94. y: currentPoint.y
  95. });
  96. this.currentPoint = currentPoint;
  97. // currentLine
  98. if (this.firstTouch) {
  99. this.cutArea = {
  100. top: currentPoint.y,
  101. right: currentPoint.x,
  102. bottom: currentPoint.y,
  103. left: currentPoint.x
  104. };
  105. this.firstTouch = false;
  106. }
  107. this.pointToLine(currentLine);
  108. },
  109. // 笔迹移动
  110. uploadScaleMove(e) {
  111. if (e.type != 'touchmove') return false;
  112. if (e.cancelable) {
  113. // 判断默认行为是否已经被禁用
  114. if (!e.defaultPrevented) {
  115. e.preventDefault();
  116. }
  117. }
  118. let point = {
  119. x: e.touches[0].x,
  120. y: e.touches[0].y
  121. };
  122. //测试裁剪
  123. if (point.y < this.cutArea.top) {
  124. this.cutArea.top = point.y;
  125. }
  126. if (point.y < 0) this.cutArea.top = 0;
  127. if (point.x > this.cutArea.right) {
  128. this.cutArea.right = point.x;
  129. }
  130. if (this.canvasWidth - point.x <= 0) {
  131. this.cutArea.right = this.canvasWidth;
  132. }
  133. if (point.y > this.cutArea.bottom) {
  134. this.cutArea.bottom = point.y;
  135. }
  136. if (this.canvasHeight - point.y <= 0) {
  137. this.cutArea.bottom = this.canvasHeight;
  138. }
  139. if (point.x < this.cutArea.left) {
  140. this.cutArea.left = point.x;
  141. }
  142. if (point.x < 0) this.cutArea.left = 0;
  143. this.lastPoint = this.currentPoint;
  144. this.currentPoint = point;
  145. let currentLine = this.currentLine;
  146. currentLine.unshift({
  147. time: new Date().getTime(),
  148. dis: this.distance(this.currentPoint, this.lastPoint),
  149. x: point.x,
  150. y: point.y
  151. });
  152. this.pointToLine(currentLine);
  153. },
  154. // 笔迹结束
  155. uploadScaleEnd(e) {
  156. if (e.type != 'touchend') return 0;
  157. let point = {
  158. x: e.changedTouches[0].x,
  159. y: e.changedTouches[0].y
  160. };
  161. this.lastPoint = this.currentPoint;
  162. this.currentPoint = point;
  163. let currentLine = this.currentLine;
  164. currentLine.unshift({
  165. time: new Date().getTime(),
  166. dis: this.distance(this.currentPoint, this.lastPoint),
  167. x: point.x,
  168. y: point.y
  169. });
  170. if (currentLine.length > 2) {
  171. var info = (currentLine[0].time - currentLine[currentLine.length - 1].time) / currentLine.length;
  172. //$("#info").text(info.toFixed(2));
  173. }
  174. //一笔结束,保存笔迹的坐标点,清空,当前笔迹
  175. //增加判断是否在手写区域;
  176. this.pointToLine(currentLine);
  177. var currentChirography = {
  178. lineSize: this.lineSize,
  179. lineColor: this.lineColor
  180. };
  181. var chirography = this.chirography;
  182. chirography.unshift(currentChirography);
  183. this.chirography = chirography;
  184. var linePrack = this.linePrack;
  185. linePrack.unshift(this.currentLine);
  186. this.linePrack = linePrack;
  187. this.currentLine = [];
  188. },
  189. retDraw() {
  190. this.ctx.clearRect(0, 0, 700, 730);
  191. this.ctx.draw();
  192. //设置canvas背景
  193. this.setCanvasBg('#fff');
  194. },
  195. //画两点之间的线条;参数为:line,会绘制最近的开始的两个点;
  196. pointToLine(line) {
  197. this.calcBethelLine(line);
  198. return;
  199. },
  200. //计算插值的方式;
  201. calcBethelLine(line) {
  202. if (line.length <= 1) {
  203. line[0].r = this.radius;
  204. return;
  205. }
  206. let x0,
  207. x1,
  208. x2,
  209. y0,
  210. y1,
  211. y2,
  212. r0,
  213. r1,
  214. r2,
  215. len,
  216. lastRadius,
  217. dis = 0,
  218. time = 0,
  219. curveValue = 0.5;
  220. if (line.length <= 2) {
  221. x0 = line[1].x;
  222. y0 = line[1].y;
  223. x2 = line[1].x + (line[0].x - line[1].x) * curveValue;
  224. y2 = line[1].y + (line[0].y - line[1].y) * curveValue;
  225. //x2 = line[1].x;
  226. //y2 = line[1].y;
  227. x1 = x0 + (x2 - x0) * curveValue;
  228. y1 = y0 + (y2 - y0) * curveValue;
  229. } else {
  230. x0 = line[2].x + (line[1].x - line[2].x) * curveValue;
  231. y0 = line[2].y + (line[1].y - line[2].y) * curveValue;
  232. x1 = line[1].x;
  233. y1 = line[1].y;
  234. x2 = x1 + (line[0].x - x1) * curveValue;
  235. y2 = y1 + (line[0].y - y1) * curveValue;
  236. }
  237. //从计算公式看,三个点分别是(x0,y0),(x1,y1),(x2,y2) ;(x1,y1)这个是控制点,控制点不会落在曲线上;实际上,这个点还会手写获取的实际点,却落在曲线上
  238. len = this.distance({
  239. x: x2,
  240. y: y2
  241. }, {
  242. x: x0,
  243. y: y0
  244. });
  245. lastRadius = this.radius;
  246. for (let n = 0; n < line.length - 1; n++) {
  247. dis += line[n].dis;
  248. time += line[n].time - line[n + 1].time;
  249. if (dis > this.smoothness) break;
  250. }
  251. this.radius = Math.min((time / len) * this.pressure + this.lineMin, this.lineMax) * this.lineSize;
  252. line[0].r = this.radius;
  253. //计算笔迹半径;
  254. if (line.length <= 2) {
  255. r0 = (lastRadius + this.radius) / 2;
  256. r1 = r0;
  257. r2 = r1;
  258. //return;
  259. } else {
  260. r0 = (line[2].r + line[1].r) / 2;
  261. r1 = line[1].r;
  262. r2 = (line[1].r + line[0].r) / 2;
  263. }
  264. let n = 5;
  265. let point = [];
  266. for (let i = 0; i < n; i++) {
  267. let t = i / (n - 1);
  268. let x = (1 - t) * (1 - t) * x0 + 2 * t * (1 - t) * x1 + t * t * x2;
  269. let y = (1 - t) * (1 - t) * y0 + 2 * t * (1 - t) * y1 + t * t * y2;
  270. let r = lastRadius + ((this.radius - lastRadius) / n) * i;
  271. point.push({
  272. x: x,
  273. y: y,
  274. r: r
  275. });
  276. if (point.length == 3) {
  277. let a = this.ctaCalc(point[0].x, point[0].y, point[0].r, point[1].x, point[1].y, point[1].r, point[2].x, point[2]
  278. .y, point[2].r);
  279. a[0].color = this.lineColor;
  280. // let bethelPoint = this.bethelPoint;
  281. // bethelPoint = bethelPoint.push(a);
  282. this.bethelDraw(a, 1);
  283. point = [{
  284. x: x,
  285. y: y,
  286. r: r
  287. }];
  288. }
  289. }
  290. this.currentLine = line;
  291. },
  292. //求两点之间距离
  293. distance(a, b) {
  294. let x = b.x - a.x;
  295. let y = b.y - a.y;
  296. return Math.sqrt(x * x + y * y);
  297. },
  298. ctaCalc(x0, y0, r0, x1, y1, r1, x2, y2, r2) {
  299. let a = [],
  300. vx01,
  301. vy01,
  302. norm,
  303. n_x0,
  304. n_y0,
  305. vx21,
  306. vy21,
  307. n_x2,
  308. n_y2;
  309. vx01 = x1 - x0;
  310. vy01 = y1 - y0;
  311. norm = Math.sqrt(vx01 * vx01 + vy01 * vy01 + 0.0001) * 2;
  312. vx01 = (vx01 / norm) * r0;
  313. vy01 = (vy01 / norm) * r0;
  314. n_x0 = vy01;
  315. n_y0 = -vx01;
  316. vx21 = x1 - x2;
  317. vy21 = y1 - y2;
  318. norm = Math.sqrt(vx21 * vx21 + vy21 * vy21 + 0.0001) * 2;
  319. vx21 = (vx21 / norm) * r2;
  320. vy21 = (vy21 / norm) * r2;
  321. n_x2 = -vy21;
  322. n_y2 = vx21;
  323. a.push({
  324. mx: x0 + n_x0,
  325. my: y0 + n_y0,
  326. color: '#1A1A1A'
  327. });
  328. a.push({
  329. c1x: x1 + n_x0,
  330. c1y: y1 + n_y0,
  331. c2x: x1 + n_x2,
  332. c2y: y1 + n_y2,
  333. ex: x2 + n_x2,
  334. ey: y2 + n_y2
  335. });
  336. a.push({
  337. c1x: x2 + n_x2 - vx21,
  338. c1y: y2 + n_y2 - vy21,
  339. c2x: x2 - n_x2 - vx21,
  340. c2y: y2 - n_y2 - vy21,
  341. ex: x2 - n_x2,
  342. ey: y2 - n_y2
  343. });
  344. a.push({
  345. c1x: x1 - n_x2,
  346. c1y: y1 - n_y2,
  347. c2x: x1 - n_x0,
  348. c2y: y1 - n_y0,
  349. ex: x0 - n_x0,
  350. ey: y0 - n_y0
  351. });
  352. a.push({
  353. c1x: x0 - n_x0 - vx01,
  354. c1y: y0 - n_y0 - vy01,
  355. c2x: x0 + n_x0 - vx01,
  356. c2y: y0 + n_y0 - vy01,
  357. ex: x0 + n_x0,
  358. ey: y0 + n_y0
  359. });
  360. a[0].mx = a[0].mx.toFixed(1);
  361. a[0].mx = parseFloat(a[0].mx);
  362. a[0].my = a[0].my.toFixed(1);
  363. a[0].my = parseFloat(a[0].my);
  364. for (let i = 1; i < a.length; i++) {
  365. a[i].c1x = a[i].c1x.toFixed(1);
  366. a[i].c1x = parseFloat(a[i].c1x);
  367. a[i].c1y = a[i].c1y.toFixed(1);
  368. a[i].c1y = parseFloat(a[i].c1y);
  369. a[i].c2x = a[i].c2x.toFixed(1);
  370. a[i].c2x = parseFloat(a[i].c2x);
  371. a[i].c2y = a[i].c2y.toFixed(1);
  372. a[i].c2y = parseFloat(a[i].c2y);
  373. a[i].ex = a[i].ex.toFixed(1);
  374. a[i].ex = parseFloat(a[i].ex);
  375. a[i].ey = a[i].ey.toFixed(1);
  376. a[i].ey = parseFloat(a[i].ey);
  377. }
  378. return a;
  379. },
  380. bethelDraw(point, is_fill, color) {
  381. let ctx = this.ctx;
  382. ctx.beginPath();
  383. ctx.moveTo(point[0].mx, point[0].my);
  384. if (undefined != color) {
  385. ctx.setFillStyle(color);
  386. ctx.setStrokeStyle(color);
  387. } else {
  388. ctx.setFillStyle(point[0].color);
  389. ctx.setStrokeStyle(point[0].color);
  390. }
  391. for (let i = 1; i < point.length; i++) {
  392. ctx.bezierCurveTo(point[i].c1x, point[i].c1y, point[i].c2x, point[i].c2y, point[i].ex, point[i].ey);
  393. }
  394. ctx.stroke();
  395. if (undefined != is_fill) {
  396. ctx.fill(); //填充图形 ( 后绘制的图形会覆盖前面的图形, 绘制时注意先后顺序 )
  397. }
  398. ctx.draw(true);
  399. },
  400. selectColorEvent(str, color) {
  401. this.selectColor = str;
  402. this.lineColor = color;
  403. },
  404. //将Canvas内容转成 临时图片 --> cb 为回调函数 形参 tempImgPath 为 生成的图片临时路径
  405. canvasToImg(cb) {
  406. //这种写法移动端 出不来
  407. this.ctx.draw(true, () => {
  408. wx.canvasToTempFilePath({
  409. canvasId: 'handWriting',
  410. fileType: 'png',
  411. quality: 1, //图片质量
  412. success(res) {
  413. // console.log(res.tempFilePath, 'canvas生成图片地址');
  414. wx.showToast({
  415. title: '执行了吗?'
  416. });
  417. cb(res.tempFilePath);
  418. }
  419. });
  420. });
  421. },
  422. //完成
  423. subCanvas() {
  424. this.ctx.draw(true, () => {
  425. wx.canvasToTempFilePath({
  426. canvasId: 'handWriting',
  427. fileType: 'png',
  428. quality: 1, //图片质量
  429. success(res) {
  430. // console.log(res.tempFilePath, 'canvas生成图片地址');
  431. wx.showToast({
  432. title: '以保存'
  433. });
  434. //保存到系统相册
  435. wx.saveImageToPhotosAlbum({
  436. filePath: res.tempFilePath,
  437. success(res) {
  438. wx.showToast({
  439. title: '已成功保存到相册',
  440. duration: 2000
  441. });
  442. }
  443. });
  444. }
  445. });
  446. });
  447. },
  448. //保存到相册
  449. saveCanvasAsImg() {
  450. /*
  451. this.canvasToImg( tempImgPath=>{
  452. // console.log(tempImgPath, '临时路径');
  453. wx.saveImageToPhotosAlbum({
  454. filePath: tempImgPath,
  455. success(res) {
  456. wx.showToast({
  457. title: '已保存到相册',
  458. duration: 2000
  459. });
  460. }
  461. })
  462. } );
  463. */
  464. var that=this;
  465. wx.canvasToTempFilePath({
  466. canvasId: 'handWriting',
  467. fileType: 'png',
  468. quality: 1, //图片质量
  469. success(res) {
  470. // 旋转图片90度在上传
  471. //绘制canvas 旋转图片
  472. let tempFilePaths = res.tempFilePath;
  473. wx.getImageInfo({ // 获取图片的信息
  474. src: tempFilePaths,
  475. success: (msg) => {
  476. // console.log(msg)
  477. let height = msg.height / 2 //图片的高
  478. let width = msg.width / 2
  479. //开始旋转 旋转方向为顺时针 90 180 270
  480. if (width < height) { // 竖变横 左为正底 旋转后 为下为正底
  481. // this.canvasWidth = height,
  482. // this.canvasHeight = width,
  483. console.log('这张图片 是竖的 要变成横屏的')
  484. //绘制canvas 旋转图片
  485. let canvas = wx.createCanvasContext('hcamCacnvs',that);
  486. // 逆时针旋转90度
  487. canvas.translate(height / 2, width / 2)
  488. canvas.rotate(270 * Math.PI / 180)
  489. canvas.drawImage(tempFilePaths, -width / 2, -height / 2, width, height);
  490. canvas.draw(false,()=> {
  491. // 把当前画布指定区域的内容导出生成指定大小的图片。在 draw() 回调里调用该方法才能保证图片导出成功。
  492. wx.canvasToTempFilePath({
  493. canvasId: 'hcamCacnvs',
  494. // canvas: canvas,
  495. destWidth: 150,
  496. destHeight: 50,
  497. fileType: 'png',
  498. quality: 1, //图片质量
  499. success(vas) {
  500. // that.uploadImg(vas.tempFilePath);
  501. //保存
  502. // console.log(that.contractId)
  503. uni.saveImageToPhotosAlbum({
  504. filePath: vas.tempFilePath,
  505. success(res) {
  506. wx.showToast({
  507. title: '已保存到相册',
  508. duration: 2000
  509. });
  510. }
  511. });
  512. // uni.uploadFile({
  513. // url: uni.getStorageSync(
  514. // 'requestPath') +
  515. // '/app/contract/getSign', //仅为示例,非真实的接口地址
  516. // filePath: vas.tempFilePath,
  517. // name: 'file',
  518. // formData: {
  519. // 'contractId': that
  520. // .contractId // 上传附带参数
  521. // },
  522. // success: (
  523. // uploadFileRes) => {
  524. // // 根据接口具体返回格式 赋值具体对应url
  525. // console.log(
  526. // uploadFileRes
  527. // )
  528. // uni.showToast({
  529. // title: '签名成功',
  530. // duration: 500
  531. // });
  532. // setTimeout(() => {
  533. // uni.navigateBack({
  534. // delta: 1
  535. // });
  536. // }, 500)
  537. // }
  538. // });
  539. },
  540. }) // 在自定义组件下,当前组件实例的this,以操作组件内 canvas 组件
  541. // }, 300));
  542. // (data) => { // 将之前在绘图上下文中的描述(路径、变形、样式)画到 canvas 中
  543. // console.log(data,12)
  544. })
  545. }
  546. }
  547. })
  548. return
  549. // console.log(res.tempFilePath, 'canvas生成图片地址');
  550. wx.saveImageToPhotosAlbum({
  551. filePath: res.tempFilePath,
  552. success(res) {
  553. wx.showToast({
  554. title: '已保存到相册',
  555. duration: 2000
  556. });
  557. }
  558. });
  559. }
  560. });
  561. },
  562. //预览
  563. previewCanvasImg() {
  564. wx.canvasToTempFilePath({
  565. canvasId: 'handWriting',
  566. fileType: 'jpg',
  567. quality: 1, //图片质量
  568. success(res) {
  569. // console.log(res.tempFilePath, 'canvas生成图片地址');
  570. wx.previewImage({
  571. urls: [res.tempFilePath] //预览图片 数组
  572. });
  573. }
  574. });
  575. /* //移动端出不来 ^~^!!
  576. this.canvasToImg( tempImgPath=>{
  577. wx.previewImage({
  578. urls: [tempImgPath], //预览图片 数组
  579. })
  580. } );
  581. */
  582. },
  583. //上传
  584. uploadCanvasImg() {
  585. wx.canvasToTempFilePath({
  586. canvasId: 'handWriting',
  587. fileType: 'png',
  588. quality: 1, //图片质量
  589. success(res) {
  590. // console.log(res.tempFilePath, 'canvas生成图片地址');
  591. //上传
  592. wx.uploadFile({
  593. url: 'https://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
  594. filePath: res.tempFilePath,
  595. name: 'file_signature',
  596. formData: {
  597. user: 'test'
  598. },
  599. success(res) {
  600. const data = res.data;
  601. // do something
  602. }
  603. });
  604. }
  605. });
  606. },
  607. //设置canvas背景色 不设置 导出的canvas的背景为透明
  608. //@params:字符串 color
  609. setCanvasBg(color) {
  610. /* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
  611. //rect() 参数说明 矩形路径左上角的横坐标,左上角的纵坐标, 矩形路径的宽度, 矩形路径的高度
  612. //这里是 canvasHeight - 4 是因为下边盖住边框了,所以手动减了写
  613. this.ctx.rect(0, 0, this.canvasWidth, this.canvasHeight - 4);
  614. // ctx.setFillStyle('red')
  615. this.ctx.setFillStyle(color);
  616. this.ctx.fill(); //设置填充
  617. this.ctx.draw(); //开画
  618. }
  619. }
  620. };
  621. </script>
  622. <style>
  623. page {
  624. background: #fbfbfb;
  625. height: auto;
  626. overflow: hidden;
  627. }
  628. </style>
  629. <style lang="scss" scoped>
  630. .sign{width: 100%;height: 100vh;padding: 24rpx;}
  631. .signtit{font-weight: 500;font-size: 30rpx;position: absolute;top: 220rpx;word-break: keep-all;transform: rotate(90deg);
  632. color: #666666;left: -140rpx;}
  633. .sinbtns{width: 214rpx;height: 74rpx;display: flex;align-items: center;justify-content: center;font-weight: 500;
  634. font-size: 30rpx;border-radius: 20rpx;position: absolute;left: -46rpx;transform: rotate(90deg);
  635. &.bga{background: #00A9F0;color: #FFFFFF;bottom: 126rpx;}
  636. &.bgb{background: #FFDEDE;color: #FF6969;bottom: 380rpx;}
  637. }
  638. .wrapper {
  639. border: 2rpx solid #DADADA;;
  640. overflow: hidden;
  641. display: flex;
  642. align-content: center;
  643. flex-direction: row;
  644. justify-content: center;
  645. font-size: 28rpx;
  646. width: 100%;height: 100%;
  647. }
  648. .handWriting {
  649. background: #fff;
  650. width: 100%;
  651. height: 100%;
  652. }
  653. .handRight {
  654. display: inline-flex;
  655. align-items: center;
  656. }
  657. .handCenter {
  658. /* border: 4rpx dashed #e9e9e9; */
  659. flex: 1;
  660. overflow: hidden;
  661. box-sizing: border-box;
  662. }
  663. .handTitle {
  664. transform: rotate(90deg);
  665. flex: 1;
  666. color: #666;
  667. }
  668. .handBtn button {
  669. font-size: 28rpx;
  670. }
  671. .handBtn {
  672. position: relative;
  673. height: 100%;
  674. width: 60px;
  675. display: inline-flex;
  676. flex-direction: column;
  677. justify-content: space-between;
  678. align-content: space-between;
  679. flex: 0 0 auto;
  680. border-right: 2rpx solid #DADADA;
  681. }
  682. .delBtn {
  683. position: absolute;
  684. top: 250rpx;
  685. left: 0rpx;
  686. transform: rotate(90deg);
  687. color: #666;
  688. }
  689. .delBtn image {
  690. position: absolute;
  691. top: 13rpx;
  692. left: 25rpx;
  693. }
  694. .subBtn {
  695. position: absolute;
  696. bottom: 52rpx;
  697. left: -3rpx;
  698. display: inline-flex;
  699. transform: rotate(90deg);
  700. background: #008ef6;
  701. color: #fff;
  702. margin-bottom: 30rpx;
  703. text-align: center;
  704. justify-content: center;
  705. }
  706. /*Peach - 新增 - 保存*/
  707. .saveBtn {
  708. position: absolute;
  709. top: 375rpx;
  710. left: 0rpx;
  711. transform: rotate(90deg);
  712. color: #666;
  713. }
  714. .previewBtn {
  715. position: absolute;
  716. top: 500rpx;
  717. left: 0rpx;
  718. transform: rotate(90deg);
  719. color: #666;
  720. }
  721. .uploadBtn {
  722. position: absolute;
  723. top: 625rpx;
  724. left: 0rpx;
  725. transform: rotate(90deg);
  726. color: #666;
  727. }
  728. /*Peach - 新增 - 保存*/
  729. .black-select {
  730. width: 60rpx;
  731. height: 60rpx;
  732. position: absolute;
  733. top: 30rpx;
  734. left: 25rpx;
  735. }
  736. .black-select.color_select {
  737. width: 90rpx;
  738. height: 90rpx;
  739. top: 100rpx;
  740. left: 10rpx;
  741. }
  742. .red-select {
  743. width: 60rpx;
  744. height: 60rpx;
  745. position: absolute;
  746. top: 140rpx;
  747. left: 25rpx;
  748. }
  749. .red-select.color_select {
  750. width: 90rpx;
  751. height: 90rpx;
  752. top: 120rpx;
  753. left: 10rpx;
  754. }
  755. </style>