工行这里学车报名流程h5
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
5.1 KiB

2 years ago
  1. <template>
  2. <view class="signature-box">
  3. <view class="topTps">需要您签名确认学时</view>
  4. <!-- 签名 -->
  5. <view class="signature">
  6. <canvas ref="mycanvas" class="mycanvas" canvas-id="mycanvas" @touchstart="touchstart" @touchmove="touchmove"
  7. @touchend="touchend"></canvas>
  8. </view>
  9. <view class="footBox">
  10. <view class="checkCon">
  11. <u-checkbox-group>
  12. <u-checkbox v-model="checked">本人 {{realName}} 承诺以上签名真实有效</u-checkbox>
  13. </u-checkbox-group>
  14. </view>
  15. <view class="footBtn">
  16. <view class="btn border" @click="clear">重签</view>
  17. <view class="btn" @click="finish">提交</view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. // import { pathToBase64 } from '@/common/js/jssdk_image_tools.js'
  24. var x = 20;
  25. var y = 20;
  26. export default {
  27. data() {
  28. return {
  29. //绘图图像
  30. ctx: '',
  31. //路径点集合
  32. points: [],
  33. //签名图片
  34. SignatureImg: '',
  35. hasSign: false,
  36. realName: '',
  37. checked: false,
  38. };
  39. },
  40. props: ['showCanvas'],
  41. mounted() {
  42. this.createCanvas();
  43. this.realName = uni.getStorageSync('userInfo').realName
  44. },
  45. methods: {
  46. //清除签名的图片
  47. obliterate() {
  48. if (this.SignatureImg) {
  49. this.SignatureImg = '';
  50. }
  51. this.close();
  52. },
  53. //关闭并清空画布
  54. close() {
  55. this.$emit('closeCanvas');
  56. this.clear();
  57. },
  58. //创建并显示画布
  59. createCanvas() {
  60. this.ctx = uni.createCanvasContext('mycanvas', this); //创建绘图对象
  61. this.ctx.setFillStyle('#000000')
  62. this.ctx.fillStyle = '#000000'
  63. //设置画笔样式
  64. this.ctx.lineWidth = 6;
  65. this.ctx.lineCap = 'round';
  66. this.ctx.lineJoin = 'round';
  67. },
  68. //触摸开始,获取到起点
  69. touchstart(e) {
  70. let startX = e.changedTouches[0].x;
  71. let startY = e.changedTouches[0].y;
  72. let startPoint = {
  73. X: startX,
  74. Y: startY
  75. };
  76. this.points.push(startPoint);
  77. //每次触摸开始,开启新的路径
  78. this.ctx.beginPath();
  79. },
  80. //触摸移动,获取到路径点
  81. touchmove(e) {
  82. let moveX = e.changedTouches[0].x;
  83. let moveY = e.changedTouches[0].y;
  84. let movePoint = {
  85. X: moveX,
  86. Y: moveY
  87. };
  88. this.points.push(movePoint); //存点
  89. let len = this.points.length;
  90. if (len >= 2) {
  91. this.draw(); //绘制路径
  92. }
  93. },
  94. // 触摸结束,将未绘制的点清空防止对后续路径产生干扰
  95. touchend() {
  96. this.points = [];
  97. },
  98. //绘制笔迹
  99. draw() {
  100. let point1 = this.points[0];
  101. let point2 = this.points[1];
  102. this.points.shift();
  103. this.ctx.moveTo(point1.X, point1.Y);
  104. this.ctx.lineTo(point2.X, point2.Y);
  105. this.ctx.stroke();
  106. this.ctx.draw(true);
  107. this.hasSign = true
  108. },
  109. //清空画布
  110. clear() {
  111. this.hasSign = false
  112. let that = this;
  113. this.createCanvas();
  114. uni.getSystemInfo({
  115. success: function(res) {
  116. let canvasw = res.windowWidth;
  117. let canvash = res.windowHeight;
  118. that.ctx.clearRect(0, 0, canvasw, canvash);
  119. that.ctx.draw(true);
  120. }
  121. });
  122. },
  123. //完成绘画并保存到本地
  124. finish() {
  125. if(!this.checked) {
  126. return this.$u.toast('请勾选承诺')
  127. }
  128. if (!this.hasSign) {
  129. uni.showToast({
  130. title: '签名为空不能保存',
  131. icon: 'none',
  132. duration: 2000
  133. })
  134. return
  135. }
  136. let that = this;
  137. uni.canvasToTempFilePath({
  138. canvasId: 'mycanvas',
  139. destWidth:160,
  140. success: function(res) {
  141. console.log('图片上传结果')
  142. console.log(res)
  143. if(!res || !res.tempFilePath) {
  144. that.SignatureImg = res.tempFilePath;
  145. console.log(that.SignatureImg)
  146. that.$emit('closeCanvas', that.SignatureImg);
  147. }else{
  148. that.$emit('closeCanvas', res.tempFilePath);
  149. // //用来解决安卓真机获取到的是canvas图片的临时路径,转成base64格式
  150. // pathToBase64(res.tempFilePath).then(re => {
  151. // that.SignatureImg = re;
  152. // that.$emit('getCanvasImg', that.SignatureImg);
  153. // })
  154. }
  155. },
  156. });
  157. }
  158. }
  159. };
  160. </script>
  161. <style lang="scss" scoped>
  162. .signature-box {
  163. padding: 0 32rpx;
  164. display: flex;
  165. flex-direction: column;
  166. width: 100%;
  167. height: 98%;
  168. // height: calc(100vh - 100rpx);
  169. background: #fff;
  170. .topTps {
  171. width: 100%;
  172. border-radius: 8rpx;
  173. background-color: #f1f1f1;
  174. height: 110rpx;
  175. line-height: 110rpx;
  176. text-align: center;
  177. font-size: 34rpx;
  178. color: #333;
  179. }
  180. .footBox {
  181. .checkCon {
  182. width: 100%;
  183. height: 100rpx;
  184. display: flex;
  185. align-items: center;
  186. }
  187. .footBtn {
  188. display: flex;
  189. justify-content: space-between;
  190. .btn {
  191. width: 49%;
  192. font-size: 32rpx;
  193. line-height: 90rpx;
  194. height: 90rpx;
  195. color: #fff;
  196. border-radius: 14rpx;
  197. background: linear-gradient(180deg, #3593FB 0%, #53D3E5 100%);;
  198. text-align: center;
  199. &.border {
  200. border: 1rpx solid #218dff ;
  201. color: #218dff;
  202. background: #fff;
  203. }
  204. }
  205. }
  206. }
  207. //签名模块
  208. .signature {
  209. flex: 1;
  210. // height: 0;
  211. // width: 0;
  212. //canvas
  213. .mycanvas {
  214. width:100%;
  215. height:100%;
  216. background-color: #fff;
  217. border-radius: 10px 10px 0 0;
  218. }
  219. }
  220. }
  221. </style>