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

261 lines
6.1 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 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. page {
  189. overflow: hidden;
  190. }
  191. .signature-box {
  192. padding: 0 32rpx;
  193. display: flex;
  194. flex-direction: column;
  195. width: 100%;
  196. // height: 98%;
  197. height: calc(100vh - 50rpx);
  198. background: #fff;
  199. overflow: hidden;
  200. position: fixed;
  201. .topTps {
  202. width: 100%;
  203. border-radius: 8rpx;
  204. background-color: #f1f1f1;
  205. height: 110rpx;
  206. line-height: 110rpx;
  207. text-align: center;
  208. font-size: 34rpx;
  209. color: #333;
  210. }
  211. .footBox {
  212. .checkCon {
  213. width: 100%;
  214. height: 100rpx;
  215. display: flex;
  216. align-items: center;
  217. }
  218. .footBtn {
  219. display: flex;
  220. justify-content: space-between;
  221. .btn {
  222. width: 49%;
  223. font-size: 32rpx;
  224. line-height: 90rpx;
  225. height: 90rpx;
  226. color: #fff;
  227. border-radius: 14rpx;
  228. background: linear-gradient(180deg, #3593FB 0%, #53D3E5 100%);;
  229. text-align: center;
  230. &.border {
  231. border: 1rpx solid #218dff ;
  232. color: #218dff;
  233. background: #fff;
  234. }
  235. }
  236. }
  237. }
  238. //签名模块
  239. .signature {
  240. flex: 1;
  241. // height: 0;
  242. // width: 0;
  243. //canvas
  244. .mycanvas {
  245. width:100%;
  246. height:100%;
  247. background-color: #fff;
  248. border-radius: 10px 10px 0 0;
  249. }
  250. }
  251. }
  252. </style>