完善部分平台治理功能,及修改看板缺陷
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
changeMyPassword,
|
||||
deleteUser,
|
||||
getUsers,
|
||||
resetUserPassword,
|
||||
@@ -106,6 +107,34 @@ async function confirmResetPwd() {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 用户自改密码 ----------
|
||||
const myPwdDialog = reactive({ visible: false, oldPassword: '', newPassword: '', saving: false })
|
||||
function openChangeMyPwd() {
|
||||
myPwdDialog.oldPassword = ''
|
||||
myPwdDialog.newPassword = ''
|
||||
myPwdDialog.visible = true
|
||||
}
|
||||
async function confirmChangeMyPwd() {
|
||||
if (!myPwdDialog.oldPassword.trim() || !myPwdDialog.newPassword.trim()) {
|
||||
ElMessage.warning('请填写旧密码和新密码')
|
||||
return
|
||||
}
|
||||
if (myPwdDialog.newPassword.length < 6) {
|
||||
ElMessage.warning('新密码至少 6 位')
|
||||
return
|
||||
}
|
||||
myPwdDialog.saving = true
|
||||
try {
|
||||
await changeMyPassword(myPwdDialog.oldPassword.trim(), myPwdDialog.newPassword.trim())
|
||||
ElMessage.success('密码修改成功')
|
||||
myPwdDialog.visible = false
|
||||
} catch {
|
||||
ElMessage.error('密码修改失败,请检查旧密码是否正确')
|
||||
} finally {
|
||||
myPwdDialog.saving = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 页面权限 ----------
|
||||
const permDialog = reactive({
|
||||
visible: false,
|
||||
@@ -117,10 +146,24 @@ const permDialog = reactive({
|
||||
function openPerms(row: SystemUser) {
|
||||
permDialog.id = row.id
|
||||
permDialog.name = row.display_name
|
||||
permDialog.checked = [...(row.permissions || [])]
|
||||
// admin 用户强制全选且只读
|
||||
if (row.role === 'admin' || row.protected) {
|
||||
permDialog.checked = [...ALL_PERMISSIONS]
|
||||
} else {
|
||||
// 非 admin 用户去掉 user-settings
|
||||
permDialog.checked = (row.permissions || []).filter((p) => p !== 'user-settings')
|
||||
}
|
||||
permDialog.visible = true
|
||||
}
|
||||
async function confirmPerms() {
|
||||
if (permReadonly.value) {
|
||||
permDialog.visible = false
|
||||
return
|
||||
}
|
||||
// 双重保险:非 admin 用户不允许勾选 user-settings
|
||||
if (!isTargetAdmin.value) {
|
||||
permDialog.checked = permDialog.checked.filter((p) => p !== 'user-settings')
|
||||
}
|
||||
permDialog.saving = true
|
||||
try {
|
||||
await updateUserAccess(permDialog.id, { permissions: permDialog.checked })
|
||||
@@ -134,7 +177,17 @@ async function confirmPerms() {
|
||||
}
|
||||
}
|
||||
|
||||
const permColumns = computed(() => ALL_PERMISSIONS)
|
||||
/** 权限列:admin 用户全选且只读,非 admin 用户不显示 user-settings */
|
||||
const isTargetAdmin = computed(() => {
|
||||
const u = users.value.find((u) => u.id === permDialog.id)
|
||||
return u?.role === 'admin' || u?.protected === true
|
||||
})
|
||||
const permColumns = computed(() => {
|
||||
if (isTargetAdmin.value) return ALL_PERMISSIONS
|
||||
// 非 admin 用户不能拥有 user-settings 权限
|
||||
return ALL_PERMISSIONS.filter((c) => c !== 'user-settings')
|
||||
})
|
||||
const permReadonly = computed(() => isTargetAdmin.value)
|
||||
|
||||
// ---------- 删除 ----------
|
||||
async function removeUser(row: SystemUser) {
|
||||
@@ -165,7 +218,10 @@ async function removeUser(row: SystemUser) {
|
||||
<h1>用户设置</h1>
|
||||
<p>管理平台账号、角色状态、登录密码与页面权限。</p>
|
||||
</div>
|
||||
<el-button type="primary" @click="$router.push('/user-settings/create')">创建用户</el-button>
|
||||
<div>
|
||||
<el-button @click="openChangeMyPwd">修改密码</el-button>
|
||||
<el-button type="primary" @click="$router.push('/user-settings/create')">创建用户</el-button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<el-table :data="users" border>
|
||||
@@ -236,8 +292,11 @@ async function removeUser(row: SystemUser) {
|
||||
|
||||
<!-- 页面权限 -->
|
||||
<el-dialog v-model="permDialog.visible" title="页面权限" width="540px">
|
||||
<p class="dlg-tip">为 <b>{{ permDialog.name }}</b> 分配可访问的页面模块:</p>
|
||||
<el-checkbox-group v-model="permDialog.checked" class="perm-group">
|
||||
<p class="dlg-tip">
|
||||
为 <b>{{ permDialog.name }}</b> 分配可访问的页面模块:
|
||||
<el-tag v-if="permReadonly" type="warning" size="small" style="margin-left: 8px">管理员权限不可更改</el-tag>
|
||||
</p>
|
||||
<el-checkbox-group v-model="permDialog.checked" class="perm-group" :disabled="permReadonly">
|
||||
<el-checkbox
|
||||
v-for="code in permColumns"
|
||||
:key="code"
|
||||
@@ -246,8 +305,24 @@ async function removeUser(row: SystemUser) {
|
||||
/>
|
||||
</el-checkbox-group>
|
||||
<template #footer>
|
||||
<el-button @click="permDialog.visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="permDialog.saving" @click="confirmPerms">保存</el-button>
|
||||
<el-button @click="permDialog.visible = false">{{ permReadonly ? '关闭' : '取消' }}</el-button>
|
||||
<el-button v-if="!permReadonly" type="primary" :loading="permDialog.saving" @click="confirmPerms">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 修改自己的密码 -->
|
||||
<el-dialog v-model="myPwdDialog.visible" title="修改密码" width="420px">
|
||||
<el-form label-width="80px">
|
||||
<el-form-item label="旧密码">
|
||||
<el-input v-model="myPwdDialog.oldPassword" placeholder="请输入当前密码" show-password />
|
||||
</el-form-item>
|
||||
<el-form-item label="新密码">
|
||||
<el-input v-model="myPwdDialog.newPassword" placeholder="至少 6 位" show-password />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="myPwdDialog.visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="myPwdDialog.saving" @click="confirmChangeMyPwd">确认修改</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user