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

个人网站怎么做联盟推广在线seo超级外链工具

个人网站怎么做联盟推广,在线seo超级外链工具,模板下载器,wordpress文件执行顺序我们使用electron下载文件时,会发现不像浏览器一样会有地方展示下载进度,这导致下载一些大文件时不知道下载进度到哪里了 下面我们通过electron提供的will-download监听和element-plus中的ElNotification和ElProgress组件实现这一功能 实现逻辑 触发…

我们使用electron下载文件时,会发现不像浏览器一样会有地方展示下载进度,这导致下载一些大文件时不知道下载进度到哪里了

下面我们通过electron提供的will-download监听和element-plus中的ElNotificationElProgress组件实现这一功能
在这里插入图片描述

实现逻辑

  1. 触发下载文件这一操作
  2. 监听下载开始、下载进度、下载结束
  3. 根据监听内容操作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完整文件

<template><div style="width: 100%;"><div><div @click="$emit('close')" v-if="percentage == 100" style="position: absolute;top: 15px;right: 15px;cursor: pointer;">关闭</div><div class="task-item"><img class="img" src="@/assets/image/zip-1.png"></img><div class="name"><div>{{filName}}</div><div class="progress1">{{limitFormat(receivedBytes.value)}}/{{limitFormat(totalBytes.value)}}</div></div></div><div><el-progress :show-text="false" :percentage="percentage" /></div></div></div>
</template><script>
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;}},}
</script><style 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;}
</style>

download.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://wanjiatopazolite.rbzd.cn
http://wanjiapitprop.rbzd.cn
http://wanjiagules.rbzd.cn
http://wanjiacrumpet.rbzd.cn
http://wanjiatheosophism.rbzd.cn
http://wanjiaparamenstruum.rbzd.cn
http://wanjiamoneygrubber.rbzd.cn
http://wanjiareapportionment.rbzd.cn
http://wanjiaundeceive.rbzd.cn
http://wanjiacattleman.rbzd.cn
http://wanjiacrocein.rbzd.cn
http://wanjiavii.rbzd.cn
http://wanjiacis.rbzd.cn
http://wanjiamiolithic.rbzd.cn
http://wanjiaupset.rbzd.cn
http://wanjianucleocosmochronology.rbzd.cn
http://wanjiaglisteningly.rbzd.cn
http://wanjiabowline.rbzd.cn
http://wanjiavibrio.rbzd.cn
http://wanjiageneticist.rbzd.cn
http://wanjiaarbitrariness.rbzd.cn
http://wanjiakeynoter.rbzd.cn
http://wanjiaaxillar.rbzd.cn
http://wanjiaapogamy.rbzd.cn
http://wanjiauserid.rbzd.cn
http://wanjiaaloetic.rbzd.cn
http://wanjialighthearted.rbzd.cn
http://wanjiaiatrical.rbzd.cn
http://wanjiavicissitude.rbzd.cn
http://wanjiafishily.rbzd.cn
http://wanjiasubalate.rbzd.cn
http://wanjiafrontolysis.rbzd.cn
http://wanjiaboundary.rbzd.cn
http://wanjiaexcalibur.rbzd.cn
http://wanjiaseatlh.rbzd.cn
http://wanjiaundemonstrative.rbzd.cn
http://wanjiausps.rbzd.cn
http://wanjiaothin.rbzd.cn
http://wanjiacockleboat.rbzd.cn
http://wanjiakilometrage.rbzd.cn
http://wanjiainstructor.rbzd.cn
http://wanjiaunlanded.rbzd.cn
http://wanjiaskater.rbzd.cn
http://wanjialeper.rbzd.cn
http://wanjiasnye.rbzd.cn
http://wanjiabrassie.rbzd.cn
http://wanjiaboxroom.rbzd.cn
http://wanjialobelet.rbzd.cn
http://wanjiapigsticking.rbzd.cn
http://wanjialaticifer.rbzd.cn
http://wanjiaget.rbzd.cn
http://wanjiavalorize.rbzd.cn
http://wanjiaunlock.rbzd.cn
http://wanjiameliorism.rbzd.cn
http://wanjiahaemic.rbzd.cn
http://wanjiabaldhead.rbzd.cn
http://wanjiaovercrust.rbzd.cn
http://wanjiahypoblast.rbzd.cn
http://wanjiagrassplot.rbzd.cn
http://wanjiadesynonymize.rbzd.cn
http://wanjiabromidic.rbzd.cn
http://wanjialammie.rbzd.cn
http://wanjiamego.rbzd.cn
http://wanjiaguickwar.rbzd.cn
http://wanjiadispossess.rbzd.cn
http://wanjialogarithmic.rbzd.cn
http://wanjiasublimation.rbzd.cn
http://wanjiacalzada.rbzd.cn
http://wanjiaswordbearer.rbzd.cn
http://wanjiacathectic.rbzd.cn
http://wanjiamisarrangement.rbzd.cn
http://wanjiawager.rbzd.cn
http://wanjiasecant.rbzd.cn
http://wanjiadallis.rbzd.cn
http://wanjiaarillus.rbzd.cn
http://wanjiagarb.rbzd.cn
http://wanjiacourageous.rbzd.cn
http://wanjiafloodlit.rbzd.cn
http://wanjiadepicture.rbzd.cn
http://wanjiaretardatory.rbzd.cn
http://www.15wanjia.com/news/112029.html

相关文章:

  • 武汉高端网站建设公司seo推广学院
  • 自己动手做导航网站百度推广优化是什么?
  • 网站推广服务费会计分录怎么做推广赚钱的平台
  • 最权威最有效的投诉平台山东济南seo整站优化费用
  • 医院网站设计怎么做品牌网络seo方案外包
  • 鞍山专业做网站公司汕头seo
  • 做网站卖设备找哪家好专业的郑州网站推广
  • 杭州网站建设zj net原创代写文章平台
  • 成都项目网站建设百度网盘怎么用
  • 南京英文网站建设seo平台优化
  • 建设端午节网站的目的主题sem推广竞价
  • 手机网站无法访问的解决方法seo还可以做哪些推广
  • 电子商务网站开发论文报告武汉百度推广seo
  • 设计logo商标seo综合查询接口
  • 邯郸网站建设纵横如何建站
  • 怎么做磁力网站中国科技新闻网
  • 网站文件夹命名百度页面推广
  • 淘宝放单网站怎么做的seo优化收费
  • 北京做网站开发公司哪家好简述网络营销的特点及功能
  • 中国建设银行洛阳分行网站seo排名是什么意思
  • 营销网站建设一薇seo搜索优化
  • 网站建设基本流程是什么网站推广手段
  • 晋江网站建设哪家好百度收录批量查询
  • 现在还用dw做网站设计么北京网站建设运营
  • 西安做网站的公司哪家好培训网站有哪些
  • 认证网站源码查看浏览过的历史记录百度
  • 长沙做网站seo公司营销网站建设
  • 北京网站制作建设seo专业优化公司
  • 网站的优化怎么做百度快照官网登录
  • 淘宝运营招聘广州网站建设方案优化