增加 重置密码的功能。
This commit is contained in:
parent
c4e997954c
commit
d528cfd6bd
@ -66,9 +66,14 @@
|
||||
{{ record.points || 0 }}
|
||||
</template>
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-button type="link" @click="handleEditRoles(record)">
|
||||
修改角色
|
||||
</a-button>
|
||||
<a-space>
|
||||
<a-button type="link" @click="handleEditRoles(record)">
|
||||
修改角色
|
||||
</a-button>
|
||||
<a-button type="link" @click="handleResetPassword(record)">
|
||||
重置密码
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
@ -97,6 +102,29 @@
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 添加密码重置结果模态框 -->
|
||||
<a-modal
|
||||
v-model:visible="passwordModalVisible"
|
||||
title="重置密码结果"
|
||||
>
|
||||
<p>密码重置成功!新密码为:</p>
|
||||
<div class="password-display">
|
||||
<a-input ref="passwordInput" v-model:value="newPassword" readonly />
|
||||
</div>
|
||||
<p class="password-tip">请及时保存并告知用户</p>
|
||||
|
||||
<template #footer>
|
||||
<a-space>
|
||||
<a-button type="primary" @click="handleCopyPassword">
|
||||
复制密码
|
||||
</a-button>
|
||||
<a-button @click="handleClosePasswordModal">
|
||||
关闭
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-modal>
|
||||
</page-container>
|
||||
</template>
|
||||
|
||||
@ -323,6 +351,64 @@ export default defineComponent({
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 密码重置相关状态
|
||||
const passwordModalVisible = ref(false)
|
||||
const newPassword = ref('')
|
||||
const passwordInput = ref(null)
|
||||
|
||||
// 生成随机密码
|
||||
const generatePassword = () => {
|
||||
const chars = '0123456789abcdefghijklmnopqrstuvwxyz'
|
||||
let password = ''
|
||||
for (let i = 0; i < 8; i++) {
|
||||
password += chars.charAt(Math.floor(Math.random() * chars.length))
|
||||
}
|
||||
return password
|
||||
}
|
||||
|
||||
// 处理重置密码
|
||||
const handleResetPassword = (record) => {
|
||||
Modal.confirm({
|
||||
title: '重置密码',
|
||||
content: `确定要重置用户 ${record.username || record.phone} 的密码吗?`,
|
||||
async onOk() {
|
||||
try {
|
||||
const password = generatePassword()
|
||||
await request.post('/api/user/reset-password', {
|
||||
user_id: record.userid,
|
||||
new_password: password
|
||||
})
|
||||
|
||||
newPassword.value = password
|
||||
passwordModalVisible.value = true
|
||||
message.success('密码重置成功')
|
||||
} catch (error) {
|
||||
console.error('重置密码失败:', error)
|
||||
message.error('重置密码失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 复制密码
|
||||
const handleCopyPassword = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(newPassword.value)
|
||||
message.success('密码已复制到剪贴板')
|
||||
} catch (err) {
|
||||
// 降级处理:如果剪贴板API不可用,使用输入框选择
|
||||
passwordInput.value.select()
|
||||
document.execCommand('copy')
|
||||
message.success('密码已复制到剪贴板')
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭密码模态框
|
||||
const handleClosePasswordModal = () => {
|
||||
passwordModalVisible.value = false
|
||||
newPassword.value = ''
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
})
|
||||
@ -346,7 +432,13 @@ export default defineComponent({
|
||||
filterForm,
|
||||
handleFilterChange,
|
||||
handleSearch,
|
||||
handleReset
|
||||
handleReset,
|
||||
passwordModalVisible,
|
||||
newPassword,
|
||||
passwordInput,
|
||||
handleResetPassword,
|
||||
handleCopyPassword,
|
||||
handleClosePasswordModal
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -405,4 +497,26 @@ export default defineComponent({
|
||||
:deep(.ant-form-item:last-child) {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.password-display {
|
||||
margin: 16px 0;
|
||||
background: #f5f5f5;
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
color: #ff4d4f;
|
||||
margin-top: 8px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
:deep(.ant-input[readonly]) {
|
||||
background-color: #fff;
|
||||
cursor: text;
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
font-family: monospace;
|
||||
font-size: 16px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user