resetPassword.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <div class="reset-password-container">
  3. <!-- 面包屑导航 -->
  4. <div class="breadcrumb">
  5. <span class="breadcrumb-item" @click="$router.push('/')">首页</span>
  6. <span class="separator">&gt;</span>
  7. <span class="breadcrumb-item" @click="$router.push('/enterprise/companyInfo')">客户中心</span>
  8. <span class="separator">&gt;</span>
  9. <span class="breadcrumb-item" @click="$router.push('/enterprise/securitySetting')">安全设置</span>
  10. <span class="separator">&gt;</span>
  11. <span class="breadcrumb-item active">重置密码</span>
  12. </div>
  13. <!-- 主体内容 -->
  14. <div class="reset-content">
  15. <div class="reset-title">重置密码</div>
  16. <!-- 步骤条 -->
  17. <div class="steps-container">
  18. <div class="step-item" :class="{ active: currentStep >= 1, done: currentStep > 1 }">
  19. <div class="step-circle">
  20. <el-icon v-if="currentStep > 1"><Check /></el-icon>
  21. <span v-else>1</span>
  22. </div>
  23. <div class="step-label">验证身份</div>
  24. </div>
  25. <div class="step-line" :class="{ active: currentStep > 1 }"></div>
  26. <div class="step-item" :class="{ active: currentStep >= 2, done: currentStep > 2 }">
  27. <div class="step-circle">
  28. <el-icon v-if="currentStep > 2"><Check /></el-icon>
  29. <span v-else>2</span>
  30. </div>
  31. <div class="step-label">设置新密码</div>
  32. </div>
  33. <div class="step-line" :class="{ active: currentStep > 2 }"></div>
  34. <div class="step-item" :class="{ active: currentStep >= 3 }">
  35. <div class="step-circle">
  36. <span>3</span>
  37. </div>
  38. <div class="step-label">完成</div>
  39. </div>
  40. </div>
  41. <!-- 步骤1:验证身份 -->
  42. <div class="step-content" v-if="currentStep === 1">
  43. <el-form ref="step1FormRef" :model="step1Form" :rules="step1Rules" label-width="100px" class="verify-form">
  44. <el-form-item label="手机号码:" prop="phone">
  45. <el-input v-model="step1Form.phone" disabled class="form-input" />
  46. <span class="form-tip">若该手机号已无法使用请联系客服</span>
  47. </el-form-item>
  48. <el-form-item label="验证码:" prop="code">
  49. <el-input v-model="step1Form.code" placeholder="短信验证码" class="form-input code-input" />
  50. <el-button link type="primary" class="send-code-btn" :disabled="countdown > 0" @click="handleSendCode">
  51. {{ countdown > 0 ? `${countdown}s后重发` : '发送验证码' }}
  52. </el-button>
  53. </el-form-item>
  54. <el-form-item label="" class="verify-checkbox">
  55. <el-checkbox v-model="step1Form.verified">点击验证</el-checkbox>
  56. </el-form-item>
  57. </el-form>
  58. <div class="step-actions">
  59. <el-button type="danger" class="next-btn" @click="handleNextStep">下一步</el-button>
  60. </div>
  61. </div>
  62. <!-- 步骤2:设置新密码 -->
  63. <div class="step-content" v-if="currentStep === 2">
  64. <el-form ref="step2FormRef" :model="step2Form" :rules="step2Rules" label-width="100px" class="password-form">
  65. <el-form-item label="新密码:" prop="newPassword">
  66. <el-input v-model="step2Form.newPassword" type="password" show-password placeholder="请输入新密码" class="form-input" />
  67. </el-form-item>
  68. <el-form-item label="确认密码:" prop="confirmPassword">
  69. <el-input v-model="step2Form.confirmPassword" type="password" show-password placeholder="请再次输入新密码" class="form-input" />
  70. </el-form-item>
  71. </el-form>
  72. <div class="step-actions">
  73. <el-button @click="currentStep = 1">上一步</el-button>
  74. <el-button type="danger" class="next-btn" @click="handleSubmit">确认修改</el-button>
  75. </div>
  76. </div>
  77. <!-- 步骤3:完成 -->
  78. <div class="step-content" v-if="currentStep === 3">
  79. <div class="success-content">
  80. <el-icon class="success-icon" color="#e60012" :size="60"><CircleCheckFilled /></el-icon>
  81. <div class="success-title">密码重置成功!</div>
  82. <div class="success-desc">您的登录密码已重置成功,请使用新密码登录</div>
  83. <el-button type="danger" @click="$router.push('/enterprise/securitySetting')">返回安全设置</el-button>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </template>
  89. <script setup lang="ts">
  90. import { ref, reactive } from 'vue';
  91. import { Check, CircleCheckFilled } from '@element-plus/icons-vue';
  92. import { ElMessage } from 'element-plus';
  93. import { useRoute } from 'vue-router';
  94. import { changePwd } from '@/api/pc/enterprise/index';
  95. const currentStep = ref(1);
  96. const route = useRoute();
  97. // 步骤1表单
  98. const step1FormRef = ref();
  99. const step1Form = reactive({
  100. phone: route.query.phone as any,
  101. code: '',
  102. verified: false
  103. });
  104. const countdown = ref(0);
  105. const step1Rules = {
  106. code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  107. };
  108. // 步骤2表单
  109. const step2FormRef = ref();
  110. const step2Form = reactive({
  111. newPassword: '',
  112. confirmPassword: ''
  113. });
  114. const validateConfirmPassword = (_rule: any, value: string, callback: any) => {
  115. if (value !== step2Form.newPassword) {
  116. callback(new Error('两次输入的密码不一致'));
  117. } else {
  118. callback();
  119. }
  120. };
  121. const step2Rules = {
  122. newPassword: [
  123. { required: true, message: '请输入新密码', trigger: 'blur' },
  124. { min: 6, max: 20, message: '密码长度为6-20位', trigger: 'blur' }
  125. ],
  126. confirmPassword: [
  127. { required: true, message: '请再次输入新密码', trigger: 'blur' },
  128. { validator: validateConfirmPassword, trigger: 'blur' }
  129. ]
  130. };
  131. // 发送验证码
  132. const handleSendCode = () => {
  133. countdown.value = 60;
  134. const timer = setInterval(() => {
  135. countdown.value--;
  136. if (countdown.value <= 0) {
  137. clearInterval(timer);
  138. }
  139. }, 1000);
  140. ElMessage.success('验证码已发送');
  141. };
  142. // 下一步
  143. const handleNextStep = async () => {
  144. const valid = await step1FormRef.value?.validate().catch(() => false);
  145. if (!valid) return;
  146. if (!step1Form.verified) {
  147. ElMessage.warning('请先点击验证');
  148. return;
  149. }
  150. currentStep.value = 2;
  151. };
  152. // 提交
  153. const handleSubmit = async () => {
  154. const valid = await step2FormRef.value?.validate().catch(() => false);
  155. if (!valid) return;
  156. try {
  157. const submitData = {
  158. phone: step1Form.phone,
  159. code: step1Form.code,
  160. password: step2Form.newPassword,
  161. confirmPassword: step2Form.confirmPassword
  162. };
  163. const res: any = await changePwd(submitData);
  164. if (res.code === 200) {
  165. ElMessage.success('密码重置成功');
  166. currentStep.value = 3;
  167. } else {
  168. ElMessage.error(res.msg || '密码修改失败');
  169. }
  170. } catch (error) {
  171. console.error('修改密码失败:', error);
  172. }
  173. };
  174. </script>
  175. <style scoped lang="scss">
  176. .reset-password-container {
  177. background: #f5f5f5;
  178. min-height: 100%;
  179. padding: 0;
  180. }
  181. // 面包屑
  182. .breadcrumb {
  183. padding: 15px 20px;
  184. font-size: 13px;
  185. color: #666;
  186. background: #fff;
  187. border-bottom: 1px solid #eee;
  188. .breadcrumb-item {
  189. cursor: pointer;
  190. &:hover {
  191. color: #e60012;
  192. }
  193. &.active {
  194. color: #333;
  195. cursor: default;
  196. &:hover {
  197. color: #333;
  198. }
  199. }
  200. }
  201. .separator {
  202. margin: 0 8px;
  203. color: #999;
  204. }
  205. }
  206. // 主体内容
  207. .reset-content {
  208. max-width: 800px;
  209. margin: 30px auto;
  210. padding: 30px 40px;
  211. background: #fff;
  212. border-radius: 4px;
  213. }
  214. .reset-title {
  215. font-size: 18px;
  216. font-weight: 500;
  217. color: #333;
  218. margin-bottom: 30px;
  219. }
  220. // 步骤条
  221. .steps-container {
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. margin-bottom: 50px;
  226. padding: 0 60px;
  227. }
  228. .step-item {
  229. display: flex;
  230. flex-direction: column;
  231. align-items: center;
  232. .step-circle {
  233. width: 32px;
  234. height: 32px;
  235. border-radius: 50%;
  236. border: 2px solid #ddd;
  237. background: #fff;
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. font-size: 14px;
  242. color: #999;
  243. margin-bottom: 10px;
  244. }
  245. .step-label {
  246. font-size: 14px;
  247. color: #999;
  248. }
  249. &.active {
  250. .step-circle {
  251. border-color: #e60012;
  252. color: #e60012;
  253. }
  254. .step-label {
  255. color: #e60012;
  256. }
  257. }
  258. &.done {
  259. .step-circle {
  260. border-color: #e60012;
  261. background: #e60012;
  262. color: #fff;
  263. }
  264. .step-label {
  265. color: #e60012;
  266. }
  267. }
  268. }
  269. .step-line {
  270. flex: 1;
  271. height: 2px;
  272. background: #ddd;
  273. margin: 0 20px;
  274. margin-bottom: 30px;
  275. &.active {
  276. background: #e60012;
  277. }
  278. }
  279. // 表单
  280. .step-content {
  281. padding: 0 60px;
  282. }
  283. .verify-form,
  284. .password-form {
  285. max-width: 500px;
  286. margin: 0 auto;
  287. .form-input {
  288. width: 280px;
  289. }
  290. .code-input {
  291. width: 180px;
  292. }
  293. .form-tip {
  294. margin-left: 15px;
  295. font-size: 12px;
  296. color: #e60012;
  297. cursor: pointer;
  298. }
  299. .send-code-btn {
  300. margin-left: 15px;
  301. color: #e60012;
  302. }
  303. .verify-checkbox {
  304. :deep(.el-form-item__content) {
  305. margin-left: 100px !important;
  306. }
  307. }
  308. }
  309. // 操作按钮
  310. .step-actions {
  311. display: flex;
  312. justify-content: center;
  313. margin-top: 40px;
  314. .next-btn {
  315. width: 200px;
  316. height: 40px;
  317. }
  318. }
  319. // 成功页面
  320. .success-content {
  321. display: flex;
  322. flex-direction: column;
  323. align-items: center;
  324. padding: 40px 0;
  325. .success-icon {
  326. margin-bottom: 20px;
  327. }
  328. .success-title {
  329. font-size: 20px;
  330. font-weight: 500;
  331. color: #333;
  332. margin-bottom: 10px;
  333. }
  334. .success-desc {
  335. font-size: 14px;
  336. color: #999;
  337. margin-bottom: 30px;
  338. }
  339. }
  340. </style>