editPassword.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div>
  3. <h3>修改密码</h3>
  4. <v-divider class="mb-4"></v-divider>
  5. <div class="login-user mb-4">当前登录账号: <span style="color: var(--v-primary-base);">{{ userInfo.phone }}</span></div>
  6. <div style="width: 300px;">
  7. <PhonePage ref="phoneRef"></PhonePage>
  8. <v-form ref="passwordRef">
  9. <v-text-field
  10. v-model="query.password"
  11. placeholder="请输入密码"
  12. variant="outlined"
  13. density="compact"
  14. color="#00897B"
  15. prepend-inner-icon="mdi-lock-outline"
  16. :append-inner-icon="passwordType ? 'mdi-eye-outline' : 'mdi-eye-off-outline'"
  17. :type="passwordType ? 'text' : 'password'"
  18. :rules="[v=> !!v || '请填写密码']"
  19. @click:append-inner="passwordType = !passwordType"
  20. ></v-text-field>
  21. <v-text-field
  22. v-model="query.checkPassword"
  23. placeholder="请再次输入密码"
  24. variant="outlined"
  25. density="compact"
  26. color="#00897B"
  27. prepend-inner-icon="mdi-lock-outline"
  28. :append-inner-icon="show ? 'mdi-eye-outline' : 'mdi-eye-off-outline'"
  29. :type="show ? 'text' : 'password'"
  30. :rules="[v=> !!v || '请再次输入密码', passwordCheck]"
  31. @click:append-inner="show = !show"
  32. ></v-text-field>
  33. </v-form>
  34. <div class="text-center">
  35. <v-btn class="buttons" color="primary" @click="handleSubmit" :loading="loading">确认密码</v-btn>
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script setup name="editPassword">
  41. import PhonePage from '@/components/VerificationCode'
  42. import { updatePassword } from '@/api/common/index'
  43. import { ref, reactive, computed } from 'vue'
  44. const phoneRef = ref()
  45. const passwordRef = ref()
  46. const passwordType = ref(false)
  47. const show = ref(false)
  48. const loading = ref(false)
  49. const query = reactive({
  50. password: '',
  51. checkPassword: ''
  52. })
  53. const passwordCheck = computed(() => {
  54. return query.checkPassword === query.password || '两次密码输入不一致'
  55. })
  56. // 当前登录的用户信息
  57. const userInfo = JSON.parse(localStorage.getItem('userInfo'))
  58. const handleSubmit = async () => {
  59. const { valid: phoneValid } = await phoneRef.value.phoneForm.validate()
  60. const { valid: passValid} = await passwordRef.value.validate()
  61. if (!phoneValid || !passValid) return
  62. loading.value = true
  63. try {
  64. await updatePassword({ password: query.password, code: phoneRef.value.loginData.code })
  65. console.log('success')
  66. } catch (error) {
  67. console.log(error, 'error')
  68. alert(error.msg)
  69. } finally {
  70. loading.value = false
  71. }
  72. }
  73. </script>
  74. <style lang="scss" scoped>
  75. h3 {
  76. font-size: 20px;
  77. text-align: left;
  78. font-weight: 600;
  79. padding-bottom: 25px;
  80. }
  81. .login-user {
  82. color: var(--default-text);
  83. font-weight: 600;
  84. }
  85. </style>