ImportUser.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('system.text_478')}}</div>
  4. <div slot="body">
  5. <a-form
  6. :form="form.fc">
  7. <a-alert type="warning" class="mb-2">
  8. <template v-slot:message>
  9. <div class="messages-list">
  10. <p>{{ $t('system.text_501') }}<a-button type="link" @click="handleDownloadTemplate">{{$t('system.text_502')}}</a-button></p>
  11. <p>{{ $t('system.text_503') }}</p>
  12. <p>{{ $t('system.text_504') }}</p>
  13. </div>
  14. </template>
  15. </a-alert>
  16. <div class="pt-3 pb-3">
  17. <a-form-item>
  18. <a-upload-dragger
  19. v-decorator="decorators.fileList"
  20. :beforeUpload="beforeUpload"
  21. :fileList="fileList"
  22. :accept="accept"
  23. :remove="handleRemove">
  24. <div class="pt-3 pb-3">
  25. <p class="ant-upload-drag-icon"><a-icon type="inbox" /></p>
  26. <p class="ant-upload-text">{{$t('system.text_505')}}</p>
  27. <p class="ant-upload-hint">{{$t('system.text_506')}}</p>
  28. </div>
  29. </a-upload-dragger>
  30. </a-form-item>
  31. </div>
  32. </a-form>
  33. </div>
  34. <div slot="footer">
  35. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  36. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  37. </div>
  38. </base-dialog>
  39. </template>
  40. <script>
  41. import DialogMixin from '@/mixins/dialog'
  42. import WindowsMixin from '@/mixins/windows'
  43. import { download } from '@/utils/utils'
  44. export default {
  45. name: 'UserImprotDialog',
  46. mixins: [DialogMixin, WindowsMixin],
  47. data () {
  48. return {
  49. accept: '.xlsx',
  50. fileList: [],
  51. loading: false,
  52. form: {
  53. fc: this.$form.createForm(this),
  54. },
  55. decorators: {
  56. fileList: ['fileList', {
  57. rules: [
  58. { required: true, message: this.$t('system.text_507') },
  59. ],
  60. }],
  61. },
  62. }
  63. },
  64. methods: {
  65. beforeUpload (file) {
  66. this.fileList = [file]
  67. return false
  68. },
  69. handleClearFile () {
  70. this.fileList = []
  71. },
  72. handleRemove () {
  73. this.handleClearFile()
  74. },
  75. handleDownloadTemplate () {
  76. this.$http({
  77. method: 'GET',
  78. url: '/v1/downloads/BatchUserRegister',
  79. responseType: 'blob',
  80. }).then(response => {
  81. download(response.data, 'user_template.xlsx')
  82. })
  83. },
  84. async handleConfirm () {
  85. try {
  86. if (!this.fileList || this.fileList.length === 0) {
  87. this.form.fc.setFieldsValue({
  88. fileList: undefined,
  89. })
  90. }
  91. this.loading = true
  92. await this.form.fc.validateFields()
  93. const formData = new FormData()
  94. formData.append('users', new Blob([this.fileList[0]], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }))
  95. formData.append('action', 'BatchUserRegister')
  96. await this.$http({
  97. url: '/v1/uploads/BatchUserRegister',
  98. method: 'post',
  99. processData: false,
  100. data: formData,
  101. timeout: 0,
  102. })
  103. this.params.refresh()
  104. this.cancelDialog()
  105. } catch (err) {
  106. throw err
  107. } finally {
  108. this.loading = false
  109. }
  110. },
  111. },
  112. }
  113. </script>
  114. <style lang="less" scoped>
  115. .messages-list p{
  116. margin-bottom: 2px;
  117. }
  118. </style>