sms-verify.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="acct-pwd-page">
  3. <view class="acct-pwd-nav" :style="{ paddingTop: statusBar + 'px' }">
  4. <view class="acct-pwd-nav-row">
  5. <view class="acct-pwd-back" @tap="goBack">
  6. <text class="acct-pwd-back-icon">←</text>
  7. </view>
  8. <text class="acct-pwd-nav-title">{{ copy.title }}</text>
  9. <view class="acct-pwd-nav-placeholder" />
  10. </view>
  11. </view>
  12. <scroll-view
  13. scroll-y
  14. class="acct-pwd-scroll"
  15. :style="{ height: scrollHeight + 'px' }"
  16. >
  17. <view class="acct-pwd-body" :style="{ paddingBottom: safeBottom + 'px' }">
  18. <view class="acct-pwd-hero">
  19. <view class="acct-pwd-hero-icon-wrap">
  20. <text class="acct-pwd-hero-icon">💬</text>
  21. </view>
  22. <text class="acct-pwd-hero-title">{{ copy.heroTitle }}</text>
  23. <text class="acct-pwd-hero-desc">{{ copy.sentTo }}</text>
  24. <text class="acct-sms-mobile">+{{ region }} {{ maskedHandset }}</text>
  25. </view>
  26. <view class="acct-pwd-card acct-sms-card">
  27. <text class="acct-pwd-label">{{ copy.codeLabel }}</text>
  28. <passcode-grid
  29. theme="light"
  30. :value="passcode"
  31. :alert="passcodeAlert"
  32. :disabled="submitting"
  33. @input="onPasscodeInput"
  34. @settled="onPasscodeSettled"
  35. />
  36. <view class="acct-sms-resend">
  37. <text v-if="coolLeft > 0" class="acct-sms-resend__muted">
  38. {{ copy.resendIn }} {{ coolLeft }}s
  39. </text>
  40. <text
  41. v-else
  42. class="acct-sms-resend__link"
  43. @tap="resendPasscode"
  44. >{{ copy.resend }}</text>
  45. <text v-if="coolLeft > 0 && coolLeft < 50" class="acct-sms-resend__hint">
  46. {{ copy.notReceive }}
  47. </text>
  48. </view>
  49. </view>
  50. <button
  51. class="acct-pwd-submit"
  52. :disabled="!canSubmit || submitting"
  53. :loading="submitting"
  54. :class="{ 'acct-pwd-submit--off': !canSubmit, 'acct-pwd-submit--busy': submitting }"
  55. @tap="onSubmit"
  56. >
  57. <text class="acct-pwd-submit__text">{{ submitting ? copy.submitting : copy.next }}</text>
  58. </button>
  59. </view>
  60. </scroll-view>
  61. </view>
  62. </template>
  63. <script>
  64. import PasscodeGrid from '@/components/passport-kit/passcode-grid.vue'
  65. import { requestPasscode } from '@/features/passport/credential-bridge'
  66. import { passcodeShape, trimHandset } from '@/features/passport/form-rules'
  67. export default {
  68. components: { PasscodeGrid },
  69. data() {
  70. return {
  71. statusBar: 0,
  72. scrollHeight: 600,
  73. safeBottom: 0,
  74. scene: 'resetpwd',
  75. handset: '',
  76. region: '852',
  77. ticketId: '',
  78. passcode: '',
  79. passcodeAlert: false,
  80. coolLeft: 0,
  81. coolTimer: null,
  82. sending: false,
  83. submitting: false,
  84. redirect: ''
  85. }
  86. },
  87. computed: {
  88. copy() {
  89. const t = this.$t.bind(this)
  90. return {
  91. title: t('passport.title-sms-verify'),
  92. heroTitle: t('user.smsVerifyHeroTitle'),
  93. sentTo: t('passport.sms-sent-to'),
  94. codeLabel: t('user.smsVerifyCodeLabel'),
  95. resend: t('passport.sms-resend'),
  96. resendIn: t('passport.sms-resend-in'),
  97. notReceive: t('user.smsVerifyNotReceive'),
  98. next: t('passport.btn-next'),
  99. submitting: t('passport.btn-probing')
  100. }
  101. },
  102. maskedHandset() {
  103. const raw = this.handset
  104. if (raw.length <= 4) return raw
  105. return `${raw.slice(0, 3)}****${raw.slice(-4)}`
  106. },
  107. canSubmit() {
  108. return passcodeShape(this.passcode)
  109. }
  110. },
  111. onLoad(query) {
  112. const sys = uni.getSystemInfoSync()
  113. this.statusBar = sys.statusBarHeight || 0
  114. this.safeBottom = sys.safeAreaInsets ? sys.safeAreaInsets.bottom : 0
  115. const navH = this.statusBar + uni.upx2px(88)
  116. this.scrollHeight = (sys.windowHeight || 667) - navH
  117. if (query && query.scene) this.scene = query.scene
  118. if (query && query.handset) {
  119. try {
  120. this.handset = trimHandset(decodeURIComponent(query.handset))
  121. } catch (_) {
  122. this.handset = trimHandset(query.handset)
  123. }
  124. }
  125. if (query && query.region) {
  126. try {
  127. this.region = String(decodeURIComponent(query.region)).replace(/^\+/, '')
  128. } catch (_) {
  129. this.region = String(query.region).replace(/^\+/, '')
  130. }
  131. }
  132. if (query && query.ticketId) {
  133. try {
  134. this.ticketId = decodeURIComponent(query.ticketId)
  135. } catch (_) {
  136. this.ticketId = query.ticketId || ''
  137. }
  138. }
  139. if (query && query.redirect) {
  140. try {
  141. this.redirect = decodeURIComponent(query.redirect)
  142. } catch (_) {
  143. this.redirect = query.redirect || ''
  144. }
  145. }
  146. this.coolStart(60)
  147. },
  148. onShow() {
  149. this.resetSubmitState()
  150. },
  151. onUnload() {
  152. if (this.coolTimer) clearInterval(this.coolTimer)
  153. },
  154. methods: {
  155. goBack() {
  156. if (getCurrentPages().length > 1) {
  157. uni.navigateBack({ delta: 1 })
  158. } else {
  159. uni.redirectTo({ url: '/pages/account/reset-password' })
  160. }
  161. },
  162. toast(msg) {
  163. if (this.$appKit && this.$appKit.msg) this.$appKit.msg(msg)
  164. else uni.showToast({ title: msg, icon: 'none' })
  165. },
  166. resetSubmitState() {
  167. this.submitting = false
  168. this.sending = false
  169. try {
  170. uni.hideLoading()
  171. } catch (_) {}
  172. },
  173. coolStart(sec) {
  174. this.coolLeft = sec
  175. if (this.coolTimer) clearInterval(this.coolTimer)
  176. this.coolTimer = setInterval(() => {
  177. this.coolLeft -= 1
  178. if (this.coolLeft <= 0) {
  179. clearInterval(this.coolTimer)
  180. this.coolTimer = null
  181. }
  182. }, 1000)
  183. },
  184. onPasscodeInput(val) {
  185. this.passcode = val
  186. this.passcodeAlert = false
  187. },
  188. onPasscodeSettled() {
  189. this.passcodeAlert = false
  190. if (this.scene === 'resetpwd') {
  191. this.onSubmit()
  192. }
  193. },
  194. buildResetSecretUrl() {
  195. const q = [
  196. `handset=${encodeURIComponent(this.handset)}`,
  197. `region=${encodeURIComponent(this.region)}`,
  198. `passcode=${encodeURIComponent(this.passcode)}`,
  199. `ticketId=${encodeURIComponent(this.ticketId || '')}`
  200. ]
  201. if (this.redirect) q.push(`redirect=${encodeURIComponent(this.redirect)}`)
  202. return `/pages/account/reset-secret?${q.join('&')}`
  203. },
  204. async resendPasscode() {
  205. if (this.coolLeft > 0 || this.sending) return
  206. this.sending = true
  207. uni.showLoading({ mask: true })
  208. try {
  209. const { ticketId, needHumanCheck } = await requestPasscode({
  210. scene: this.scene,
  211. handset: this.handset,
  212. region: this.region
  213. })
  214. if (needHumanCheck) {
  215. this.toast(this.$t('passport.tip-need-captcha'))
  216. return
  217. }
  218. this.ticketId = ticketId
  219. this.passcode = ''
  220. this.coolStart(60)
  221. this.toast(this.$t('passport.tip-code-sent'))
  222. } catch (err) {
  223. const bizHandled = err && (err.kind === 'BUSINESS' || err.kind === 'SILENT')
  224. if (!bizHandled) {
  225. this.toast((err && err.message) || this.$t('passport.tip-code-failed'))
  226. }
  227. } finally {
  228. this.sending = false
  229. uni.hideLoading()
  230. }
  231. },
  232. onSubmit() {
  233. if (this.submitting) return
  234. if (!this.canSubmit) {
  235. this.passcodeAlert = true
  236. this.toast(this.$t('passport.err-passcode'))
  237. return
  238. }
  239. if (this.scene !== 'resetpwd') return
  240. this.submitting = true
  241. uni.navigateTo({
  242. url: this.buildResetSecretUrl(),
  243. complete: () => {
  244. this.resetSubmitState()
  245. }
  246. })
  247. }
  248. }
  249. }
  250. </script>
  251. <style scoped>
  252. @import './account-flow.css';
  253. .acct-sms-mobile {
  254. font-size: 32rpx;
  255. font-weight: 600;
  256. color: #4a8cff;
  257. margin-top: 12rpx;
  258. letter-spacing: 1rpx;
  259. }
  260. .acct-sms-card {
  261. padding-bottom: 32rpx;
  262. }
  263. .acct-sms-resend {
  264. margin-top: 28rpx;
  265. display: flex;
  266. flex-direction: column;
  267. align-items: center;
  268. }
  269. .acct-sms-resend__muted {
  270. font-size: 26rpx;
  271. color: #8a8d9e;
  272. }
  273. .acct-sms-resend__link {
  274. font-size: 26rpx;
  275. color: #4a8cff;
  276. font-weight: 600;
  277. }
  278. .acct-sms-resend__hint {
  279. margin-top: 12rpx;
  280. font-size: 24rpx;
  281. color: #b8bcc8;
  282. }
  283. </style>