特易招,招聘小程序
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.

187 lines
3.6 KiB

4 months ago
  1. <template>
  2. <div class="contain">
  3. <navbar
  4. title="电子签名"
  5. v-if="!crosswise"
  6. leftClick
  7. @leftClick="$utils.navigateBack"/>
  8. <view
  9. class="electronic-contract"
  10. :class="{crosswise}">
  11. <canvas
  12. canvas-id="mycanvas"
  13. class="mycanvas"
  14. :style="{height, width}"
  15. disable-scroll="true"
  16. @touchstart="ontouchstart"
  17. @touchmove="touchmove"></canvas>
  18. <view class="title"
  19. v-if="crosswise">
  20. 请旋转屏幕按文字方向开始签名
  21. </view>
  22. </view>
  23. <view class="btn-list">
  24. <view class="uni-color-btn" @click="clear">
  25. 清除
  26. </view>
  27. <view class="uni-color-btn" @click="close">
  28. 完成
  29. </view>
  30. </view>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. oc: null,
  38. points: [], //路径点集合
  39. show: true,
  40. height : '350rpx',
  41. width : '700rpx',
  42. crosswise : false,
  43. options : {},
  44. }
  45. },
  46. onReady() {
  47. this.open()
  48. },
  49. onLoad(options) {
  50. this.options = options
  51. },
  52. onShow() {
  53. this.initPM()
  54. },
  55. methods: {
  56. initPM(){
  57. if(!this.crosswise) return
  58. let info = uni.getSystemInfoSync();
  59. console.log(info.windowWidth);
  60. console.log(info.windowHeight);
  61. },
  62. open() {
  63. this.initCanvas();
  64. },
  65. close() {
  66. uni.canvasToTempFilePath({
  67. canvasId: "mycanvas",
  68. success: (res) => {
  69. console.log(res.tempFilePath);
  70. const canvas = res.tempFilePath;
  71. uni.setStorageSync('electronicSignature', canvas)
  72. let o = this.options
  73. uni.navigateBack(-1)
  74. },
  75. fail(error) {
  76. console.error("转化图片错误!", error)
  77. }
  78. });
  79. },
  80. initCanvas() {
  81. this.oc = uni.createCanvasContext("mycanvas");
  82. },
  83. ontouchstart(e) {
  84. this.points = []
  85. const startX = e.changedTouches[0].x;
  86. const startY = e.changedTouches[0].y;
  87. let startPoint = {
  88. X: startX,
  89. Y: startY,
  90. };
  91. this.points.push(startPoint);
  92. },
  93. touchmove(e) {
  94. let moveX = e.changedTouches[0].x;
  95. let moveY = e.changedTouches[0].y;
  96. let movePoint = {
  97. X: moveX,
  98. Y: moveY,
  99. };
  100. this.points.push(movePoint);
  101. let len = this.points.length;
  102. if (len >= 2) {
  103. this.draw(); //绘制路径
  104. }
  105. },
  106. draw() {
  107. if (this.points.length < 2) return;
  108. this.oc.beginPath();
  109. this.oc.moveTo(this.points[0].X, this.points[0].Y);
  110. // for (let i = 1; i < this.points.length; i++) {
  111. // let point = this.points[i];
  112. // this.oc.lineTo(point.X, point.Y);
  113. // }
  114. this.oc.lineTo(this.points[1].X, this.points[1].Y);
  115. this.points.shift()
  116. this.oc.setStrokeStyle('#000000');
  117. this.oc.setLineWidth(5);
  118. this.oc.setLineCap('round');
  119. this.oc.setLineJoin('round');
  120. this.oc.stroke();
  121. this.oc.draw(true);
  122. },
  123. //清空画布
  124. clear() {
  125. let that = this;
  126. uni.getSystemInfo({
  127. success: (res) => {
  128. let canvasw = res.windowWidth;
  129. let canvash = res.windowHeight;
  130. that.oc.clearRect(0, 0, canvasw, canvash);
  131. that.oc.draw(true);
  132. },
  133. });
  134. },
  135. }
  136. };
  137. </script>
  138. <style lang="scss" scoped>
  139. .contain {
  140. position: relative;
  141. .mycanvas {
  142. background-color: #fff;
  143. border-radius: 20rpx;
  144. }
  145. .electronic-contract{
  146. display: flex;
  147. justify-content: center;
  148. align-items: center;
  149. margin: 25rpx;
  150. }
  151. .crosswise{
  152. .title{
  153. writing-mode: vertical-lr; /* 垂直从上到下 */
  154. transform: skewY(180deg); /* 颠倒文本 */
  155. display: inline-block; /* 需要设置为内联块 */
  156. }
  157. }
  158. .btn-list {
  159. display: flex;
  160. padding: 20rpx;
  161. justify-content: space-around;
  162. .uni-color-btn {
  163. border-radius: 10rpx;
  164. margin: 0;
  165. padding: 20rpx 40rpx;
  166. }
  167. }
  168. }
  169. </style>