signature.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view>
  3. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" ref="inputForm">
  4. <u-form-item label="旧签名" borderBottom prop="signPic">
  5. <u--image :showLoading="true" :src="BASE_URL + inputForm.signPic " width="100px"
  6. height="40px"></u--image>
  7. </u-form-item>
  8. <u-form-item label="上传签字图片" borderBottom prop="signPic">
  9. <u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" :maxCount="1"></u-upload>
  10. </u-form-item>
  11. <u--text size="10" type="warning" text="有签名图片,请上传,无,请点击下面签字生成"></u--text>
  12. <u-form-item label="签字" borderBottom prop="signPic">
  13. <signInput ref="sign" canvasId="twoDrowCanvas" canvasIds="twoRotateCanvas" :header="header"
  14. :action="action" @signToUrl="signToUrl">
  15. </signInput>
  16. </u-form-item>
  17. <view class="padding-xl">
  18. <u-button type="primary" @click="formSubmit" text="提交"></u-button>
  19. </view>
  20. </u--form>
  21. </view>
  22. </template>
  23. <script>
  24. import userService from "@/api/sys/userService"
  25. import * as $auth from "@/common/auth.js"
  26. import BASE_URL from '@/config.js'
  27. import signInput from "@/components/am-sign-input/am-sign-input.vue"
  28. export default {
  29. components: {
  30. signInput
  31. },
  32. data() {
  33. return {
  34. action: this.BASE_URL + '/gwfile/upload?uploadPath=sign', //上传服务器的地址
  35. header: {
  36. "token": $auth.getUserToken()
  37. }, //图片上传携带头部信息
  38. loading: false,
  39. inputForm: this.$auth.getUserInfo(),
  40. fileList: [],
  41. }
  42. },
  43. methods: {
  44. /**
  45. * @param {Object} e
  46. * 签名完成回调
  47. */
  48. signToUrl(e) {
  49. this.inputForm.signPic = e.data
  50. if (e.error_code && e.error_code === '201') {
  51. uni.showToast({
  52. title: e.msg,
  53. icon: 'none'
  54. })
  55. return
  56. }
  57. },
  58. // 删除图片
  59. deletePic(event) {
  60. this.fileList.splice(event.index, 1)
  61. },
  62. // 新增图片
  63. async afterRead(event) {
  64. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  65. let lists = [].concat(event.file)
  66. let fileListLen = this.fileList.length
  67. lists.map((item) => {
  68. this.fileList.push({
  69. ...item,
  70. status: 'uploading',
  71. message: '上传中'
  72. })
  73. })
  74. for (let i = 0; i < lists.length; i++) {
  75. const result = await this.uploadFilePromise(lists[i])
  76. let item = this.fileList[fileListLen]
  77. this.fileList.splice(fileListLen, 1, Object.assign(item, {
  78. status: 'success',
  79. message: '',
  80. url: result
  81. }))
  82. fileListLen++
  83. }
  84. },
  85. uploadFilePromise(url) {
  86. return new Promise((resolve, reject) => {
  87. let a = uni.uploadFile({
  88. url: this.BASE_URL + '/gwfile/upload?uploadPath=signature',
  89. filePath: url.url,
  90. name: 'file',
  91. header: {
  92. "token": $auth.getUserToken()
  93. },
  94. formData: url,
  95. success: (res) => {
  96. setTimeout(() => {
  97. resolve(res.data.data)
  98. }, 1000)
  99. }
  100. });
  101. })
  102. },
  103. formSubmit: function(e) {
  104. //定义表单规则
  105. // this.$refs.inputForm.validate().then(res => {
  106. uni.showLoading()
  107. let files = []
  108. if (this.fileList.length > 0) {
  109. this.fileLists.forEach(item => {
  110. files.push(item.url)
  111. })
  112. this.inputForm.signPic = files.join(",");
  113. }
  114. userService.saveInfo(this.inputForm).then((data) => {
  115. uni.showToast({
  116. title: data,
  117. icon: "success"
  118. });
  119. uni.clearStorage();
  120. uni.reLaunch({
  121. url: '/pages/login/login'
  122. })
  123. // }).catch((e) => {
  124. // console.log(e)
  125. // })
  126. })
  127. }
  128. }
  129. }
  130. </script>
  131. <style>
  132. .btn-logout {
  133. margin-top: 100upx;
  134. width: 80%;
  135. border-radius: 50upx;
  136. font-size: 16px;
  137. color: #fff;
  138. background: linear-gradient(to right, #365fff, #36bbff);
  139. }
  140. .btn-logout-hover {
  141. background: linear-gradient(to right, #365fdd, #36bbfa);
  142. }
  143. .cu-form-group .title {
  144. min-width: calc(4em + 40px);
  145. }
  146. </style>