security.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view class="acct-sec-page">
  3. <view class="acct-sec-nav" :style="{ paddingTop: statusBar + 'px' }">
  4. <view class="acct-sec-nav-row">
  5. <view class="acct-sec-back" @tap="goBack">
  6. <text class="acct-sec-back-icon">←</text>
  7. </view>
  8. <text class="acct-sec-nav-title">{{ copy.title }}</text>
  9. <view class="acct-sec-nav-placeholder" />
  10. </view>
  11. </view>
  12. <scroll-view
  13. scroll-y
  14. class="acct-sec-scroll"
  15. :style="{ height: scrollHeight + 'px' }"
  16. >
  17. <view class="acct-sec-body" :style="{ paddingBottom: safeBottom + 'px' }">
  18. <view class="acct-sec-card">
  19. <view
  20. class="acct-sec-row"
  21. hover-class="acct-sec-row--press"
  22. @tap="openPasswordReset"
  23. >
  24. <text class="acct-sec-row-label">{{ copy.changePassword }}</text>
  25. <text class="acct-sec-chevron">›</text>
  26. </view>
  27. </view>
  28. <view class="acct-sec-card acct-sec-card--danger">
  29. <view
  30. class="acct-sec-row acct-sec-row--last"
  31. hover-class="acct-sec-row--press"
  32. @tap="confirmRemoveAccount"
  33. >
  34. <text class="acct-sec-row-label acct-sec-row-label--danger">{{ copy.cancelAccount }}</text>
  35. <text class="acct-sec-chevron">›</text>
  36. </view>
  37. </view>
  38. <text class="acct-sec-hint">{{ copy.cancelHint }}</text>
  39. </view>
  40. </scroll-view>
  41. </view>
  42. </template>
  43. <script>
  44. import { mapState } from 'vuex'
  45. import { looksLikeHandset, trimHandset } from '@/features/passport/form-rules'
  46. import { removeAccount } from '@/features/account/account-security-gateway'
  47. import { buildRestPath } from '@/core/config/api-paths'
  48. import { post } from '@/core/http/http-client'
  49. export default {
  50. data() {
  51. return {
  52. statusBar: 0,
  53. scrollHeight: 600,
  54. safeBottom: 0,
  55. removing: false
  56. }
  57. },
  58. computed: {
  59. ...mapState('user', {
  60. profile: (state) => state
  61. }),
  62. copy() {
  63. const t = this.$t.bind(this)
  64. return {
  65. title: t('user.securityTitle'),
  66. changePassword: t('user.securityChangePassword'),
  67. cancelAccount: t('user.securityCancelAccount'),
  68. cancelHint: t('user.securityCancelHint'),
  69. cancelTitle: t('user.securityCancelTitle'),
  70. cancelMessage: t('user.securityCancelMessage'),
  71. cancelConfirm: t('user.securityCancelConfirm'),
  72. cancelKeep: t('user.securityCancelKeep'),
  73. cancelOk: t('user.securityCancelOk'),
  74. prompt: t('user.panelPrompt'),
  75. noMobile: t('user.securityNoMobile'),
  76. network: t('user.realnameNetworkError')
  77. }
  78. }
  79. },
  80. onLoad() {
  81. const sys = uni.getSystemInfoSync()
  82. this.statusBar = sys.statusBarHeight || 0
  83. this.safeBottom = sys.safeAreaInsets ? sys.safeAreaInsets.bottom : 0
  84. const navH = this.statusBar + uni.upx2px(88)
  85. this.scrollHeight = (sys.windowHeight || 667) - navH
  86. },
  87. methods: {
  88. goBack() {
  89. if (getCurrentPages().length > 1) {
  90. uni.navigateBack({ delta: 1 })
  91. } else {
  92. uni.switchTab({
  93. url: '/pages/mine/index',
  94. fail: () => uni.reLaunch({ url: '/pages/mine/index' })
  95. })
  96. }
  97. },
  98. toast(msg) {
  99. if (this.$appKit && this.$appKit.msg) this.$appKit.msg(msg)
  100. else uni.showToast({ title: msg, icon: 'none' })
  101. },
  102. handsetDigits() {
  103. return trimHandset(this.profile.mobile || '')
  104. },
  105. regionDigits() {
  106. return String(this.profile.area_code || '852').replace(/^\+/, '')
  107. },
  108. openPasswordReset() {
  109. const params = []
  110. const handset = this.handsetDigits()
  111. const region = this.regionDigits()
  112. if (looksLikeHandset(handset)) {
  113. params.push(`handset=${encodeURIComponent(handset)}`)
  114. params.push(`region=${encodeURIComponent(region)}`)
  115. if (this.profile && this.profile.isLogin) {
  116. params.push('lock=1')
  117. }
  118. }
  119. const url = params.length
  120. ? `/pages/account/reset-password?${params.join('&')}`
  121. : '/pages/account/reset-password'
  122. uni.navigateTo({
  123. url,
  124. fail: () => this.$appKit && this.$appKit.to(url)
  125. })
  126. },
  127. confirmRemoveAccount() {
  128. uni.showModal({
  129. title: this.copy.cancelTitle,
  130. content: this.copy.cancelMessage,
  131. confirmText: this.copy.cancelConfirm,
  132. cancelText: this.copy.cancelKeep,
  133. confirmColor: '#ef4444',
  134. success: (res) => {
  135. if (res.confirm) this.removeAccountNow()
  136. }
  137. })
  138. },
  139. async removeAccountNow() {
  140. if (this.removing) return
  141. this.removing = true
  142. uni.showLoading({ mask: true })
  143. try {
  144. await removeAccount()
  145. try {
  146. await post(buildRestPath('user/logout'))
  147. } catch (_) {}
  148. try {
  149. await this.$store.dispatch('im/pause', true)
  150. } catch (_) {}
  151. await this.$store.dispatch('clearSession')
  152. this.toast(this.copy.cancelOk)
  153. uni.reLaunch({ url: '/pages/passport/signin?mode=secret' })
  154. } catch (err) {
  155. this.toast((err && err.message) || this.copy.network)
  156. } finally {
  157. this.removing = false
  158. uni.hideLoading()
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style scoped>
  165. .acct-sec-page {
  166. min-height: 100vh;
  167. background-color: #f4f6fb;
  168. }
  169. .acct-sec-nav {
  170. background-color: #ffffff;
  171. border-bottom: 1rpx solid #eef1f6;
  172. }
  173. .acct-sec-nav-row {
  174. display: flex;
  175. flex-direction: row;
  176. align-items: center;
  177. height: 88rpx;
  178. padding: 0 24rpx;
  179. box-sizing: border-box;
  180. }
  181. .acct-sec-back {
  182. width: 64rpx;
  183. height: 64rpx;
  184. display: flex;
  185. align-items: center;
  186. justify-content: center;
  187. }
  188. .acct-sec-back-icon {
  189. font-size: 40rpx;
  190. color: #1a1d26;
  191. line-height: 1;
  192. }
  193. .acct-sec-nav-title {
  194. flex: 1;
  195. text-align: center;
  196. font-size: 32rpx;
  197. font-weight: 600;
  198. color: #1a1d26;
  199. }
  200. .acct-sec-nav-placeholder {
  201. width: 64rpx;
  202. }
  203. .acct-sec-body {
  204. padding: 24rpx 28rpx 0;
  205. box-sizing: border-box;
  206. }
  207. .acct-sec-card {
  208. background-color: #ffffff;
  209. border-radius: 24rpx;
  210. box-shadow: 0 6rpx 24rpx rgba(74, 140, 255, 0.06);
  211. overflow: hidden;
  212. margin-bottom: 24rpx;
  213. }
  214. .acct-sec-card--danger {
  215. margin-bottom: 16rpx;
  216. }
  217. .acct-sec-row {
  218. display: flex;
  219. flex-direction: row;
  220. align-items: center;
  221. justify-content: space-between;
  222. min-height: 104rpx;
  223. padding: 0 28rpx;
  224. border-bottom: 1rpx solid #f0f2f7;
  225. box-sizing: border-box;
  226. }
  227. .acct-sec-row--last {
  228. border-bottom-width: 0;
  229. }
  230. .acct-sec-row--press {
  231. background-color: #f7f9fc;
  232. }
  233. .acct-sec-row-label {
  234. font-size: 30rpx;
  235. color: #1a1d26;
  236. }
  237. .acct-sec-row-label--danger {
  238. color: #ef4444;
  239. }
  240. .acct-sec-chevron {
  241. font-size: 36rpx;
  242. color: #c5cad6;
  243. line-height: 1;
  244. }
  245. .acct-sec-hint {
  246. display: block;
  247. padding: 0 8rpx;
  248. font-size: 24rpx;
  249. line-height: 1.5;
  250. color: #8a8d9e;
  251. }
  252. </style>