|
@@ -0,0 +1,162 @@
|
|
|
+<template>
|
|
|
+ <CzrDialog
|
|
|
+ :show="show"
|
|
|
+ title="Excel导入许可范围"
|
|
|
+ @onClose="$emit('update:show', false)"
|
|
|
+ @onSubmit="onSubmit"
|
|
|
+ width="auto"
|
|
|
+ :loading="state.loading"
|
|
|
+ >
|
|
|
+ <div class="__normal-form">
|
|
|
+ <CzrForm ref="ref_form" label-width="80px">
|
|
|
+ <CzrFormColumn
|
|
|
+ :span="24"
|
|
|
+ label="下载模板"
|
|
|
+ v-model:param="state.tempVal"
|
|
|
+ >
|
|
|
+ <template #czr>
|
|
|
+ <div class="btn __hover" @click="onDownload">点击下载导入模板</div>
|
|
|
+ </template>
|
|
|
+ </CzrFormColumn>
|
|
|
+ <CzrFormColumn
|
|
|
+ :span="24"
|
|
|
+ label="上传文件"
|
|
|
+ v-model:param="state.tempVal"
|
|
|
+ >
|
|
|
+ <template #czr>
|
|
|
+ <el-upload
|
|
|
+ ref="ref_upload"
|
|
|
+ :limit="1"
|
|
|
+ accept=".xlsx, .xls"
|
|
|
+ :headers="upload.headers"
|
|
|
+ :action="upload.url"
|
|
|
+ :disabled="upload.isUploading"
|
|
|
+ :on-progress="() => (upload.isUploading = true)"
|
|
|
+ :on-success="handleFileSuccess"
|
|
|
+ :before-upload="handleBeforeUpload"
|
|
|
+ :auto-upload="false"
|
|
|
+ drag
|
|
|
+ >
|
|
|
+ <el-icon class="el-icon--upload"><UploadFilled /></el-icon>
|
|
|
+ <div class="el-upload__text">
|
|
|
+ 将文件拖到此处,或<em style="color: var(--czr-main-color)"
|
|
|
+ >点击上传</em
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </el-upload>
|
|
|
+ </template>
|
|
|
+ </CzrFormColumn>
|
|
|
+ </CzrForm>
|
|
|
+ </div>
|
|
|
+ </CzrDialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import {
|
|
|
+ computed,
|
|
|
+ getCurrentInstance,
|
|
|
+ inject,
|
|
|
+ nextTick,
|
|
|
+ reactive,
|
|
|
+ ref,
|
|
|
+ watch,
|
|
|
+} from 'vue'
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
+import { UploadFilled } from '@element-plus/icons-vue'
|
|
|
+
|
|
|
+const emit = defineEmits(['update:show', 'refresh'])
|
|
|
+const { proxy } = getCurrentInstance()
|
|
|
+const props = defineProps({
|
|
|
+ show: { default: false },
|
|
|
+ transfer: {},
|
|
|
+})
|
|
|
+const state: any = reactive({
|
|
|
+ loading: false,
|
|
|
+ tempVal: '',
|
|
|
+ uploaded: false,
|
|
|
+})
|
|
|
+const ref_upload = ref()
|
|
|
+/*** 用户导入参数 */
|
|
|
+const upload = reactive({
|
|
|
+ // 是否禁用上传
|
|
|
+ isUploading: false,
|
|
|
+ // 设置上传的请求头部
|
|
|
+ headers: {
|
|
|
+ 'Blade-Auth': inject('token'),
|
|
|
+ },
|
|
|
+ // 上传的地址
|
|
|
+ url: '/business-model-api/api/blade-dcms/hazardouschemicalscatalog/parseBusinessScope',
|
|
|
+})
|
|
|
+watch(
|
|
|
+ () => props.show,
|
|
|
+ (n) => {
|
|
|
+ if (n) {
|
|
|
+ state.uploaded = false
|
|
|
+ upload.isUploading = false
|
|
|
+ state.tempVal = ''
|
|
|
+ nextTick(() => {
|
|
|
+ ref_upload.value.clearFiles()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+)
|
|
|
+const onDownload = () => {
|
|
|
+ window.open(
|
|
|
+ 'http://120.226.134.7:8100/cdn/xlsx/businessScopeImport.xlsx',
|
|
|
+ '_blank',
|
|
|
+ )
|
|
|
+}
|
|
|
+const onSubmit = () => {
|
|
|
+ ref_upload.value.submit()
|
|
|
+}
|
|
|
+const handleBeforeUpload = () => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ ElMessageBox.confirm(`请确认是否导入?`, '提示', {
|
|
|
+ confirmButtonText: '是',
|
|
|
+ cancelButtonText: '否',
|
|
|
+ type: 'warning',
|
|
|
+ } as any)
|
|
|
+ .then(() => {
|
|
|
+ resolve(true)
|
|
|
+ })
|
|
|
+ .catch(() => {})
|
|
|
+ })
|
|
|
+}
|
|
|
+/** 文件上传成功处理 */
|
|
|
+const handleFileSuccess = (res, file, fileList) => {
|
|
|
+ console.log(res, file, fileList)
|
|
|
+ ElMessageBox.confirm(
|
|
|
+ `成功导入 <span style="color: var(--czr-success-color)">${res.data.data.length}</span> 条数据!`,
|
|
|
+ '导入结果',
|
|
|
+ {
|
|
|
+ dangerouslyUseHTMLString: true,
|
|
|
+ showClose: false,
|
|
|
+ showCancelButton: false,
|
|
|
+ },
|
|
|
+ ).then(() => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ if (res.data.success) {
|
|
|
+ emit('update:show', false)
|
|
|
+ emit('refresh', res.data.data)
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.data.errorMsg)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.btn {
|
|
|
+ background-color: var(--czr-main-color);
|
|
|
+ color: #ffffff;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ padding: 0 6px;
|
|
|
+ border-radius: 4px;
|
|
|
+ flex: none !important;
|
|
|
+}
|
|
|
+</style>
|