阿里官方使用说明

前端组件使用方法

  1. <!-- excel导入弹窗 -->
  2. <NewByXlsx v-if="newByXlsxDialog.visible" @close="newByXlsxClose" @refresh="getList"
  3. :title="newByXlsxDialog.title" />
  1. import NewByXlsx from './NewByxlsx.vue'
  2. //************
  3. components: { NewByXlsx },
  4. //************
  5. // 用户导入
  6. newByXlsxDialog: {
  7. visible: false,
  8. title: '用户信息-导入',
  9. },
  10. //************
  11. // excel导入信息
  12. newByXlsxOpen() {
  13. this.newByXlsxDialog.visible = true
  14. },
  15. newByXlsxClose() { //关闭
  16. this.newByXlsxDialog.visible = false
  17. },

后端接口

  1. /**
  2. * 批量导入
  3. *
  4. * @param keyShops
  5. * @return
  6. */
  7. @PutMapping("/upload")
  8. R<String> upload(@RequestBody List<KeyShop> keyShops) {
  9. return keyShopService.uploadByXlsx(keyShops);
  10. }
  1. /**
  2. * 批量导入
  3. *
  4. * @param keyShops
  5. * @return
  6. */
  7. @Override
  8. public R<String> uploadByXlsx(List<KeyShop> keyShops) {
  9. Integer successNum = 0; //成功的数量
  10. Integer failedNum = 0; //失败的数量
  11. if (CollectionUtils.isNotEmpty(keyShops)) {
  12. for (KeyShop keyShop : keyShops) {
  13. if (save(keyShop)) {
  14. successNum++; //成功计数
  15. } else {
  16. failedNum++; //失败计数
  17. }
  18. }
  19. }
  20. if (failedNum > 0) {
  21. return R.error("导入成功 " + successNum + " 条记录;失败 " + failedNum + " 条记录。");
  22. } else {
  23. return R.success("导入成功 " + successNum + " 条记录");
  24. }
  25. }

附NewByXlsx组件

  1. <template>
  2. <div>
  3. <el-dialog v-dialogDrag :title="title" visible width="600px"
  4. :before-close="beforeClose">
  5. <!-- 弹窗页面内容 -->
  6. <!-- Excel文件转JSON数据 -->
  7. <div>注:请使用导出用户的模板导入用户数据</div>
  8. <ExcelToJSON @data="usersJsonData"></ExcelToJSON>
  9. <span slot="footer" class="dialog-footer">
  10. <el-button size="default" @click="beforeClose">取消</el-button>
  11. <el-button size="default" type="primary" @click="onSubmit">确定</el-button>
  12. </span>
  13. </el-dialog>
  14. </div>
  15. </template>
  16. <script>
  17. import ExcelToJSON from '@/pages/models/excel/ExcelToJSON.vue'
  18. export default {
  19. components: { ExcelToJSON },
  20. props: {
  21. title: {
  22. type: String,
  23. default: ''
  24. }
  25. },
  26. data() {
  27. return {
  28. data: [],
  29. }
  30. },
  31. methods: {
  32. usersJsonData(data) {
  33. this.data = data.map(item => {
  34. let { 帐号: user_accout,
  35. 姓名: user_name,
  36. 地址: address,
  37. 电话: phone,
  38. 邮箱: email,
  39. 微信: weixin,
  40. QQ: qq } = item
  41. return { user_accout, user_name, address, phone, email, weixin, qq }
  42. })
  43. console.log('接受到的json信息', this.data);
  44. },
  45. async onSubmit() {
  46. //检查是否有数据
  47. if (!this.data || this.data.length === 0) {
  48. this.$message.warning(`没有数据`)
  49. return
  50. }
  51. let res = await this.$api.setting.usersUp(this.data)
  52. if (res.code === 1) {
  53. this.$message.success(res.msg)
  54. } else {
  55. this.$message.warning(res.msg)
  56. }
  57. this.$emit('refresh') //触发refresh事件
  58. this.$emit('close') //触发close事件
  59. },
  60. beforeClose() {
  61. this.$emit('close')
  62. }
  63. }
  64. }
  65. </script>