Skip to content

Commit 15ac1d9

Browse files
author
admin
committed
采用ep重写dept页面
1 parent 2cf384d commit 15ac1d9

File tree

4 files changed

+346
-243
lines changed

4 files changed

+346
-243
lines changed

src/types/auto-components.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ declare module '@vue/runtime-core' {
2323
DictTag: typeof import('./../components/DictTag/src/DictTag.vue')['default']
2424
Echart: typeof import('./../components/Echart/src/Echart.vue')['default']
2525
Editor: typeof import('./../components/Editor/src/Editor.vue')['default']
26-
ElAutoResizer: typeof import('element-plus/es')['ElAutoResizer']
27-
ElAvatar: typeof import('element-plus/es')['ElAvatar']
2826
ElBadge: typeof import('element-plus/es')['ElBadge']
2927
ElButton: typeof import('element-plus/es')['ElButton']
3028
ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup']
@@ -35,7 +33,6 @@ declare module '@vue/runtime-core' {
3533
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
3634
ElCollapseTransition: typeof import('element-plus/es')['ElCollapseTransition']
3735
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
38-
ElDatePicker: typeof import('element-plus/es')['ElDatePicker']
3936
ElDescriptions: typeof import('element-plus/es')['ElDescriptions']
4037
ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem']
4138
ElDialog: typeof import('element-plus/es')['ElDialog']
@@ -54,34 +51,23 @@ declare module '@vue/runtime-core' {
5451
ElForm: typeof import('element-plus/es')['ElForm']
5552
ElFormItem: typeof import('element-plus/es')['ElFormItem']
5653
ElIcon: typeof import('element-plus/es')['ElIcon']
57-
ElImage: typeof import('element-plus/es')['ElImage']
5854
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
5955
ElInput: typeof import('element-plus/es')['ElInput']
6056
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
6157
ElLink: typeof import('element-plus/es')['ElLink']
6258
ElOption: typeof import('element-plus/es')['ElOption']
6359
ElPagination: typeof import('element-plus/es')['ElPagination']
6460
ElPopover: typeof import('element-plus/es')['ElPopover']
65-
ElRadio: typeof import('element-plus/es')['ElRadio']
66-
ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
67-
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
6861
ElRow: typeof import('element-plus/es')['ElRow']
6962
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
7063
ElSelect: typeof import('element-plus/es')['ElSelect']
7164
ElSkeleton: typeof import('element-plus/es')['ElSkeleton']
72-
ElSpace: typeof import('element-plus/es')['ElSpace']
7365
ElSwitch: typeof import('element-plus/es')['ElSwitch']
7466
ElTable: typeof import('element-plus/es')['ElTable']
7567
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
76-
ElTableV2: typeof import('element-plus/es')['ElTableV2']
7768
ElTabPane: typeof import('element-plus/es')['ElTabPane']
7869
ElTabs: typeof import('element-plus/es')['ElTabs']
79-
ElTag: typeof import('element-plus/es')['ElTag']
80-
ElTimeline: typeof import('element-plus/es')['ElTimeline']
81-
ElTimelineItem: typeof import('element-plus/es')['ElTimelineItem']
8270
ElTooltip: typeof import('element-plus/es')['ElTooltip']
83-
ElTransfer: typeof import('element-plus/es')['ElTransfer']
84-
ElTree: typeof import('element-plus/es')['ElTree']
8571
ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect']
8672
ElUpload: typeof import('element-plus/es')['ElUpload']
8773
Error: typeof import('./../components/Error/src/Error.vue')['default']

src/views/system/dept/dept.data.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/views/system/dept/form.vue

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<template>
2+
<Dialog :title="modelTitle" v-model="modelVisible" width="800">
3+
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px">
4+
<el-row>
5+
<el-col :span="24" v-if="formData.parentId !== 0">
6+
<el-form-item label="上级部门" prop="parentId">
7+
<el-tree-select
8+
v-model="formData.parentId"
9+
:data="deptOptions"
10+
:props="{ value: 'id', label: 'name', children: 'children' }"
11+
value-key="deptId"
12+
placeholder="选择上级部门"
13+
check-strictly
14+
/>
15+
</el-form-item>
16+
</el-col>
17+
<el-col :span="12">
18+
<el-form-item label="部门名称" prop="name">
19+
<el-input v-model="formData.name" placeholder="请输入部门名称" />
20+
</el-form-item>
21+
</el-col>
22+
<el-col :span="12">
23+
<el-form-item label="显示排序" prop="sort">
24+
<el-input-number v-model="formData.sort" controls-position="right" :min="0" />
25+
</el-form-item>
26+
</el-col>
27+
<el-col :span="12">
28+
<el-form-item label="负责人" prop="leaderUserId">
29+
<el-select
30+
v-model="formData.leaderUserId"
31+
placeholder="请输入负责人"
32+
clearable
33+
style="width: 100%"
34+
>
35+
<el-option
36+
v-for="item in props.userOption"
37+
:key="item.id"
38+
:label="item.nickname"
39+
:value="item.id"
40+
/>
41+
</el-select>
42+
</el-form-item>
43+
</el-col>
44+
<el-col :span="12">
45+
<el-form-item label="联系电话" prop="phone">
46+
<el-input v-model="formData.phone" placeholder="请输入联系电话" maxlength="11" />
47+
</el-form-item>
48+
</el-col>
49+
<el-col :span="12">
50+
<el-form-item label="邮箱" prop="email">
51+
<el-input v-model="formData.email" placeholder="请输入邮箱" maxlength="50" />
52+
</el-form-item>
53+
</el-col>
54+
<el-col :span="12">
55+
<el-form-item label="状态" prop="status">
56+
<el-select v-model="formData.status" placeholder="请选择状态" clearable>
57+
<el-option
58+
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
59+
:key="parseInt(dict.value)"
60+
:label="dict.label"
61+
:value="parseInt(dict.value)"
62+
/>
63+
</el-select>
64+
</el-form-item>
65+
</el-col>
66+
</el-row>
67+
</el-form>
68+
69+
<template #footer>
70+
<div class="dialog-footer">
71+
<el-button type="primary" @click="submitForm">确 定</el-button>
72+
<el-button @click="modelVisible = false">取 消</el-button>
73+
</div>
74+
</template>
75+
</Dialog>
76+
</template>
77+
78+
<script setup lang="ts">
79+
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
80+
import * as DeptApi from '@/api/system/dept'
81+
import { UserVO } from '@/api/system/user'
82+
import { handleTree } from '@/utils/tree'
83+
const { t } = useI18n() // 国际化
84+
const message = useMessage() // 消息弹窗
85+
const modelVisible = ref(false) // 弹窗的是否展示
86+
const modelTitle = ref('') // 弹窗的标题
87+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
88+
const formType = ref('') // 表单的类型:create - 新增;update - 修改
89+
const formRef = ref() // 表单 Ref
90+
const deptOptions = ref() // 树形结构
91+
92+
const formData = ref({
93+
id: undefined,
94+
title: '',
95+
parentId: undefined,
96+
name: undefined,
97+
sort: undefined,
98+
leaderUserId: undefined,
99+
phone: undefined,
100+
email: undefined,
101+
status: undefined
102+
})
103+
const props = defineProps({
104+
userOption: {
105+
type: Array,
106+
default: () => [] as UserVO[]
107+
}
108+
})
109+
110+
const formRules = reactive({
111+
parentId: [{ required: true, message: '上级部门不能为空', trigger: 'blur' }],
112+
name: [{ required: true, message: '部门名称不能为空', trigger: 'blur' }],
113+
order: [{ required: true, message: '显示排序不能为空', trigger: 'blur' }],
114+
email: [{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }],
115+
phone: [
116+
{ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请输入正确的手机号码', trigger: 'blur' }
117+
]
118+
})
119+
120+
/** 打开弹窗 */
121+
const openModal = async (type: string, id?: number) => {
122+
modelVisible.value = true
123+
modelTitle.value = t('action.' + type)
124+
formType.value = type
125+
resetForm()
126+
console.log(id)
127+
// 修改时,设置数据
128+
if (id) {
129+
formLoading.value = true
130+
try {
131+
formData.value = await DeptApi.getDeptApi(id)
132+
} finally {
133+
formLoading.value = false
134+
}
135+
}
136+
}
137+
138+
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
139+
140+
/** 提交表单 */
141+
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
142+
const submitForm = async () => {
143+
// 校验表单
144+
if (!formRef) return
145+
const valid = await formRef.value.validate()
146+
if (!valid) return
147+
// 提交请求
148+
formLoading.value = true
149+
try {
150+
const data = formData.value as unknown as DeptApi.DeptVO
151+
if (formType.value === 'create') {
152+
await DeptApi.createDeptApi(data)
153+
message.success(t('common.createSuccess'))
154+
} else {
155+
await DeptApi.updateDeptApi(data)
156+
message.success(t('common.updateSuccess'))
157+
}
158+
modelVisible.value = false
159+
// 发送操作成功的事件
160+
emit('success')
161+
} finally {
162+
formLoading.value = false
163+
}
164+
}
165+
166+
/** 重置表单 */
167+
const resetForm = () => {
168+
formData.value = {
169+
id: undefined,
170+
title: '',
171+
parentId: undefined,
172+
name: undefined,
173+
sort: undefined,
174+
leaderUserId: undefined,
175+
phone: undefined,
176+
email: undefined,
177+
status: undefined
178+
}
179+
formRef.value?.resetFields()
180+
}
181+
182+
// 获取下拉框[上级]的数据
183+
const getTree = async () => {
184+
deptOptions.value = []
185+
const res = await DeptApi.listSimpleDeptApi()
186+
let dept: Tree = { id: 0, name: '顶级部门', children: [] }
187+
dept.children = handleTree(res)
188+
deptOptions.value.push(dept)
189+
}
190+
191+
// ========== 初始化 ==========
192+
onMounted(async () => {
193+
await getTree()
194+
})
195+
</script>

0 commit comments

Comments
 (0)