Browse Source

Merge branch 'maziyang/feature-20251025172218-智能客服中台' into milestone-20251031-简版功能开发

lihuilin/feature-20251024095243-我的
maziyang 3 weeks ago
parent
commit
11763822cf
  1. 4
      api/customerServicePlatform/customerServicePlatform.js
  2. 57
      pages/customerServicePlatform/questionDetail.vue

4
api/customerServicePlatform/customerServicePlatform.js

@ -14,7 +14,7 @@ export const uploadImageApi = (data) => {
export const getAnswerApi = (data) => {
return http({
method: 'POST',
url: 'http://pbb6edde.natappfree.cc' +'/api/customer/askQuestion',
url: '/api/customer/askQuestion',
data
})
}
@ -23,7 +23,7 @@ export const getAnswerApi = (data) => {
export const getQuestionApi = (data) => {
return http({
method: 'GET',
url: 'http://pbb6edde.natappfree.cc' +'/api/customer/getQuestion',
url: '/api/customer/getQuestion',
})
}

57
pages/customerServicePlatform/questionDetail.vue

@ -45,9 +45,12 @@
mode="aspectFit"></image>
<view class="card-text">
<text class="card-paragraph">
<rich-text :nodes="renderMarkdown(answerContent)"></rich-text>
<!-- <text class="card-paragraph">
{{answerContent}}
</text>
</text> -->
</view>
</view>
@ -65,6 +68,8 @@
import {
getAnswerApi
} from "../../api/customerServicePlatform/customerServicePlatform";
import marked from "marked"; // marked
export default {
data() {
return {
@ -90,6 +95,29 @@
}
},
methods: {
renderMarkdown(content) {
const renderer = new marked.Renderer();
// renderer.heading = function (text, level) {
// return `<p>${text}</p>`;
// };
// marked
marked.setOptions({
renderer: renderer,
highlight: null, //
langPrefix: "language-",
pedantic: false,
gfm: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false,
});
if (!content) return "";
let renderedContent = marked.parse(content);
renderedContent = renderedContent.replace(/\*/g, '');
return renderedContent;
},
async getAnswerContent() {
let conversationId = '';
try {
@ -98,7 +126,7 @@
} catch (e) {
conversationId = '';
}
try {
const res = await getAnswerApi({
question: this.questionTitle,
conversationId: conversationId,
@ -108,18 +136,29 @@
if (res.code == 200) {
uni.setStorageSync('conversationId', res.data.conversationId);
const answer = res.data.answer
this.answerContent = '';
for (let i = 0; i < answer.length; i++) {
this.answerContent += answer[i];
await this.sleepTime();
//
let currentIndex = 0;
const answerLength = answer.length;
//
this.interval = setInterval(() => {
this.answerContent = answer.slice(0, currentIndex);
currentIndex++;
if (currentIndex > answerLength) {
clearInterval(this.interval);
}
}, Math.floor(Math.random() * (150 - 30 + 1)) + 30);
} else {
this.answerContent = '获取回答失败,请重试';
}
} catch {
this.answerContent = '获取回答失败,请重试';
}
},
async sleepTime() {
sleepTime() {
const ms = Math.floor(Math.random() * (300 - 30 + 1)) + 30;
return new Promise(resolve => setTimeout(resolve, ms));
return ms;
},
toRegistration() {

Loading…
Cancel
Save