Selaa lähdekoodia

事件详情上传的txt文档打开后乱码

王通 1 vuosi sitten
vanhempi
commit
2174e8a70c
1 muutettua tiedostoa jossa 15 lisäystä ja 2 poistoa
  1. 15 2
      src/views/eventLogUpload.vue

+ 15 - 2
src/views/eventLogUpload.vue

@@ -11,6 +11,7 @@
         :on-error="handleUploadError"
         :on-exceed="handleExceed"
         :on-success="handleUploadSuccess"
+        :on-change="handleChange"
         :show-file-list="false"
         :headers="headers"
         class="upload-file-uploader"
@@ -22,7 +23,7 @@
         <div class="el-upload__tip" slot="tip" v-if="showTip">
           请上传
           <template v-if="fileSize"> 大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b></template>
-<!--          <template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join('/') }}</b></template>-->
+          <!--          <template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join('/') }}</b></template>-->
           的文件
         </div>
       </el-upload>
@@ -32,7 +33,7 @@
         <li :key="file.url" class="el-upload-list__item ele-upload-list__item-content"
             v-for="(file, index) in fileList">
           <el-link :href="file.webUrl" :underline="false" target="_blank">
-            <span class="el-icon-document"> {{ file.webName}} </span>
+            <span class="el-icon-document"> {{ file.webName }} </span>
           </el-link>
           <div class="ele-upload-list__item-content-action">
             <el-link :underline="false" @click="handleDelete(index)" type="danger">删除</el-link>
@@ -150,6 +151,18 @@ export default {
 
 
     },
+    handleChange(file, fileList) {
+      var _this = this;
+      if (file.raw) {
+        let reader = new FileReader()
+        reader.onload = function (e) {
+          _this.contentHtml = e.target.result;
+        };
+        reader.readAsText(file.raw,'gb2312');
+
+      }
+      console.log(file, fileList);
+    },
     eventLogUpload(eventCode) {
       this.eventCode=eventCode
       //上传页面弹出