Skip to content

Commit 74846a1

Browse files
committed
1. 优化 Dialog 组件,增加 scroll 标识滚动
2. 优化配置管理的 :default-time 设置
1 parent 0ea6b1b commit 74846a1

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

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/views/infra/config/form.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
2-
<!-- TODO 芋艿:Dialog 貌似高度不太对劲 已解决:textarea导致 设置一个最大高就行了 -->
3-
<Dialog :title="modelTitle" v-model="modelVisible" :loading="modelLoading" :max-height="'310px'">
2+
<Dialog :title="modelTitle" v-model="modelVisible" :loading="modelLoading">
43
<el-form ref="ruleFormRef" :model="formData" :rules="formRules" label-width="80px">
54
<el-form-item label="参数分类" prop="category">
65
<el-input v-model="formData.category" placeholder="请输入参数分类" />
@@ -48,7 +47,7 @@ const formType = ref('') // 表单的类型:create - 新增;update - 修改
4847
const formLoading = ref(false) // 操作按钮的 Loading 加载
4948
// let formRef = ref() // 表单的 Ref
5049
const formData = reactive({
51-
id: 0,
50+
id: undefined,
5251
category: '',
5352
name: '',
5453
key: '',
@@ -70,24 +69,27 @@ const { proxy } = getCurrentInstance() as any
7069
/** 打开弹窗 */
7170
const openModal = async (type: string, id?: number) => {
7271
modelVisible.value = true
73-
modelLoading.value = true
7472
modelTitle.value = t('action.' + type)
7573
formType.value = type
76-
// 设置数据
7774
resetForm()
75+
// 修改时,设置数据
7876
if (id) {
79-
const data = await ConfigApi.getConfig(id)
80-
Object.assign(formData, data)
77+
modelLoading.value = true
78+
try {
79+
const data = await ConfigApi.getConfig(id)
80+
// TODO 规范纠结点:因为用 reactive,所以需要使用 Object;可以替换的方案,1)把 reactive 改成 ref;
81+
Object.assign(formData, data)
82+
} finally {
83+
modelLoading.value = false
84+
}
8185
}
82-
modelLoading.value = false
8386
}
8487
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
8588
8689
/** 提交表单 */
8790
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
8891
const submitForm = async () => {
89-
const formRef = proxy.$refs['ruleFormRef']
90-
console.log(formRef, '======')
92+
const formRef = proxy.$refs['formRef']
9193
// 校验表单
9294
if (!formRef) return
9395
const valid = await formRef.validate()
@@ -112,7 +114,7 @@ const submitForm = async () => {
112114
113115
/** 重置表单 */
114116
const resetForm = () => {
115-
formData.id = 0
117+
formData.id = undefined
116118
formData.category = ''
117119
formData.name = ''
118120
formData.key = ''

src/views/infra/config/index.vue

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@
3636
/>
3737
</el-select>
3838
</el-form-item>
39-
<!-- TODO:时间无法设置 已解决 -->
4039
<el-form-item label="创建时间" prop="createTime">
4140
<el-date-picker
42-
v-model="createTime"
41+
v-model="queryParams.createTime"
4342
style="width: 240px"
44-
value-format="yyyy-MM-DD HH:mm:ss"
43+
value-format="YYYY-MM-DD HH:mm:ss"
4544
type="daterange"
4645
range-separator="-"
4746
start-placeholder="开始日期"
4847
end-placeholder="结束日期"
49-
:default-time="defaultTime"
48+
:default-time="[new Date(0, 0, 0, 0, 0, 0), new Date(0, 0, 0, 23, 59, 59)]"
5049
/>
5150
</el-form-item>
5251
<el-form-item>
@@ -139,14 +138,13 @@
139138
</content-wrap>
140139

141140
<!-- 表单弹窗:添加/修改 -->
142-
<!-- TODO 芋艿:可以改成 form 么? 已解决 -->
143-
<Form ref="modalRef" @success="getList" />
141+
<config-form ref="modalRef" @success="getList" />
144142
</template>
145143
<script setup lang="ts" name="Config">
146144
import * as ConfigApi from '@/api/infra/config'
147-
import Form from './form.vue'
145+
import ConfigForm from './form.vue'
148146
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
149-
import { Delete, Edit, Search, Download, Plus, Refresh } from '@element-plus/icons-vue'
147+
// import { Delete, Edit, Search, Download, Plus, Refresh } from '@element-plus/icons-vue'
150148
import dayjs from 'dayjs'
151149
const showSearch = ref(true) // 搜索框的是否展示
152150
const loading = ref(true) // 列表的加载中
@@ -157,13 +155,9 @@ const queryParams = reactive({
157155
pageSize: 10,
158156
name: undefined,
159157
key: undefined,
160-
type: undefined
158+
type: undefined,
159+
createTime: []
161160
})
162-
const createTime = ref('')
163-
const defaultTime = ref<[Date, Date]>([
164-
new Date(2000, 1, 1, 0, 0, 0),
165-
new Date(2000, 2, 1, 23, 59, 59)
166-
])
167161
const queryFormRef = ref() // 搜索的表单
168162
169163
/** 搜索按钮操作 */
@@ -196,7 +190,7 @@ const openModal = (type: string, id?: number) => {
196190
modalRef.value.openModal(type, id)
197191
}
198192
199-
// ========== 初始化 ==========
193+
/** 初始化 **/
200194
onMounted(() => {
201195
getList()
202196
})

0 commit comments

Comments
 (0)