fei
2025-09-16 882c04207fdc667b0be8dc347e320d0414eedb94
src/views/archivePlaceName/index.vue
@@ -58,6 +58,35 @@
          v-hasPermi="['system:name:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExportTemplate"
          v-hasPermi="['system:name:export']"
        >导入模板下载</el-button>
      </el-col>
             <el-col :span="1.5">
        <el-upload
          action=""
          class="upload-demo"
          :show-file-list="false"
          :http-request="handleImport"
              accept=".xlsx,.xls"
        >
          <el-button size="mini"   type="primary"
                     plain
                     icon="el-icon-top">导入</el-button>
        </el-upload>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
@@ -113,7 +142,7 @@
</template>
<script>
import { listPlaceName, getName, delName, addName, updateName } from "@/api/system/placeName"
import { listPlaceName, enload,getName, delName, addName, updateName } from "@/api/system/placeName"
export default {
  name: "Name",
@@ -246,7 +275,49 @@
      this.download('/system/placeName/export', {
        ...this.queryParams
      }, `name_${new Date().getTime()}.xlsx`)
    },
             /** 导入模板下载操作*/
    handleExportTemplate()
    {
     this.download('/system/placeName/model', {
      }, `placeName_${new Date().getTime()}.xlsx`)
    },
      /** 导入操作*/
    async handleImport({file}){
   // 检查文件类型是否为xlsx
  // if (!params.file.name.endsWith('.xlsx')) {
  //   this.$message.error('请上传.xlsx格式的文件');
  //   return;
  // }
  const formData = new FormData();
  formData.append('file', file);
  console.log(file)
  // 显示加载中状态
  const loading = this.$loading({
    lock: true,
    text: '上传中...',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)'
  });
  enload(formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }).then(response => {
    loading.close();
    this.$message.success('导入成功');
    this.getList();
  }).catch(error => {
    loading.close();
    this.$message.error('导入失败: ' + (error.message || '未知错误'));
  });
    }
  }
}
</script>