1. 优化 Dialog 组件,增加 scroll 标识滚动

2. 优化配置管理的 :default-time 设置
This commit is contained in:
YunaiV 2023-03-09 19:36:57 +08:00
parent 0ea6b1b749
commit 74846a11bd
3 changed files with 30 additions and 29 deletions

View File

@ -8,8 +8,9 @@ const props = defineProps({
modelValue: propTypes.bool.def(false), modelValue: propTypes.bool.def(false),
title: propTypes.string.def('Dialog'), title: propTypes.string.def('Dialog'),
fullscreen: propTypes.bool.def(true), fullscreen: propTypes.bool.def(true),
maxHeight: propTypes.oneOfType([String, Number]).def('300px'), width: propTypes.oneOfType([String, Number]).def('40%'),
width: propTypes.oneOfType([String, Number]).def('40%') scroll: propTypes.bool.def(false), // maxHeight
maxHeight: propTypes.oneOfType([String, Number]).def('300px')
}) })
const getBindValue = computed(() => { const getBindValue = computed(() => {
@ -35,6 +36,7 @@ const dialogHeight = ref(isNumber(props.maxHeight) ? `${props.maxHeight}px` : pr
watch( watch(
() => isFullscreen.value, () => isFullscreen.value,
async (val: boolean) => { async (val: boolean) => {
//
await nextTick() await nextTick()
if (val) { if (val) {
const windowHeight = document.documentElement.offsetHeight const windowHeight = document.documentElement.offsetHeight
@ -80,9 +82,12 @@ const dialogStyle = computed(() => {
</div> </div>
</template> </template>
<ElScrollbar :style="dialogStyle"> <!-- 情况一如果 scroll true说明开启滚动条 -->
<ElScrollbar :style="dialogStyle" v-if="scroll">
<slot></slot> <slot></slot>
</ElScrollbar> </ElScrollbar>
<!-- 情况一如果 scroll false说明关闭滚动条滚动条 -->
<slot v-else></slot>
<template v-if="slots.footer" #footer> <template v-if="slots.footer" #footer>
<slot name="footer"></slot> <slot name="footer"></slot>

View File

@ -1,6 +1,5 @@
<template> <template>
<!-- TODO 芋艿Dialog 貌似高度不太对劲 已解决textarea导致 设置一个最大高就行了 --> <Dialog :title="modelTitle" v-model="modelVisible" :loading="modelLoading">
<Dialog :title="modelTitle" v-model="modelVisible" :loading="modelLoading" :max-height="'310px'">
<el-form ref="ruleFormRef" :model="formData" :rules="formRules" label-width="80px"> <el-form ref="ruleFormRef" :model="formData" :rules="formRules" label-width="80px">
<el-form-item label="参数分类" prop="category"> <el-form-item label="参数分类" prop="category">
<el-input v-model="formData.category" placeholder="请输入参数分类" /> <el-input v-model="formData.category" placeholder="请输入参数分类" />
@ -48,7 +47,7 @@ const formType = ref('') // 表单的类型create - 新增update - 修改
const formLoading = ref(false) // Loading const formLoading = ref(false) // Loading
// let formRef = ref() // Ref // let formRef = ref() // Ref
const formData = reactive({ const formData = reactive({
id: 0, id: undefined,
category: '', category: '',
name: '', name: '',
key: '', key: '',
@ -70,24 +69,27 @@ const { proxy } = getCurrentInstance() as any
/** 打开弹窗 */ /** 打开弹窗 */
const openModal = async (type: string, id?: number) => { const openModal = async (type: string, id?: number) => {
modelVisible.value = true modelVisible.value = true
modelLoading.value = true
modelTitle.value = t('action.' + type) modelTitle.value = t('action.' + type)
formType.value = type formType.value = type
//
resetForm() resetForm()
//
if (id) { if (id) {
const data = await ConfigApi.getConfig(id) modelLoading.value = true
Object.assign(formData, data) try {
const data = await ConfigApi.getConfig(id)
// TODO reactive使 Object1 reactive ref
Object.assign(formData, data)
} finally {
modelLoading.value = false
}
} }
modelLoading.value = false
} }
defineExpose({ openModal }) // openModal defineExpose({ openModal }) // openModal
/** 提交表单 */ /** 提交表单 */
const emit = defineEmits(['success']) // success const emit = defineEmits(['success']) // success
const submitForm = async () => { const submitForm = async () => {
const formRef = proxy.$refs['ruleFormRef'] const formRef = proxy.$refs['formRef']
console.log(formRef, '======')
// //
if (!formRef) return if (!formRef) return
const valid = await formRef.validate() const valid = await formRef.validate()
@ -112,7 +114,7 @@ const submitForm = async () => {
/** 重置表单 */ /** 重置表单 */
const resetForm = () => { const resetForm = () => {
formData.id = 0 formData.id = undefined
formData.category = '' formData.category = ''
formData.name = '' formData.name = ''
formData.key = '' formData.key = ''

View File

@ -36,17 +36,16 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- TODO时间无法设置 已解决 -->
<el-form-item label="创建时间" prop="createTime"> <el-form-item label="创建时间" prop="createTime">
<el-date-picker <el-date-picker
v-model="createTime" v-model="queryParams.createTime"
style="width: 240px" style="width: 240px"
value-format="yyyy-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
type="daterange" type="daterange"
range-separator="-" range-separator="-"
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期" end-placeholder="结束日期"
:default-time="defaultTime" :default-time="[new Date(0, 0, 0, 0, 0, 0), new Date(0, 0, 0, 23, 59, 59)]"
/> />
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
@ -139,14 +138,13 @@
</content-wrap> </content-wrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<!-- TODO 芋艿可以改成 form 已解决 --> <config-form ref="modalRef" @success="getList" />
<Form ref="modalRef" @success="getList" />
</template> </template>
<script setup lang="ts" name="Config"> <script setup lang="ts" name="Config">
import * as ConfigApi from '@/api/infra/config' import * as ConfigApi from '@/api/infra/config'
import Form from './form.vue' import ConfigForm from './form.vue'
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { Delete, Edit, Search, Download, Plus, Refresh } from '@element-plus/icons-vue' // import { Delete, Edit, Search, Download, Plus, Refresh } from '@element-plus/icons-vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
const showSearch = ref(true) // const showSearch = ref(true) //
const loading = ref(true) // const loading = ref(true) //
@ -157,13 +155,9 @@ const queryParams = reactive({
pageSize: 10, pageSize: 10,
name: undefined, name: undefined,
key: undefined, key: undefined,
type: undefined type: undefined,
createTime: []
}) })
const createTime = ref('')
const defaultTime = ref<[Date, Date]>([
new Date(2000, 1, 1, 0, 0, 0),
new Date(2000, 2, 1, 23, 59, 59)
])
const queryFormRef = ref() // const queryFormRef = ref() //
/** 搜索按钮操作 */ /** 搜索按钮操作 */
@ -196,7 +190,7 @@ const openModal = (type: string, id?: number) => {
modalRef.value.openModal(type, id) modalRef.value.openModal(type, id)
} }
// ========== ========== /** 初始化 **/
onMounted(() => { onMounted(() => {
getList() getList()
}) })