|
@@ -1,6 +1,6 @@
|
|
|
import getMD5 from '@/components/MD5';
|
|
|
import { useAjax } from '@/Hook/useAjax';
|
|
|
-import { bdSysMediaList, bdSysMediaAdd, delMedia, bdSysMediaEdit, getFileUrl, syncMedia, getMedia, configSortApi, syncForSend, wxSysMediaAdd, editWxlist, getFolderTree, editMediaFolder } from '@/services/launchAdq/material';
|
|
|
+import { bdSysMediaListImg, bdSysMediaListVideo, bdSysMediaAdd, delMedia, bdSysMediaEdit, getFileUrl, syncMedia, getMedia, configSortApi, syncForSend, wxSysMediaAdd, editWxlist, getFolderTreeImg, getFolderTreeVideo, editMediaFolder } from '@/services/launchAdq/material';
|
|
|
import { message } from 'antd';
|
|
|
import { Dispatch, useCallback, useReducer, useState } from 'react'
|
|
|
import { request } from 'umi';
|
|
@@ -15,7 +15,7 @@ type State = {
|
|
|
videoTitle?: string,//video文件名称
|
|
|
videoDescription?: string,//视频描述
|
|
|
belongUser?: any,//0公共本地|1个人本地
|
|
|
- fileType?: 'image' | 'news' | 'voice' | 'video' | 'knews',//类型
|
|
|
+ mediaType?: 'VIDEO' | 'IMG',//类型
|
|
|
parentId?: any,//上级目录ID,顶级使用null
|
|
|
url?: string,//素材地址
|
|
|
pathId?: string,//路径ID
|
|
@@ -36,11 +36,8 @@ export type Action = {
|
|
|
params?: any
|
|
|
}
|
|
|
const typeEnum = {
|
|
|
- 'image': '图片',
|
|
|
- 'news': '图文素材',
|
|
|
- 'voice': '音频',
|
|
|
- 'video': '视频',
|
|
|
- 'knews': 'K-图文'
|
|
|
+ 'IMG': '图片',
|
|
|
+ 'VIDEO': '视频'
|
|
|
}
|
|
|
function reducer(state: State, action: Action) {
|
|
|
let { type, params } = action
|
|
@@ -65,7 +62,7 @@ const initData: State = {
|
|
|
videoTitle: '',
|
|
|
videoDescription: '',
|
|
|
belongUser: '1',
|
|
|
- fileType: 'image',
|
|
|
+ mediaType: 'IMG',
|
|
|
parentId: null,
|
|
|
selectFile: [],
|
|
|
delPupId: '',
|
|
@@ -80,8 +77,9 @@ const initData: State = {
|
|
|
/**本地素材管理器 */
|
|
|
function useBdMediaPup() {
|
|
|
const [state, dispatch]: [State, Dispatch<Action>] = useReducer(reducer, initData)
|
|
|
- const { fileName, sort, belongUser, fileType, parentId, selectFile, delPupId, rightClickPup, actionItem, path, publicPath, file, videoTitle, videoDescription } = state
|
|
|
- const list = useAjax((params) => bdSysMediaList(params))
|
|
|
+ const { fileName, sort, belongUser, mediaType, parentId, selectFile, delPupId, rightClickPup, actionItem, path, publicPath, file, videoTitle, videoDescription } = state
|
|
|
+ const listImg = useAjax((params) => bdSysMediaListImg(params))
|
|
|
+ const listVideo = useAjax((params) => bdSysMediaListVideo(params))
|
|
|
const add = useAjax((params) => bdSysMediaAdd(params), { msgNmae: '新增' })
|
|
|
const addWx = useAjax((params) => wxSysMediaAdd(params), { msgNmae: '新增' })
|
|
|
const del = useAjax((params) => delMedia(params), { msgNmae: '删除' })
|
|
@@ -89,7 +87,8 @@ function useBdMediaPup() {
|
|
|
const sync = useAjax((params) => syncMedia(params), { msgNmae: '同步' })
|
|
|
const syncId = useAjax((params) => syncForSend(params), { msgNmae: '同步' })
|
|
|
const configSort = useAjax((params) => configSortApi(params), { msgNmae: '排序' })
|
|
|
- const get_folder_tree = useAjax((params: any) => getFolderTree(params))
|
|
|
+ const get_folder_tree_img = useAjax((params: any) => getFolderTreeImg(params))
|
|
|
+ const get_folder_tree_video = useAjax((params: any) => getFolderTreeVideo(params))
|
|
|
const edit_media_folder = useAjax((params: any) => editMediaFolder(params))
|
|
|
const get = useAjax((params) => getMedia(params))//获取图文详情
|
|
|
const eidtWxlists = useAjax((params) => editWxlist(params))
|
|
@@ -115,9 +114,9 @@ function useBdMediaPup() {
|
|
|
let { title, knewsThumbUrl, knewsLink, description, knewsThumbId } = props?.newsList[0]
|
|
|
let obj = {
|
|
|
parentId,
|
|
|
- belongUser,
|
|
|
+ belongUser: belongUser === '0' ? false : true,
|
|
|
folder: false,
|
|
|
- fileType,
|
|
|
+ mediaType,
|
|
|
title: title,
|
|
|
knewsThumbUrl: knewsThumbUrl,
|
|
|
knewsLink: knewsLink,
|
|
@@ -131,7 +130,11 @@ function useBdMediaPup() {
|
|
|
obj['sysMediaId'] = rightClickPup?.id
|
|
|
edit.run(obj).then((res) => {
|
|
|
if (res) {
|
|
|
- list.refresh()
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ listImg.refresh()
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ listVideo.refresh()
|
|
|
+ }
|
|
|
set({ knewsVisrible: false, knewsdefaultData: null })
|
|
|
}
|
|
|
})
|
|
@@ -141,17 +144,22 @@ function useBdMediaPup() {
|
|
|
} else {
|
|
|
add.run({ ...obj, mpIds: props?.mpIds || [] }).then((res) => {
|
|
|
if (res) {
|
|
|
- list.refresh()
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ listImg.refresh()
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ listVideo.refresh()
|
|
|
+ }
|
|
|
set({ knewsVisrible: false, knewsdefaultData: null })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- }, [add, edit, list, parentId, belongUser, fileType, rightClickPup])
|
|
|
+ }, [add, edit, listImg, listVideo, parentId, belongUser, mediaType, rightClickPup])
|
|
|
/**新增文件夹,非图文素材 */
|
|
|
const fileOk = useCallback((e: any, fnc?: () => Promise<any>, selectWx?: number[]) => {
|
|
|
e?.stopPropagation()
|
|
|
if (fnc) {//存在代表素材
|
|
|
fnc().then(res => {
|
|
|
+ console.log('11111111--->', res)
|
|
|
if (!res) {
|
|
|
return
|
|
|
}
|
|
@@ -159,14 +167,7 @@ function useBdMediaPup() {
|
|
|
/**修改文件名以用户设置的文件title命名*/
|
|
|
let newFile = new File([file], res?.fileName ? res?.fileName + '.' + file?.name?.split('.')[1] : file?.name, { type: file?.type })
|
|
|
let formData = new FormData();
|
|
|
-
|
|
|
- if (fileType === 'voice') {
|
|
|
- if (newFile.size > 2097152) {
|
|
|
- message.error('请上传小于2M的音频')
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- if (fileType === 'video' || fileType === 'image') {
|
|
|
+ if (mediaType === 'VIDEO' || mediaType === 'IMG') {
|
|
|
if (newFile.size > 10485760) {
|
|
|
message.error('请上传小于10M的素材')
|
|
|
return
|
|
@@ -189,14 +190,18 @@ function useBdMediaPup() {
|
|
|
/**取到返回的文件地址向后端发送具体数据*/
|
|
|
if (res2?.data?.url) {
|
|
|
let fileMd5 = await getMD5(file)
|
|
|
- let obj = { title: res?.fileName, fileType, folder: false, parentId, belongUser, url: res2?.data?.url, mpIds: selectWx, sort: res?.sort, fileMd5, fileSize: newFile?.size }
|
|
|
- if (fileType === 'video') {
|
|
|
+ let obj = { title: res?.fileName, mediaType, folder: false, parentId, belongUser: belongUser === '0' ? false : true, url: res2?.data?.url, mpIds: selectWx, sort: res?.sort, fileMd5, fileSize: newFile?.size }
|
|
|
+ if (mediaType === 'VIDEO') {
|
|
|
obj['videoTitle'] = res?.videoTitle || res?.title
|
|
|
obj['videoDescription'] = res?.videoDescription
|
|
|
}
|
|
|
add.run(obj).then((res) => {
|
|
|
console.log(res)
|
|
|
- list.refresh()//刷新页面
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ listImg.refresh()
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ listVideo.refresh()
|
|
|
+ }
|
|
|
offEditFile()//关闭弹窗并清空相关数据
|
|
|
})
|
|
|
}
|
|
@@ -210,25 +215,38 @@ function useBdMediaPup() {
|
|
|
})
|
|
|
} else {
|
|
|
if (fileName) {
|
|
|
- let obj = { title: fileName, fileType, folder: true, parentId, belongUser, mpIds: selectWx, sort }
|
|
|
+ let obj = { title: fileName, mediaType, folder: true, parentId, belongUser: belongUser === '0' ? false : true, mpIds: selectWx, sort }
|
|
|
add.run(obj).then((res) => {
|
|
|
- get_folder_tree.refresh()
|
|
|
- list.refresh()//刷新页面
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ get_folder_tree_img.refresh()
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ get_folder_tree_video.refresh()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ listImg.refresh()
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ listVideo.refresh()
|
|
|
+ }
|
|
|
offEditFile()//关闭弹窗并清空相关数据
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- }, [fileName, fileType, parentId, belongUser, list, file])
|
|
|
+ }, [fileName, mediaType, parentId, belongUser, listImg, listVideo, file])
|
|
|
/**编辑非图文素材名称*/
|
|
|
const nameOk = useCallback((selectWx?: any) => {
|
|
|
if (fileName && actionItem) {
|
|
|
- let obj = { title: fileName, belongUser, sysMediaId: actionItem?.id, fileType: actionItem?.fileType, folder: actionItem?.folder, url: actionItem?.url, sort }
|
|
|
- if (fileType === 'video') {
|
|
|
+ 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()//刷新页面
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ listImg.refresh()
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ listVideo.refresh()
|
|
|
+ }
|
|
|
offEditFile()//关闭弹窗并清空相关数据
|
|
|
})
|
|
|
}
|
|
@@ -236,7 +254,7 @@ function useBdMediaPup() {
|
|
|
eidtWxlists.run({ sysMediaId: actionItem?.id, mpIds: selectWx || [] }).then((res) => {
|
|
|
console.log(res)
|
|
|
})
|
|
|
- }, [fileName, actionItem, edit, belongUser, fileType, videoTitle, videoDescription])
|
|
|
+ }, [fileName, actionItem, edit, belongUser, mediaType, videoTitle, videoDescription])
|
|
|
/**删除文件 */
|
|
|
const dels = useCallback((id?: any) => {
|
|
|
let arr = typeof id === 'number' ? [id] : selectFile
|
|
@@ -246,19 +264,29 @@ function useBdMediaPup() {
|
|
|
del.run(id).then(() => {
|
|
|
set({ selectFile: selectFile?.filter(i => i !== id) })//清理已删除文件
|
|
|
if (index === len - 1) {
|
|
|
- list.refresh()//最后一次刷新页面
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ listImg.refresh()
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ listVideo.refresh()
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
- }, [list, selectFile])
|
|
|
+ }, [listImg, listVideo, selectFile])
|
|
|
/**获取本地素材数据列表 */
|
|
|
const getList = useCallback((props?: any) => {
|
|
|
- let obj = { pageSize: 20, pageNum: 1, fileType, belongUser, parentId, ...props }
|
|
|
- list.run(obj).then((res) => {
|
|
|
- setIsOk(true)
|
|
|
- })
|
|
|
- }, [list, fileType, belongUser, parentId])
|
|
|
+ let obj = { pageSize: 20, pageNum: 1, belongUser: belongUser === '0' ? false : true, parentId, ...props }
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ listImg.run(obj).then((res) => {
|
|
|
+ setIsOk(true)
|
|
|
+ })
|
|
|
+ } else if (mediaType === 'VIDEO') {
|
|
|
+ listVideo.run(obj).then((res) => {
|
|
|
+ setIsOk(true)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }, [mediaType, belongUser, parentId])
|
|
|
/**选中文件 single 开启可单选为了在右键删除选择时只选一个*/
|
|
|
const onFile = useCallback((e: any, item: { id: any, folder?: boolean }, isAll?: boolean, single?: boolean) => {
|
|
|
let { id } = item
|
|
@@ -288,7 +316,7 @@ function useBdMediaPup() {
|
|
|
getList({ parentId: item.id })//请求对应文件夹列表
|
|
|
}
|
|
|
|
|
|
- }, [path, publicPath, fileType, belongUser, isOk])
|
|
|
+ }, [path, publicPath, mediaType, belongUser, isOk])
|
|
|
/**点击目录树*/
|
|
|
const treeClick = useCallback((item) => {
|
|
|
if (isOk) {
|
|
@@ -303,7 +331,7 @@ function useBdMediaPup() {
|
|
|
set({ parentId: item.id })
|
|
|
getList({ parentId: item.id })//请求对应文件夹列表
|
|
|
}
|
|
|
- }, [path, publicPath, fileType, belongUser, isOk])
|
|
|
+ }, [path, publicPath, mediaType, belongUser, isOk])
|
|
|
/**点击路径 */
|
|
|
const pathClick = useCallback((item) => {
|
|
|
let newPath: any[] = []
|
|
@@ -324,9 +352,9 @@ function useBdMediaPup() {
|
|
|
}
|
|
|
set({ parentId: item.parentId })
|
|
|
console.log(item)
|
|
|
- getList({ pageSize: 20, pageNum: 1, fileType, belongUser, parentId: item.id })
|
|
|
+ getList({ pageSize: 20, pageNum: 1, mediaType, belongUser: belongUser === '0' ? false : true, parentId: item.id })
|
|
|
console.log('文件夹被点击')
|
|
|
- }, [path, fileType, belongUser, publicPath])
|
|
|
+ }, [path, mediaType, belongUser, publicPath])
|
|
|
/**取消文件 */
|
|
|
const offFile = useCallback((e: any, item: { id: any }) => {
|
|
|
let { id } = item
|
|
@@ -344,7 +372,7 @@ function useBdMediaPup() {
|
|
|
set({ selectFile: [...selectFile as number[], id] })
|
|
|
}
|
|
|
} else {//单选情况存在于选择素材弹窗组件
|
|
|
- if (item?.folder && fileType !== 'image') {//假如是文件不让选择
|
|
|
+ if (item?.folder && mediaType !== 'IMG') {//假如是文件不让选择
|
|
|
message.error('不能选择文件夹')
|
|
|
return
|
|
|
}
|
|
@@ -356,7 +384,7 @@ function useBdMediaPup() {
|
|
|
set({ selectItem: item })
|
|
|
}
|
|
|
}
|
|
|
- }, [selectFile, fileType])
|
|
|
+ }, [selectFile, mediaType])
|
|
|
/**开启删除弹窗 */
|
|
|
const delPupOn = useCallback((delPupId) => {
|
|
|
set({ delPupId })
|
|
@@ -370,9 +398,9 @@ function useBdMediaPup() {
|
|
|
const editFile = useCallback((e?: any,) => {
|
|
|
e?.stopPropagation()
|
|
|
onFile(null, rightClickPup, true, true)
|
|
|
- // if (rightClickPup?.fileType !== 'news') {//不是图文开启编辑名字弹窗
|
|
|
+ // if (rightClickPup?.mediaType !== 'news') {//不是图文开启编辑名字弹窗
|
|
|
let obj = { fileVisible: true, actionItem: rightClickPup, fileName: rightClickPup.title, sort: rightClickPup.sort }
|
|
|
- if (rightClickPup?.fileType === 'video') {
|
|
|
+ if (rightClickPup?.mediaType === 'video') {
|
|
|
obj['videoTitle'] = rightClickPup?.videoTitle || rightClickPup?.title
|
|
|
obj['videoDescription'] = rightClickPup?.videoDescription
|
|
|
}
|
|
@@ -386,11 +414,18 @@ function useBdMediaPup() {
|
|
|
/**全选反选文件*/
|
|
|
const allFile = useCallback(() => {
|
|
|
let allArr: any[] = []
|
|
|
- list?.data?.records?.forEach((item: { id: any }) => {
|
|
|
- allArr.push(item.id)
|
|
|
- })
|
|
|
+
|
|
|
+ if (mediaType === 'IMG') {
|
|
|
+ listImg?.data?.records?.forEach((item: { id: any }) => {
|
|
|
+ allArr.push(item.id)
|
|
|
+ })
|
|
|
+ } else if (mediaType === "VIDEO") {
|
|
|
+ listVideo?.data?.records?.forEach((item: { id: any }) => {
|
|
|
+ allArr.push(item.id)
|
|
|
+ })
|
|
|
+ }
|
|
|
set({ selectFile: allArr.filter((i) => selectFile?.every(id => id !== i)) })
|
|
|
- }, [selectFile, list])
|
|
|
+ }, [selectFile, listImg, listVideo, mediaType])
|
|
|
/**图文素材弹窗开关 */
|
|
|
const showNews = useCallback(() => {
|
|
|
|
|
@@ -417,7 +452,8 @@ function useBdMediaPup() {
|
|
|
configSort,
|
|
|
fileUrl,
|
|
|
addWx,
|
|
|
- list,
|
|
|
+ listImg,
|
|
|
+ listVideo,
|
|
|
add,
|
|
|
sync,
|
|
|
get,
|
|
@@ -425,7 +461,8 @@ function useBdMediaPup() {
|
|
|
syncId,
|
|
|
typeEnum,
|
|
|
eidtWxlists,
|
|
|
- get_folder_tree,
|
|
|
+ get_folder_tree_img,
|
|
|
+ get_folder_tree_video,
|
|
|
edit_media_folder
|
|
|
}
|
|
|
}
|