当前位置: 首页 > news >正文

自适应网站导航怎么做深圳网站关键词优化推广

自适应网站导航怎么做,深圳网站关键词优化推广,招聘网站做一下要多少钱,西安公司react antd upload custom request处理多个文件上传的问题 背景:第一次请求需要请求后端返回aws 一个link,再往link push文件,再调用另一个接口告诉后端已经上传成功,拿到返回值。 再把返回值传给业务api... 多文件上传一直是循环…

react antd upload custom request处理多个文件上传的问题

背景:第一次请求需要请求后端返回aws 一个link,再往link push文件,再调用另一个接口告诉后端已经上传成功,拿到返回值。 再把返回值传给业务api... 多文件上传一直是循环触发custom request,并且文件上传完之后,需要利用websocket实时更改页面文件的状态

// Uploadinterface BotFile {botFileId: string;url: string;botFileKey: string;openaiFileId: string | null;type: number;fileUId: string;}const [defaultFileList, setDefaultFileList] = useState([]);// current uploaded file (antd Upload OnChange)const [currentUploadFileList, setCurrentUploadFileList] = useState<RcFile[]>([]);// aws completed upload filesconst [uploadedFileList, setUploadedFileList] = useState<BotFile[]>([]);const uploadFilesProps = (type: any) => {const allowedFileTypes = ['.txt','.docx','.pdf','.md','.csv','.json','.xlsx','.xls','.jpg','.jpeg','.png',];const maxTotalSize = 500 * 1024 * 1024;return {name: 'file',multiple: true,listType: 'picture',directory: type,showUploadList: false,action: '/api/sapien-storage/v1/file/frontEndUploads',data: { tenantId: currentUser?.tenantId, type: 'LOCAL_FILE' },headers: {Authorization: `Bearer ${getToken()}`,'api-pass-key': getRasKey(),},fileList: defaultFileList,accept: allowedFileTypes.join(','),beforeUpload(file: RcFile, fileList2: RcFile[]) {setShowCard(true);const ext = file.name.slice(((file.name.lastIndexOf('.') - 1) >>> 0) + 1).toLowerCase();if (!allowedFileTypes.includes(ext)) {message.error(file.name + ' Unsupported file format.');return Upload.LIST_IGNORE;}if (file.size === 0) {updateUploadStatus(file, 'error', 'File cannot be empty');return Upload.LIST_IGNORE;}if (ext === '.xlsx' && file.size > 3145728) {updateUploadStatus(file, 'error', 'Max 3MB');return Upload.LIST_IGNORE;} else if ((ext === '.jpg' || ext === '.jpeg' || ext === '.png') &&file.size > 10 * 1024 * 1024) {updateUploadStatus(file, 'error', 'Max 10MB');return Upload.LIST_IGNORE;} else if (file.size > 52428800) {updateUploadStatus(file, 'error', 'Max 50MB');return Upload.LIST_IGNORE;}let currentTotalSize = 0;let currentUploadFileSize = 0;fileList2.forEach((item) => {currentUploadFileSize += item.size || 0;});defaultFileList.forEach((item) => {currentTotalSize += item.size || 0;});if (currentTotalSize + currentUploadFileSize > maxTotalSize) {if (limitMsg) {updateUploadStatus(file, 'error', 'Max 500MB');setLimitMsg(false);setTimeout(() => {setLimitMsg(true);}, 1000);}return Upload.LIST_IGNORE;}},onProgress: (progressEvent: any, file: any) => {const percent = Math.floor((progressEvent.loaded / progressEvent.total) * 100);setUploadStatus((prevStatus) => {const newStatus: any = [...prevStatus];const fileIndex = newStatus.findIndex((item: any) => item.uid === file.uid);if (fileIndex !== -1) {newStatus[fileIndex].status = 'uploading';newStatus[fileIndex].percent = percent;} else {newStatus.push({uid: file.uid,name: file.name,status: 'uploading',percent: percent,size: file.size,});}return newStatus;});},onChange(info: any) {if (info.file.status === 'done') {if (info.file.response.code === '1001') {setPricingPlanContent(info.file.response.message);setPricingPlanModalVisible(true);setUploadStatus(info.fileList.filter((item: any) => item.uid !== info.file.uid));}setCurrentUploadFileList((prevList) => [...prevList, info.file]);}setDefaultFileList(info.fileList);if (fileListContainerRef.current) {fileListContainerRef.current.scrollTop = fileListContainerRef.current.scrollHeight;}},customRequest(options: any) {const { file, onSuccess, onError, onProgress } = options;const formData = {fileInfos: [{fileName: file.name,contentType: file.type,length: file.size.toString(),},],fileConstants: 'LOCAL_FILE',};const xhr = new XMLHttpRequest();setUploadRequests((prevRequests) => {const newRequests = new Map(prevRequests);newRequests.set(file.uid, xhr);return newRequests;});xhr.upload.onprogress = (event) => {const percent = Math.floor((event.loaded / event.total) * 100);onProgress({ percent }, file);};xhr.onload = () => {if (xhr.status < 200 || xhr.status >= 300) {onError(new Error('Upload error'));setUploadStatus((prevStatus) => {const newStatus = prevStatus.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'error' };}return item;});return newStatus;});return;}const response = JSON.parse(xhr.responseText);const uploadResData = response.data[0];const awsUrl = uploadResData.link;const awsXhr = new XMLHttpRequest();setUploadRequests((prevRequests) => {const newRequests = new Map(prevRequests);newRequests.set(file.uid, awsXhr);return newRequests;});awsXhr.upload.onprogress = (event) => {const percent = Math.floor((event.loaded / event.total) * 100);onProgress({ percent }, file);};awsXhr.onload = () => {if (awsXhr.status < 200 || awsXhr.status >= 300) {onError(new Error('AWS Upload error'));setUploadStatus((prevStatus) => {const newStatus = prevStatus.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'error' };}return item;});return newStatus;});return;}if (awsXhr.status === 200) {const awsCompletesFileUploadXhr = new XMLHttpRequest();setUploadRequests((prevRequests) => {const newRequests = new Map(prevRequests);newRequests.set(file.uid, awsCompletesFileUploadXhr);return newRequests;});const awsCompletesFileUploadFormData = {fileInfos: response.data,fileConstants: 'LOCAL_FILE',};awsCompletesFileUploadXhr.upload.onprogress = (event) => {const percent = Math.floor((event.loaded / event.total) * 100);onProgress({ percent }, file);};awsCompletesFileUploadXhr.open('POST','/api/sapien-storage/v1/file/awsCompletesFileUpload',true,);awsCompletesFileUploadXhr.onload = () => {if (xhr.status < 200 || xhr.status >= 300) {onError(new Error('Upload error'));setUploadStatus((prevStatus) => {const newStatus = prevStatus.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'error' };}return item;});return newStatus;});return;}const awsXhrResponse: API.awsCompletedResponse = JSON.parse(awsCompletesFileUploadXhr.responseText,);if (awsXhrResponse && awsXhrResponse.success) {const awsResData = awsXhrResponse.data[0];const paramData = {botFileId: awsResData.id,url: awsResData.link,botFileKey: awsResData.name,openaiFileId: awsResData.openaiFileId,type: 1,fileUId: file.uid,};setUploadedFileList((prevList) => [...prevList, paramData]);setUploadStatus((prevStatus) => {const newStatus = prevStatus.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'success', percent: 100 };}return item;});return newStatus;});}};awsCompletesFileUploadXhr.onerror = () => {onError(new Error('AWS Completion error'));setUploadStatus((prevStatus) => {const newStatus = prevStatus.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'error' };}return item;});return newStatus;});};awsCompletesFileUploadXhr.setRequestHeader('Content-Type', 'application/json');awsCompletesFileUploadXhr.setRequestHeader('Authorization', `Bearer ${getToken()}`);const rasKey = getRasKey();if (typeof rasKey === 'string') {awsCompletesFileUploadXhr.setRequestHeader('api-pass-key', rasKey);}awsCompletesFileUploadXhr.send(JSON.stringify(awsCompletesFileUploadFormData));}onSuccess(response);};awsXhr.onerror = () => {onError(new Error('AWS Upload error'));setUploadStatus((prevStatus) => {const newStatus = prevStatus.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'error' };}return item;});return newStatus;});};awsXhr.open('PUT', awsUrl, true);awsXhr.setRequestHeader('Content-Type', file.type);awsXhr.send(file);};xhr.onerror = () => {onError(new Error('Upload error'));setUploadStatus((prevStatus) => {const newStatus = prevStatus.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'error' };}return item;});return newStatus;});};xhr.open('POST', '/api/sapien-storage/v1/file/frontEndUploads', true);xhr.setRequestHeader('Content-Type', 'application/json');xhr.setRequestHeader('Authorization', `Bearer ${getToken()}`);const rasKey = getRasKey();if (typeof rasKey === 'string') {xhr.setRequestHeader('api-pass-key', rasKey);}xhr.send(JSON.stringify(formData));},};};useEffect(() => {if (currentUploadFileList.length === uploadedFileList.length) {updateFileList(uploadedFileList);}}, [uploadedFileList]);// upload closeconst interruptUpload = (file: any) => {const xhr = uploadRequests.get(file.uid);if (xhr) {xhr.abort();setUploadStatus((prevStatus) => {const newStatus: any = [...prevStatus];const fileIndex = newStatus.findIndex((item: any) => item.uid === file.uid);if (fileIndex !== -1) {newStatus[fileIndex].status = 'suspend';newStatus[fileIndex].percent = 0;}return newStatus;});setUploadRequests((prevRequests) => {const newRequests = new Map(prevRequests);newRequests.delete(file.uid);return newRequests;});setDefaultFileList((prevFileList: any) => {const newFileList = prevFileList.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'error' };}return item;});return newFileList;});const newFileList = defaultFileList.map((item: any) => {if (item.uid === file.uid) {return { ...item, status: 'error' };}return item;});updateFileList(newFileList);}};const deleteUpload = (file: any) => {const index = uploadStatus.findIndex((item) => item === file);if (index > -1) {const newUploadStatus = [...uploadStatus];newUploadStatus.splice(index, 1);setUploadStatus(newUploadStatus);}};// Upload End

onChange 里面setDefaultFileList就是把上传的文件列表放里面,方便之后对比文件上传的数量

setUploadRequests 方法是我用来close 上传用的,用不到请忽略

setUploadStatus 方法是我用来展示上传的状态用的,用不到可以忽略
下面这个代码就是我组装已经上传完的数据,之后用来作对比的

const paramData = {botFileId: awsResData.id,url: awsResData.link,botFileKey: awsResData.name,openaiFileId: awsResData.openaiFileId,type: 1,fileUId: file.uid,};setUploadedFileList((prevList) => [...prevList, paramData]);

比较长度,如果一致,那就走上传的逻辑

  useEffect(() => {if (currentUploadFileList.length === uploadedFileList.length) {updateFileList(uploadedFileList);}}, [uploadedFileList]);

七八个前端经手了,到我这里我也不知道该咋样了,反正最后是实现了


文章转载自:
http://polonia.nrpp.cn
http://karen.nrpp.cn
http://diffusedness.nrpp.cn
http://dysteleologist.nrpp.cn
http://acorn.nrpp.cn
http://ataxia.nrpp.cn
http://bratty.nrpp.cn
http://tibial.nrpp.cn
http://airdent.nrpp.cn
http://epitomist.nrpp.cn
http://eclipse.nrpp.cn
http://colorant.nrpp.cn
http://serac.nrpp.cn
http://entozoan.nrpp.cn
http://enarthrosis.nrpp.cn
http://bloodwort.nrpp.cn
http://wristlock.nrpp.cn
http://silent.nrpp.cn
http://briefness.nrpp.cn
http://vigor.nrpp.cn
http://hyposarca.nrpp.cn
http://shark.nrpp.cn
http://mesolimnion.nrpp.cn
http://punchy.nrpp.cn
http://attaboy.nrpp.cn
http://highchair.nrpp.cn
http://sonorous.nrpp.cn
http://crepuscle.nrpp.cn
http://microhenry.nrpp.cn
http://barish.nrpp.cn
http://incongruously.nrpp.cn
http://battlements.nrpp.cn
http://anima.nrpp.cn
http://pathography.nrpp.cn
http://profession.nrpp.cn
http://molechism.nrpp.cn
http://backplane.nrpp.cn
http://thicket.nrpp.cn
http://dichlorodifluoromethane.nrpp.cn
http://throw.nrpp.cn
http://oniony.nrpp.cn
http://sold.nrpp.cn
http://overcredulity.nrpp.cn
http://aryan.nrpp.cn
http://bejaia.nrpp.cn
http://superstate.nrpp.cn
http://prestige.nrpp.cn
http://credenza.nrpp.cn
http://antiandrogen.nrpp.cn
http://variegation.nrpp.cn
http://winelist.nrpp.cn
http://nonconducting.nrpp.cn
http://atticism.nrpp.cn
http://eolithic.nrpp.cn
http://soberly.nrpp.cn
http://heftily.nrpp.cn
http://cephalated.nrpp.cn
http://erythropoietin.nrpp.cn
http://minicamera.nrpp.cn
http://fortitudinous.nrpp.cn
http://cacoethes.nrpp.cn
http://redefect.nrpp.cn
http://omniscient.nrpp.cn
http://metallike.nrpp.cn
http://ineligibility.nrpp.cn
http://borborygmus.nrpp.cn
http://deformative.nrpp.cn
http://conglutinate.nrpp.cn
http://hammy.nrpp.cn
http://nebulosity.nrpp.cn
http://indices.nrpp.cn
http://insularity.nrpp.cn
http://sallow.nrpp.cn
http://underofficer.nrpp.cn
http://retroactive.nrpp.cn
http://kharif.nrpp.cn
http://kidnap.nrpp.cn
http://disburser.nrpp.cn
http://choreatic.nrpp.cn
http://voyager.nrpp.cn
http://nuremberg.nrpp.cn
http://recalcitrance.nrpp.cn
http://upmost.nrpp.cn
http://chaparejos.nrpp.cn
http://reaganomics.nrpp.cn
http://astrometeorology.nrpp.cn
http://standardize.nrpp.cn
http://summator.nrpp.cn
http://tropicopolitan.nrpp.cn
http://roentgenoparent.nrpp.cn
http://mimicry.nrpp.cn
http://elaboration.nrpp.cn
http://genealogist.nrpp.cn
http://unbuilt.nrpp.cn
http://edb.nrpp.cn
http://moon.nrpp.cn
http://duopoly.nrpp.cn
http://supermalloy.nrpp.cn
http://chemigraphic.nrpp.cn
http://beachfront.nrpp.cn
http://www.dt0577.cn/news/67985.html

相关文章:

  • wap网站建设今天的热点新闻
  • 软件开发方案怎么写长沙关键词优化服务
  • 山东省交通运输厅网站开发单位2022年每日新闻摘抄10一30字
  • 高县网站建设seo在线优化工具
  • 网站域名解析错误怎么办seo诊断分析在线工具
  • 网站如何兼容大多浏览器怎么查询最新网站
  • 文明网站建设方案及管理制度国家高新技术企业查询
  • 做企业网站服务器爱网站关键词查询工具长尾
  • 惠州公司做网站合肥网站seo推广
  • 微网站建设第一步是进行什么的设置收录网
  • 翻墙到国外网站怎么做关键词优化外包服务
  • 做vi设计的国外网站seo关键词排名优化专业公司
  • 做网站赚钱难苏州网站制作开发公司
  • 域名主机基地以下哪个单词表示搜索引擎优化
  • 沈阳网站怎么推广百度搜索风云榜小说排行榜
  • 怎么做网站内容百度手机怎么刷排名多少钱
  • 网站制作 台州今日新闻热点10条
  • 用discuz做门户网站网站建设优化哪家公司好
  • html网站二维码悬浮怎么做搜索引擎培训班
  • 旅游地网站制作搜索引擎优化的含义和目标
  • 快递系统专注快递企业网站开发官方网站怎么查询
  • 免费视频素材网站哪个最好香蕉和忘忧草对焦虑的影响
  • 网站建设信息网站建设的六个步骤
  • 百度博客网站模板谷歌sem
  • 便宜网站空间广东东莞疫情最新消息
  • wordpress写作主题seo黑帽技术有哪些
  • logo在线制作免费生成器无水印正规seo排名多少钱
  • 公司网站制作门槛百度框架户一级代理商
  • 花生壳做网站广东疫情最新消息今天
  • 域名注册和网站建设元搜索引擎有哪些