|
@@ -5,6 +5,8 @@
|
|
|
|
|
|
<el-row :gutter="10" class="mb10">
|
|
|
<div>
|
|
|
+ <el-button type="primary" size="mini" @click="mbDownload">模板下载</el-button>
|
|
|
+ <el-button type="primary" size="mini" @click="importMb">导入</el-button>
|
|
|
<el-button type="primary" size="mini" plain @click="addClassify">新增</el-button>
|
|
|
<el-button type="primary" size="mini" plain @click="editClassify">修改</el-button>
|
|
|
<el-button type="primary" size="mini" plain @click="refreshData">{{refreshName ? '全部分类': '过滤停用'}}</el-button>
|
|
@@ -140,10 +142,10 @@
|
|
|
<el-row :gutter="20">
|
|
|
<el-col :span="24">
|
|
|
<el-form-item v-if="!disable">
|
|
|
- <el-button type="primary" @click="submitForm('ruleForm')"
|
|
|
+ <el-button size="mini" type="primary" @click="submitForm('ruleForm')"
|
|
|
>保存</el-button
|
|
|
>
|
|
|
- <el-button @click="resetForm('ruleForm')">取消</el-button>
|
|
|
+ <el-button size="mini" @click="resetForm('ruleForm')">取消</el-button>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
@@ -151,22 +153,71 @@
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
</el-card>
|
|
|
+
|
|
|
+ <!-- 导入对话框 -->
|
|
|
+ <el-dialog title="数据导入" :visible.sync="upload.open" width="400px">
|
|
|
+ <el-upload
|
|
|
+ ref="upload"
|
|
|
+ :limit="1"
|
|
|
+ accept=".xlsx, .xls"
|
|
|
+ :headers="upload.headers"
|
|
|
+ :action="upload.url + '?updateSupport=' + upload.updateSupport"
|
|
|
+ :disabled="upload.isUploading"
|
|
|
+ :on-progress="handleFileUploadProgress"
|
|
|
+ :on-success="handleFileSuccess"
|
|
|
+ :on-error="errorFile"
|
|
|
+ :auto-upload="false"
|
|
|
+ drag
|
|
|
+ >
|
|
|
+ <i class="el-icon-upload"></i>
|
|
|
+ <div class="el-upload__text">
|
|
|
+ 将文件拖到此处,或
|
|
|
+ <em>点击上传</em>
|
|
|
+ </div>
|
|
|
+ <!-- <div class="el-upload__tip" slot="tip">
|
|
|
+ <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
|
|
|
+ </div> -->
|
|
|
+ <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
|
|
|
+ </el-upload>
|
|
|
+ <div slot="footer">
|
|
|
+ <el-button size="mini" type="primary" @click="submitFile">确 定</el-button>
|
|
|
+ <el-button size="mini" @click="upload.open = false">取 消</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+// 导入的token
|
|
|
+import { getToken } from "@/utils/auth";
|
|
|
import {
|
|
|
getTree,
|
|
|
getDetail,
|
|
|
add,
|
|
|
delClassify,
|
|
|
edit,
|
|
|
+ downLoadClassify,
|
|
|
} from "@/api/classify/basic";
|
|
|
export default {
|
|
|
name: "classify",
|
|
|
dicts: ["material_enable", "sys_assist_condtion"],
|
|
|
data() {
|
|
|
return {
|
|
|
+ // 导入参数
|
|
|
+ upload: {
|
|
|
+ // 是否显示弹出层(导入)
|
|
|
+ open: false,
|
|
|
+ // 弹出层标题(导入)
|
|
|
+ title: "数据导入",
|
|
|
+ // 是否禁用上传
|
|
|
+ isUploading: false,
|
|
|
+ // 是否更新已经存在的用户数据
|
|
|
+ updateSupport: 1,
|
|
|
+ // 设置上传的请求头部
|
|
|
+ headers: { Authorization: "Bearer " + getToken() },
|
|
|
+ // 上传的地址
|
|
|
+ url: process.env.VUE_APP_BASE_API + "/system/classify/import"
|
|
|
+ },
|
|
|
loading: false,
|
|
|
filterText: "",
|
|
|
data: [],
|
|
@@ -406,6 +457,56 @@ export default {
|
|
|
this.getTreeData();
|
|
|
}
|
|
|
},
|
|
|
+ // 模板下载
|
|
|
+ mbDownload() {
|
|
|
+ this.$modal.loading("正在下载模板,请稍后...");
|
|
|
+ downLoadClassify({}).then(res => {
|
|
|
+ this.$modal.closeLoading();
|
|
|
+ const blob = new Blob([res], {
|
|
|
+ type: "application/vnd.ms-excel;charset=UTF-8",
|
|
|
+ });// 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
|
|
|
+ const downloadElement = document.createElement("a"); //创建a标签
|
|
|
+ const href = window.URL.createObjectURL(blob); // 创建下载的链接
|
|
|
+ // var temp = res.headers["content-disposition"];
|
|
|
+ // var fileName = decodeURIComponent(temp.split("filename=")[1]); // 中文需要转码 (前端乱码)
|
|
|
+ // var name = fileName.split(";")[0]; //切割成文件名
|
|
|
+ downloadElement.href = href; //下载地址
|
|
|
+ downloadElement.download = '物料基本分类模板'+ this.parseTime(new Date().getTime()) + ".xlsx"; // 下载后文件名
|
|
|
+ document.body.appendChild(downloadElement);
|
|
|
+ downloadElement.click(); // 点击下载
|
|
|
+ document.body.removeChild(downloadElement); // 下载完成移除元素
|
|
|
+ window.URL.revokeObjectURL(href); // 释放blob对象
|
|
|
+ this.download.open = false
|
|
|
+ }).catch(err => {
|
|
|
+ this.$modal.closeLoading();
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 文件导入
|
|
|
+ importMb() {
|
|
|
+ this.upload.open = true
|
|
|
+ },
|
|
|
+ // 文件上传中处理
|
|
|
+ handleFileUploadProgress(event, file, fileList) {
|
|
|
+ this.upload.isUploading = true;
|
|
|
+ this.$modal.loading("正在导入数据,请稍后...");
|
|
|
+ },
|
|
|
+ // 文件上传成功处理
|
|
|
+ handleFileSuccess(response, file, fileList) {
|
|
|
+ this.$modal.closeLoading();
|
|
|
+ this.upload.open = false;
|
|
|
+ this.upload.isUploading = false;
|
|
|
+ this.$refs.upload.clearFiles();
|
|
|
+ this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
|
|
|
+ this.getTreeData();
|
|
|
+ },
|
|
|
+ errorFile(err) {
|
|
|
+ this.$modal.closeLoading();
|
|
|
+ this.$modal.notifyError("文件已变动,请重新上传");
|
|
|
+ },
|
|
|
+ // 提交上传文件
|
|
|
+ submitFile() {
|
|
|
+ this.$refs.upload.submit();
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|