signature.vue 6.1 KB

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