Skip to content

Commit bdca75d

Browse files
committed
refactor: 优化系统管理相关代码
1 parent 5de731d commit bdca75d

33 files changed

+461
-490
lines changed

src/apis/system/dict.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type * from './type'
66
const BASE_URL = '/system/dict'
77

88
/** @desc 查询字典列表 */
9-
export function listDict(query: T.DictQuery) {
9+
export function listDict(query?: T.DictQuery) {
1010
return http.get<T.DictResp[]>(`${BASE_URL}/list`, query)
1111
}
1212

src/components/GiCell/GiCellTag.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<template>
22
<span v-if="!dictItem"></span>
3-
<span v-else-if="!dictItem.extend">{{ dictItem.label }}</span>
4-
<a-tag v-else-if="dictItem.extend === 'primary'" color="arcoblue">{{ dictItem.label }}</a-tag>
5-
<a-tag v-else-if="dictItem.extend === 'success'" color="green">{{ dictItem.label }}</a-tag>
6-
<a-tag v-else-if="dictItem.extend === 'warning'" color="orangered">{{ dictItem.label }}</a-tag>
7-
<a-tag v-else-if="dictItem.extend === 'error'" color="red">{{ dictItem.label }}</a-tag>
8-
<a-tag v-else-if="dictItem.extend === 'default'" color="gray">{{ dictItem.label }}</a-tag>
9-
<a-tag v-else :color="dictItem.extend">{{ dictItem.label }}</a-tag>
3+
<span v-else-if="!dictItem.extra">{{ dictItem.label }}</span>
4+
<a-tag v-else-if="dictItem.extra === 'primary'" color="arcoblue">{{ dictItem.label }}</a-tag>
5+
<a-tag v-else-if="dictItem.extra === 'success'" color="green">{{ dictItem.label }}</a-tag>
6+
<a-tag v-else-if="dictItem.extra === 'warning'" color="orangered">{{ dictItem.label }}</a-tag>
7+
<a-tag v-else-if="dictItem.extra === 'error'" color="red">{{ dictItem.label }}</a-tag>
8+
<a-tag v-else-if="dictItem.extra === 'default'" color="gray">{{ dictItem.label }}</a-tag>
9+
<a-tag v-else :color="dictItem.extra">{{ dictItem.label }}</a-tag>
1010
</template>
1111

1212
<script setup lang="ts">

src/components/UserSelect/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<template>
22
<div class="container">
33
<a-row :gutter="16">
4-
<a-col :span="24" :md="18">
4+
<a-col :span="24" :md="17">
55
<GiTable
66
v-model:selectedKeys="selectedKeys"
77
row-key="id"
88
:data="dataList"
99
:columns="listColumns"
1010
:loading="loading"
11-
:scroll="{ x: '100%', y: '100%', minWidth: 900 }"
11+
:scroll="{ x: '100%', y: '100%', minWidth: 500 }"
1212
style="max-height: 600px"
1313
:pagination="pagination"
1414
:disabled-tools="['size', 'fullscreen', 'setting', 'refresh']"
@@ -57,7 +57,7 @@
5757
</template>
5858
</GiTable>
5959
</a-col>
60-
<a-col :span="24" :md="6" class="section">
60+
<a-col :span="24" :md="7" class="section">
6161
<a-card>
6262
<template #title>已选择: {{ selectedKeys.length }}</template>
6363
<a-table :columns="selectedColumns" :data="[...selectedData.values()]" :pagination="paginationOptions">

src/config/setting.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"theme": "light",
33
"themeColor": "#165DFF",
44
"tab": true,
5-
"tabMode": "card",
5+
"tabMode": "card-gutter",
66
"animate": false,
77
"animateMode": "zoom-fade",
88
"menuCollapse": true,

src/views/open/app/AppDetailDrawer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<a-drawer v-model:visible="visible" title="应用详情" :width="width >= 580 ? 580 : '100%'" :footer="false">
2+
<a-drawer v-model:visible="visible" title="应用详情" :width="width >= 600 ? 600 : '100%'" :footer="false">
33
<a-descriptions :column="1" size="large" class="general-description" bordered>
44
<a-descriptions-item label="应用名称">{{ dataDetail?.name }}</a-descriptions-item>
55
<a-descriptions-item label="APPKEY">{{ dataDetail?.appKey }}</a-descriptions-item>

src/views/setting/components/VerifyModel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<a-modal
33
v-model:visible="visible" :title="title" :mask-closable="false" :esc-to-close="false"
4-
:width="width >= 500 ? 500 : '100%'" draggable @before-ok="save" @ok="saveAfter" @close="reset"
4+
:width="width >= 600 ? 600 : '100%'" draggable @before-ok="save" @ok="saveAfter" @close="reset"
55
>
66
<GiForm ref="formRef" v-model="form" :options="options" :columns="columns">
77
<template #captcha>

src/views/system/dept/DeptAddModal.vue

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
:title="title"
55
:mask-closable="false"
66
:esc-to-close="false"
7-
:modal-style="{ maxWidth: '520px' }"
8-
width="90%"
7+
:width="width >= 500 ? 500 : '100%'"
98
draggable
109
@before-ok="save"
1110
@close="reset"
@@ -16,22 +15,41 @@
1615

1716
<script setup lang="ts">
1817
import { Message } from '@arco-design/web-vue'
19-
import { addDept, getDept, updateDept } from '@/apis/system'
20-
import { type Columns, GiForm } from '@/components/GiForm'
18+
import { useWindowSize } from '@vueuse/core'
19+
import { mapTree } from 'xe-utils'
20+
import { type DeptResp, addDept, getDept, updateDept } from '@/apis/system/dept'
21+
import { type Columns, GiForm, type Options } from '@/components/GiForm'
2122
import { useForm } from '@/hooks'
22-
import { useDept } from '@/hooks/app'
23+
24+
interface Props {
25+
depts: DeptResp[]
26+
}
27+
const props = withDefaults(defineProps<Props>(), {
28+
depts: () => [],
29+
})
2330
2431
const emit = defineEmits<{
2532
(e: 'save-success'): void
2633
}>()
2734
28-
const { deptList, getDeptList } = useDept()
35+
const { width } = useWindowSize()
2936
3037
const dataId = ref('')
38+
const visible = ref(false)
3139
const isUpdate = computed(() => !!dataId.value)
3240
const title = computed(() => (isUpdate.value ? '修改部门' : '新增部门'))
3341
const formRef = ref<InstanceType<typeof GiForm>>()
3442
43+
// 转换为部门树
44+
const deptSelectTree = computed(() => {
45+
const data = JSON.parse(JSON.stringify(props.depts)) as DeptResp[]
46+
return mapTree(data, (i) => ({
47+
key: i.id,
48+
title: i.name,
49+
children: i.children,
50+
}))
51+
})
52+
3553
const options: Options = {
3654
form: { size: 'large' },
3755
btns: { hide: true },
@@ -42,7 +60,7 @@ const columns: Columns = reactive([
4260
label: '上级部门',
4361
field: 'parentId',
4462
type: 'tree-select',
45-
data: deptList,
63+
data: deptSelectTree,
4664
hide: (form) => {
4765
return form.parentId === 0
4866
},
@@ -111,30 +129,6 @@ const reset = () => {
111129
resetForm()
112130
}
113131
114-
const visible = ref(false)
115-
// 新增
116-
const onAdd = (id?: string) => {
117-
if (!deptList.value.length) {
118-
getDeptList()
119-
}
120-
reset()
121-
form.parentId = id
122-
dataId.value = ''
123-
visible.value = true
124-
}
125-
126-
// 修改
127-
const onUpdate = async (id: string) => {
128-
if (!deptList.value.length) {
129-
await getDeptList()
130-
}
131-
reset()
132-
dataId.value = id
133-
const res = await getDept(id)
134-
Object.assign(form, res.data)
135-
visible.value = true
136-
}
137-
138132
// 保存
139133
const save = async () => {
140134
try {
@@ -147,14 +141,31 @@ const save = async () => {
147141
await addDept(form)
148142
Message.success('新增成功')
149143
}
150-
// 更新部门树
151-
await getDeptList()
152144
emit('save-success')
153145
return true
154146
} catch (error) {
155147
return false
156148
}
157149
}
158150
151+
// 新增
152+
const onAdd = (id?: string) => {
153+
reset()
154+
form.parentId = id
155+
dataId.value = ''
156+
visible.value = true
157+
}
158+
159+
// 修改
160+
const onUpdate = async (id: string) => {
161+
reset()
162+
dataId.value = id
163+
const { data } = await getDept(id)
164+
Object.assign(form, data)
165+
visible.value = true
166+
}
167+
159168
defineExpose({ onAdd, onUpdate })
160169
</script>
170+
171+
<style lang="scss" scoped></style>

src/views/system/dept/index.vue

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
<div class="table-page">
33
<GiTable
44
ref="tableRef"
5-
row-key="id"
65
title="部门管理"
6+
row-key="id"
77
:data="dataList"
88
:columns="columns"
99
:loading="loading"
1010
:scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
1111
:pagination="false"
12-
:disabled-tools="['size']"
1312
:disabled-column-keys="['name']"
1413
@refresh="search"
1514
>
@@ -18,7 +17,7 @@
1817
<IconRight v-else />
1918
</template>
2019
<template #toolbar-left>
21-
<a-input v-model="name" placeholder="请输入名称" allow-clear @change="search">
20+
<a-input v-model="name" placeholder="请输入名称" allow-clear>
2221
<template #prefix><icon-search /></template>
2322
</a-input>
2423
<a-button @click="reset">
@@ -45,38 +44,38 @@
4544
</template>
4645
<template #action="{ record }">
4746
<a-space>
48-
<a-link v-permission="['system:dept:update']" @click="onUpdate(record)">修改</a-link>
49-
<a-link v-permission="['system:dept:add']" @click="onAdd(record.id)">新增</a-link>
47+
<a-link v-permission="['system:dept:update']" title="修改" @click="onUpdate(record)">修改</a-link>
5048
<a-link
5149
v-permission="['system:dept:delete']"
5250
status="danger"
53-
:title="record.isSystem ? '系统内置数据不能删除' : undefined"
5451
:disabled="record.isSystem"
52+
:title="record.isSystem ? '系统内置数据不能删除' : '删除'"
5553
@click="onDelete(record)"
5654
>
5755
删除
5856
</a-link>
57+
<a-link v-permission="['system:dept:add']" title="新增" @click="onAdd(record.id)">新增</a-link>
5958
</a-space>
6059
</template>
6160
</GiTable>
6261

63-
<DeptAddModal ref="DeptAddModalRef" @save-success="search" />
62+
<DeptAddModal ref="DeptAddModalRef" :depts="dataList" @save-success="search" />
6463
</div>
6564
</template>
6665

6766
<script setup lang="ts">
6867
import DeptAddModal from './DeptAddModal.vue'
69-
import { type DeptQuery, type DeptResp, deleteDept, exportDept, listDept } from '@/apis/system'
70-
import type GiTable from '@/components/GiTable/index.vue'
68+
import { type DeptQuery, type DeptResp, deleteDept, exportDept, listDept } from '@/apis/system/dept'
7169
import type { TableInstanceColumns } from '@/components/GiTable/type'
70+
import type GiTable from '@/components/GiTable/index.vue'
7271
import { useDownload, useTable } from '@/hooks'
7372
import { isMobile } from '@/utils'
7473
import has from '@/utils/has'
7574
7675
defineOptions({ name: 'SystemDept' })
7776
78-
const tableRef = ref<InstanceType<typeof GiTable>>()
7977
const queryForm = reactive<DeptQuery>({})
78+
const tableRef = ref<InstanceType<typeof GiTable>>()
8079
const {
8180
tableData,
8281
loading,
@@ -92,7 +91,6 @@ const {
9291
})
9392
9493
// 过滤树
95-
const name = ref('')
9694
const searchData = (name: string) => {
9795
const loop = (data: DeptResp[]) => {
9896
const result = [] as DeptResp[]
@@ -114,25 +112,27 @@ const searchData = (name: string) => {
114112
return loop(tableData.value)
115113
}
116114
115+
const name = ref('')
117116
const dataList = computed(() => {
118117
if (!name.value) return tableData.value
119118
return searchData(name.value)
120119
})
121120
122121
const columns: TableInstanceColumns[] = [
123122
{ title: '名称', dataIndex: 'name', minWidth: 170, ellipsis: true, tooltip: true },
124-
{ title: '状态', slotName: 'status', align: 'center' },
123+
{ title: '状态', dataIndex: 'status', slotName: 'status', align: 'center' },
125124
{ title: '排序', dataIndex: 'sort', align: 'center', show: false },
126-
{ title: '系统内置', slotName: 'isSystem', align: 'center', show: false },
125+
{ title: '系统内置', dataIndex: 'isSystem', slotName: 'isSystem', align: 'center', show: false },
127126
{ title: '描述', dataIndex: 'description', ellipsis: true, tooltip: true },
128127
{ title: '创建人', dataIndex: 'createUserString', ellipsis: true, tooltip: true, show: false },
129128
{ title: '创建时间', dataIndex: 'createTime', width: 180 },
130129
{ title: '修改人', dataIndex: 'updateUserString', ellipsis: true, tooltip: true, show: false },
131130
{ title: '修改时间', dataIndex: 'updateTime', width: 180, show: false },
132131
{
133132
title: '操作',
133+
dataIndex: 'action',
134134
slotName: 'action',
135-
width: 180,
135+
width: 160,
136136
align: 'center',
137137
fixed: !isMobile() ? 'right' : undefined,
138138
show: has.hasPermOr(['system:dept:update', 'system:dept:delete', 'system:dept:add']),
@@ -147,7 +147,7 @@ const reset = () => {
147147
// 删除
148148
const onDelete = (record: DeptResp) => {
149149
return handleDelete(() => deleteDept(record.id), {
150-
content: `是否确定删除 [${record.name}]`,
150+
content: `是否确定删除部门「${record.name}`,
151151
showModal: true,
152152
})
153153
}

src/views/system/dept/type.ts

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

0 commit comments

Comments
 (0)