用户原话: 不是让你沿用老vue页面内容了吗, 只是更换成新版本的UI 用户原话: 要能够交付使用, 像原有的vue平台一样使用 整改 (5 个 view 从严重简化变完整版): - OrderListView 240 行: 订单号/合同号/供应商/状态/时间范围 完整搜索, 8 种状态 tab, 操作 (详情/付款/发货/收货/退款/取消/打印), 批量导出, type 自适应 good/service/group - OrderDetailView 582 行: 完整 4-tab (订单信息/商品明细/物流/付款发票), 状态卡 + 操作按钮 (按状态动态显示), 9 种订单状态, 推广信息, 多状态按需渲染 - GoodListView 507 行: 12 列表格 (封面/商品/供应商/3 级分类/品牌/单位/铺货/审核/状态), 4 种状态 tab, 5 种操作 (详情/审核/上下架/改分类/删除), 5 种批量操作, 详情弹窗含 SKU 列表 (编码/原价/现价/秒杀价/拼团价/库存) - ServiceGoodListView 302 行: 同上针对服务商品 - InquiryDetailView 229 行: 询价基本信息 (产品/品牌/规格/数量/收货地址/交货日期/价格有效), 附件下载, 报价列表 (供应商/状态/金额/次数/来源/查看报价) 字段 100% 沿用老 vue (supplierGoodId/contractCode/groupNumber/acceptNum 等), 新增 mock 数据 (3-8 条覆盖各种业务场景), 弹窗/操作/批量/导出 全部走通 (mock 实现) + W3.x C P0-P2 累计 30+ 个 view 文件补 commit (inquiry/openapi/order/sys 等 11+ 模块) router 调整: 9 个 order 路由统一到 OrderListView (type 自动推断) + /supplier/servicegood 路由独立 (避免被 tree-shake)
370 lines
10 KiB
Vue
370 lines
10 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* F006 角色管理 - 套老 vue role.vue 结构 + v1.9 设计规范
|
|
*
|
|
* 后端端点 (SysRoleController):
|
|
* GET /sys/role/page 分页列表
|
|
* GET /sys/role/list 列表(不分页)
|
|
* GET /sys/role/{id} 详情
|
|
* POST /sys/role 新增
|
|
* PUT /sys/role 修改
|
|
* DELETE /sys/role 删除
|
|
*
|
|
* 字段(来自 SysRoleDTO):
|
|
* id / name / remark / operationId / roleGroupId
|
|
* createDate / menuIdList / deptIdList
|
|
*
|
|
* 设计规范:§16 列表页 + §17.7 紧凑弹窗 + §17.8 主题色弹窗 + §17.9 列优化
|
|
*/
|
|
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'
|
|
|
|
interface SysRole {
|
|
id: string
|
|
name: string
|
|
remark?: string | null
|
|
operationId?: string | null
|
|
roleGroupId?: string | null
|
|
createDate: string | number
|
|
menuIdList?: number[] | null
|
|
deptIdList?: number[] | null
|
|
raw: any
|
|
}
|
|
|
|
const list = ref<SysRole[]>([])
|
|
const total = ref(0)
|
|
const loading = ref(false)
|
|
const page = ref(1)
|
|
const limit = ref(10)
|
|
const loadError = ref<string | null>(null)
|
|
|
|
const filters = reactive({
|
|
name: ''
|
|
})
|
|
|
|
const editVisible = ref(false)
|
|
const editMode = ref<'create' | 'update'>('create')
|
|
const editForm = reactive({
|
|
id: null as number | null,
|
|
name: '',
|
|
remark: '',
|
|
operationId: null as number | null,
|
|
roleGroupId: null as number | null
|
|
})
|
|
|
|
function fmtDate(ts?: string | number | null) {
|
|
if (!ts) return '--'
|
|
const n = typeof ts === 'string' ? Date.parse(ts) : ts
|
|
if (!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
|
|
loadError.value = null
|
|
try {
|
|
const data = await httpGet<{ total: number; list: any[] }>('/sys/role/page', {
|
|
page: page.value,
|
|
limit: limit.value,
|
|
...(filters.name ? { name: filters.name } : {})
|
|
})
|
|
list.value = (data.list || []).map((it: any) => ({
|
|
id: String(it.id),
|
|
name: it.name || '--',
|
|
remark: it.remark || '--',
|
|
operationId: it.operationId ? String(it.operationId) : '--',
|
|
roleGroupId: it.roleGroupId ? String(it.roleGroupId) : '--',
|
|
createDate: it.createDate,
|
|
raw: it
|
|
}))
|
|
total.value = data.total || 0
|
|
} catch (e: any) {
|
|
console.error('角色列表加载失败', e)
|
|
list.value = []
|
|
total.value = 0
|
|
loadError.value = e?.msg || e?.message || '后端接口异常(详见 console)'
|
|
} 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.remark = ''
|
|
editForm.operationId = null
|
|
editForm.roleGroupId = null
|
|
editVisible.value = true
|
|
}
|
|
|
|
async function editHandle(row: SysRole) {
|
|
editMode.value = 'update'
|
|
try {
|
|
const data = await httpGet<any>(`/sys/role/${row.id}`)
|
|
editForm.id = Number(row.id)
|
|
editForm.name = data.name || ''
|
|
editForm.remark = data.remark || ''
|
|
editForm.operationId = data.operationId ? Number(data.operationId) : null
|
|
editForm.roleGroupId = data.roleGroupId ? Number(data.roleGroupId) : null
|
|
editVisible.value = true
|
|
} catch (e: any) {
|
|
ElMessage.error(e?.msg || e?.message || '详情加载失败')
|
|
}
|
|
}
|
|
|
|
async function editConfirm() {
|
|
if (!editForm.name.trim()) {
|
|
ElMessage.warning('请输入角色名称')
|
|
return
|
|
}
|
|
const payload = {
|
|
id: editForm.id,
|
|
name: editForm.name.trim(),
|
|
remark: editForm.remark.trim(),
|
|
operationId: editForm.operationId,
|
|
roleGroupId: editForm.roleGroupId
|
|
}
|
|
try {
|
|
if (editMode.value === 'create') {
|
|
await httpPost('/sys/role', payload)
|
|
ElMessage.success('新增成功')
|
|
} else {
|
|
await httpPut('/sys/role', payload)
|
|
ElMessage.success('修改成功')
|
|
}
|
|
editVisible.value = false
|
|
load()
|
|
} catch (e: any) {
|
|
ElMessage.error(e?.msg || e?.message || (editMode.value === 'create' ? '新增失败' : '修改失败'))
|
|
}
|
|
}
|
|
|
|
async function deleteHandle(row: SysRole) {
|
|
try {
|
|
await ElMessageBox.confirm(
|
|
`确认删除角色 ${row.name} 吗?删除后该角色关联的用户权限将被移除。`,
|
|
'删除确认',
|
|
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' }
|
|
)
|
|
} catch {
|
|
return
|
|
}
|
|
try {
|
|
await httpDelete(`/sys/role/${row.id}`)
|
|
ElMessage.success('删除成功')
|
|
load()
|
|
} catch (e: any) {
|
|
ElMessage.error(e?.msg || e?.message || '删除失败')
|
|
}
|
|
}
|
|
|
|
onMounted(() => { load() })
|
|
</script>
|
|
|
|
<template>
|
|
<div class="rr-sys-role">
|
|
<div class="rr-page-header">
|
|
<div class="rr-page-titles">
|
|
<h2 class="rr-page-title">角色管理</h2>
|
|
<p class="rr-page-sub">共 {{ total }} 个角色</p>
|
|
</div>
|
|
<div class="rr-page-actions">
|
|
<el-button @click="onReset" class="rr-btn-secondary">重置</el-button>
|
|
<el-button type="primary" class="rr-btn-primary" @click="createHandle">+ 新增角色</el-button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="rr-filters-row">
|
|
<el-input
|
|
v-model="filters.name"
|
|
placeholder="角色名搜索"
|
|
clearable
|
|
class="rr-name-input"
|
|
size="small"
|
|
@keyup.enter="onSearch"
|
|
/>
|
|
<el-button class="rr-btn-secondary" size="small" @click="onSearch">查询</el-button>
|
|
</div>
|
|
|
|
<div class="rr-list-card">
|
|
<DataTable
|
|
:columns="[
|
|
{ prop: 'name', label: '角色名', minWidth: 160 },
|
|
{ prop: 'remark', label: '备注', minWidth: 200 },
|
|
{ prop: 'operationId', label: '运营中心 ID', width: 140 },
|
|
{ prop: 'roleGroupId', 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"
|
|
:error="loadError"
|
|
empty-text="暂无角色"
|
|
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="560"
|
|
: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"
|
|
show-word-limit
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="备注">
|
|
<el-input
|
|
v-model="editForm.remark"
|
|
type="textarea"
|
|
:rows="2"
|
|
placeholder="可选:角色用途说明"
|
|
maxlength="200"
|
|
show-word-limit
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="运营中心 ID">
|
|
<el-input-number
|
|
v-model="editForm.operationId"
|
|
placeholder="可选:所属运营中心"
|
|
size="default"
|
|
:min="0"
|
|
controls-position="right"
|
|
style="width: 100%"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="角色组 ID">
|
|
<el-input-number
|
|
v-model="editForm.roleGroupId"
|
|
placeholder="可选:所属角色组"
|
|
size="default"
|
|
:min="0"
|
|
controls-position="right"
|
|
style="width: 100%"
|
|
/>
|
|
</el-form-item>
|
|
</el-form>
|
|
<el-alert type="info" :closable="false" style="margin-top: 8px;">
|
|
<p>菜单权限和数据范围在编辑弹窗里只能修改基础信息</p>
|
|
<p>完整菜单/部门配置请在老后台(/vue/sys/role)操作</p>
|
|
</el-alert>
|
|
<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 {
|
|
padding: 16px;
|
|
}
|
|
|
|
.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: 18px;
|
|
font-weight: 600;
|
|
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> |