|
|
@@ -17,24 +17,14 @@
|
|
|
:class="'intelligent_chat_view' + index"
|
|
|
>
|
|
|
<view :class="item.left ? 'robot_word' : 'patient_word'">
|
|
|
- <view v-if="item.msg">
|
|
|
+ <view v-if="item.type === 'img' && item.data">
|
|
|
<view>
|
|
|
- {{ item.msg }}
|
|
|
+ <image :src="item.data.url" class="img-msg" mode="widthFix" />
|
|
|
</view>
|
|
|
</view>
|
|
|
- <view v-else>
|
|
|
+ <view v-if="item.msg">
|
|
|
<view>
|
|
|
- {{ item.title }}
|
|
|
- </view>
|
|
|
- <view v-if="item.data">
|
|
|
- <view v-for="(data, data_index) in item.data" :key="data.id">
|
|
|
- <view
|
|
|
- class="keyHighlight"
|
|
|
- v-html="data.keyHighlight"
|
|
|
- v-if="data.keyHighlight"
|
|
|
- @click="keyHighlight(data, data_index)"
|
|
|
- ></view>
|
|
|
- </view>
|
|
|
+ {{ item.msg }}
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -72,6 +62,7 @@
|
|
|
<script lang="ts">
|
|
|
import { Component } from "vue-property-decorator";
|
|
|
import AccountMixin from "@/mixins/account";
|
|
|
+import { textToImage } from "@/apis/base";
|
|
|
|
|
|
@Component({})
|
|
|
export default class HomeView extends AccountMixin {
|
|
|
@@ -79,18 +70,12 @@ export default class HomeView extends AccountMixin {
|
|
|
// 输入框距底部高度(键盘显示隐藏高度变化)
|
|
|
bottom = "0px";
|
|
|
// 对话框数组
|
|
|
- msg_list = [
|
|
|
- {
|
|
|
- left: true,
|
|
|
- msg: "嗨~我是小助,您身边的智能助手~",
|
|
|
- data: null,
|
|
|
- },
|
|
|
- {
|
|
|
- left: true,
|
|
|
- msg: "请问有什么可以帮助您的?",
|
|
|
- data: null,
|
|
|
- },
|
|
|
- ];
|
|
|
+ msg_list: {
|
|
|
+ left: boolean;
|
|
|
+ msg: string;
|
|
|
+ type?: "text" | "img";
|
|
|
+ data?: { url: string };
|
|
|
+ }[] = [];
|
|
|
// 容器高度
|
|
|
key_height = "0px";
|
|
|
// 容器滚动底部定位id
|
|
|
@@ -154,7 +139,6 @@ export default class HomeView extends AccountMixin {
|
|
|
this.key_height = `${res_keyboard.windowHeight - this.inputHeight}px`;
|
|
|
}
|
|
|
|
|
|
- console.log(this.key_height);
|
|
|
this.num = this.msg_list.length;
|
|
|
this.bottomId = "dade" + this.num;
|
|
|
});
|
|
|
@@ -176,8 +160,15 @@ export default class HomeView extends AccountMixin {
|
|
|
// 换id
|
|
|
this.controlId = false;
|
|
|
}
|
|
|
+ async getImg() {
|
|
|
+ const res = await textToImage({
|
|
|
+ q: this.value.toString().trim(),
|
|
|
+ });
|
|
|
+ console.log(res);
|
|
|
+ }
|
|
|
// input发送事件
|
|
|
async input_send() {
|
|
|
+ this.getImg();
|
|
|
if (!this.value.toString()) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -192,84 +183,26 @@ export default class HomeView extends AccountMixin {
|
|
|
{
|
|
|
left: false,
|
|
|
msg: this.value,
|
|
|
- data: null,
|
|
|
},
|
|
|
];
|
|
|
- // 如果你们没有网络请求,----------------
|
|
|
- if (this.value.match(/你好|您好/)) {
|
|
|
+ const res = await textToImage({
|
|
|
+ q: this.value.trim(),
|
|
|
+ });
|
|
|
+ if (res.errno === 10000) {
|
|
|
this.msg_list = [
|
|
|
...this.msg_list,
|
|
|
- {
|
|
|
- left: true,
|
|
|
- msg: "您好,我是小助,您有什么问题可以直接问我哦~",
|
|
|
- data: null,
|
|
|
- },
|
|
|
- ];
|
|
|
- } else {
|
|
|
- this.msg_list = [
|
|
|
- ...this.msg_list,
|
|
|
- {
|
|
|
- left: true,
|
|
|
- msg: "没有找到该问题答案,请换种问法试一试。",
|
|
|
- data: null,
|
|
|
- },
|
|
|
+ ...res.data.imgs.map((data) => {
|
|
|
+ return {
|
|
|
+ left: true,
|
|
|
+ msg: "",
|
|
|
+ type: "img",
|
|
|
+ data,
|
|
|
+ } as (typeof this.msg_list)[number];
|
|
|
+ }),
|
|
|
];
|
|
|
}
|
|
|
this.value = "";
|
|
|
- this.num = this.msg_list.length;
|
|
|
- this.bottomId = "dade" + this.num;
|
|
|
-
|
|
|
- timer = setTimeout(() => {
|
|
|
- this.boolen = true;
|
|
|
- }, 300);
|
|
|
- // 如果你们有网络请求,把下边的注开----------------------------------------------
|
|
|
-
|
|
|
- // // 注释掉的是网络请求,如果直接粘贴会报错,所以我就注掉了这就不会报错了
|
|
|
- // let res = await this.$api.disease_keyword({
|
|
|
- // keyword: this.value
|
|
|
- // })
|
|
|
- // console.log(res);
|
|
|
- // if (res.code == 200) {
|
|
|
- // if (Array.isArray(res.data) && res.data.length > 0) {
|
|
|
- // // 替换高亮,增加样式
|
|
|
- // res.data.forEach((v, i) => {
|
|
|
- // if (v.keyHighlight && v.keyHighlight.match(/em/)) {
|
|
|
- // v.keyHighlight = v.keyHighlight.replace(/<em>/,
|
|
|
- // '<strong style="color: #F07828;">')
|
|
|
- // v.keyHighlight = v.keyHighlight.replace(/<\/em>/, '</strong>')
|
|
|
- // }
|
|
|
- // })
|
|
|
- // // 增加回答,机器人回答的话
|
|
|
- // this.msg_list = [...this.msg_list, {
|
|
|
- // left: true,
|
|
|
- // title: `以下是关于“${this.value}”的解答:`,
|
|
|
- // data: res.data
|
|
|
- // }]
|
|
|
- // } else {
|
|
|
- // // 提示,没有找到该问题答案
|
|
|
- // if (this.value.match(/你好|您好/)) {
|
|
|
- // this.msg_list = [...this.msg_list, {
|
|
|
- // left: true,
|
|
|
- // msg: '您好,我是小助,您有什么问题可以直接问我哦~',
|
|
|
- // data: null
|
|
|
- // }]
|
|
|
- // } else {
|
|
|
- // this.msg_list = [...this.msg_list, {
|
|
|
- // left: true,
|
|
|
- // msg: '没有找到该问题答案,请换种问法试一试。',
|
|
|
- // data: null
|
|
|
- // }]
|
|
|
- // }
|
|
|
- // }
|
|
|
- // this.value = '';
|
|
|
- // this.num = this.msg_list.length;
|
|
|
- // this.bottomId = 'dade' + (this.num);
|
|
|
- // } else {
|
|
|
- // // 出什么问题,toast出来
|
|
|
- // }
|
|
|
- // timer = setTimeout(() => {
|
|
|
- // this.boolen = true
|
|
|
- // }, 300)
|
|
|
+ this.boolen = true;
|
|
|
}
|
|
|
}
|
|
|
}
|