Selaa lähdekoodia

富文本限制长度

natasha 3 vuotta sitten
vanhempi
commit
bc65cf2908

+ 26 - 1
src/components/Adult/inputModules/Tinydemo.vue

@@ -14,6 +14,8 @@
         placeholder="请输入标题"
         v-model="curQue.title"
         @blur="curQue.title = curQue.title.trim()"
+        maxlength="500"
+        show-word-limit
       ></el-input>
     </div>
     <div class="adult-book-input-item">
@@ -37,7 +39,7 @@
       </li>
     </ul>
     <div class="main">
-      <Editor :id="'tinydemo' + number" v-model="curQue.con" :init="init" />
+      <Editor :id="'tinydemo' + number" v-model="curQue.con" :init="init" @input="articleChange" />
     </div>
   </div>
 </template>
@@ -83,6 +85,11 @@ export default {
         toolbar:
           "preview bold italic underline strikethrough | fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent blockquote | undo redo | link unlink image code | removeformat",
         branding: false,
+        ax_wordlimit_num: 50,
+        ax_wordlimit_callback: function(editor,txt,num){
+            debugger
+            tipsJS('当前字数:' + txt.length + ',限制字数:' + num);
+        }
       }, //富文本初始化
       data_structure: {
         type: "tinydemo",
@@ -115,6 +122,24 @@ export default {
       });
       this.curQue.img_list = JSON.parse(JSON.stringify(articleImgRes));
     },
+    articleChange(e) {
+      let _this = this;
+      let str = e.replace(/<[^>]+>/g, "");
+      let arr = str.split(/[\n]/);
+      let newstr = "";
+      arr.forEach((item) => {
+        newstr += item;
+      });
+      if (newstr.length == 5000) {
+        this.newarticle = e;
+      }
+      if (newstr.length > 5000) {
+        if (document.getElementsByClassName("el-message").length == 0) {
+          this.$message.warning("已超出字数限制");
+        }
+        return;
+      }
+    },
   },
   //生命周期 - 创建完成(可以访问当前this实例)
   created() {

+ 19 - 0
src/components/Adult/inputModules/ToneSelect.vue

@@ -63,6 +63,7 @@
             v-model="curQueItem.con"
             :init="init"
             @change="changeCon(curQueItem)"
+            @input="articleChange"
           />
           <img
             @click="deleteGroup"
@@ -481,6 +482,24 @@ export default {
         };
       });
     },
+    articleChange(e) {
+      let _this = this;
+      let str = e.replace(/<[^>]+>/g, "");
+      let arr = str.split(/[\n]/);
+      let newstr = "";
+      arr.forEach((item) => {
+        newstr += item;
+      });
+      if (newstr.length == 5000) {
+        this.newarticle = e;
+      }
+      if (newstr.length > 5000) {
+        if (document.getElementsByClassName("el-message").length == 0) {
+          this.$message.warning("已超出字数限制");
+        }
+        return;
+      }
+    },
   },
   //生命周期 - 创建完成(可以访问当前this实例)
   created() {},

+ 49 - 22
src/components/Adult/preview/UploadControlView.vue

@@ -6,7 +6,28 @@
       :style="{ display: type == 'upload_control_chs' ? 'flex' : 'block' }"
     >
       <div class="content">
-        <template v-if="curQue.data">
+        <template v-if="curQue.Bookanswer&&type == 'upload_control_chs'">
+          <template
+            v-if="
+              curQue.Bookanswer.file_name.indexOf('png') != -1 ||
+              curQue.Bookanswer.file_name.indexOf('jpg') != -1 ||
+              curQue.Bookanswer.file_name.indexOf('jpeg') != -1
+            "
+          >
+            <img :src="curQue.Bookanswer.file_url" alt="" />
+          </template>
+          <template v-else-if="curQue.Bookanswer.file_name.indexOf('pdf') != -1">
+            <pdf
+              ref="pdf"
+              :src="curQue.Bookanswer.fileRelativePath"
+              v-for="i in curQue.Bookanswer.numPages"
+              :key="i"
+              :page="i"
+            >
+            </pdf>
+          </template>
+        </template>
+        <template v-else-if="curQue.data&&type == 'upload_control_preview_chs'">
           <template
             v-if="
               curQue.data.file_name.indexOf('png') != -1 ||
@@ -16,11 +37,11 @@
           >
             <img :src="curQue.data.file_url" alt="" />
           </template>
-          <template v-else-if="curQue.data.file_name.indexOf('pdf') != -1">
+          <template v-else-if="curQue.Bookanswer.file_name.indexOf('pdf') != -1">
             <pdf
               ref="pdf"
-              :src="curQue.data.fileRelativePath"
-              v-for="i in curQue.data.numPages"
+              :src="curQue.Bookanswer.fileRelativePath"
+              v-for="i in curQue.Bookanswer.numPages"
               :key="i"
               :page="i"
             >
@@ -30,7 +51,7 @@
         <template v-else>
           <div
             style="display: flex; height: 40px"
-            v-if="type == 'upload_control_chs'"
+            v-if="type == 'upload_control_chs'&&TaskModel!='ANSWER'"
           >
             <UploadView
               :changeFillId="changeFillId"
@@ -54,8 +75,8 @@
         />
         下载
       </div>
-      <div class="dv" v-if="curQue.data">
-        <div v-if="type == 'upload_control_chs'" class="remove" @click="remove">
+      <div class="dv" v-if="curQue.Bookanswer">
+        <div v-if="type == 'upload_control_chs'" class="remove" :class="[TaskModel == 'ANSWER'?'notAllow':'']" @click="remove">
           <img src="../../../assets/adult/red_remove.png" alt="" />
         </div>
       </div>
@@ -73,7 +94,7 @@ export default {
     UploadView,
     pdf,
   },
-  props: ["curQue", "fn_data", "type"],
+  props: ["curQue", "fn_data", "type", "TaskModel"],
   data() {
     return {
       uploadType: "",
@@ -111,7 +132,7 @@ export default {
         UserType = userInfor.user_type;
         SessionID = userInfor.session_id;
       }
-      let FileID = this.curQue.data.file_id;
+      let FileID = this.curQue.Bookanswer.file_id;
       let data = {
         SessionID,
         UserCode,
@@ -123,22 +144,25 @@ export default {
         `/GCLSFileServer/WebFileDownload?UserCode=${data.UserCode}&UserType=${data.UserType}&SessionID=${data.SessionID}&FileID=${data.FileID}`;
     },
     remove() {
-      if (this.curQue.data) {
-        this.data = null;
-        this.curQue.data = null;
-        this.curQue.fileList = [];
-        this.$message.success("删除成功");
-        this.$forceUpdate()
-      }
+        if(!this.TaskModel||this.TaskModel!='ANSWER'){
+            if (this.curQue.Bookanswer) {
+                this.data = null;
+                this.curQue.Bookanswer = null;
+                this.curQue.fileList = [];
+                this.$message.success("删除成功");
+                this.$forceUpdate()
+            }
+        }
     },
     changeFillId(fileList, item, index) {
       this.curQue.fileList = fileList;
       // this.$set(this.curQue,data,fileList[0].response.file_info_list[0])
       this.curQue.data = fileList[0].response.file_info_list[0];
-      if (this.curQue.data.file_name.indexOf("pdf") != -1) {
-        this.curQue.data = fileList[0].response.file_info_list[0];
-        this.curQue.data.fileRelativePath =
-          process.env.VUE_APP_BASE_API + this.curQue.data.file_relative_path;
+      this.curQue.Bookanswer = fileList[0].response.file_info_list[0];
+      if (this.curQue.Bookanswer.file_name.indexOf("pdf") != -1) {
+        this.curQue.Bookanswer = fileList[0].response.file_info_list[0];
+        this.curQue.Bookanswer.fileRelativePath =
+          process.env.VUE_APP_BASE_API + this.curQue.Bookanswer.file_relative_path;
         this.getNumPages();
       }
       this.$forceUpdate();
@@ -147,12 +171,12 @@ export default {
     getNumPages() {
       let _this = this;
       let loadingTask = pdf.createLoadingTask(
-        _this.curQue.data.fileRelativePath
+        _this.curQue.Bookanswer.fileRelativePath
       );
       loadingTask.promise
         .then((pdff) => {
           _this.numPages = pdff.numPages;
-          _this.curQue.data.numPages = pdff.numPages;
+          _this.curQue.Bookanswer.numPages = pdff.numPages;
           this.$forceUpdate();
         })
         .catch((err) => {
@@ -199,6 +223,9 @@ export default {
       justify-content: center;
       margin-left: 32px;
       cursor: pointer;
+      &.notAllow{
+          cursor: not-allowed;
+      }
       img {
         width: 24px;
         height: 24px;

+ 22 - 0
src/views/adultInput.vue

@@ -1487,6 +1487,28 @@ export default {
     },
     onSave() {
       let isProof = true;
+      for(let j=0; j<this.question_list.cur_fn_data.length;j++){
+          for(let l=0; l<this.question_list.cur_fn_data[j].table_list.length;l++){
+              for(let m=0; m<this.question_list.cur_fn_data[j].table_list[l].length;m++){
+                  if(this.question_list.cur_fn_data[j].table_list[l][m].type =='tinydemo_chs'||this.question_list.cur_fn_data[j].table_list[l][m].type =='toneSelect_chs'){
+                        for (let i=0; i < tinymce.editors.length; i++){
+                            var content = tinymce.editors[i].getContent();
+                            let arr = content.split(/[\n]/);
+                            let newstr = "";
+                            arr.forEach((item) => {
+                            newstr += item;
+                            });
+                            if (newstr.length > 5000) {
+                                this.$message.warning("富文本已超出字数限制");
+                                this.loading = false;
+                                return false
+                            }
+                        }
+                  }
+              }
+          }
+      }
+      
       let question_list_str = JSON.stringify(this.question_list);
       console.log(this.question_list);
       localStorage.setItem("question_list", question_list_str);