2026-05-18 12:39:57 +08:00
|
|
|
<script setup lang="ts">
|
2026-05-18 18:41:32 +08:00
|
|
|
import { ref, reactive,onMounted } from 'vue'
|
2026-05-18 12:39:57 +08:00
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
2026-05-19 09:14:37 +08:00
|
|
|
import { verifyAccessPassword,saveDeviceConfig,fetchDeviceConfig } from '@/api/platform'
|
2026-05-18 18:41:32 +08:00
|
|
|
import { ElMessage } from 'element-plus'
|
2026-05-18 12:39:57 +08:00
|
|
|
const formRef = ref<FormInstance>()
|
|
|
|
|
|
|
|
|
|
// 表单数据
|
|
|
|
|
const form = reactive({
|
|
|
|
|
oldPassword: '',
|
|
|
|
|
newPassword: '',
|
|
|
|
|
confirmPassword: ''
|
|
|
|
|
})
|
2026-05-19 09:14:37 +08:00
|
|
|
const deviceConfig: any = ref({})
|
2026-05-18 12:39:57 +08:00
|
|
|
// 校验规则
|
|
|
|
|
const rules: FormRules = {
|
|
|
|
|
oldPassword: [
|
|
|
|
|
{ required: true, message: '请输入原密码', trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
newPassword: [
|
|
|
|
|
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
|
|
|
|
{ min: 6, max: 20, message: '密码长度需在 6~20 位之间', trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
confirmPassword: [
|
|
|
|
|
{ required: true, message: '请再次输入新密码', trigger: 'blur' },
|
|
|
|
|
{
|
|
|
|
|
validator: (rule, value, callback) => {
|
|
|
|
|
if (value !== form.newPassword) {
|
|
|
|
|
callback(new Error('两次输入的密码不一致'))
|
|
|
|
|
} else {
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2026-05-18 18:41:32 +08:00
|
|
|
const isSubmit = ref(false)
|
2026-05-18 12:39:57 +08:00
|
|
|
// 提交保存
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
|
if (!formRef.value) return
|
|
|
|
|
await formRef.value.validate((valid) => {
|
|
|
|
|
if (valid) {
|
2026-05-18 18:41:32 +08:00
|
|
|
if (isSubmit.value) return
|
|
|
|
|
isSubmit.value = true
|
|
|
|
|
verifyAccessPassword(form.oldPassword).then(res => {
|
|
|
|
|
if (res.data) {
|
2026-05-19 09:14:37 +08:00
|
|
|
// ElMessage({
|
|
|
|
|
// type: 'success',
|
|
|
|
|
// message: '原密码验证成功',
|
2026-05-18 18:41:32 +08:00
|
|
|
// })
|
2026-05-19 09:14:37 +08:00
|
|
|
saveDeviceConfig({
|
|
|
|
|
password: form.newPassword,
|
|
|
|
|
hardware_version: deviceConfig.value.hardware_version,
|
|
|
|
|
software_version: deviceConfig.value.software_version,
|
|
|
|
|
net: deviceConfig.value.net,
|
|
|
|
|
uart: deviceConfig.value.uart,
|
|
|
|
|
}).then(res => {
|
|
|
|
|
if (res.data) {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '密码设置成功',
|
|
|
|
|
})
|
|
|
|
|
isSubmit.value = false
|
|
|
|
|
} else {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: 'info',
|
|
|
|
|
message: '密码设置失败',
|
|
|
|
|
})
|
|
|
|
|
isSubmit.value = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-05-18 18:41:32 +08:00
|
|
|
} else {
|
|
|
|
|
ElMessage({
|
2026-05-19 09:14:37 +08:00
|
|
|
type: 'error',
|
2026-05-18 18:41:32 +08:00
|
|
|
message: '原密码验证失败',
|
|
|
|
|
})
|
|
|
|
|
isSubmit.value = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-05-18 12:39:57 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-05-19 09:14:37 +08:00
|
|
|
|
2026-05-18 18:41:32 +08:00
|
|
|
function init() {
|
2026-05-19 09:14:37 +08:00
|
|
|
fetchDeviceConfig().then(res => {
|
|
|
|
|
if (res) {
|
|
|
|
|
deviceConfig.value = res
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-05-18 18:41:32 +08:00
|
|
|
}
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
init()
|
|
|
|
|
})
|
2026-05-18 12:39:57 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="password-container">
|
|
|
|
|
<!-- 标题 -->
|
|
|
|
|
<div class="password-container-content">
|
|
|
|
|
<div class="title">
|
|
|
|
|
<span class="title-line"></span>
|
|
|
|
|
密码设置
|
|
|
|
|
</div>
|
|
|
|
|
<!-- 表单 -->
|
2026-05-19 09:14:37 +08:00
|
|
|
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px" class="password-form">
|
2026-05-18 18:41:32 +08:00
|
|
|
<el-form-item label="原密码" prop="oldPassword">
|
2026-05-18 12:39:57 +08:00
|
|
|
<el-input v-model="form.oldPassword" type="password" placeholder="请输入原密码" show-password />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
2026-05-18 18:41:32 +08:00
|
|
|
<el-form-item label="新密码" prop="newPassword">
|
2026-05-18 12:39:57 +08:00
|
|
|
<el-input v-model="form.newPassword" type="password" placeholder="请输入新密码" show-password />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
2026-05-18 18:41:32 +08:00
|
|
|
<el-form-item label="确认新密码" prop="confirmPassword">
|
2026-05-18 12:39:57 +08:00
|
|
|
<el-input v-model="form.confirmPassword" type="password" placeholder="请再次输入新密码" show-password />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 保存按钮 -->
|
|
|
|
|
<el-button type="primary" style="background-color: #0099ff;width: 150px;height: 40px;" class="save-btn" @click="handleSubmit">
|
|
|
|
|
保存
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.password-container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
2026-05-19 09:14:37 +08:00
|
|
|
padding: 15px;
|
2026-05-18 12:39:57 +08:00
|
|
|
|
|
|
|
|
.password-container-content {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: calc(100vh - 230px);
|
|
|
|
|
background-color: #ffffff;
|
|
|
|
|
padding: 20px 50px;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
box-shadow: 0px 0px 10px rgba(219, 225, 236, 1);
|
|
|
|
|
}
|
|
|
|
|
.title {
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
color: #303133;
|
|
|
|
|
margin-bottom: 24px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
|
|
.title-line {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
width: 4px;
|
|
|
|
|
height: 14px;
|
|
|
|
|
background-color: #409eff;
|
|
|
|
|
margin-right: 8px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.password-form {
|
|
|
|
|
width: 60%;
|
|
|
|
|
}
|
|
|
|
|
.save-btn {
|
|
|
|
|
margin-top: 30px;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
:deep(.el-form-item--label-right .el-form-item__label) {
|
|
|
|
|
text-align: left;
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
color: #787878;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
:deep(.el-input__inner) {
|
|
|
|
|
color: #363636;
|
|
|
|
|
min-height: 40px;
|
|
|
|
|
}
|
|
|
|
|
:deep(.el-form-item__label) {
|
|
|
|
|
line-height: 40px !important;
|
|
|
|
|
}
|
|
|
|
|
</style>
|