Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 图片上传,拖动排序完成
gaoSir8d0e78823a99
diff --git a/package-lock.json b/package-lock.jsonindex 1033e2d2..f3533217 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "att",- "version": "0.1.3",+ "version": "0.1.4","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "att",- "version": "0.1.3",+ "version": "0.1.4","license": "MIT","dependencies": {"@ant-design/colors": "^7.2.0",@@ -41,8 +41,10 @@"playwright": "^1.49.1","qs": "^6.14.0","react-router-dom": "6",+ "react-sortablejs": "^6.1.4","react-svg": "^16.2.0","reflect-metadata": "^0.2.2",+ "sortablejs": "^1.15.6","typeorm": "^0.3.20","uninstall": "^0.0.0","uuid": "^11.0.5",@@ -59,6 +61,7 @@"@types/qs": "^6.9.18","@types/react": "^18.3.12","@types/react-dom": "^18.3.1",+ "@types/sortablejs": "^1.15.8","@types/xml2js": "^0.4.14","@typescript-eslint/eslint-plugin": "^8.0.0","@typescript-eslint/parser": "^8.0.0",@@ -2784,6 +2787,12 @@"@types/node": "*"}},+ "node_modules/@types/sortablejs": {+ "version": "1.15.8",+ "resolved": "https://registry.npmmirror.com/@types/sortablejs/-/sortablejs-1.15.8.tgz",+ "integrity": "sha512-b79830lW+RZfwaztgs1aVPgbasJ8e7AXtZYHTELNXZPsERt4ymJdjV4OccDbHQAvHrCcFpbF78jkm0R6h/pZVg==",+ "license": "MIT"+ },"node_modules/@types/verror": {"version": "1.10.11","resolved": "https://registry.npmmirror.com/@types/verror/-/verror-1.10.11.tgz",@@ -10255,6 +10264,28 @@"react-dom": ">=16.8"}},+ "node_modules/react-sortablejs": {+ "version": "6.1.4",+ "resolved": "https://registry.npmmirror.com/react-sortablejs/-/react-sortablejs-6.1.4.tgz",+ "integrity": "sha512-fc7cBosfhnbh53Mbm6a45W+F735jwZ1UFIYSrIqcO/gRIFoDyZeMtgKlpV4DdyQfbCzdh5LoALLTDRxhMpTyXQ==",+ "license": "MIT",+ "dependencies": {+ "classnames": "2.3.1",+ "tiny-invariant": "1.2.0"+ },+ "peerDependencies": {+ "@types/sortablejs": "1",+ "react": ">=16.9.0",+ "react-dom": ">=16.9.0",+ "sortablejs": "1"+ }+ },+ "node_modules/react-sortablejs/node_modules/classnames": {+ "version": "2.3.1",+ "resolved": "https://registry.npmmirror.com/classnames/-/classnames-2.3.1.tgz",+ "integrity": "sha512-OlQdbZ7gLfGarSqxesMesDa5uz7KFbID8Kpq/SxIoNGDqY8lSYs0D+hhtBXhcdB3rcbXArFr7vlHheLk1voeNA==",+ "license": "MIT"+ },"node_modules/react-svg": {"version": "16.3.0","resolved": "https://registry.npmmirror.com/react-svg/-/react-svg-16.3.0.tgz",@@ -11196,6 +11227,12 @@"node": ">= 10"}},+ "node_modules/sortablejs": {+ "version": "1.15.6",+ "resolved": "https://registry.npmmirror.com/sortablejs/-/sortablejs-1.15.6.tgz",+ "integrity": "sha512-aNfiuwMEpfBM/CN6LY0ibyhxPfPbyFeBTYJKCvzkJ2GkUpazIt3H+QIPAMHwqQ7tMKaHz1Qj+rJJCqljnf4p3A==",+ "license": "MIT"+ },"node_modules/sorted-array-functions": {"version": "1.3.0","resolved": "https://registry.npmmirror.com/sorted-array-functions/-/sorted-array-functions-1.3.0.tgz",@@ -11851,6 +11888,12 @@"node": ">=12.22"}},+ "node_modules/tiny-invariant": {+ "version": "1.2.0",+ "resolved": "https://registry.npmmirror.com/tiny-invariant/-/tiny-invariant-1.2.0.tgz",+ "integrity": "sha512-1Uhn/aqw5C6RI4KejVeTg6mIS7IqxnLJ8Mv2tV5rTc0qWobay7pDUz6Wi392Cnc8ak1H0F2cjoRzb2/AW4+Fvg==",+ "license": "MIT"+ },"node_modules/tiny-typed-emitter": {"version": "2.1.0","resolved": "https://registry.npmmirror.com/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz",diff --git a/package.json b/package.jsonindex 9d0548f0..2ff348ee 100644--- a/package.json+++ b/package.json@@ -62,8 +62,10 @@"playwright": "^1.49.1","qs": "^6.14.0","react-router-dom": "6",+ "react-sortablejs": "^6.1.4","react-svg": "^16.2.0","reflect-metadata": "^0.2.2",+ "sortablejs": "^1.15.6","typeorm": "^0.3.20","uninstall": "^0.0.0","uuid": "^11.0.5",@@ -80,6 +82,7 @@"@types/qs": "^6.9.18","@types/react": "^18.3.12","@types/react-dom": "^18.3.1",+ "@types/sortablejs": "^1.15.8","@types/xml2js": "^0.4.14","@typescript-eslint/eslint-plugin": "^8.0.0","@typescript-eslint/parser": "^8.0.0",diff --git a/src/components/Choose/ImgChoose.tsx b/src/components/Choose/ImgChoose.tsxindex ef501617..71b7e1eb 100644--- a/src/components/Choose/ImgChoose.tsx+++ b/src/components/Choose/ImgChoose.tsx@@ -7,7 +7,7 @@*/import { Button, message } from 'antd';import { FC } from 'react';-import { getFilePathName } from '@/utils';+import { generateUUID, getFilePathName } from "@/utils";import { icpGetFileStream } from '@/icp/view';interface ImgChooseProps {@@ -21,6 +21,7 @@ interface ImgChooseProps {}export interface IImgFile {+ id: string;size: number;file: Blob;// 前端临时路径,注意不要存到数据库@@ -67,6 +68,7 @@ export const formatImg = async ({const img = new Image();img.onload = () => {resolve({+ id: generateUUID(),width: img.width,height: img.height,imgPath: path,diff --git a/src/views/publish/children/imagePage/components/ImageLeftSetting/ImageLeftSetting.tsx b/src/views/publish/children/imagePage/components/ImageLeftSetting/ImageLeftSetting.tsxindex f9c28590..5304961f 100644--- a/src/views/publish/children/imagePage/components/ImageLeftSetting/ImageLeftSetting.tsx+++ b/src/views/publish/children/imagePage/components/ImageLeftSetting/ImageLeftSetting.tsx@@ -7,6 +7,7 @@ import { Button, Input } from 'antd';import { ArrowRightOutlined } from '@ant-design/icons';import { useShallow } from 'zustand/react/shallow';import { useImagePageStore } from '../../useImagePageStore';+import ImgTextImagesView from './ImgTextImagesView';const { TextArea } = Input;@@ -17,31 +18,48 @@ export interface IImageLeftSettingProps {}const ImageLeftSetting = memo(forwardRef(({}: IImageLeftSettingProps, ref: ForwardedRef<IImageLeftSettingRef>) => {- const { setAllPubParams, commonPubParams, setCommonPubParams } =- useImagePageStore(- useShallow((state) => ({- setAllPubParams: state.setAllPubParams,- commonPubParams: state.commonPubParams,- setCommonPubParams: state.setCommonPubParams,- })),- );+ const {+ setAllPubParams,+ commonPubParams,+ setCommonPubParams,+ addImages,+ images,+ } = useImagePageStore(+ useShallow((state) => ({+ setAllPubParams: state.setAllPubParams,+ commonPubParams: state.commonPubParams,+ setCommonPubParams: state.setCommonPubParams,+ addImages: state.addImages,+ images: state.images,+ })),+ );return (<div className={styles.imageLeftSetting}><div className="imageLeftSetting-upload">- <ImgChoose- onMultipleChoose={(e) => {- console.log(e);- }}- >- <ChooseChunk- text="本地上传"- imgUrl={localUpload}- color="linear-gradient(to right, rgb(255, 142, 28), rgb(255, 124, 24))"- hoverColor="rgb(255, 142, 28)"- style={{ marginRight: '15px', width: '260px', height: '180px' }}- />- </ImgChoose>+ {images.length === 0 ? (+ <ImgChoose+ onMultipleChoose={(imgFiles) => {+ if (imgFiles.length !== 0) {+ addImages(imgFiles);+ }+ }}+ >+ <ChooseChunk+ text="本地上传"+ imgUrl={localUpload}+ color="linear-gradient(to right, rgb(255, 142, 28), rgb(255, 124, 24))"+ hoverColor="rgb(255, 142, 28)"+ style={{+ marginRight: '15px',+ width: '260px',+ height: '180px',+ }}+ />+ </ImgChoose>+ ) : (+ <ImgTextImagesView />+ )}</div><div className="imageLeftSetting-commonPar">diff --git a/src/views/publish/children/imagePage/components/ImageLeftSetting/ImgTextImagesView.tsx b/src/views/publish/children/imagePage/components/ImageLeftSetting/ImgTextImagesView.tsxnew file mode 100644index 00000000..88ad72b1--- /dev/null+++ b/src/views/publish/children/imagePage/components/ImageLeftSetting/ImgTextImagesView.tsx@@ -0,0 +1,96 @@+import { ForwardedRef, forwardRef, memo, useEffect, useState } from 'react';+import styles from './imgTextImagesView.module.scss';+import { Button } from 'antd';+import { CloseOutlined, PlusOutlined } from '@ant-design/icons';+import { useImagePageStore } from '../../useImagePageStore';+import { useShallow } from 'zustand/react/shallow';+import { ReactSortable } from 'react-sortablejs';+import ImgChoose from '../../../../../../components/Choose/ImgChoose';++export interface IImgTextImagesViewRef {}++export interface IImgTextImagesViewProps {}++const ImgTextImagesView = memo(+ forwardRef(+ ({}: IImgTextImagesViewProps, ref: ForwardedRef<IImgTextImagesViewRef>) => {+ const { images, setImages, addImages, imgUploadLimit } =+ useImagePageStore(+ useShallow((state) => ({+ images: state.images,+ setImages: state.setImages,+ addImages: state.addImages,+ imgUploadLimit: state.imgUploadLimit,+ })),+ );+ const [srcollEl, setSrcollEl] = useState<HTMLElement>();++ useEffect(() => {+ const el = document.getElementById('imgTextImagesView-wrapper');+ setSrcollEl(el!);+ }, []);++ return (+ <div className={styles.imgTextImagesView}>+ <div className="imgTextImagesView_head">+ <div className="imgTextImagesView_head-left">+ 图片编辑({images.length}/{imgUploadLimit})+ </div>+ <div className="imgTextImagesView_head-right">+ <div className="imgTextImagesView_head-right-tips">+ 长按拖动排序+ </div>+ <ImgChoose+ onMultipleChoose={(imgFiles) => {+ if (imgFiles.length !== 0) {+ addImages(imgFiles);+ }+ }}+ >+ <Button type="link" icon={<PlusOutlined />}>+ 本地上传+ </Button>+ </ImgChoose>+ </div>+ </div>++ <div id="imgTextImagesView-wrapper">+ {srcollEl && (+ <ReactSortable+ className="imgTextImagesView_content"+ list={images}+ animation={250}+ setList={setImages}+ scrollSensitivity={100}+ scroll={srcollEl}+ scrollSpeed={15}+ >+ {images.map((v, i) => {+ return (+ <div className="imgTextImagesView_content-item" key={v.id}>+ <img src={v.imgUrl} alt={v.filename} />+ <div+ className="imgTextImagesView_content-item-close"+ onClick={() => {+ console.log(i);+ const newImages = [...images];+ newImages.splice(i, 1);+ setImages(newImages);+ }}+ >+ <CloseOutlined />+ </div>+ </div>+ );+ })}+ </ReactSortable>+ )}+ </div>+ </div>+ );+ },+ ),+);+ImgTextImagesView.displayName = 'ImgTextImagesView';++export default ImgTextImagesView;diff --git a/src/views/publish/children/imagePage/components/ImageLeftSetting/imgTextImagesView.module.scss b/src/views/publish/children/imagePage/components/ImageLeftSetting/imgTextImagesView.module.scssnew file mode 100644index 00000000..79bebdd4--- /dev/null+++ b/src/views/publish/children/imagePage/components/ImageLeftSetting/imgTextImagesView.module.scss@@ -0,0 +1,83 @@+.imgTextImagesView {+ width: 100%;+ border-radius: 6px;+ padding: 10px;+ box-sizing: border-box;+ font-size: 15px;+ border: 10px solid rgb(247, 250, 250);+ :global {+ .imgTextImagesView_head {+ display: flex;+ justify-content: space-between;+ align-items: center;+ margin-bottom: 10px;+ &-left {+ }+ &-right {+ display: flex;+ align-items: center;+ &-tips {+ color: var(--lightGreyColor);+ margin-right: 8px;+ }+ button {+ margin: 0;+ padding: 0;+ gap: 3px;+ display: flex;+ align-items: center;+ font-size: 15px;+ }+ }+ }+++ .imgTextImagesView_content {+ display: grid;+ grid-template-columns: repeat(5, 1fr);+ gap: 10px;+ height: 100%;+ box-sizing: border-box;+ &-item {+ min-width: 100px;+ height: 102px;+ border: 1px solid var(--superLightGreyColor);+ cursor: move;+ position: relative;+ &:hover {+ .imgTextImagesView_content-item-close {+ display: block !important;+ }+ }+ img {+ width: 100%;+ height: 100%;+ object-fit: contain;+ user-select: none;+ display: block;+ }+ &-close {+ display: none;+ cursor: pointer;+ background: rgba(0, 0, 0, 0.7);+ width: 16px;+ height: 16px;+ line-height: 15px;+ font-size: 10px;+ text-align: center;+ position: absolute;+ right: 0;+ top: 0;+ color: #fff;+ }+ }+ }++ #imgTextImagesView-wrapper {+ overflow-y: auto;+ overflow-x: hidden;+ max-height: 500px;+ box-sizing: border-box;+ }+ }+}\ No newline at end of filediff --git a/src/views/publish/children/imagePage/components/ImageRightSetting/components/imageParamsSet.module.scss b/src/views/publish/children/imagePage/components/ImageRightSetting/components/imageParamsSet.module.scssindex 1d5afd48..929189a1 100644--- a/src/views/publish/children/imagePage/components/ImageRightSetting/components/imageParamsSet.module.scss+++ b/src/views/publish/children/imagePage/components/ImageRightSetting/components/imageParamsSet.module.scss@@ -56,6 +56,8 @@.paramsSettingItem {width: 100%;+ overflow: auto;+ padding-right: 15px;text-align: left;:global {h1 {diff --git a/src/views/publish/children/imagePage/image.module.scss b/src/views/publish/children/imagePage/image.module.scssindex 222d472a..b4e963d6 100644--- a/src/views/publish/children/imagePage/image.module.scss+++ b/src/views/publish/children/imagePage/image.module.scss@@ -5,13 +5,16 @@height: 100%;:global {.image-wrapper {- width: 80%;+ width: 1200px;margin: 0 auto;height: 100%;min-height: 0;box-sizing: border-box;padding: 15px 0;display: flex;+ @media (max-width: 1450px) {+ width: 90%;+ }}.image-footer {border-top: 1px solid var(--superLightGreyColor);@@ -24,6 +27,7 @@width: 65%;display: flex;flex-direction: column;+ overflow: auto;height: 100%;min-height: 0;box-sizing: border-box;@@ -39,7 +43,6 @@margin-bottom: 25px;}.imageLeftSetting-commonPar {- overflow: auto;height: 100%;&-titles, &-item {display: flex;diff --git a/src/views/publish/children/imagePage/page.tsx b/src/views/publish/children/imagePage/page.tsxindex a35b7fcc..782d67d0 100644--- a/src/views/publish/children/imagePage/page.tsx+++ b/src/views/publish/children/imagePage/page.tsx@@ -7,9 +7,11 @@ import { Button, Popconfirm } from 'antd';import { useEffect } from 'react';export default function Page() {- const { clear } = useImagePageStore(+ const { clear, images, imageAccounts } = useImagePageStore(useShallow((state) => ({clear: state.clear,+ images: state.images,+ imageAccounts: state.imageAccounts,})),);@@ -37,7 +39,16 @@ export default function Page() {><Button style={{ marginRight: '20px' }}>一键清空</Button></Popconfirm>- <Button type="primary">一键发布</Button>+ <Button+ type="primary"+ disabled={imageAccounts.length === 0 || images.length === 0}+ onClick={() => {+ console.log('images:', images);+ console.log('imageAccounts:', imageAccounts);+ }}+ >+ 一键发布+ </Button></div></div>);diff --git a/src/views/publish/children/imagePage/useImagePageStore.ts b/src/views/publish/children/imagePage/useImagePageStore.tsindex ca0f6610..3163862f 100644--- a/src/views/publish/children/imagePage/useImagePageStore.ts+++ b/src/views/publish/children/imagePage/useImagePageStore.ts@@ -7,6 +7,7 @@ import { AccountInfo } from '../../../account/comment';import { useVideoPageStore } from '../videoPage/useVideoPageStore';import { AccountType } from '../../../../../commont/AccountEnum';import { IPubParams } from '../videoPage/videoPage';+import { message } from 'antd';interface IImagePageStore {// 账户数据和对应参数@@ -17,10 +18,14 @@ interface IImagePageStore {platActiveAccountMap: Map<AccountType, IImageAccountItem>;// 当前选择的平台activePlat?: AccountType;+ // 通用参数commonPubParams: IPubParams;+ // 图片上传上限+ imgUploadLimit: number;}const store: IImagePageStore = {+ imgUploadLimit: 35,images: [],imageAccounts: [],platActiveAccountMap: new Map<AccountType, IImageAccountItem>(),@@ -54,6 +59,23 @@ export const useImagePageStore = create(});},+ // 设置图片+ setImages(images: IImgFile[]) {+ set({+ images,+ });+ },++ // 添加图片+ addImages(images: IImgFile[]) {+ if (images.length + get().images.length > get().imgUploadLimit) {+ return message.warning(`最多上传${get().imgUploadLimit}张图片!`);+ }+ set({+ images: [...get().images, ...images],+ });+ },+// 设置所有参数setAllPubParams(pubParmas: IPubParams) {const imageAccounts = [...get().imageAccounts];