• 微信小程序签名


    1. <view style="padding: 15rpx;font-size: 26rpx;">
    2. <view style="width: 720rpx;margin-left: 15rpx;">
    3. <view><rich-text nodes="{{content}}">rich-text>view>
    4. <view style="margin-top: 50rpx;">
    5. <view style="display: flex;">
    6. <view>签名view>
    7. <view style="position: absolute;margin-left: 60rpx;margin-top: -30rpx;"><image style="width: 170rpx;height: 60rpx;" src="{{img}}">image>view>
    8. view>
    9. <view style="width: 200rpx;border-bottom: 1rpx solid #000000;margin-left: 56rpx;">view>
    10. <view wx:if="{{img == ''}}" style="text-align: center;margin-top: 50rpx;width: 730rpx;">
    11. <view class="dade_sign" bindtap="sign">签名view>
    12. view>
    13. <view wx:else style="text-align: center;margin-top: 50rpx;width: 730rpx;">
    14. <view class="dade_sign_xh" bindtap="xhsign">确定签署协议view>
    15. view>
    16. view>
    17. <view style="{{sign==1 ? ' display: none;' : ''}}">
    18. <view class="dade_sign_top" catchtouchmove='true'>
    19. <view style="display: flex;line-height: 70rpx;">
    20. <view style="width: 750rpx;text-align: center;">开始签名view>
    21. <view style="position: absolute;right: 50rpx;" bindtap="colse">关闭view>
    22. view>
    23. <view>
    24. <canvas style="width: 750rpx;background-color: rgb(242, 247, 247);position: fixed;" canvas-id="firstCanvas" id='firstCanvas' bindtouchstart="bindtouchstart" bindtouchmove="bindtouchmove">canvas>
    25. view>
    26. <view style="display: flex;position: absolute;bottom: 40rpx;">
    27. <button style="font-size: 26rpx;height: 70rpx;border-radius: 100rpx;padding: 0 105rpx;margin-top: 40rpx;background-color: rgb(247, 145, 86);margin-left: 66rpx;" type="warn" bindtap='clear'>重签button>
    28. <button style="font-size: 26rpx;height: 70rpx;border-radius: 100rpx;padding: 0 75rpx;margin-top: 40rpx;background-color: rgb(74, 135, 248);margin-left: 66rpx;" type="primary" bindtap='export'>完成签名button>
    29. view>
    30. view>
    31. view>
    32. view>
    33. view>
    1. // pages/topay/sign/sign.js
    2. var app = getApp();
    3. var api = require('../../../api.js');
    4. var util = require("../../../utils/util.js");
    5. Page({
    6. /**
    7. * 页面的初始数据
    8. */
    9. data: {
    10. context: null,
    11. index: 0,
    12. height: 0,
    13. width: 0,
    14. img:'',
    15. sign:1,
    16. url:'',
    17. path:'',
    18. content:'',
    19. },
    20. /**记录开始点 */
    21. bindtouchstart: function(e) {
    22. this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y)
    23. },
    24. /**记录移动点,刷新绘制 */
    25. bindtouchmove: function(e) {
    26. this.data.context.lineTo(e.changedTouches[0].x, e.changedTouches[0].y);
    27. this.data.context.stroke();
    28. this.data.context.draw(true);
    29. this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y);
    30. },
    31. /**清空画布 */
    32. clear: function() {
    33. this.data.context.clearRect(0, 0, this.data.width, this.data.height);
    34. this.data.context.draw();
    35. this.data.context.setStrokeStyle('#000000')
    36. this.data.context.setLineWidth(4)
    37. this.data.context.setFillStyle('white')
    38. this.data.context.setFontSize(20)
    39. let str = "";
    40. this.data.context.fillText(str, Math.ceil((this.data.width - this.data.context.measureText(str).width) / 2), Math.ceil(this.data.height / 2) - 20)
    41. this.data.context.draw()
    42. },
    43. /**导出图片 */
    44. export: function() {
    45. const that=this;
    46. wx.canvasToTempFilePath({
    47. canvasId: 'firstCanvas',
    48. success: function(res) {
    49. //打印图片路径
    50. //console.log(res.tempFilePath)
    51. //设置保存的图片
    52. // that.setData({
    53. // img: res.tempFilePath
    54. // })
    55. let imgurl = res.tempFilePath;
    56. wx.getFileSystemManager().readFile({
    57. filePath: res.tempFilePath, //选择图片返回的相对路径
    58. encoding: 'base64', //编码格式
    59. success: res => {
    60. let imgs = res.data;
    61. let data = {'img':imgs};
    62. util.post({
    63. api_url: api.payOrderSign,
    64. params: data,
    65. success: function (res) {
    66. console.log(res.data.data.data)
    67. that.data.sign = 1;
    68. that.data.context.setLineWidth(4)
    69. that.data.context.setFillStyle('white')
    70. that.data.url=res.data.data.data;
    71. that.data.path=res.data.data.path;
    72. that.setData({
    73. img:res.data.data.data,
    74. sign:1
    75. })
    76. }, fail: function (res) {
    77. that.setData({"loading.hidden": true});
    78. util.showMsg("网络不给力");
    79. }
    80. });
    81. }
    82. })
    83. }
    84. })
    85. },
    86. onLoad: function(options) {
    87. console.log(options.id);
    88. if (options.id) {
    89. wx.showToast({
    90. title: '姓名' + options.id,
    91. icon: 'success',
    92. duration: 2000
    93. })
    94. }
    95. },
    96. onShow: function() {
    97. let query = wx.createSelectorQuery();
    98. const that = this;
    99. query.select('#firstCanvas').boundingClientRect();
    100. query.exec(function(rect) {
    101. let width = rect[0].width;
    102. let height = rect[0].height;
    103. that.setData({
    104. width,
    105. height
    106. });
    107. const context = wx.createCanvasContext('firstCanvas')
    108. context.setStrokeStyle('#000000')
    109. context.setLineWidth(4)
    110. context.setFontSize(20)
    111. context.setFillStyle('white')
    112. let str = "";
    113. context.fillText(str, Math.ceil((width - context.measureText(str).width) / 2), Math.ceil(height / 2) - 20)
    114. context.draw()
    115. that.setData({
    116. context: context
    117. })
    118. });
    119. },
    120. /**
    121. * 生命周期函数--监听页面加载
    122. */
    123. onLoad: function (options) {
    124. let _this = this;
    125. var data = {'shool_id':3};
    126. util.post({
    127. api_url: api.payGetSign,
    128. params: data,
    129. success: function (res) {
    130. _this.data.content = res.data.data.data[0].content;
    131. _this.setData({
    132. content:res.data.data.data[0].content
    133. })
    134. }, fail: function (res) {
    135. that.setData({"loading.hidden": true});
    136. util.showMsg("网络不给力");
    137. }
    138. });
    139. },
    140. /**
    141. * 生命周期函数--监听页面初次渲染完成
    142. */
    143. onReady: function () {
    144. },
    145. /**
    146. * 生命周期函数--监听页面隐藏
    147. */
    148. onHide: function () {
    149. },
    150. /**
    151. * 生命周期函数--监听页面卸载
    152. */
    153. onUnload: function () {
    154. },
    155. /**
    156. * 页面相关事件处理函数--监听用户下拉动作
    157. */
    158. onPullDownRefresh: function () {
    159. },
    160. // 签名
    161. sign:function(){
    162. this.data.sign = 2;
    163. this.setData({
    164. sign:2
    165. })
    166. },
    167. //关闭签名
    168. colse:function(){
    169. this.data.sign = 1;
    170. this.setData({
    171. sign:1
    172. })
    173. },
    174. //确定签署协议
    175. xhsign:function(){
    176. var pages = getCurrentPages();
    177. var prevPage = pages[pages.length - 2]; // 上一个页面
    178. let urls = this.data.url;
    179. let paths = this.data.path;
    180. let contents = this.data.content;
    181. console.log(urls)
    182. //改变上一页参数
    183. prevPage.setData({
    184. url:urls,
    185. path:paths,
    186. content:contents,
    187. })
    188. //返回上一页
    189. wx.navigateBack({
    190. delta: 1
    191. })
    192. },
    193. })
    1. /* pages/topay/sign/sign.wxss */
    2. page {
    3. background-color: #ffffff;
    4. }
    5. .dade_sign{
    6. width: 100rpx;
    7. background-color: rgb(40, 122, 245);
    8. padding: 10rpx 15rpx 10rpx 15rpx;
    9. border-radius: 100rpx;
    10. font-size: 25rpx;
    11. color: #ffffff;
    12. margin-left: 300rpx;
    13. margin-bottom: 10rpx;
    14. }
    15. .dade_sign_xh{
    16. width: 200rpx;
    17. background-color: rgb(231, 65, 74);
    18. padding: 10rpx 15rpx 10rpx 15rpx;
    19. border-radius: 100rpx;
    20. font-size: 25rpx;
    21. color: #ffffff;
    22. margin-left: 270rpx;
    23. margin-bottom: 10rpx;
    24. }
    25. .dade_sign_top{
    26. position: fixed;
    27. bottom: 0;
    28. width: 100%;
    29. height: 530rpx;
    30. background-color: #ffffff;
    31. border-top-left-radius: 10rpx;
    32. border-top-right-radius: 10rpx;
    33. z-index: 1000;
    34. }

  • 相关阅读:
    Vue07/Vue 具名插槽 及 作用域插槽( 带数据插槽 ) 作用介绍和说明
    字符(字符数组)越界
    【每日一题Day336】LC146最近最少使用缓存 | 哈希表+链表
    Git代码仓库管理系统的配置方法之:Gitlab
    ES:模板字符串的使用
    前端三剑客 - JavaScript
    Zookeeper-命令操作
    Kitex踩坑 [Error] KITEX: processing request error,i/o timeout
    系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
    【正点原子STM32连载】 第二十五章 TFTLCD(MCU屏)实验 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1
  • 原文地址:https://blog.csdn.net/qq_34631220/article/details/126299389