importFileNew.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div>
  3. <!-- 按钮类型 -->
  4. <el-button type="success" size="small" @click="onShow(0)" icon="el-icon-upload">{{$t(title)}}</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" @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. <a :href="errorUrl" class="tips" style="color:red" v-if="errorUrl">•{{$t(`下载错误数据`)}}</a>
  51. <div class="dialog-footer">
  52. <el-button size="small" @click="cancel" class="normal-btn-width">{{$t('取 消')}}</el-button>
  53. <el-button size="small" type="warning" @click="dialogUploadVisible = false" class="normal-btn-width btn-warning">{{$t('确 定')}}</el-button>
  54. </div>
  55. </div>
  56. </el-dialog>
  57. </div>
  58. </template>
  59. <script>
  60. export default {
  61. /*
  62. folderid:文件夹id; 必填
  63. btntype:展示上传按钮的类型;
  64. accept:限制上传文件类型;
  65. bindData:附件上传成功后对应需要绑定的数据信息
  66. */
  67. name: "importFileNew",
  68. props:['btntype','accept','bindData','errorUrl','title','paramID'],
  69. data () {
  70. return {
  71. dialogUploadVisible: false,
  72. params: {
  73. "classname": "system.attachment.huawei.OBS",
  74. "method": "getFileName",
  75. "content": {
  76. "filename": '',
  77. "filetype": '',
  78. "parentid": ""//归属文件夹ID
  79. }
  80. },
  81. file: {},
  82. filelist: [],
  83. CampaignList:[],
  84. activeName:'last',
  85. modelurl:'',
  86. campaignid:'',
  87. folderid:JSON.parse(sessionStorage.getItem('folderid')).appfolderid,
  88. }
  89. },
  90. mounted () {
  91. // this.listData()
  92. },
  93. methods: {
  94. onShow () {
  95. this.dialogUploadVisible = true
  96. this.getModelUrl()
  97. },
  98. cancel () {
  99. this.dialogUploadVisible = false
  100. this.campaignid = ''
  101. this.$refs['my-upload'].clearFiles()
  102. this.filelist = []
  103. },
  104. handleChange (file, filelist) {
  105. this.filelist = filelist
  106. var index = file.raw.name.lastIndexOf(".");
  107. var ext = file.name.substr(index + 1);
  108. this.params.content.filename = file.raw.name
  109. this.params.content.filetype = ext
  110. this.getUploadUrl(file, ext)
  111. },
  112. handleClick () {
  113. this.getModelUrl()
  114. },
  115. // 获取导入模板
  116. async getModelUrl () {
  117. const res = await this.$api.requested({
  118. "id":this.paramID,
  119. "content": {
  120. }
  121. })
  122. this.modelurl = res.data
  123. },
  124. // 获取华为云上传地址
  125. async getUploadUrl (file, ext) {
  126. this.params.content.parentid = this.folderid
  127. const res = await this.$api.requested(this.params)
  128. let url = res.data.uploadurl
  129. let obsfilename = res.data.serialfilename
  130. this.upoladFileToServer(url, file, ext, obsfilename)
  131. },
  132. // 上传到华为云
  133. async upoladFileToServer (url, file, ext, obsfilename) {
  134. let THIS = this
  135. let config = {
  136. headers: ext === 'pdf' ? { 'Content-Type': 'application/pdf' } : { 'Content-Type': 'application/octet-stream' },
  137. onUploadProgress: function (progressEvent) {
  138. let percent = progressEvent.loaded / progressEvent.total * 100
  139. THIS.filelist.forEach(e => {
  140. if (e.uid === file.uid) {
  141. THIS.$set(e, 'type', ext.toUpperCase());
  142. THIS.$set(e, 'progress', percent);
  143. }
  144. })
  145. },
  146. }
  147. const res = await this.$upload.hw_upload(url, file.raw, config)
  148. this.createFileRecord(obsfilename)
  149. },
  150. // 上传成功以后生成附件记录
  151. async createFileRecord (obsfilename) {
  152. let obj = {
  153. "serialfilename": obsfilename
  154. }
  155. obj = Object.assign({},obj,this.bindData)
  156. let param = {
  157. "classname": "system.attachment.huawei.OBS",
  158. "method": "uploadSuccess",
  159. "content":obj
  160. }
  161. const res = await this.$api.requested(param)
  162. this.$emit('onSuccess',res.data.attachmentids[0])
  163. },
  164. clearFiles () {
  165. this.$refs['my-upload'].clearFiles()
  166. this.filelist = []
  167. this.dialogUploadVisible = false
  168. this.$emit('clearUrl')
  169. },
  170. }
  171. }
  172. </script>
  173. <style>
  174. .import-panel .el-dialog__header,.import-panel .el-dialog__body{
  175. padding: 0 !important;
  176. }
  177. .upload-demo > div {
  178. width: 100% !important;
  179. }
  180. .upload-demo .el-upload-dragger {
  181. width: 100% !important;
  182. }
  183. </style>
  184. <style scoped>
  185. .progress_panel {
  186. display: flex;
  187. align-items: center;
  188. padding: 10px;
  189. margin: 10px 0;
  190. border-radius: 5px;
  191. transition: linear 0.2s all;
  192. }
  193. .progress_panel:hover {
  194. box-shadow: 0px 0px 5px #ccc;
  195. }
  196. .progress_panel > div {
  197. flex: 1;
  198. padding: 0 10px;
  199. }
  200. .progress_panel > div > p {
  201. line-height: 30px;
  202. }
  203. .tips{
  204. line-height: 30px;
  205. }
  206. </style>