import {computed, designComponent, iMouseEvent, PropType} from "@peryl/react-compose"; import {createPlcPropOptions, PlcEmitsOptions} from "../Table/plc/utils/plc.utils"; import {PlcScopeSlotsOptions} from "../Table/plc/utils/plc.scope-slots"; import {injectPlainTable} from "../Table/table/Table"; import {FileServiceUploadConfig} from "../$file"; import $configuration from "../$configuration"; import {formatImagePath, Image} from "../Image"; import {usePlc} from "../Table/plc/use/usePlc"; import ImageUploader from "../ImageUploader"; import {$previewer} from "../$previewer"; export const PlcImage = designComponent({ name: 'plc-image', props: { ...createPlcPropOptions({ align: 'center', noPadding: true, }), uploadConfig: { type: Object as PropType> }, // 上传配置信息对象 imgKeyField: { type: String }, urlPrefix: { type: String }, }, scopeSlots: PlcScopeSlotsOptions, emits: PlcEmitsOptions, setup({ props, event, slots, scopeSlots }) { const table = injectPlainTable(); const upload = $configuration.use('upload'); const size = computed(() => { const bodyRowHeight = table.numberState.bodyRowHeight; return Math.ceil((bodyRowHeight as number) - 8); }); const urlPrefix = computed(() => props.urlPrefix || upload?.config.prefix); const preview = (index: number, e: iMouseEvent) => { $previewer.preview({ current: index, urls: (table.dataRef.value.data || []).map(i => formatImagePath(i[props.field!], urlPrefix.value)) }, e.currentTarget as any); }; return usePlc({ props, slots, scopeSlots, event, defaultScopeSlots: { normal: ({ row, plc, node }) => ( !plc.props.field ? null : preview(node.state.index, e)} /> ), edit: ({ row, plc }) => !plc.props.field ? null : row[plc.props.field!] = val} uploadConfig={props.uploadConfig} height={size.value} width={size.value} minWidth={size.value} minHeight={size.value} hideTips handleDelete={() => { row[plc.props.field!] = null; row[props.imgKeyField!] = null; }} onUploadSuccess={(resp: any) => { row[props.imgKeyField!] = resp.result.id; }} /> } }); }, }); export default PlcImage;