signature.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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="@/pages_basics/images/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="@/pages_basics/images/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. this.alreadyImg = '';
  63. },
  64. //保存按钮
  65. async saveFun() {
  66. let _this = this;
  67. if (!this.signatureData) {
  68. uni.showToast({
  69. title: '请先选择签名上传并保存查看',
  70. icon: "none",
  71. mask: true,
  72. duration: 2000
  73. });
  74. return
  75. }
  76. var arr = this.signatureData.split(',')
  77. let obj = {
  78. signature: arr[1]
  79. }
  80. const {
  81. data
  82. } = await updateSignature(obj);
  83. if (data.code == 200) {
  84. uni.showToast({
  85. title: '上传成功',
  86. icon: "none",
  87. mask: true,
  88. duration: 2000
  89. });
  90. setTimeout(function() {
  91. uni.navigateBack()
  92. }, 2000);
  93. // uni.switchTab({
  94. // url: '/pages/mine'
  95. // });
  96. }
  97. },
  98. // 头像上传
  99. selectImage() {
  100. let self = this;
  101. wx.chooseImage({
  102. count: 1,
  103. sizeType: ["original", "compressed"],
  104. sourceType: ["album", "camera"],
  105. success: function(res) {
  106. console.log("res1", res)
  107. let tempFilePaths = res.tempFilePaths[0];
  108. self.uploadImg(tempFilePaths);
  109. }
  110. });
  111. },
  112. async uploadImg(tempFilePaths) {
  113. var self = this;
  114. uni.showLoading({
  115. title: '上传中',
  116. mask: true
  117. });
  118. uni.uploadFile({
  119. url: config.base_url + '/system/file/upload', //仅为示例,非真实的接口地址
  120. header: {
  121. 'Authorization': uni.getStorageSync('token')
  122. },
  123. filePath: tempFilePaths,
  124. name: 'file',
  125. formData: {
  126. 'user': 'test'
  127. },
  128. success: (uploadFileRes) => {
  129. let res = JSON.parse(uploadFileRes.data);
  130. if (res.code == 200) {
  131. uni.navigateTo({
  132. url: '/pages_basics/views/signature/signatureImg?src=' + config
  133. .base_url + res.data.url, //电子签名-图片处理
  134. });
  135. } else {
  136. uni.showToast({
  137. title: res.msg,
  138. icon: "none",
  139. mask: true,
  140. duration: 2000
  141. });
  142. }
  143. },
  144. fail: err => {},
  145. complete: () => {
  146. uni.hideLoading()
  147. }
  148. });
  149. },
  150. },
  151. }
  152. </script>
  153. <style lang="stylus" scoped>
  154. #signature {
  155. width: 710rpx;
  156. height: auto;
  157. background: #FFFFFF;
  158. border-radius: 20rpx;
  159. margin: 20rpx 20rpx 0;
  160. padding: 28rpx 20rpx 94rpx;
  161. box-sizing: border-box;
  162. .tip {
  163. width: 100%;
  164. font-size: 24rpx;
  165. font-family: PingFang SC;
  166. font-weight: 500;
  167. color: #999999;
  168. line-height: 24rpx;
  169. margin: 24rpx 0 42rpx 0;
  170. text-align: center;
  171. }
  172. .signature_li {
  173. .signature_li_t {
  174. font-size: 28rpx;
  175. font-family: PingFang SC;
  176. font-weight: 500;
  177. color: #333333;
  178. line-height: 28rpx;
  179. }
  180. .signature_li_b {
  181. position: relative;
  182. margin-top: 28rpx;
  183. width: 668rpx;
  184. height: 250rpx;
  185. background: #FFFFFF;
  186. border: 1px solid #E0E0E0;
  187. border-radius: 10rpx;
  188. text-align: center;
  189. >img {
  190. display: inline-block;
  191. width: 192rpx;
  192. height: 60rpx;
  193. margin-top: 90rpx;
  194. }
  195. .signature_li_b_c {
  196. font-size: 26rpx;
  197. font-family: PingFang SC;
  198. font-weight: 500;
  199. color: #0183FA;
  200. line-height: 250rpx;
  201. cursor: pointer;
  202. position: relative;
  203. z-index: 200;
  204. }
  205. .signature_li_img2 {
  206. position: absolute;
  207. left: 0;
  208. top: 0;
  209. z-index: 100;
  210. width: 668rpx;
  211. height: 250rpx;
  212. margin: 0;
  213. }
  214. }
  215. .signature_li_img {
  216. margin-top: 28rpx;
  217. width: 668rpx;
  218. height: 250rpx;
  219. background: #FFFFFF;
  220. border: 1px solid #E0E0E0;
  221. border-radius: 10rpx;
  222. text-align: center;
  223. }
  224. .upload_tip {
  225. width: 100%;
  226. font-size: 24rpx;
  227. font-family: PingFang SC;
  228. font-weight: 500;
  229. color: #999999;
  230. line-height: 24rpx;
  231. margin: 24rpx 0 42rpx 0;
  232. text-align: center;
  233. }
  234. .clear_signature {
  235. height: 30rpx;
  236. margin: 20rpx 0;
  237. display: flex;
  238. justify-content: flex-end;
  239. .clear_signature_img {
  240. width: 30rpx;
  241. height: 30rpx;
  242. margin-right: 10rpx;
  243. }
  244. >text {
  245. font-size: 26rpx;
  246. font-family: PingFang SC;
  247. font-weight: 500;
  248. color: #A2A2A2;
  249. line-height: 30rpx;
  250. }
  251. }
  252. }
  253. /* 保存按钮*/
  254. .save_btn {
  255. width: 650rpx;
  256. height: 100rpx;
  257. background: #0183FA;
  258. border-radius: 20px;
  259. font-size: 28rpx;
  260. font-family: PingFang SC;
  261. font-weight: 500;
  262. color: #FFFFFF;
  263. line-height: 100rpx;
  264. text-align: center;
  265. margin-top: 44rpx;
  266. }
  267. }
  268. </style>