Bladeren bron

批量导入字词卡片

natasha 1 jaar geleden
bovenliggende
commit
b2e5be8f46
3 gewijzigde bestanden met toevoegingen van 136 en 14 verwijderingen
  1. 109 1
      src/views/wordcard/cread.vue
  2. 13 6
      src/views/wordcard/printNew.vue
  3. 14 7
      src/views/wordcard/writeTableNew.vue

+ 109 - 1
src/views/wordcard/cread.vue

@@ -13,6 +13,19 @@
         </div>
         <div class="btn-box">
           <el-button small @click="addCard"><i class="el-icon-plus"></i>增加卡片</el-button>
+          <el-upload
+            ref="upload"
+            :action="url"
+            accept=".xlsx,.xls"
+            :limit="9999"
+            :on-exceed="handleExceed"
+            :on-success="handleSuccess"
+            :show-file-list="false"
+            class="btn"
+            style="margin: 0 8px"
+          >
+            <el-button>通过模版导入</el-button>
+          </el-upload>
           <el-button type="primary" plain small @click="save">结束编辑并保存</el-button>
         </div>
       </template>
@@ -76,6 +89,7 @@
 import Header from '@/components/Header';
 import { getLogin, LearnWebSI, getHZChineseInfo, getContentFile } from '@/api/api';
 import writeTable from './writeTableNew.vue';
+import { getToken } from '@/utils/auth';
 import html2canvas from 'html2canvas';
 import { jsPDF } from 'jspdf';
 import canvg from 'canvg';
@@ -130,7 +144,17 @@ export default {
     };
   },
   //计算属性 类似于data概念
-  computed: {},
+  computed: {
+    url() {
+      let userInfo = getToken()
+        ? JSON.parse(getToken())
+        : sessionStorage.getItem('GCLS_Token_Tc')
+        ? JSON.parse(sessionStorage.getItem('GCLS_Token_Tc'))
+        : null;
+      if (!userInfo) return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload`;
+      return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?AccessToken=${userInfo.access_token}&SecurityLevel=Mid"`;
+    },
+  },
   //监控data中数据变化
   watch: {},
   //方法集合
@@ -298,6 +322,90 @@ export default {
         }
       });
     },
+    async handleSuccess(res, file, fileList) {
+      if (res.status !== 1) {
+        this.$message.error(res.message);
+        return;
+      }
+      let file_id = file.response.file_info_list[0].file_id;
+      this.loading = true;
+      // 通过 fileList 的 response 判断是否已全部完成上传
+      this.loading = true;
+      this.$refs.upload.clearFiles();
+      await LearnWebSI('tr_tool-wsc_manager-ParseWordSentenceCardImportFile', {
+        file_id: file_id,
+      })
+        .then((res) => {
+          this.loading = false;
+          this.$message.success('导入成功');
+          res.content_json_text.forEach((items) => {
+            if (
+              items.headerCon ||
+              items.label ||
+              items.left.con ||
+              items.right.cixing ||
+              items.right.collocation ||
+              items.right.definition ||
+              items.right.exampleSent ||
+              items.right.pinyin
+            ) {
+              items.borderColor = '#243C97';
+              items.fontAlign = 'left';
+              items.fontColor = '#243C97';
+              let con = items.left.con.trim();
+              if (con) {
+                let MethodName = 'hz_resource_manager-GetMultHZStrokesContent';
+                let data = {
+                  hz_str: con,
+                };
+                getLogin(MethodName, data)
+                  .then((res) => {
+                    this.loading = false;
+                    for (let key in res) {
+                      if (key != 'status' && key != ',' && res[key]) {
+                        res[key] = JSON.parse(res[key]);
+                      }
+                    }
+                    let hzDetailList = res;
+                    let hz_list = [];
+                    con.split('').forEach((items) => {
+                      let res = JSON.parse(JSON.stringify(hzDetailList[items]));
+                      let obj = {
+                        con: items,
+                        hzDetail: {
+                          hz_json: res,
+                        },
+                      };
+                      hz_list.push(obj);
+                    });
+                    items.right.hz_info = hz_list;
+                    let MethodName = 'tool-TextToVoiceFile';
+                    if (con) {
+                      let datas = {
+                        text: con,
+                      };
+                      getLogin(MethodName, datas).then((res) => {
+                        if (res.status === 1) {
+                          items.right.audio_file = res.file_id;
+                        }
+                      });
+                    }
+                  })
+                  .catch(() => {
+                    this.loading = false;
+                  });
+              }
+              this.newEditTable.push(items);
+            }
+          });
+        })
+        .catch((res) => {
+          this.loading = false;
+        });
+    },
+    handleExceed(files) {
+      this.$message.warning(`当前限制选择 9999 个文件,本次选择了 ${files.length} 个文件`);
+    },
   },
   //生命周期 - 创建完成(可以访问当前this实例)
   created() {},

+ 13 - 6
src/views/wordcard/printNew.vue

@@ -27,7 +27,8 @@
           <div
             :style="{
               display: 'flex',
-              justifyContent: !(data.right.collocation && data.right.exampleSent) ? 'center' : 'auto',
+              justifyContent:
+                !(data.right.collocation && data.right.exampleSent) && data.left.con.length < 4 ? 'center' : 'auto',
             }"
           >
             <div style="width: max-content">
@@ -60,7 +61,7 @@
             </div>
             <div
               class="definition-box"
-              v-if="data.right.collocation || data.right.exampleSent"
+              v-if="(data.right.collocation || data.right.exampleSent) && data.left.con.length < 4"
               style="flex: 1; margin: 100px 0 0 16px"
             >
               <div v-if="data.right.cixing">
@@ -76,11 +77,17 @@
           <div
             class="definition-box"
             :style="{
-              width: !(data.right.collocation || data.right.exampleSent) ? data.right.hz_info.length * 98 + 'px' : '',
-              margin: !(data.right.collocation || data.right.exampleSent) ? '16px auto 0 auto' : '',
+              width:
+                !(data.right.collocation || data.right.exampleSent) && data.left.con.length < 4
+                  ? data.right.hz_info.length * 98 + 'px'
+                  : '',
+              margin:
+                !(data.right.collocation || data.right.exampleSent) && data.left.con.length < 4
+                  ? '16px auto 0 auto'
+                  : '',
             }"
           >
-            <template v-if="!(data.right.collocation || data.right.exampleSent)">
+            <template v-if="!(data.right.collocation || data.right.exampleSent) || data.left.con.length >= 4">
               <div v-if="data.right.cixing">
                 <label class="card-label">词性:</label>
                 <p>{{ data.right.cixing }}</p>
@@ -330,7 +337,7 @@ export default {
     .left,
     .right {
       width: 600px;
-      height: 450px;
+      min-height: 450px;
       padding: 8px 12px 18px 12px;
       border-radius: 24px;
       background: #fff;

+ 14 - 7
src/views/wordcard/writeTableNew.vue

@@ -96,7 +96,8 @@
           <div
             :style="{
               display: 'flex',
-              justifyContent: !(data.right.collocation && data.right.exampleSent) ? 'center' : 'auto',
+              justifyContent:
+                !(data.right.collocation && data.right.exampleSent) && data.left.con.length < 4 ? 'center' : 'auto',
             }"
           >
             <div style="width: max-content">
@@ -130,7 +131,7 @@
 
             <div
               class="definition-box"
-              v-if="data.right.collocation || data.right.exampleSent"
+              v-if="(data.right.collocation || data.right.exampleSent) && data.left.con.length < 4"
               style="flex: 1; margin: 100px 0 0 16px"
             >
               <div v-if="data.right.cixing">
@@ -146,11 +147,17 @@
           <div
             class="definition-box"
             :style="{
-              width: !(data.right.collocation || data.right.exampleSent) ? data.right.hz_info.length * 98 + 'px' : '',
-              margin: !(data.right.collocation || data.right.exampleSent) ? '16px auto 0 auto' : '',
+              width:
+                !(data.right.collocation || data.right.exampleSent) && data.left.con.length < 4
+                  ? data.right.hz_info.length * 98 + 'px'
+                  : '',
+              margin:
+                !(data.right.collocation || data.right.exampleSent) && data.left.con.length < 4
+                  ? '16px auto 0 auto'
+                  : '',
             }"
           >
-            <template v-if="!(data.right.collocation || data.right.exampleSent)">
+            <template v-if="!(data.right.collocation || data.right.exampleSent) || data.left.con.length >= 4">
               <div v-if="data.right.cixing">
                 <label class="card-label">词性:</label>
                 <p>{{ data.right.cixing }}</p>
@@ -366,7 +373,7 @@ export default {
     width: 600px;
   }
   .writeTop {
-    height: 450px;
+    min-height: 450px;
     display: flex;
     column-gap: 8px;
     perspective: 1000px;
@@ -377,7 +384,7 @@ export default {
     .left,
     .right {
       width: 600px;
-      height: 100%;
+      min-height: 450px;
       padding: 8px 12px 18px 12px;
       border-radius: 24px;
       background: #fff;