2023-07-26 15:54:34 +08:00
< template >
2023-12-08 16:27:35 +08:00
< div class = "robot Guide_1_1_1" :class = "[driver__.driver?'showEvents':'']" @mousemove ="robotmax" >
2023-07-26 15:54:34 +08:00
< div class = "robot_top" ref = "robotDom" v-fade = "robotTop,'block'" >
2023-10-11 17:34:14 +08:00
< div : class = "[item.state == 1?'text_right':'text_left',item.img?'white':'']" v-for = "item,index in record" ref="robotChildDom" >
2023-09-26 15:05:14 +08:00
< div class = "robot_text" >
< span >
{ { item . str } }
2023-11-20 09:47:10 +08:00
< a v-if = "item.src" :href="item.src" target="_blank"><i class="fi fi-br-link-alt" > < / i > < / a >
2023-09-26 15:05:14 +08:00
< / span >
2023-12-08 16:27:35 +08:00
< span class = "driver__" v-if = "driver__.driver" >
{ { item . str } }
< div class = "driver__btn" v-if = "item.driver" >
< span @click ="setDriver" >
Yes
< / span >
< span @click ="removeDriver" >
No
< / span >
< / div >
< / span >
2023-10-11 17:34:14 +08:00
< div class = "robot_img" : class = "[item.img ?'img':'']" >
< div class = "robot_img_item" v-for = "imgItem,imgIndex in item.img" >
< img :src = "imgItem.presignedUrl" alt = "" >
2023-09-26 15:05:14 +08:00
< div
class = "delete_like_file_block"
>
2023-10-11 17:34:14 +08:00
< i v-if = "imgItem.id == null" class="fi fi-rr-heart" @click.stop="likeFile(imgItem,imgIndex,index)" > < / i >
< i v-else class = "fi fi-sr-heart" @click.stop ="likeFile(imgItem,imgIndex,index)" > < / i >
2023-09-26 15:05:14 +08:00
< / div >
< / div >
< / div >
< / div >
2023-07-26 15:54:34 +08:00
< / div >
< / div >
2023-10-11 17:34:14 +08:00
< div class = "robot_content" >
< div :style = "'width:'+bloodBars+'%;'" > < / div >
< / div >
2023-07-26 15:54:34 +08:00
< div class = "robot_bottom" >
< div class = "robot_input" v-fade = "robotInput,'flex'" >
< input
2023-10-30 17:26:36 +08:00
: placeholder = "$t('RobotAssist.inputContent1')"
2023-07-26 15:54:34 +08:00
v - model = "chatCentent"
@ keydown . enter = "roborSend()"
@ input = "robotmax"
/ >
< div class = "robot_btn" >
< i class = "fi fi-ss-paper-plane-top" @click ="roborSend" > < / i >
< / div >
< / div >
< div class = "robot_img" >
< img src = "@/assets/images/homePage/robot.png" @click ="robotBtn" >
< / div >
< / div >
< / div >
< / template >
< script lang = "ts" >
2023-11-23 11:15:10 +08:00
import { defineComponent , createVNode , computed , ref , Ref } from "vue" ;
2023-07-26 15:54:34 +08:00
import { UserOutlined , DownOutlined } from "@ant-design/icons-vue" ;
import { Https } from "@/tool/https" ;
import { getCookie } from "@/tool/cookie" ;
2023-11-23 11:15:10 +08:00
import { useStore } from "vuex" ;
2023-07-26 15:54:34 +08:00
import { message } from "ant-design-vue" ;
2023-12-08 16:27:35 +08:00
import { openGuide , driverObj _ _ } from "@/tool/guide" ;
2023-10-30 17:26:36 +08:00
import { useI18n } from "vue-i18n" ;
2023-07-26 15:54:34 +08:00
export default defineComponent ( {
components : {
DownOutlined ,
UserOutlined ,
} ,
setup ( ) {
const robotDom = ref < HTMLElement | null > ( null ) ;
const robotChildDom = ref < HTMLElement | null > ( null ) ;
let chatCentent = ref < string > ( '' ) ;
const robotTop = ref ( false )
const robotInput = ref ( false )
let timeTop : any = 0 ;
let timeInput : any = 0 ;
2023-09-12 10:09:02 +08:00
let record : any = ref ( [
2023-10-11 17:34:14 +08:00
2023-07-26 15:54:34 +08:00
] )
const userInfo : any = { }
2023-10-11 17:34:14 +08:00
let bloodBars : any = ref ( 0 )
2023-10-30 17:26:36 +08:00
let { t } = useI18n ( )
2023-11-20 09:47:10 +08:00
let isTest = ref ( )
2023-11-23 11:15:10 +08:00
let store = useStore ( )
let workspace : any = ref ( { } )
2023-12-08 16:27:35 +08:00
let driver _ _ : any = computed ( ( ) => {
return store . state . Guide . guide
} )
let driver _ _Time : any = ref ( )
2023-07-26 15:54:34 +08:00
return {
robotTop ,
robotInput ,
chatCentent ,
2023-09-12 10:09:02 +08:00
record ,
2023-07-26 15:54:34 +08:00
robotDom ,
robotChildDom ,
timeTop ,
timeInput ,
userInfo ,
2023-10-11 17:34:14 +08:00
bloodBars ,
2023-10-30 17:26:36 +08:00
t ,
2023-11-20 09:47:10 +08:00
isTest ,
2023-11-23 11:15:10 +08:00
store ,
2023-12-08 16:27:35 +08:00
workspace ,
driver _ _ ,
driver _ _Time
2023-07-26 15:54:34 +08:00
} ;
} ,
data ( ) {
return {
} ;
} ,
2023-12-08 16:27:35 +08:00
watch : {
driver _ _ : {
handler : function ( newval ) {
console . log ( this . driver _ _ ) ;
if ( this . driver _ _ . driver && this . driver _ _ . index == 0 ) {
this . robotTop = true
this . robotInput = true
driverObj _ _ . refresh ( ) ;
this . record . push ( {
state : 1 ,
2023-12-12 13:26:29 +08:00
str : "Welcome to the AiDA system, your friendly fashion design assistant at your service! If you have any questions or need assistance, please don't hesitate to ask. " ,
driver : false ,
2023-12-08 16:27:35 +08:00
} )
2023-12-12 13:26:29 +08:00
this . textScroll ( )
setTimeout ( ( ) => {
this . record . push ( {
state : 1 ,
str : "I see you might be new here, and I'd love to guide you through a tutorial to help you get acquainted with our new and improved AiDA system. How does that sound? Would you like to start the tutorial now?" ,
driver : true ,
} )
this . textScroll ( )
} , 1000 ) ;
2023-12-08 16:27:35 +08:00
this . driver _ _Time = setInterval ( ( ) => {
this . $nextTick ( ) . then ( ( ) => {
driverObj _ _ . refresh ( ) ;
} )
this . createTimer ( )
} , 3000 ) ;
} else {
clearTimeout ( this . driver _ _Time )
}
2023-12-12 13:26:29 +08:00
if ( ! newval . driver ) {
this . record . push ( {
state : 1 ,
str : "You can start the tutorial at any time by simply telling me that you want to. " ,
driver : false ,
} )
clearTimeout ( this . driver _ _Time )
}
2023-12-08 16:27:35 +08:00
}
}
} ,
2023-07-26 15:54:34 +08:00
mounted ( ) {
this . textScroll ( )
let userInfo : any = getCookie ( "userInfo" )
2023-11-20 09:47:10 +08:00
let isTest : any = getCookie ( 'isTest' )
this . isTest = JSON . parse ( isTest ) || ''
2023-07-26 15:54:34 +08:00
this . userInfo = JSON . parse ( userInfo ) ;
2023-10-11 17:34:14 +08:00
if ( sessionStorage . getItem ( "record" ) == null ) {
this . record = [ ]
} else {
this . record = JSON . parse ( sessionStorage . getItem ( "record" ) as string )
}
this . getBloodBars ( )
2023-11-23 11:15:10 +08:00
this . workspace = computed ( ( ) => {
return this . store ? . state ? . Workspace ? . workspace
} )
2023-12-08 16:27:35 +08:00
2023-07-26 15:54:34 +08:00
} ,
directives : {
fade : {
updated ( el , oldVal ) {
if ( oldVal . value ) {
el . style . display = oldVal . arg
setTimeout ( ( ) => {
el . classList . add ( "active" )
} , 100 ) ;
} else {
el . classList . remove ( "active" )
setTimeout ( ( ) => {
el . style . display = "none"
} , 100 ) ;
}
}
}
} ,
methods : {
robotBtn ( ) {
if ( ! this . robotTop || ! this . robotInput ) {
this . robotTop = true
this . robotInput = true
} else {
this . robotTop = false
this . robotInput = false
}
2023-09-26 15:05:14 +08:00
// let noRefresh = false;
// this.$router.push({ name: 'library', params: { noRefresh: false } });
2023-07-26 15:54:34 +08:00
this . textScroll ( ) //聊天定位到最低部
this . createTimer ( )
} ,
2023-10-11 17:34:14 +08:00
getBloodBars ( ) {
2023-10-20 17:21:45 +08:00
Https . axiosGet ( Https . httpUrls . getBloodBars , { params : { userId : this ? . userInfo ? . userId } } ) . then ( ( rv : any ) => {
2023-10-11 17:34:14 +08:00
if ( rv ) {
this . bloodBars = rv * 100
}
} )
} ,
2023-07-26 15:54:34 +08:00
textScroll ( ) {
this . $nextTick ( ( ) => {
if ( this . robotDom && this . robotChildDom ) {
2023-09-26 15:05:14 +08:00
// const items = this.robotChildDom._rawValue
let num = 0
for ( let index = 0 ; index < ( this . $refs . robotChildDom as any ) . length ; index ++ ) {
const height = ( this . $refs . robotChildDom as any ) [ index ] . clientHeight ;
num = num + 40 + height
}
this . robotDom . scrollTop = num
2023-07-26 15:54:34 +08:00
}
} )
} ,
robotmax ( ) { //点击内容就设置为true显示 重置定时器
this . createTimer ( )
} ,
roborSend ( ) {
2023-09-12 10:09:02 +08:00
this . clearTimer ( )
2023-07-26 15:54:34 +08:00
if ( ! this . chatCentent ) {
2023-11-16 17:23:17 +08:00
message . info ( this . t ( 'RobotAssist.jsContent1' ) ) ;
2023-07-26 15:54:34 +08:00
return
}
2023-09-12 10:09:02 +08:00
this . record . push ( {
2023-07-26 15:54:34 +08:00
state : 2 ,
str : this . chatCentent
} )
2023-09-25 10:09:00 +08:00
this . textScroll ( )
2023-09-26 15:05:14 +08:00
let sessionId
if ( sessionStorage . getItem ( "sessionId" ) == null ) {
let randomNum : any = Math . floor ( Math . random ( ) * 9000000000000000 ) + 1000000000000000 ;
sessionStorage . setItem ( 'sessionId' , randomNum ) ;
sessionId = randomNum
} else {
sessionId = sessionStorage . getItem ( "sessionId" )
}
// sessionStorage.setItem('username', '23123123123');
// sessionStorage.getItem("username")
// sessionStorage.removeItem
2023-07-26 15:54:34 +08:00
let a = true
let data = {
2023-10-20 17:21:45 +08:00
"user_id" : this . userInfo ? . userId ,
2023-09-26 15:05:14 +08:00
"session_id" : sessionId ,
2023-09-12 10:09:02 +08:00
"message" : this . chatCentent ,
2023-11-23 11:15:10 +08:00
gender : this . workspace . sexEnum . name ,
2023-07-26 15:54:34 +08:00
}
let interaction = { onDownloadProgress : ( progressEvent : any ) => {
this . clearTimer ( )
2023-09-25 10:09:00 +08:00
// console.log(progressEvent.event.currentTarget.response);
2023-08-05 12:52:56 +08:00
// if(a){
2023-09-12 10:09:02 +08:00
// this.record.push({
2023-08-05 12:52:56 +08:00
// state:1,
// str:progressEvent.event.currentTarget.response
// })
// a = false
// }else{
2023-09-12 10:09:02 +08:00
// this.record[this.record.length].str = progressEvent.event.currentTarget.response
2023-08-05 12:52:56 +08:00
// }
2023-07-26 15:54:34 +08:00
} ,
}
2023-11-20 09:47:10 +08:00
if ( this . isTest ) { //试用用户禁止使用
// message.warning(
// this.t('isTest.available')
// );
this . record . push ( {
state : 1 ,
str : this . t ( 'isTest.src' ) ,
src : 'https://code-create.com.hk/aida/'
} )
this . createTimer ( )
this . textScroll ( )
this . chatCentent = ""
return
}
2023-09-25 10:09:00 +08:00
Https . axiosPost ( Https . httpUrls . chatStreamTest , data ) . then (
// Https.axiosPost(Https.httpUrls.pythonChatStream, data,interaction).then(
( rv ) => {
if ( rv ) {
2023-10-11 17:34:14 +08:00
if ( rv . chatRobotLibraryList != null ) {
this . record . push ( {
state : 1 ,
img : rv . chatRobotLibraryList
} )
} else {
this . record . push ( {
state : 1 ,
str : rv . output ,
} )
}
sessionStorage . setItem ( 'record' , JSON . stringify ( this . record ) ) ;
2023-09-25 10:09:00 +08:00
this . createTimer ( )
this . textScroll ( )
2023-10-11 17:34:14 +08:00
this . getBloodBars ( )
2023-09-25 10:09:00 +08:00
}
}
) . catch ( res => {
} ) ;
2023-07-26 15:54:34 +08:00
this . chatCentent = ""
} ,
2023-12-08 16:27:35 +08:00
setDriver ( ) {
if ( this . driver _ _ . driver ) {
driverObj _ _ . moveNext ( ) ;
this . robotTop = false
this . robotInput = false
}
} ,
removeDriver ( ) {
if ( this . driver _ _ . driver ) {
driverObj _ _ . destroy ( ) ;
2023-12-11 10:24:04 +08:00
let data = {
index : 0 ,
driver : false ,
}
this . store ? . commit ( "setGuide" , data ) ;
2023-12-12 13:26:29 +08:00
// this.robotTop = false
// this.robotInput = false
this . createTimer ( )
2023-12-08 16:27:35 +08:00
}
} ,
2023-10-11 17:34:14 +08:00
likeFile ( item : any , imgIndex : number , index : number ) {
let data = {
... item ,
2023-10-20 17:21:45 +08:00
"userId" : this . userInfo ? . userId ,
2023-10-11 17:34:14 +08:00
}
Https . axiosPost ( Https . httpUrls . pictureLikeOrUnLike , data ) . then (
( rv ) => {
if ( this . record [ index ] . img [ imgIndex ] . id == null ) {
this . record [ index ] . img [ imgIndex ] . id = rv . id
} else {
this . record [ index ] . img [ imgIndex ] . id = null
2023-09-26 15:05:14 +08:00
}
2023-10-11 17:34:14 +08:00
sessionStorage . setItem ( 'record' , JSON . stringify ( this . record ) ) ;
2023-09-26 15:05:14 +08:00
}
2023-10-11 17:34:14 +08:00
) . catch ( res => {
} ) ;
2023-09-26 15:05:14 +08:00
} ,
2023-07-26 15:54:34 +08:00
//创建定时器
createTimer ( ) {
if ( this . robotTop || this . robotInput ) {
this . clearTimer ( )
this . timeTop = setInterval ( ( ) => {
this . robotTop = false
2023-10-13 17:06:44 +08:00
} , 15000 ) ;
2023-07-26 15:54:34 +08:00
this . timeInput = setInterval ( ( ) => {
this . robotInput = false
2023-10-13 17:06:44 +08:00
} , 10000 ) ;
2023-07-26 15:54:34 +08:00
}
} ,
//清除定时器
clearTimer ( ) {
clearInterval ( this . timeTop ) ;
clearInterval ( this . timeInput ) ;
} ,
} ,
} ) ;
< / script >
< style lang = "less" scoped >
. robot {
position : absolute ;
2023-08-05 12:52:56 +08:00
bottom : .5 rem ;
// bottom: 2.5rem;
right : 2.5 rem ;
// right: 5rem;
2023-11-24 17:32:57 +08:00
z - index : 10003 ;
2023-07-26 15:54:34 +08:00
// width: 400px;
. robot _top {
2023-09-26 15:05:14 +08:00
// width: 25rem;
width : 30 rem ;
2023-07-26 15:54:34 +08:00
margin - left : auto ;
2023-09-26 15:05:14 +08:00
// height: 20rem;
2023-07-26 15:54:34 +08:00
overflow - x : hidden ;
transition : .3 s all ;
opacity : 0 ;
2023-10-11 17:34:14 +08:00
height : auto ;
max - height : 30 rem ;
2023-07-26 15:54:34 +08:00
display : none ;
& . active {
opacity : 1 ;
}
& . robot _top : : - webkit - scrollbar { display : none ; }
. robot _text {
2023-08-05 12:52:56 +08:00
font - size : 1.4 rem ;
2023-09-26 15:05:14 +08:00
padding : 1 rem 1.5 rem ;
2023-07-26 15:54:34 +08:00
display : inline - block ;
2023-08-05 12:52:56 +08:00
border - radius : 2 rem ;
2023-07-26 15:54:34 +08:00
max - width : 80 % ;
2023-09-26 15:05:14 +08:00
. robot _img {
display : flex ;
flex - wrap : wrap ;
align - items : center ;
justify - content : center ;
2023-10-11 17:34:14 +08:00
& . img {
width : 18 rem ;
}
2023-09-26 15:05:14 +08:00
. robot _img _item {
max - height : 100 % ;
position : relative ;
width : 40 % ;
2023-10-11 17:34:14 +08:00
overflow : hidden ;
margin : 0 5 % ;
margin - bottom : 5 % ;
2023-09-26 15:05:14 +08:00
& : hover . delete _like _file _block {
display : block ;
}
}
img {
width : 100 % ;
height : 8 rem ;
object - fit : contain ;
cursor : auto ;
// width: auto;
}
img : nth - child ( 2 n - 1 ) {
// margin-right: 5%;
}
}
2023-12-08 16:27:35 +08:00
. driver _ _ {
. driver _ _btn {
width : 100 % ;
margin - top : 1 rem ;
display : flex ;
justify - content : space - around ;
span {
font - size : 1.4 em ;
color : # 9 efff4 ;
cursor : pointer ;
}
}
}
2023-07-26 15:54:34 +08:00
}
. text _left , . text _right {
2023-08-05 12:52:56 +08:00
margin : 2 rem 0 ;
font - size : 1.2 rem ;
2023-07-26 15:54:34 +08:00
}
. text _left {
display : flex ;
justify - content : flex - start ;
> div {
background - color : # e8e8ea ;
color : # 000 ;
}
}
. text _right {
display : flex ;
justify - content : flex - end ;
> div {
background - color : # 835 ff7 ;
color : # fff ;
}
2023-10-11 17:34:14 +08:00
& . white {
> div {
background - color : # fff ;
}
}
2023-07-26 15:54:34 +08:00
}
}
2023-10-11 17:34:14 +08:00
. robot _content {
opacity : 0 ;
width : 8 rem ;
height : 1.1 rem ;
border - radius : 2 rem ;
overflow : hidden ;
border : .2 rem solid ;
background : # 341 e57 ;
display : flex ;
justify - content : flex - end ;
margin - left : auto ;
transition : all .3 s ;
> div {
background : linear - gradient ( 45 deg , # eee4f3 , # f3f4e6 ) ;
height : 100 % ;
width : 80 % ;
border - radius : 2 rem ;
}
}
& . robot : hover . robot _content {
opacity : 1 ;
}
2023-07-26 15:54:34 +08:00
. robot _bottom {
display : flex ;
align - items : center ;
}
. robot _input {
border : 1 px solid # d5d5d7 ;
display : flex ;
align - items : center ;
justify - content : space - between ;
2023-10-20 17:21:45 +08:00
padding : .5 rem 1 rem ;
2023-07-26 15:54:34 +08:00
background : # fff ;
border - radius : 5 px ;
// height: 32px;
transition : .3 s all ;
opacity : 0 ;
display : none ;
2023-08-05 12:52:56 +08:00
margin - right : 4 rem ;
2023-07-26 15:54:34 +08:00
& . active {
opacity : 1 ;
}
input {
border : none ;
2023-08-05 12:52:56 +08:00
font - size : 1.2 rem ;
width : 25 rem ;
2023-07-26 15:54:34 +08:00
}
. robot _btn {
display : flex ;
height : 100 % ;
cursor : pointer ;
}
. fi - ss - paper - plane - top {
display : flex ;
align - items : center ;
}
. fi - ss - paper - plane - top : : before {
color : # 835 df8 ;
}
}
. robot _img {
margin - left : auto ;
img {
2023-08-05 12:52:56 +08:00
width : 8 rem ;
2023-07-26 15:54:34 +08:00
// margin-left: 40px;
cursor : pointer ;
}
}
}
< / style >