|
|
@@ -0,0 +1,174 @@
|
|
|
+<!-- 资料导入 -->
|
|
|
+<template>
|
|
|
+ <hc-new-dialog v-model="dataModal" title="资料导入" @close="closeModal">
|
|
|
+ <div style="position: relative;">
|
|
|
+ <el-upload
|
|
|
+ ref="dialogUploadRef" :headers="getHeader()" drag
|
|
|
+ action="/api/blade-manager/wbsTreeContract/importTree"
|
|
|
+ :data="{ pkeyId: pKeyIdData }"
|
|
|
+ :on-success="handleSuccess" :on-error="handleError" accept=".xls,.xlsx"
|
|
|
+ :auto-upload="false"
|
|
|
+ :limit="1"
|
|
|
+ :on-exceed="handleExceed"
|
|
|
+ :before-upload="beforeUpload"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-change="handleChange"
|
|
|
+ >
|
|
|
+ <div class="mt-24px text-black">将文件拖动到此处,<span class="text-blue">或点击上传</span></div>
|
|
|
+ <div class="mt-8px text-12px">支持的文件格式:.xls,.xlsx</div>
|
|
|
+ </el-upload>
|
|
|
+ <!-- 自定义文件列表 -->
|
|
|
+ <div v-if="fileList.length > 0" class="upload-file-list mt-4">
|
|
|
+ <div v-for="file in fileList" :key="file.uid" class="mb-2 flex items-center justify-between border rounded p-2">
|
|
|
+ <div class="flex items-center">
|
|
|
+ <HcIcon name="file-excel" class="mr-2 text-green-500" />
|
|
|
+ <span>{{ file.name }}</span>
|
|
|
+ </div>
|
|
|
+ <el-button type="danger" link @click="handleRemove(file)">
|
|
|
+ <HcIcon name="delete" />
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="mt-2 text-right">
|
|
|
+ <el-button hc-btn type="primary" :loading="downLoadTemplateLoading" @click="downLoadTemplate">
|
|
|
+ <HcIcon name="download-2" />
|
|
|
+ 导入模板
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <template #footer>
|
|
|
+ <el-button @click="divisionImportDialog = false">取消</el-button>
|
|
|
+ <el-button type="primary" :loading="confirmLoading" @click="confirmTap">确认上传</el-button>
|
|
|
+ </template>
|
|
|
+ </hc-new-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { nextTick, ref, watch } from 'vue'
|
|
|
+import { downloadBlob, getArrValue, getObjValue, isNullES } from 'js-fast-way'
|
|
|
+import { useAppStore } from '~src/store'
|
|
|
+import { HcDelMsg, getHeader } from 'hc-vue3-ui'
|
|
|
+
|
|
|
+import wbsApi from '~api/data-fill/wbs'
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ dataModal: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false,
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+})
|
|
|
+
|
|
|
+//事件
|
|
|
+const emit = defineEmits(['close', 'save'])
|
|
|
+const dataModal = defineModel('modelValue', {
|
|
|
+ default: false,
|
|
|
+})
|
|
|
+const closeModal = ()=>{
|
|
|
+ dataModal.value = false
|
|
|
+
|
|
|
+ emit('close')
|
|
|
+}
|
|
|
+const useAppState = useAppStore()
|
|
|
+const contractId = ref(useAppState.getContractId)
|
|
|
+const projectId = ref(useAppState.getProjectId)
|
|
|
+
|
|
|
+
|
|
|
+//上传文件
|
|
|
+const dialogUploadRef = ref(null)
|
|
|
+const pKeyIdData = ref('')
|
|
|
+// 文件类型验证
|
|
|
+const beforeUpload = (file) => {
|
|
|
+ const extension = file.name.split('.').pop().toLowerCase()
|
|
|
+ if (!['xls', 'xlsx'].includes(extension)) {
|
|
|
+ window.$message.error('仅支持上传 .xls 或 .xlsx 格式的表格文件')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+// 添加以下数据和方法
|
|
|
+const fileList = ref([])
|
|
|
+
|
|
|
+const handleChange = (file, files) => {
|
|
|
+ fileList.value = [file] // 由于限制为1个文件,直接替换
|
|
|
+}
|
|
|
+
|
|
|
+const handleRemove = (file) => {
|
|
|
+ fileList.value = fileList.value.filter(item => item.uid !== file.uid)
|
|
|
+ dialogUploadRef.value?.clearFiles()
|
|
|
+}
|
|
|
+
|
|
|
+const handleExceed = (files) => {
|
|
|
+ dialogUploadRef.value.clearFiles()
|
|
|
+ const file = files[0]
|
|
|
+ dialogUploadRef.value.handleStart(file)
|
|
|
+}
|
|
|
+//上传成功
|
|
|
+
|
|
|
+const confirmLoading = ref(false)
|
|
|
+const handleSuccess = (res) => {
|
|
|
+
|
|
|
+ confirmLoading.value = false
|
|
|
+ if (res.code === 200) {
|
|
|
+ window.$message.success(res.msg || '上传成功')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ window.$message.error(res.msg || '上传失败')
|
|
|
+ nextTick(()=>{
|
|
|
+ fileList.value = []
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//上传失败
|
|
|
+const handleError = (error) => {
|
|
|
+ confirmLoading.value = false
|
|
|
+ const { msg } = !isNullES(error.message) ? JSON.parse(error.message) : {}
|
|
|
+ if (isNullES(msg)) {
|
|
|
+ window.$message.error('上传失败')
|
|
|
+ } else {
|
|
|
+ window.$message.error(msg)
|
|
|
+ }
|
|
|
+ fileList.value = []
|
|
|
+
|
|
|
+}
|
|
|
+const confirmTap = async ()=>{
|
|
|
+ if (!fileList.value.length) {
|
|
|
+ window.$message.warning('请先选择文件')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ confirmLoading.value = true
|
|
|
+ dialogUploadRef.value.submit()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+//导入模板
|
|
|
+const downLoadTemplate = async ()=>{
|
|
|
+ downLoadTemplateLoading.value = true
|
|
|
+ const { error, disposition, res, msg } = await wbsApi.downloadGongChengExcel()
|
|
|
+ downLoadTemplateLoading.value = false
|
|
|
+ if (!error) {
|
|
|
+ if (disposition) {
|
|
|
+ downloadBlob(res, disposition)
|
|
|
+ } else {
|
|
|
+ window.$message?.error(msg || '数据异常')
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+const downLoadTemplateLoading = ref(false)
|
|
|
+
|
|
|
+//获取两棵树的数据
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang='scss' scoped>
|
|
|
+
|
|
|
+</style>
|
|
|
+
|