Vue3 重构:REVIEW 岗位

This commit is contained in:
YunaiV 2023-03-22 22:11:03 +08:00
parent 320cffee19
commit c424ee76e4
5 changed files with 63 additions and 67 deletions

View File

@ -10,49 +10,37 @@ export interface PostVO {
createTime?: Date
}
export interface PostPageReqVO extends PageParam {
code?: string
name?: string
status?: number
}
export interface PostExportReqVO {
code?: string
name?: string
status?: number
}
// 查询岗位列表
export const getPostPageApi = async (params: PostPageReqVO) => {
export const getPostPage = async (params: PageParam) => {
return await request.get({ url: '/system/post/page', params })
}
// 获取岗位精简信息列表
export const listSimplePostsApi = async () => {
export const getSimplePostList = async () => {
return await request.get({ url: '/system/post/list-all-simple' })
}
// 查询岗位详情
export const getPostApi = async (id: number) => {
export const getPost = async (id: number) => {
return await request.get({ url: '/system/post/get?id=' + id })
}
// 新增岗位
export const createPostApi = async (data: PostVO) => {
export const createPost = async (data: PostVO) => {
return await request.post({ url: '/system/post/create', data })
}
// 修改岗位
export const updatePostApi = async (data: PostVO) => {
export const updatePost = async (data: PostVO) => {
return await request.put({ url: '/system/post/update', data })
}
// 删除岗位
export const deletePostApi = async (id: number) => {
export const deletePost = async (id: number) => {
return await request.delete({ url: '/system/post/delete?id=' + id })
}
// 导出岗位
export const exportPostApi = async (params: PostExportReqVO) => {
export const exportPost = async (params) => {
return await request.download({ url: '/system/post/export', params })
}

View File

@ -139,7 +139,7 @@ import { FormInstance } from 'element-plus'
// import
import * as TaskAssignRuleApi from '@/api/bpm/taskAssignRule'
import { listSimpleRolesApi } from '@/api/system/role'
import { listSimplePostsApi } from '@/api/system/post'
import { getSimplePostList } from '@/api/system/post'
import { getSimpleUserList } from '@/api/system/user'
import { listSimpleUserGroup } from '@/api/bpm/userGroup'
import { listSimpleDeptApi } from '@/api/system/dept'
@ -336,7 +336,7 @@ onMounted(() => {
})
//
postOptions.value = []
listSimplePostsApi().then((data) => {
getSimplePostList().then((data) => {
postOptions.value.push(...data)
})
//

View File

@ -37,6 +37,7 @@
</template>
<script setup lang="ts">
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { CommonStatusEnum } from '@/utils/constants'
import * as PostApi from '@/api/system/post'
const { t } = useI18n() //
@ -50,7 +51,8 @@ const formData = ref({
id: undefined,
name: '',
code: '',
status: undefined,
sort: undefined,
status: CommonStatusEnum.ENABLE,
remark: ''
})
const formRules = reactive({
@ -71,7 +73,7 @@ const openModal = async (type: string, id?: number) => {
if (id) {
formLoading.value = true
try {
formData.value = await PostApi.getPostApi(id)
formData.value = await PostApi.getPost(id)
} finally {
formLoading.value = false
}
@ -91,10 +93,10 @@ const submitForm = async () => {
try {
const data = formData.value as unknown as PostApi.PostVO
if (formType.value === 'create') {
await PostApi.createPostApi(data)
await PostApi.createPost(data)
message.success(t('common.createSuccess'))
} else {
await PostApi.updatePostApi(data)
await PostApi.updatePost(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
@ -109,10 +111,10 @@ const submitForm = async () => {
const resetForm = () => {
formData.value = {
id: undefined,
title: '',
type: undefined,
content: '',
status: undefined,
name: '',
code: '',
sort: undefined,
status: CommonStatusEnum.ENABLE,
remark: ''
}
formRef.value?.resetFields()

View File

@ -1,7 +1,13 @@
<template>
<content-wrap>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="岗位名称" prop="name">
<el-input
v-model="queryParams.name"
@ -21,10 +27,10 @@
<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)"
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:label="dict.label"
:value="parseInt(dict.value)"
:value="dict.value"
/>
</el-select>
</el-form-item>
@ -49,15 +55,16 @@
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<!-- 列表 -->
<ContentWrap>
<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" />
@ -98,18 +105,17 @@
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</content-wrap>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<post-form ref="modalRef" @success="getList" />
<PostForm ref="formRef" @success="getList" />
</template>
<script setup lang="tsx">
import * as PostApi from '@/api/system/post'
import PostForm from './form.vue'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { DictTag } from '@/components/DictTag'
import * as PostApi from '@/api/system/post'
import PostForm from './PostForm.vue'
const message = useMessage() //
const { t } = useI18n() //
@ -118,20 +124,20 @@ const loading = ref(true) // 列表的加载中
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
code: '',
name: '',
status: undefined,
pageNo: 1,
pageSize: 100
status: undefined
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询岗位列表 */
const getList = async () => {
loading.value = true
try {
const data = await PostApi.getPostPageApi(queryParams)
const data = await PostApi.getPostPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
@ -139,21 +145,6 @@ const getList = async () => {
}
}
/** 导出按钮操作 */
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
@ -167,9 +158,9 @@ const resetQuery = () => {
}
/** 添加/修改操作 */
const modalRef = ref()
const formRef = ref()
const openModal = (type: string, id?: number) => {
modalRef.value.openModal(type, id)
formRef.value.openModal(type, id)
}
/** 删除按钮操作 */
@ -178,13 +169,28 @@ const handleDelete = async (id: number) => {
//
await message.delConfirm()
//
await PostApi.deletePostApi(id)
await PostApi.deletePost(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await PostApi.exportPost(queryParams)
download.excel(data, '岗位列表.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()

View File

@ -273,7 +273,7 @@ import { rules, allSchemas } from './user.data'
import * as UserApi from '@/api/system/user'
import { listSimpleDeptApi } from '@/api/system/dept'
import { listSimpleRolesApi } from '@/api/system/role'
import { listSimplePostsApi, PostVO } from '@/api/system/post'
import { getSimplePostList, PostVO } from '@/api/system/post'
import {
aassignUserRoleApi,
listUserRolesApi,
@ -329,7 +329,7 @@ const postOptions = ref<PostVO[]>([]) //岗位列表
//
const getPostOptions = async () => {
const res = await listSimplePostsApi()
const res = await getSimplePostList()
postOptions.value.push(...res)
}
const dataFormater = (val) => {