Vue3 重构:REVIEW 岗位

pull/43/MERGE
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 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 }) 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' }) 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 }) 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 }) 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 }) 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 }) 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 }) return await request.download({ url: '/system/post/export', params })
} }

View File

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

View File

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

View File

@ -1,7 +1,13 @@
<template> <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-form-item label="岗位名称" prop="name">
<el-input <el-input
v-model="queryParams.name" v-model="queryParams.name"
@ -21,10 +27,10 @@
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable> <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
<el-option <el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)" v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="parseInt(dict.value)" :key="dict.value"
:label="dict.label" :label="dict.label"
:value="parseInt(dict.value)" :value="dict.value"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -49,15 +55,16 @@
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</ContentWrap>
<!-- 列表 --> <!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" align="center"> <el-table v-loading="loading" :data="list" align="center">
<el-table-column label="岗位编号" align="center" prop="id" /> <el-table-column label="岗位编号" align="center" prop="id" />
<el-table-column label="岗位名称" align="center" prop="name" /> <el-table-column label="岗位名称" align="center" prop="name" />
<el-table-column label="岗位编码" align="center" prop="code" /> <el-table-column label="岗位编码" align="center" prop="code" />
<el-table-column label="岗位顺序" align="center" prop="sort" /> <el-table-column label="岗位顺序" align="center" prop="sort" />
<el-table-column label="岗位备注" align="center" prop="remark" /> <el-table-column label="岗位备注" align="center" prop="remark" />
<el-table-column label="状态" align="center" prop="status"> <el-table-column label="状态" align="center" prop="status">
<template #default="scope"> <template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" /> <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
@ -98,18 +105,17 @@
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
@pagination="getList" @pagination="getList"
/> />
</content-wrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<post-form ref="modalRef" @success="getList" /> <PostForm ref="formRef" @success="getList" />
</template> </template>
<script setup lang="tsx"> <script setup lang="tsx">
import * as PostApi from '@/api/system/post' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import PostForm from './form.vue'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download' 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 message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
@ -118,20 +124,20 @@ const loading = ref(true) // 列表的加载中
const total = ref(0) // const total = ref(0) //
const list = ref([]) // const list = ref([]) //
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1,
pageSize: 10,
code: '', code: '',
name: '', name: '',
status: undefined, status: undefined
pageNo: 1,
pageSize: 100
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) // const exportLoading = ref(false) //
/** 查询岗位列表 */ /** 查询岗位列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await PostApi.getPostPageApi(queryParams) const data = await PostApi.getPostPage(queryParams)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } 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 = () => { const handleQuery = () => {
queryParams.pageNo = 1 queryParams.pageNo = 1
@ -167,9 +158,9 @@ const resetQuery = () => {
} }
/** 添加/修改操作 */ /** 添加/修改操作 */
const modalRef = ref() const formRef = ref()
const openModal = (type: string, id?: number) => { 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 message.delConfirm()
// //
await PostApi.deletePostApi(id) await PostApi.deletePost(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// //
await getList() await getList()
} catch {} } 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(() => { onMounted(() => {
getList() getList()

View File

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