uni-popup-captcha.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <uni-popup ref="popup" type="center">
  3. <view class="popup-captcha">
  4. <view class="content">
  5. <text class="title">{{title}}</text>
  6. <uni-captcha :focus="focus" :scene="scene" v-model="val"></uni-captcha>
  7. </view>
  8. <view class="button-box">
  9. <view @click="close" class="btn">取消</view>
  10. <view @click="confirm" class="btn confirm">确认</view>
  11. </view>
  12. </view>
  13. </uni-popup>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. focus: false
  20. }
  21. },
  22. props: {
  23. modelValue:String,
  24. value:String,
  25. scene: {
  26. type: String,
  27. default () {
  28. return ""
  29. }
  30. },
  31. title: {
  32. type: String,
  33. default () {
  34. return ""
  35. }
  36. },
  37. },
  38. computed:{
  39. val:{
  40. get(){
  41. return this.value||this.modelValue
  42. },
  43. set(value){
  44. // console.log(value);
  45. // TODO 兼容 vue2
  46. // #ifdef VUE2
  47. this.$emit('input', value);
  48. // #endif
  49. // TODO 兼容 vue3
  50. // #ifdef VUE3
  51. this.$emit('update:modelValue', value)
  52. // #endif
  53. }
  54. }
  55. },
  56. methods: {
  57. open() {
  58. this.focus = true
  59. this.val = ""
  60. this.$refs.popup.open()
  61. },
  62. close() {
  63. this.focus = false
  64. this.$refs.popup.close()
  65. },
  66. confirm() {
  67. if(!this.val||this.val.length < 4){
  68. return uni.showToast({
  69. title: '请填写验证码',
  70. icon: 'none'
  71. });
  72. }
  73. this.close()
  74. this.$emit('confirm')
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. /* #ifndef APP-NVUE */
  81. view {
  82. display: flex;
  83. flex-direction: column;
  84. }
  85. /* #endif */
  86. .popup-captcha {
  87. /* #ifndef APP-NVUE */
  88. display: flex;
  89. max-width: 600px;
  90. /* #endif */
  91. width: 600rpx;
  92. padding-bottom: 0;
  93. background-color: #FFF;
  94. border-radius: 10px;
  95. flex-direction: column;
  96. position: relative;
  97. }
  98. .popup-captcha .content {
  99. padding: 1.3em 0.8em;
  100. }
  101. .popup-captcha .title {
  102. text-align: center;
  103. word-wrap: break-word;
  104. word-break: break-all;
  105. white-space: pre-wrap;
  106. font-weight: 400;
  107. font-size: 18px;
  108. overflow: hidden;
  109. text-overflow: ellipsis;
  110. color: #111;
  111. margin-bottom: 15px;
  112. }
  113. .button-box {
  114. height: 44px;
  115. border-top: solid 1px #eee;
  116. flex-direction: row;
  117. align-items: center;
  118. justify-content: space-around;
  119. }
  120. .button-box ,.btn{
  121. height: 44px;
  122. line-height: 44px;
  123. }
  124. .button-box .btn{
  125. flex: 1;
  126. margin: 1px;
  127. text-align: center;
  128. }
  129. .button-box .confirm{
  130. color: #007aff;
  131. border-left: solid 1px #eee;
  132. }
  133. </style>