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

做设计常用网站有哪些网站开发设计

做设计常用网站有哪些,网站开发设计,有哪个网站专业做漫画素材的,wordpress侧栏文章前端实现本地文件上传与预览(PDF格式展示)不走后端接口 实现步骤 第一步:文件选择 使用前端原生input上传本地文件,或者是el-upload组件实现文件选择功能,核心在于文件渲染处理。(input只不过可以自定义样…

前端实现本地文件上传与预览(PDF格式展示)不走后端接口

实现步骤

第一步:文件选择

使用前端原生input上传本地文件,或者是el-upload组件实现文件选择功能,核心在于文件渲染处理。(input只不过可以自定义样式)

 <div v-if="!uploaded" v-loading="loading" class="upload_box"><p @click="openFileSelector()"><img src="@/assets/上传文件.png" @dragover.prevent @drop.prevent="onDrop" @dragenter.prevent="onDragEnter"@dragleave.prevent="onDragLeave" style="padding-left: 30px" /><input :id="'file' + title" type="file" ref="fileInput" single accept=".pdf" @change="handleFileSelect"style="display: none" /><span class="card_text" for="file">请上传本地文件</span><span class="card_text" style="font-weight: 400">支持选择、拖拽上传PDF</span></p></div>

第二步:文件处理

通过URL.createObjectURL(file)将本地文件转换为URL进行访问。

<script>methods: {//点击上传的方法openFileSelector() {// console.log('aaaa');const filedox = document.getElementById("file" + this.title);filedox.click();//this.fileInputRef.click();},}//拖拽的方法onDrop(event) {// console.log('ondrop',event)this.isDragging = false;const file1 = event.dataTransfer.files[0];this.uploaded = true;this.loading = falseif (file1 && file1.type === 'application/pdf') {//重点是这里将文件转换成本地url地址去访问const blobUrl = URL.createObjectURL(file1);// http://192.168.203.213:8080// console.log('blobUrl',blobUrl)//将url返回给标签渲染的this.pdfPreview = blobUrl}for (let i = 0; i < files.length; i++) {const file = files[i];if (file.type === "application/pdf" ||file.type === "application/msword" ||file.type ==="application/vnd.openxmlformats-officedocument.wordprocessingml.document") {let transform_type_val;if (files[0].type === "application/pdf") {if (this.routerType == 'word') {transform_type_val = 'pdf2word';file.transform_type = transform_type_val;} else if (this.routerType == 'excel') {transform_type_val = 'risk';file.extract_type = transform_type_val;}// console.log('pdf',file.transform_type)}this.selectedFiles.push(file);}}// this.uploadFiles();this.fileInputRef.value = null;},//input事件 和 拖拽事件一致handleFileSelect(event) {const file1 = event.target.files[0];if (file1 && file1.type === 'application/pdf') {this.uploaded = true;this.loading = falseconst blobUrl = URL.createObjectURL(file1);// http://192.168.203.213:8080// console.log('blobUrl',blobUrl)this.pdfPreview = blobUrl} else {this.$message.error('仅支持pdf格式文件');return;}// console.log('触犯上传',files);// for (let i = 0; i < files.length; i++) {// const file = files[i];const file = files[0];const regx = /\.docx$/i;const regc = /\.doc$/i;// console.log('file==',file)if (file.type === "application/pdf" ||file.type === "application/msword" ||file.type === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||regx.test(file.name) || regc.test(file.name)) {let transform_type_val;if (files[0].type === "application/pdf") {if (this.routerType == 'word') {transform_type_val = 'pdf2word';file.transform_type = transform_type_val;} else if (this.routerType == 'excel') {transform_type_val = 'risk';file.extract_type = transform_type_val;}// console.log('pdf',file.transform_type)}//this.selectedFiles.push(file);// console.log('this.selectedF/iles',this.selectedFiles)}// }// this.uploadFiles();this.fileInputRef.value = null;},//走接口的方法async uploadFiles() {// console.log('this.selecte/dFiles==',this.selectedFiles)if (this.selectedFiles.length === 0) {this.$message.warning("没有选择要上传的文件");return;}const pattern = /http:\/\/oss:/g;// const pattern = /http:\/\/127.0.0.1:/g;const formData = new FormData();let ConvertPDF = false;// console.log('this.selectedFiles===',this.selectedFiles)this.selectedFiles.forEach((file) => {// if(file.transform_type=='pdf2word'){//   ConvertPDF = true// }formData.append("file", file);// console.log('2656251==',)if (this.routerType == 'word') {formData.append("transform_type", file.transform_type);} else if (this.routerType == 'excel') {formData.append("extract_type", file.extract_type);}});// console.log('didiididi==',)const aiToken = sessionStorage.getItem("aiToken");const xtpToken = sessionStorage.getItem("xtpToken");let apiUrlif (this.routerType == 'word') {apiUrl = '/api/v1/transform/create'// apiUrl = '/api/api/v1/transform/create'} else if (this.routerType == 'excel') {apiUrl = '/api/v1/extract/create'// apiUrl = '/api/api/v1/extract/create'}try {// console.log('上传')const response = await axios.post(apiUrl,formData,{headers: {"Content-Type": "multipart/form-data",token: aiToken ? aiToken : xtpToken,},});this.loading = truethis.$message.success("文件上传成功");//这应该获得上传好文件的id// console.log('didi==',response.data.data);let id = response.data.data.id;this.$emit('upload', id)if (!id) {this.$message.warning('请上传文件')return} else {const fileId = idif (this.routerType == 'word') {startTransform({ transform_task_id: fileId }).then((res) => {// console.log('转换',res);})} else if (this.routerType == 'excel') {startExtract({ extract_task_id: fileId }).then((res) => {// console.log('转换',res);}).finally(() => {console.log("无论如何都执行")});}if (this.routerType == 'word') {this.$router.push('/wordTable')} else if (this.routerType == 'excel') {this.$router.push('/excelTable')}}let src = '';let errorMsg = '';// 判断是否转pdf走转pdf的接口if (ConvertPDF) {this.timer = setInterval(() => {detai(id).then((res) => {src = res.data.pdf_filepath;errorMsg = res.data.convert_errorif (src) {const a = src.replace(pattern, `http://10.223.33.105:`);this.ispdf = true;this.pdfsrc = a;this.uploaded = true;this.loading = falseclearInterval(this.timer)}if (errorMsg) {this.$message.error("文件转换失败" + errorMsg);}})}, 3000);} else {//在这获取要展示的pdf地址// file_url// console.log('在这获取要展示的pdf地址',response.data)src = response.data.data.file_url;// const a = src.replace(pattern, `http://192.168.202.231:`);const a = src.replace(pattern, `http://10.223.33.105:`); this.ispdf = true;this.pdfsrc = a;this.uploaded = true;// console.log('pdfsrc==',this.pdfsrc)}} catch (error) {// this.uploaded = true;this.$message.error("文件上传失败" + error.message);}},// 重新选择reselect() {this.$confirm("重新选择比对结果会被清空?", "提示", {distinguishCancelAndClose: true,confirmButtonText: "确定",cancelButtonText: "取消",}).then(() => {this.uploaded = false;// console.log("dada");this.selectedFiles = []this.pdfsrc = ''this.loading = falsethis.$emit('upload', null)if (this.timer) {clearInterval(this.timer)}}).catch(() => { });},
</script>

第三步:实现本地文件渲染的 <embed> 标签

渲染机制:利用浏览器内置的 PDF 插件进行渲染

<embed v-if="pdfPreview" id="pdfPreview" :src="pdfPreview" width="100%" />

效果图
在这里插入图片描述

在这里插入图片描述

http://www.dtcms.com/wzjs/753446.html

相关文章:

  • 建设局网站查勘表是什么男女做暖网站是什么意思
  • 攀枝花网站开发湖南省城乡建设厅网站查证
  • 个人做网站猛赚钱网站基建建设
  • 自己怎么做wap网站网站最新一次改版时间什么意思
  • 临沂企业宣传片制作公司搜索引擎优化的内容包括
  • 投教网站建设wordpress的站 做固定链接301重定向对百度的影响
  • 平阳住房和城乡建设厅网站做阅读理解的网站
  • 烟台市建设工程检测站网站深圳证券网站开发
  • 绿色在线网站模板西安网站制作公司有哪家
  • 好的做问卷调查的网站wordpress 移动版商城
  • 手机网站会员识别功能投资建设集团网站
  • 设计商标的网站重庆网上房地产查询
  • 网站被黑是什么原因扬州seo
  • 织梦如何生成网站地图网页布局设计技术包括
  • 丝绸之路网站建设报告皮带哥 长沙
  • 淮安建设网站制作wordpress默认主题加logo
  • 搭建一个网站的流程电商网站建设网络公司
  • 网站上传用什么软件做视频格式南京移动网站设计
  • 网站建设优点如何查询网站建设时间
  • 返利导购网站建设需求文档网站建设古典风格
  • 北滘禅城网站建设自助建网站平台怎么收费
  • 网站服务器租用价格门户网站做等保需要备案哪些
  • 重庆做营销型网站建设公司河南论坛网站建设
  • 重庆网站建设找重庆最佳科技企业网站 jquery
  • 网站推广方案中评价效果是指logo设计注册
  • 杭州网站公司设计注册资本随便填了500万
  • 门户网站是用户上网的第一入口卸载wordpress
  • 网站流量 名词百度推广一年收费标准
  • 电子商务网站建设的范围是什么意思北京网页制作设计
  • 哪些网站可以医生做兼职更换网站需要备案吗