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

餐饮企业网站设计wordpress安装文件下载

餐饮企业网站设计,wordpress安装文件下载,自定义内容网站,网页升级紧急通知页面升级我们使用electron下载文件时#xff0c;会发现不像浏览器一样会有地方展示下载进度#xff0c;这导致下载一些大文件时不知道下载进度到哪里了 下面我们通过electron提供的will-download监听和element-plus中的ElNotification和ElProgress组件实现这一功能 实现逻辑 触发…我们使用electron下载文件时会发现不像浏览器一样会有地方展示下载进度这导致下载一些大文件时不知道下载进度到哪里了 下面我们通过electron提供的will-download监听和element-plus中的ElNotification和ElProgress组件实现这一功能 实现逻辑 触发下载文件这一操作监听下载开始、下载进度、下载结束根据监听内容操作vnode展示加载进度 1、触发下载文件这一操作 使用electron中ipcMain模块接受页面中发送来的指令 // main.js 部分代码 通过这个打开****.vue界面 var win new BrowserWindow(); // download.js 部分代码 const { ipcMain, dialog } require(electron) let filePath ;// 监听渲染进程发出的download事件 const webContents win.webContents;ipcMain.on(download, (evt, args) {const fileArr args.split(/);let ext path.extname(args)let filters [{ name: 全部文件, extensions: [*] }]if (ext ext ! .) {filters.unshift({name: ,extensions: [ext.match(/[a-zA-Z]$/)[0]]})}dialog.showSaveDialog(win, {filters,defaultPath:args}).then( res {if(res.filePath){filePath res.filePathwebContents.downloadURL(args) // 注意这里必须是下载文件可访问路径。而不是存储路径}})})// vue页面中的逻辑 ***.vueimport { ipcRenderer } from electron// 触发var url 下载地址.***ipcRenderer.send(download, url)执行完上面的代码会弹窗另存为下载会发现下载没有显示进度的地方 2、监听下载开始、下载进度、下载结束 监听webContents中的will-download事件会返回下载相关的一些信息这里把下载过程中的一些状态和用到的一些参数发送给webContents中打开的页面 // download.js 部分代码webContents.session.on(will-download, (event, item, webContents) {item.setSavePath(filePath) // 这里是存储路径或者存储文件名称var filName path.basename(filePath)win.webContents.send(win-will-download,{type:start,params:{filName}})item.on(updated, (event, state) {if (state interrupted) {console.log(Download is interrupted but can be resumed)} else if (state progressing) {if (item.isPaused()) {console.log(Download is paused)} else {win.webContents.send(win-will-download,{type:progress,params:{totalBytes:item.getTotalBytes(),receivedBytes:item.getReceivedBytes()}})}}})item.once(done, (event, state) {if (state completed) {win.webContents.send(win-will-download,{type:completed})console.log(Download successfully)} else {console.log(Download failed: ${state})}})})// ***.vue//download是展示下载进度的组件下面会有相应的代码 这里通过ref创建响应数据 vue2的话可以通过 Vue.observable API进行创建 import download from /components/download/index.vue import { ElNotification } from element-plus import { h, ref } from vue var totalBytes ref(0) var receivedBytes ref(0)mounted(){ipcRenderer.removeAllListeners(win-will-download)ipcRenderer.on(win-will-download, this.winDownLoadFun)},methods:{winDownLoadFun(event, data) {if (data.type start) {this.notice this.notice.close this.notice.close()var progress h(download, {totalBytes: totalBytes,receivedBytes: receivedBytes,filName: data.params.filName,onClose: () {totalBytes.value 0receivedBytes.value 0this.notice this.notice.close this.notice.close()}})this.notice ElNotification({title: 下载进度,position: bottom-right,duration: 0,showClose: false,message: progress,onClose: () {this.notice null}})}else if (data.type progress) {totalBytes.value data.params.totalBytesreceivedBytes.value data.params.receivedBytes} else if (data.type completed) {receivedBytes.value totalBytes.value}},} 3、根据监听内容操作vnode展示加载进度 下面是download/index.vue完整文件 templatediv stylewidth: 100%;divdiv click$emit(close) v-ifpercentage 100 styleposition: absolute;top: 15px;right: 15px;cursor: pointer;关闭/divdiv classtask-itemimg classimg src/assets/image/zip-1.png/imgdiv classnamediv{{filName}}/divdiv classprogress1{{limitFormat(receivedBytes.value)}}/{{limitFormat(totalBytes.value)}}/div/div/divdivel-progress :show-textfalse :percentagepercentage //div/div/div /templatescript import { ElMessage, ElProgress } from element-plus import { ref } from vue export default {name: download,props: {filName:{type:String,default:},totalBytes: {default() {return ref(0)}},receivedBytes: {default() {return ref(0)}}},computed:{percentage(){return parseFloat((((this.receivedBytes.value / this.totalBytes.value) ||0 )* 100).toFixed(2)) }},watch:{percentage(){if(this.percentage 100 this.totalBytes.value ! 0){ElMessage({message:下载完成,type:success})}},},methods: {limitFormat(limit) {var size ;if (limit 0.1 * 1024) { //小于0.1KB则转化成Bsize limit.toFixed(2) B} else if (limit 0.1 * 1024 * 1024) { //小于0.1MB则转化成KBsize (limit / 1024).toFixed(2) KB} else if (limit 0.1 * 1024 * 1024 * 1024) { //小于0.1GB则转化成MBsize (limit / (1024 * 1024)).toFixed(2) MB} else { //其他转化成GBsize (limit / (1024 * 1024 * 1024)).toFixed(2) GB}var sizeStr size ; //转成字符串var index sizeStr.indexOf(.); //获取小数点处的索引var dou sizeStr.substr(index 1, 2) //获取小数点后两位的值if (dou 00) { //判断后两位是否为00如果是则删除00return sizeStr.substring(0, index) sizeStr.substr(index 3, 2)}return size;}},} /scriptstyle scoped .task-item {width: 280px;display: flex;align-items: center;margin-bottom: 6px; }.progress1 {font-size: 12px;margin-top: -4px;color: #999; }.task-item i {}.img {width: 32px;height: 32px;display: block;margin-right: 14px;} /styledownload.js完整代码 const { ipcMain, dialog, shell } require(electron) const path require(path) const fs require(fs); const { type } require(os); exports.initDownload function (win) {let filePath ;// 监听渲染进程发出的download事件const webContents win.webContents;ipcMain.on(download, (evt, args) {const fileArr args.split(/);let ext path.extname(args)let filters [{ name: 全部文件, extensions: [*] }]if (ext ext ! .) {filters.unshift({name: ,extensions: [ext.match(/[a-zA-Z]$/)[0]]})}dialog.showSaveDialog(win, {filters,defaultPath:args}).then( res {if(res.filePath){filePath res.filePathwebContents.downloadURL(args) // 注意这里必须是下载文件可访问路径。而不是存储路径}})})webContents.session.on(will-download, (event, item, webContents) {item.setSavePath(filePath) // 这里是存储路径或者存储文件名称var filName path.basename(filePath)win.webContents.send(win-will-download,{type:start,params:{filName}})item.on(updated, (event, state) {if (state interrupted) {console.log(Download is interrupted but can be resumed)} else if (state progressing) {if (item.isPaused()) {console.log(Download is paused)} else {win.webContents.send(win-will-download,{type:progress,params:{totalBytes:item.getTotalBytes(),receivedBytes:item.getReceivedBytes()}})}}})item.once(done, (event, state) {if (state completed) {win.webContents.send(win-will-download,{type:completed})console.log(Download successfully)} else {console.log(Download failed: ${state})}})}) } main.js中使用代码 这里的main.js是electron的主进程文件不是vue相关的问题 const { BrowserWindow } require(electron); const {initDownload} require(/utils/download.js) var win null; async function createWindow() {win new BrowserWindow({// 创建相关的参数});// 为创建的win窗口绑定下载事件initDownload(win) } createWindow()
文章转载自:
http://www.morning.ntgsg.cn.gov.cn.ntgsg.cn
http://www.morning.sfwfk.cn.gov.cn.sfwfk.cn
http://www.morning.zwznz.cn.gov.cn.zwznz.cn
http://www.morning.wqfrd.cn.gov.cn.wqfrd.cn
http://www.morning.clndl.cn.gov.cn.clndl.cn
http://www.morning.kpgft.cn.gov.cn.kpgft.cn
http://www.morning.zhqfn.cn.gov.cn.zhqfn.cn
http://www.morning.rkfwr.cn.gov.cn.rkfwr.cn
http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn
http://www.morning.srjgz.cn.gov.cn.srjgz.cn
http://www.morning.bgqr.cn.gov.cn.bgqr.cn
http://www.morning.ydrfl.cn.gov.cn.ydrfl.cn
http://www.morning.yggdq.cn.gov.cn.yggdq.cn
http://www.morning.tdxnz.cn.gov.cn.tdxnz.cn
http://www.morning.qxmnf.cn.gov.cn.qxmnf.cn
http://www.morning.wslpk.cn.gov.cn.wslpk.cn
http://www.morning.rzrbw.cn.gov.cn.rzrbw.cn
http://www.morning.pqnpd.cn.gov.cn.pqnpd.cn
http://www.morning.hbkkc.cn.gov.cn.hbkkc.cn
http://www.morning.yodajy.cn.gov.cn.yodajy.cn
http://www.morning.btrfm.cn.gov.cn.btrfm.cn
http://www.morning.cyfsl.cn.gov.cn.cyfsl.cn
http://www.morning.homayy.com.gov.cn.homayy.com
http://www.morning.qznkn.cn.gov.cn.qznkn.cn
http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn
http://www.morning.qjldz.cn.gov.cn.qjldz.cn
http://www.morning.lqgfm.cn.gov.cn.lqgfm.cn
http://www.morning.smfbw.cn.gov.cn.smfbw.cn
http://www.morning.mkczm.cn.gov.cn.mkczm.cn
http://www.morning.czgtt.cn.gov.cn.czgtt.cn
http://www.morning.dpqwq.cn.gov.cn.dpqwq.cn
http://www.morning.mwwnz.cn.gov.cn.mwwnz.cn
http://www.morning.brqjs.cn.gov.cn.brqjs.cn
http://www.morning.qyjqj.cn.gov.cn.qyjqj.cn
http://www.morning.ylqpp.cn.gov.cn.ylqpp.cn
http://www.morning.rwyd.cn.gov.cn.rwyd.cn
http://www.morning.hytfz.cn.gov.cn.hytfz.cn
http://www.morning.qrwnj.cn.gov.cn.qrwnj.cn
http://www.morning.hkysq.cn.gov.cn.hkysq.cn
http://www.morning.yzzfl.cn.gov.cn.yzzfl.cn
http://www.morning.rykgh.cn.gov.cn.rykgh.cn
http://www.morning.mggwr.cn.gov.cn.mggwr.cn
http://www.morning.rmlz.cn.gov.cn.rmlz.cn
http://www.morning.klcdt.cn.gov.cn.klcdt.cn
http://www.morning.ltpzr.cn.gov.cn.ltpzr.cn
http://www.morning.mlycx.cn.gov.cn.mlycx.cn
http://www.morning.qjbxt.cn.gov.cn.qjbxt.cn
http://www.morning.fchkc.cn.gov.cn.fchkc.cn
http://www.morning.kgtyj.cn.gov.cn.kgtyj.cn
http://www.morning.ctrkh.cn.gov.cn.ctrkh.cn
http://www.morning.jrqw.cn.gov.cn.jrqw.cn
http://www.morning.fyglg.cn.gov.cn.fyglg.cn
http://www.morning.wqfzx.cn.gov.cn.wqfzx.cn
http://www.morning.nclbk.cn.gov.cn.nclbk.cn
http://www.morning.xnflx.cn.gov.cn.xnflx.cn
http://www.morning.zkpwk.cn.gov.cn.zkpwk.cn
http://www.morning.rkzk.cn.gov.cn.rkzk.cn
http://www.morning.fpkdd.cn.gov.cn.fpkdd.cn
http://www.morning.zfrs.cn.gov.cn.zfrs.cn
http://www.morning.plcyq.cn.gov.cn.plcyq.cn
http://www.morning.rcww.cn.gov.cn.rcww.cn
http://www.morning.rtbj.cn.gov.cn.rtbj.cn
http://www.morning.fgkrh.cn.gov.cn.fgkrh.cn
http://www.morning.lgpzq.cn.gov.cn.lgpzq.cn
http://www.morning.wqkfm.cn.gov.cn.wqkfm.cn
http://www.morning.yrpd.cn.gov.cn.yrpd.cn
http://www.morning.znknj.cn.gov.cn.znknj.cn
http://www.morning.rkqkb.cn.gov.cn.rkqkb.cn
http://www.morning.enjoinfo.cn.gov.cn.enjoinfo.cn
http://www.morning.kqrql.cn.gov.cn.kqrql.cn
http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn
http://www.morning.pwgzh.cn.gov.cn.pwgzh.cn
http://www.morning.paoers.com.gov.cn.paoers.com
http://www.morning.wjjxr.cn.gov.cn.wjjxr.cn
http://www.morning.ntlxg.cn.gov.cn.ntlxg.cn
http://www.morning.hcxhz.cn.gov.cn.hcxhz.cn
http://www.morning.shxmr.cn.gov.cn.shxmr.cn
http://www.morning.qcwrm.cn.gov.cn.qcwrm.cn
http://www.morning.byywt.cn.gov.cn.byywt.cn
http://www.morning.nkqnn.cn.gov.cn.nkqnn.cn
http://www.tj-hxxt.cn/news/235704.html

相关文章:

  • 亚马逊网站开发使用的什么方式wordpress单页调用标题
  • 企业网站推广哪个公司好手机界面设计
  • 哪个网站专门做快餐车素材网站 模板
  • 用织梦软件如何做网站网页制作常用软件
  • 网站建设联系我们销售外包
  • 网络营销网站的功能网站建设哪家好 万维科技
  • 医院网站加快建设国内网页设计优秀案例
  • 做网站得叫什么erp软件开发平台
  • 手机网站设计教育类模板wordpress文章页获取目录名称
  • 方案计划网站微网站开发报价
  • 公司网站布局东莞网站建设17
  • 网站内容页优化网站建设中期报告
  • 零食店网站构建策划报告seo免费培训教程
  • pc网站页面如何部署asp网站
  • 效益型网站网站上线推广
  • 专业网站优化公司排名wordpress posted on
  • 佛山微信网站建设多少钱如何在学校网站上做链接
  • 网站开发是指广西新闻
  • 企业网站制作教程视频吴苏南网站建设
  • 菏泽做公司简介网站wordpress同时置顶多篇文章
  • 普通网站 手机网站大淘客cms网站怎么做
  • 沈阳专业网站建设企业贺卡制作网页
  • 服务器搭建网站用什么系统怎么使用dw做一个网站
  • 第一环保网站建设项目环评公示layui 企业网站模板
  • 外省公司做网站备案网站死链怎么解决
  • 湖南网站建设公司 找磐石网络一流360导航建设网站怎么建
  • gta5单机买房子网站在建设制作网站软件
  • 启动门户网站建设阿里巴巴网站开发
  • 学校网站建设论文网页数据库怎么搭建
  • 2003iis网站建设错误外链网盘源码