2026-07-30 17:59:43 +08:00
|
|
|
<script setup lang="ts">
|
2026-08-04 13:32:08 +08:00
|
|
|
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
2026-08-01 12:17:33 +08:00
|
|
|
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
2026-08-10 16:24:54 +08:00
|
|
|
import { Pencil, Plus, Power } from '@lucide/vue'
|
2026-07-31 15:34:35 +08:00
|
|
|
import {
|
2026-08-03 14:58:17 +08:00
|
|
|
changePlatformManagedUserStatus,
|
|
|
|
|
createPlatformManagedUser,
|
|
|
|
|
getPlatformUserOptions,
|
|
|
|
|
listPlatformManagedUsers,
|
|
|
|
|
resetPlatformManagedUserPassword,
|
|
|
|
|
updatePlatformManagedUser,
|
|
|
|
|
type PlatformManagedUser,
|
|
|
|
|
type PlatformUserOptions,
|
2026-08-03 18:49:18 +08:00
|
|
|
} from '@/modules/iam/api/platformIam'
|
|
|
|
|
import { getApiErrorDetails, getApiErrorMessage, type ApiErrorDetails } from '@/shared/api/http'
|
|
|
|
|
import ApiErrorMeta from '@/shared/components/ApiErrorMeta.vue'
|
|
|
|
|
import StatusBadge from '@/shared/components/StatusBadge.vue'
|
|
|
|
|
import DataTable, { type DataTableColumn } from '@/shared/components/DataTable.vue'
|
2026-08-03 19:05:40 +08:00
|
|
|
import QueryToolbar, { type QueryField, type QueryModel } from '@/shared/components/QueryToolbar.vue'
|
2026-08-10 15:36:53 +08:00
|
|
|
import AdminPage from '@/shared/components/AdminPage.vue'
|
|
|
|
|
import AppDialog from '@/shared/components/AppDialog.vue'
|
|
|
|
|
import FormSection from '@/shared/components/FormSection.vue'
|
|
|
|
|
import ListPageLayout from '@/shared/components/ListPageLayout.vue'
|
|
|
|
|
import LoadErrorState from '@/shared/components/LoadErrorState.vue'
|
2026-08-03 18:49:18 +08:00
|
|
|
import { useUnsavedWorkRegistration } from '@/core/unsaved-work/useUnsavedWorkRegistration'
|
|
|
|
|
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
|
|
|
|
import { useAuthStore } from '@/core/auth/auth'
|
2026-07-30 17:59:43 +08:00
|
|
|
|
|
|
|
|
const access = useAccessPreviewStore()
|
2026-08-01 12:17:33 +08:00
|
|
|
const auth = useAuthStore()
|
2026-08-03 14:58:17 +08:00
|
|
|
const users = ref<PlatformManagedUser[]>([])
|
|
|
|
|
const options = ref<PlatformUserOptions>({ tenants: [], roles: [] })
|
2026-07-31 15:34:35 +08:00
|
|
|
const loading = ref(false)
|
|
|
|
|
const saving = ref(false)
|
|
|
|
|
const loadError = ref<ApiErrorDetails | null>(null)
|
|
|
|
|
const editorOpen = ref(false)
|
2026-08-01 12:17:33 +08:00
|
|
|
const formRef = ref<FormInstance>()
|
2026-08-03 14:58:17 +08:00
|
|
|
const editingUser = ref<PlatformManagedUser | null>(null)
|
2026-08-01 12:17:33 +08:00
|
|
|
const rowActionId = ref('')
|
2026-08-04 13:32:08 +08:00
|
|
|
let loadRequestId = 0
|
2026-07-30 17:59:43 +08:00
|
|
|
const page = ref(1)
|
2026-08-01 12:17:33 +08:00
|
|
|
const pageSize = ref(10)
|
2026-08-04 13:32:08 +08:00
|
|
|
const total = ref(0)
|
|
|
|
|
type UserFilters = QueryModel & { keyword: string; status: string }
|
|
|
|
|
const filters = ref<UserFilters>({ keyword: '', status: '' })
|
2026-08-03 19:05:40 +08:00
|
|
|
const appliedFilters = ref<UserFilters>({ ...filters.value })
|
|
|
|
|
const queryFields = computed<QueryField[]>(() => [
|
|
|
|
|
{
|
|
|
|
|
key: 'keyword',
|
|
|
|
|
type: 'input',
|
2026-08-06 19:03:13 +08:00
|
|
|
label: '用户关键词',
|
2026-08-04 13:32:08 +08:00
|
|
|
placeholder: '姓名、手机号、邮箱或员工编号',
|
2026-08-03 19:05:40 +08:00
|
|
|
props: { maxlength: 128, 'aria-label': '用户关键词' },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'status',
|
|
|
|
|
type: 'select',
|
2026-08-06 19:03:13 +08:00
|
|
|
label: '状态',
|
2026-08-03 19:05:40 +08:00
|
|
|
placeholder: '全部状态',
|
|
|
|
|
props: { 'aria-label': '用户状态' },
|
|
|
|
|
options: [
|
|
|
|
|
{ label: '正常', value: 'ACTIVE' },
|
|
|
|
|
{ label: '禁用', value: 'DISABLED' },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
])
|
2026-08-03 14:58:17 +08:00
|
|
|
|
|
|
|
|
const emptyForm = () => ({
|
|
|
|
|
username: '',
|
|
|
|
|
displayName: '',
|
|
|
|
|
phone: '',
|
|
|
|
|
email: '',
|
2026-08-04 13:32:08 +08:00
|
|
|
tenantId: '0',
|
2026-08-03 14:58:17 +08:00
|
|
|
roleIds: [] as string[],
|
|
|
|
|
password: '',
|
|
|
|
|
confirmPassword: '',
|
|
|
|
|
status: 'ACTIVE' as 'ACTIVE' | 'DISABLED',
|
|
|
|
|
resetPassword: false,
|
|
|
|
|
})
|
2026-07-30 17:59:43 +08:00
|
|
|
const form = reactive(emptyForm())
|
2026-08-03 14:58:17 +08:00
|
|
|
|
|
|
|
|
const canCreate = computed(() => access.can('platform:user:create') && access.can('platform:user:grant-role'))
|
|
|
|
|
const canEdit = computed(() => access.can('platform:user:edit'))
|
|
|
|
|
const canGrantRoles = computed(() => access.can('platform:user:grant-role'))
|
|
|
|
|
const canChangeStatus = computed(() => access.can('platform:user:status'))
|
|
|
|
|
const canResetPassword = computed(() => access.can('platform:user:reset-password'))
|
|
|
|
|
const editorLabel = computed(() => editingUser.value ? `编辑用户 - ${editingUser.value.displayName}` : '新增用户')
|
|
|
|
|
|
|
|
|
|
useUnsavedWorkRegistration({
|
|
|
|
|
key: 'platform-user-editor',
|
2026-08-01 12:17:33 +08:00
|
|
|
label: editorLabel,
|
2026-07-30 17:59:43 +08:00
|
|
|
isOpen: editorOpen,
|
|
|
|
|
model: form,
|
2026-08-03 14:58:17 +08:00
|
|
|
requiredPermission: computed(() => editingUser.value ? 'platform:user:edit' : 'platform:user:create'),
|
2026-07-30 17:59:43 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-03 14:58:17 +08:00
|
|
|
const availableRoles = computed(() => options.value.roles.filter((role) =>
|
2026-08-04 13:32:08 +08:00
|
|
|
String(role.tenantId) === '0'
|
2026-08-03 14:58:17 +08:00
|
|
|
&& (role.status === 'ACTIVE' || form.roleIds.includes(String(role.id))),
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
const formRules = computed<FormRules>(() => ({
|
|
|
|
|
username: editingUser.value ? [] : [
|
|
|
|
|
{ required: true, whitespace: true, message: '请输入用户名', trigger: 'blur' },
|
|
|
|
|
{ pattern: /^[A-Za-z0-9_.@-]{4,64}$/, message: '用户名为 4-64 位字母、数字或 _ . @ -', trigger: 'blur' },
|
|
|
|
|
],
|
|
|
|
|
displayName: editingUser.value && !canEdit.value ? [] : [{ required: true, whitespace: true, message: '请输入姓名', trigger: 'blur' }],
|
|
|
|
|
phone: editingUser.value && !canEdit.value ? [] : [
|
|
|
|
|
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
|
|
|
|
{ pattern: /^1\d{10}$/, message: '请输入正确的 11 位手机号', trigger: 'blur' },
|
|
|
|
|
],
|
|
|
|
|
email: editingUser.value && !canEdit.value ? [] : [{ type: 'email', message: '请输入有效的邮箱地址', trigger: 'blur' }],
|
|
|
|
|
roleIds: editingUser.value && !canEdit.value ? [] : [{ type: 'array', required: true, min: 1, message: '请选择角色', trigger: 'change' }],
|
|
|
|
|
password: editingUser.value && !form.resetPassword ? [] : [
|
|
|
|
|
{ required: true, message: '请输入密码', trigger: 'blur' },
|
|
|
|
|
{ pattern: /^(?=.*[A-Za-z])(?=.*\d).{8,64}$/, message: '密码为 8-64 位,且必须包含字母和数字', trigger: 'blur' },
|
|
|
|
|
],
|
|
|
|
|
confirmPassword: editingUser.value && !form.resetPassword ? [] : [
|
|
|
|
|
{ required: true, message: '请再次输入密码', trigger: 'blur' },
|
|
|
|
|
{ validator: (_rule, value, callback) => value === form.password ? callback() : callback(new Error('两次输入的密码不一致')), trigger: 'blur' },
|
|
|
|
|
],
|
2026-07-30 17:59:43 +08:00
|
|
|
}))
|
2026-08-03 14:58:17 +08:00
|
|
|
|
2026-08-01 12:17:33 +08:00
|
|
|
const userColumns: DataTableColumn[] = [
|
2026-08-03 14:58:17 +08:00
|
|
|
{ key: 'actions', label: '操作', width: 170, fixed: 'left', slotName: 'actions' },
|
2026-08-06 19:03:13 +08:00
|
|
|
{ key: 'username', prop: 'username', label: '用户名', minWidth: 145 },
|
|
|
|
|
{ key: 'displayName', prop: 'displayName', label: '姓名', minWidth: 130 },
|
2026-08-03 14:58:17 +08:00
|
|
|
{ key: 'roles', label: '角色', minWidth: 180, slotName: 'roles' },
|
2026-08-01 12:17:33 +08:00
|
|
|
{ key: 'status', label: '状态', width: 100, slotName: 'status' },
|
2026-08-03 14:58:17 +08:00
|
|
|
{ key: 'lastLoginAt', label: '最后登录', minWidth: 170, slotName: 'lastLoginAt' },
|
2026-08-01 12:17:33 +08:00
|
|
|
]
|
2026-07-30 17:59:43 +08:00
|
|
|
|
2026-08-04 13:32:08 +08:00
|
|
|
function userQuery() {
|
|
|
|
|
return {
|
|
|
|
|
page: page.value,
|
|
|
|
|
size: pageSize.value,
|
|
|
|
|
...(appliedFilters.value.keyword.trim() ? { keyword: appliedFilters.value.keyword.trim() } : {}),
|
|
|
|
|
...(appliedFilters.value.status ? { status: appliedFilters.value.status as PlatformManagedUser['status'] } : {}),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-31 15:34:35 +08:00
|
|
|
async function loadUsers() {
|
2026-08-04 13:32:08 +08:00
|
|
|
const requestId = ++loadRequestId
|
2026-07-31 15:34:35 +08:00
|
|
|
loading.value = true
|
|
|
|
|
loadError.value = null
|
|
|
|
|
try {
|
2026-08-04 13:32:08 +08:00
|
|
|
const result = await listPlatformManagedUsers(userQuery())
|
|
|
|
|
if (requestId !== loadRequestId) return
|
|
|
|
|
users.value = result.records
|
|
|
|
|
total.value = result.total
|
2026-07-31 15:34:35 +08:00
|
|
|
} catch (error) {
|
2026-08-04 13:32:08 +08:00
|
|
|
if (requestId !== loadRequestId) return
|
2026-08-03 14:58:17 +08:00
|
|
|
users.value = []
|
2026-08-04 13:32:08 +08:00
|
|
|
total.value = 0
|
2026-08-03 14:58:17 +08:00
|
|
|
loadError.value = getApiErrorDetails(error, '用户列表加载失败,请稍后重试')
|
2026-07-31 15:34:35 +08:00
|
|
|
} finally {
|
2026-08-04 13:32:08 +08:00
|
|
|
if (requestId === loadRequestId) loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadInitialData() {
|
|
|
|
|
const requestId = ++loadRequestId
|
|
|
|
|
loading.value = true
|
|
|
|
|
loadError.value = null
|
|
|
|
|
try {
|
|
|
|
|
const [result, optionRecords] = await Promise.all([
|
|
|
|
|
listPlatformManagedUsers(userQuery()),
|
|
|
|
|
getPlatformUserOptions(),
|
|
|
|
|
])
|
|
|
|
|
options.value = {
|
|
|
|
|
tenants: optionRecords.tenants.filter((tenant) => String(tenant.id) === '0'),
|
|
|
|
|
roles: optionRecords.roles.filter((role) => String(role.tenantId) === '0'),
|
|
|
|
|
}
|
|
|
|
|
if (requestId !== loadRequestId) return
|
|
|
|
|
users.value = result.records
|
|
|
|
|
total.value = result.total
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (requestId !== loadRequestId) return
|
|
|
|
|
users.value = []
|
|
|
|
|
total.value = 0
|
|
|
|
|
loadError.value = getApiErrorDetails(error, '内部用户列表加载失败,请稍后重试')
|
|
|
|
|
} finally {
|
|
|
|
|
if (requestId === loadRequestId) loading.value = false
|
2026-07-31 15:34:35 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-01 12:17:33 +08:00
|
|
|
function openCreate() {
|
|
|
|
|
Object.assign(form, emptyForm())
|
2026-08-03 14:58:17 +08:00
|
|
|
editingUser.value = null
|
2026-08-01 12:17:33 +08:00
|
|
|
editorOpen.value = true
|
|
|
|
|
nextTick(() => formRef.value?.clearValidate())
|
|
|
|
|
}
|
2026-08-03 14:58:17 +08:00
|
|
|
|
|
|
|
|
function openEdit(row: PlatformManagedUser) {
|
|
|
|
|
editingUser.value = row
|
2026-08-01 12:17:33 +08:00
|
|
|
Object.assign(form, {
|
2026-08-03 14:58:17 +08:00
|
|
|
username: row.username,
|
2026-08-01 12:17:33 +08:00
|
|
|
displayName: row.displayName,
|
|
|
|
|
phone: row.phone ?? '',
|
|
|
|
|
email: row.email ?? '',
|
2026-08-04 13:32:08 +08:00
|
|
|
tenantId: '0',
|
2026-08-01 12:17:33 +08:00
|
|
|
roleIds: row.roleIds.map(String),
|
2026-08-03 14:58:17 +08:00
|
|
|
password: '',
|
|
|
|
|
confirmPassword: '',
|
|
|
|
|
status: row.status,
|
|
|
|
|
resetPassword: false,
|
2026-08-01 12:17:33 +08:00
|
|
|
})
|
|
|
|
|
editorOpen.value = true
|
|
|
|
|
nextTick(() => formRef.value?.clearValidate())
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-03 14:58:17 +08:00
|
|
|
function isCurrentUser(row: PlatformManagedUser | null) {
|
|
|
|
|
if (!row) return false
|
2026-08-01 12:17:33 +08:00
|
|
|
return String(row.userId) === auth.user?.id || String(row.authUserId) === auth.user?.id
|
|
|
|
|
}
|
2026-07-30 17:59:43 +08:00
|
|
|
|
2026-08-03 14:58:17 +08:00
|
|
|
function cannotDisable(row: PlatformManagedUser | null) {
|
|
|
|
|
return Boolean(row?.protectedAccount) || isCurrentUser(row)
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-31 15:34:35 +08:00
|
|
|
async function saveUser() {
|
2026-08-01 12:17:33 +08:00
|
|
|
const valid = await formRef.value?.validate().catch(() => false)
|
|
|
|
|
if (!valid) return
|
2026-07-31 15:34:35 +08:00
|
|
|
saving.value = true
|
2026-07-30 17:59:43 +08:00
|
|
|
try {
|
2026-08-03 14:58:17 +08:00
|
|
|
if (!editingUser.value) {
|
|
|
|
|
await createPlatformManagedUser({
|
|
|
|
|
username: form.username.trim(),
|
2026-08-01 12:17:33 +08:00
|
|
|
displayName: form.displayName.trim(),
|
|
|
|
|
phone: form.phone.trim(),
|
|
|
|
|
email: form.email.trim(),
|
2026-08-04 13:32:08 +08:00
|
|
|
tenantId: '0',
|
2026-08-01 12:17:33 +08:00
|
|
|
roleIds: form.roleIds,
|
2026-08-03 14:58:17 +08:00
|
|
|
password: form.password,
|
|
|
|
|
status: form.status,
|
2026-08-01 12:17:33 +08:00
|
|
|
})
|
2026-08-03 14:58:17 +08:00
|
|
|
ElMessage.success('用户添加成功')
|
2026-08-01 12:17:33 +08:00
|
|
|
} else {
|
2026-08-03 14:58:17 +08:00
|
|
|
const row = editingUser.value
|
|
|
|
|
if (canEdit.value) {
|
|
|
|
|
await updatePlatformManagedUser(row.membershipId, {
|
|
|
|
|
displayName: form.displayName.trim(),
|
|
|
|
|
phone: form.phone.trim(),
|
|
|
|
|
email: form.email.trim(),
|
2026-08-04 13:32:08 +08:00
|
|
|
tenantId: '0',
|
2026-08-03 14:58:17 +08:00
|
|
|
roleIds: form.roleIds,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (canChangeStatus.value && form.status !== row.status) {
|
|
|
|
|
await changePlatformManagedUserStatus(row.membershipId, form.status)
|
|
|
|
|
}
|
|
|
|
|
if (canResetPassword.value && form.resetPassword) {
|
|
|
|
|
await resetPlatformManagedUserPassword(row.membershipId, form.password)
|
|
|
|
|
}
|
|
|
|
|
ElMessage.success(form.resetPassword ? '用户信息已更新,密码已重置' : '用户信息已更新')
|
2026-08-01 12:17:33 +08:00
|
|
|
}
|
2026-07-31 15:34:35 +08:00
|
|
|
editorOpen.value = false
|
|
|
|
|
await loadUsers()
|
|
|
|
|
} catch (error) {
|
2026-08-03 14:58:17 +08:00
|
|
|
ElMessage.error(getApiErrorMessage(error, editingUser.value ? '用户更新失败,请稍后重试' : '用户添加失败,请稍后重试'))
|
2026-07-31 15:34:35 +08:00
|
|
|
} finally {
|
|
|
|
|
saving.value = false
|
2026-07-30 17:59:43 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-03 14:58:17 +08:00
|
|
|
async function toggleStatus(row: PlatformManagedUser) {
|
|
|
|
|
const targetStatus = row.status === 'ACTIVE' ? 'DISABLED' : 'ACTIVE'
|
|
|
|
|
const targetLabel = targetStatus === 'ACTIVE' ? '启用' : '禁用'
|
2026-08-01 12:17:33 +08:00
|
|
|
try {
|
2026-08-03 14:58:17 +08:00
|
|
|
await ElMessageBox.confirm(`确认${targetLabel}用户“${row.displayName}”吗?`, `${targetLabel}用户`, {
|
|
|
|
|
confirmButtonText: `确认${targetLabel}`,
|
2026-08-01 12:17:33 +08:00
|
|
|
cancelButtonText: '取消',
|
2026-08-03 14:58:17 +08:00
|
|
|
type: targetStatus === 'DISABLED' ? 'warning' : 'info',
|
2026-08-01 12:17:33 +08:00
|
|
|
})
|
|
|
|
|
rowActionId.value = String(row.membershipId)
|
2026-08-03 14:58:17 +08:00
|
|
|
const updated = await changePlatformManagedUserStatus(row.membershipId, targetStatus)
|
|
|
|
|
Object.assign(row, updated)
|
|
|
|
|
ElMessage.success(`用户已${targetLabel}`)
|
2026-08-01 12:17:33 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
if (error === 'cancel' || error === 'close') return
|
2026-08-03 14:58:17 +08:00
|
|
|
ElMessage.error(getApiErrorMessage(error, `用户${targetLabel}失败,请稍后重试`))
|
2026-08-01 12:17:33 +08:00
|
|
|
} finally {
|
|
|
|
|
rowActionId.value = ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-03 14:58:17 +08:00
|
|
|
function formatLogin(value: string | null) {
|
|
|
|
|
if (!value) return '—'
|
|
|
|
|
return value.replace('T', ' ').slice(0, 16)
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-03 19:05:40 +08:00
|
|
|
function applyFilters() {
|
|
|
|
|
appliedFilters.value = { ...filters.value }
|
2026-08-04 13:32:08 +08:00
|
|
|
if (page.value === 1) void loadUsers()
|
|
|
|
|
else page.value = 1
|
2026-08-01 12:17:33 +08:00
|
|
|
}
|
|
|
|
|
|
2026-08-04 13:32:08 +08:00
|
|
|
watch([page, pageSize], () => void loadUsers())
|
|
|
|
|
onMounted(loadInitialData)
|
2026-07-30 17:59:43 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-08-10 15:36:53 +08:00
|
|
|
<AdminPage as="div">
|
|
|
|
|
<ListPageLayout aria-label="内部用户管理">
|
|
|
|
|
<template #toolbar>
|
|
|
|
|
<QueryToolbar
|
|
|
|
|
v-model="filters"
|
|
|
|
|
class="surface-panel"
|
|
|
|
|
ariaLabel="用户筛选"
|
|
|
|
|
:fields="queryFields"
|
|
|
|
|
preference-key="internal-users-query"
|
|
|
|
|
@search="applyFilters"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="loadError" #state>
|
|
|
|
|
<LoadErrorState title="内部用户列表暂时无法加载" :message="loadError.message" :loading="loading" @retry="loadInitialData">
|
|
|
|
|
<template #details><ApiErrorMeta :details="loadError" /></template>
|
|
|
|
|
</LoadErrorState>
|
2026-08-03 14:58:17 +08:00
|
|
|
</template>
|
|
|
|
|
|
2026-08-10 16:24:54 +08:00
|
|
|
<section v-if="!loadError" class="surface-panel table-panel" :aria-busy="loading">
|
2026-08-06 19:03:13 +08:00
|
|
|
<DataTable v-model:page="page" v-model:page-size="pageSize" :data="users" :columns="userColumns" preference-key="internal-users-table"
|
2026-08-04 13:32:08 +08:00
|
|
|
:loading="loading" :total="total" aria-label="内部用户列表" row-key="membershipId" empty-text="没有符合筛选条件的内部用户">
|
2026-08-06 20:14:56 +08:00
|
|
|
<template #toolbar-actions><el-button v-if="canCreate" type="primary" @click="openCreate"><Plus :size="16" />新增用户</el-button></template>
|
2026-08-03 14:58:17 +08:00
|
|
|
<template #actions="{ row }">
|
|
|
|
|
<div class="table-actions">
|
2026-08-12 17:45:49 +08:00
|
|
|
<el-button v-if="canEdit || canChangeStatus || canResetPassword" size="small" plain type="primary" @click="openEdit(row as PlatformManagedUser)">
|
2026-08-03 14:58:17 +08:00
|
|
|
<Pencil :size="15" />编辑
|
|
|
|
|
</el-button>
|
2026-08-12 17:45:49 +08:00
|
|
|
<el-button v-if="canChangeStatus" size="small" plain :type="(row as PlatformManagedUser).status === 'ACTIVE' ? 'danger' : 'success'"
|
2026-08-03 14:58:17 +08:00
|
|
|
:loading="rowActionId === String((row as PlatformManagedUser).membershipId)"
|
|
|
|
|
:disabled="cannotDisable(row as PlatformManagedUser)"
|
|
|
|
|
:title="(row as PlatformManagedUser).protectedAccount ? '系统管理员不能被禁用' : isCurrentUser(row as PlatformManagedUser) ? '不能禁用当前登录用户' : undefined"
|
|
|
|
|
@click="toggleStatus(row as PlatformManagedUser)">
|
2026-08-10 16:24:54 +08:00
|
|
|
<Power :size="15" />{{ (row as PlatformManagedUser).status === 'ACTIVE' ? '禁用' : '启用' }}
|
2026-08-03 14:58:17 +08:00
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template #roles="{ row }">
|
|
|
|
|
<div class="tag-list">
|
|
|
|
|
<el-tag v-for="role in (row as PlatformManagedUser).roleNames" :key="role" effect="plain" size="small">{{ role }}</el-tag>
|
|
|
|
|
<span v-if="!(row as PlatformManagedUser).roleNames.length" class="secondary-text">未分配</span>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template #status="{ row }"><StatusBadge :status="(row as PlatformManagedUser).status === 'ACTIVE' ? '正常' : '禁用'" /></template>
|
|
|
|
|
<template #lastLoginAt="{ row }">{{ formatLogin((row as PlatformManagedUser).lastLoginAt) }}</template>
|
2026-08-10 16:24:54 +08:00
|
|
|
<template #pagination-left="{ total: tableTotal }"><span>共 {{ tableTotal }} 条</span></template>
|
2026-08-01 12:17:33 +08:00
|
|
|
</DataTable>
|
2026-08-10 15:36:53 +08:00
|
|
|
</section>
|
|
|
|
|
</ListPageLayout>
|
2026-08-03 14:58:17 +08:00
|
|
|
|
2026-08-12 17:29:35 +08:00
|
|
|
<AppDialog v-model="editorOpen" :title="editorLabel" width="min(650px, calc(100vw - 28px))" class="internal-user-editor-dialog" destroy-on-close :confirm-loading="saving" :confirm-text="editingUser ? '保存修改' : '确认添加'" @confirm="saveUser">
|
2026-08-03 14:58:17 +08:00
|
|
|
<el-form ref="formRef" :model="form" :rules="formRules" label-position="top">
|
2026-08-10 15:36:53 +08:00
|
|
|
<FormSection title="用户资料" description="维护登录身份、联系方式与平台角色。">
|
|
|
|
|
<div class="form-grid two-cols">
|
2026-08-03 14:58:17 +08:00
|
|
|
<el-form-item label="用户名" prop="username" required>
|
|
|
|
|
<el-input v-model="form.username" :disabled="Boolean(editingUser)" placeholder="登录用户名" maxlength="64" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="姓名" prop="displayName" required>
|
|
|
|
|
<el-input v-model="form.displayName" :disabled="Boolean(editingUser) && !canEdit" placeholder="真实姓名" maxlength="64" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="手机号" prop="phone" required>
|
|
|
|
|
<el-input v-model="form.phone" :disabled="Boolean(editingUser) && !canEdit" placeholder="手机号码" inputmode="tel" maxlength="11" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="邮箱" prop="email">
|
|
|
|
|
<el-input v-model="form.email" :disabled="Boolean(editingUser) && !canEdit" placeholder="邮箱地址" inputmode="email" maxlength="128" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="角色" prop="roleIds" required>
|
|
|
|
|
<el-select v-model="form.roleIds" multiple collapse-tags collapse-tags-tooltip
|
|
|
|
|
:disabled="Boolean(editingUser) && (!canEdit || !canGrantRoles || editingUser?.protectedAccount)" placeholder="选择角色">
|
|
|
|
|
<el-option v-for="role in availableRoles" :key="role.id" :label="role.name" :value="String(role.id)" :disabled="role.status !== 'ACTIVE'" />
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="状态" prop="status">
|
|
|
|
|
<el-select v-model="form.status" :disabled="Boolean(editingUser) && (!canChangeStatus || cannotDisable(editingUser))">
|
|
|
|
|
<el-option label="正常" value="ACTIVE" />
|
|
|
|
|
<el-option label="禁用" value="DISABLED" />
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item v-if="editingUser" label="最后登录">
|
|
|
|
|
<el-input :model-value="formatLogin(editingUser.lastLoginAt)" disabled />
|
|
|
|
|
</el-form-item>
|
2026-08-10 15:36:53 +08:00
|
|
|
</div>
|
|
|
|
|
</FormSection>
|
2026-08-03 14:58:17 +08:00
|
|
|
|
2026-08-10 15:36:53 +08:00
|
|
|
<FormSection v-if="!editingUser || canResetPassword" title="登录密码" description="密码为 8-64 位,并同时包含字母和数字。">
|
2026-08-03 14:58:17 +08:00
|
|
|
<el-checkbox v-if="editingUser" v-model="form.resetPassword">同时重置密码</el-checkbox>
|
|
|
|
|
<div v-if="!editingUser || form.resetPassword" class="form-grid two-cols password-fields">
|
|
|
|
|
<el-form-item :label="editingUser ? '新密码' : '初始密码'" prop="password" required>
|
|
|
|
|
<el-input v-model="form.password" type="password" show-password autocomplete="new-password" placeholder="8-64 位,包含字母和数字" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="确认密码" prop="confirmPassword" required>
|
|
|
|
|
<el-input v-model="form.confirmPassword" type="password" show-password autocomplete="new-password" placeholder="再次输入密码" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</div>
|
2026-08-10 15:36:53 +08:00
|
|
|
</FormSection>
|
2026-07-30 17:59:43 +08:00
|
|
|
</el-form>
|
2026-08-10 15:36:53 +08:00
|
|
|
</AppDialog>
|
|
|
|
|
</AdminPage>
|
2026-07-30 17:59:43 +08:00
|
|
|
</template>
|
2026-08-03 14:58:17 +08:00
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.password-fields { margin-top: 16px; }
|
2026-08-12 17:29:35 +08:00
|
|
|
:global(.internal-user-editor-dialog) { max-height: min(760px, calc(100vh - 32px)); display: flex; flex-direction: column; }
|
|
|
|
|
:global(.internal-user-editor-dialog .el-dialog__body) { min-height: 0; overflow-y: auto; }
|
|
|
|
|
:global(.internal-user-editor-dialog .el-dialog__footer) { flex: 0 0 auto; }
|
2026-08-03 14:58:17 +08:00
|
|
|
@media (max-width: 720px) {
|
2026-08-03 19:05:40 +08:00
|
|
|
.form-grid.two-cols { grid-template-columns: 1fr; }
|
2026-08-03 14:58:17 +08:00
|
|
|
}
|
|
|
|
|
</style>
|