!44 [系统管理 -> 岗位管理] 使用 Element Plus 原生实现

Merge pull request !44 from Chika/master
This commit is contained in:
芋道源码 2023-03-22 14:00:20 +00:00 committed by Gitee
commit 320cffee19
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 258 additions and 166 deletions

View File

@ -1,81 +1,96 @@
<template> <template>
<!-- 弹窗 --> <Dialog :title="modelTitle" v-model="modelVisible" width="800">
<XModal :title="modelTitle" :loading="modelLoading" v-model="modelVisible"> <el-form
<!-- 表单添加/修改 -->
<Form
ref="formRef" ref="formRef"
v-if="['create', 'update'].includes(actionType)" :model="formData"
:schema="allSchemas.formSchema" :rules="formRules"
:rules="rules" label-width="80px"
/> v-loading="formLoading"
<!-- 表单详情 --> >
<Descriptions <el-form-item label="岗位标题" prop="name">
v-if="actionType === 'detail'" <el-input v-model="formData.name" placeholder="请输入岗位标题" />
:schema="allSchemas.detailSchema" </el-form-item>
:data="detailData" <el-form-item label="岗位编码" prop="code">
<el-input :model-value="formData.code" placeholder="请输入岗位编码" height="150px" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="formData.status" placeholder="请选择状态" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="parseInt(dict.value)"
:label="dict.label"
:value="parseInt(dict.value)"
/> />
</el-select>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="formData.remark" type="textarea" placeholder="请输备注" />
</el-form-item>
</el-form>
<template #footer> <template #footer>
<!-- 按钮保存 --> <div class="dialog-footer">
<XButton <el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
v-if="['create', 'update'].includes(actionType)" <el-button @click="modelVisible = false"> </el-button>
type="primary" </div>
:title="t('action.save')"
:loading="actionLoading"
@click="submitForm()"
/>
<!-- 按钮关闭 -->
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="modelVisible = false" />
</template> </template>
</XModal> </Dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import type { FormExpose } from '@/components/Form' import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import * as PostApi from '@/api/system/post' import * as PostApi from '@/api/system/post'
import { rules, allSchemas } from './post.data'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
// const modelVisible = ref(false) //
const modelVisible = ref(false) // const modelTitle = ref('') //
const modelTitle = ref('') // const formLoading = ref(false) // 12
const modelLoading = ref(false) // loading const formType = ref('') // create - update -
const actionType = ref('') // const formData = ref({
const actionLoading = ref(false) // Loading id: undefined,
const formRef = ref<FormExpose>() // Ref name: '',
const detailData = ref() // Ref code: '',
status: undefined,
remark: ''
})
const formRules = reactive({
name: [{ required: true, message: '岗位标题不能为空', trigger: 'blur' }],
code: [{ required: true, message: '岗位编码不能为空', trigger: 'change' }],
status: [{ required: true, message: '岗位状态不能为空', trigger: 'change' }],
remark: [{ required: false, message: '岗位内容不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
// /** 打开弹窗 */
const openModal = async (type: string, id?: number) => { const openModal = async (type: string, id?: number) => {
modelVisible.value = true modelVisible.value = true
modelLoading.value = true
modelTitle.value = t('action.' + type) modelTitle.value = t('action.' + type)
actionType.value = type formType.value = type
// resetForm()
//
if (id) { if (id) {
const res = await PostApi.getPostApi(id) formLoading.value = true
if (type === 'update') { try {
unref(formRef)?.setValues(res) formData.value = await PostApi.getPostApi(id)
} else if (type === 'detail') { } finally {
detailData.value = res formLoading.value = false
} }
} }
modelLoading.value = false
} }
defineExpose({ openModal }) // openModal defineExpose({ openModal }) // openModal
// / /** 提交表单 */
const emit = defineEmits(['success']) // success const emit = defineEmits(['success']) // success
const submitForm = async () => { const submitForm = async () => {
// //
const elForm = unref(formRef)?.getElFormRef() if (!formRef) return
if (!elForm) return const valid = await formRef.value.validate()
const valid = await elForm.validate()
if (!valid) return if (!valid) return
// //
actionLoading.value = true formLoading.value = true
try { try {
const data = unref(formRef)?.formModel as PostApi.PostVO const data = formData.value as unknown as PostApi.PostVO
if (actionType.value === 'create') { if (formType.value === 'create') {
await PostApi.createPostApi(data) await PostApi.createPostApi(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
@ -83,9 +98,23 @@ const submitForm = async () => {
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
modelVisible.value = false modelVisible.value = false
//
emit('success') emit('success')
} finally { } finally {
actionLoading.value = false formLoading.value = false
} }
} }
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
title: '',
type: undefined,
content: '',
status: undefined,
remark: ''
}
formRef.value?.resetFields()
}
</script> </script>

View File

@ -1,71 +1,192 @@
<template> <template>
<ContentWrap> <content-wrap>
<!-- 列表 --> <!-- 搜索工作栏 -->
<XTable @register="registerTable"> <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
<template #toolbar_buttons> <el-form-item label="岗位名称" prop="name">
<!-- 操作新增 --> <el-input
<XButton v-model="queryParams.name"
placeholder="请输入岗位名称"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="岗位编码" prop="code">
<el-input
v-model="queryParams.code"
placeholder="请输入岗位编码"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="parseInt(dict.value)"
:label="dict.label"
:value="parseInt(dict.value)"
/>
</el-select>
</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
type="primary" type="primary"
preIcon="ep:zoom-in"
:title="t('action.add')"
v-hasPermi="['system:post:create']"
@click="openModal('create')" @click="openModal('create')"
/> v-hasPermi="['system:notice:create']"
<!-- 操作导出 --> >
<XButton <Icon icon="ep:plus" class="mr-5px" /> 新增
type="primary" </el-button>
<el-button
type="success"
plain plain
preIcon="ep:download" @click="handleExport"
:title="t('action.export')" :loading="exportLoading"
v-hasPermi="['system:post:export']" v-hasPermi="['infra:config:export']"
@click="exportList('岗位列表.xls')" >
/> <Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
</el-form-item>
</el-form>
<!-- 列表 -->
<el-table v-loading="loading" :data="list" align="center">
<el-table-column label="岗位编号" align="center" prop="id" />
<el-table-column label="岗位名称" align="center" prop="name" />
<el-table-column label="岗位编码" align="center" prop="code" />
<el-table-column label="岗位顺序" align="center" prop="sort" />
<el-table-column label="岗位备注" align="center" prop="remark" />
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template> </template>
<template #actionbtns_default="{ row }"> </el-table-column>
<!-- 操作修改 --> <el-table-column
<XTextButton label="创建时间"
preIcon="ep:edit" align="center"
:title="t('action.edit')" prop="createTime"
width="180"
:formatter="dateFormatter"
/>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button
link
type="primary"
@click="openModal('update', scope.row.id)"
v-hasPermi="['system:post:update']" v-hasPermi="['system:post:update']"
@click="openModal('update', row?.id)" >
/> 编辑
<!-- 操作详情 --> </el-button>
<XTextButton <el-button
preIcon="ep:view" link
:title="t('action.detail')" type="danger"
v-hasPermi="['system:post:query']" @click="handleDelete(scope.row.id)"
@click="openModal('detail', row?.id)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.delete')"
v-hasPermi="['system:post:delete']" v-hasPermi="['system:post:delete']"
@click="deleteData(row?.id)" >
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/> />
</content-wrap>
<!-- 表单弹窗添加/修改 -->
<post-form ref="modalRef" @success="getList" />
</template> </template>
</XTable> <script setup lang="tsx">
</ContentWrap>
<!-- 表单弹窗添加/修改/详情 -->
<PostForm ref="modalRef" @success="reload()" />
</template>
<script setup lang="ts" name="Post">
import * as PostApi from '@/api/system/post' import * as PostApi from '@/api/system/post'
import { allSchemas } from './post.data'
import PostForm from './form.vue' import PostForm from './form.vue'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { DictTag } from '@/components/DictTag'
const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
// const loading = ref(true) //
const [registerTable, { reload, deleteData, exportList }] = useXTable({ const total = ref(0) //
allSchemas: allSchemas, // const list = ref([]) //
getListApi: PostApi.getPostPageApi, // API const queryParams = reactive({
deleteApi: PostApi.deletePostApi, // API code: '',
exportListApi: PostApi.exportPostApi // API name: '',
status: undefined,
pageNo: 1,
pageSize: 100
}) })
const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询岗位列表 */
const getList = async () => {
loading.value = true
try {
const data = await PostApi.getPostPageApi(queryParams)
// list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await PostApi.exportPostApi(queryParams)
download.excel(data, '岗位列表.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const modalRef = ref() const modalRef = ref()
const openModal = (type: string, id?: number) => { const openModal = (type: string, id?: number) => {
modalRef.value.openModal(type, id) modalRef.value.openModal(type, id)
} }
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await PostApi.deletePostApi(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script> </script>

View File

@ -1,58 +0,0 @@
import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
// 表单校验
export const rules = reactive({
name: [required],
code: [required],
sort: [required]
})
// 增删改查 CrudSchema 配置
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'id',
primaryTitle: '岗位编号',
action: true,
columns: [
{
title: '岗位名称',
field: 'name',
isSearch: true
},
{
title: '岗位编码',
field: 'code',
isSearch: true
},
{
title: '岗位顺序',
field: 'sort',
form: {
component: 'InputNumber'
}
},
{
title: t('common.status'),
field: 'status',
dictType: DICT_TYPE.COMMON_STATUS,
dictClass: 'number',
isSearch: true
},
{
title: '备注',
field: 'remark',
isTable: false
},
{
title: t('common.createTime'),
field: 'createTime',
formatter: 'formatDate',
isForm: false,
table: {
width: 180
}
}
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)