This commit is contained in:
张成
2026-04-13 11:16:22 +08:00
parent 75149f994f
commit c73afd2325
13 changed files with 421 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import SysLog from './system/sys_log.vue'
import SysParamSetup from './system/sys_param_setup.vue'
import SysRole from './system/sys_role.vue'
import SysUser from './system/sys_user.vue'
import SysTenant from './system/sys_tenant.vue'
import SysLogOperate from './system/sys_log_operate.vue'
@@ -36,6 +37,7 @@ export function setupComponentMap(customMap = {}, uiTool) {
'system/sys_param_setup': SysParamSetup,
'system/sys_role': SysRole,
'system/sys_user': SysUser,
'system/sys_tenant': SysTenant,
'system/sys_control': SysControl,
'system/sys_menu': SysMenu,
'system/sys_title': SysTitle,
@@ -60,6 +62,7 @@ export default {
SysParamSetup,
SysRole,
SysUser,
SysTenant,
SysControl,
SysMenu,
SysTitle,

View File

@@ -43,9 +43,13 @@ export default {
},
methods: {
...mapActions('user', ['handleLogin']),
async handleSubmit({ userName, password }) {
async handleSubmit({ userName, password, tenantCode }) {
try {
let userFrom = { name: userName, password: password }
let userFrom = {
name: userName,
password: password,
tenant_code: tenantCode || 'default'
}
await this.handleLogin({
userFrom,
Main,

View File

@@ -1,5 +1,8 @@
<template>
<div class="content-view">
<Alert type="info" show-icon closable style="margin-bottom: 12px">
角色为<strong>全库共用</strong>不按租户隔离各租户用户可在用户管理中绑定同一角色菜单权限以角色配置为准
</Alert>
<div class="table-head-tool">
<Button type="primary" @click="showAddWarp">新增</Button>
</div>
@@ -73,6 +76,23 @@ export default {
this.init()
},
methods: {
parseRoleMenuIds(menus) {
if (menus == null || menus === '') {
return []
}
if (Array.isArray(menus)) {
return menus.map((id) => Number(id)).filter((id) => !Number.isNaN(id))
}
if (typeof menus === 'string') {
try {
const parsed = JSON.parse(menus)
return this.parseRoleMenuIds(parsed)
} catch {
return []
}
}
return []
},
async init() {
let res = await roleServer.list()
this.gridOption.data = res.data
@@ -120,12 +140,8 @@ export default {
let res = await menuServer.list()
let tree = uiTool.transformTree(res.data)
if (row.menus) {
this.expandTreeAll = JSON.parse(row.menus)
this.treeData = this.mapTree(tree)
} else {
this.treeData = this.mapTree(tree)
}
this.expandTreeAll = this.parseRoleMenuIds(row.menus)
this.treeData = this.mapTree(tree)
this.isShowPermission = true
},
@@ -136,7 +152,7 @@ export default {
p.children = this.mapTree(p.children)
}
let row = this.expandTreeAll.find((p2) => p2 === p.id)
let row = this.expandTreeAll.find((p2) => Number(p2) === Number(p.id))
if (row) {
p.checked = true
}

View File

@@ -0,0 +1,127 @@
<template>
<div class="content-view">
<Alert type="warning" show-icon style="margin-bottom: 12px">
<strong>平台租户</strong>is_platform=1可维护租户列表普通租户登录后本页仅能看到自身租户信息
需在数据库执行迁移脚本创建 <code>sys_tenant</code> 表及默认数据
</Alert>
<div class="table-head-tool">
<Button type="primary" @click="showAddWarp">新增租户</Button>
</div>
<div class="table-body">
<tables ref="tables" v-model="gridOption.data" :columns="gridOption.columns" />
</div>
<editModal ref="editModal" :columns="gridOption.columns" :data="gridOption.editRow" />
</div>
</template>
<script>
import uiTool from '@/utils/uiTool'
import sysTenantServer from '@/api/system/sysTenantServer'
export default {
name: 'sys_tenant_page',
data() {
return {
gridOption: {
editRow: {},
columns: [
{ title: 'id', key: 'id' },
{ title: '名称', key: 'name' },
{ title: '编码', key: 'code' },
{ title: '备注', key: 'remark' },
{
title: '状态',
key: 'status',
com: 'Radio',
source: [
{ key: 1, value: '启用' },
{ key: 0, value: '停用' }
],
render(h, p) {
return h('span', p.row.status === 1 ? '启用' : '停用')
}
},
{
title: '平台租户',
key: 'is_platform',
render(h, p) {
return h('span', Number(p.row.is_platform) === 1 ? '是' : '否')
}
},
{
title: '操作',
render: (h, params) => {
if (params.row.id === 1) {
return h('span', { style: { color: '#999' } }, '内置租户')
}
const btns = [
{
title: '修改',
type: 'primary',
click: () => this.showEditWarp(params.row)
},
{
title: '删除',
type: 'primary',
click: () => this.delConfirm(params.row)
}
]
return uiTool.getBtn(h, btns)
}
}
],
data: []
}
}
},
created() {
this.init()
},
methods: {
async init() {
const res = await sysTenantServer.list()
if (res && res.code === 0) {
this.gridOption.data = res.data || []
}
},
showAddWarp() {
this.$refs.editModal.addShow(
{ status: 1 },
async (row) => {
await sysTenantServer.add(row)
this.$Message.success('新增成功')
this.init()
}
)
},
showEditWarp(row) {
this.$refs.editModal.editShow(row, async (newRow) => {
await sysTenantServer.edit(newRow)
this.$Message.success('修改成功')
this.init()
})
},
delConfirm(row) {
uiTool.delConfirm(async () => {
await sysTenantServer.del(row)
this.$Message.success('删除成功')
this.init()
})
}
}
}
</script>
<style scoped>
.content-view {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}
.table-body {
flex: 1;
min-height: 0;
overflow-y: auto;
}
</style>

View File

@@ -1,5 +1,10 @@
<template>
<div class="content-view">
<Alert v-if="currentTenant" type="info" show-icon closable style="margin-bottom: 12px">
当前租户<strong>{{ currentTenant.name }}</strong>{{ currentTenant.code }}用户按租户隔离
<strong>角色全库共用</strong>下拉中的角色对所有租户一致
<span v-if="isPlatformTenant">平台租户可为他人指定目标租户</span>
</Alert>
<div class="table-head-tool">
<Button type="primary" @click="showAddWarp">新增</Button>
@@ -16,9 +21,10 @@
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { mapGetters, mapState } from 'vuex'
import userServer from '@/api/system/userServer'
import roleServer from '@/api/system/roleServer'
import sysTenantServer from '@/api/system/sysTenantServer'
import uiTool from '@/utils/uiTool'
export default {
@@ -30,7 +36,17 @@ export default {
editRow: {},
columns: [
{ title: '登陆名', key: 'name' },
{
title: '租户',
key: 'tenantName',
display: true,
render(h, params) {
if (params.row.tenant) {
return h('span', params.row.tenant.name || '')
}
return h('span', '')
}
},
{
title: '密码',
key: 'password',
@@ -83,19 +99,37 @@ export default {
...mapGetters({
shopList: 'shop/shopList',
}),
...mapState('user', ['currentTenant']),
isPlatformTenant() {
return this.currentTenant && Number(this.currentTenant.is_platform) === 1
},
},
watch: {
currentTenant() {
this.syncTenantSelectColumn()
this.initCol()
},
},
created() {
this.init()
this.initCol()
},
methods: {
syncTenantSelectColumn() {
const idx = this.gridOption.columns.findIndex((c) => c.key === 'tenant_id_select')
if (idx !== -1) {
this.gridOption.columns.splice(idx, 1)
}
},
async init() {
let res = await userServer.all()
this.gridOption.data = res.data
},
async initCol() {
this.syncTenantSelectColumn()
let res = await roleServer.list()
this.roles = res.data
this.roles = res.data || []
let roleSource = this.roles.map((p) => {
return {
key: p.id,
@@ -107,18 +141,51 @@ export default {
if (roleRow) {
roleRow.source = roleSource
}
if (this.isPlatformTenant) {
try {
const tr = await sysTenantServer.list()
const tenants = (tr && tr.data) || []
const tenantSource = tenants.map((t) => ({
key: t.id,
value: `${t.name}${t.code}`,
}))
this.gridOption.columns.splice(1, 0, {
title: '目标租户',
key: 'tenant_id_select',
com: 'Select',
source: tenantSource,
})
} catch (e) {
console.warn('加载租户列表失败', e)
}
}
},
showAddWarp() {
this.$refs.editModal.addShow({}, async (newRow) => {
await userServer.add(newRow)
const payload = { ...newRow }
if (payload.tenant_id_select != null && payload.tenant_id_select !== '') {
payload.tenant_id = Number(payload.tenant_id_select)
}
delete payload.tenant_id_select
await userServer.add(payload)
this.$Message.success('新增成功!')
this.init()
})
},
showEditWarp(row) {
this.$refs.editModal.editShow(row, async (newRow) => {
await userServer.edit(newRow)
const rowWithSelect = { ...row }
if (this.isPlatformTenant) {
rowWithSelect.tenant_id_select = row.tenant_id
}
this.$refs.editModal.editShow(rowWithSelect, async (newRow) => {
const payload = { ...newRow }
if (payload.tenant_id_select != null && payload.tenant_id_select !== '') {
payload.tenant_id = Number(payload.tenant_id_select)
}
delete payload.tenant_id_select
await userServer.edit(payload)
this.$Message.success('修改成功!')
this.init()
})