| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <template>
- <view class="container">
- <!-- 旧密码输入框 -->
- <view class="input-group-header">旧密码:</view>
- <view class="uni-input-wrapper">
- <input class="uni-input" placeholder="请输入旧密码" :password="showPassword1" v-model="oldPassword" />
- <text class="uni-icon" :class="[!showPassword1 ? 'uni-eye-active' : '']"
- @click="changePassword1"></text>
- </view>
- <view class="input-group-header">新密码:</view>
- <!-- 新密码输入框 -->
- <view class="uni-input-wrapper">
- <input class="uni-input" placeholder="请输入新密码" :password="showPassword2" v-model="newPassword" />
- <text class="uni-icon" :class="[!showPassword2 ? 'uni-eye-active' : '']"
- @click="changePassword2"></text>
- </view>
- <!-- 确认新密码输入框 -->
- <view class="uni-input-wrapper">
- <input class="uni-input" placeholder="请确认新密码" :password="showPassword3" v-model="confirmPassword" />
- <text class="uni-icon" :class="[!showPassword3 ? 'uni-eye-active' : '']"
- @click="changePassword3"></text>
- </view>
- <!-- 提交按钮 -->
- <button @click="submit" class="submitBtn">提交</button>
- </view>
- </template>
- <script setup lang="ts">
- import {
- ref
- } from 'vue';
- import $modal from '@/plugins/modal.js'
- import {
- changePWD
- } from '@/api/mine';
- import {
- useUserStore
- } from '@/store/user';
- import $tab from '@/plugins/tab.js'
- const userStore = useUserStore();
- const oldPassword = ref(''); // 旧密码
- const newPassword = ref(''); // 新密码
- const confirmPassword = ref(''); // 确认新密码
- const showPassword1 = ref(true); // 旧密码可见性
- const showPassword2 = ref(true); // 新密码可见性
- const showPassword3 = ref(true); // 确认密码可见性
- // 提交逻辑
- function submit() {
- // 检查新密码和确认密码是否一致
- if (newPassword.value !== confirmPassword.value) {
- $modal.showToast('新密码和确认密码不一致')
- return; // 终止提交
- }
- // 检查新密码强度
- if (!validatePassword(newPassword.value)) {
- $modal.showToast('新密码必须包含至少6个字符、包含字母和数字')
- return; // 终止提交
- }
- // 通过校验后,提示提交成功
- const params = {
- staffId: userStore.user.useId,
- oldpassword: oldPassword.value,
- newpassword: newPassword.value,
- }
- changePWD(params).then(res => {
- $modal.showToast(res.returnMsg);
- if ("1" == res.returnCode) { //修改成功
- userStore.LogOut().then(() => {
- $tab.reLaunch('/pages/login')
- })
- }
- })
- }
- // 校验密码强度
- function validatePassword(password) {
- // 密码至少有6个字符,包含字母和数字
- const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/;
- return passwordRegex.test(password);
- }
- // 切换旧密码可见性
- function changePassword1() {
- showPassword1.value = !showPassword1.value;
- }
- // 切换新密码可见性
- function changePassword2() {
- showPassword2.value = !showPassword2.value;
- }
- // 切换确认密码可见性
- function changePassword3() {
- showPassword3.value = !showPassword3.value;
- }
- </script>
- <style lang="scss" scoped>
- .container{
- padding-top: 1rem;
- .input-group-header{
- margin-left: 1rem;
- }
- .uni-input-wrapper {
- display: flex;
- align-items: center;
- margin: 1rem;
- background-color: #ffffff;
- .uni-icon {
- margin: 20rpx;
- }
- }
-
- .submitBtn {
- background-color: #007aff;
- color: white;
- width: 90%;
- margin-top: 2rem;
- }
- }
- .uni-eye-active {
- color: #007aff;
- }
-
-
- </style>
|