index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <script>
  2. export default {
  3. name:'BatchImport',
  4. props:{
  5. disabled:{
  6. type:Boolean,
  7. default:false,
  8. },
  9. limit:{
  10. type:Number,
  11. default:1,
  12. },
  13. fileType:{
  14. type:Array,
  15. default:()=>['xls', 'xlsx'],
  16. },
  17. size:{
  18. type:String,
  19. default:'mini',
  20. },
  21. isShowTip:{
  22. type:Boolean,
  23. default:true,
  24. },
  25. isTemplate:{
  26. type:Boolean,
  27. default:true,
  28. },
  29. fileSize: {
  30. type: Number,
  31. default: 100,
  32. },
  33. },
  34. computed:{
  35. tips:{
  36. get(){
  37. // this.accept.
  38. },
  39. set(){},
  40. },
  41. // 是否显示提示
  42. showTip() {
  43. return this.isShowTip && (this.fileType || this.fileSize);
  44. },
  45. },
  46. data(){
  47. return {
  48. title:'批量导入',
  49. visible:false,
  50. loading:false,
  51. fileList:[],
  52. }
  53. },
  54. methods:{
  55. // 确认上传
  56. async submitUpload(){
  57. },
  58. // 模板下载
  59. async templateDownload(){
  60. // 放父组件
  61. // this.download('/system/material/download', {}, `物料基本信息模板.xlsx`);
  62. },
  63. //
  64. beforeClose(done){
  65. // 关闭前清空
  66. done();
  67. },
  68. // 预览
  69. handlePreview(){},
  70. // 移除
  71. handleRemove(file, fileList){
  72. this.fileList = fileList;
  73. },
  74. // 文件改变
  75. onChange(file, fileList){
  76. this.fileList = fileList;
  77. },
  78. // 取消
  79. cancal(){
  80. this.visible = false;
  81. },
  82. },
  83. created(){},
  84. }
  85. </script>
  86. <template>
  87. <el-button :disabled="disabled">
  88. {{ title }}
  89. <el-dialog
  90. :title="title"
  91. :visible.sync="visible"
  92. v-loading="loading"
  93. width="35%"
  94. center
  95. :before-close="beforeClose"
  96. >
  97. <el-upload
  98. ref="upload"
  99. :accept="accept"
  100. action="#"
  101. :on-preview="handlePreview"
  102. :on-remove="handleRemove"
  103. :file-list="fileList"
  104. :auto-upload="false"
  105. :on-change="onChange"
  106. :limit="limit"
  107. append-to-body
  108. >
  109. <el-button
  110. slot="trigger"
  111. :size="size"
  112. type="primary"
  113. >选取文件</el-button>
  114. <el-button
  115. v-if="isTemplate"
  116. style="margin-left: 10px;"
  117. :size="size"
  118. type="success"
  119. @click="templateDownload"
  120. >下载模板</el-button>
  121. <div slot="tip" class="el-upload__tip" v-if="isShowTip">
  122. 请上传
  123. <template v-if="fileSize">
  124. 大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b>
  125. </template>
  126. <template v-if="fileType">
  127. 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b>
  128. </template>
  129. </div>
  130. </el-upload>
  131. <div slot="footer" class="dialog-footer">
  132. <el-button @click="cancal">取 消</el-button>
  133. <el-button type="primary" @click="submitUpload">确 定</el-button>
  134. </div>
  135. </el-dialog>
  136. </el-button>
  137. </template>