signature.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <!-- 电子签名 -->
  2. <template>
  3. <view id="signature">
  4. <view class="signature_li">
  5. <view class="signature_li_t">示例:</view>
  6. <view class="signature_li_b">
  7. <img :src="imagesUrl('commonality/img_dzqm_sl.png')">
  8. </view>
  9. </view>
  10. <view class="tip">请上传白字黑子正楷签名</view>
  11. <view class="signature_li">
  12. <view class="signature_li_t">上传签名:</view>
  13. <view class="signature_li_b">
  14. <view class="signature_li_b_c" @click="selectImage"><span v-if="!signatureData">点击上传签名</span></view>
  15. <img class=".signature_li_img2" :src="signatureData">
  16. </view>
  17. <view class="clear_signature" @tap="signatureDele()">
  18. <img class="clear_signature_img" :src="imagesUrl('commonality/icon_sczl_sc.png')" />
  19. <text>清除</text>
  20. </view>
  21. <view class="upload_tip">请严格按照示例上传正楷签名并置于框内</view>
  22. </view>
  23. <view class="signature_li">
  24. <view class="signature_li_t" style="margin-top: 20rpx;">已上传的签名:</view>
  25. <image class="signature_li_img" :src="alreadyImg"></image>
  26. </view>
  27. <view class="save_btn" @click="saveFun()">保存</view>
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. config
  33. } from '@/api/request/config.js'
  34. import {
  35. updateSignature
  36. } from '@/pages_basics/api/index.js'
  37. export default {
  38. data() {
  39. return {
  40. baseUrl: config.base_url,
  41. signatureData: '',
  42. alreadyImg: '',
  43. }
  44. },
  45. onLoad(option) {
  46. //首次进入获取上个页面传过来的签名
  47. this.alreadyImg = this.baseUrl + option.item;
  48. console.log(this.alreadyImg)
  49. },
  50. onShow() {
  51. //用户点击上传签名
  52. if (uni.getStorageSync('signatureData')) {
  53. this.signatureData = uni.getStorageSync('signatureData');
  54. uni.removeStorageSync('signatureData');
  55. }
  56. },
  57. methods: {
  58. //清除签名
  59. async signatureDele() {
  60. let _this = this;
  61. this.signatureData = '';
  62. },
  63. //保存按钮
  64. async saveFun() {
  65. let _this = this;
  66. if (!this.signatureData) {
  67. uni.showToast({
  68. title: '请先选择签名上传并保存查看',
  69. icon: "none",
  70. mask: true,
  71. duration: 2000
  72. });
  73. return
  74. }
  75. var arr = this.signatureData.split(',')
  76. let obj = {
  77. signature: arr[1]
  78. }
  79. const {
  80. data
  81. } = await updateSignature(obj);
  82. if (data.code == 200) {
  83. uni.showToast({
  84. title: '上传成功',
  85. icon: "none",
  86. mask: true,
  87. duration: 2000
  88. });
  89. setTimeout(function() {
  90. uni.navigateBack()
  91. }, 2000);
  92. // uni.switchTab({
  93. // url: '/pages/mine'
  94. // });
  95. }
  96. },
  97. // 头像上传
  98. selectImage() {
  99. let self = this;
  100. wx.chooseImage({
  101. count: 1,
  102. sizeType: ["original", "compressed"],
  103. sourceType: ["album", "camera"],
  104. success: function(res) {
  105. console.log("res1", res)
  106. let tempFilePaths = res.tempFilePaths[0];
  107. self.uploadImg(tempFilePaths);
  108. }
  109. });
  110. },
  111. async uploadImg(tempFilePaths) {
  112. var self = this;
  113. uni.showLoading({
  114. title: '上传中',
  115. mask: true
  116. });
  117. uni.uploadFile({
  118. url: config.base_url + '/system/file/upload', //仅为示例,非真实的接口地址
  119. header: {
  120. 'Authorization': uni.getStorageSync('token')
  121. },
  122. filePath: tempFilePaths,
  123. name: 'file',
  124. formData: {
  125. 'user': 'test'
  126. },
  127. success: (uploadFileRes) => {
  128. let res = JSON.parse(uploadFileRes.data);
  129. if (res.code == 200) {
  130. uni.navigateTo({
  131. url: '/pages_basics/views/signature/signatureImg?src=' + config
  132. .base_url + res.data.url, //电子签名-图片处理
  133. });
  134. } else {
  135. uni.showToast({
  136. title: res.msg,
  137. icon: "none",
  138. mask: true,
  139. duration: 2000
  140. });
  141. }
  142. },
  143. fail: err => {},
  144. complete: () => {
  145. uni.hideLoading()
  146. }
  147. });
  148. },
  149. },
  150. }
  151. </script>
  152. <style lang="stylus" scoped>
  153. #signature {
  154. width: 710rpx;
  155. height: auto;
  156. background: #FFFFFF;
  157. border-radius: 20rpx;
  158. margin: 20rpx 20rpx 0;
  159. padding: 28rpx 20rpx 94rpx;
  160. box-sizing: border-box;
  161. .tip {
  162. width: 100%;
  163. font-size: 24rpx;
  164. font-family: PingFang SC;
  165. font-weight: 500;
  166. color: #999999;
  167. line-height: 24rpx;
  168. margin: 24rpx 0 42rpx 0;
  169. text-align: center;
  170. }
  171. .signature_li {
  172. .signature_li_t {
  173. font-size: 28rpx;
  174. font-family: PingFang SC;
  175. font-weight: 500;
  176. color: #333333;
  177. line-height: 28rpx;
  178. }
  179. .signature_li_b {
  180. position: relative;
  181. margin-top: 28rpx;
  182. width: 668rpx;
  183. height: 250rpx;
  184. background: #FFFFFF;
  185. border: 1px solid #E0E0E0;
  186. border-radius: 10rpx;
  187. text-align: center;
  188. >img {
  189. display: inline-block;
  190. width: 192rpx;
  191. height: 60rpx;
  192. margin-top: 90rpx;
  193. }
  194. .signature_li_b_c {
  195. font-size: 26rpx;
  196. font-family: PingFang SC;
  197. font-weight: 500;
  198. color: #0183FA;
  199. line-height: 250rpx;
  200. cursor: pointer;
  201. position: relative;
  202. z-index: 200;
  203. }
  204. .signature_li_img2 {
  205. position: absolute;
  206. left: 0;
  207. top: 0;
  208. z-index: 100;
  209. width: 668rpx;
  210. height: 250rpx;
  211. margin: 0;
  212. }
  213. }
  214. .signature_li_img {
  215. margin-top: 28rpx;
  216. width: 668rpx;
  217. height: 250rpx;
  218. background: #FFFFFF;
  219. border: 1px solid #E0E0E0;
  220. border-radius: 10rpx;
  221. text-align: center;
  222. }
  223. .upload_tip {
  224. width: 100%;
  225. font-size: 24rpx;
  226. font-family: PingFang SC;
  227. font-weight: 500;
  228. color: #999999;
  229. line-height: 24rpx;
  230. margin: 24rpx 0 42rpx 0;
  231. text-align: center;
  232. }
  233. .clear_signature {
  234. height: 30rpx;
  235. margin: 20rpx 0;
  236. display: flex;
  237. justify-content: flex-end;
  238. .clear_signature_img {
  239. width: 30rpx;
  240. height: 30rpx;
  241. margin-right: 10rpx;
  242. }
  243. >text {
  244. font-size: 26rpx;
  245. font-family: PingFang SC;
  246. font-weight: 500;
  247. color: #A2A2A2;
  248. line-height: 30rpx;
  249. }
  250. }
  251. }
  252. /* 保存按钮*/
  253. .save_btn {
  254. width: 650rpx;
  255. height: 100rpx;
  256. background: #0183FA;
  257. border-radius: 20px;
  258. font-size: 28rpx;
  259. font-family: PingFang SC;
  260. font-weight: 500;
  261. color: #FFFFFF;
  262. line-height: 100rpx;
  263. text-align: center;
  264. margin-top: 44rpx;
  265. }
  266. }
  267. </style>