daikins/.svn/pristine/c4/c466962e8a0c7d553f3a7b6bf8d...

140 lines
4.4 KiB
Plaintext

<!-- 外部情报 > 情报详情 -->
<script setup lang="ts">
import { updatePwd } from '@/api/daikin/base'
import { NForm, NFormItem, NInput, NButton } from 'naive-ui'
import { useDate } from '@/views/home/hooks/useDate'
import { message } from '@/utils/message'
const { push } = useRouter()
const route = useRoute()
const { day, week } = useDate()
const formValue = ref({
newPassword: '',
oldPassword: ''
})
console.log(route, route.path)
async function submitSave() {
let formdata = new FormData();
const { newPassword, oldPassword } = formValue.value
console.log(formValue.value, newPassword, oldPassword)
if (!newPassword) {
message.error('新密码不能为空')
return
}
if (!oldPassword) {
message.error('旧密码不能为空')
return
}
if (!isStrongPassword(newPassword)) {
message.error('新密码必须为8位及以上,包含大写字母、小写字母、数字、特殊字符中至少3种组合')
return
}
formdata.append("oldPassword", oldPassword)
formdata.append("newPassword", newPassword)
const { code, msg } = await updatePwd(formdata, { headers: { 'Content-Type': 'application/form-data' } })
if (code === 200) {
message.success("修改成功 请重新登录")
push({ name: 'Entry' })
}
else message.error(msg)
}
function isStrongPassword(password) {
// 至少包含8个字符
if (password.length < 8) {
return false;
}
// const tag = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*()_+{}\[\]:;<>,.?~\\-]).{8,20)$/.test(password);
// 至少包含大写字母、小写字母、数字、特殊字符中的三种组合
const hasUpperCase = /[A-Z]/.test(password);
const hasLowerCase = /[a-z]/.test(password);
const hasDigit = /[0-9]/.test(password);
const hasSpecialChar = /[!@#$%^&*()_+{}\[\]:;<>,.?~\\-]/.test(password);
const combinations = [hasUpperCase, hasLowerCase, hasDigit, hasSpecialChar];
const validCombinations = combinations.filter((value) => value);
return validCombinations.length >= 3;
}
</script>
<template>
<div class="page">
<div class="back" @click="push({ name: 'external' })">返回首页</div>
<div class="topt ml30px">
<div class="font-600 flex items-end mt30px">
<div class="text-36px">密码修改</div>
<div class="text-18px ml40px mr25px">{{ day }}</div>
<div class="text-18px">{{ week }}</div>
</div>
</div>
<div class="page-main">
<n-form :label-width="900" :model="formValue" size="medium" require-mark-placement="left">
<n-form-item label="旧密码:" path="oldPassword" class="w300px">
<n-input v-model:value="formValue.oldPassword" placeholder="" type="password" />
</n-form-item>
<n-form-item label="新密码:" path="newPassword" class="w300px">
<n-input v-model:value="formValue.newPassword" placeholder="" type="password" />
</n-form-item>
<span class="text-#000">新密码必须为8位及以上,包含大写字母、小写字母、数字、特殊字符中至少3种组合</span>
<br>
<n-button attr-type="button" @click="submitSave"
style="background-color: #3870E5; border-radius: 5px; color: #fff;margin-left: 10px; padding: 0 20px;margin-top: 30px;">
确认修改
</n-button>
</n-form>
</div>
</div>
</template>
<style scoped lang="less">
.topt {
position: absolute;
top: 50px;
}
.back {
position: absolute;
// width: 300px;
height: 50px;
top: 25px;
left: 25px;
color: #fff;
// z-index: 500;
font-size: 25px;
font-weight: bold;
text-align: center;
justify-content: center;
}
.page {
width: 100%;
height: 100%;
font-family: 'PingFang SC';
user-select: none;
background-position: 0 0;
background-repeat: no-repeat;
background-size: cover;
color: #fff;
line-height: 1;
.page-main {
width: 90%;
height: 834px;
background-color: #fff;
position: absolute;
top: 150px;
left: 4%;
border-radius: 50px;
padding: 50px;
}
}
</style>