pay-password.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <cwg-page-wrapper>
  3. <view class="page">
  4. <u-form ref="resetForm">
  5. <cwg-input v-model:value="loginName" type="text" :required="true" fkey="loginName" :label="t('login.p1')"
  6. :clearable="true" :placeholder="t('login.msg1')" :rules="[{ required: true, message: t('login.msg1') }]"
  7. @change="handleChange">
  8. </cwg-input>
  9. <cwg-input v-model:value="oldPassword" :type="showPassword ? 'text' : 'password'" fkey="oldPassword"
  10. :required="true" :label="t('login.p3')" :clearable="true" :placeholder="t('login.msg3')"
  11. :rules="[{ required: true, message: t('login.msg3') }]" @change="handleChange">
  12. <template #right-icon1>
  13. <!-- <u-icon name="eye-o" @click="showPassword = !showPassword" /> -->
  14. </template>
  15. </cwg-input>
  16. <cwg-input v-model:value="newPassword" :type="showPassword1 ? 'text' : 'password'" fkey="newPassword"
  17. :required="true" :label="t('login.p4')" :clearable="true" :placeholder="t('login.msg3')"
  18. :rules="[{ required: true, message: t('login.msg3') }]" @change="handleChange">
  19. <template #right-icon1>
  20. <!-- <u-icon name="eye-o" @click="showPassword1 = !showPassword1" /> -->
  21. </template>
  22. </cwg-input>
  23. <view class="fixed-btn">
  24. <view class="cwg-button">
  25. <u-button type="primary" block :loading="loading" @click="handleReset">{{ t("pages.mine.pay-password")
  26. }}</u-button>
  27. </view>
  28. </view>
  29. </u-form>
  30. <SuccessPrompt v-if="isShow" :btn-click="btnClick" :btn-title="t('newSignin.item7')" />
  31. </view>
  32. </cwg-page-wrapper>
  33. </template>
  34. <script setup lang="ts">
  35. import { ref, onMounted, watch } from "vue";
  36. import { showToast } from "@/utils/toast";
  37. import { useI18n } from "vue-i18n";
  38. import useRouter from "@/hooks/useRouter";
  39. import { userApi } from "@/api/user";
  40. const { t } = useI18n();
  41. const resetForm = ref();
  42. const router = useRouter();
  43. const loading = ref(false);
  44. const loginName = ref("");
  45. const oldPassword = ref("");
  46. const newPassword = ref("");
  47. const isShow = ref(false);
  48. const showPassword = ref(false);
  49. const showPassword1 = ref(false);
  50. function btnClick() {
  51. router.push("/pages/login/index");
  52. }
  53. async function handleReset() {
  54. loading.value = true;
  55. try {
  56. await resetForm.value?.validate([
  57. "loginName",
  58. "newPassword",
  59. "oldPassword",
  60. ]);
  61. if (newPassword.value == oldPassword.value) {
  62. showToast(t("login.msg5"));
  63. return;
  64. }
  65. const res = await userApi.updateEmailPassword({
  66. newPassword: newPassword.value,
  67. oldPassword: oldPassword.value,
  68. });
  69. if (res.code == 200) {
  70. isShow.value = true;
  71. } else {
  72. showToast(res.msg);
  73. }
  74. } catch (error: any) {
  75. if (Array.isArray(error) && error.length > 0) {
  76. showToast(error[0].message);
  77. } else {
  78. showToast(t("login.msg0_2"));
  79. }
  80. return;
  81. } finally {
  82. loading.value = false;
  83. }
  84. }
  85. function handleChange(value: any) { }
  86. </script>
  87. <style scoped lang="scss"></style>