Skip to content

Commit b347ca1

Browse files
YunaiVgitee-org
authored andcommitted
!24 Vue3 重构:基础设施 -> 配置管理功能
Merge pull request !24 from 芋道源码/dev
2 parents 67873d9 + 74d225c commit b347ca1

File tree

14 files changed

+809
-382
lines changed

14 files changed

+809
-382
lines changed

src/api/infra/config/index.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import request from '@/config/axios'
22

33
export interface ConfigVO {
4-
id: number
4+
id: number | undefined
55
category: string
66
name: string
77
key: string
@@ -12,13 +12,6 @@ export interface ConfigVO {
1212
createTime: Date
1313
}
1414

15-
export interface ConfigPageReqVO extends PageParam {
16-
name?: string
17-
key?: string
18-
type?: number
19-
createTime?: Date[]
20-
}
21-
2215
export interface ConfigExportReqVO {
2316
name?: string
2417
key?: string
@@ -27,32 +20,32 @@ export interface ConfigExportReqVO {
2720
}
2821

2922
// 查询参数列表
30-
export const getConfigPageApi = (params: ConfigPageReqVO) => {
23+
export const getConfigPage = (params: PageParam) => {
3124
return request.get({ url: '/infra/config/page', params })
3225
}
3326

3427
// 查询参数详情
35-
export const getConfigApi = (id: number) => {
28+
export const getConfig = (id: number) => {
3629
return request.get({ url: '/infra/config/get?id=' + id })
3730
}
3831

3932
// 根据参数键名查询参数值
40-
export const getConfigKeyApi = (configKey: string) => {
33+
export const getConfigKey = (configKey: string) => {
4134
return request.get({ url: '/infra/config/get-value-by-key?key=' + configKey })
4235
}
4336

4437
// 新增参数
45-
export const createConfigApi = (data: ConfigVO) => {
38+
export const createConfig = (data: ConfigVO) => {
4639
return request.post({ url: '/infra/config/create', data })
4740
}
4841

4942
// 修改参数
50-
export const updateConfigApi = (data: ConfigVO) => {
43+
export const updateConfig = (data: ConfigVO) => {
5144
return request.put({ url: '/infra/config/update', data })
5245
}
5346

5447
// 删除参数
55-
export const deleteConfigApi = (id: number) => {
48+
export const deleteConfig = (id: number) => {
5649
return request.delete({ url: '/infra/config/delete?id=' + id })
5750
}
5851

src/components/Dialog/src/Dialog.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const props = defineProps({
88
modelValue: propTypes.bool.def(false),
99
title: propTypes.string.def('Dialog'),
1010
fullscreen: propTypes.bool.def(true),
11-
maxHeight: propTypes.oneOfType([String, Number]).def('300px'),
12-
width: propTypes.oneOfType([String, Number]).def('40%')
11+
width: propTypes.oneOfType([String, Number]).def('40%'),
12+
scroll: propTypes.bool.def(false), // 是否开启滚动条。如果是的话,按照 maxHeight 设置最大高度
13+
maxHeight: propTypes.oneOfType([String, Number]).def('300px')
1314
})
1415
1516
const getBindValue = computed(() => {
@@ -35,6 +36,7 @@ const dialogHeight = ref(isNumber(props.maxHeight) ? `${props.maxHeight}px` : pr
3536
watch(
3637
() => isFullscreen.value,
3738
async (val: boolean) => {
39+
// 计算最大高度
3840
await nextTick()
3941
if (val) {
4042
const windowHeight = document.documentElement.offsetHeight
@@ -80,9 +82,12 @@ const dialogStyle = computed(() => {
8082
</div>
8183
</template>
8284

83-
<ElScrollbar :style="dialogStyle">
85+
<!-- 情况一:如果 scroll 为 true,说明开启滚动条 -->
86+
<ElScrollbar :style="dialogStyle" v-if="scroll">
8487
<slot></slot>
8588
</ElScrollbar>
89+
<!-- 情况二:如果 scroll 为 false,说明关闭滚动条滚动条 -->
90+
<slot v-else></slot>
8691

8792
<template v-if="slots.footer" #footer>
8893
<slot name="footer"></slot>

src/components/DictTag/src/DictTag.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default defineComponent({
3434
return null
3535
}
3636
// 解决自定义字典标签值为零时标签不渲染的问题
37-
if (!props.value && props.value !== 0) {
37+
if (props.value === undefined) {
3838
return null
3939
}
4040
getDictObj(props.type, props.value.toString())

src/components/Pagination/index.vue

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!-- 基于 ruoyi-vue3 的 Pagination 重构,核心是简化无用的属性,并使用 ts 重写 -->
2+
<template>
3+
<el-pagination
4+
v-show="total > 0"
5+
class="float-right mt-15px mb-15px"
6+
:background="true"
7+
layout="total, sizes, prev, pager, next, jumper"
8+
:page-sizes="[10, 20, 30, 50]"
9+
v-model:current-page="currentPage"
10+
v-model:page-size="pageSize"
11+
:pager-count="pagerCount"
12+
:total="total"
13+
@size-change="handleSizeChange"
14+
@current-change="handleCurrentChange"
15+
/>
16+
</template>
17+
<script setup>
18+
import { computed } from 'vue'
19+
20+
const props = defineProps({
21+
// 总条目数
22+
total: {
23+
required: true,
24+
type: Number
25+
},
26+
// 当前页数:pageNo
27+
page: {
28+
type: Number,
29+
default: 1
30+
},
31+
// 每页显示条目个数:pageSize
32+
limit: {
33+
type: Number,
34+
default: 20
35+
},
36+
// 设置最大页码按钮数。 页码按钮的数量,当总页数超过该值时会折叠
37+
// 移动端页码按钮的数量端默认值 5
38+
pagerCount: {
39+
type: Number,
40+
default: document.body.clientWidth < 992 ? 5 : 7
41+
}
42+
})
43+
44+
const emit = defineEmits(['update:page', 'update:limit', 'pagination', 'pagination'])
45+
const currentPage = computed({
46+
get() {
47+
return props.page
48+
},
49+
set(val) {
50+
// 触发 update:page 事件,更新 limit 属性,从而更新 pageNo
51+
emit('update:page', val)
52+
}
53+
})
54+
const pageSize = computed({
55+
get() {
56+
return props.limit
57+
},
58+
set(val) {
59+
// 触发 update:limit 事件,更新 limit 属性,从而更新 pageSize
60+
emit('update:limit', val)
61+
}
62+
})
63+
const handleSizeChange = (val) => {
64+
// 如果修改后超过最大页面,强制跳转到第 1 页
65+
if (currentPage.value * val > props.total) {
66+
currentPage.value = 1
67+
}
68+
// 触发 pagination 事件,重新加载列表
69+
emit('pagination', { page: currentPage.value, limit: val })
70+
}
71+
const handleCurrentChange = (val) => {
72+
// 触发 pagination 事件,重新加载列表
73+
emit('pagination', { page: val, limit: pageSize.value })
74+
}
75+
</script>

src/config/axios/service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ service.interceptors.response.use(
170170
return Promise.reject(new Error(msg))
171171
} else if (code === 901) {
172172
ElMessage.error({
173-
duration: 5,
174173
offset: 300,
175174
dangerouslyUseHTMLString: true,
176175
message:

src/types/auto-components.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ 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']
2627
ElAvatar: typeof import('element-plus/es')['ElAvatar']
2728
ElBadge: typeof import('element-plus/es')['ElBadge']
2829
ElButton: typeof import('element-plus/es')['ElButton']
@@ -34,6 +35,7 @@ declare module '@vue/runtime-core' {
3435
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
3536
ElCollapseTransition: typeof import('element-plus/es')['ElCollapseTransition']
3637
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
38+
ElDatePicker: typeof import('element-plus/es')['ElDatePicker']
3739
ElDescriptions: typeof import('element-plus/es')['ElDescriptions']
3840
ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem']
3941
ElDialog: typeof import('element-plus/es')['ElDialog']
@@ -91,6 +93,7 @@ declare module '@vue/runtime-core' {
9193
ImageViewer: typeof import('./../components/ImageViewer/src/ImageViewer.vue')['default']
9294
Infotip: typeof import('./../components/Infotip/src/Infotip.vue')['default']
9395
InputPassword: typeof import('./../components/InputPassword/src/InputPassword.vue')['default']
96+
Pagination: typeof import('./../components/Pagination/index.vue')['default']
9497
ProcessDesigner: typeof import('./../components/bpmnProcessDesigner/package/designer/ProcessDesigner.vue')['default']
9598
ProcessPalette: typeof import('./../components/bpmnProcessDesigner/package/palette/ProcessPalette.vue')['default']
9699
ProcessViewer: typeof import('./../components/bpmnProcessDesigner/package/designer/ProcessViewer.vue')['default']

src/utils/dict.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const getBoolDictOptions = (dictType: string) => {
5555
dictOptions.forEach((dict: DictDataType) => {
5656
dictOption.push({
5757
...dict,
58-
value: dict.value + '' === 'true' ? true : false
58+
value: dict.value + '' === 'true'
5959
})
6060
})
6161
return dictOption

src/utils/formatTime.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import dayjs from 'dayjs'
2+
13
/**
24
* 时间日期转换
35
* @param date 当前时间,new Date() 格式
@@ -174,3 +176,18 @@ export function formatPast2(ms) {
174176
return 0 + '秒'
175177
}
176178
}
179+
180+
/**
181+
* element plus 的时间 Formatter 实现,使用 YYYY-MM-DD HH:mm:ss 格式
182+
*
183+
* @param row 行数据
184+
* @param column 字段
185+
* @param cellValue 字段值
186+
*/
187+
// @ts-ignore
188+
export const dateFormatter = (row, column, cellValue) => {
189+
if (!cellValue) {
190+
return
191+
}
192+
return dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss')
193+
}

src/views/infra/config/config.data.ts

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

0 commit comments

Comments
 (0)