REVIEW 租户套餐

This commit is contained in:
YunaiV 2023-03-29 23:43:22 +08:00
parent e30d32effb
commit 216ad84938
4 changed files with 68 additions and 87 deletions

View File

@ -12,15 +12,8 @@ export interface TenantPackageVO {
createTime: Date
}
export interface TenantPackagePageReqVO extends PageParam {
name?: string
status?: number
remark?: string
createTime?: Date[]
}
// 查询租户套餐列表
export const getTenantPackageTypePage = (params: TenantPackagePageReqVO) => {
export const getTenantPackagePage = (params: PageParam) => {
return request.get({ url: '/system/tenant-package/page', params })
}
@ -30,17 +23,17 @@ export const getTenantPackage = (id: number) => {
}
// 新增租户套餐
export const createTenantPackageType = (data: TenantPackageVO) => {
export const createTenantPackage = (data: TenantPackageVO) => {
return request.post({ url: '/system/tenant-package/create', data })
}
// 修改租户套餐
export const updateTenantPackageType = (data: TenantPackageVO) => {
export const updateTenantPackage = (data: TenantPackageVO) => {
return request.put({ url: '/system/tenant-package/update', data })
}
// 删除租户套餐
export const deleteTenantPackageType = (id: number) => {
export const deleteTenantPackage = (id: number) => {
return request.delete({ url: '/system/tenant-package/delete?id=' + id })
}
// 获取租户套餐精简信息列表

View File

@ -52,6 +52,7 @@ declare module '@vue/runtime-core' {
ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import('element-plus/es')['ElFormItem']
ElIcon: typeof import('element-plus/es')['ElIcon']
ElImage: typeof import('element-plus/es')['ElImage']
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
ElInput: typeof import('element-plus/es')['ElInput']
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
@ -72,7 +73,10 @@ declare module '@vue/runtime-core' {
ElTabPane: typeof import('element-plus/es')['ElTabPane']
ElTabs: typeof import('element-plus/es')['ElTabs']
ElTag: typeof import('element-plus/es')['ElTag']
ElTimeline: typeof import('element-plus/es')['ElTimeline']
ElTimelineItem: typeof import('element-plus/es')['ElTimelineItem']
ElTooltip: typeof import('element-plus/es')['ElTooltip']
ElTransfer: typeof import('element-plus/es')['ElTransfer']
ElTree: typeof import('element-plus/es')['ElTree']
ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect']
ElUpload: typeof import('element-plus/es')['ElUpload']

View File

@ -1,5 +1,5 @@
<template>
<Dialog :title="modelTitle" v-model="modelVisible" width="50%">
<Dialog :title="modelTitle" v-model="modelVisible">
<el-form
ref="formRef"
:model="formData"
@ -13,13 +13,6 @@
<el-form-item label="菜单权限">
<el-card class="cardHeight">
<template #header>
父子联动(选中父节点自动选择子节点):
<el-switch
v-model="menuCheckStrictly"
inline-prompt
active-text="是"
inactive-text="否"
/>
全选/全不选:
<el-switch
v-model="treeNodeAll"
@ -43,7 +36,7 @@
:check-strictly="!menuCheckStrictly"
show-checkbox
:props="defaultProps"
:data="menuOptions as any[]"
:data="menuOptions"
empty-text="加载中,请稍候"
/>
</el-card>
@ -51,7 +44,7 @@
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:label="parseInt(dict.value)"
>
@ -70,30 +63,28 @@
</Dialog>
</template>
<script setup lang="ts" name="TenantPackageForm">
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { CommonStatusEnum } from '@/utils/constants'
import type { FormRules } from 'element-plus'
import { defaultProps } from '@/utils/tree'
//
import * as TenantPackageApi from '@/api/system/tenantPackage'
import { getSimpleMenusList } from '@/api/system/menu'
import * as MenuApi from '@/api/system/menu'
import { ElTree } from 'element-plus'
import { handleTree } from '@/utils/tree'
const { t } = useI18n() //
const message = useMessage() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData: Record<string, any> = ref<Record<string, any>>({
const formData = ref({
id: null,
name: null,
remark: null,
menuIds: [],
status: CommonStatusEnum.ENABLE
})
const formRules: FormRules = ref<FormRules>({
const formRules = reactive({
name: [{ required: true, message: '套餐名不能为空', trigger: 'blur' }],
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }],
menuIds: [{ required: true, message: '关联的菜单编号不能为空', trigger: 'blur' }]
@ -105,26 +96,12 @@ const menuExpand = ref(false) // 展开/折叠
const treeRef = ref<InstanceType<typeof ElTree>>() // Ref
const treeNodeAll = ref(false) // /
// /
const handleCheckedTreeNodeAll = () => {
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])
}
// /TODO:for
const handleCheckedTreeExpand = () => {
const nodes = treeRef.value?.store.nodesMap
for (let node in nodes) {
nodes[node].expanded = !nodes[node].expanded
}
}
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.' + type)
formType.value = type
resetForm()
// Menu
menuOptions.value = handleTree(await getSimpleMenusList())
//
if (id) {
formLoading.value = true
@ -140,6 +117,8 @@ const open = async (type: string, id?: number) => {
formLoading.value = false
}
}
// Menu
menuOptions.value = handleTree(await MenuApi.getSimpleMenusList())
}
defineExpose({ open }) // open
@ -159,10 +138,10 @@ const submitForm = async () => {
...(treeRef.value!.getHalfCheckedKeys() as unknown as Array<number>)
]
if (formType.value === 'create') {
await TenantPackageApi.createTenantPackageType(data)
await TenantPackageApi.createTenantPackage(data)
message.success(t('common.createSuccess'))
} else {
await TenantPackageApi.updateTenantPackageType(data)
await TenantPackageApi.updateTenantPackage(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
@ -189,6 +168,18 @@ const resetForm = () => {
menuCheckStrictly.value = false
formRef.value?.resetFields()
}
// /
const handleCheckedTreeNodeAll = () => {
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])
}
// /TODO:for
const handleCheckedTreeExpand = () => {
const nodes = treeRef.value?.store.nodesMap
for (let node in nodes) {
nodes[node].expanded = !nodes[node].expanded
}
}
</script>
<style lang="scss" scoped>
.cardHeight {

View File

@ -14,10 +14,11 @@
placeholder="请输入套餐名"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
@ -29,7 +30,6 @@
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
style="width: 240px"
type="daterange"
value-format="YYYY-MM-DD HH:mm:ss"
start-placeholder="开始日期"
@ -37,19 +37,12 @@
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery">
<Icon icon="ep:search" class="mr-5px" />
搜索
</el-button>
<el-button @click="resetQuery">
<Icon icon="ep:refresh" class="mr-5px" />
重置
</el-button>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary"
@click="handleCreate('create')"
@click="openForm('create')"
v-hasPermi="['system:tenant-package:create']"
>
<Icon icon="ep:plus" class="mr-5px" />
@ -72,26 +65,26 @@
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template #default="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
<span>{{ formatDate(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate('update', scope.row.id)"
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['system:tenant-package:update']"
>修改
>
修改
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['system:tenant-package:delete']"
>删除
>
删除
</el-button>
</template>
</el-table-column>
@ -104,15 +97,15 @@
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<TenantPackageForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts" name="TenantPackage">
import TenantPackageForm from './form.vue'
// import
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { parseTime } from '@/utils/formatTime'
import { formatDate } from '@/utils/formatTime'
import * as TenantPackageApi from '@/api/system/tenantPackage'
import TenantPackageForm from './TenantPackageForm.vue'
const message = useMessage() //
const { t } = useI18n() //
@ -128,17 +121,17 @@ const queryParams: Record<string, any> = ref<Record<string, any>>({
createTime: []
})
const queryFormRef = ref() //
const formRef = ref() // Ref
/** 查询列表 */
const getList = () => {
const getList = async () => {
loading.value = true
//
TenantPackageApi.getTenantPackageTypePage(queryParams.value).then((response) => {
list.value = response.list
total.value = response.total
try {
const data = await TenantPackageApi.getTenantPackagePage(queryParams.value)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
})
}
}
/** 搜索按钮操作 */
@ -149,31 +142,31 @@ const handleQuery = () => {
/** 重置按钮操作 */
const resetQuery = () => {
//
queryFormRef.value?.resetFields()
getList()
}
//
const handleCreate = (type: string) => {
formRef.value.open(type)
}
//
const handleUpdate = async (type: string, id?: number) => {
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await TenantPackageApi.deleteTenantPackageType(id)
await TenantPackageApi.deleteTenantPackage(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>