| | |
| | | import { treeToList } from '@/utils/helper/treeHelper'; |
| | | import { Spin } from 'ant-design-vue'; |
| | | import { parseRowKey } from '../../helper'; |
| | | import { warn } from '@/utils/log'; |
| | | |
| | | export default defineComponent({ |
| | | name: 'EditableCell', |
| | |
| | | const getIsCheckComp = computed(() => { |
| | | const component = unref(getComponent); |
| | | return ['Checkbox', 'Switch'].includes(component); |
| | | }); |
| | | |
| | | const getDisable = computed(() => { |
| | | const { editDynamicDisabled } = props.column; |
| | | let disabled = false; |
| | | if (isBoolean(editDynamicDisabled)) { |
| | | disabled = editDynamicDisabled; |
| | | } |
| | | if (isFunction(editDynamicDisabled)) { |
| | | const { record } = props; |
| | | disabled = editDynamicDisabled({ record, currentValue: currentValueRef.value }); |
| | | } |
| | | return disabled; |
| | | }); |
| | | |
| | | const getComponentProps = computed(() => { |
| | |
| | | const dataKey = (dataIndex || key) as string; |
| | | set(record, dataKey, value); |
| | | } |
| | | const getDisable = computed(() => { |
| | | const { editDynamicDisabled } = props.column; |
| | | let disabled = false; |
| | | if (isBoolean(editDynamicDisabled)) { |
| | | disabled = editDynamicDisabled; |
| | | } |
| | | if (isFunction(editDynamicDisabled)) { |
| | | const { record } = props; |
| | | disabled = editDynamicDisabled({ record, currentValue: currentValueRef.value }); |
| | | } |
| | | return disabled; |
| | | }); |
| | | |
| | | const getValues = computed(() => { |
| | | const { editValueMap } = props.column; |
| | | |
| | |
| | | return option?.label ?? value; |
| | | }); |
| | | |
| | | const getRowEditable = computed(() => { |
| | | const { editable } = props.record || {}; |
| | | return !!editable; |
| | | }); |
| | | |
| | | const getWrapperStyle = computed((): CSSProperties => { |
| | | if (unref(getIsCheckComp) || unref(getRowEditable)) { |
| | | return {}; |
| | |
| | | const getWrapperClass = computed(() => { |
| | | const { align = 'center' } = props.column; |
| | | return `edit-cell-align-${align}`; |
| | | }); |
| | | |
| | | const getRowEditable = computed(() => { |
| | | const { editable } = props.record || {}; |
| | | return !!editable; |
| | | }); |
| | | |
| | | watchEffect(() => { |
| | |
| | | }); |
| | | } |
| | | |
| | | async function handleChange(e: any) { |
| | | async function handleChange(e: any, ...rest: any[]) { |
| | | const component = unref(getComponent); |
| | | if (!e) { |
| | | currentValueRef.value = e; |
| | |
| | | currentValueRef.value = e; |
| | | } |
| | | const onChange = unref(getComponentProps)?.onChangeTemp; |
| | | if (onChange && isFunction(onChange)) onChange(...arguments); |
| | | if (onChange && isFunction(onChange)) onChange(e, ...rest); |
| | | |
| | | table.emit?.('edit-change', { |
| | | column: props.column, |
| | |
| | | }); |
| | | } catch (e) { |
| | | result = false; |
| | | warn(e); |
| | | } finally { |
| | | spinning.value = false; |
| | | } |
| | |
| | | if (!props.record.editValueRefs) props.record.editValueRefs = {}; |
| | | props.record.editValueRefs[props.column.dataIndex as any] = currentValueRef; |
| | | } |
| | | /* eslint-disable */ |
| | | props.record.onCancelEdit = () => { |
| | | isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn()); |
| | | }; |
| | | /* eslint-disable */ |
| | | props.record.onSubmitEdit = async () => { |
| | | if (isArray(props.record?.submitCbs)) { |
| | | if (!props.record?.onValid?.()) return; |
| | |
| | | } |
| | | .@{prefix-cls} { |
| | | position: relative; |
| | | min-height: 24px; //设置高度让其始终可被hover |
| | | min-height: 24px; // 设置高度让其始终可被hover |
| | | |
| | | &__wrapper { |
| | | display: flex; |