Files
ipms-sjy/yudao-ui-admin-vue3/src/views/system/tenantPackage/index.vue

183 lines
5.4 KiB
Vue
Raw Normal View History

2022-11-15 17:44:28 +08:00
<template>
<ContentWrap>
<!-- 列表 -->
2022-11-22 13:15:07 +08:00
<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()"
/>
2022-11-15 17:44:28 +08:00
</template>
2022-11-22 13:15:07 +08:00
<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)" />
2022-11-15 17:44:28 +08:00
</template>
2022-11-22 13:15:07 +08:00
</vxe-grid>
2022-11-15 17:44:28 +08:00
</ContentWrap>
2022-11-15 17:57:03 +08:00
<XModal v-model="dialogVisible" :title="dialogTitle">
2022-11-15 17:44:28 +08:00
<!-- 对话框(添加 / 修改) -->
<Form
v-if="['create', 'update'].includes(actionType)"
:schema="allSchemas.formSchema"
:rules="rules"
ref="formRef"
>
<template #menuIds>
2022-11-28 16:50:53 +08:00
<el-card class="w-120">
2022-11-15 17:44:28 +08:00
<template #header>
<div class="card-header">
全选/全不选:
<el-switch
v-model="treeNodeAll"
inline-prompt
active-text="是"
inactive-text="否"
@change="handleCheckedTreeNodeAll()"
/>
</div>
</template>
<el-tree
ref="treeRef"
node-key="id"
show-checkbox
:props="defaultProps"
:data="menuOptions"
empty-text="加载中,请稍后"
/>
</el-card>
</template>
</Form>
<!-- 操作按钮 -->
<template #footer>
<!-- 按钮保存 -->
<XButton
v-if="['create', 'update'].includes(actionType)"
type="primary"
:title="t('action.save')"
:loading="loading"
@click="submitForm()"
/>
<!-- 按钮关闭 -->
<XButton :loading="loading" :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
</template>
2022-11-23 22:26:25 +08:00
<script setup lang="ts" name="TenantPackage">
2022-07-18 19:06:37 +08:00
import { onMounted, ref, unref } from 'vue'
import { handleTree } from '@/utils/tree'
import { useI18n } from '@/hooks/web/useI18n'
2022-11-22 13:15:07 +08:00
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
2022-07-18 19:06:37 +08:00
import { FormExpose } from '@/components/Form'
2022-11-22 13:15:07 +08:00
import { ElCard, ElSwitch, ElTree } from 'element-plus'
// 业务相关的 import
2022-07-18 19:06:37 +08:00
import { rules, allSchemas } from './tenantPackage.data'
import * as TenantPackageApi from '@/api/system/tenantPackage'
import { listSimpleMenusApi } from '@/api/system/menu'
2022-11-22 13:15:07 +08:00
2022-07-18 19:06:37 +08:00
const { t } = useI18n() // 国际化
2022-11-22 13:15:07 +08:00
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') // 弹出层标题
2022-07-18 19:06:37 +08:00
const defaultProps = {
children: 'children',
label: 'name',
value: 'id'
}
2022-11-22 13:15:07 +08:00
2022-08-01 19:50:43 +08:00
// 全选/全不选
const handleCheckedTreeNodeAll = () => {
treeRef.value!.setCheckedNodes(treeNodeAll.value ? menuOptions.value : [])
}
2022-07-18 19:06:37 +08:00
const getTree = async () => {
const res = await listSimpleMenusApi()
menuOptions.value = handleTree(res)
}
2022-11-22 13:15:07 +08:00
const { gridOptions, getList, deleteData } = useVxeGrid<TenantPackageApi.TenantPackageVO>({
allSchemas: allSchemas,
2022-07-18 19:06:37 +08:00
getListApi: TenantPackageApi.getTenantPackageTypePageApi,
2022-11-22 13:15:07 +08:00
deleteApi: TenantPackageApi.deleteTenantPackageTypeApi
2022-07-18 19:06:37 +08:00
})
// 设置标题
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
actionType.value = type
dialogVisible.value = true
}
// 新增操作
const handleCreate = () => {
//重置菜单树
unref(treeRef)?.setCheckedKeys([])
menuExpand.value = false
menuNodeAll.value = false
2022-11-15 10:52:27 +08:00
setDialogTile('create')
2022-07-18 19:06:37 +08:00
}
// 修改操作
2022-11-22 13:15:07 +08:00
const handleUpdate = async (rowId: number) => {
2022-07-18 19:06:37 +08:00
setDialogTile('update')
// 设置数据
2022-11-22 13:15:07 +08:00
const res = await TenantPackageApi.getTenantPackageApi(rowId)
2022-07-18 19:06:37 +08:00
unref(formRef)?.setValues(res)
// 设置选中
unref(treeRef)?.setCheckedKeys(res.menuIds)
}
2022-11-22 13:15:07 +08:00
// 删除操作
const handleDelete = async (rowId: number) => {
await deleteData(xGrid, rowId)
}
2022-07-18 19:06:37 +08:00
// 提交按钮
const submitForm = async () => {
2022-10-17 11:24:22 +08:00
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
loading.value = true
// 提交请求
try {
2022-11-22 13:15:07 +08:00
const data = unref(formRef)?.formModel as TenantPackageApi.TenantPackageVO
2022-12-06 14:12:57 +08:00
data.menuIds = treeRef.value!.getCheckedKeys(false) as number[]
2022-10-17 11:24:22 +08:00
if (actionType.value === 'create') {
await TenantPackageApi.createTenantPackageTypeApi(data)
2022-11-22 13:15:07 +08:00
message.success(t('common.createSuccess'))
2022-10-17 11:24:22 +08:00
} else {
await TenantPackageApi.updateTenantPackageTypeApi(data)
2022-11-22 13:15:07 +08:00
message.success(t('common.updateSuccess'))
2022-10-17 11:24:22 +08:00
}
// 操作成功,重新加载列表
dialogVisible.value = false
} finally {
loading.value = false
2022-11-22 13:15:07 +08:00
// 刷新列表
await getList(xGrid)
2022-10-17 11:24:22 +08:00
}
2022-07-18 19:06:37 +08:00
}
2022-10-17 11:24:22 +08:00
})
2022-07-18 19:06:37 +08:00
}
// ========== 初始化 ==========
onMounted(async () => {
await getTree()
})
// getList()
</script>