首页 > 其他分享 >vue3 文件上传进度条组件

vue3 文件上传进度条组件

时间:2023-08-17 17:24:03浏览次数:38  
标签:const 进度条 color vm height width background vue3 上传

index.vue文件

<template>
  <div class="confirm-modal">
    <transition name="fade">
      <div class="modal-dialog" @click="clickMaskToClose ? handleCancel() : null" v-if="visible" @touchmove.prevent>
        <div class="modal">
          <div class="modal-title" v-if="title">
            {{ title }}
          </div>
          <div class="modal-content">
            <div class="lineBox">
              <div class="line" :style="{'width': parseInt(percentage)+'%'}">
              </div>
            </div>
            <div class="num">
              {{parseInt(percentage)}}%
            </div>
          </div>
          <div class="hint" v-if="hint">
            {{parseInt(percentage) === 100 ? '数据整在处理请耐心等待...' : hint}}
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
  import {ref, defineComponent, reactive, toRefs} from "vue";

  export default defineComponent({
    props: {
      visible: {
        type: Boolean,
        default: false,
      },
      title: {
        type: String,
        default: "提示",
      },
      percentage: {
        type: Number,
        default: 0,
      },
      hint: {
        type: String,
        default: '',
      },
      clickMaskToClose: {
        type: Boolean,
        default: false,
      }, // 点击遮罩是否隐藏
    },

    emits: {
      onConfirm: null,
      onCancel: null,
    },
    setup(props, context) {
      let percentage = ref(0)
      let tempData = Object.assign({}, props);
      const propsData = reactive(tempData);
      const handleConfirm = () => {
        propsData.visible = false;
        context.emit("onConfirm");
      };
      const handleCancel = () => {
        propsData.visible = false;
        context.emit("onCancel");
      };
      return {
        ...toRefs(propsData),
        handleCancel,
        handleConfirm
      };
    },
  });
</script>

<style lang='scss' scoped>
  .modal-dialog {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 9999;
    transform: translateZ(9999px);
    letter-spacing: 0;
    background: rgba(0, 0, 0, 0.3);
  }

  .modal {
    position: absolute;
    top: 40%;
    left: 50%;
    z-index: 9000;
    width: 350px;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    background: #fff;
    border-radius: 4px;
    padding: 15px;
  }

  .modal-title {
    font-size: 16px;
    line-height: 25px;
    color: #030303;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
  }
  .hint {
    font-size: 13px;
    color: #e6a23c;
  }
  .modal-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    line-height: 21px;
    color: #5e5f64;
    padding: 10px 0;
    .lineBox {
      position: relative;
      width: 100%;
      height: 15px;
      background-color: #ebeef5;
      border-radius: 2px;
      .line {
        position: absolute;
        top: 0;
        left: 0;
        height: 15px;
        border-radius: 2px;
        background-color: #409eff;
        transition: width 0.5s;
      }
    }
    .num {
      text-align: right;
      width: 50px;
    }
  }

  .no-title-content {
    font-size: 16px;
    padding: 28px;
    color: #333333;
  }

  .modal-right {
    padding-right: 10px;
    width: 36px;
    background: #f2f2f2;
    color: rgba(0, 16, 38, 0.3);
    font-size: 12px;
    border-radius: 0 4px 4px 0;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
  }

  .split-line-top {
    height: 1px;
    transform: scale(1, 0.5);
    background: #e8eaef;
  }

  .modal-footer {
    width: 100%;
    display: flex;
    align-items: center;
    height: 52px;
    font-size: 16px;
    line-height: 52px;
    text-align: center;
  }

  .split-line-center {
    width: 1px;
    height: 100%;
    transform: scale(0.5, 1);
    background: #e8eaef;
  }

  .btn-cancel {
    flex: 1;
    color: #696d76;
  }

  .btn-confirm {
    position: relative;
    flex: 1;
    color: #409eff;
  }
</style>

 

index.js文件

import { createApp } from "vue";
import uploadProgressIndex from "./index.vue";

const UploadProgressPlugin = {};
let $vm;

const defaultsOptions = {
  title: "提示",
  content: "内容",
  hint: "",
  clickMaskToClose: false,
};

const initInstance = () => {
  const app = createApp(uploadProgressIndex);
  const container = document.createElement("div");
  $vm = app.mount(container);
  document.body.appendChild(container);
};

UploadProgressPlugin.install = (app) => {
  const uploadProgress = {
    show(options) {
      if (!$vm) initInstance();
      options = Object.assign({}, defaultsOptions, options);
      for (const i in options) {
        $vm[i] = options[i];
      }
      $vm.visible = true;
      return $vm;
    },
    close() {
      $vm.percentage = 0
      if ($vm) $vm.visible = false;
    },
  };
  app.config.globalProperties.$uploadProgress = uploadProgress;
};

export default UploadProgressPlugin;

 

 

标签:const,进度条,color,vm,height,width,background,vue3,上传
From: https://www.cnblogs.com/xzc666/p/17638217.html

相关文章

  • vue3第一章
    官方文档(中文版):https://vue3js.cn/docs/zh/视频:https://www.qiuzhi99.com/movies/vue3/1330.html语法对比:https://www.jianshu.com/p/4e7ba9e93402与2.x区别对比1.vue2和vue3双向数据绑定原理发生了改变vue2的双向数据绑定是利用ES5的一个apiObject.definePropert()对数......
  • java springboot excel 上传
    spring.http.multipart.location=/data/server/upload/spring.http.multipart.max-file-size=2048MBspring.http.multipart.max-request-size=2048MBimportjava.io.File;importjavax.servlet.MultipartConfigElement;importorg.springframework.beans.factory.ann......
  • [18章]Vue3+NestJS 全栈开发企业级管理后台
    点击下载:[18章]Vue3+NestJS全栈开发企业级管理后台提取码:zzbv Next.js是一个用于构建现代化React应用程序的框架。它强调性能、开发体验和SEO优化,是许多React开发者的首选。Next.js提供了许多功能,包括:服务器渲染:Next.js允许在服务器端渲染React应用程序,从而提高了应......
  • vue3 组合式 api 单文件组件写法
    1Vue3组合式API的基本原理和理念1.1Vue3中的CompositionAPIVue3中的CompositionAPI是一种新的编写组件逻辑的方式,它提供了更好的代码组织、类型推导、测试支持和复用性。相比于Vue2的OptionsAPI,CompositionAPI更加灵活和可扩展。在CompositionAPI中,我们使......
  • Vue3 常用组件库推荐
    Vue 作为一款深受广大群众喜欢的前端框架,拥有众多优秀的开源UI组件库,这里整理了一下供大家参考。这几套框架主要用于后台管理系统和移动端的制作,方便开发者快速开发。一、PC端UI库1.1ElementPlus官网地址:https://element-plus.org/zh-CN/Github:https://github.com/e......
  • 【Python-每日技巧】利用python进行文件上传
    有时候,需要上传文件到对方服务器,可以利用python实现在Python中,可以使用requests库来上传MultipartFile。以下是一个示例代码:importrequestsurl="http://example.com/upload"#替换为实际的上传接口地址#读取要上传的文件withopen("path/to/file.jpg","rb")asfi......
  • elementUI使用el-upload组件上传图片
    <el-form-itemlabel="上传图片":rules="[{required:true,message:'必须要上传图片',trigger:'blur'}]"prop="image"><el-upload:action=webSite......
  • 关于ios5上的浏览器无法上传图片的问题
    大家都知道ios5上的浏览器(包括safari)是无法上传附件的。这个是因为苹果公司并没有支持inputfile这个控件,在这个版本上。但是在ios6.0版本上就已经支持了inputfile控件。但是对 ios5用户如果想通过safari上传图片(比如想访问facebook,twitter网页版),怎么办呢。我推荐几种方法:方......
  • 漏洞复现-绿盟 NF下一代防火墙 任意文件上传漏洞
    漏洞描述:绿盟SSLVPN存在任意文件上传漏洞,攻击者通过发送特殊的请求包可以获取服务器权限,进行远程命令执行漏洞影响:绿盟SSLVPN网络测绘:app="NSFOCUS-下一代防火墙" 出现漏洞的端口为808112345678910POST/api/v1/device/bugsInfoHTTP......
  • JavaScript实现大文件上传
    ​ASP.NET上传文件用FileUpLoad就可以,但是对文件夹的操作却不能用FileUpLoad来实现。下面这个示例便是使用ASP.NET来实现上传文件夹并对文件夹进行压缩以及解压。ASP.NET页面设计:TextBox和Button按钮。 ​编辑TextBox中需要自己受到输入文件夹的路径(包含文件夹),通过Button......