mirror of
https://github.com/fugary/simple-element-plus-template.git
synced 2025-11-12 14:27:49 +00:00
优化一些显示问题
This commit is contained in:
@@ -51,7 +51,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
inputWidth: {
|
inputWidth: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '200px'
|
default: ''
|
||||||
},
|
},
|
||||||
autocompleteConfig: {
|
autocompleteConfig: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -194,10 +194,21 @@ const onInputKeywords = debounce((input) => {
|
|||||||
}
|
}
|
||||||
}, props.debounceTime)
|
}, props.debounceTime)
|
||||||
|
|
||||||
|
const calcDefaultLabelFunc = () => {
|
||||||
|
if (!props.useIdModel) {
|
||||||
|
const value = props.modelValue
|
||||||
|
return value && isObject(value) ? value[labelProp.value] : ''
|
||||||
|
}
|
||||||
|
return props.defaultLabel
|
||||||
|
}
|
||||||
|
|
||||||
|
const calcDefaultLabel = computed(calcDefaultLabelFunc)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
onClickOutside(autocompletePopover.value?.popperRef?.contentRef, () => {
|
onClickOutside(autocompletePopover.value?.popperRef?.contentRef, () => {
|
||||||
popoverVisible.value = false
|
popoverVisible.value = false
|
||||||
})
|
})
|
||||||
|
setAutocompleteLabel(calcDefaultLabel.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(() => popoverVisible.value, (val) => {
|
watch(() => popoverVisible.value, (val) => {
|
||||||
@@ -211,7 +222,6 @@ watch(() => popoverVisible.value, (val) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
watch(() => props.modelValue, (value) => {
|
watch(() => props.modelValue, (value) => {
|
||||||
console.info('=====================value', value)
|
|
||||||
if (!props.useIdModel) {
|
if (!props.useIdModel) {
|
||||||
setAutocompleteLabel(value && isObject(value) ? value[labelProp.value] : '')
|
setAutocompleteLabel(value && isObject(value) ? value[labelProp.value] : '')
|
||||||
if (isEmpty(value)) {
|
if (isEmpty(value)) {
|
||||||
@@ -220,13 +230,7 @@ watch(() => props.modelValue, (value) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(() => {
|
watch(calcDefaultLabelFunc, (label) => {
|
||||||
if (!props.useIdModel) {
|
|
||||||
const value = props.modelValue
|
|
||||||
return value && isObject(value) ? value[labelProp.value] : ''
|
|
||||||
}
|
|
||||||
return props.defaultLabel
|
|
||||||
}, (label) => {
|
|
||||||
setAutocompleteLabel(label)
|
setAutocompleteLabel(label)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -287,7 +291,6 @@ const moveSelection = function (down) {
|
|||||||
currentOnIndex.value = -1
|
currentOnIndex.value = -1
|
||||||
currentOnRow.value = null
|
currentOnRow.value = null
|
||||||
}
|
}
|
||||||
console.info('=================', tableRef.value.table, currentOnIndex.value, currentOnRow.value)
|
|
||||||
tableRef.value.table?.setCurrentRow(currentOnRow.value)
|
tableRef.value.table?.setCurrentRow(currentOnRow.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import ControlChild from '@/components/common-form-control/control-child.vue'
|
|||||||
import { useInputType } from '@/components/utils'
|
import { useInputType } from '@/components/utils'
|
||||||
import cloneDeep from 'lodash/cloneDeep'
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
import { get, set } from 'lodash'
|
import { get, set } from 'lodash'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {{option:CommonFormOption}}
|
* @type {{option:CommonFormOption}}
|
||||||
@@ -38,9 +39,40 @@ const modelAttrs = computed(() => {
|
|||||||
if (inputType.value === 'common-autocomplete' && option.getAutocompleteLabel) {
|
if (inputType.value === 'common-autocomplete' && option.getAutocompleteLabel) {
|
||||||
attrs.defaultLabel = option.getAutocompleteLabel(props.model, option)
|
attrs.defaultLabel = option.getAutocompleteLabel(props.model, option)
|
||||||
}
|
}
|
||||||
|
if (inputType.value === 'el-date-picker') {
|
||||||
|
attrs.disabledDate = (date) => {
|
||||||
|
const option = props.option
|
||||||
|
let result = false
|
||||||
|
if (option.minDate) {
|
||||||
|
result = date.getTime() < dayjs(option.minDate).startOf('d').toDate().getTime()
|
||||||
|
}
|
||||||
|
if (result && option.maxDate) {
|
||||||
|
result = date.getTime() > dayjs(option.maxDate).startOf('d').toDate().getTime()
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attrs.defaultValue = modelValue.value || option.minDate
|
||||||
return attrs
|
return attrs
|
||||||
})
|
})
|
||||||
|
|
||||||
|
watch(() => [inputType.value, props.option.minDate, props.option.maxDate], ([type, minDate, maxDate]) => {
|
||||||
|
const option = props.option
|
||||||
|
const date = modelValue.value
|
||||||
|
if (type === 'el-date-picker' && date && !option.disabled && option.clearInvalidDate !== false) {
|
||||||
|
let invalid = false
|
||||||
|
if (minDate) {
|
||||||
|
invalid = date.getTime() < dayjs(option.minDate).startOf('d').toDate().getTime()
|
||||||
|
}
|
||||||
|
if (invalid && maxDate) {
|
||||||
|
invalid = date.getTime() > dayjs(option.maxDate).startOf('d').toDate().getTime()
|
||||||
|
}
|
||||||
|
if (invalid) {
|
||||||
|
modelValue.value = undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const label = computed(() => {
|
const label = computed(() => {
|
||||||
const option = props.option
|
const option = props.option
|
||||||
if (option.labelKey) {
|
if (option.labelKey) {
|
||||||
@@ -142,6 +174,12 @@ const controlChange = (...args) => {
|
|||||||
|
|
||||||
const formItemEnabled = computed(() => props.option.enabled !== false)
|
const formItemEnabled = computed(() => props.option.enabled !== false)
|
||||||
|
|
||||||
|
const controlLabelWidth = computed(() => {
|
||||||
|
const option = props.option
|
||||||
|
const labelWidth = props.labelWidth
|
||||||
|
return option.labelWidth || modelAttrs.value.labelWidth || labelWidth
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -150,13 +188,15 @@ const formItemEnabled = computed(() => props.option.enabled !== false)
|
|||||||
ref="formItemRef"
|
ref="formItemRef"
|
||||||
:rules="rules"
|
:rules="rules"
|
||||||
:prop="option.prop"
|
:prop="option.prop"
|
||||||
:label-width="labelWidth"
|
:label-width="controlLabelWidth"
|
||||||
|
v-bind="$attrs"
|
||||||
>
|
>
|
||||||
<template
|
<template
|
||||||
v-if="showLabel"
|
v-if="showLabel"
|
||||||
#label
|
#label
|
||||||
>
|
>
|
||||||
<span>{{ label }}</span>
|
<slot name="beforeLabel" />
|
||||||
|
<span :class="option.labelCls">{{ label }}</span>
|
||||||
<el-tooltip
|
<el-tooltip
|
||||||
v-if="option.tooltip||option.tooltipFunc"
|
v-if="option.tooltip||option.tooltipFunc"
|
||||||
class="box-item"
|
class="box-item"
|
||||||
@@ -200,6 +240,7 @@ const formItemEnabled = computed(() => props.option.enabled !== false)
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</component>
|
</component>
|
||||||
|
<slot name="after" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ const props = defineProps({
|
|||||||
type: Object,
|
type: Object,
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
|
className: {
|
||||||
|
type: String,
|
||||||
|
default: 'common-form'
|
||||||
|
},
|
||||||
|
buttonStyle: {
|
||||||
|
type: [String, Object],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
validateOnRuleChange: {
|
validateOnRuleChange: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
@@ -78,7 +86,7 @@ defineExpose({
|
|||||||
<template>
|
<template>
|
||||||
<el-form
|
<el-form
|
||||||
ref="form"
|
ref="form"
|
||||||
class="common-form"
|
:class="className"
|
||||||
:model="formModel"
|
:model="formModel"
|
||||||
:label-width="labelWidth"
|
:label-width="labelWidth"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
@@ -106,7 +114,10 @@ defineExpose({
|
|||||||
:model="formModel"
|
:model="formModel"
|
||||||
name="default"
|
name="default"
|
||||||
/>
|
/>
|
||||||
<el-form-item v-if="showButtons">
|
<el-form-item
|
||||||
|
v-if="showButtons"
|
||||||
|
:style="buttonStyle"
|
||||||
|
>
|
||||||
<el-button
|
<el-button
|
||||||
v-if="showSubmit"
|
v-if="showSubmit"
|
||||||
type="primary"
|
type="primary"
|
||||||
|
|||||||
4
src/components/common-form/public.d.ts
vendored
4
src/components/common-form/public.d.ts
vendored
@@ -14,6 +14,10 @@ export interface CommonFormOption {
|
|||||||
label?: string;
|
label?: string;
|
||||||
/** 用于国际化的label */
|
/** 用于国际化的label */
|
||||||
labelKey?: string;
|
labelKey?: string;
|
||||||
|
/**
|
||||||
|
* 样式自定义
|
||||||
|
*/
|
||||||
|
labelCls?: string;
|
||||||
/** 是否必填,后面解析成为rules的一部分 */
|
/** 是否必填,后面解析成为rules的一部分 */
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
/** 正则表达式验证,解析成为rules的一部分 */
|
/** 正则表达式验证,解析成为rules的一部分 */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { formatDate } from '@/components/utils'
|
import { formatDate } from '@/utils'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { get } from 'lodash'
|
import { get } from 'lodash'
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { $i18nBundle } from '@/messages'
|
import { $i18nBundle } from '@/messages'
|
||||||
import dayjs from 'dayjs'
|
|
||||||
|
|
||||||
const calcWithIf = menuItem => {
|
const calcWithIf = menuItem => {
|
||||||
['icon', 'labelKey', 'label', 'html'].forEach(key => {
|
['icon', 'labelKey', 'label', 'html'].forEach(key => {
|
||||||
@@ -74,15 +73,3 @@ export const useParentRoute = function (route) {
|
|||||||
}
|
}
|
||||||
return route
|
return route
|
||||||
}
|
}
|
||||||
|
|
||||||
export const formatDate = (date, format) => {
|
|
||||||
if (date) {
|
|
||||||
return dayjs(date).format(format || 'YYYY-MM-DD HH:mm:ss')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const formatDay = (date, format) => {
|
|
||||||
if (date) {
|
|
||||||
return dayjs(date).format(format || 'YYYY-MM-DD')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user