1
jhzh
2026-05-22 ef52095f5e9f0a9fe2da779bb1573947d77d75b6
src/views/changePassword/index.vue
@@ -1,70 +1,129 @@
<template>
    <div class="changePassword">
        <fx-header>
            <template #title>
                {{ $t('changeLoginPassword') }}
            </template>
        </fx-header>
        <div class="content">
            <ExInput :label="$t('oldPassword')" :placeholderText="$t('entryPassword')" v-model="oldPassword"
                typeText="password" />
            <ExInput :label="$t('newPassword')" :placeholderText="$t('entryPassword')" :tips="$t('setPasswordTips')"
                v-model="newPassword" typeText="password" />
            <ExInput :label="$t('sureNewPassword')" :placeholderText="$t('entryPassword')" :tips="$t('setPasswordTips')"
                v-model="rePassword" typeText="password" />
            <van-button class="w-full" style="margin-top:10px;" type="primary" @click="submit">{{ $t('sure') }}
            </van-button>
        </div>
  <div class="change-password">
    <assets-head :title="''" :show-left="true" />
    <div class="edit-content">
      <div class="edit-input-wrap">
        <input
          v-model="oldPassword"
          type="password"
          class="edit-input"
          :placeholder="$t('oldPassword')"
        />
      </div>
      <div class="edit-input-wrap">
        <input
          v-model="newPassword"
          type="password"
          class="edit-input"
          :placeholder="$t('newPassword')"
        />
      </div>
      <div class="edit-input-wrap">
        <input
          v-model="rePassword"
          type="password"
          class="edit-input"
          :placeholder="$t('sureNewPassword')"
        />
      </div>
      <button class="edit-submit" @click="submit">{{ $t('sure') }}</button>
    </div>
  </div>
</template>
<script setup>
import ExInput from "@/components/ex-input/index.vue";
import { _changePassword } from '@/service/user.api.js'
import { ref } from "vue";
import { showToast } from "vant";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
const { t } = useI18n()
const router = useRouter()
import { _changePassword } from "@/service/user.api.js";
import AssetsHead from "@/components/Transform/assets-head/index.vue";
const oldPassword = ref('')
const newPassword = ref('')
const rePassword = ref('')
const { t } = useI18n();
const router = useRouter();
const oldPassword = ref("");
const newPassword = ref("");
const rePassword = ref("");
const submit = () => {
    _changePassword({
        old_password: oldPassword.value,
        password: newPassword.value,
        re_password: rePassword.value,
    }).then((res) => {
        showToast(t('changeSuccess'))
        setTimeout(() => {
            router.push('/my/index')
        }, 1000);
  if (!oldPassword.value) {
    showToast(t("旧密码不能为空"));
    return;
  }
  if (!newPassword.value || newPassword.value.length < 6) {
    showToast(t("setPasswordTips"));
    return;
  }
  if (newPassword.value !== rePassword.value) {
    showToast(t("noSamePassword"));
    return;
  }
  _changePassword({
    old_password: oldPassword.value,
    password: newPassword.value,
    re_password: rePassword.value,
  })
    .then(() => {
      showToast(t("changeSuccess"));
      setTimeout(() => router.push("/my/index"), 1000);
    })
}
    .catch((err) => {
      const msg = err?.message || err?.msg;
      if (msg && (msg.includes("旧密码") || msg.includes("incorrect") || msg.includes("wrong"))) {
        showToast(t("旧密码不正确"));
      } else {
        showToast(msg || t("fail"));
      }
    });
};
</script>
<style lang="scss" scoped>
.changePassword {
    width: 100%;
    box-sizing: border-box;
.change-password {
  min-height: 100vh;
  background: #fff;
  box-sizing: border-box;
}
.line {
    width: 100%;
    height: 2px;
    background: $light-grey;
.edit-content {
  padding: 24px 16px;
}
.content {
    padding: 16px;
    font-size: 13px;
.edit-input-wrap {
  height: 48px;
  margin-bottom: 20px;
  padding: 0 16px;
  background: #f5f5f5;
  border-radius: 10px;
  display: flex;
  align-items: center;
}
.hightLight {
    background: $btn_main;
    color: $text_color;
.edit-input {
  flex: 1;
  height: 100%;
  border: none;
  background: transparent;
  font-size: 16px;
  color: #333;
  outline: none;
}
.edit-input::placeholder {
  color: #999;
}
.edit-submit {
  width: 100%;
  margin-top: 40px;
  padding: 16px 0;
  border: none;
  border-radius: 12px;
  background: linear-gradient(90deg, #5e2bc8, #a443cf);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
</style>