Commit 210cadac by 李伟康

提交

1 parent 7c4d2007
const url = '/router' const url = '/rop-scrm-marketing/router'
import { utils } from 'glsx-common' import { utils } from 'glsx-common'
export default { export default {
...@@ -8,6 +8,27 @@ export default { ...@@ -8,6 +8,27 @@ export default {
return httpRequest(method, data) return httpRequest(method, data)
}, },
/**
* 获取AI id
*/
getAiId (data) {
data.method = 'marketing.api.scriptlibrary.ai.id'
return window.$HTTP({
url,
data,
returnAll: true
})
},
/**
* 新增聊天记录
*/
updatedAiRecord (data) {
data.method = 'marketing.api.scriptlibrary.ai.record.add'
return window.$HTTP({
url,
data
})
},
} }
const httpRequest = (method, data) => { const httpRequest = (method, data) => {
const { secret, sign, request } = window.$fetchConfig const { secret, sign, request } = window.$fetchConfig
...@@ -16,7 +37,7 @@ const httpRequest = (method, data) => { ...@@ -16,7 +37,7 @@ const httpRequest = (method, data) => {
...sign ...sign
}) })
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
window.fetch(`${request.baseURL}/router/${method}/1.0.0`, { window.fetch(`${request.chatGptURL}/router/${method}/1.0.0`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json;charset=UTF-8' }, headers: { 'Content-Type': 'application/json;charset=UTF-8' },
body: JSON.stringify(utils.createSign(data, secret)) body: JSON.stringify(utils.createSign(data, secret))
......
...@@ -4,9 +4,15 @@ ...@@ -4,9 +4,15 @@
:class="['view',{'show-tips':showTips&& issuesList.length}]" :class="['view',{'show-tips':showTips&& issuesList.length}]"
ref="contentView" ref="contentView"
> >
<div class="content-item left">
<div class="sprite-icon icon-ai icon"></div>
<div class="content">
您可以向我提问公司的业务产品或销售等相关问题,我将给您组织语言并提供建议,您可以复制段落稍作润色并答复给您的客户。
</div>
</div>
<template v-for="(i,index) in contentList"> <template v-for="(i,index) in contentList">
<div :key="index"> <div :key="index">
<template v-if="i.speaker == 'AI'"> <template v-if="i.contentType == 1">
<div class="content-item left"> <div class="content-item left">
<div class="sprite-icon icon-ai icon"></div> <div class="sprite-icon icon-ai icon"></div>
<div class="content"> <div class="content">
...@@ -70,24 +76,40 @@ ...@@ -70,24 +76,40 @@
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import { chatgptApi } from '@/api' import { chatgptApi } from '@/api'
import * as dayjs from 'dayjs'
export default { export default {
name: 'ChatGpt', name: 'ChatGpt',
data () { data () {
return { return {
contentList: [{ contentList: [],
content: '您可以向我提问公司的业务产品或销售等相关问题,我将给您组织语言并提供建议,您可以复制段落稍作润色并答复给您的客户。',
speaker: 'AI'
}],
issuesList: window.$fetchConfig.issuesList || [], issuesList: window.$fetchConfig.issuesList || [],
showTips: true, showTips: true,
issue: '' issue: '',
scriptLibraryAIId: ''
} }
}, },
mounted () { mounted () {
this.getAiId()
}, },
methods: { methods: {
async getAiId () {
this.showLoading()
const { merchantId, uuid, merchantName, userName } = this.getLocalStorage('dj_scrm_userInfo')
try {
const { code, data, message } = await chatgptApi.getAiId({
merchantId,
merchantName,
staffUuid: uuid,
staffName: userName
})
if (code == 0 && data) this.scriptLibraryAIId = data
else throw message
this.hideLoading()
} catch (error) {
console.log(error)
this.showToast(error)
}
},
onkeydown (e) { onkeydown (e) {
if (e.keyCode == 13) { if (e.keyCode == 13) {
this.send() this.send()
...@@ -97,16 +119,20 @@ export default { ...@@ -97,16 +119,20 @@ export default {
const { issue } = this, const { issue } = this,
content = val || issue content = val || issue
if (!content) return if (!content) return
const chatTime = Date.now()
this.contentList.push({ this.contentList.push({
speaker: 'ME', contentType: 0,
content content,
chatTime: dayjs(chatTime).format('YYYY-MM-DD HH:mm:ss')
}) })
if (!val) { if (!val) {
this.issue = '' this.issue = ''
this.$refs.input.blur() this.$refs.input.blur()
} }
this.toBottom() this.toBottom()
this.toQuestionChatGPT(content) this.$nextTick(() => {
this.toQuestionChatGPT(content)
})
}, },
toBottom () { toBottom () {
this.$nextTick(() => { this.$nextTick(() => {
...@@ -116,14 +142,17 @@ export default { ...@@ -116,14 +142,17 @@ export default {
async toQuestionChatGPT (question) { async toQuestionChatGPT (question) {
const id = Date.now() const id = Date.now()
this.contentList.push({ this.contentList.push({
speaker: 'AI', contentType: 1,
id, content: '',
content: '' id
}) })
const { response } = await chatgptApi.issueChatGpt({ const { response } = await chatgptApi.issueChatGpt({
question, question,
history: '' history: ''
}) })
let questionEffectiveCount = 0
if (response.indexOf('很抱歉') == -1) questionEffectiveCount = 1
this.contentList.find(i => i.id == id).chatTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
let index = 0, speed = 10 let index = 0, speed = 10
const typeWriter = () => { const typeWriter = () => {
if (index < response.length) { if (index < response.length) {
...@@ -131,10 +160,28 @@ export default { ...@@ -131,10 +160,28 @@ export default {
index++ index++
setTimeout(typeWriter, speed) setTimeout(typeWriter, speed)
this.toBottom() this.toBottom()
} } else this.addRecord(id, questionEffectiveCount)
} }
typeWriter() typeWriter()
}, },
addRecord (id, questionEffectiveCount) {
const { contentList, scriptLibraryAIId } = this,
index = this.contentList.findIndex(i => i.id == id),
questionItem = contentList[index - 1],
answerItem = contentList[index],
lastQuestionTime = dayjs(questionItem.chatTime).format('YYYY-MM-DD HH:mm:ss')
delete answerItem.id
// aiRecordList[index - 1] = questionItem
// aiRecordList[index] = answerItem
chatgptApi.updatedAiRecord({
scriptLibraryAIId,
lastQuestionTime,
aiRecordList: [questionItem, answerItem],
questionCount: 1,
questionEffectiveCount
})
}
} }
} }
</script> </script>
......
...@@ -11,8 +11,8 @@ module.exports = { ...@@ -11,8 +11,8 @@ module.exports = {
title: '嘻嘻', title: '嘻嘻',
envVersion: 'trial', envVersion: 'trial',
request: { request: {
baseURL: '//192.168.1.124:7860', // 本地测试项目地址, // baseURL: '//192.168.3.191:7860', // 本地测试项目地址,
// baseURL: '//scrm.test.glsx.com.cn', // 本地测试项目地址, baseURL: '//scrm.dev.glsx.com.cn', // 本地测试项目地址,
// 设置超时时间 // 设置超时时间
timeout: 180000, timeout: 180000,
...@@ -20,7 +20,11 @@ module.exports = { ...@@ -20,7 +20,11 @@ module.exports = {
withCredentials: true, withCredentials: true,
// 返回数据类型 // 返回数据类型
responseType: 'json', responseType: 'json',
chatGptURL:'//chatgpt.dev.glsx.com.cn',
/**
* 开发//chatgpt.dev.glsx.com.cn
* 测试//chatgpt.dev.glsx.com.cn
*/
ropMerchantURL: 'http://rop-merchant.dev.glsx.com.cn' ropMerchantURL: 'http://rop-merchant.dev.glsx.com.cn'
/** /**
* 开发:http://rop-merchant.dev.glsx.com.cn * 开发:http://rop-merchant.dev.glsx.com.cn
...@@ -47,7 +51,7 @@ module.exports = { ...@@ -47,7 +51,7 @@ module.exports = {
source: "scrm-main", source: "scrm-main",
v: "1.0.0", v: "1.0.0",
}, },
vconsole: false, vconsole: true,
issuesList: [ issuesList: [
'你这个保险有点贵啊,好像别人那里都没有那么高的价格。', '你这个保险有点贵啊,好像别人那里都没有那么高的价格。',
'我这个保险在外面朋友买没那么便宜。', '我这个保险在外面朋友买没那么便宜。',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!