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

网站进度条源代码juqery-ui商城网站的建设费用

网站进度条源代码juqery-ui,商城网站的建设费用,国外做的比较好的展台网站,打开网站总显示建设中功能#xff1a; 1.多文件同时上传、2.拖动上传、3.实时上传进度条、4.中断上传和删除文件、5.原生file控件的美化 搁置的功能: 上传文件夹、大文件切片上传、以及其他限制条件未处理 Node服务器的前置准备: 新建文件夹: file_upload_serve初始化npm: npm …功能 1.多文件同时上传、2.拖动上传、3.实时上传进度条、4.中断上传和删除文件、5.原生file控件的美化 搁置的功能: 上传文件夹、大文件切片上传、以及其他限制条件未处理 Node服务器的前置准备: 新建文件夹: file_upload_serve初始化npm: npm init -y安装工具 npm add express multernodemon工具: npm install nodemon -gaxios: npm install axios -sNode运行版本: 18.17.1修改package.json文件scripts: {test: echo \Error: no test specified\ exit 1}, 改为:监听app.jsscripts: {dev: nodemon ./app.js}, 启动: npm run dev Node file_upload_serve app.js 按前置准备完成其他无需更改,请求部分全在app.js /** Description: * Last Date: Do not edit*/ const express require(express) // post请求解析body const bodyParser require(body-parser) // 上传工具库 const multer require(multer) const { writeFileSync } require(fs) const { resolve } require(path) const path require(path) const fs require(fs)const app express() app.use(bodyParser.json({limit: 10mb, extended: true})) // 静态资源共享(下载需要) app.use(express.static(path.join(__dirname, public))) // const storage multer.diskStorage({ // destination: function (req, file, callback) { // // 第一个参数: errorMessage; 参数2: 目标,即下载到哪个文件夹下 // callback(null, uploads/) // }, // filename: function (req, file, callback) { // // 获取上传文件的后缀名 // const ext file.originalname.split(.)[1] // callback(null, Date.now() . ext) // } // }) const storage multer.diskStorage({destination: (req, file, cb) {cb(null, uploads/) // 分片存储目录},filename: (req, file, cb) {const ext file.originalname.split(.)[1]if(req.body.rename) {cb(null, Date.now() . ext) // 单文件名} else {cb(null, ${req.body.index}-${req.body.fileName}) // 分片文件名}} })// 生成upload对象 const upload multer({storage, })// 设置请求头 app.all(*, (req, res, next) {// 允许所有不同源的地址访问res.header(Access-Control-Allow-Origin, *);// 跨域允许的请求方式res.header(Access-Control-Allow-Methods, GET, POST);// x-ext: 获取文件的后缀名// res.header(Access-Control-Allow-Headers, Content-Type, x-ext);// res.header(Access-Control-Allow-Headers, Content-Type);res.header(Access-Control-Allow-Headers, Origin, X-Requested-With, Content-Type, Accept, x-ext);if (req.method.toLowerCase() options){res.send(200); //让options尝试请求快速结束} else {next()}})/* 上传方式1 multipart/form-data** upload.single 单文件上传*/ app.post(/file, upload.single(file), (req, res) {if(req.file){res.send(formData上传成功)} else {res.send(form-data上传失败)} })/* 上传方式2 base64** upload.single 单文件上传*/ app.post(/base64, (req, res) {const { file, ext, fileName } req.bodyconst binaryData Buffer.from(file, base64)if(!fileName) {writeFileSync(resolve(__dirname, uploads/ Date.now() . ext), binaryData, binary)} else {writeFileSync(resolve(__dirname, uploads/ fileName), binaryData, binary)}res.send(base64文件流上传成功) })/* 上传方式3 binary 二进制** upload.single 单文件上传*/ app.post(/binary, (req, res) {const ext req.headers[x-ext]const buffers []req.on(data, chunk {buffers.push(chunk)}).on(end, () {const binaryData Buffer.concat(buffers)writeFileSync(resolve(__dirname, uploads/ Date.now() . ext), binaryData, binary)res.send(二进制流上传成功)}) }) /* 多文件上传 formData** upload.array(formData中的字段名, 最大上传数量): */ app.post(/files, upload.array(files, 4), (req, res) {console.log(req.files)if(req.files){res.send(多文件formData上传成功)} else {res.send(多文件formData上传失败)} }) /* 文件下载* __dirname: 代表当前文件app.js所在的文件路径*/ app.get(/download, (req, res) {try{// 下载路径: __dirname 拼接 第二个参数的路径const filePath path.join(__dirname, /public/download/1731726859151.txt)res.download(filePath)}catch(e){console.log(e)}})app.post(/merge, async (req, res) {const uploadPath /uploadslet files fs.readdirSync(path.join(process.cwd(), uploadPath)) // 获取所有的分片数据console.log(files)console.log(req.body.fileName)files files.sort((a, b) a.split(-)[0] - b.split(-)[0]) // 将分片按照文件名进行排序const writePath path.join(process.cwd(), uploadPath, ${req.body.fileName}) // 生成新的文件路径files.forEach((item) {fs.appendFileSync(writePath, fs.readFileSync(path.join(process.cwd(), uploadPath, item))) // 读取分片信息追加到新文件路径尾部fs.unlinkSync(path.join(process.cwd(), uploadPath, item)) // 将读取过的分片进行删除})res.send(ok) })app.listen(8888, () {console.log(链接成功)})客户端 !--* Description: 功能 1.多文件同时上传、2.拖动上传、3.实时上传进度条、* 4.中断上传和删除文件、5.原生file控件的美化* 搁置的功能: 上传文件夹、大文件切片上传、以及其他限制条件未处理* Last Date: Do not edit -- templatediv classcontainerheaderdivclassboxdrophandleClickdragenterhandleClickdragoverhandleClickdragleavehandleClickdiv classbox-fontdivspan styledisplay: flex; align-items: centeri classel-icon-upload /ip将目录或多个文件拖拽到此进行扫描/p/span/divdivspan支持的文件类型: .JPG、.JPEG、.BMP、.PNG、.GIF、.ZIP、/span/divdivspan每个文件允许的最大尺寸: 1M/span/div/div/div/headermaindiv classmain-choose-files-btndiv classfile-boxinput typebutton classbtn value选择文件 /inputtypefileclassfilechangepreviewMoreFilesByFormDatamultiple//divdiv classfile-boxinput typebutton classbtn value选择文件夹 /inputtypefileclassfilechangepreviewMoreFilesByFormDatamultiple//div/divdivel-table :datatableData stripe stylewidth: 85%!-- el-table-columnv-foritem in tableColumn:keyitem.prop:propitem.prop:labelitem.label/el-table-column --el-table-columnpropnamelabel文件名width240fixed/el-table-columnel-table-column proptype label类型/el-table-columnel-table-column propsize label大小/el-table-columnel-table-column propstate label状态!-- 当template中有多个元素需要切换时,需要在最外层使用div将所有元素包裹住 --!-- slot-scopescope 必须加,否则数据不是响应式的 --template slot-scopescopedivdivv-showscope.row.progressPercent 0 scope.row.progressPercent 100el-progress:text-insidetrue:stroke-width15:percentagescope.row.progressPercent//divdivv-showscope.row.progressPercent 1slotreferenceclassname-wrapperel-tag sizemedium 待上传 /el-tag/divdivv-showscope.row.progressPercent 100slotreferenceclassname-wrapperel-tag sizemedium 已上传 /el-tag/div/div/template/el-table-columnel-table-column label操作template slot-scopescopei classel-icon-delete clickdeleteFile(scope.row)/i/template/el-table-column/el-table/div/mainfooterel-rowel-button classfoot-btn sizeminispan文件数量: {{ tableData.length }}/span/el-buttonel-button classfoot-btn typesuccess plain sizemini成功数量: {{ successCount }}/el-buttonel-button classfoot-btn sizeminispan总大小: {{ countSize }} MB/span/el-button/el-rowel-row classupload-btnel-buttontypeprimary:disableduploadDisabledclickhandelUploadMoreFile开始上传/el-button/el-row/footer/div /templatescript import axios from axios export default {data() {return {ext: undefined, // 文件后缀名tableData: [],tableColumn: [{ prop: name, label: 文件名 },{ prop: type, label: 类型 },{ prop: size, label: 大小 },{ prop: progressPercent, label: 状态 },{ prop: option, label: 操作 },],filesNumber: 1, // 列表文件总条数successCount: 0, // 上传成功条数cancelTokens: [], // 存储每个请求的取消方法}},mounted() {// 阻止事件冒泡,防止在拖拽后意外打开新标签页document.body.ondrop function (event) {event.preventDefault()event.stopPropagation()}},computed: {getByte() {return this.tableData.reduce((a, b) {return a b.size}, 0)},// 文件总大小countSize() {return (this.getByte / 1048576).toFixed(2)},// 是否禁用上传按钮uploadDisabled() {return this.tableData.length 0 ? false : true},},methods: {// 读取多个文件previewMoreFilesByFormData(e, drop) {let filesif (!drop) {files e.target.files} else {files e}// 获取文件后缀名this.ext files[0].name.split(.)[1]if (!files) returnvar i 0var _this thisvar funcs function () {if (files[i]) {var reader new FileReader()reader.onload function (e) {const uint8Array new Uint8Array(e.target.result)const str uint8Array.reduce((prev, byte) {prev String.fromCharCode(byte)return prev}, )let now new Date()// 由于JS执行速度很快,极大可能会得到一样的时间戳,故将timestamp加上下标// timestamp的作用是在将来删除文件时,作为唯一id对比删除let timestamp now.getTime()// 将预览的文件中数据转换到table中_this.tableData.push({timestamp: timestamp i,name: files[i].name,type: files[i].type,size: files[i].size,progressPercent: 0,dataBase64: btoa(str),})// progressPercent 上传进度条ifuncs() // onload为异步调用}reader.readAsArrayBuffer(files[i])}}funcs()},/** 删除上传文件* 不能通过数组下标去删。删除再添加新文件时,下标会重复* param row(行数据)*/deleteFile(row) {// 删除文件this.tableData this.tableData.filter((item) item.timestamp ! row.timestamp)// 中断请求const requestToCancel this.cancelTokens.find((token) token.requestId row.requestId)if (requestToCancel requestToCancel.cancel) {requestToCancel.cancel(Request was canceled by the user.)}},// 上传文件handelUploadMoreFile() {let _this thisconst CancelToken axios.CancelTokenconst List []for (let i 0; i this.tableData.length; i) {// console.log(source.cancel)const ext this.ext // 文件后缀名// 为每个请求创建一个新的取消令牌源const cancelTokenSource CancelToken.source()this.cancelTokens.push({requestId: i,cancel: cancelTokenSource.cancel,})// 给tableData设置requestId,将来取消请求通过比对id对应到具体的请求this.tableData[i].requestId ivar a axios({url: http://localhost:8888/base64,method: post,cancelToken: cancelTokenSource.token,data: {ext,fileName: this.tableData[i].name,file: this.tableData[i].dataBase64,},onUploadProgress: (progressEvent) {/** 上传进度条* progressEvent.loaded: 已上传文件大小* progressEvent.total: 被上传文件的总大小*/_this.tableData[i].progressPercent (progressEvent.loaded / progressEvent.total) * 100},}).then((res) {// this.$message({// message: 文件上传成功,// type: success// })// console.log(res)}).catch((error) {if (axios.isCancel(error)) {console.log(error.message)} else {console.log(error.message)}})List.push(a)}// 合并异步上传Promise.all(List).then((res) {}).catch((err) {})},// 处理鼠标拖放事件handleClick(e) {if (e.type dragenter) {// this.className drag_hover}if (e.type dragleave) {// this.className }if (e.type drop) {var files e.dataTransfer.filesthis.className if (files.length ! 0) {this.previewMoreFilesByFormData(files, drop)}}if (e.type dragover) {// e.dataTransfer.dragEffect copy}},}, } /scriptstyle langscss body, html {list-style: none;padding: 0;margin: 0; } .container {width: 85%;margin: 25px auto;.box {width: 85%;height: 300px;border-style: dashed; // border虚线border-width: 1px;margin-bottom: 20px;display: flex; /* 启用 Flexbox */justify-content: center; /* 水平居中 */align-items: center; /* 垂直居中 */.box-font {display: flex;flex-direction: column;align-items: center;gap: 30px;span {display: block;}}}main {.main-choose-files-btn {display: flex;gap: 100px;height: 44px;}}footer {margin-top: 20px;.upload-btn {margin-top: 10px;}} } // 对原生file控件优化 .btn, .file {extend .merge-input; } .merge-input {// display: block;position: absolute;width: 75px;height: 35px;color: #fff;border-radius: 4px;border-color: #409eff; } .btn {z-index: 2;background: #409eff; // #66b1ff 409effpointer-events: none; /* 让事件传递到下一层,即: btn的层级比file高,但btn能触发file的事件 */ } .file {z-index: 1; } // el-table表头样式修改 .el-table th {font-size: 13px;font-weight: 700; }.el-table .el-table__header th, .el-table .el-table__header tr, .el-table .el-table__header td {background: #f5f8fd; }.el-icon-upload {font-size: 35px; } /style
文章转载自:
http://www.morning.bflws.cn.gov.cn.bflws.cn
http://www.morning.rnds.cn.gov.cn.rnds.cn
http://www.morning.wwwghs.com.gov.cn.wwwghs.com
http://www.morning.tzrmp.cn.gov.cn.tzrmp.cn
http://www.morning.cfnsn.cn.gov.cn.cfnsn.cn
http://www.morning.mzjbz.cn.gov.cn.mzjbz.cn
http://www.morning.nsrtvu.com.gov.cn.nsrtvu.com
http://www.morning.kzcfp.cn.gov.cn.kzcfp.cn
http://www.morning.jbxd.cn.gov.cn.jbxd.cn
http://www.morning.swkpq.cn.gov.cn.swkpq.cn
http://www.morning.wkmyt.cn.gov.cn.wkmyt.cn
http://www.morning.rqkck.cn.gov.cn.rqkck.cn
http://www.morning.lwnwl.cn.gov.cn.lwnwl.cn
http://www.morning.ydxx123.cn.gov.cn.ydxx123.cn
http://www.morning.tjsxx.cn.gov.cn.tjsxx.cn
http://www.morning.bxsgl.cn.gov.cn.bxsgl.cn
http://www.morning.myfwb.cn.gov.cn.myfwb.cn
http://www.morning.hmlpn.cn.gov.cn.hmlpn.cn
http://www.morning.krhkn.cn.gov.cn.krhkn.cn
http://www.morning.xctdn.cn.gov.cn.xctdn.cn
http://www.morning.gmplp.cn.gov.cn.gmplp.cn
http://www.morning.dzfwb.cn.gov.cn.dzfwb.cn
http://www.morning.ktmbp.cn.gov.cn.ktmbp.cn
http://www.morning.lqws.cn.gov.cn.lqws.cn
http://www.morning.qphcq.cn.gov.cn.qphcq.cn
http://www.morning.xqkjp.cn.gov.cn.xqkjp.cn
http://www.morning.lrylj.cn.gov.cn.lrylj.cn
http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn
http://www.morning.wjwfj.cn.gov.cn.wjwfj.cn
http://www.morning.pqwhk.cn.gov.cn.pqwhk.cn
http://www.morning.lgtzd.cn.gov.cn.lgtzd.cn
http://www.morning.cznsq.cn.gov.cn.cznsq.cn
http://www.morning.lfjmp.cn.gov.cn.lfjmp.cn
http://www.morning.yxbdl.cn.gov.cn.yxbdl.cn
http://www.morning.ghxsn.cn.gov.cn.ghxsn.cn
http://www.morning.tkflb.cn.gov.cn.tkflb.cn
http://www.morning.hxrfb.cn.gov.cn.hxrfb.cn
http://www.morning.swdnr.cn.gov.cn.swdnr.cn
http://www.morning.zqxhn.cn.gov.cn.zqxhn.cn
http://www.morning.lbbrw.cn.gov.cn.lbbrw.cn
http://www.morning.rfwgg.cn.gov.cn.rfwgg.cn
http://www.morning.srmdr.cn.gov.cn.srmdr.cn
http://www.morning.ntyks.cn.gov.cn.ntyks.cn
http://www.morning.dqrpz.cn.gov.cn.dqrpz.cn
http://www.morning.kfclh.cn.gov.cn.kfclh.cn
http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn
http://www.morning.sqdjn.cn.gov.cn.sqdjn.cn
http://www.morning.pmhln.cn.gov.cn.pmhln.cn
http://www.morning.brnwc.cn.gov.cn.brnwc.cn
http://www.morning.wsyst.cn.gov.cn.wsyst.cn
http://www.morning.psqs.cn.gov.cn.psqs.cn
http://www.morning.nmnhs.cn.gov.cn.nmnhs.cn
http://www.morning.xnnxp.cn.gov.cn.xnnxp.cn
http://www.morning.vvdifactory.com.gov.cn.vvdifactory.com
http://www.morning.kklwz.cn.gov.cn.kklwz.cn
http://www.morning.pamdeer.com.gov.cn.pamdeer.com
http://www.morning.rmfh.cn.gov.cn.rmfh.cn
http://www.morning.dhxnr.cn.gov.cn.dhxnr.cn
http://www.morning.ebpz.cn.gov.cn.ebpz.cn
http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn
http://www.morning.czqqy.cn.gov.cn.czqqy.cn
http://www.morning.rqgbd.cn.gov.cn.rqgbd.cn
http://www.morning.tkfnp.cn.gov.cn.tkfnp.cn
http://www.morning.fmqng.cn.gov.cn.fmqng.cn
http://www.morning.gskzy.cn.gov.cn.gskzy.cn
http://www.morning.knlyl.cn.gov.cn.knlyl.cn
http://www.morning.cbnlg.cn.gov.cn.cbnlg.cn
http://www.morning.sqhlx.cn.gov.cn.sqhlx.cn
http://www.morning.rjnx.cn.gov.cn.rjnx.cn
http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn
http://www.morning.xppj.cn.gov.cn.xppj.cn
http://www.morning.nwllb.cn.gov.cn.nwllb.cn
http://www.morning.bpmfg.cn.gov.cn.bpmfg.cn
http://www.morning.jfnbh.cn.gov.cn.jfnbh.cn
http://www.morning.trsfm.cn.gov.cn.trsfm.cn
http://www.morning.wfttq.cn.gov.cn.wfttq.cn
http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn
http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn
http://www.morning.mlzyx.cn.gov.cn.mlzyx.cn
http://www.morning.hkshy.cn.gov.cn.hkshy.cn
http://www.tj-hxxt.cn/news/240769.html

相关文章:

  • 中国城乡建设网站收费网站素材
  • 柳州网站建设价格深圳网站建设代理
  • 河北省建设集团有限公司网站做的网站怎样更新
  • 三合一网站有必要吗离婚在线律师
  • 合肥高端网站建设公司哪家好网站备案 取消接入
  • 简单的购物网站制作昆明seo怎么做
  • 友情链接站长平台制作宣传片视频
  • 网站开发进阶实训报告直接在原备案号下增加新网站
  • 做布料的著名网站广州地铁官网
  • 网站开发googlevue cdn做的网站
  • 制作个人网站教程怎么分析网页的布局
  • 要建立网站和账号违法违规行为数据库和什么黑名单怎么在虚拟空间做两个网站
  • 学校网站开发的背景网站建设代码题
  • 网站怎么做登陆17网站一起做网店潮汕
  • 烟台怎么做网站建设网站花多少钱
  • 哪家房屋设计公司网站新北做网站
  • 焦作网站建设哪家便宜外链工具在线
  • 百度云做网站空间做AMC12的题的网站
  • 如何制作收费网站响应式网页设计名词解释
  • 天津做网站的费用东港网站建设
  • 做国外的营销的网站如何更改网站关键词
  • 网站软件下载wordpress movie
  • 压铸东莞网站建设苏宁易购网站建设情况
  • 站长工具天美传媒深圳个人网站制作
  • 站外推广营销方案建筑人才网 珠海
  • 内江市网站建设网站获取访问者qq号码
  • 网站域名怎么申请阜南网站建设公司
  • 网站建设项目规划书案例做网站为什么要买服务器
  • 百度的合作网站有哪些怎么做网站搜索框搜索
  • 建设部网站资质查询6wordpress 用户登录ip