feat: tenant

This commit is contained in:
xingyu4j 2022-11-22 13:15:07 +08:00
parent 88cb5497c5
commit 407ac853cb
10 changed files with 290 additions and 359 deletions

View File

@ -27,7 +27,6 @@
<mybatis-plus-generator.version>3.5.2</mybatis-plus-generator.version>
<dynamic-datasource.version>3.5.2</dynamic-datasource.version>
<redisson.version>3.18.0</redisson.version>
<!-- Config 配置中心相关 -->
<!-- 服务保障相关 -->
<lock4j.version>2.2.2</lock4j.version>
<resilience4j.version>1.7.1</resilience4j.version>

View File

@ -28,7 +28,7 @@ specifiers:
dayjs: ^1.11.6
echarts: ^5.4.0
echarts-wordcloud: ^2.0.0
element-plus: 2.2.22
element-plus: 2.2.21
eslint: ^8.27.0
eslint-config-prettier: ^8.5.0
eslint-define-config: ^1.12.0
@ -92,7 +92,7 @@ dependencies:
dayjs: registry.npmmirror.com/dayjs/1.11.6
echarts: registry.npmmirror.com/echarts/5.4.0
echarts-wordcloud: registry.npmmirror.com/echarts-wordcloud/2.0.0_echarts@5.4.0
element-plus: registry.npmmirror.com/element-plus/2.2.22_vue@3.2.45
element-plus: registry.npmmirror.com/element-plus/2.2.21_vue@3.2.45
intro.js: registry.npmmirror.com/intro.js/6.0.0
js-cookie: registry.npmmirror.com/js-cookie/3.0.1
jsencrypt: registry.npmmirror.com/jsencrypt/3.3.1
@ -3645,11 +3645,11 @@ packages:
version: 1.4.284
dev: true
registry.npmmirror.com/element-plus/2.2.22_vue@3.2.45:
resolution: {integrity: sha512-gg2g2WOMNpWf0wGesymUvTV0VZDF/4khQKroSNeCV/vWJ/cqssPYdtqfGxTiFRt/f+JpyFkV7O1mo0yzMCzrBg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/element-plus/-/element-plus-2.2.22.tgz}
id: registry.npmmirror.com/element-plus/2.2.22
registry.npmmirror.com/element-plus/2.2.21_vue@3.2.45:
resolution: {integrity: sha512-wZUePoXZ1zuCkzENK/8mn+mekuLJ9OoGYiudjUujzCf+T8HfOQl+TKQStwOkGBNk93fK8e9YdFIty4jH4AX6dg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/element-plus/-/element-plus-2.2.21.tgz}
id: registry.npmmirror.com/element-plus/2.2.21
name: element-plus
version: 2.2.22
version: 2.2.21
peerDependencies:
vue: ^3.2.0
dependencies:

View File

@ -1,8 +1,36 @@
import request from '@/config/axios'
import type { TenantVO } from './types'
export interface TenantVO {
id: number
name: string
packageId: number
contactName: string
contactMobile: string
username: string
password: string
accountCount: number
expireTime: string
domain: string
status: number
createTime: string
}
export interface TenantPageReqVO extends PageParam {
name?: string
contactName?: string
contactMobile?: string
status?: number
}
export interface TenantExportReqVO {
name?: string
contactName?: string
contactMobile?: string
status?: number
}
// 查询租户列表
export const getTenantPageApi = (params) => {
export const getTenantPageApi = (params: TenantPageReqVO) => {
return request.get({ url: '/system/tenant/page', params })
}
@ -27,6 +55,6 @@ export const deleteTenantApi = (id: number) => {
}
// 导出租户
export const exportTenantApi = (params) => {
export const exportTenantApi = (params: TenantExportReqVO) => {
return request.download({ url: '/system/tenant/export-excel', params })
}

View File

@ -1,14 +0,0 @@
export type TenantVO = {
id: number
name: string
packageId: number
contactName: string
contactMobile: string
username: string
password: string
accountCount: number
expireTime: string
domain: string
status: number
createTime: string
}

View File

@ -1,8 +1,26 @@
import request from '@/config/axios'
import type { TenantPackageVO } from './types'
export interface TenantPackageVO {
id: number
name: string
status: number
remark: string
creator: string
createTime: string
updater: string
updateTime: string
menuIds: string[]
}
export interface TenantPackagePageReqVO extends PageParam {
name?: string
contactName?: string
contactMobile?: string
status?: number
}
// 查询租户套餐列表
export const getTenantPackageTypePageApi = (params) => {
export const getTenantPackageTypePageApi = (params: TenantPackagePageReqVO) => {
return request.get({ url: '/system/tenant-package/page', params })
}
@ -25,7 +43,7 @@ export const updateTenantPackageTypeApi = (data: TenantPackageVO) => {
export const deleteTenantPackageTypeApi = (id: number) => {
return request.delete({ url: '/system/tenant-package/delete?id=' + id })
}
// // 获取租户套餐精简信息列表
// 获取租户套餐精简信息列表
export const getTenantPackageList = () => {
return request.get({ url: '/system/tenant-package/get-simple-list' })
}

View File

@ -1,11 +0,0 @@
export type TenantPackageVO = {
id: number
name: string
status: number
remark: string
creator: string
createTime: string
updater: string
updateTime: string
menuIds: string[]
}

View File

@ -1,11 +1,9 @@
<template>
<!-- 搜索工作区 -->
<ContentWrap>
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
</ContentWrap>
<ContentWrap>
<!-- 操作工具栏 -->
<div class="mb-10px">
<!-- 列表 -->
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
<template #toolbar_buttons>
<!-- 操作新增 -->
<XButton
type="primary"
preIcon="ep:zoom-in"
@ -18,62 +16,40 @@
preIcon="ep:download"
:title="t('action.export')"
v-hasPermi="['system:tenant:export']"
@click="exportList('租户数据.xls')"
@click="handleExport()"
/>
</div>
<!-- 列表 -->
<Table
:columns="allSchemas.tableColumns"
:selection="false"
:data="tableObject.tableList"
:loading="tableObject.loading"
:pagination="{
total: tableObject.total
}"
v-model:pageSize="tableObject.pageSize"
v-model:currentPage="tableObject.currentPage"
@register="register"
>
</template>
<template #accountCount="{ row }">
<el-tag> {{ row.accountCount }} </el-tag>
</template>
<template #status="{ row }">
<DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
</template>
<template #packageId="{ row }">
<el-tag v-if="row.packageId === 0" type="danger">系统租户</el-tag>
<el-tag v-else type="success"> {{ getPackageName(row.packageId) }} </el-tag>
</template>
<template #expireTime="{ row }">
<span>{{ dayjs(row.expireTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
</template>
<template #createTime="{ row }">
<span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
</template>
<template #action="{ row }">
<template #actionbtns_default="{ row }">
<!-- 操作修改 -->
<XTextButton
preIcon="ep:edit"
:title="t('action.edit')"
v-hasPermi="['system:tenant:update']"
@click="handleUpdate(row)"
@click="handleUpdate(row.id)"
/>
<!-- 操作详情 -->
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
v-hasPermi="['system:tenant:update']"
@click="handleDetail(row)"
@click="handleDetail(row.id)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.del')"
v-hasPermi="['system:tenant:delete']"
@click="delList(row.id, false)"
@click="handleDelete(row.id)"
/>
</template>
</Table>
</vxe-grid>
</ContentWrap>
<XModal v-model="dialogVisible" :title="dialogTitle">
@ -124,27 +100,33 @@
<script setup lang="ts">
import { ref, unref, onMounted } from 'vue'
import dayjs from 'dayjs'
import { ElMessage, ElTag, ElSelect, ElOption } from 'element-plus'
import { DICT_TYPE } from '@/utils/dict'
import { useTable } from '@/hooks/web/useTable'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
import { ElTag, ElSelect, ElOption } from 'element-plus'
import { FormExpose } from '@/components/Form'
import type { TenantVO } from '@/api/system/tenant/types'
import { rules, allSchemas } from './tenant.data'
import * as TenantApi from '@/api/system/tenant'
import { getTenantPackageList } from '@/api/system/tenantPackage'
import { TenantPackageVO } from '@/api/system/tenantPackage/types'
const { t } = useI18n() //
import { rules, allSchemas } from './tenant.data'
import { getTenantPackageList, TenantPackageVO } from '@/api/system/tenantPackage'
// ========== ==========
const { register, tableObject, methods } = useTable<TenantVO>({
const { t } = useI18n() //
const message = useMessage() //
//
const xGrid = ref<VxeGridInstance>() // Grid Ref
const { gridOptions, getList, deleteData, exportList } = useVxeGrid<TenantApi.TenantVO>({
allSchemas: allSchemas,
getListApi: TenantApi.getTenantPageApi,
delListApi: TenantApi.deleteTenantApi,
deleteApi: TenantApi.deleteTenantApi,
exportListApi: TenantApi.exportTenantApi
})
const { getList, setSearchParams, delList, exportList } = methods
// ========== ==========
const actionLoading = ref(false) //
const actionType = ref('') //
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const formRef = ref<FormExpose>() // Ref
const detailRef = ref() // Ref
const tenantPackageId = ref() //
const tenantPackageOptions = ref<TenantPackageVO[]>([]) //
@ -160,12 +142,6 @@ const getPackageName = (packageId: number) => {
}
return '未知套餐'
}
// ========== CRUD ==========
const actionLoading = ref(false) //
const actionType = ref('') //
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const formRef = ref<FormExpose>() // Ref
//
const setDialogTile = (type: string) => {
@ -182,15 +158,34 @@ const handleCreate = () => {
}
//
const handleUpdate = async (row: any) => {
const handleUpdate = async (rowId: number) => {
setDialogTile('update')
//
const res = await TenantApi.getTenantApi(row.id)
const res = await TenantApi.getTenantApi(rowId)
tenantPackageId.value = res.packageId
res.expireTime = dayjs(res.expireTime).format('YYYY-MM-DD HH:mm:ss')
unref(formRef)?.setValues(res)
}
//
const handleDetail = async (rowId: number) => {
//
const res = await TenantApi.getTenantApi(rowId)
tenantPackageId.value = res.packageId
detailRef.value = res
setDialogTile('detail')
}
//
const handleDelete = async (rowId: number) => {
await deleteData(xGrid, rowId)
}
//
const handleExport = async () => {
await exportList(xGrid, '租户列表.xls')
}
//
const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
@ -200,40 +195,30 @@ const submitForm = async () => {
actionLoading.value = true
//
try {
const data = unref(formRef)?.formModel as TenantVO
const data = unref(formRef)?.formModel as TenantApi.TenantVO
data.packageId = tenantPackageId.value
if (actionType.value === 'create') {
data.expireTime = dayjs(data.expireTime).valueOf().toString()
await TenantApi.createTenantApi(data)
ElMessage.success(t('common.createSuccess'))
message.success(t('common.createSuccess'))
} else {
data.expireTime = dayjs(data.expireTime).valueOf().toString()
await TenantApi.updateTenantApi(data)
ElMessage.success(t('common.updateSuccess'))
message.success(t('common.updateSuccess'))
}
//
dialogVisible.value = false
await getList()
} finally {
actionLoading.value = false
//
await getList(xGrid)
}
}
})
}
// ========== ==========
const detailRef = ref() // Ref
//
const handleDetail = async (row: any) => {
//
detailRef.value = row
setDialogTile('detail')
}
// ========== ==========
onMounted(async () => {
await getList()
await getTenantPackageOptions()
})
</script>

View File

@ -1,8 +1,8 @@
import { reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { DICT_TYPE } from '@/utils/dict'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
// 表单校验
@ -18,76 +18,56 @@ export const rules = reactive({
})
// CrudSchema.
const crudSchemas = reactive<CrudSchema[]>([
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'seq',
action: true,
columns: [
{
label: t('common.index'),
field: 'id',
type: 'index',
form: {
show: false
},
detail: {
show: false
}
},
{
label: '租户名称',
title: '租户名称',
field: 'name',
search: {
show: true
}
isSearch: true
},
{
label: '租户套餐',
title: '租户套餐',
field: 'packageId'
},
{
label: '联系人',
title: '联系人',
field: 'contactName',
search: {
show: true
}
isSearch: true
},
{
label: '联系手机',
title: '联系手机',
field: 'contactMobile',
search: {
show: true
}
isSearch: true
},
{
label: '用户名称',
title: '用户名称',
field: 'username',
table: {
show: false
},
detail: {
show: false
}
isTable: false,
isDetail: false
},
{
label: '用户密码',
title: '用户密码',
field: 'password',
table: {
show: false
},
detail: {
show: false
},
isTable: false,
isDetail: false,
form: {
component: 'InputPassword'
}
},
{
label: '账号额度',
title: '账号额度',
field: 'accountCount',
form: {
component: 'InputNumber'
}
},
{
label: '过期时间',
title: '过期时间',
field: 'expireTime',
formatter: 'formatDate',
form: {
show: true,
component: 'DatePicker',
@ -98,35 +78,22 @@ const crudSchemas = reactive<CrudSchema[]>([
}
},
{
label: '绑定域名',
title: '绑定域名',
field: 'domain'
},
{
label: '租户状态',
title: '租户状态',
field: 'status',
dictType: DICT_TYPE.COMMON_STATUS,
dictClass: 'number',
search: {
show: true
}
isSearch: true
},
{
label: t('table.createTime'),
title: t('table.createTime'),
field: 'createTime',
form: {
show: false
formatter: 'formatDate',
isForm: false
}
},
{
label: t('table.action'),
field: 'action',
width: '240px',
form: {
show: false
},
detail: {
show: false
}
}
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)

View File

@ -1,42 +1,20 @@
<template>
<!-- 搜索工作区 -->
<ContentWrap>
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
</ContentWrap>
<ContentWrap>
<!-- 操作工具栏 -->
<div class="mb-10px">
<!-- 列表 -->
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
<template #toolbar_buttons>
<XButton
type="primary"
preIcon="ep:zoom-in"
:title="t('action.add')"
@click="handleCreate()"
/>
</div>
<!-- 列表 -->
<Table
:columns="allSchemas.tableColumns"
:selection="false"
:data="tableObject.tableList"
:loading="tableObject.loading"
:pagination="{
total: tableObject.total
}"
v-model:pageSize="tableObject.pageSize"
v-model:currentPage="tableObject.currentPage"
@register="register"
>
<template #status="{ row }">
<DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
</template>
<template #createTime="{ row }">
<span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
<template #actionbtns_default="{ row }">
<XTextButton preIcon="ep:edit" :title="t('action.edit')" @click="handleUpdate(row.id)" />
<XTextButton preIcon="ep:delete" :title="t('action.del')" @click="handleDelete(row.id)" />
</template>
<template #action="{ row }">
<XTextButton preIcon="ep:edit" :title="t('action.edit')" @click="handleUpdate(row)" />
<XTextButton preIcon="ep:delete" :title="t('action.del')" @click="delList(row.id, false)" />
</template>
</Table>
</vxe-grid>
</ContentWrap>
<XModal v-model="dialogVisible" :title="dialogTitle">
@ -89,28 +67,39 @@
</template>
<script setup lang="ts">
import { onMounted, ref, unref } from 'vue'
import dayjs from 'dayjs'
import { handleTree } from '@/utils/tree'
import { DICT_TYPE } from '@/utils/dict'
import { useTable } from '@/hooks/web/useTable'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
import { FormExpose } from '@/components/Form'
import { TenantPackageVO } from '@/api/system/tenantPackage/types'
import { ElMessage, ElCard, ElSwitch, ElTree } from 'element-plus'
import { ElCard, ElSwitch, ElTree } from 'element-plus'
// import
import { rules, allSchemas } from './tenantPackage.data'
import * as TenantPackageApi from '@/api/system/tenantPackage'
import { listSimpleMenusApi } from '@/api/system/menu'
const { t } = useI18n() //
const message = useMessage() //
const menuOptions = ref<any[]>([]) //
const menuExpand = ref(false)
const menuNodeAll = ref(false)
const treeRef = ref<InstanceType<typeof ElTree>>()
const treeNodeAll = ref(false)
const xGrid = ref<VxeGridInstance>() // Grid Ref
const formRef = ref<FormExpose>() // Ref
const loading = ref(false) //
const actionType = ref('') //
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const defaultProps = {
children: 'children',
label: 'name',
value: 'id'
}
// ========== ==========
const menuOptions = ref<any[]>([]) //
const treeRef = ref<InstanceType<typeof ElTree>>()
const treeNodeAll = ref(false)
// /
const handleCheckedTreeNodeAll = () => {
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])
@ -119,22 +108,12 @@ const getTree = async () => {
const res = await listSimpleMenusApi()
menuOptions.value = handleTree(res)
}
const menuExpand = ref(false)
const menuNodeAll = ref(false)
// ========== ==========
const { register, tableObject, methods } = useTable<TenantPackageVO>({
const { gridOptions, getList, deleteData } = useVxeGrid<TenantPackageApi.TenantPackageVO>({
allSchemas: allSchemas,
getListApi: TenantPackageApi.getTenantPackageTypePageApi,
delListApi: TenantPackageApi.deleteTenantPackageTypeApi
deleteApi: TenantPackageApi.deleteTenantPackageTypeApi
})
const { getList, setSearchParams, delList } = methods
// ========== CRUD ==========
const loading = ref(false) //
const formRef = ref<FormExpose>() // Ref
const actionType = ref('') //
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
//
const setDialogTile = (type: string) => {
@ -153,14 +132,20 @@ const handleCreate = () => {
}
//
const handleUpdate = async (row: any) => {
const handleUpdate = async (rowId: number) => {
setDialogTile('update')
//
const res = await TenantPackageApi.getTenantPackageApi(row.id)
const res = await TenantPackageApi.getTenantPackageApi(rowId)
unref(formRef)?.setValues(res)
//
unref(treeRef)?.setCheckedKeys(res.menuIds)
}
//
const handleDelete = async (rowId: number) => {
await deleteData(xGrid, rowId)
}
//
const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
@ -170,20 +155,21 @@ const submitForm = async () => {
loading.value = true
//
try {
const data = unref(formRef)?.formModel as TenantPackageVO
const data = unref(formRef)?.formModel as TenantPackageApi.TenantPackageVO
data.menuIds = treeRef.value!.getCheckedKeys(false) as string[]
if (actionType.value === 'create') {
await TenantPackageApi.createTenantPackageTypeApi(data)
ElMessage.success(t('common.createSuccess'))
message.success(t('common.createSuccess'))
} else {
await TenantPackageApi.updateTenantPackageTypeApi(data)
ElMessage.success(t('common.updateSuccess'))
message.success(t('common.updateSuccess'))
}
//
dialogVisible.value = false
await getList()
} finally {
loading.value = false
//
await getList(xGrid)
}
}
})
@ -191,7 +177,6 @@ const submitForm = async () => {
// ========== ==========
onMounted(async () => {
await getList()
await getTree()
})
// getList()

View File

@ -1,8 +1,8 @@
import { reactive } from 'vue'
import { required } from '@/utils/formRules'
import { useI18n } from '@/hooks/web/useI18n'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { DICT_TYPE } from '@/utils/dict'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
// 表单校验
@ -16,44 +16,32 @@ export const rules = reactive({
})
// CrudSchema
const crudSchemas = reactive<CrudSchema[]>([
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'seq',
action: true,
columns: [
{
label: t('common.index'),
field: 'id',
type: 'index',
form: {
show: false
},
detail: {
show: false
}
},
{
label: '套餐名称',
title: '套餐名称',
field: 'name',
search: {
show: true
}
isSearch: true
},
{
label: t('common.status'),
title: t('common.status'),
field: 'status',
dictType: DICT_TYPE.COMMON_STATUS,
dictClass: 'number',
search: {
show: true
}
isSearch: true
},
{
label: '菜单权限',
title: '菜单权限',
field: 'menuIds',
table: {
show: false
}
isTable: false
},
{
label: t('form.remark'),
title: t('form.remark'),
field: 'remark',
isTable: false,
form: {
component: 'Input',
componentProps: {
@ -63,28 +51,14 @@ const crudSchemas = reactive<CrudSchema[]>([
colProps: {
span: 24
}
},
table: {
show: false
}
},
{
label: '创建时间',
title: '创建时间',
field: 'createTime',
form: {
show: false
formatter: 'formatDate',
isForm: false
}
},
{
label: t('table.action'),
field: 'action',
width: '240px',
form: {
show: false
},
detail: {
show: false
}
}
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)