jp-signature-popup.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <div class="signature">
  3. <div class="inputs" v-if="!popup">
  4. <div class="label" :class="required?'labelqr':''">{{label}}</div>
  5. <div>
  6. <div v-if="value" class="images">
  7. <image @tap="toImg" class="images" mode="aspectFit" :src="value"></image>
  8. <view v-if="!readonly" @click="toDeleteImg" class="icons">
  9. <view class="Deletes">×</view>
  10. </view>
  11. </div>
  12. <div v-if="!value && !readonly" class="explain" @click="toPop">
  13. {{placeholder?placeholder:'点击签名'}}
  14. </div>
  15. </div>
  16. </div>
  17. <view class="bottomPopup" v-if="showPopup" @touchmove.stop.prevent="moveHandle">
  18. <transition name="slide-up" appear>
  19. <view class="popup-content">
  20. <view class="popup">
  21. <div class="hader" v-if="!isHeight">
  22. <div @click="toclear">取消</div>
  23. <div class="text">{{label}}</div>
  24. <div @click="isEmpty">确定</div>
  25. </div>
  26. <div :class="isHeight?'wgSignatureq':'wgSignature'">
  27. <div v-if="isHeight" key="999" style="width: 750rpx ;height: 100vh;">
  28. <jp-signature :beforeDelay="200" :landscape="true" disableScroll ref="signatureRef" :openSmooth="openSmooth" :penSize="6" :bounding-box="boundingBox"></jp-signature>
  29. </div>
  30. <div v-else key="888" style="width: 750rpx ;height: 35vh;">
  31. <jp-signature :beforeDelay="200" disableScroll ref="signatureRef" :openSmooth="openSmooth" :bounding-box="boundingBox" :penSize="3"></jp-signature>
  32. </div>
  33. <div v-if="!isHeight" class="appBut" >
  34. <div class="buts" @click="undo" >撤销</div>
  35. <div class="buts" @click="deleteImg" >清除</div>
  36. <div class="buts" style="background-color: #55aaff;color: #fff;" @click="Tomagnify" >全屏</div>
  37. </div>
  38. <div v-else class="appBut" style="height: 80px;">
  39. <div class="butx" @click="undo" >撤销</div>
  40. <div class="butx" @click="deleteImg">清除</div>
  41. <div class="butx" style="background-color: #55aaff;color: #fff;" @click="Tomagnify" >小屏</div>
  42. <div class="butx" @click="toclear">取消</div>
  43. <div class="butx" style="background-color: #E59C36;color: #fff;" @click="isEmpty">完成</div>
  44. </div>
  45. </div>
  46. </view>
  47. </view>
  48. </transition>
  49. </view>
  50. </div>
  51. </template>
  52. <!-- 有项目需要开发的请联系 扣 - 371524845 -->
  53. <script>
  54. /**
  55. * 手写签名组件
  56. * 用于手写签名(弹框签名支持小屏和全屏)
  57. *
  58. *********参数********
  59. * label 选项名称
  60. * value 初始值String(支持bas64,url 等图片显示)
  61. * required 是否显示必填
  62. * placeholder 默认值
  63. * readonly 是否只读
  64. *
  65. * *********回调********
  66. * @input(e) 点击确认 e生成的图片数据(bas64)
  67. *
  68. *********方法********
  69. * isEmpty() 生成图片
  70. * deleteImg() 删除图片
  71. */
  72. export default {
  73. props: {
  74. popup: {
  75. type: [Boolean, String],
  76. default: false,
  77. },
  78. label: {
  79. type: String,
  80. default: '手写签名',
  81. },
  82. value: {
  83. type: String,
  84. default: '',
  85. },
  86. required: {
  87. type: [Boolean, String],
  88. default: false,
  89. },
  90. placeholder: {
  91. type: String,
  92. default: '点击签名',
  93. },
  94. readonly: {
  95. type: [Boolean, String],
  96. default: false,
  97. },
  98. openSmooth: {
  99. type: [Boolean, String],
  100. default: true,
  101. },
  102. boundingBox: {
  103. type: [Boolean, String],
  104. default: true,
  105. },
  106. },
  107. data() {
  108. return {
  109. showPopup: false,
  110. isHeight: false,
  111. height1: uni.getSystemInfoSync().windowWidth / 2,
  112. width: uni.getSystemInfoSync().windowWidth, //实时屏幕宽度
  113. height: uni.getSystemInfoSync().windowHeight, //实时屏幕高度
  114. showPicker: false
  115. }
  116. },
  117. methods: {
  118. moveHandle(){
  119. },
  120. toImg(){
  121. this.$emit('toImg',this.value)
  122. },
  123. undo() {
  124. this.$refs.signatureRef.undo()
  125. },
  126. toPop() {
  127. this.showPopup = true
  128. },
  129. toDeleteImg() {
  130. // #ifndef VUE3
  131. this.$emit('input','')
  132. // #endif
  133. // #ifdef VUE3
  134. this.$emit('update:value','')
  135. // #endif
  136. },
  137. toclear() {
  138. this.isHeight = false
  139. this.showPopup = false
  140. },
  141. close() {
  142. this.isHeight = false
  143. this.showPopup = false
  144. const {signatureRef} = this.$refs
  145. signatureRef.clear()
  146. },
  147. deleteImg() {
  148. const {signatureRef} = this.$refs
  149. signatureRef.clear()
  150. },
  151. toDataURL(url) {
  152. // #ifndef VUE3
  153. this.$emit('input',url)
  154. // #endif
  155. // #ifdef VUE3
  156. this.$emit('update:value',url)
  157. // #endif
  158. this.showPicker = false
  159. },
  160. Tomagnify() {
  161. this.isHeight = !this.isHeight
  162. const {signatureRef} = this.$refs
  163. signatureRef.clear()
  164. },
  165. isEmpty() {
  166. const {signatureRef} = this.$refs
  167. signatureRef.canvasToTempFilePath({
  168. quality: 0.8,
  169. success: (res) => {
  170. if (this.required) {
  171. if (!res.isEmpty) {
  172. // #ifndef VUE3
  173. this.$emit('input', res.tempFilePath)
  174. // #endif
  175. // #ifdef VUE3
  176. this.$emit('update:value',res.tempFilePath)
  177. // #endif
  178. this.$emit('change', res.tempFilePath)
  179. this.isHeight = false
  180. this.showPopup = false
  181. } else {
  182. uni.showToast({
  183. title: '请先签名',
  184. icon: 'none'
  185. });
  186. }
  187. } else {
  188. // #ifndef VUE3
  189. this.$emit('input', res.tempFilePath)
  190. // #endif
  191. // #ifdef VUE3
  192. this.$emit('update:value',res.tempFilePath)
  193. // #endif
  194. this.$emit('change', res.tempFilePath)
  195. this.isHeight = false
  196. this.showPopup = false
  197. }
  198. }
  199. })
  200. },
  201. },
  202. beforeCreate() {},
  203. created() {}
  204. }
  205. </script>
  206. <style scoped lang="scss">
  207. .wgSignatureq{
  208. }
  209. .appBut{
  210. display: flex;justify-content: flex-start;align-items: center;text-align: center;height: 50px;line-height: 35px;
  211. .buts{
  212. color: #333;flex: 1;margin: 0 15px;background-color: #ccc;border-radius: 5px;height: 35px;
  213. }
  214. .butx{
  215. color: #333;flex: 1;margin: 0 5px;background-color: #ccc;border-radius: 5px;height: 35px;
  216. transform: rotate(90deg);
  217. }
  218. }
  219. .bottomPopup {
  220. position: fixed;
  221. left: 0;
  222. top: 0;
  223. bottom: 0;
  224. right: 0;
  225. z-index: 999;
  226. background-color: rgba(0, 0, 0, 0.5);
  227. .popup-content {
  228. position: fixed;
  229. left: 0;
  230. right: 0;
  231. bottom: 0;
  232. // top: 0;
  233. background-color: #ffffff;
  234. }
  235. .slide-up-enter-active,
  236. .slide-up-leave-active {
  237. transition: all .3s ease;
  238. }
  239. .slide-up-enter,
  240. .slide-up-leave-to {
  241. transform: translateY(100%);
  242. }
  243. }
  244. .signature {
  245. .inputs {
  246. background-color: #fff;
  247. padding: 10px 16px;
  248. .label {
  249. line-height: 35px;
  250. position: relative;
  251. }
  252. .labelqr:before {
  253. content: "*";
  254. color: #f00;
  255. }
  256. .explain {
  257. width: 100%;
  258. background-color: #f1f1f1;
  259. text-align: center;
  260. line-height: 40px;
  261. border: 1px dotted #ccc;
  262. color: #999;
  263. }
  264. .Deletes {
  265. border: 1px solid #f00;
  266. width: 30rpx;
  267. height: 30rpx;
  268. border-radius: 50%;
  269. color: #f00;
  270. text-align: center;
  271. font-size: 30rpx;
  272. line-height: 30rpx;
  273. }
  274. }
  275. .images {
  276. width: 300rpx;
  277. height: 150rpx;
  278. position: relative;
  279. .icons {
  280. position: absolute;
  281. top: 0;
  282. right: 0;
  283. }
  284. }
  285. }
  286. .popup {
  287. background-color: #fff;
  288. }
  289. .hader {
  290. display: flex;
  291. justify-content: center;
  292. text-align: center;
  293. height: 45px;
  294. border-bottom: 1px solid #f5f5f5;
  295. align-items: center;
  296. div {
  297. text-align: center;
  298. width: 80px;
  299. color: #E59C36;
  300. }
  301. .text {
  302. color: #333;
  303. flex: 1;
  304. }
  305. }
  306. </style>