signature.vue 6.3 KB

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