import { connect, useRequest } from "umi"; import type { CurrentUser } from "umi"; import type { ConnectState } from "@/models/connect"; import React, { useRef, useState } from "react"; import ProCard from "@ant-design/pro-card"; import { MenuFoldOutlined } from "@ant-design/icons"; import type { FormInstance } from "antd"; import { Popconfirm, Space, Tree, Image, Modal, Divider, Row, Col, message, Button } from "antd"; import type { ActionType } from "@ant-design/pro-table"; import ProTable from "@ant-design/pro-table"; import PageTitleBox from "@/components/PageTitleBox"; import { getFieldEnumTreeNoSession, handleGetFIELDENUMList } from "@/services/options"; import { handeGetPictureList } from "../service"; import { hanleDeletePICTURE, hanleGetPictureListPost, hanleSaveImgFile, hanleSynchroPICTURE, uploadAHYDPicture } from "@/services/picture"; import ModalFooter from "../scenicSpotConfig/component/modalFooter"; import ProForm, { ProFormSelect, ProFormText, ProFormUploadButton } from "@ant-design/pro-form"; import moment from 'moment' const beforeUpload = (file: any) => { const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'; if (!isJpgOrPng) { message.error('请上传JPEG、jpg、png格式的图片文件!'); } const isLt2M = file.size / 1024 / 1024 < 2; if (!isLt2M) { message.error('图片大小不超过 2MB!'); } return isJpgOrPng && isLt2M; } const LibraryInformationManager: React.FC<{ currentUser: CurrentUser }> = (props) => { const { currentUser } = props const actionRef = useRef(); const formRef = useRef(); const [collapsible, setCollapsible] = useState(false) const [treeView, setTreeView] = useState() // 左侧树的枚举 const [treeViewObj, setTreeViewObj] = useState() // 拿到headerTitle const { loading: imageLibraryLoading, data: imageLibrary } = useRequest(async () => { const req: any = { SearchParameter: { FIELDENUM_IDS: "11462,11423,11422,11473,11472", }, requestEncryption: true } const data = await handleGetFIELDENUMList(req) setTreeView(data) let obj: any = {} if (data && data.length > 0) { data.forEach((item: any) => { obj[item.FIELDENUM_ID] = item.FIELDENUM_NAME }) } setTreeViewObj(obj) return data }) // 图片信息 const [fileList, setFileList] = useState() // 树相关的属性和方法 const [selectedId, setSelectedId] = useState() // 查询的条件 const [searchParams, setSearchParams] = useState() const [imagePreviewVisible, setImagePreviewVisible] = useState(false) // 预览图片 const handleChangePreview = (val: any) => { setImagePreviewVisible(val) } // 详情 const [showDetail, setShowDetail] = useState(false) const [currentRow, setCurrentRow] = useState() const [modalLoading, setModalLoading] = useState(false) const ModalFormRef = useRef(); const columns: any = [ { dataIndex: "PICTURE_URL", hideInSearch: true, width: 200, align: 'center', ellipsis: true, render: (_, record) => { return record?.PICTURE_URL ? { let list: any = [{ url: record?.PICTURE_URL }] setFileList(list) handleChangePreview(true) }} src={record?.PICTURE_URL} alt="" /> : "-" } }, { dataIndex: 'PICTURE_NAME', title: '图片名称', width: 200, align: 'center', ellipsis: true, hideInSearch: true, render: (_, record) => { return record?.PICTURE_NAME ? { setCurrentRow(record) setShowDetail(true) }}> {`${record?.PICTURE_NAME ? record?.PICTURE_NAME : ""}${record?.PICTURE_TYPE && treeViewObj[record?.PICTURE_TYPE] ? `【${treeViewObj[record?.PICTURE_TYPE]}】` : ""}`} : "" } }, { dataIndex: 'STAFF_NAME', title: '操作人', width: 200, align: 'center', ellipsis: true, hideInSearch: true, }, { dataIndex: 'OPERATE_DATE', title: '操作时间', width: 200, align: 'center', ellipsis: true, hideInSearch: true, }, // { // dataIndex: 'option', // title: '操作', // width: 150, // align: 'center', // valueType: 'option', // hideInSearch: true, // render: (_, record) => { // return ( // // { // setCurrentRow(record) // setShowDetail(true) // }} // > // 编辑 // // { // await handleDeleteImg(record?.PICTURE_ID) // }} // > // 删除 // // // ); // }, // }, ] // 同步图片信息 const handleSynchroImage = async (obj: any) => { let req: any = {} if (currentRow?.PICTURE_ID) { req = { ...currentRow, ...obj, requestEncryption: true } } else { req = { ...obj, PICTURE_URL: fileList[0].url, PICTURE_INDEX: 0, STAFF_ID: currentUser.ID, STAFF_NAME: currentUser.Name, OPERATE_DATE: moment().format('YYYY-MM-DD HH:mm:ss'), requestEncryption: true } } const data = await hanleSynchroPICTURE(req) console.log('datadatadatadatadata', data); if (data.Result_Code === 100) { message.success('同步成功!') setCurrentRow(null) setShowDetail(false) actionRef.current?.reload() } else { message.error(data.Result_Desc) } } // 删除图片信息 const handleDeleteImg = async (id: any) => { const req: any = { PICTUREId: id, requestEncryption: true } const data = await hanleDeletePICTURE(req) if (data.Result_Code === 100) { message.success('同步成功!') setCurrentRow(null) setShowDetail(false) actionRef.current?.reload() } else { message.error(data.Result_Desc) } } return (
{ setCollapsible(!collapsible); }} /> } colSpan={!collapsible ? "300px" : "60px"} title={!collapsible ? "请选择图库类型" : ""} headerBordered collapsed={collapsible} > {treeView && treeView.length > 0 ? { // 多选逻辑 const selectedIds = info.checkedNodes.filter((n: any) => n?.key !== '0-0') setSelectedId(selectedIds.map((n: any) => n?.FIELDENUM_ID)?.toString() || '') }} fieldNames={{ title: "FIELDENUM_NAME", key: "FIELDENUM_ID" }} /> : ''}
} // 列表表头 search={{ span: 6 }} request={async (params) => { if (!selectedId) { return } const req: any = { SearchParameter: { PICTURE_TYPES: selectedId, }, PageIndex: 1, PageSize: 999999, requestEncryption: true } setSearchParams(params) const data = await hanleGetPictureListPost(req) if (data && data.length > 0) { return { data, success: true } } return { data: [], success: true } }} toolbar={{ actions: [ ] }} />
{/* 图片预览组件 */} {fileList && fileList.length > 0 &&
{ handleChangePreview(vis) } }}> { fileList.map((n) => ) }
} { ModalFormRef?.current?.resetFields() setCurrentRow(null) setShowDetail(false) setFileList([]) }} confirmLoading={modalLoading} width={1400} bodyStyle={{ height: '700px', // 你可以根据需要调整高度 overflowY: 'auto', }} destroyOnClose title={currentRow?.PICTURE_ID ? '编辑图片' : "新增卡券"} onOk={() => { ModalFormRef?.current?.validateFields().then(async (res) => { await handleSynchroImage(res) }) }} footer={ { // await handleDeleteShopRule(currentRow?.PICTURE_ID) await handleDeleteImg(currentRow?.PICTURE_ID) }} handleCancel={() => { ModalFormRef?.current?.resetFields() setCurrentRow(null) setShowDetail(false) setFileList([]) }} handleOK={() => { ModalFormRef?.current?.validateFields().then(async (res) => { await handleSynchroImage(res) }) }} />} > { if (currentRow?.PICTURE_ID) { return { ...currentRow } } else { return { STAFF_NAME: currentUser.Name, OPERATE_DATE: moment().format('YYYY-MM-DD HH:mm:ss') } } }} > { currentRow ? '' : <> 上传图片 { const formData = new FormData(); formData.append('files', info.file); formData.append('TableType', "1203"); formData.append('ImageName', typeof info.file !== 'string' ? info.file?.name : ''); if (info.filename) { const success = await hanleSaveImgFile(formData) console.log('successsuccesssuccess', success); if (success) { const list = [{ uid: `${success.Result_Data.ImageId}`, // 注意,这个uid一定不能少,否则上传失败 name: success.Result_Data.ImageName, status: 'done', url: success.Result_Data.ImageUrl, // url 是展示在页面上的绝对链接 // imgUrl: success.ImagePath // + success.ImageUrl, }] setFileList(list) } } else { message.error("您上传的图片不存在.") } } }} /> } 基本信息
) } export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser }))(LibraryInformationManager);