瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.2 KiB

  1. <template>
  2. <!-- 邮箱填写弹窗 -->
  3. <uv-popup ref="emailPopup" :round="30">
  4. <view class="email-popup">
  5. <view class="email-title">
  6. 完善邮箱信息
  7. </view>
  8. <view class="email-desc">
  9. 为了更好的服务体验请填写您的邮箱地址
  10. </view>
  11. <view class="email-input-box">
  12. <input
  13. type="email"
  14. v-model="emailForm.mail"
  15. placeholder="请输入邮箱地址"
  16. class="email-input"
  17. />
  18. </view>
  19. <view class="email-buttons">
  20. <view class="email-btn cancel-btn" @click="skipEmail">
  21. 跳过
  22. </view>
  23. <view class="email-btn confirm-btn" @click="saveEmail">
  24. 确认
  25. </view>
  26. </view>
  27. </view>
  28. </uv-popup>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'EmailPopup',
  33. data() {
  34. return {
  35. emailForm: {
  36. mail: ''
  37. }
  38. }
  39. },
  40. methods: {
  41. // 显示邮箱填写弹窗
  42. show() {
  43. this.$refs.emailPopup.open('center')
  44. },
  45. // 隐藏邮箱填写弹窗
  46. hide() {
  47. this.$refs.emailPopup.close()
  48. },
  49. // 跳过邮箱填写
  50. skipEmail() {
  51. this.hide()
  52. this.resetForm()
  53. this.$emit('skip')
  54. },
  55. // 保存邮箱
  56. saveEmail() {
  57. if (!this.emailForm.mail) {
  58. uni.showToast({
  59. title: '请输入邮箱地址',
  60. icon: 'none'
  61. })
  62. return
  63. }
  64. // 验证邮箱格式
  65. const emailReg = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
  66. if (!emailReg.test(this.emailForm.mail)) {
  67. uni.showToast({
  68. title: '请输入正确的邮箱格式',
  69. icon: 'none'
  70. })
  71. return
  72. }
  73. // 更新用户邮箱信息
  74. this.$api('updateInfo', {
  75. mail: this.emailForm.mail
  76. }, res => {
  77. if (res.code == 200) {
  78. // 更新本地用户信息
  79. this.$store.commit('getUserInfo')
  80. this.hide()
  81. this.resetForm()
  82. uni.showToast({
  83. title: '邮箱保存成功',
  84. icon: 'success'
  85. })
  86. this.$emit('confirm', this.emailForm.mail)
  87. }
  88. })
  89. },
  90. // 重置表单
  91. resetForm() {
  92. this.emailForm.mail = ''
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped lang="scss">
  98. .email-popup {
  99. padding: 40rpx;
  100. width: 600rpx;
  101. .email-title {
  102. font-size: 36rpx;
  103. font-weight: bold;
  104. text-align: center;
  105. margin-bottom: 20rpx;
  106. color: #333;
  107. }
  108. .email-desc {
  109. font-size: 28rpx;
  110. color: #666;
  111. text-align: center;
  112. margin-bottom: 40rpx;
  113. line-height: 1.5;
  114. }
  115. .email-input-box {
  116. margin-bottom: 40rpx;
  117. .email-input {
  118. width: 100%;
  119. height: 80rpx;
  120. border: 2rpx solid #e5e5e5;
  121. border-radius: 10rpx;
  122. padding: 0 20rpx;
  123. font-size: 28rpx;
  124. box-sizing: border-box;
  125. &:focus {
  126. border-color: $uni-color-primary;
  127. }
  128. }
  129. }
  130. .email-buttons {
  131. display: flex;
  132. gap: 20rpx;
  133. .email-btn {
  134. flex: 1;
  135. height: 80rpx;
  136. line-height: 80rpx;
  137. text-align: center;
  138. border-radius: 10rpx;
  139. font-size: 28rpx;
  140. &.cancel-btn {
  141. background-color: #f5f5f5;
  142. color: #666;
  143. }
  144. &.confirm-btn {
  145. background-color: $uni-color-primary;
  146. color: #fff;
  147. }
  148. }
  149. }
  150. }
  151. </style>