|
@@ -1,424 +1,596 @@
|
|
|
import getMD5 from '@/components/MD5';
|
|
|
import { useAjax } from '@/Hook/useAjax';
|
|
|
-import { bdSysMediaList, bdSysMediaAdd, delMedia, bdSysMediaEdit, getFileUrl, getMedia, configSortApi, getFolderTree, editMediaFolder } from '@/services/launchAdq/material';
|
|
|
+import {
|
|
|
+ bdSysMediaList,
|
|
|
+ bdSysMediaAdd,
|
|
|
+ delMedia,
|
|
|
+ bdSysMediaEdit,
|
|
|
+ getFileUrl,
|
|
|
+ getMedia,
|
|
|
+ configSortApi,
|
|
|
+ getFolderTree,
|
|
|
+ editMediaFolder,
|
|
|
+} from '@/services/launchAdq/material';
|
|
|
import { blobToBase64, dataURLtoFile, videoMessage } from '@/utils/compress';
|
|
|
import { getImgSize } from '@/utils/utils';
|
|
|
import { message } from 'antd';
|
|
|
import { compressAccurately } from 'image-conversion';
|
|
|
-import { Dispatch, useCallback, useReducer, useState } from 'react'
|
|
|
+import { Dispatch, useCallback, useReducer, useState } from 'react';
|
|
|
import { request } from 'umi';
|
|
|
|
|
|
type State = {
|
|
|
- fileVisible?: boolean,
|
|
|
- imgVisrible?: boolean,
|
|
|
- newsVisrible?: boolean,
|
|
|
- knewsVisrible?: boolean,
|
|
|
- fileName?: string,
|
|
|
- sort?: number,
|
|
|
- videoTitle?: string,
|
|
|
- videoDescription?: string,
|
|
|
- belongUser?: any,
|
|
|
- mediaType?: 'VIDEO' | 'IMG' | 'PAGE',
|
|
|
- parentId?: any,
|
|
|
- url?: string,
|
|
|
- pathId?: string,
|
|
|
- selectFile?: number[],
|
|
|
- rightClickPup?: any,
|
|
|
- xy?: { x: number, y: number },
|
|
|
- delPupId?: any,
|
|
|
- actionItem?: any,
|
|
|
- path?: any[],
|
|
|
- publicPath?: any[],
|
|
|
- file?: File,
|
|
|
- selectItem?: any[],
|
|
|
- knewsdefaultData?: any,
|
|
|
- sortVisible?: boolean,
|
|
|
- num?: number,
|
|
|
- size?: number,
|
|
|
- upLoadLoading?: boolean,
|
|
|
- cloudSize?: any[],
|
|
|
- maxSize?:number,
|
|
|
-}
|
|
|
+ fileVisible?: boolean;
|
|
|
+ imgVisrible?: boolean;
|
|
|
+ newsVisrible?: boolean;
|
|
|
+ knewsVisrible?: boolean;
|
|
|
+ fileName?: string;
|
|
|
+ sort?: number;
|
|
|
+ videoTitle?: string;
|
|
|
+ videoDescription?: string;
|
|
|
+ belongUser?: any;
|
|
|
+ mediaType?: 'VIDEO' | 'IMG' | 'PAGE';
|
|
|
+ parentId?: any;
|
|
|
+ url?: string;
|
|
|
+ pathId?: string;
|
|
|
+ selectFile?: number[];
|
|
|
+ rightClickPup?: any;
|
|
|
+ xy?: { x: number; y: number };
|
|
|
+ delPupId?: any;
|
|
|
+ actionItem?: any;
|
|
|
+ path?: any[];
|
|
|
+ publicPath?: any[];
|
|
|
+ file?: File;
|
|
|
+ selectItem?: any[];
|
|
|
+ knewsdefaultData?: any;
|
|
|
+ sortVisible?: boolean;
|
|
|
+ num?: number;
|
|
|
+ size?: number;
|
|
|
+ upLoadLoading?: boolean;
|
|
|
+ cloudSize?: any[];
|
|
|
+ maxSize?: number;
|
|
|
+ adcreativeTemplateId?: number;
|
|
|
+ promotedObjectType?: string;
|
|
|
+ promotedObjectId?: string;
|
|
|
+ pageType?: string;
|
|
|
+ canvasType?: string;
|
|
|
+ siteSet?: string[];
|
|
|
+ sourceType?: string;
|
|
|
+ marketingScene?: string;
|
|
|
+};
|
|
|
export type Action = {
|
|
|
- type: 'set' | 'init',
|
|
|
- params?: any
|
|
|
-}
|
|
|
+ type: 'set' | 'init';
|
|
|
+ params?: any;
|
|
|
+};
|
|
|
const typeEnum = {
|
|
|
- 'IMG': '图片',
|
|
|
- 'VIDEO': '视频'
|
|
|
-}
|
|
|
+ IMG: '图片',
|
|
|
+ VIDEO: '视频',
|
|
|
+};
|
|
|
function reducer(state: State, action: Action) {
|
|
|
- let { type, params } = action
|
|
|
- let newState = JSON.parse(JSON.stringify(state))
|
|
|
- newState.file = state.file
|
|
|
- switch (type) {
|
|
|
- case 'set':
|
|
|
- Object.keys(params as State).forEach((key: string) => {
|
|
|
- newState[key] = (params as State)[key]
|
|
|
- })
|
|
|
- return newState
|
|
|
- case 'init':
|
|
|
- return { ...initData, ...params }
|
|
|
- default:
|
|
|
- return state;
|
|
|
- }
|
|
|
+ let { type, params } = action;
|
|
|
+ let newState = JSON.parse(JSON.stringify(state));
|
|
|
+ newState.file = state.file;
|
|
|
+ switch (type) {
|
|
|
+ case 'set':
|
|
|
+ Object.keys(params as State).forEach((key: string) => {
|
|
|
+ newState[key] = (params as State)[key];
|
|
|
+ });
|
|
|
+ return newState;
|
|
|
+ case 'init':
|
|
|
+ return { ...initData, ...params };
|
|
|
+ default:
|
|
|
+ return state;
|
|
|
+ }
|
|
|
}
|
|
|
const initData: State = {
|
|
|
- fileVisible: false,
|
|
|
- knewsVisrible: false,
|
|
|
- videoTitle: '',
|
|
|
- videoDescription: '',
|
|
|
- fileName: '',
|
|
|
- belongUser: '1',
|
|
|
- mediaType: 'IMG',
|
|
|
- parentId: null,
|
|
|
- selectFile: [],
|
|
|
- delPupId: '',
|
|
|
- rightClickPup: { id: '' },
|
|
|
- publicPath: [{ title: '公共本地', number: '0' }],
|
|
|
- path: [{ title: '个人本地', number: '0' }],
|
|
|
- imgVisrible: false,
|
|
|
- newsVisrible: false,
|
|
|
- sortVisible: false,
|
|
|
- sort: 0,
|
|
|
- num: 1
|
|
|
-}
|
|
|
+ fileVisible: false,
|
|
|
+ knewsVisrible: false,
|
|
|
+ videoTitle: '',
|
|
|
+ videoDescription: '',
|
|
|
+ fileName: '',
|
|
|
+ belongUser: '1',
|
|
|
+ mediaType: 'IMG',
|
|
|
+ parentId: null,
|
|
|
+ selectFile: [],
|
|
|
+ delPupId: '',
|
|
|
+ rightClickPup: { id: '' },
|
|
|
+ publicPath: [{ title: '公共本地', number: '0' }],
|
|
|
+ path: [{ title: '个人本地', number: '0' }],
|
|
|
+ imgVisrible: false,
|
|
|
+ newsVisrible: false,
|
|
|
+ sortVisible: false,
|
|
|
+ sort: 0,
|
|
|
+ num: 1,
|
|
|
+};
|
|
|
|
|
|
function useBdMediaPup() {
|
|
|
- const [state, dispatch]: [State, Dispatch<Action>] = useReducer(reducer, initData)
|
|
|
- const { fileName, sort, belongUser, mediaType, parentId, selectFile, selectItem, delPupId, cloudSize, num, rightClickPup, actionItem, path, publicPath, videoTitle, videoDescription, size,maxSize } = state
|
|
|
- const list = useAjax((params) => bdSysMediaList(params))
|
|
|
- const add = useAjax((params) => bdSysMediaAdd(params), { msgNmae: '新增' })
|
|
|
- const del = useAjax((params) => delMedia(params), { msgNmae: '删除' })
|
|
|
- const edit = useAjax((params) => bdSysMediaEdit(params), { msgNmae: '编辑' })
|
|
|
- const configSort = useAjax((params) => configSortApi(params), { msgNmae: '排序' })
|
|
|
- const get = useAjax((params) => getMedia(params))
|
|
|
- const get_folder_tree = useAjax((params: any) => getFolderTree(params))
|
|
|
- const edit_media_folder = useAjax((params: any) => editMediaFolder(params))
|
|
|
- const [isOk, setIsOk] = useState<boolean>(true)
|
|
|
-
|
|
|
- const fileUrl = useAjax((params: { type: string, fileType: 'video' | 'image' }) => getFileUrl(params), {
|
|
|
- manual: true,
|
|
|
- })
|
|
|
-
|
|
|
- const init = useCallback((params: any) => {
|
|
|
- console.log('params======>',params)
|
|
|
- dispatch({ type: 'init', params })
|
|
|
- }, [])
|
|
|
-
|
|
|
- const set = useCallback((params: State) => {
|
|
|
- if (params) {
|
|
|
- dispatch({ type: 'set', params })
|
|
|
- }
|
|
|
- }, [])
|
|
|
-
|
|
|
- const addFolder = () => {
|
|
|
- if (fileName) {
|
|
|
- let obj = { title: fileName, mediaType, folder: true, parentId, belongUser: belongUser === '0' ? false : true, sort }
|
|
|
- add.run(obj).then((res) => {
|
|
|
- get_folder_tree.refresh()
|
|
|
- list.refresh()
|
|
|
- offEditFile()
|
|
|
- })
|
|
|
- }
|
|
|
+ const [state, dispatch]: [State, Dispatch<Action>] = useReducer(reducer, initData);
|
|
|
+ const {
|
|
|
+ fileName,
|
|
|
+ sort,
|
|
|
+ belongUser,
|
|
|
+ mediaType,
|
|
|
+ parentId,
|
|
|
+ selectFile,
|
|
|
+ selectItem,
|
|
|
+ delPupId,
|
|
|
+ cloudSize,
|
|
|
+ num,
|
|
|
+ rightClickPup,
|
|
|
+ actionItem,
|
|
|
+ path,
|
|
|
+ publicPath,
|
|
|
+ videoTitle,
|
|
|
+ videoDescription,
|
|
|
+ size,
|
|
|
+ maxSize,
|
|
|
+ adcreativeTemplateId,
|
|
|
+ promotedObjectType,
|
|
|
+ promotedObjectId,
|
|
|
+ pageType,
|
|
|
+ canvasType,
|
|
|
+ siteSet,
|
|
|
+ sourceType,
|
|
|
+ marketingScene,
|
|
|
+ } = state;
|
|
|
+ const list = useAjax((params) => bdSysMediaList(params));
|
|
|
+ const add = useAjax((params) => bdSysMediaAdd(params), { msgNmae: '新增' });
|
|
|
+ const del = useAjax((params) => delMedia(params), { msgNmae: '删除' });
|
|
|
+ const edit = useAjax((params) => bdSysMediaEdit(params), { msgNmae: '编辑' });
|
|
|
+ const configSort = useAjax((params) => configSortApi(params), { msgNmae: '排序' });
|
|
|
+ const get = useAjax((params) => getMedia(params));
|
|
|
+ const get_folder_tree = useAjax((params: any) => getFolderTree(params));
|
|
|
+ const edit_media_folder = useAjax((params: any) => editMediaFolder(params));
|
|
|
+ const [isOk, setIsOk] = useState<boolean>(true);
|
|
|
+
|
|
|
+ const fileUrl = useAjax(
|
|
|
+ (params: { type: string; fileType: 'video' | 'image' }) => getFileUrl(params),
|
|
|
+ {
|
|
|
+ manual: true,
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ const init = useCallback((params: State) => {
|
|
|
+ console.log('params======>', params);
|
|
|
+ dispatch({ type: 'init', params });
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const set = useCallback((params: State) => {
|
|
|
+ if (params) {
|
|
|
+ dispatch({ type: 'set', params });
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const addFolder = () => {
|
|
|
+ if (fileName) {
|
|
|
+ let obj = {
|
|
|
+ title: fileName,
|
|
|
+ mediaType,
|
|
|
+ folder: true,
|
|
|
+ parentId,
|
|
|
+ belongUser: belongUser === '0' ? false : true,
|
|
|
+ sort,
|
|
|
+ };
|
|
|
+ add.run(obj).then((res) => {
|
|
|
+ get_folder_tree.refresh();
|
|
|
+ list.refresh();
|
|
|
+ offEditFile();
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
- const addFile = async (data: any) => {
|
|
|
- if (data) {
|
|
|
- if (!data) {
|
|
|
- return
|
|
|
+ };
|
|
|
+
|
|
|
+ const addFile = async (data: any) => {
|
|
|
+ if (data) {
|
|
|
+
|
|
|
+ if (!data) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (data?.file) {
|
|
|
+ let file = data.file;
|
|
|
+ let fileSize = size || 0;
|
|
|
+ if (!size) {
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ fileSize = 307200;
|
|
|
+ } else {
|
|
|
+ fileSize = 104857600;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ if (file?.size > fileSize) {
|
|
|
+
|
|
|
+ let bole = await compressAccurately(file, 250);
|
|
|
+ if (bole?.size > 300000) {
|
|
|
+ bole = await compressAccurately(file, 200);
|
|
|
}
|
|
|
- if (data?.file) {
|
|
|
- let file = data.file
|
|
|
- let fileSize = size || 0
|
|
|
- if (!size) {
|
|
|
- if (mediaType === 'IMG') {
|
|
|
- fileSize = 307200
|
|
|
- } else {
|
|
|
- fileSize = 104857600
|
|
|
- }
|
|
|
- }
|
|
|
+ if (bole?.size > 300000) {
|
|
|
+ bole = await compressAccurately(file, 150);
|
|
|
+ }
|
|
|
+ if (bole?.size > 300000) {
|
|
|
+ bole = await compressAccurately(file, 100);
|
|
|
+ }
|
|
|
+ let newFile = await blobToBase64(bole);
|
|
|
+ message.warning({
|
|
|
+ content: `选择的图片大于${fileSize / 1024}KB,图片已压缩`,
|
|
|
+ duration: 3,
|
|
|
+ });
|
|
|
+ file = await dataURLtoFile(newFile, file?.name);
|
|
|
+ }
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ if (file?.size > fileSize) {
|
|
|
+
|
|
|
+ message.error({
|
|
|
+ content: `选择的视频大于${fileSize / 1024 / 1024}MB,请重新选择提交`,
|
|
|
+ duration: 3,
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ set({ upLoadLoading: true });
|
|
|
+ let width = 0;
|
|
|
+ let height = 0;
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ let imgData = await getImgSize(file);
|
|
|
+ width = imgData.width;
|
|
|
+ height = imgData.height;
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ let videoInfo: any = await videoMessage([file]);
|
|
|
+ width = videoInfo[0].width;
|
|
|
+ height = videoInfo[0].height;
|
|
|
+ }
|
|
|
+
|
|
|
+ let newFile = new File(
|
|
|
+ [file],
|
|
|
+ data?.title ? data?.title + '.' + file?.name?.split('.')[1] : file?.name,
|
|
|
+ { type: file?.type },
|
|
|
+ );
|
|
|
+ let formData = new FormData();
|
|
|
|
|
|
- if (mediaType === 'IMG') {
|
|
|
- if (file?.size > fileSize) {
|
|
|
- let bole = await compressAccurately(file, 250)
|
|
|
- if (bole?.size > 300000) {
|
|
|
- bole = await compressAccurately(file, 200)
|
|
|
- }
|
|
|
- if (bole?.size > 300000) {
|
|
|
- bole = await compressAccurately(file, 150)
|
|
|
- }
|
|
|
- if (bole?.size > 300000) {
|
|
|
- bole = await compressAccurately(file, 100)
|
|
|
- }
|
|
|
- let newFile = await blobToBase64(bole)
|
|
|
- message.warning({
|
|
|
- content: `选择的图片大于${fileSize / 1024}KB,图片已压缩`,
|
|
|
- duration: 3
|
|
|
+
|
|
|
+ fileUrl
|
|
|
+ .run({ type: newFile.type, fileType: mediaType === 'VIDEO' ? 'video' : 'image' })
|
|
|
+ .then((res1) => {
|
|
|
+ Object.keys(res1).forEach((key: string) => {
|
|
|
+ if (key !== 'url') {
|
|
|
+ formData.append(key, res1[key]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ formData.append('file', newFile);
|
|
|
+
|
|
|
+ request(res1?.ossUrl, { method: 'post', body: formData })
|
|
|
+ .then(async (res2: { code: number; data: { url: string } }) => {
|
|
|
+ if (res2.code === 200) {
|
|
|
+ message.success('上传成功');
|
|
|
+ if (data) {
|
|
|
+
|
|
|
+ if (res2?.data?.url) {
|
|
|
+ let fileMd5 = await getMD5(newFile);
|
|
|
+ let obj = {
|
|
|
+ title: data.title,
|
|
|
+ mediaType,
|
|
|
+ folder: false,
|
|
|
+ parentId,
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ fileMd5,
|
|
|
+ belongUser: belongUser === '0' ? false : true,
|
|
|
+ url: res2?.data?.url,
|
|
|
+ sort: data?.sort,
|
|
|
+ fileSize: newFile?.size,
|
|
|
+ fileMime: newFile.type,
|
|
|
+ };
|
|
|
+ if (mediaType === 'VIDEO') {
|
|
|
+ obj['videoTitle'] = data?.videoTitle || data?.title;
|
|
|
+ obj['videoDescription'] = data?.videoDescription;
|
|
|
+ }
|
|
|
+ add
|
|
|
+ .run(obj)
|
|
|
+ .then((res) => {
|
|
|
+ list.refresh();
|
|
|
+ offEditFile();
|
|
|
+ set({ upLoadLoading: false });
|
|
|
})
|
|
|
- file = await dataURLtoFile(newFile, file?.name)
|
|
|
+ .catch(() => set({ upLoadLoading: false }));
|
|
|
}
|
|
|
- } else if (mediaType === 'VIDEO') {
|
|
|
- if (file?.size > fileSize) {
|
|
|
- message.error({
|
|
|
- content: `选择的视频大于${fileSize / 1024 / 1024}MB,请重新选择提交`,
|
|
|
- duration: 3
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- set({ upLoadLoading: true })
|
|
|
- let width = 0
|
|
|
- let height = 0
|
|
|
- if (mediaType === 'IMG') {
|
|
|
- let imgData = await getImgSize(file)
|
|
|
- width = imgData.width
|
|
|
- height = imgData.height
|
|
|
- } else if (mediaType === "VIDEO") {
|
|
|
- let videoInfo: any = await videoMessage([file])
|
|
|
- width = videoInfo[0].width
|
|
|
- height = videoInfo[0].height
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ message.error('上传失败!');
|
|
|
}
|
|
|
-
|
|
|
- let newFile = new File([file], data?.title ? data?.title + '.' + file?.name?.split('.')[1] : file?.name, { type: file?.type })
|
|
|
- let formData = new FormData();
|
|
|
-
|
|
|
-
|
|
|
- fileUrl.run({ type: newFile.type, fileType: mediaType === 'VIDEO' ? 'video' : 'image' }).then(res1 => {
|
|
|
- Object.keys(res1).forEach((key: string) => {
|
|
|
- if (key !== 'url') {
|
|
|
- formData.append(key, res1[key])
|
|
|
- }
|
|
|
- })
|
|
|
- formData.append('file', newFile)
|
|
|
-
|
|
|
- request(res1?.ossUrl, { method: 'post', body: formData }).then(async (res2: { code: number, data: { url: string } }) => {
|
|
|
- if (res2.code === 200) {
|
|
|
- message.success('上传成功')
|
|
|
- if (data) {
|
|
|
-
|
|
|
- if (res2?.data?.url) {
|
|
|
- let fileMd5 = await getMD5(newFile)
|
|
|
- let obj = { title: data.title, mediaType, folder: false, parentId, width, height, fileMd5, belongUser: belongUser === '0' ? false : true, url: res2?.data?.url, sort: data?.sort, fileSize: newFile?.size, fileMime: newFile.type }
|
|
|
- if (mediaType === 'VIDEO') {
|
|
|
- obj['videoTitle'] = data?.videoTitle || data?.title
|
|
|
- obj['videoDescription'] = data?.videoDescription
|
|
|
- }
|
|
|
- add.run(obj).then((res) => {
|
|
|
- list.refresh()
|
|
|
- offEditFile()
|
|
|
- set({ upLoadLoading: false })
|
|
|
- }).catch(() => set({ upLoadLoading: false }))
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- message.error('上传失败!')
|
|
|
- }
|
|
|
- }).catch(() => set({ upLoadLoading: false }))
|
|
|
- }).catch(() => set({ upLoadLoading: false }))
|
|
|
- }
|
|
|
- }
|
|
|
+ })
|
|
|
+ .catch(() => set({ upLoadLoading: false }));
|
|
|
+ })
|
|
|
+ .catch(() => set({ upLoadLoading: false }));
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- const nameOk = useCallback((selectWx: any) => {
|
|
|
- if (fileName && actionItem) {
|
|
|
- let obj = { title: fileName, belongUser: belongUser === '0' ? false : true, sysMediaId: actionItem?.id, mediaType: actionItem?.mediaType, folder: actionItem?.folder, url: actionItem?.url, sort }
|
|
|
- if (mediaType === 'VIDEO') {
|
|
|
- obj['videoTitle'] = videoTitle
|
|
|
- obj['videoDescription'] = videoDescription
|
|
|
- }
|
|
|
- edit.run(obj).then((res) => {
|
|
|
- list.refresh()
|
|
|
- offEditFile()
|
|
|
- })
|
|
|
- }
|
|
|
- }, [fileName, actionItem, edit, belongUser, mediaType, videoTitle, videoDescription])
|
|
|
-
|
|
|
- const dels = useCallback((id?: any) => {
|
|
|
- let arr = typeof id === 'number' ? [id] : selectFile
|
|
|
- let len = arr?.length || 0
|
|
|
- if (len) {
|
|
|
- arr?.map((id, index) => {
|
|
|
- del.run({ sysMediaId: id, mediaType }).then(() => {
|
|
|
- set({ selectFile: selectFile?.filter(i => i !== id) })
|
|
|
- if (index === len - 1) {
|
|
|
- list.refresh()
|
|
|
- get_folder_tree.refresh()
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
+ };
|
|
|
+
|
|
|
+ const nameOk = useCallback(
|
|
|
+ (selectWx: any) => {
|
|
|
+ if (fileName && actionItem) {
|
|
|
+ let obj = {
|
|
|
+ title: fileName,
|
|
|
+ belongUser: belongUser === '0' ? false : true,
|
|
|
+ sysMediaId: actionItem?.id,
|
|
|
+ mediaType: actionItem?.mediaType,
|
|
|
+ folder: actionItem?.folder,
|
|
|
+ url: actionItem?.url,
|
|
|
+ sort,
|
|
|
+ };
|
|
|
+ if (mediaType === 'VIDEO') {
|
|
|
+ obj['videoTitle'] = videoTitle;
|
|
|
+ obj['videoDescription'] = videoDescription;
|
|
|
}
|
|
|
- }, [list, selectFile, mediaType])
|
|
|
-
|
|
|
- const getList = useCallback((props?: any) => {
|
|
|
- console.log('getList====>',props)
|
|
|
- let obj = { pageSize: 20, pageNum: 1, belongUser: belongUser === '0' ? false : true, mediaType, parentId, sizeQueries: cloudSize,maxSize, ...props }
|
|
|
- list.run(obj).then((res) => {
|
|
|
- setIsOk(true)
|
|
|
- })
|
|
|
- }, [list, mediaType, belongUser, parentId, cloudSize,maxSize])
|
|
|
-
|
|
|
- const onFile = useCallback((e: any, item: { id: any, folder?: boolean }, isAll?: boolean, single?: boolean) => {
|
|
|
- let { id } = item
|
|
|
- e?.stopPropagation()
|
|
|
- if (isAll && !single) {
|
|
|
- set({ selectFile: [...new Set([...selectFile as number[], id])] })
|
|
|
- } else {
|
|
|
- if (item?.folder && !single) {
|
|
|
- message.error('不能选择文件夹')
|
|
|
- return
|
|
|
+ edit.run(obj).then((res) => {
|
|
|
+ list.refresh();
|
|
|
+ offEditFile();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [fileName, actionItem, edit, belongUser, mediaType, videoTitle, videoDescription],
|
|
|
+ );
|
|
|
+
|
|
|
+ const dels = useCallback(
|
|
|
+ (id?: any) => {
|
|
|
+ let arr = typeof id === 'number' ? [id] : selectFile;
|
|
|
+ let len = arr?.length || 0;
|
|
|
+ if (len) {
|
|
|
+ arr?.map((id, index) => {
|
|
|
+ del.run({ sysMediaId: id, mediaType }).then(() => {
|
|
|
+ set({ selectFile: selectFile?.filter((i) => i !== id) });
|
|
|
+ if (index === len - 1) {
|
|
|
+ list.refresh();
|
|
|
+ get_folder_tree.refresh();
|
|
|
}
|
|
|
- set({ selectFile: [item.id], selectItem: [item] })
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [list, selectFile, mediaType],
|
|
|
+ );
|
|
|
+
|
|
|
+ const getList = useCallback(
|
|
|
+ (props?: any) => {
|
|
|
+ console.log('getList====>', props);
|
|
|
+ let obj = {
|
|
|
+ pageSize: 20,
|
|
|
+ pageNum: 1,
|
|
|
+ belongUser: belongUser === '0' ? false : true,
|
|
|
+ mediaType,
|
|
|
+ parentId,
|
|
|
+ sizeQueries: cloudSize,
|
|
|
+ maxSize,
|
|
|
+ ...props,
|
|
|
+ };
|
|
|
+ if (mediaType === 'PAGE') {
|
|
|
+ obj = {
|
|
|
+ ...obj,
|
|
|
+ adcreativeTemplateId,
|
|
|
+ promotedObjectType,
|
|
|
+ promotedObjectId,
|
|
|
+ pageType,
|
|
|
+ canvasType,
|
|
|
+ siteSet,
|
|
|
+ sourceType,
|
|
|
+ marketingScene,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ list.run(obj).then((res) => {
|
|
|
+ setIsOk(true);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ [list, mediaType, belongUser, parentId, cloudSize, maxSize,adcreativeTemplateId,promotedObjectType,promotedObjectId,pageType,canvasType,siteSet,sourceType,marketingScene],
|
|
|
+ );
|
|
|
+
|
|
|
+ const onFile = useCallback(
|
|
|
+ (e: any, item: { id: any; folder?: boolean }, isAll?: boolean, single?: boolean) => {
|
|
|
+ let { id } = item;
|
|
|
+ e?.stopPropagation();
|
|
|
+ if (isAll && !single) {
|
|
|
+ set({ selectFile: [...new Set([...(selectFile as number[]), id])] });
|
|
|
+ } else {
|
|
|
+ if (item?.folder && !single) {
|
|
|
+
|
|
|
+ message.error('不能选择文件夹');
|
|
|
+ return;
|
|
|
}
|
|
|
- }, [selectFile])
|
|
|
-
|
|
|
- const fileClick = useCallback((item) => {
|
|
|
- if (isOk) {
|
|
|
- setIsOk(false)
|
|
|
- if (belongUser == '1' && path) {
|
|
|
- set({ path: [...path, item] })
|
|
|
- }
|
|
|
- if (belongUser == '0' && publicPath) {
|
|
|
- set({ publicPath: [...publicPath, item] })
|
|
|
- }
|
|
|
- set({ parentId: item.id })
|
|
|
- getList({ parentId: item.id })
|
|
|
+ set({ selectFile: [item.id], selectItem: [item] });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [selectFile],
|
|
|
+ );
|
|
|
+
|
|
|
+ const fileClick = useCallback(
|
|
|
+ (item) => {
|
|
|
+ if (isOk) {
|
|
|
+ setIsOk(false);
|
|
|
+ if (belongUser == '1' && path) {
|
|
|
+ set({ path: [...path, item] });
|
|
|
}
|
|
|
- }, [path, publicPath, mediaType, belongUser, isOk])
|
|
|
-
|
|
|
- const treeClick = useCallback((item) => {
|
|
|
- if (isOk) {
|
|
|
- setIsOk(false)
|
|
|
- console.log(item, belongUser == '1')
|
|
|
- if (belongUser == '1' && path) {
|
|
|
- set({ path: [path[0], item] })
|
|
|
- }
|
|
|
- if (belongUser == '0' && publicPath) {
|
|
|
- set({ publicPath: [publicPath[0], item] })
|
|
|
- }
|
|
|
- set({ parentId: item.id })
|
|
|
- getList({ parentId: item.id })
|
|
|
+ if (belongUser == '0' && publicPath) {
|
|
|
+ set({ publicPath: [...publicPath, item] });
|
|
|
}
|
|
|
- }, [path, publicPath, mediaType, belongUser, isOk])
|
|
|
-
|
|
|
- const pathClick = useCallback((item) => {
|
|
|
- let newPath: any[] = []
|
|
|
- if (belongUser == '1') {
|
|
|
- path?.forEach((paths, index) => {
|
|
|
- if (index <= item.index) {
|
|
|
- newPath.push(paths)
|
|
|
- }
|
|
|
- })
|
|
|
- set({ path: newPath })
|
|
|
- } else {
|
|
|
- publicPath?.forEach((paths, index) => {
|
|
|
- if (index <= item.index) {
|
|
|
- newPath.push(paths)
|
|
|
- }
|
|
|
- })
|
|
|
- set({ publicPath: newPath })
|
|
|
+ set({ parentId: item.id });
|
|
|
+ getList({ parentId: item.id });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [path, publicPath, mediaType, belongUser, isOk],
|
|
|
+ );
|
|
|
+
|
|
|
+ const treeClick = useCallback(
|
|
|
+ (item) => {
|
|
|
+ if (isOk) {
|
|
|
+ setIsOk(false);
|
|
|
+ console.log(item, belongUser == '1');
|
|
|
+ if (belongUser == '1' && path) {
|
|
|
+ set({ path: [path[0], item] });
|
|
|
+ }
|
|
|
+ if (belongUser == '0' && publicPath) {
|
|
|
+ set({ publicPath: [publicPath[0], item] });
|
|
|
}
|
|
|
- set({ parentId: item.parentId })
|
|
|
- getList({ pageSize: 20, pageNum: 1, mediaType, belongUser: belongUser === '0' ? false : true, parentId: item.id })
|
|
|
- }, [path, mediaType, belongUser, publicPath])
|
|
|
-
|
|
|
- const offFile = useCallback((e: any, item: { id: any }) => {
|
|
|
- let { id } = item
|
|
|
- set({ selectFile: selectFile?.filter(i => i !== id) })
|
|
|
- }, [selectFile])
|
|
|
-
|
|
|
- const changeClickFile = useCallback((e: any, item: { id: any, folder?: boolean }, isAll?: boolean, noFile?: boolean) => {
|
|
|
- let { id } = item
|
|
|
- e?.stopPropagation()
|
|
|
- console.log(111111, num);
|
|
|
-
|
|
|
-
|
|
|
+ set({ parentId: item.id });
|
|
|
+ getList({ parentId: item.id });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [path, publicPath, mediaType, belongUser, isOk],
|
|
|
+ );
|
|
|
+
|
|
|
+ const pathClick = useCallback(
|
|
|
+ (item) => {
|
|
|
+ let newPath: any[] = [];
|
|
|
+ if (belongUser == '1') {
|
|
|
+ path?.forEach((paths, index) => {
|
|
|
+
|
|
|
+ if (index <= item.index) {
|
|
|
+ newPath.push(paths);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ set({ path: newPath });
|
|
|
+ } else {
|
|
|
+ publicPath?.forEach((paths, index) => {
|
|
|
+
|
|
|
+ if (index <= item.index) {
|
|
|
+ newPath.push(paths);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ set({ publicPath: newPath });
|
|
|
+ }
|
|
|
+ set({ parentId: item.parentId });
|
|
|
+ getList({
|
|
|
+ pageSize: 20,
|
|
|
+ pageNum: 1,
|
|
|
+ mediaType,
|
|
|
+ belongUser: belongUser === '0' ? false : true,
|
|
|
+ parentId: item.id,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ [path, mediaType, belongUser, publicPath],
|
|
|
+ );
|
|
|
+
|
|
|
+ const offFile = useCallback(
|
|
|
+ (e: any, item: { id: any }) => {
|
|
|
+ let { id } = item;
|
|
|
+ set({ selectFile: selectFile?.filter((i) => i !== id) });
|
|
|
+ },
|
|
|
+ [selectFile],
|
|
|
+ );
|
|
|
+
|
|
|
+ const changeClickFile = useCallback(
|
|
|
+ (e: any, item: { id: any; folder?: boolean }, isAll?: boolean, noFile?: boolean) => {
|
|
|
+ let { id } = item;
|
|
|
+ e?.stopPropagation();
|
|
|
+ console.log(111111, num);
|
|
|
|
|
|
-
|
|
|
- let state = selectFile?.some((i) => i === id)
|
|
|
- if (state) {
|
|
|
- set({ selectFile: selectFile?.filter(i => i !== id), selectItem: selectItem?.filter((i: { id: number }) => i.id !== id) })
|
|
|
- } else {
|
|
|
- if (num === 1) {
|
|
|
- if (state) {
|
|
|
- set({ selectFile: selectFile?.filter(i => i !== id), selectItem: [] })
|
|
|
- } else {
|
|
|
- console.log(11111)
|
|
|
- set({ selectFile: [id], selectItem: [item] })
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (selectFile && num && (selectFile?.length >= num)) {
|
|
|
- message.error(`只能选择${num}张`)
|
|
|
- return
|
|
|
- }
|
|
|
- let newSelectItem = selectItem || []
|
|
|
- newSelectItem.push(item)
|
|
|
- set({ selectItem: newSelectItem, selectFile: [...selectFile as number[], id] })
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }, [selectFile, mediaType, num])
|
|
|
-
|
|
|
- const delPupOn = useCallback((delPupId) => {
|
|
|
- set({ delPupId })
|
|
|
- }, [])
|
|
|
-
|
|
|
- const delPupOff = useCallback(() => {
|
|
|
- set({ delPupId: '' })
|
|
|
- offFile(null, { id: delPupId })
|
|
|
- }, [delPupId,])
|
|
|
-
|
|
|
- const editFile = useCallback((e?: any,) => {
|
|
|
- e?.stopPropagation()
|
|
|
- onFile(null, rightClickPup, true, true)
|
|
|
-
|
|
|
- let obj = { fileVisible: true, actionItem: rightClickPup, fileName: rightClickPup.title, sort: rightClickPup.sort }
|
|
|
- if (rightClickPup?.mediaType === 'video') {
|
|
|
- obj['videoTitle'] = rightClickPup?.videoTitle || rightClickPup?.title
|
|
|
- obj['videoDescription'] = rightClickPup?.videoDescription
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let state = selectFile?.some((i) => i === id);
|
|
|
+ if (state) {
|
|
|
+
|
|
|
+ set({
|
|
|
+ selectFile: selectFile?.filter((i) => i !== id),
|
|
|
+ selectItem: selectItem?.filter((i: { id: number }) => i.id !== id),
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (num === 1) {
|
|
|
+ if (state) {
|
|
|
+
|
|
|
+ set({ selectFile: selectFile?.filter((i) => i !== id), selectItem: [] });
|
|
|
+ } else {
|
|
|
+
|
|
|
+ console.log(11111);
|
|
|
+ set({ selectFile: [id], selectItem: [item] });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (selectFile && num && selectFile?.length >= num) {
|
|
|
+ message.error(`只能选择${num}张`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let newSelectItem = selectItem || [];
|
|
|
+ newSelectItem.push(item);
|
|
|
+ set({ selectItem: newSelectItem, selectFile: [...(selectFile as number[]), id] });
|
|
|
}
|
|
|
- set(obj)
|
|
|
-
|
|
|
- }, [rightClickPup])
|
|
|
-
|
|
|
- const offEditFile = useCallback(() => {
|
|
|
- set({ fileVisible: false, imgVisrible: false, sortVisible: false, actionItem: '', fileName: '', selectFile: selectFile?.filter(id => id !== actionItem?.id), sort: 0 })
|
|
|
- }, [selectFile, actionItem])
|
|
|
-
|
|
|
- const allFile = useCallback(() => {
|
|
|
- let allArr: any[] = []
|
|
|
- list?.data?.records?.forEach((item: { id: any }) => {
|
|
|
- allArr.push(item.id)
|
|
|
- })
|
|
|
- set({ selectFile: allArr.filter((i) => selectFile?.every(id => id !== i)) })
|
|
|
- }, [selectFile, list, mediaType])
|
|
|
- return {
|
|
|
- state,
|
|
|
- init,
|
|
|
- set,
|
|
|
- addFile,
|
|
|
- addFolder,
|
|
|
- getList,
|
|
|
- dels,
|
|
|
- onFile,
|
|
|
- changeClickFile,
|
|
|
- allFile,
|
|
|
- delPupOn,
|
|
|
- delPupOff,
|
|
|
- editFile,
|
|
|
- offEditFile,
|
|
|
- nameOk,
|
|
|
- fileClick,
|
|
|
- treeClick,
|
|
|
- pathClick,
|
|
|
- configSort,
|
|
|
- list,
|
|
|
- add,
|
|
|
- get,
|
|
|
- edit,
|
|
|
- typeEnum,
|
|
|
- get_folder_tree,
|
|
|
- edit_media_folder
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ [selectFile, mediaType, num],
|
|
|
+ );
|
|
|
+
|
|
|
+ const delPupOn = useCallback((delPupId) => {
|
|
|
+ set({ delPupId });
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const delPupOff = useCallback(() => {
|
|
|
+ set({ delPupId: '' });
|
|
|
+ offFile(null, { id: delPupId });
|
|
|
+ }, [delPupId]);
|
|
|
+
|
|
|
+ const editFile = useCallback(
|
|
|
+ (e?: any) => {
|
|
|
+ e?.stopPropagation();
|
|
|
+ onFile(null, rightClickPup, true, true);
|
|
|
+
|
|
|
+ let obj = {
|
|
|
+ fileVisible: true,
|
|
|
+ actionItem: rightClickPup,
|
|
|
+ fileName: rightClickPup.title,
|
|
|
+ sort: rightClickPup.sort,
|
|
|
+ };
|
|
|
+ if (rightClickPup?.mediaType === 'video') {
|
|
|
+ obj['videoTitle'] = rightClickPup?.videoTitle || rightClickPup?.title;
|
|
|
+ obj['videoDescription'] = rightClickPup?.videoDescription;
|
|
|
+ }
|
|
|
+ set(obj);
|
|
|
+
|
|
|
+ },
|
|
|
+ [rightClickPup],
|
|
|
+ );
|
|
|
+
|
|
|
+ const offEditFile = useCallback(() => {
|
|
|
+ set({
|
|
|
+ fileVisible: false,
|
|
|
+ imgVisrible: false,
|
|
|
+ sortVisible: false,
|
|
|
+ actionItem: '',
|
|
|
+ fileName: '',
|
|
|
+ selectFile: selectFile?.filter((id) => id !== actionItem?.id),
|
|
|
+ sort: 0,
|
|
|
+ });
|
|
|
+ }, [selectFile, actionItem]);
|
|
|
+
|
|
|
+ const allFile = useCallback(() => {
|
|
|
+ let allArr: any[] = [];
|
|
|
+ list?.data?.records?.forEach((item: { id: any }) => {
|
|
|
+ allArr.push(item.id);
|
|
|
+ });
|
|
|
+ set({ selectFile: allArr.filter((i) => selectFile?.every((id) => id !== i)) });
|
|
|
+ }, [selectFile, list, mediaType]);
|
|
|
+ return {
|
|
|
+ state,
|
|
|
+ init,
|
|
|
+ set,
|
|
|
+ addFile,
|
|
|
+ addFolder,
|
|
|
+ getList,
|
|
|
+ dels,
|
|
|
+ onFile,
|
|
|
+ changeClickFile,
|
|
|
+ allFile,
|
|
|
+ delPupOn,
|
|
|
+ delPupOff,
|
|
|
+ editFile,
|
|
|
+ offEditFile,
|
|
|
+ nameOk,
|
|
|
+ fileClick,
|
|
|
+ treeClick,
|
|
|
+ pathClick,
|
|
|
+ configSort,
|
|
|
+ list,
|
|
|
+ add,
|
|
|
+ get,
|
|
|
+ edit,
|
|
|
+ typeEnum,
|
|
|
+ get_folder_tree,
|
|
|
+ edit_media_folder,
|
|
|
+ };
|
|
|
}
|
|
|
-export default useBdMediaPup
|
|
|
+export default useBdMediaPup;
|