signature.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view class="wrapper">
  3. <view class="handRight"></view>
  4. <view class="handBtn">
  5. <view class="slide-wrapper">
  6. <text>选择粗细</text>
  7. <slider @change="updateValue" value="25" show-value class="slider" step="25" />
  8. </view>
  9. </view>
  10. <view class="handCenter">
  11. <canvas class="handWriting" disable-scroll="true" @touchstart="uploadScaleStart"
  12. @touchmove="uploadScaleMove" @touchend="uploadScaleEnd" @tap="mouseDown" canvas-id="handWriting">
  13. </canvas>
  14. </view>
  15. <view class="showimg">
  16. <image v-if="showimg" :src="showimg" mode=""></image>
  17. <text v-else>图片展示</text>
  18. </view>
  19. <view class="buttons">
  20. <button @click="retDraw" class="delBtn">重写</button>
  21. <button @click="subCanvas" class="subBtn">保存</button>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import Handwriting from "./js/signature.js"
  27. export default {
  28. data() {
  29. return {
  30. lineColor: 'black',
  31. slideValue: 25,
  32. handwriting: '',
  33. selectColor: 'black',
  34. color: '',
  35. showimg: '',
  36. share_popup: false,
  37. }
  38. },
  39. onLoad() {
  40. this.handwriting = new Handwriting({
  41. lineColor: this.lineColor,
  42. slideValue: this.slideValue, // 0, 25, 50, 75, 100
  43. canvasName: 'handWriting',
  44. })
  45. },
  46. methods: {
  47. // 选择画笔颜色
  48. selectColorEvent(event) {
  49. this.selectColor = event;
  50. if (event == 'black') {
  51. this.color = '#1A1A1A'
  52. } else if (event == 'red') {
  53. this.color = '#ca262a'
  54. }
  55. this.handwriting.selectColorEvent(this.color)
  56. },
  57. retDraw() {
  58. this.handwriting.retDraw()
  59. },
  60. // 笔迹粗细滑块
  61. updateValue(e) {
  62. console.log(e.detail);
  63. this.slideValue = e.detail.value;
  64. this.handwriting.selectSlideValue(this.slideValue);
  65. },
  66. uploadScaleStart(event) {
  67. this.handwriting.uploadScaleStart(event)
  68. },
  69. uploadScaleMove(event) {
  70. this.handwriting.uploadScaleMove(event)
  71. },
  72. uploadScaleEnd(event) {
  73. this.handwriting.uploadScaleEnd(event)
  74. },
  75. subCanvas() {
  76. this.handwriting.saveCanvas().then(res => {
  77. this.showimg = res;
  78. console.log(res);
  79. this.$api.worksheet_baseimg({
  80. staff_num: uni.getStorageSync('user').staff_num,
  81. base_img:res
  82. }).then((res)=>{
  83. uni.showToast({
  84. icon:"none",
  85. title:"保存成功"
  86. })
  87. setTimeout(() => {
  88. uni.navigateBack()
  89. }, 1500)
  90. console.log(res)
  91. })
  92. }).catch(err => {
  93. console.log(err);
  94. });
  95. },
  96. }
  97. }
  98. </script>
  99. <style scoped="true">
  100. view{
  101. display: flex;
  102. }
  103. .wrapper {
  104. width: 100%;
  105. height: 100%;
  106. margin: 30upx 0;
  107. overflow: hidden;
  108. display: flex;
  109. align-content: center;
  110. flex-direction: column;
  111. justify-content: center;
  112. font-size: 28upx;
  113. }
  114. .handWriting {
  115. background: #fff;
  116. width: 100%;
  117. height: 350upx;
  118. }
  119. .handRight {
  120. align-items: center;
  121. }
  122. .handCenter {
  123. border: 4upx dashed #e9e9e9;
  124. flex: 5;
  125. overflow: hidden;
  126. box-sizing: border-box;
  127. width: 90%;
  128. margin: 0 auto;
  129. }
  130. .handTitle {
  131. flex: 1;
  132. color: #666;
  133. justify-content: center;
  134. font-size: 30upx;
  135. }
  136. .handBtn {
  137. flex-direction: column;
  138. padding: 40upx 0;
  139. width: 90%;
  140. margin: 0 auto;
  141. }
  142. .buttons {
  143. width: 100%;
  144. margin-top: 100upx;
  145. justify-content: space-between;
  146. }
  147. .buttons>button {
  148. font-size: 30upx;
  149. height: 80upx;
  150. width: 120upx;
  151. }
  152. .delBtn {
  153. color: #666;
  154. }
  155. .color {
  156. align-items: center;
  157. }
  158. .color>text {
  159. margin-right: 20upx;
  160. }
  161. .subBtn {
  162. background: #008ef6;
  163. color: #fff;
  164. text-align: center;
  165. justify-content: center;
  166. }
  167. .black-select {
  168. width: 60upx;
  169. height: 60upx;
  170. }
  171. .black-select.color_select {
  172. width: 90upx;
  173. height: 90upx;
  174. }
  175. .red-select {
  176. width: 60upx;
  177. height: 60upx;
  178. }
  179. .red-select.color_select {
  180. width: 90upx;
  181. height: 90upx;
  182. }
  183. .slide-wrapper {
  184. align-items: center;
  185. margin-bottom: 20upx;
  186. }
  187. .slider {
  188. width: 400upx;
  189. padding-left: 20upx;
  190. }
  191. .drop {
  192. width: 50upx;
  193. height: 50upx;
  194. border-radius: 50%;
  195. background: #FFF;
  196. position: absolute;
  197. left: 0upx;
  198. top: -10upx;
  199. box-shadow: 0px 1px 5px #888888;
  200. }
  201. .slide {
  202. width: 250upx;
  203. height: 30upx;
  204. }
  205. .showimg {
  206. border: 4upx solid #e9e9e9;
  207. overflow: hidden;
  208. width: 90%;
  209. margin: 0 auto;
  210. background: #eee;
  211. height: 350upx;
  212. margin-top: 40upx;
  213. align-items: center;
  214. justify-content: center;
  215. }
  216. .showimg>image {
  217. width: 100%;
  218. height: 100%;
  219. }
  220. .showimg>text {
  221. font-size: 40upx;
  222. color: #888;
  223. }
  224. </style>