|
@@ -8,7 +8,11 @@
|
|
|
class="chat-window"
|
|
|
style="padding-left: 20px; padding-right: 20px; margin-top: 20px"
|
|
|
id="contant1"
|
|
|
+ ref="scrollview"
|
|
|
>
|
|
|
+ <div v-if="echoFlag" style="text-align: center">
|
|
|
+ <i class="el-icon-loading"></i>
|
|
|
+ </div>
|
|
|
<div
|
|
|
class="chat-msg-content"
|
|
|
id="rongqi"
|
|
@@ -84,7 +88,7 @@
|
|
|
v-if="content.isType == 0"
|
|
|
v-model="content.radio"
|
|
|
:disabled="!(chatContents.length - 1 == index)"
|
|
|
- @input="chooseAnswer"
|
|
|
+ @input="chooseAnswer(content)"
|
|
|
>
|
|
|
<el-radio
|
|
|
style="width: 100%"
|
|
@@ -102,11 +106,15 @@
|
|
|
v-if="content.isType == 1"
|
|
|
v-model="content.text"
|
|
|
/><i
|
|
|
- style="width: 20px; height: 20px; color: #57c02c"
|
|
|
- v-if="content.isType == 1"
|
|
|
- @click="
|
|
|
- sendMessageFun(content.question[0].nextQuestionNo)
|
|
|
+ v-show="chatContents.length - 1 == index"
|
|
|
+ style="
|
|
|
+ width: 20px;
|
|
|
+ height: 20px;
|
|
|
+ color: #57c02c;
|
|
|
+ margin-left: 10px;
|
|
|
"
|
|
|
+ v-if="content.isType == 1"
|
|
|
+ @click="sendMessageFun(content)"
|
|
|
class="el-icon-s-promotion"
|
|
|
></i>
|
|
|
|
|
@@ -119,20 +127,6 @@
|
|
|
>
|
|
|
{{ content.question }}
|
|
|
</div>
|
|
|
- <!-- <el-radio-group v-if="content.isType==-1"
|
|
|
- v-model="content.radio"
|
|
|
- :disabled="content.disabled"
|
|
|
- @input="chooseAnswer"
|
|
|
- >
|
|
|
- <el-radio
|
|
|
- v-for="item in content.question"
|
|
|
- :key="item.id"
|
|
|
- size="small"
|
|
|
- :label="item.nextQuestionNo"
|
|
|
- border
|
|
|
- >{{ item.answer }}</el-radio
|
|
|
- >
|
|
|
- </el-radio-group> -->
|
|
|
</div>
|
|
|
<div class="img-wrapper">
|
|
|
<img
|
|
@@ -267,22 +261,73 @@ export default {
|
|
|
questionList: [],
|
|
|
answerList: [],
|
|
|
interveneId: "",
|
|
|
-
|
|
|
//当回显接口正在调用时为true
|
|
|
echoFlag: false,
|
|
|
//当前返回历史记录
|
|
|
currenRecordTotol: 0,
|
|
|
+ //当前页
|
|
|
+ pageNum: 1,
|
|
|
+ //一页多少条
|
|
|
+ pageSize: 10,
|
|
|
+ printIndex: 0,
|
|
|
+ flagTime: null,
|
|
|
};
|
|
|
},
|
|
|
created() {},
|
|
|
mounted() {
|
|
|
+ var scrollview = this.$refs["scrollview"];
|
|
|
this.interveneId = this.$route.query.id;
|
|
|
- this.init("start");
|
|
|
+ //
|
|
|
+ // this.init("start");
|
|
|
// this.selectScale("20220805135201");
|
|
|
//上来就查询之前的聊天记录
|
|
|
+ scrollview.addEventListener("scroll", this.handleScroll, true);
|
|
|
this.selectPage();
|
|
|
+ //判断是否是第一次进来,如果查询记录为空,则是第一次进来--则需要调用出初始化语句
|
|
|
+ //如果不是第一次进来--则接着上次的记录说
|
|
|
},
|
|
|
+ beforeDestroy() {
|
|
|
+ let that = this;
|
|
|
+ var scrollview = this.$refs["scrollview"];
|
|
|
+ scrollview.removeEventListener("scroll", that.handleScroll);
|
|
|
+ },
|
|
|
+
|
|
|
methods: {
|
|
|
+ handleScroll() {
|
|
|
+ let scrollview = this.$refs["scrollview"];
|
|
|
+ if (scrollview.scrollTop == 0) {
|
|
|
+ //当前没有调接口的时候
|
|
|
+ if (!this.echoFlag) {
|
|
|
+ //判断上一次的页面是否足够10条如果不够就不查询了
|
|
|
+ //页面页数加1
|
|
|
+ if (this.currenRecordTotol == this.pageSize) {
|
|
|
+ this.pageNum++;
|
|
|
+ this.selectPage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当等于0时需要调用加载上一页
|
|
|
+ }
|
|
|
+ // console.log("qlkhdeqj1");
|
|
|
+ //滚动监听事件
|
|
|
+ },
|
|
|
+ //保存聊天记录--单条
|
|
|
+ saveRecord(val) {
|
|
|
+ let data = {
|
|
|
+ identifier: sessionStorage.getItem("num"),
|
|
|
+ label: val.label,
|
|
|
+ content: val.content,
|
|
|
+ userName: sessionStorage.getItem("name"),
|
|
|
+ questionNo: val.questionNo,
|
|
|
+ type: this.interveneId,
|
|
|
+ };
|
|
|
+ console.log(data);
|
|
|
+ // this.$message.success("保存成功");
|
|
|
+ this.$http.post(`/intelligent/save`, data, (res) => {
|
|
|
+ if (res.data.code == 200) {
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
//查询聊天记录
|
|
|
selectPage() {
|
|
|
let that = this;
|
|
@@ -290,34 +335,72 @@ export default {
|
|
|
this.$http.get(
|
|
|
`/intelligent/dialogueRecords?identifier=${sessionStorage.getItem(
|
|
|
"num"
|
|
|
- )}&pageNum=${that.pageNum}&pageSize=${that.pageSize}&type=${that.interveneId}`,
|
|
|
+ )}&pageNum=${that.pageNum}&pageSize=${that.pageSize}&type=${
|
|
|
+ that.interveneId
|
|
|
+ }`,
|
|
|
{},
|
|
|
(res) => {
|
|
|
- debugger;
|
|
|
if (res.code == 200) {
|
|
|
that.echoFlag = false;
|
|
|
// res.data.
|
|
|
- if (res.data.content.length > 0) {
|
|
|
- that.currenRecordTotol = res.data.content.length;
|
|
|
+ if (res.data.intelligentDialogueEntities.content.length > 0) {
|
|
|
+ that.currenRecordTotol =
|
|
|
+ res.data.intelligentDialogueEntities.content.length;
|
|
|
//判断当前是第几页
|
|
|
//如果是第一个
|
|
|
- for (let i = 0; i < res.data.content.length; i++) {
|
|
|
- if (res.data.content[i].label == "0") {
|
|
|
+ for (
|
|
|
+ let i = 0;
|
|
|
+ i < res.data.intelligentDialogueEntities.content.length;
|
|
|
+ i++
|
|
|
+ ) {
|
|
|
+ if (
|
|
|
+ res.data.intelligentDialogueEntities.content[i].label == "0"
|
|
|
+ ) {
|
|
|
this.chatContents.unshift({
|
|
|
from: 1,
|
|
|
- question: res.data.content[i].content,
|
|
|
+ //是否是量表的信息
|
|
|
+ isScale: false,
|
|
|
+ //是单选还是文字 0单选 1填空 -1描述
|
|
|
+ isType: -1,
|
|
|
+ //可点击可不点击 0单选 1填空
|
|
|
+ disabled: false,
|
|
|
+ //问题
|
|
|
+ question:
|
|
|
+ res.data.intelligentDialogueEntities.content[i].content,
|
|
|
+ //头像
|
|
|
from1: HeadImg,
|
|
|
});
|
|
|
} else {
|
|
|
this.chatContents.unshift({
|
|
|
from: 2,
|
|
|
- answer: res.data.content[i].content,
|
|
|
+ //是否是量表的信息
|
|
|
+ isScale: false,
|
|
|
+ //是单选还是文字 0单选 1填空 -1描述
|
|
|
+ isType: -1,
|
|
|
+ //可点击可不点击 0单选 1填空
|
|
|
+ disabled: false,
|
|
|
+ //问题
|
|
|
+ question:
|
|
|
+ res.data.intelligentDialogueEntities.content[i].content,
|
|
|
+ //头像
|
|
|
from1: HeadImg,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
console.log(this.chatContents);
|
|
|
}
|
|
|
+
|
|
|
+ //当是第一页
|
|
|
+ //且总条数为0时
|
|
|
+ if (that.pageNum == 1) {
|
|
|
+ //当是第一次进来时,需要调用question 获取第一次问答信息,但是传输的是type为5
|
|
|
+ if (res.data.intelligentDialogueEntities.content.length == 0) {
|
|
|
+ //将当前的设置为5
|
|
|
+ that.interveneId = 5;
|
|
|
+ that.getQuestion('');
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
}
|
|
|
}
|
|
@@ -413,9 +496,22 @@ export default {
|
|
|
contant1.scrollTop = contant1.scrollHeight;
|
|
|
});
|
|
|
},
|
|
|
- sendMessageFun(id) {
|
|
|
+ sendMessageFun(val) {
|
|
|
+ let id = val.question[0].nextQuestionNo;
|
|
|
+ let questionNo = val.question[0].questionNo;
|
|
|
//发送填空题
|
|
|
+
|
|
|
if (!id == "") {
|
|
|
+ let paramsSave = {
|
|
|
+ label: 1,
|
|
|
+ content: val.text,
|
|
|
+ questionNo: questionNo,
|
|
|
+ };
|
|
|
+ //当标志是5时,则不需要保存
|
|
|
+ if (this.interveneId != 5) {
|
|
|
+ this.saveRecord(paramsSave);
|
|
|
+ }
|
|
|
+
|
|
|
this.getQuestion(id);
|
|
|
} else {
|
|
|
this.chatContents.push({
|
|
@@ -432,7 +528,13 @@ export default {
|
|
|
//头像
|
|
|
from1: HeadImg,
|
|
|
});
|
|
|
- this.saveChat();
|
|
|
+ // let paramsSave = {
|
|
|
+ // label: 1,
|
|
|
+ // content: val.text,
|
|
|
+ // questionNo: questionNo,
|
|
|
+ // };
|
|
|
+ // this.saveRecord(paramsSave);
|
|
|
+ // this.saveChat();
|
|
|
let contant1 = document.getElementById("contant1");
|
|
|
this.sleep(101).then(() => {
|
|
|
contant1.scrollTop = contant1.scrollHeight;
|
|
@@ -441,10 +543,11 @@ export default {
|
|
|
},
|
|
|
// 获取问题
|
|
|
getQuestion(id) {
|
|
|
- if (id == "109" || id == "117" || id == "119") {
|
|
|
- this.centerDialogVisible = true;
|
|
|
+ if (this.interveneId == 4) {
|
|
|
+ if (id == "109" || id == "117" || id == "119") {
|
|
|
+ this.centerDialogVisible = true;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
this.$http.get(
|
|
|
`chat/getQuestion/${this.interveneId}`,
|
|
|
{
|
|
@@ -456,7 +559,7 @@ export default {
|
|
|
if (result == null) {
|
|
|
//将结束对话
|
|
|
// console.log(this.chatContents)
|
|
|
- this.saveChat();
|
|
|
+ // this.saveChat();
|
|
|
return;
|
|
|
}
|
|
|
// 将本次问题加入对话
|
|
@@ -470,27 +573,100 @@ export default {
|
|
|
//可点击可不点击 0单选 1填空
|
|
|
disabled: false,
|
|
|
//问题
|
|
|
- question: result ? result.question : "",
|
|
|
+ question: "",
|
|
|
//头像
|
|
|
from1: HeadImg,
|
|
|
});
|
|
|
- let contant1 = document.getElementById("contant1");
|
|
|
- this.sleep(101).then(() => {
|
|
|
- contant1.scrollTop = contant1.scrollHeight;
|
|
|
- });
|
|
|
- if (!result.nextQuestionNo) {
|
|
|
- // 无下一题,查询答案
|
|
|
- this.getAnswer(result.id);
|
|
|
- } else if (/flag/g.test(result.nextQuestionNo)) {
|
|
|
- // 下一题为量表,查询量表内容
|
|
|
- this.flag = result.nextQuestionNo.split("-")[1];
|
|
|
- this.getScaleInfo(this.flag);
|
|
|
+ this.pFun(result.question, true, result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
+ //修改文本打印效果
|
|
|
+ pFun(val, flag, result) {
|
|
|
+ let that = this;
|
|
|
+ //3个循环播放
|
|
|
+ this.chatContents[this.chatContents.length - 1].question = "";
|
|
|
+ this.printIndex = 0;
|
|
|
+ // let a = val;
|
|
|
+ let a = "......";
|
|
|
+
|
|
|
+ clearInterval(this.flagTime);
|
|
|
+ this.flagTime = setInterval(
|
|
|
+ () => {
|
|
|
+ if (this.printIndex < a.length) {
|
|
|
+ this.chatContents[this.chatContents.length - 1].question +=
|
|
|
+ a.charAt(this.printIndex);
|
|
|
+ this.printIndex++;
|
|
|
+
|
|
|
+ if (a == "......") {
|
|
|
+ if (this.printIndex == 4) {
|
|
|
+ this.chatContents[this.chatContents.length - 1].question = "";
|
|
|
+ this.printIndex = 0;
|
|
|
+ a = val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
+ if (a != "......") {
|
|
|
+ let contant1 = document.getElementById("contant1");
|
|
|
+ this.sleep(101).then(() => {
|
|
|
+ contant1.scrollTop = contant1.scrollHeight;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (flag) {
|
|
|
+ that.buttonFlag = false;
|
|
|
+ //清除定时器
|
|
|
+ let contant1 = document.getElementById("contant1");
|
|
|
+ this.sleep(101).then(() => {
|
|
|
+ contant1.scrollTop = contant1.scrollHeight;
|
|
|
+ });
|
|
|
+ // this.saveRecord(this.chatContents[this.chatContents.length - 1].question)
|
|
|
+ clearInterval(this.flagTime);
|
|
|
+ // let ob = {
|
|
|
+ // label: 0,
|
|
|
+ // content:
|
|
|
+ // this.chatContents[this.chatContents.length - 1].question,
|
|
|
+ // };
|
|
|
+ // this.saveRecord(ob);
|
|
|
+ //在这判断负面情绪是否足够5个
|
|
|
+ if (this.interveneId != 5) {
|
|
|
+ let paramsSave = {
|
|
|
+ label: 0,
|
|
|
+ content: result ? result.question : "",
|
|
|
+ questionNo: result.id,
|
|
|
+ };
|
|
|
+ this.saveRecord(paramsSave);
|
|
|
+ }
|
|
|
+
|
|
|
+ // identifier: sessionStorage.getItem("num"),
|
|
|
+ // label: val.label,
|
|
|
+ // content: val.content,
|
|
|
+ // userName:sessionStorage.getItem("name"),
|
|
|
+ // questionNo: val.questionNo,
|
|
|
+ // type: this.interveneId,
|
|
|
+ if (!result.nextQuestionNo) {
|
|
|
+ // 无下一题,查询答案
|
|
|
+ this.getAnswer(result.id);
|
|
|
+
|
|
|
+ //保存所选问题的答案
|
|
|
+ } else if (/flag/g.test(result.nextQuestionNo)) {
|
|
|
+ // 下一题为量表,查询量表内容
|
|
|
+ this.flag = result.nextQuestionNo.split("-")[1];
|
|
|
+ this.getScaleInfo(this.flag);
|
|
|
+ } else {
|
|
|
+ // 下一题非量表,继续查询下一题
|
|
|
+ this.getQuestion(result.nextQuestionNo);
|
|
|
+ }
|
|
|
} else {
|
|
|
- // 下一题非量表,继续查询下一题
|
|
|
- this.getQuestion(result.nextQuestionNo);
|
|
|
+ this.printIndex = 0;
|
|
|
+ this.chatContents[this.chatContents.length - 1].question = ".";
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ flag ? 60 : 300
|
|
|
);
|
|
|
},
|
|
|
// 获取答案
|
|
@@ -525,13 +701,12 @@ export default {
|
|
|
text: "",
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
let contant1 = document.getElementById("contant1");
|
|
|
this.sleep(101).then(() => {
|
|
|
contant1.scrollTop = contant1.scrollHeight;
|
|
|
});
|
|
|
} else {
|
|
|
- this.saveChat();
|
|
|
+ // this.saveChat();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -608,9 +783,29 @@ export default {
|
|
|
},
|
|
|
|
|
|
// 选择答案
|
|
|
- chooseAnswer(id) {
|
|
|
+ chooseAnswer(val) {
|
|
|
+ let id = val.radio;
|
|
|
console.log("下一题编号");
|
|
|
console.log(id);
|
|
|
+ //循环这个数组得到选择的答案
|
|
|
+ let questionRadio = val.question;
|
|
|
+ let contentRadio = "";
|
|
|
+ let questionNo = "";
|
|
|
+ for (let i = 0; i < questionRadio.length; i++) {
|
|
|
+ if (questionRadio[i].nextQuestionNo == id) {
|
|
|
+ contentRadio = questionRadio[i].answer;
|
|
|
+ questionNo = questionRadio[i].questionNo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let paramsSave = {
|
|
|
+ label: 1,
|
|
|
+ content: contentRadio,
|
|
|
+ questionNo: questionNo,
|
|
|
+ };
|
|
|
+ //当编号是5时不需要保存
|
|
|
+ if (this.interveneId != 5) {
|
|
|
+ this.saveRecord(paramsSave);
|
|
|
+ }
|
|
|
if (id == "") {
|
|
|
this.chatContents.push({
|
|
|
//是问题还是答案
|
|
@@ -626,7 +821,7 @@ export default {
|
|
|
//头像
|
|
|
from1: HeadImg,
|
|
|
});
|
|
|
- this.saveChat();
|
|
|
+ // this.saveChat();
|
|
|
let contant1 = document.getElementById("contant1");
|
|
|
this.sleep(101).then(() => {
|
|
|
contant1.scrollTop = contant1.scrollHeight;
|