199 lines
7.4 KiB
Vue
199 lines
7.4 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* F006 角色组管理 - W4.16
|
|
*
|
|
* W11 A8: 套 PageHeader/SearchBar 标准化模板
|
|
*
|
|
* 后端: GET /sys/roleGroup/page
|
|
* 字段: id/operationId/name/createDate
|
|
*/
|
|
import { onMounted, ref, reactive } from 'vue'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import { httpGet, httpPost, httpPut, httpDelete } from '@/utils/request'
|
|
import DataTable from '@/components/DataTable/DataTable.vue'
|
|
import PageHeader from '@/components/PageHeader/PageHeader.vue'
|
|
import SearchBar from '@/components/SearchBar/SearchBar.vue'
|
|
|
|
interface RoleGroup {
|
|
id: string
|
|
operationId: string
|
|
name: string
|
|
createDate: string | number
|
|
raw: any
|
|
}
|
|
|
|
const list = ref<RoleGroup[]>([])
|
|
const total = ref(0)
|
|
const loading = ref(false)
|
|
const error = ref<string | null>(null)
|
|
const page = ref(1)
|
|
const limit = ref(10)
|
|
const filters = reactive({ name: '' })
|
|
|
|
const editVisible = ref(false)
|
|
const editMode = ref<'create' | 'update'>('create')
|
|
const editForm = reactive({ id: null as number | null, name: '', operationId: '1' })
|
|
|
|
function fmtDate(ts?: string | number | null) {
|
|
if (!ts) return '--'
|
|
const n = typeof ts === 'string' ? Date.parse(ts) : ts
|
|
if (!n || isNaN(n)) return String(ts)
|
|
const d = new Date(n)
|
|
if (isNaN(d.getTime())) return String(ts)
|
|
const pad = (x: number) => String(x).padStart(2, '0')
|
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
|
}
|
|
|
|
async function load() {
|
|
loading.value = true
|
|
error.value = null
|
|
try {
|
|
const data = await httpGet<{ total: number | string; list: any[] }>('/sys/roleGroup/page', {
|
|
page: page.value,
|
|
limit: limit.value,
|
|
...(filters.name ? { name: filters.name } : {})
|
|
})
|
|
list.value = (data.list || []).map((it: any) => ({
|
|
id: String(it.id),
|
|
operationId: String(it.operationId || '--'),
|
|
name: it.name || '--',
|
|
createDate: it.createDate,
|
|
raw: it
|
|
}))
|
|
total.value = Number(data.total) || 0
|
|
} catch (e: any) {
|
|
error.value = e?.msg || e?.message || '后端接口异常'
|
|
list.value = []
|
|
total.value = 0
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function onSearch() { page.value = 1; load() }
|
|
function onReset() { filters.name = ''; page.value = 1; load() }
|
|
function onPageChange(p: number) { page.value = p; load() }
|
|
function onLimitChange(l: number) { limit.value = l; page.value = 1; load() }
|
|
|
|
function createHandle() {
|
|
editMode.value = 'create'
|
|
editForm.id = null
|
|
editForm.name = ''
|
|
editForm.operationId = '1'
|
|
editVisible.value = true
|
|
}
|
|
|
|
async function editHandle(row: RoleGroup) {
|
|
editMode.value = 'update'
|
|
editForm.id = Number(row.id)
|
|
editForm.name = row.name
|
|
editForm.operationId = row.operationId
|
|
editVisible.value = true
|
|
}
|
|
|
|
async function editConfirm() {
|
|
if (!editForm.name.trim()) { ElMessage.warning('请输入角色组名'); return }
|
|
const payload = { id: editForm.id, name: editForm.name.trim(), operationId: Number(editForm.operationId) || 1 }
|
|
try {
|
|
if (editMode.value === 'create') { await httpPost('/sys/roleGroup', payload); ElMessage.success('新增成功') }
|
|
else { await httpPut('/sys/roleGroup', payload); ElMessage.success('修改成功') }
|
|
editVisible.value = false
|
|
load()
|
|
} catch (e: any) {
|
|
ElMessage.error(e?.msg || e?.message || '操作失败')
|
|
}
|
|
}
|
|
|
|
async function deleteHandle(row: RoleGroup) {
|
|
try { await ElMessageBox.confirm(`确认删除角色组 ${row.name} 吗?`, '删除确认', { type: 'warning' }) } catch { return }
|
|
try { await httpDelete(`/sys/roleGroup/${row.id}`); ElMessage.success('删除成功'); load() }
|
|
catch (e: any) { ElMessage.error(e?.msg || e?.message || '删除失败') }
|
|
}
|
|
|
|
onMounted(load)
|
|
</script>
|
|
|
|
<template>
|
|
<div class="rr-sys-role-group">
|
|
<PageHeader title="角色组管理" :sub="`共 ${total} 个角色组`">
|
|
<el-button @click="onReset" class="rr-btn-secondary">重置</el-button>
|
|
<el-button type="primary" class="rr-btn-primary" @click="createHandle">+ 新增角色组</el-button>
|
|
</PageHeader>
|
|
|
|
<SearchBar
|
|
v-model:filters="filters"
|
|
:fields='[
|
|
{ key: "name", label: "角色组名", type: "text", placeholder: "角色组名" }
|
|
]'
|
|
@search="onSearch"
|
|
@reset="onReset"
|
|
/>
|
|
|
|
<div class="rr-list-card">
|
|
<DataTable
|
|
:columns="[
|
|
{ prop: 'name', label: '角色组名', minWidth: 200 },
|
|
{ prop: 'operationId', label: '运营中心 ID', width: 160 },
|
|
{ prop: 'createDate', label: '创建时间', width: 170, slot: 'createDate' },
|
|
{ label: '操作', width: 180, slot: 'action' }
|
|
]"
|
|
:data="list"
|
|
:loading="loading"
|
|
:total="total"
|
|
:page="page"
|
|
:limit="limit"
|
|
:show-pagination="true" :page-sizes="[10, 20, 50, 100]"
|
|
:error="error"
|
|
empty-text="暂无角色组"
|
|
borderless
|
|
row-key="id"
|
|
@page-change="onPageChange"
|
|
@limit-change="onLimitChange"
|
|
>
|
|
<template #createDate="{ row }"><span class="rr-time">{{ fmtDate(row.createDate) }}</span></template>
|
|
<template #action="{ row }">
|
|
<el-button text type="primary" size="small" @click="editHandle(row)">编辑</el-button>
|
|
<el-button text type="primary" size="small" @click="deleteHandle(row)">删除</el-button>
|
|
</template>
|
|
</DataTable>
|
|
</div>
|
|
|
|
<el-dialog
|
|
v-model="editVisible"
|
|
:title="editMode === 'create' ? '新增角色组' : '编辑角色组'"
|
|
width="480"
|
|
:style="{ borderRadius: '12px', overflow: 'hidden' }"
|
|
align-center
|
|
destroy-on-close
|
|
>
|
|
<el-form label-width="100px" label-position="right">
|
|
<el-form-item label="角色组名" required>
|
|
<el-input v-model="editForm.name" placeholder="请输入角色组名" size="default" maxlength="50" />
|
|
</el-form-item>
|
|
<el-form-item label="运营中心 ID">
|
|
<el-input-number v-model="editForm.operationId" :min="0" controls-position="right" size="default" style="width: 100%" />
|
|
</el-form-item>
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button @click="editVisible = false">取消</el-button>
|
|
<el-button type="primary" @click="editConfirm">{{ editMode === 'create' ? '确认新增' : '确认修改' }}</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.rr-sys-role-group { padding: 16px; }
|
|
.rr-list-card { background: var(--surface); border-radius: 12px; padding: 4px; }
|
|
.rr-time { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: 12px; color: var(--ink-2); }
|
|
.rr-muted { color: var(--ink-3); font-size: 12px; }
|
|
.rr-page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
|
|
.rr-page-titles { display: flex; flex-direction: column; gap: 2px; }
|
|
.rr-page-title { margin: 0; font-size: 20px; font-weight: 700; color: var(--el-text-color-primary); }
|
|
.rr-page-sub { margin: 0; font-size: 12px; color: var(--el-text-color-secondary); }
|
|
.rr-page-actions { display: flex; gap: 8px; }
|
|
.rr-filters-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; padding: 12px 16px; background: var(--el-fill-color-light); border-radius: 8px; }
|
|
.rr-name-input { width: 240px; }
|
|
.rr-list-card { background: var(--el-bg-color); border-radius: 12px; padding: 4px; }
|
|
.rr-time { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: 12px; color: var(--el-text-color-regular); }
|
|
</style> |