|  | @@ -1,6 +1,6 @@
 | 
	
		
			
				|  |  |  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, bdSysMediaAddsApi } from '@/services/launchAdq/material';
 | 
	
		
			
				|  |  |  import { blobToBase64, dataURLtoFile, videoMessage } from '@/utils/compress';
 | 
	
		
			
				|  |  |  import { getImgSize } from '@/utils/utils';
 | 
	
		
			
				|  |  |  import { message } from 'antd';
 | 
	
	
		
			
				|  | @@ -11,6 +11,7 @@ import { request } from 'umi';
 | 
	
		
			
				|  |  |  type State = {
 | 
	
		
			
				|  |  |      fileVisible?: boolean,//文件夹弹窗
 | 
	
		
			
				|  |  |      imgVisrible?: boolean,//img,voice,video弹窗
 | 
	
		
			
				|  |  | +    imgsVisrible?: boolean,//img,voice,video弹窗
 | 
	
		
			
				|  |  |      newsVisrible?: boolean,//news弹窗
 | 
	
		
			
				|  |  |      knewsVisrible?: boolean,//客服图文弹窗
 | 
	
		
			
				|  |  |      fileName?: string,//文件夹名称
 | 
	
	
		
			
				|  | @@ -78,6 +79,7 @@ const initData: State = {
 | 
	
		
			
				|  |  |      publicPath: [{ title: '公共本地', number: '0' }],
 | 
	
		
			
				|  |  |      path: [{ title: '个人本地', number: '0' }],
 | 
	
		
			
				|  |  |      imgVisrible: false,
 | 
	
		
			
				|  |  | +    imgsVisrible: false,
 | 
	
		
			
				|  |  |      newsVisrible: false,
 | 
	
		
			
				|  |  |      sortVisible: false,
 | 
	
		
			
				|  |  |      sort: 0,
 | 
	
	
		
			
				|  | @@ -88,6 +90,7 @@ function useBdMediaPup() {
 | 
	
		
			
				|  |  |      const { fileName, sort, belongUser, mediaType, parentId, selectFile, delPupId, rightClickPup, actionItem, path, publicPath, size, videoTitle, videoDescription } = state
 | 
	
		
			
				|  |  |      const list = useAjax((params) => bdSysMediaList(params))
 | 
	
		
			
				|  |  |      const add = useAjax((params) => bdSysMediaAdd(params), { msgNmae: '新增' })
 | 
	
		
			
				|  |  | +    const adds = useAjax((params) => bdSysMediaAddsApi(params), { msgNmae: '新增' })
 | 
	
		
			
				|  |  |      const del = useAjax((params) => delMedia(params), { msgNmae: '删除' })
 | 
	
		
			
				|  |  |      const edit = useAjax((params) => bdSysMediaEdit(params), { msgNmae: '编辑' })
 | 
	
		
			
				|  |  |      const configSort = useAjax((params) => configSortApi(params), { msgNmae: '排序' })
 | 
	
	
		
			
				|  | @@ -141,15 +144,15 @@ function useBdMediaPup() {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  if (mediaType === 'IMG') {
 | 
	
		
			
				|  |  |                      if (file?.size > fileSize) { // 大于300kb进入压缩
 | 
	
		
			
				|  |  | -                        let bole = await compressAccurately(file, 250)
 | 
	
		
			
				|  |  | -                        if (bole?.size > 300000) {
 | 
	
		
			
				|  |  | -                            bole = await compressAccurately(file, 200)
 | 
	
		
			
				|  |  | +                        let bole = await compressAccurately(file, fileSize / 1024 - 50)
 | 
	
		
			
				|  |  | +                        if (bole?.size > fileSize) {
 | 
	
		
			
				|  |  | +                            bole = await compressAccurately(file, fileSize / 1024 - 100)
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                        if (bole?.size > 300000) {
 | 
	
		
			
				|  |  | -                            bole = await compressAccurately(file, 150)
 | 
	
		
			
				|  |  | +                        if (bole?.size > fileSize) {
 | 
	
		
			
				|  |  | +                            bole = await compressAccurately(file, fileSize / 1024 - 150)
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                        if (bole?.size > 300000) {
 | 
	
		
			
				|  |  | -                            bole = await compressAccurately(file, 100)
 | 
	
		
			
				|  |  | +                        if (bole?.size > fileSize) {
 | 
	
		
			
				|  |  | +                            bole = await compressAccurately(file, fileSize / 1024 - 200)
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                          let newFile = await blobToBase64(bole)
 | 
	
		
			
				|  |  |                          message.warning({
 | 
	
	
		
			
				|  | @@ -182,7 +185,6 @@ function useBdMediaPup() {
 | 
	
		
			
				|  |  |                  /**修改文件名以用户设置的文件title命名*/
 | 
	
		
			
				|  |  |                  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) => {
 | 
	
	
		
			
				|  | @@ -219,6 +221,107 @@ function useBdMediaPup() {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /** 批量新增图片 视频 */
 | 
	
		
			
				|  |  | +    const addFiles = async (data: any) => {
 | 
	
		
			
				|  |  | +        if (data) {//存在代表素材
 | 
	
		
			
				|  |  | +            if (!data) {
 | 
	
		
			
				|  |  | +                return
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            let { files, ...value } = data
 | 
	
		
			
				|  |  | +            let params = files?.map(async (item: any, index: number) => {
 | 
	
		
			
				|  |  | +                let file = item
 | 
	
		
			
				|  |  | +                let fileSize = size || 0
 | 
	
		
			
				|  |  | +                if (mediaType === 'IMG') {
 | 
	
		
			
				|  |  | +                    fileSize = value?.fileSize ? value?.fileSize * 1024 : 307200
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    fileSize = 104857600
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (mediaType === 'IMG') {
 | 
	
		
			
				|  |  | +                    let bad = 50
 | 
	
		
			
				|  |  | +                    let size = fileSize / 1024
 | 
	
		
			
				|  |  | +                    if (size > 10 && size <= 50) {
 | 
	
		
			
				|  |  | +                        bad = 5
 | 
	
		
			
				|  |  | +                    } else if (size > 50 && size <= 100) {
 | 
	
		
			
				|  |  | +                        bad = 10
 | 
	
		
			
				|  |  | +                    } else if (size > 100 && size <= 300) {
 | 
	
		
			
				|  |  | +                        bad = 20
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        bad = 50
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (file?.size > fileSize) { // 大于300kb进入压缩
 | 
	
		
			
				|  |  | +                        let bole = await compressAccurately(file, fileSize / 1024 - bad)
 | 
	
		
			
				|  |  | +                        if (bole?.size > fileSize) {
 | 
	
		
			
				|  |  | +                            bole = await compressAccurately(file, fileSize / 1024 - bad * 2)
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        if (bole?.size > fileSize) {
 | 
	
		
			
				|  |  | +                            bole = await compressAccurately(file, fileSize / 1024 - bad * 3)
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        if (bole?.size > fileSize) {
 | 
	
		
			
				|  |  | +                            bole = await compressAccurately(file, fileSize / 1024 - bad * 4)
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        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) { // 大于100mb进入压缩
 | 
	
		
			
				|  |  | +                        message.error({
 | 
	
		
			
				|  |  | +                            content: `选择的视频大于${fileSize / 1024 / 1024}MB,请重新选择提交`,
 | 
	
		
			
				|  |  | +                            duration: 3
 | 
	
		
			
				|  |  | +                        })
 | 
	
		
			
				|  |  | +                        return
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                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
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                /**修改文件名以用户设置的文件title命名*/
 | 
	
		
			
				|  |  | +                let newFile = new File([file], data?.title ? data?.title + index + 1 + '.' + file?.name?.split('.')[1] : file?.name, { type: file?.type })
 | 
	
		
			
				|  |  | +                let formData = new FormData();
 | 
	
		
			
				|  |  | +                set({ upLoadLoading: true })
 | 
	
		
			
				|  |  | +                let res = await getFileUrl({ type: newFile.type, fileType: mediaType === 'VIDEO' ? 'video' : 'image' }).catch(() => set({ upLoadLoading: false }))
 | 
	
		
			
				|  |  | +                let res1 = res.data
 | 
	
		
			
				|  |  | +                Object.keys(res1).forEach((key: string) => {
 | 
	
		
			
				|  |  | +                    if (key !== 'url') {
 | 
	
		
			
				|  |  | +                        formData.append(key, res1[key])
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                })
 | 
	
		
			
				|  |  | +                formData.append('file', newFile)
 | 
	
		
			
				|  |  | +                /**向阿里云返回的上传地址上传文件*/
 | 
	
		
			
				|  |  | +                let data1: { code: number, data: { url: string } } = await request(res1?.ossUrl, { method: 'post', body: formData }).catch(() => set({ upLoadLoading: false }))
 | 
	
		
			
				|  |  | +                message.success('上传成功')
 | 
	
		
			
				|  |  | +                let fileMd5 = await getMD5(newFile)
 | 
	
		
			
				|  |  | +                let obj = { title: data.title ? data.title + '_' + (index + 1).toString() : data.title, folder: false, parentId, width, height, fileMd5, url: data1?.data?.url, sort: data?.sort, fileSize: newFile?.size, fileMime: newFile.type }
 | 
	
		
			
				|  |  | +                if (mediaType === 'VIDEO') {
 | 
	
		
			
				|  |  | +                    obj['videoTitle'] = data?.videoTitle || data?.title
 | 
	
		
			
				|  |  | +                    obj['videoDescription'] = data?.videoDescription
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                return { ...obj }
 | 
	
		
			
				|  |  | +            })
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            Promise.all(params).then(res => {
 | 
	
		
			
				|  |  | +                adds.run({ belongUser: belongUser === '0' ? false : true, data: res }).then(response => {
 | 
	
		
			
				|  |  | +                    list.refresh()
 | 
	
		
			
				|  |  | +                    offEditFile()//关闭弹窗并清空相关数据
 | 
	
		
			
				|  |  | +                    set({ upLoadLoading: false })
 | 
	
		
			
				|  |  | +                }).catch(() => set({ upLoadLoading: false }))
 | 
	
		
			
				|  |  | +            })
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**编辑非图文素材名称*/
 | 
	
		
			
				|  |  |      const nameOk = useCallback((selectWx?: any) => {
 | 
	
		
			
				|  |  |          if (fileName && actionItem) {
 | 
	
	
		
			
				|  | @@ -378,7 +481,7 @@ function useBdMediaPup() {
 | 
	
		
			
				|  |  |      }, [rightClickPup])
 | 
	
		
			
				|  |  |      /**取消编辑后清空选中存放的数据并关闭弹窗*/
 | 
	
		
			
				|  |  |      const offEditFile = useCallback(() => {
 | 
	
		
			
				|  |  | -        set({ fileVisible: false, imgVisrible: false, sortVisible: false, actionItem: '', fileName: '', selectFile: selectFile?.filter(id => id !== actionItem?.id), sort: 0 })
 | 
	
		
			
				|  |  | +        set({ fileVisible: false, imgVisrible: false, imgsVisrible: false, sortVisible: false, actionItem: '', fileName: '', selectFile: selectFile?.filter(id => id !== actionItem?.id), sort: 0 })
 | 
	
		
			
				|  |  |      }, [selectFile, actionItem])
 | 
	
		
			
				|  |  |      /**全选反选文件*/
 | 
	
		
			
				|  |  |      const allFile = useCallback(() => {
 | 
	
	
		
			
				|  | @@ -407,6 +510,7 @@ function useBdMediaPup() {
 | 
	
		
			
				|  |  |          fileClick,
 | 
	
		
			
				|  |  |          treeClick,
 | 
	
		
			
				|  |  |          pathClick,
 | 
	
		
			
				|  |  | +        addFiles,
 | 
	
		
			
				|  |  |          configSort,
 | 
	
		
			
				|  |  |          fileUrl,
 | 
	
		
			
				|  |  |          list,
 |