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> <mybatis-plus-generator.version>3.5.2</mybatis-plus-generator.version>
<dynamic-datasource.version>3.5.2</dynamic-datasource.version> <dynamic-datasource.version>3.5.2</dynamic-datasource.version>
<redisson.version>3.18.0</redisson.version> <redisson.version>3.18.0</redisson.version>
<!-- Config 配置中心相关 -->
<!-- 服务保障相关 --> <!-- 服务保障相关 -->
<lock4j.version>2.2.2</lock4j.version> <lock4j.version>2.2.2</lock4j.version>
<resilience4j.version>1.7.1</resilience4j.version> <resilience4j.version>1.7.1</resilience4j.version>

View File

@ -28,7 +28,7 @@ specifiers:
dayjs: ^1.11.6 dayjs: ^1.11.6
echarts: ^5.4.0 echarts: ^5.4.0
echarts-wordcloud: ^2.0.0 echarts-wordcloud: ^2.0.0
element-plus: 2.2.22 element-plus: 2.2.21
eslint: ^8.27.0 eslint: ^8.27.0
eslint-config-prettier: ^8.5.0 eslint-config-prettier: ^8.5.0
eslint-define-config: ^1.12.0 eslint-define-config: ^1.12.0
@ -92,7 +92,7 @@ dependencies:
dayjs: registry.npmmirror.com/dayjs/1.11.6 dayjs: registry.npmmirror.com/dayjs/1.11.6
echarts: registry.npmmirror.com/echarts/5.4.0 echarts: registry.npmmirror.com/echarts/5.4.0
echarts-wordcloud: registry.npmmirror.com/echarts-wordcloud/2.0.0_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 intro.js: registry.npmmirror.com/intro.js/6.0.0
js-cookie: registry.npmmirror.com/js-cookie/3.0.1 js-cookie: registry.npmmirror.com/js-cookie/3.0.1
jsencrypt: registry.npmmirror.com/jsencrypt/3.3.1 jsencrypt: registry.npmmirror.com/jsencrypt/3.3.1
@ -3645,11 +3645,11 @@ packages:
version: 1.4.284 version: 1.4.284
dev: true dev: true
registry.npmmirror.com/element-plus/2.2.22_vue@3.2.45: registry.npmmirror.com/element-plus/2.2.21_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} 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.22 id: registry.npmmirror.com/element-plus/2.2.21
name: element-plus name: element-plus
version: 2.2.22 version: 2.2.21
peerDependencies: peerDependencies:
vue: ^3.2.0 vue: ^3.2.0
dependencies: dependencies:

View File

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

View File

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

View File

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

View File

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