洛阳学员端
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.

255 lines
6.0 KiB

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