提交 | 用户 | 时间
|
314507
|
1 |
<template> |
H |
2 |
<!-- 搜索工作栏 --> |
|
3 |
<ContentWrap> |
|
4 |
<el-form |
|
5 |
class="-mb-15px" |
|
6 |
:model="queryParams" |
|
7 |
ref="queryFormRef" |
|
8 |
:inline="true" |
|
9 |
label-width="68px" |
|
10 |
> |
|
11 |
<el-form-item label="部门名称" prop="name"> |
|
12 |
<el-input |
|
13 |
v-model="queryParams.name" |
|
14 |
placeholder="请输入部门名称" |
|
15 |
clearable |
|
16 |
class="!w-240px" |
|
17 |
/> |
|
18 |
</el-form-item> |
|
19 |
<el-form-item label="部门状态" prop="status"> |
|
20 |
<el-select |
|
21 |
v-model="queryParams.status" |
|
22 |
placeholder="请选择部门状态" |
|
23 |
clearable |
|
24 |
class="!w-240px" |
|
25 |
> |
|
26 |
<el-option |
|
27 |
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" |
|
28 |
:key="dict.value" |
|
29 |
:label="dict.label" |
|
30 |
:value="dict.value" |
|
31 |
/> |
|
32 |
</el-select> |
|
33 |
</el-form-item> |
|
34 |
<el-form-item> |
|
35 |
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> |
|
36 |
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> |
|
37 |
<el-button |
|
38 |
type="primary" |
|
39 |
plain |
|
40 |
@click="openForm('create')" |
|
41 |
v-hasPermi="['system:dept:create']" |
|
42 |
> |
|
43 |
<Icon icon="ep:plus" class="mr-5px" /> 新增 |
|
44 |
</el-button> |
|
45 |
<el-button type="danger" plain @click="toggleExpandAll"> |
|
46 |
<Icon icon="ep:sort" class="mr-5px" /> 展开/折叠 |
|
47 |
</el-button> |
|
48 |
</el-form-item> |
|
49 |
</el-form> |
|
50 |
</ContentWrap> |
|
51 |
|
|
52 |
<!-- 列表 --> |
|
53 |
<ContentWrap> |
|
54 |
<el-table |
|
55 |
v-loading="loading" |
|
56 |
:data="list" |
|
57 |
row-key="id" |
|
58 |
:default-expand-all="isExpandAll" |
|
59 |
v-if="refreshTable" |
|
60 |
> |
|
61 |
<el-table-column prop="name" label="部门名称" /> |
|
62 |
<el-table-column prop="leader" label="负责人"> |
|
63 |
<template #default="scope"> |
|
64 |
{{ userList.find((user) => user.id === scope.row.leaderUserId)?.nickname }} |
|
65 |
</template> |
|
66 |
</el-table-column> |
|
67 |
<el-table-column prop="sort" label="排序" /> |
|
68 |
<el-table-column prop="status" label="状态"> |
|
69 |
<template #default="scope"> |
|
70 |
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" /> |
|
71 |
</template> |
|
72 |
</el-table-column> |
|
73 |
<el-table-column |
|
74 |
label="创建时间" |
|
75 |
align="center" |
|
76 |
prop="createTime" |
|
77 |
width="180" |
|
78 |
:formatter="dateFormatter" |
|
79 |
/> |
|
80 |
<el-table-column label="操作" align="center"> |
|
81 |
<template #default="scope"> |
|
82 |
<el-button |
|
83 |
link |
|
84 |
type="primary" |
|
85 |
@click="openForm('update', scope.row.id)" |
|
86 |
v-hasPermi="['system:dept:update']" |
|
87 |
> |
|
88 |
修改 |
|
89 |
</el-button> |
|
90 |
<el-button |
|
91 |
link |
|
92 |
type="danger" |
|
93 |
@click="handleDelete(scope.row.id)" |
|
94 |
v-hasPermi="['system:dept:delete']" |
|
95 |
> |
|
96 |
删除 |
|
97 |
</el-button> |
|
98 |
</template> |
|
99 |
</el-table-column> |
|
100 |
</el-table> |
|
101 |
</ContentWrap> |
|
102 |
|
|
103 |
<!-- 表单弹窗:添加/修改 --> |
|
104 |
<DeptForm ref="formRef" @success="getList" /> |
|
105 |
</template> |
|
106 |
<script lang="ts" setup> |
|
107 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
108 |
import { dateFormatter } from '@/utils/formatTime' |
|
109 |
import { handleTree } from '@/utils/tree' |
|
110 |
import * as DeptApi from '@/api/system/dept' |
|
111 |
import DeptForm from './DeptForm.vue' |
|
112 |
import * as UserApi from '@/api/system/user' |
|
113 |
|
|
114 |
defineOptions({ name: 'SystemDept' }) |
|
115 |
|
|
116 |
const message = useMessage() // 消息弹窗 |
|
117 |
const { t } = useI18n() // 国际化 |
|
118 |
|
|
119 |
const loading = ref(true) // 列表的加载中 |
|
120 |
const list = ref() // 列表的数据 |
|
121 |
const queryParams = reactive({ |
|
122 |
pageNo: 1, |
|
123 |
pageSize: 100, |
|
124 |
name: undefined, |
|
125 |
status: undefined |
|
126 |
}) |
|
127 |
const queryFormRef = ref() // 搜索的表单 |
|
128 |
const isExpandAll = ref(true) // 是否展开,默认全部展开 |
|
129 |
const refreshTable = ref(true) // 重新渲染表格状态 |
|
130 |
const userList = ref<UserApi.UserVO[]>([]) // 用户列表 |
|
131 |
|
|
132 |
/** 查询部门列表 */ |
|
133 |
const getList = async () => { |
|
134 |
loading.value = true |
|
135 |
try { |
|
136 |
const data = await DeptApi.getDeptPage(queryParams) |
|
137 |
list.value = handleTree(data) |
|
138 |
} finally { |
|
139 |
loading.value = false |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
/** 展开/折叠操作 */ |
|
144 |
const toggleExpandAll = () => { |
|
145 |
refreshTable.value = false |
|
146 |
isExpandAll.value = !isExpandAll.value |
|
147 |
nextTick(() => { |
|
148 |
refreshTable.value = true |
|
149 |
}) |
|
150 |
} |
|
151 |
|
|
152 |
/** 搜索按钮操作 */ |
|
153 |
const handleQuery = () => { |
|
154 |
getList() |
|
155 |
} |
|
156 |
|
|
157 |
/** 重置按钮操作 */ |
|
158 |
const resetQuery = () => { |
|
159 |
queryParams.pageNo = 1 |
|
160 |
queryFormRef.value.resetFields() |
|
161 |
handleQuery() |
|
162 |
} |
|
163 |
|
|
164 |
/** 添加/修改操作 */ |
|
165 |
const formRef = ref() |
|
166 |
const openForm = (type: string, id?: number) => { |
|
167 |
formRef.value.open(type, id) |
|
168 |
} |
|
169 |
|
|
170 |
/** 删除按钮操作 */ |
|
171 |
const handleDelete = async (id: number) => { |
|
172 |
try { |
|
173 |
// 删除的二次确认 |
|
174 |
await message.delConfirm() |
|
175 |
// 发起删除 |
|
176 |
await DeptApi.deleteDept(id) |
|
177 |
message.success(t('common.delSuccess')) |
|
178 |
// 刷新列表 |
|
179 |
await getList() |
|
180 |
} catch {} |
|
181 |
} |
|
182 |
|
|
183 |
/** 初始化 **/ |
|
184 |
onMounted(async () => { |
|
185 |
await getList() |
|
186 |
// 获取用户列表 |
|
187 |
userList.value = await UserApi.getSimpleUserList() |
|
188 |
}) |
|
189 |
</script> |