|
|
@@ -0,0 +1,164 @@
|
|
|
+<template>
|
|
|
+ <!-- 上传 -->
|
|
|
+ <el-dialog title="导入文件上传" :visible.sync="dialogVisible" width="40%">
|
|
|
+ <el-form label-width="110px" class="zw-criterion">
|
|
|
+ <el-form-item label="选择文件">
|
|
|
+ <el-upload
|
|
|
+ class="avatar-uploader"
|
|
|
+ action="#"
|
|
|
+ :show-file-list="false"
|
|
|
+ :http-request="handlSuccess"
|
|
|
+ :before-upload="beforeUpload"
|
|
|
+ >
|
|
|
+ <!-- x -->
|
|
|
+ <el-button icon="el-icon-plus" size="small" type="primary"
|
|
|
+ >文件上传</el-button
|
|
|
+ >
|
|
|
+ <div slot="tip" class="el-upload__tip">
|
|
|
+ 只能上传excel文件,点击
|
|
|
+ <el-link
|
|
|
+ type="primary"
|
|
|
+ :underline="false"
|
|
|
+ @click="downLoadTemplate()"
|
|
|
+ >
|
|
|
+ 下载模板</el-link
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="上传列表">
|
|
|
+ <div class="imgs-box">
|
|
|
+ <p v-for="(item, index) in attaments" :key="index" class="imgs-p">
|
|
|
+ <span> {{ item.name }}</span>
|
|
|
+ <el-link @click="delFileList(index)" type="primary">删除</el-link>
|
|
|
+ </p>
|
|
|
+ <el-progress
|
|
|
+ v-if="progressVisible"
|
|
|
+ :percentage="percentage"
|
|
|
+ :status="uploadStatus"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button size="small" @click="dialogVisible = false">关 闭</el-button>
|
|
|
+ <el-button size="small" :loading="loading" @click="upload" type="primary"
|
|
|
+ >上 传</el-button
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+ import { batchImportPBom } from '@/api/system/file/index.js';
|
|
|
+ import { downLoadBom } from '@/api/system/file/index.js';
|
|
|
+
|
|
|
+ export default {
|
|
|
+ props: {
|
|
|
+ defModule: '',
|
|
|
+ categoryId: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //注册组件
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ showViewer: false, // 显示查看器
|
|
|
+ dialogVisible: false,
|
|
|
+ uploadShow: false,
|
|
|
+ module: '',
|
|
|
+ attaments: [], //上传文件
|
|
|
+ file: '',
|
|
|
+ percentage: 0, // 进度百分比 (0-100)
|
|
|
+ progressVisible: false, // 是否显示进度条
|
|
|
+ uploadStatus: '', // 进度条状态 (success/exception)
|
|
|
+ loading: false
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {},
|
|
|
+ methods: {
|
|
|
+ // handleProgress(event, file) {
|
|
|
+ // this.progressVisible = true;
|
|
|
+ // this.percentage = Math.floor(event.percent); // 四舍五入取整
|
|
|
+ // },
|
|
|
+
|
|
|
+ open() {
|
|
|
+ this.attaments = [];
|
|
|
+ this.module = '';
|
|
|
+ this.dialogVisible = true;
|
|
|
+ },
|
|
|
+ //删除附件
|
|
|
+ delFileList(index) {
|
|
|
+ this.attaments.splice(index, 1);
|
|
|
+ },
|
|
|
+ //上传限制
|
|
|
+ beforeUpload(file) {
|
|
|
+ const isLt10M = file.size / 1024 / 1024 < 10;
|
|
|
+ if (!isLt10M) {
|
|
|
+ this.$message.error('导入单文件大小不能超过 10MB!');
|
|
|
+ }
|
|
|
+ return isLt10M;
|
|
|
+ },
|
|
|
+ //图片上传
|
|
|
+ handlSuccess(param) {
|
|
|
+ this.file = param.file;
|
|
|
+ this.attaments.push(param.file);
|
|
|
+ },
|
|
|
+
|
|
|
+ downLoadTemplate() {
|
|
|
+ downLoadBom();
|
|
|
+ },
|
|
|
+
|
|
|
+ // 文件上传
|
|
|
+ async upload() {
|
|
|
+ if (this.attaments.length == 0) {
|
|
|
+ return this.$message.warning('文件不能为空!');
|
|
|
+ }
|
|
|
+ this.module = this.$props.defModule;
|
|
|
+ this.loading = true;
|
|
|
+
|
|
|
+ await batchImportPBom({
|
|
|
+ module: this.module,
|
|
|
+ multiPartFiles: this.attaments
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.loading = false;
|
|
|
+ }, 2000);
|
|
|
+
|
|
|
+ this.$message.success('上传成功!');
|
|
|
+ this.dialogVisible = false;
|
|
|
+ this.$emit('success');
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+ .zw-table-header {
|
|
|
+ float: right;
|
|
|
+ }
|
|
|
+
|
|
|
+ .imgs-box .imgs-p {
|
|
|
+ height: 30px;
|
|
|
+ background: #f0f3f3;
|
|
|
+ line-height: 30px;
|
|
|
+ width: 372px;
|
|
|
+ margin-bottom: 5px;
|
|
|
+ padding: 0 10px;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ }
|
|
|
+ .zw-criterion-normal {
|
|
|
+ padding: 20px 0 0 0;
|
|
|
+ }
|
|
|
+ .el-main {
|
|
|
+ overflow: hidden;
|
|
|
+ }
|
|
|
+</style>
|