导出

前端

$nextTick 让前面的事情执行完

  1. <code-type-dialog
  2. :visible.sync="dialogVisible"
  3. title="选择生成类型"
  4. :show-file-name="showFileName"
  5. @confirm="generate"
  6. />
  1. data(){
  2. return {
  3. dialogVisible: false,
  4. showFileName: false,
  5. }
  6. },
  7. handleExport() {
  8. // 导出
  9. this.download('system/operlog/export', {
  10. ...this.queryParams
  11. }, `operlog_${new Date().getTime()}.xlsx`)
  12. },
  13. download() {
  14. this.dialogVisible = true
  15. this.showFileName = true
  16. this.operationType = 'download'
  17. },

后端

导入

前端

  1. <!-- 用户导入对话框 -->
  2. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  3. <el-upload
  4. ref="upload"
  5. :limit="1"
  6. accept=".xlsx, .xls"
  7. :headers="upload.headers"
  8. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  9. :disabled="upload.isUploading"
  10. :on-progress="handleFileUploadProgress"
  11. :on-success="handleFileSuccess"
  12. :auto-upload="false"
  13. drag
  14. >
  15. <i class="el-icon-upload"></i>
  16. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  17. <div class="el-upload__tip text-center" slot="tip">
  18. <div class="el-upload__tip" slot="tip">
  19. <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
  20. </div>
  21. <span>仅允许导入xls、xlsx格式文件。</span>
  22. <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
  23. </div>
  24. </el-upload>
  25. <div slot="footer" class="dialog-footer">
  26. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  27. <el-button @click="upload.open = false">取 消</el-button>
  28. </div>
  29. </el-dialog>

后端

  1. @Log(title = "用户管理", businessType = BusinessType.IMPORT)
  2. @PreAuthorize(hasPermi = "system:user:import")
  3. @PostMapping("/importData")
  4. public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
  5. ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class);
  6. List<SysUser> userList = util.importExcel(file.getInputStream());
  7. String operName = SecurityUtils.getUserId()+"";
  8. String message = userService.importUser(userList, updateSupport, operName);
  9. return AjaxResult.success(message);
  10. }