Selaa lähdekoodia

feat: 上传文件适配

Carson 1 vuosi sitten
vanhempi
commit
5cea7f4c72
3 muutettua tiedostoa jossa 50 lisäystä ja 18922 poistoa
  1. 1 18848
      package-lock.json
  2. 1 0
      package.json
  3. 48 74
      src/components/pages/classroomObservation/components/chatArea.vue

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 18848
package-lock.json


+ 1 - 0
package.json

@@ -38,6 +38,7 @@
     "lodash": "^4.17.21",
     "markdown-it": "^13.0.2",
     "opencc-js": "^1.0.5",
+    "papaparse": "^5.4.1",
     "pdfjs-dist": "^2.5.207",
     "pptxgenjs": "^3.12.0",
     "qrcodejs2": "^0.0.2",

+ 48 - 74
src/components/pages/classroomObservation/components/chatArea.vue

@@ -428,6 +428,7 @@ import EditorBar from "./wangEnduit";
 const lamejs = require("lamejs");
 import vpdf from "./vpdf";
 import _ from "lodash";
+import Papa from "papaparse";
 // const recorder = new Recorder({
 // 	sampleBits: 16, // 采样位数,支持 8 或 16,默认是16
 // 	sampleRate: 48000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000
@@ -459,7 +460,7 @@ const OPTIONS_GROUP = {
   ],
 };
 const ATTENTION_GROUP = {
-  default: "先根据说话人角色判断,再在对应角色的选项中选择选项",
+  default: "- 先根据说话人角色判断,再在对应角色的选项中选择选项\n- 如果没有合适的选项,默认使用`老师其他`或者`学生其他`",
 };
 
 // 自定义指令,用于处理点击外部区域的事件
@@ -686,7 +687,7 @@ export default {
       input.onchange = () => {
         this.uploadFileLoading = true;
         let file = input.files[0];
-        if (!/\.(wav|txt|pdf|xlsx|doc|docx)$/i.test(file.name)) {
+        if (!/\.(wav|txt|pdf|xlsx|doc|docx|csv)$/i.test(file.name)) {
           this.uploadFileLoading = false;
           return this.$message.info(
             "请上传.wav,.txt,.pdf,.xlsx,.doc,.docx,.csv格式的文件"
@@ -1804,8 +1805,8 @@ ${JSON.stringify(_list)}
             } else {
               // 判断是不是音频文件
               const audioRegex = /\.(mp3|wav|ogg|flac|m4a)$/i;
-              const txtRegex = /\.(txt)$/i;
-              const otherRegex = /\.(pdf|xlsx|doc|docx|csv)$/i;
+              const txtRegex = /\.(txt|csv)$/i;
+              const otherRegex = /\.(pdf|xlsx|doc|docx)$/i;
               // if (audioRegex.test(data.Location)) {
               // 	// console.log(data);
               // 	_this.uploadWavFileAndGetText(file)
@@ -1848,73 +1849,44 @@ ${JSON.stringify(_list)}
                         _this.controlsStatus = 2;
                         _this.showIndexPage = false;
                         _this.pageStatus = 2;
-                        // _this.transcriptionData.content += _res.data;
-                        _this.editorBarData.type = "0";
-                        let _textData = _res.data;
-                        if (flag) {
-                          let _result = `<table
-														border="0"
-														width="100%"
-														cellpadding="0"
-														cellspacing="0"
-														style="text-align: center"
-													>
-														<tbody>`;
-                          _textData.split("\n").forEach((item, index) => {
-                            if (index == _textData.split("\n").length - 1) return;
-                            if (index == 0) {
-                              _result += `<tr>`;
-                              if (
-                                item.split("").filter((char) => char === ",").length >= 6
-                              ) {
-                                item.split(",").forEach((item2, index2) => {
-                                  _result += `
-																			<th>${item2}</th>
-																		`;
-                                });
-                              } else {
-                                item
-                                  .trim()
-                                  .split(/\s+/)
-                                  .forEach((item2, index2) => {
-                                    _result += `
-																			<th>${item2}</td>
-																		`;
-                                  });
-                              }
-                              _result += `</tr>`;
-                              return;
-                            }
-                            _result += `<tr>`;
-                            if (
-                              item.split("").filter((char) => char === ",").length >= 6
-                            ) {
-                              item.split(",").forEach((item2, index2) => {
-                                _result += `
-																			<td>${item2}</td>
-																		`;
-                              });
-                            } else {
-                              item
-                                .trim()
-                                .split(/\s+/)
-                                .forEach((item2, index2) => {
-                                  _result += `
-																			<td>${item2}</td>
-																		`;
-                                });
-                            }
-
-                            _result += `</tr>`;
-                          });
-                          _result += `
-															</tbody>
-														</table>`;
-                          _this.editorBarData.content = _result;
-                        } else {
-                          _this.editorBarData.content = _textData;
-                        }
-
+                        const arr = Papa.parse(_res.data, {
+                          header: false,
+                        }).data.slice(1);
+                        console.log(arr);
+                        const _editorBarDataContent = `<table
+                          border="0"
+                          width="100%"
+                          cellpadding="0"
+                          cellspacing="0"
+                          style="text-align: center"
+                        >
+                          <tbody>
+                            <tr>
+                              <th>序号1</th>
+                              <th>开始时间</th>
+                              <th>结束时间</th>
+                              <th>发言内容</th>
+                              <th>时长</th>
+                              <th>说话人身份</th>
+                              <th>行为编码</th>
+                            </tr>
+                            ${arr.map(
+                              (row) => `
+                              <tr>
+                                <td>${_.get(row, 0, "")}</td>
+                                <td>${_.get(row, 1, "")}</td>
+                                <td>${_.get(row, 2, "")}</td>
+                                <td>${_.get(row, 3, "")}</td>
+                                <td>${_.get(row, 4, "")}</td>
+                                <td>${_.get(row, 5, "")}</td>
+                                <td>${_.get(row, 6, "")}</td>
+                              </tr>
+                              `
+                            ).join('\n')}
+                          </tbody>
+                        </table>`;
+                        _this.editorBarData.type = '0';
+                        _this.editorBarData.content = _editorBarDataContent;
                         // _this.transcriptionData.content = _res.data;
                         _this.editorBarData.url = "";
                         _this.saveEditorBar();
@@ -2092,8 +2064,7 @@ ${JSON.stringify(_list)}
 
         if (this.editorBarData.type == 0) {
           let _data = this.editorBarData.content;
-          let _div = document.createElement("div");
-          _div.innerHTML = _data;
+          let _div = document.createRange().createContextualFragment(_data);
           let _tableRows = _div.querySelectorAll(`table tbody tr`);
           _tableRows.forEach((i, index) => {
             while (i.cells.length > 7) {
@@ -2375,7 +2346,10 @@ ${JSON.stringify(_list)}
               inputs: {
                 // PERF better to just include `role` and `content` to minimize token cost
                 rows: JSON.stringify(
-                  rows.map((r) => ({content: r.cells[3].textContent, role: r.cells[5].textContent}))
+                  rows.map((r) => ({
+                    content: r.cells[3].textContent,
+                    role: r.cells[5].textContent,
+                  }))
                 ),
                 options: options.join(","),
                 attention,

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä