Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 2 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="sign">
  3. <view class="paper">
  4. <canvas class="handWriting" disable-scroll="true" @touchstart="touchstart1" @touchmove="touchmove1"
  5. canvas-id="handWriting1">
  6. </canvas>
  7. </view>
  8. <view class="btns">
  9. <view class="btn1" @click="reSign1">清除</view>
  10. <view class="btn2" @click="sign1ok">生成并返回</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script setup lang="ts">
  15. import {
  16. reactive
  17. } from "vue";
  18. import {
  19. onLoad
  20. } from "@dcloudio/uni-app";
  21. const state = reactive({
  22. context1: null,
  23. hasDraw: false, //默认没有画
  24. src: null
  25. })
  26. onLoad((option) => {
  27. setTimeout(() => {
  28. let context1 = uni.createCanvasContext('handWriting1');
  29. context1.setStrokeStyle("#000000")
  30. context1.setLineWidth(3);
  31. state.context1 = context1;
  32. })
  33. })
  34. function touchstart1(e) {
  35. let context1 = state.context1;
  36. context1.moveTo(e.touches[0].x, e.touches[0].y);
  37. state.context1 = context1;
  38. state.hasDraw = true;
  39. }
  40. function touchmove1(e) {
  41. var x = e.touches[0].x;
  42. var y = e.touches[0].y;
  43. var context1 = state.context1;
  44. context1.setLineWidth(3);
  45. context1.lineTo(x, y);
  46. context1.stroke();
  47. context1.setLineCap('round');
  48. context1.draw(true);
  49. context1.moveTo(x, y);
  50. }
  51. function reSign1() {
  52. let context1 = state.context1;
  53. context1.draw(); //清空画布
  54. state.hasDraw = false;
  55. state.src = null;
  56. }
  57. function sign1ok() {
  58. if (!state.hasDraw) {
  59. console.log("签字是空白的 没有签字")
  60. uni.showToast({
  61. title: "请先签名",
  62. duration: 2000
  63. });
  64. } else {
  65. var context1 = state.context1;
  66. //保存签名图片到本地
  67. context1.draw(true, uni.canvasToTempFilePath({
  68. canvasId: 'handWriting1',
  69. success(res) {
  70. console.log(res);
  71. state.src = res.tempFilePath
  72. }
  73. }))
  74. }
  75. }
  76. function signAgreement(file) {
  77. console.log(file);
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .sign {
  82. //padding: 30rpx;
  83. }
  84. .paper {
  85. // border: 1px solid #dedede;
  86. margin: 30rpx 0;
  87. height: 650rpx
  88. }
  89. .btns {
  90. width: 100%;
  91. display: flex;
  92. flex-direction: row;
  93. justify-content: center;
  94. }
  95. .btns .btn1,
  96. .btns .btn2 {
  97. width: 200rpx;
  98. height: 70rpx;
  99. background: #00B38B;
  100. color: #ffffff;
  101. text-align: center;
  102. line-height: 70rpx;
  103. border-radius: 8rpx;
  104. }
  105. .btn1 {
  106. margin-right: 70rpx;
  107. }
  108. .signTitle {
  109. text-align: center;
  110. font-size: 1.2em;
  111. margin: 10px auto;
  112. }
  113. .handWriting {
  114. width: 100%;
  115. height: 100%;
  116. }
  117. </style>