1
jhzh
2026-05-22 ef52095f5e9f0a9fe2da779bb1573947d77d75b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
  <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 { ref } from "vue";
import { showToast } from "vant";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { _changePassword } from "@/service/user.api.js";
import AssetsHead from "@/components/Transform/assets-head/index.vue";
 
const { t } = useI18n();
const router = useRouter();
 
const oldPassword = ref("");
const newPassword = ref("");
const rePassword = ref("");
 
const submit = () => {
  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>
.change-password {
  min-height: 100vh;
  background: #fff;
  box-sizing: border-box;
}
 
.edit-content {
  padding: 24px 16px;
}
 
.edit-input-wrap {
  height: 48px;
  margin-bottom: 20px;
  padding: 0 16px;
  background: #f5f5f5;
  border-radius: 10px;
  display: flex;
  align-items: center;
}
 
.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>