|
@@ -1,12 +1,12 @@
|
|
|
-import React, { useCallback, useRef } from "react";
|
|
|
+import React, { useCallback, useRef, useState } from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
import {
|
|
|
PlusOutlined,
|
|
|
EyeOutlined,
|
|
|
CloseOutlined,
|
|
|
DownloadOutlined,
|
|
|
+ CheckOutlined,
|
|
|
} from "@ant-design/icons";
|
|
|
-import { ReactSortable } from "react-sortablejs";
|
|
|
import ImageLazy from "@/components/ImageLazy";
|
|
|
|
|
|
import { FileImgListType } from "@/types";
|
|
@@ -106,6 +106,65 @@ function Z_upFileMore({
|
|
|
[fileList, setFileList]
|
|
|
);
|
|
|
|
|
|
+ const showInpRef = useRef<HTMLInputElement>(null);
|
|
|
+
|
|
|
+ // 点击 排序 编辑
|
|
|
+ const sortShowFu = useCallback(
|
|
|
+ (id: number, ind: number) => {
|
|
|
+ const newList = fileList.map((v) => {
|
|
|
+ return {
|
|
|
+ ...v,
|
|
|
+ show: id === v.id ? !v.show : false,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ setFileList(newList);
|
|
|
+ setSortValue(ind + "");
|
|
|
+ setTimeout(() => {
|
|
|
+ if (showInpRef.current) showInpRef.current.focus();
|
|
|
+ }, 100);
|
|
|
+ },
|
|
|
+ [fileList, setFileList]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 当前排序输入框的值
|
|
|
+ const [sortValue, setSortValue] = useState("");
|
|
|
+ const sortValueChange = useCallback(
|
|
|
+ (val: string) => {
|
|
|
+ if (Number(val) > fileList.length) val = fileList.length + "";
|
|
|
+ setSortValue(val.replace(/^(0+)|[^\d]+/g, ""));
|
|
|
+ },
|
|
|
+ [fileList.length]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击序号的 √
|
|
|
+ const sortOkFu = useCallback(
|
|
|
+ (oldInd: number) => {
|
|
|
+ if (!sortValue) return MessageFu.warning("请输入序号值!");
|
|
|
+
|
|
|
+ const newInd = Number(sortValue) - 1;
|
|
|
+
|
|
|
+ if (oldInd === newInd) return MessageFu.warning("不能和之前的序号一样!");
|
|
|
+
|
|
|
+ const newArr = [...fileList];
|
|
|
+ newArr[oldInd] = fileList[newInd];
|
|
|
+ newArr[newInd] = fileList[oldInd];
|
|
|
+ setFileList(newArr.map((v) => ({ ...v, show: false })));
|
|
|
+
|
|
|
+ MessageFu.success("修改序号成功!");
|
|
|
+ },
|
|
|
+ [fileList, setFileList, sortValue]
|
|
|
+ );
|
|
|
+
|
|
|
+ const inputKeyFu = useCallback(
|
|
|
+ (e: React.KeyboardEvent<HTMLInputElement>, ind: number) => {
|
|
|
+ if (e.key === "Enter") {
|
|
|
+ sortOkFu(ind);
|
|
|
+ e.preventDefault();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [sortOkFu]
|
|
|
+ );
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.Z_upFileMore}>
|
|
|
<input
|
|
@@ -124,15 +183,7 @@ function Z_upFileMore({
|
|
|
<PlusOutlined />
|
|
|
</div>
|
|
|
|
|
|
- <ReactSortable
|
|
|
- disabled={isLook}
|
|
|
- className={classNames(
|
|
|
- "fileImgListBox",
|
|
|
- isLook ? "fileImgListBoxNo" : ""
|
|
|
- )}
|
|
|
- list={fileList}
|
|
|
- setList={setFileList}
|
|
|
- >
|
|
|
+ <div className="fileImgListBox">
|
|
|
{fileList.map((v, i) => (
|
|
|
<div className="fileBoxRow_r_img" key={v.id}>
|
|
|
{v.filePath ? (
|
|
@@ -149,9 +200,43 @@ function Z_upFileMore({
|
|
|
<CloseOutlined />
|
|
|
</div>
|
|
|
</Popconfirm>
|
|
|
- {/* 下面的预览和下载 */}
|
|
|
+
|
|
|
+ {/* 当前序号 */}
|
|
|
+ <div
|
|
|
+ className="dangXBox"
|
|
|
+ hidden={isLook || fileList.length <= 1}
|
|
|
+ onClick={() => sortShowFu(v.id, i + 1)}
|
|
|
+ >
|
|
|
+ {i + 1}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 输入框 */}
|
|
|
+ <div className="sortInpBox" hidden={!v.show}>
|
|
|
+ <div className="clickOk" onClick={() => sortOkFu(i)}>
|
|
|
+ <CheckOutlined />
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ className="clickX"
|
|
|
+ onClick={() =>
|
|
|
+ setFileList(fileList.map((v) => ({ ...v, show: false })))
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <CloseOutlined />
|
|
|
+ </div>
|
|
|
+ <input
|
|
|
+ onKeyDown={(e) => inputKeyFu(e, i)}
|
|
|
+ ref={v.show ? showInpRef : null}
|
|
|
+ maxLength={2}
|
|
|
+ type="text"
|
|
|
+ value={sortValue}
|
|
|
+ onChange={(e) => sortValueChange(e.target.value)}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 下面的预览和下载 和 排序 */}
|
|
|
<div className="fileImgListLDBox">
|
|
|
<EyeOutlined
|
|
|
+ title="预览"
|
|
|
onClick={() =>
|
|
|
store.dispatch({
|
|
|
type: "layout/lookBigImg",
|
|
@@ -163,6 +248,7 @@ function Z_upFileMore({
|
|
|
}
|
|
|
/>
|
|
|
<a
|
|
|
+ title="下载"
|
|
|
href={baseURL + v.filePath}
|
|
|
download
|
|
|
target="_blank"
|
|
@@ -173,11 +259,11 @@ function Z_upFileMore({
|
|
|
</div>
|
|
|
</div>
|
|
|
))}
|
|
|
- </ReactSortable>
|
|
|
+ </div>
|
|
|
<div className="fileTit" hidden={isLook}>
|
|
|
{fileList.length && fileList.length >= 2 ? (
|
|
|
<>
|
|
|
- 按住鼠标可拖动图片调整顺序。
|
|
|
+ 点击左上角可设置图片序号(1-{fileList.length}),调整图片顺序。
|
|
|
<br />
|
|
|
</>
|
|
|
) : null}
|