importFile.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div>
  3. <!-- 按钮类型 -->
  4. <el-button type="primary" size="small" @click="dialogUploadVisible = true">{{$t('导入值')}}</el-button>
  5. <el-dialog :title="$t('文件上传')" class="import-panel" :visible.sync="dialogUploadVisible" width="500px" append-to-body :close-on-click-modal="false" :show-close="false" :before-close="clearFiles">
  6. <div slot="title"></div>
  7. <div style="background:#f1f2f3" class="my-tabs" >
  8. <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
  9. <!-- <el-tab-pane :label="$t('导入经销商线索')" name="first"></el-tab-pane> -->
  10. <el-tab-pane :label="$t(`导入序列号模板`)" name="second"></el-tab-pane>
  11. </el-tabs>
  12. </div>
  13. <div style="padding:20px">
  14. <el-upload
  15. style="width:100%"
  16. ref="my-upload"
  17. class="upload-demo normal-margin"
  18. :accept="accept"
  19. action="#"
  20. :auto-upload="false"
  21. :show-file-list="false"
  22. :on-change="handleChange"
  23. drag
  24. multiple>
  25. <i class="el-icon-upload"></i>
  26. <div class="el-upload__text">{{$t('将文件拖到此处,或') + ' '}}<em>{{$t('点击上传')}}</em></div>
  27. </el-upload>
  28. <div class="progress_panel" v-for="file in filelist" :key="file.uid">
  29. <img v-if="file.type === 'DOC' || file.type === 'DOCX'" width="30" src="../../../../../assets/file_icons/word.png"
  30. alt="">
  31. <img v-else-if="file.type === 'PDF'" width="30" src="../../../../../assets/file_icons/PDF.png" alt="">
  32. <img v-else-if="file.type === 'MP4' || file.type === 'AVI'" width="30" src="../../../../../assets/file_icons/video.png"
  33. alt="">
  34. <img v-else-if="file.type === 'XLS' || file.type === 'XLSX'" width="30" src="../../../../../assets/file_icons/excel.png"
  35. alt="">
  36. <img v-else-if="file.type === 'PNG' || file.type === 'JPG'|| file.type === 'JPEG'" width="30"
  37. src="../../../../../assets/file_icons/image.png" alt="">
  38. <img v-else-if="file.type === 'PPT' || file.type === 'PPTX'" width="30" src="../../../../../assets/file_icons/PPT.png"
  39. alt="">
  40. <img v-else width="30" src="../../../../../assets/file_icons/unknow.png" alt="">
  41. <div>
  42. <p v-if="file.progress === 100" style="float:right"><span style="color:#67C23A">●</span>{{$t('上传成功')}}</p>
  43. <p>{{file.raw?file.raw.name:$t('暂无上传文件')}}</p>
  44. <el-progress :percentage="file.progress" :show-text="false"></el-progress>
  45. </div>
  46. </div>
  47. <slot name="errorFile"></slot>
  48. <p class="tips">• + {{$t('为保证数据导入顺利,推荐您下载并使用' + ' ')}}<a :href="modelurl">《{{$t('Excel序列号标准模板')}}》</a></p>
  49. <p class="tips">• {{$t('文件中数据不能超过5000行')}}</p>
  50. <div class="dialog-footer">
  51. <el-button size="small" @click="cancel" class="normal-btn-width">{{$t('取 消')}}</el-button>
  52. <el-button size="small" type="warning" @click="dialogUploadVisible = false" class="normal-btn-width btn-warning">{{$t('确 定')}}</el-button>
  53. </div>
  54. </div>
  55. </el-dialog>
  56. </div>
  57. </template>
  58. <script>
  59. export default {
  60. /*
  61. folderid:文件夹id; 必填
  62. btntype:展示上传按钮的类型;
  63. accept:限制上传文件类型;
  64. bindData:附件上传成功后对应需要绑定的数据信息
  65. */
  66. props:['folderid','btntype','accept','bindData'],
  67. data () {
  68. return {
  69. dialogUploadVisible: false,
  70. params: {
  71. "classname": "system.attachment.huawei.OBS",
  72. "method": "getFileName",
  73. "content": {
  74. "filename": '',
  75. "filetype": '',
  76. "parentid": ""//归属文件夹ID
  77. }
  78. },
  79. file: {},
  80. filelist: [],
  81. CampaignList:[],
  82. activeName:'last',
  83. modelurl:'',
  84. campaignid:''
  85. }
  86. },
  87. mounted () {
  88. this.getModelUrl()
  89. },
  90. methods: {
  91. cancel () {
  92. this.dialogUploadVisible = false
  93. this.campaignid = ''
  94. this.$refs['my-upload'].clearFiles()
  95. this.filelist = []
  96. },
  97. handleChange (file, filelist) {
  98. this.filelist = filelist
  99. var index = file.raw.name.lastIndexOf(".");
  100. var ext = file.name.substr(index + 1);
  101. this.params.content.filename = file.raw.name
  102. this.params.content.filetype = ext
  103. this.getUploadUrl(file, ext)
  104. },
  105. handleClick () {
  106. this.getModelUrl()
  107. },
  108. // 获取导入模板
  109. async getModelUrl () {
  110. const res = await this.$api.requested({
  111. "id": 2024060413153202,
  112. "content": {
  113. }
  114. })
  115. this.modelurl = res.data
  116. console.log(this.modelurl);
  117. },
  118. // 获取华为云上传地址
  119. async getUploadUrl (file, ext) {
  120. const folderIdData = JSON.parse(sessionStorage.getItem('folderid'))
  121. this.params.content.parentid = folderIdData ? folderIdData.appfolderid : ''
  122. const res = await this.$api.requested(this.params)
  123. let url = res.data.uploadurl
  124. let obsfilename = res.data.serialfilename
  125. this.upoladFileToServer(url, file, ext, obsfilename)
  126. },
  127. // 上传到华为云
  128. async upoladFileToServer (url, file, ext, obsfilename) {
  129. let THIS = this
  130. let config = {
  131. headers: ext === 'pdf' ? { 'Content-Type': 'application/pdf' } : { 'Content-Type': 'application/octet-stream' },
  132. onUploadProgress: function (progressEvent) {
  133. let percent = progressEvent.loaded / progressEvent.total * 100
  134. THIS.filelist.forEach(e => {
  135. if (e.uid === file.uid) {
  136. THIS.$set(e, 'type', ext.toUpperCase());
  137. THIS.$set(e, 'progress', percent);
  138. }
  139. })
  140. },
  141. }
  142. const res = await this.$upload.hw_upload(url, file.raw, config)
  143. this.createFileRecord(obsfilename)
  144. },
  145. // 上传成功以后生成附件记录
  146. async createFileRecord (obsfilename) {
  147. let obj = {
  148. "serialfilename": obsfilename
  149. }
  150. obj = Object.assign({},obj,this.bindData)
  151. let param = {
  152. "classname": "system.attachment.huawei.OBS",
  153. "method": "uploadSuccess",
  154. "content":obj
  155. }
  156. const res = await this.$api.requested(param)
  157. console.log(res,'结果')
  158. this.$emit('onSuccess',res.data.attachmentids)
  159. },
  160. clearFiles () {
  161. this.$refs['my-upload'].clearFiles()
  162. this.filelist = []
  163. this.dialogUploadVisible = false
  164. },
  165. }
  166. }
  167. </script>
  168. <style>
  169. .import-panel .el-dialog__header,.import-panel .el-dialog__body{
  170. padding: 0 !important;
  171. }
  172. .upload-demo > div {
  173. width: 100% !important;
  174. }
  175. .upload-demo .el-upload-dragger {
  176. width: 100% !important;
  177. }
  178. </style>
  179. <style scoped>
  180. .progress_panel {
  181. display: flex;
  182. align-items: center;
  183. padding: 10px;
  184. margin: 10px 0;
  185. border-radius: 5px;
  186. transition: linear 0.2s all;
  187. }
  188. .progress_panel:hover {
  189. box-shadow: 0px 0px 5px #ccc;
  190. }
  191. .progress_panel > div {
  192. flex: 1;
  193. padding: 0 10px;
  194. }
  195. .progress_panel > div > p {
  196. line-height: 30px;
  197. }
  198. .tips{
  199. line-height: 30px;
  200. }
  201. </style>