userphone.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <view class="modify-phone-page">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-navbar">
  5. <view class="navbar-content">
  6. <view class="nav-left" @click="goBack">
  7. <u-icon name="arrow-leftward" color="#333" size="42"></u-icon>
  8. </view>
  9. <view class="nav-title">修改手机号</view>
  10. <view class="nav-right"></view>
  11. </view>
  12. </view>
  13. <!-- 主要内容 -->
  14. <view class="main-content">
  15. <!-- 页面标题 -->
  16. <view class="page-title">修改手机号</view>
  17. <!-- 说明文字 -->
  18. <view class="description">
  19. <text>修改手机号后,可以使用新手机号登录亿职赞,聊天时"交换电话"功能的手机号会统一修改</text>
  20. </view>
  21. <!-- 当前手机号显示 -->
  22. <view class="current-phone-section">
  23. <text class="current-label">当前手机号:</text>
  24. <text class="current-phone">{{ currentPhoneMask }}</text>
  25. </view>
  26. <!-- 新手机号输入 -->
  27. <view class="input-section">
  28. <view class="phone-input-container">
  29. <view class="country-selector" @click="showCountrySelector">
  30. <text class="country-code">+ 86</text>
  31. <u-icon name="arrow-down" color="#999" size="24"></u-icon>
  32. </view>
  33. <input v-model="newPhone" type="number" placeholder="请输入新手机号" maxlength="11" class="phone-input" />
  34. </view>
  35. </view>
  36. <!-- 验证码输入 -->
  37. <view class="verification-section">
  38. <view class="verify-input-container">
  39. <view class="verify-boxes">
  40. <input v-for="(digit, index) in verificationDigits" :key="index"
  41. v-model="verificationDigits[index]" type="number" maxlength="1"
  42. :focus="focusIndex === index" class="verify-box" @input="handleDigitInput(index, $event)"
  43. @keyup.delete="handleDelete(index)" />
  44. </view>
  45. <view class="get-code-btn" @click="getVerificationCode" :class="{ disabled: isCountingDown }">
  46. <text>{{ countdownText }}</text>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 底部确定按钮 -->
  52. <view class="bottom-btn-container">
  53. <view class="confirm-btn" @click="confirmChange" :class="{ disabled: !canConfirm }">
  54. <text>确定</text>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import configdata from '../../common/config.js';
  61. export default {
  62. data() {
  63. return {
  64. currentPhone: '', // 当前手机号
  65. newPhone: '', // 新手机号
  66. verificationDigits: ['', '', '', '', '', ''], // 验证码
  67. focusIndex: 0,
  68. isCountingDown: false,
  69. countdown: 60,
  70. countdownText: '获取验证码',
  71. };
  72. },
  73. computed: {
  74. // 当前手机号脱敏显示
  75. currentPhoneMask() {
  76. if (this.currentPhone && this.currentPhone.length >= 11) {
  77. return this.currentPhone.substring(0, 3) + '********' + this.currentPhone.substring(9);
  78. }
  79. return this.currentPhone || '请设置手机号';
  80. },
  81. // 是否可以确认
  82. canConfirm() {
  83. return this.newPhone.length === 11 && this.verificationDigits.join('').length === 6;
  84. }
  85. },
  86. onLoad(options) {
  87. // 从用户信息页面获取当前手机号
  88. if (options.currentPhone) {
  89. this.currentPhone = options.currentPhone;
  90. }
  91. },
  92. methods: {
  93. // 返回上一页
  94. goBack() {
  95. uni.navigateBack();
  96. },
  97. // 显示国家选择器
  98. showCountrySelector() {
  99. uni.showToast({
  100. title: '选择国家/地区',
  101. icon: 'none'
  102. });
  103. },
  104. // 验证码输入处理
  105. handleDigitInput(index, event) {
  106. const value = event.detail.value;
  107. this.verificationDigits[index] = value;
  108. // 自动跳转到下一框
  109. if (value && index < 5) {
  110. this.$nextTick(() => {
  111. this.focusIndex = index + 1;
  112. return;
  113. const nextInput = this.$el.querySelector(`input[data-index="${index + 1}"]`);
  114. console.log(nextInput)
  115. if (nextInput) nextInput.focus();
  116. });
  117. }
  118. },
  119. // 删除处理
  120. handleDelete(index) {
  121. if (!this.verificationDigits[index] && index > 0) {
  122. this.$nextTick(() => {
  123. //this.focusIndex = index - 1;
  124. return;
  125. const prevInput = this.$el.querySelector(`input[data-index="${index - 1}"]`);
  126. if (prevInput) prevInput.focus();
  127. });
  128. }
  129. },
  130. // 获取验证码
  131. async getVerificationCode() {
  132. if (!this.newPhone) {
  133. uni.showToast({
  134. title: '请输入新手机号',
  135. icon: 'none'
  136. });
  137. return;
  138. }
  139. if (this.newPhone.length !== 11) {
  140. uni.showToast({
  141. title: '请输入正确的手机号',
  142. icon: 'none'
  143. });
  144. return;
  145. }
  146. uni.showLoading({
  147. title: '发送中...'
  148. });
  149. try {
  150. // 调用发送验证码API
  151. this.$Request.getT("/app/Login/sendMsg/" + this.newPhone + "/1").then((res) => {
  152. uni.hideLoading();
  153. if (res.code === 0) {
  154. uni.showToast({
  155. title: '验证码发送成功',
  156. icon: 'success'
  157. });
  158. this.startCountdown();
  159. } else {
  160. uni.showToast({
  161. title: res.msg || '发送失败,请重试',
  162. icon: 'none'
  163. });
  164. }
  165. });
  166. // const res = await this.$Request.getT("/app/Login/sendMsg/" + this.newPhone + "/1")
  167. // uni.hideLoading();
  168. // if (res.status === 0) {
  169. // uni.showToast({
  170. // title: '验证码发送成功',
  171. // icon: 'success'
  172. // });
  173. // this.startCountdown();
  174. // } else {
  175. // uni.showToast({
  176. // title: res.msg || '发送失败,请重试',
  177. // icon: 'none'
  178. // });
  179. // }
  180. } catch (error) {
  181. uni.hideLoading();
  182. uni.showToast({
  183. title: '网络错误,请重试',
  184. icon: 'none'
  185. });
  186. }
  187. },
  188. // 开始倒计时
  189. startCountdown() {
  190. this.isCountingDown = true;
  191. this.countdown = 60;
  192. this.countdownText = '60秒后重新获取';
  193. const timer = setInterval(() => {
  194. this.countdown--;
  195. this.countdownText = `${this.countdown}秒后重新获取`;
  196. if (this.countdown <= 0) {
  197. clearInterval(timer);
  198. this.isCountingDown = false;
  199. this.countdownText = '获取验证码';
  200. }
  201. }, 1000);
  202. },
  203. // 确认修改
  204. async confirmChange() {
  205. if (!this.canConfirm) {
  206. uni.showToast({
  207. title: '请完整填写信息',
  208. icon: 'none'
  209. });
  210. return;
  211. }
  212. uni.showLoading({
  213. title: '处理中...'
  214. });
  215. try {
  216. const userId = uni.getStorageSync('userId');
  217. // 验证手机号接口
  218. // const res = await this.$Request.postJson("/app/user/updatePhone", {
  219. // phone: this.newPhone,
  220. // code: this.verificationDigits.join(''),
  221. // })
  222. const res = await this.$Request.post(`/app/user/updatePhone?phone=${this.newPhone}&msg=${this.verificationDigits.join('')}`)
  223. uni.hideLoading();
  224. if (res.code === 0) {
  225. uni.showToast({
  226. title: '手机号修改成功',
  227. icon: 'success'
  228. });
  229. setTimeout(() => {
  230. this.$queue.setData('newPhone', this.newPhone);
  231. uni.navigateBack()
  232. }, 1500);
  233. } else {
  234. uni.showToast({
  235. title: res.msg || '手机号验证失败',
  236. icon: 'none'
  237. });
  238. }
  239. } catch (error) {
  240. uni.hideLoading();
  241. uni.showToast({
  242. title: '网络错误,请重试',
  243. icon: 'none'
  244. });
  245. }
  246. },
  247. // 请求封装
  248. request(options) {
  249. return new Promise((resolve, reject) => {
  250. uni.request({
  251. url: configdata.APIHOST1 + options.url,
  252. method: options.method || 'POST',
  253. data: options.data || {},
  254. success: resolve,
  255. fail: reject
  256. });
  257. });
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .modify-phone-page {
  264. min-height: 100vh;
  265. background: #ffffff;
  266. }
  267. /* 导航栏 */
  268. .custom-navbar {
  269. position: fixed;
  270. top: 0;
  271. left: 0;
  272. right: 0;
  273. padding-top: 80rpx;
  274. background-color: #ffffff;
  275. z-index: 9999;
  276. // border-bottom: 1rpx solid #f0f0f0;
  277. .navbar-content {
  278. display: flex;
  279. align-items: center;
  280. justify-content: space-between;
  281. height: 88rpx;
  282. padding: 0 40rpx;
  283. .nav-left,
  284. .nav-right {
  285. width: 60rpx;
  286. height: 60rpx;
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. }
  291. .nav-title {
  292. color: rgba(51, 51, 51, 1);
  293. font-family: PingFang SC;
  294. font-size: 36rpx;
  295. font-weight: 600;
  296. line-height: 50rpx;
  297. text-align: center;
  298. }
  299. }
  300. }
  301. /* 主要内容 */
  302. .main-content {
  303. margin-top: 168rpx;
  304. padding: 40rpx 30rpx;
  305. }
  306. .page-title {
  307. color: rgba(51, 51, 51, 1);
  308. font-family: DM Sans;
  309. font-size: 48rpx;
  310. font-weight: 700;
  311. line-height: 60rpx;
  312. letter-spacing: 0px;
  313. text-align: left;
  314. margin-bottom: 20rpx;
  315. }
  316. .description {
  317. color: rgba(102, 102, 102, 1);
  318. font-family: DM Sans;
  319. font-size: 24rpx;
  320. font-weight: 400;
  321. line-height: 32rpx;
  322. letter-spacing: 0.5%;
  323. text-align: left;
  324. margin-bottom: 20rpx;
  325. }
  326. .current-phone-section {
  327. display: flex;
  328. align-items: center;
  329. margin-bottom: 20rpx;
  330. gap: 16rpx;
  331. .current-label,
  332. .current-phone {
  333. color: rgba(102, 102, 102, 1);
  334. font-family: DM Sans;
  335. font-size: 24rpx;
  336. font-weight: 400;
  337. line-height: 32rpx;
  338. letter-spacing: 0.5%;
  339. text-align: left;
  340. }
  341. }
  342. /* 手机号输入 */
  343. .input-section {
  344. margin-bottom: 40rpx;
  345. }
  346. .phone-input-container {
  347. width: 100%;
  348. height: 88rpx;
  349. // border: 1px solid rgba(227, 231, 236, 1);
  350. // border-radius: 24px;
  351. background: rgba(255, 255, 255, 1);
  352. display: flex;
  353. align-items: center;
  354. // padding: 0 20rpx;
  355. .country-selector {
  356. display: flex;
  357. align-items: center;
  358. justify-content: center;
  359. width: 208rpx;
  360. height: 96rpx;
  361. border-radius: 12rpx;
  362. background: rgba(247, 248, 249, 1);
  363. // border-right: 1rpx solid #e4e6ea;
  364. margin-right: 20rpx;
  365. gap: 26rpx;
  366. .country-code {
  367. color: rgba(56, 59, 70, 1);
  368. font-family: DM Sans;
  369. font-size: 32rpx;
  370. font-weight: 500;
  371. line-height: 48rpx;
  372. letter-spacing: 0%;
  373. text-align: center;
  374. }
  375. }
  376. .phone-input {
  377. flex: 1;
  378. width: 446rpx;
  379. height: 96rpx;
  380. border-radius: 12rpx;
  381. padding: 0 32rpx;
  382. background: rgba(247, 248, 249, 1);
  383. // color: rgba(195, 196, 199, 1);
  384. font-family: DM Sans;
  385. font-size: 32rpx;
  386. font-weight: 400;
  387. line-height: 48rpx;
  388. letter-spacing: 0%;
  389. text-align: left;
  390. &::placeholder {
  391. color: rgba(195, 196, 199, 1);
  392. }
  393. }
  394. }
  395. /* 验证码部分 */
  396. .verification-section {
  397. margin-bottom: 60rpx;
  398. }
  399. .verify-input-container {
  400. display: flex;
  401. flex-direction: column;
  402. width: 100%;
  403. gap: 20rpx;
  404. padding: 20rpx 0;
  405. }
  406. .verify-boxes {
  407. display: flex;
  408. gap: 20rpx;
  409. justify-content: space-between;
  410. width: 100%;
  411. .verify-box {
  412. width: 110rpx;
  413. height: 96rpx;
  414. border: 1px solid rgba(234, 239, 245, 1);
  415. border-radius: 24rpx;
  416. background: rgba(245, 249, 254, 1);
  417. text-align: center;
  418. color: rgba(23, 23, 37, 1);
  419. font-family: PingFang SC;
  420. font-size: 32rpx;
  421. font-weight: 500;
  422. line-height: 80rpx;
  423. &:focus {
  424. border-color: rgba(24, 144, 255, 1);
  425. background: rgba(255, 255, 255, 1);
  426. }
  427. &::placeholder {
  428. color: rgba(155, 155, 155, 1);
  429. }
  430. }
  431. }
  432. .get-code-btn {
  433. color: rgba(1, 107, 246, 1);
  434. font-family: DM Sans;
  435. font-size: 26rpx;
  436. font-weight: 400;
  437. line-height: 32rpx;
  438. letter-spacing: 0.5%;
  439. text-align: left;
  440. &.disabled {
  441. color: rgba(155, 155, 155, 1);
  442. }
  443. }
  444. /* 底部按钮 */
  445. .bottom-btn-container {
  446. padding: 30rpx;
  447. background: #fff;
  448. // border-top: 1rpx solid #f0f0f0;
  449. z-index: 9999;
  450. }
  451. .confirm-btn {
  452. width: 100%;
  453. height: 88rpx;
  454. background: var(--线性渐变, linear-gradient(90.00deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%));
  455. border-radius: 44rpx;
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. &.disabled {
  460. opacity: 0.4;
  461. }
  462. text {
  463. color: rgba(255, 255, 255, 1);
  464. font-family: PingFang SC;
  465. font-size: 32rpx;
  466. font-weight: 600;
  467. line-height: 44rpx;
  468. }
  469. }
  470. </style>