diff --git a/ci/project.config.json b/ci/project.config.json index 6e07504..8fb78ef 100644 --- a/ci/project.config.json +++ b/ci/project.config.json @@ -1,3 +1,3 @@ { - "version": "0.0.80" + "version": "0.0.83" } \ No newline at end of file diff --git a/dist/build/mp-weixin/app.json b/dist/build/mp-weixin/app.json index b20c5fc..31ca5d0 100644 --- a/dist/build/mp-weixin/app.json +++ b/dist/build/mp-weixin/app.json @@ -6,6 +6,7 @@ "pages/forward/index", "pages/me/index", "pages/ai/chat", + "pages/ai/index", "pages/web_view/index" ], "subPackages": [ @@ -95,7 +96,7 @@ "selectedIconPath": "/static/tabbar/home_active.png" }, { - "pagePath": "pages/ai/chat", + "pagePath": "pages/ai/index", "text": "管家在线", "iconPath": "/static/tabbar/news_active.png", "selectedIconPath": "/static/tabbar/news_active.png" diff --git a/dist/build/mp-weixin/common/libraries/request.js b/dist/build/mp-weixin/common/libraries/request.js index f43e9dd..bfbc15a 100644 --- a/dist/build/mp-weixin/common/libraries/request.js +++ b/dist/build/mp-weixin/common/libraries/request.js @@ -1 +1 @@ -"use strict";const e=require("../vendor.js"),r=require("../store/useWeAppAuthStore.js"),t=new e.Request;t.setConfig((e=>(e.baseURL="https://weapp-api.linyikj.com.cn/api/",e.header={...e.header},e))),t.interceptors.request.use((r=>(r.header={...r.header,Authorization:"Bearer "+e.index.getStorageSync("NCHL_TEST_ACCESS_TOKEN_CUSTOMER")},r)),(e=>Promise.reject(e))),t.interceptors.response.use((t=>{const o=t.data;if(e.index.hideLoading(),!0!==o.success){if(10001===o.errorCode){r.useWeAppAuthStore().loading=!1,e.index.showToast({title:o.errorMessage,icon:"none"})}else e.index.showToast({title:o.errorMessage,icon:"none"});return Promise.reject(t.data)}return t.data}),(e=>{console.log("error",e);return r.useWeAppAuthStore().loading=!1,Promise.reject(e)})),exports.request=function(e,r){return t.post(e,r.data)}; +"use strict";const e=require("../vendor.js"),r=require("../store/useWeAppAuthStore.js"),t=new e.Request;t.setConfig((e=>(e.baseURL="https://weapp-api.linyikj.com.cn/api/",e.header={...e.header},e))),t.interceptors.request.use((r=>(r.header={...r.header,Authorization:"Bearer "+e.index.getStorageSync("NCHL_PROD_ACCESS_TOKEN_CUSTOMER")},r)),(e=>Promise.reject(e))),t.interceptors.response.use((t=>{const o=t.data;if(e.index.hideLoading(),!0!==o.success){if(10001===o.errorCode){r.useWeAppAuthStore().loading=!1,e.index.showToast({title:o.errorMessage,icon:"none"})}else e.index.showToast({title:o.errorMessage,icon:"none"});return Promise.reject(t.data)}return t.data}),(e=>{console.log("error",e);return r.useWeAppAuthStore().loading=!1,Promise.reject(e)})),exports.request=function(e,r){return t.post(e,r.data)}; diff --git a/dist/build/mp-weixin/common/libraries/setTabBar.js b/dist/build/mp-weixin/common/libraries/setTabBar.js index 33a8f53..6083b75 100644 --- a/dist/build/mp-weixin/common/libraries/setTabBar.js +++ b/dist/build/mp-weixin/common/libraries/setTabBar.js @@ -1 +1 @@ -"use strict";let t=[{pagePath:"/pages/index/index",iconPath:"/static/tabbar/home_icon.png",selectedIconPath:"/static/tabbar/home_active.png",text:"首页"},{pagePath:"/pages/ai/chat",iconPath:"/static/tabbar/news_icon.png",selectedIconPath:"/static/tabbar/news_active.png",text:"管家在线"},{pagePath:"/pages/me/index",iconPath:"/static/tabbar/news_icon.png",selectedIconPath:"/static/tabbar/news_active.png",text:"我的"}];exports.setTabBar=function(a){var e,n,l,o,c,i,s,u;const g=getCurrentPages(),p=g[g.length-1];if(p){const s=(null==p?void 0:p.getTabBar)?null==p?void 0:p.getTabBar():null;let u=null==(l=null==(n=null==(e=null==a?void 0:a.companyConfig)?void 0:e.config_value)?void 0:n.menu)?void 0:l.map((t=>{var a,e,n,l;return{...t,iconPath:null==(e=null==(a=t.iconPath)?void 0:a[0])?void 0:e.url,selectedIconPath:null==(l=null==(n=t.selectedIconPath)?void 0:n[0])?void 0:l.url}}));u.splice((null==(i=null==(c=null==(o=null==a?void 0:a.companyConfig)?void 0:o.config_value)?void 0:c.menu)?void 0:i.length)/2,0,{pagePath:"/pages/ai/chat",iconPath:"https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN63WTGSX2T5X8N233CJ5K0Q.png",selectedIconPath:"https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN63WTGSX2T5X8N233CJ5K0Q.png",text:"管家在线"}),getApp().globalData.menuList=u||t,s&&s.setData({list:u||t})}console.log("App.globalData.selectedOrg",null==(u=null==(s=null==a?void 0:a.companyConfig)?void 0:s.config_value)?void 0:u.menu)}; +"use strict";let t=[{pagePath:"/pages/index/index",iconPath:"/static/tabbar/home_icon.png",selectedIconPath:"/static/tabbar/home_active.png",text:"首页"},{pagePath:"/pages/ai/chat",iconPath:"/static/tabbar/news_icon.png",selectedIconPath:"/static/tabbar/news_active.png",text:"管家在线"},{pagePath:"/pages/me/index",iconPath:"/static/tabbar/news_icon.png",selectedIconPath:"/static/tabbar/news_active.png",text:"我的"}];exports.setTabBar=function(a){var e,n,l,o,c,i,s,g;const p=getCurrentPages(),u=p[p.length-1];if(u){const s=(null==u?void 0:u.getTabBar)?null==u?void 0:u.getTabBar():null;let g=null==(l=null==(n=null==(e=null==a?void 0:a.companyConfig)?void 0:e.config_value)?void 0:n.menu)?void 0:l.map((t=>{var a,e,n,l;return{...t,iconPath:null==(e=null==(a=t.iconPath)?void 0:a[0])?void 0:e.url,selectedIconPath:null==(l=null==(n=t.selectedIconPath)?void 0:n[0])?void 0:l.url}}));g.splice((null==(i=null==(c=null==(o=null==a?void 0:a.companyConfig)?void 0:o.config_value)?void 0:c.menu)?void 0:i.length)/2,0,{pagePath:"/pages/ai/index",iconPath:"https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN63WTGSX2T5X8N233CJ5K0Q.png",selectedIconPath:"https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN63WTGSX2T5X8N233CJ5K0Q.png",text:"管家在线"}),getApp().globalData.menuList=g||t,console.log("getApp().globalData",getApp().globalData,g),s&&s.setData({list:g||t})}console.log("App.globalData.selectedOrg",null==(g=null==(s=null==a?void 0:a.companyConfig)?void 0:s.config_value)?void 0:g.menu)}; diff --git a/dist/build/mp-weixin/common/libraries/userUserLogin.js b/dist/build/mp-weixin/common/libraries/userUserLogin.js index 7c26596..7b2fc55 100644 --- a/dist/build/mp-weixin/common/libraries/userUserLogin.js +++ b/dist/build/mp-weixin/common/libraries/userUserLogin.js @@ -1 +1 @@ -"use strict";const e=require("../vendor.js");require("./request.js");const o=require("../store/useWeAppAuthStore.js");require("../store/useWorkStore.js");const n=o.useWeAppAuthStore(),r={onBindPhone(){var o;return console.log("auth?.userInfo:",null==n?void 0:n.data),!!(null==(o=null==n?void 0:n.data)?void 0:o.user)||(e.index.showModal({title:"登录",content:"请先登录体验更多功能!",success:function(o){o.confirm?(e.index.navigateTo({url:"/pages/login"}),console.log("用户点击确定")):o.cancel&&console.log("用户点击取消")}}),!1)},getLoginStatus(){var e;return!!(null==(e=null==n?void 0:n.data)?void 0:e.user)}};exports.getUserLogin=r; +"use strict";const e=require("../vendor.js");require("./request.js");const o=require("../store/useWeAppAuthStore.js");require("../store/useWorkStore.js");const n=o.useWeAppAuthStore(),t={onBindPhone(){var o;return console.log("auth?.userInfo:",null==n?void 0:n.data),!!(null==(o=null==n?void 0:n.data)?void 0:o.user)||(e.index.showModal({title:"登录",content:"请先登录体验更多功能!",success:function(o){o.confirm?(e.index.navigateTo({url:"/pages/login"}),console.log("用户点击确定")):o.cancel&&console.log("用户点击取消")}}),!1)},getLoginStatus(){var e,o;return console.log("auth?.data?.user:",null==(e=null==n?void 0:n.data)?void 0:e.user),!!(null==(o=null==n?void 0:n.data)?void 0:o.user)}};exports.getUserLogin=t; diff --git a/dist/build/mp-weixin/common/store/useWeAppAuthStore.js b/dist/build/mp-weixin/common/store/useWeAppAuthStore.js index d4468bb..abd42ef 100644 --- a/dist/build/mp-weixin/common/store/useWeAppAuthStore.js +++ b/dist/build/mp-weixin/common/store/useWeAppAuthStore.js @@ -1 +1 @@ -"use strict";const e=require("../vendor.js"),o=require("../../gen/Apis.js"),i=require("../libraries/setTabBar.js"),u=require("../libraries/apiLoading.js"),a="wx31500e871924b903",n=e.defineStore("we_app_auth",(()=>{const n=e.ref(!1),s=e.ref(!1),t=e.ref(0),l=e.ref({user:{id:0,name:""},work_info:{session_key:"",openid:""},selected_house:{},environment:"",house_occupant:!1,house_register:!1,is_house_exist:0,config:{}});const r=(u,t)=>{o.Apis.Login.Auth.Login({code:t,app_id:a}).then((o=>{var a,t,r,v,c,g;console.log("登录",null==o?void 0:o.data),l.value.user=null==(a=o.data)?void 0:a.user,l.value.selected_house=null==(t=o.data)?void 0:t.selected_house,l.value.config=null==(r=o.data)?void 0:r.config,i.setTabBar(null==(v=null==o?void 0:o.data)?void 0:v.config),e.index.setStorageSync("NCHL_TEST_ACCESS_TOKEN_CUSTOMER",null==(g=null==(c=null==o?void 0:o.data)?void 0:c.token)?void 0:g.token),l.value.user&&d(),setTimeout((()=>{n.value=!1,s.value=!1}),300),null==u||u.appContext.config.globalProperties.$isResolve()})).catch((()=>{n.value=!1,s.value=!0}))},d=()=>{o.Apis.Archive.HouseOccupants.GetCustomerHouseIsExist().then((e=>{var o,i;l.value.house_occupant=(null==(o=e.data)?void 0:o.house_occupant)||!1,l.value.house_register=(null==(i=e.data)?void 0:i.house_register)||!1,l.value.is_house_exist=t.value+1}))};function v(e){u.getApiLoading(o.Apis.Login.Auth.Me,{}).then((o=>{var u,a,t;return l.value.user=o.data.user,l.value.config=null==(u=o.data)?void 0:u.config,l.value.selected_house=null==(a=o.data)?void 0:a.selected_house,i.setTabBar(null==(t=null==o?void 0:o.data)?void 0:t.config),console.log("me",o.data),l.value.user&&d(),setTimeout((()=>{n.value=!1,s.value=!1}),300),null==e?void 0:e()}))}return{loading:n,hasError:s,data:l,login:function(o){e.index.login({provider:"weixin",success:function(e){console.log(e),r(o,e.code)}})},me:v,handleUserLogin:async i=>{u.getApiLoading(o.Apis.Login.Auth.BindPhoneNumber,{app_id:a,...i}).then((o=>{v((()=>{e.index.navigateBack({delta:1})}))}))},getIsHouseExist:d}}));exports.useWeAppAuthStore=n; +"use strict";const e=require("../vendor.js"),o=require("../../gen/Apis.js"),i=require("../libraries/setTabBar.js"),u=require("../libraries/apiLoading.js"),a="wx31500e871924b903",n=e.defineStore("we_app_auth",(()=>{const n=e.ref(!1),s=e.ref(!1),t=e.ref(0),l=e.ref({user:{id:0,name:""},work_info:{session_key:"",openid:""},selected_house:{},environment:"",house_occupant:!1,house_register:!1,is_house_exist:0,config:{}});const r=(u,t)=>{o.Apis.Login.Auth.Login({code:t,app_id:a}).then((o=>{var a,t,r,v,c,g;console.log("登录",null==o?void 0:o.data),e.index.setStorageSync("NCHL_PROD_ACCESS_TOKEN_CUSTOMER",null==(t=null==(a=null==o?void 0:o.data)?void 0:a.token)?void 0:t.token),null==u||u.appContext.config.globalProperties.$isResolve(),setTimeout((()=>{n.value=!1,s.value=!1}),300),l.value.selected_house=null==(r=o.data)?void 0:r.selected_house,l.value.user=null==(v=o.data)?void 0:v.user,l.value.config=null==(c=o.data)?void 0:c.config,i.setTabBar(null==(g=null==o?void 0:o.data)?void 0:g.config),l.value.user&&d()})).catch((()=>{n.value=!1,s.value=!0}))},d=()=>{o.Apis.Archive.HouseOccupants.GetCustomerHouseIsExist().then((e=>{var o,i;l.value.house_occupant=(null==(o=e.data)?void 0:o.house_occupant)||!1,l.value.house_register=(null==(i=e.data)?void 0:i.house_register)||!1,l.value.is_house_exist=t.value+1}))};function v(e){u.getApiLoading(o.Apis.Login.Auth.Me,{}).then((o=>{var u,a,t;return l.value.user=o.data.user,l.value.config=null==(u=o.data)?void 0:u.config,l.value.selected_house=null==(a=o.data)?void 0:a.selected_house,console.log("me",o.data),l.value.user&&d(),setTimeout((()=>{n.value=!1,s.value=!1}),300),i.setTabBar(null==(t=null==o?void 0:o.data)?void 0:t.config),null==e?void 0:e()}))}return{loading:n,hasError:s,data:l,login:function(o){e.index.login({provider:"weixin",success:function(e){console.log(e),r(o,e.code)}})},me:v,handleUserLogin:async i=>{u.getApiLoading(o.Apis.Login.Auth.BindPhoneNumber,{app_id:a,...i}).then((o=>{v((()=>{e.index.navigateBack({delta:1})}))}))},getIsHouseExist:d}}));exports.useWeAppAuthStore=n; diff --git a/dist/build/mp-weixin/custom-tab-bar/index.js b/dist/build/mp-weixin/custom-tab-bar/index.js index 3cce33f..7ab000e 100644 --- a/dist/build/mp-weixin/custom-tab-bar/index.js +++ b/dist/build/mp-weixin/custom-tab-bar/index.js @@ -12,9 +12,11 @@ Component({ text: '首页' }, { - pagePath: '/pages/ai/chat', - iconPath: '/static/tabbar/news_icon.png', - selectedIconPath: '/static/tabbar/news_active.png', + pagePath: '/pages/ai/index', + iconPath: + 'https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN63WTGSX2T5X8N233CJ5K0Q.png', + selectedIconPath: + 'https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN63WTGSX2T5X8N233CJ5K0Q.png', text: '管家在线' }, { @@ -32,17 +34,20 @@ Component({ let _this = this const pages = getCurrentPages() const currentPage = pages[pages.length - 1] - console.log('currentList', getApp().globalData.menuList) - if (currentPage) { + console.log('currentList', getApp().globalData, currentPage) + if (currentPage && this.data.list) { const currentPath = currentPage.route const index = this.data.list.findIndex(item => item.pagePath === `/${currentPath}`) if (index !== -1) { this.setData({ selected: index, - list: getApp().globalData.menuList + list: this.data.list }) App.globalData.selectedIndex = index } + if (!getApp().globalData.menuList) { + getApp().globalData.menuList = this.data.list + } } } // 初始化时执行一次 diff --git a/dist/build/mp-weixin/custom-tab-bar/index.wxml b/dist/build/mp-weixin/custom-tab-bar/index.wxml index 67375b5..6a5b259 100644 --- a/dist/build/mp-weixin/custom-tab-bar/index.wxml +++ b/dist/build/mp-weixin/custom-tab-bar/index.wxml @@ -1,8 +1,11 @@ - - - - - {{item.text}} + + + + + + {{item.text}} + + diff --git a/dist/build/mp-weixin/custom-tab-bar/index.wxss b/dist/build/mp-weixin/custom-tab-bar/index.wxss index 49012fb..f1796a7 100644 --- a/dist/build/mp-weixin/custom-tab-bar/index.wxss +++ b/dist/build/mp-weixin/custom-tab-bar/index.wxss @@ -3,16 +3,22 @@ bottom: 0; left: 0; right: 0; - height: 48px; - /* background: url('https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN62JHV37KC4W8K8A391MS3Y.png') - no-repeat; */ - background: url(' https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN62VGEVV8NSR4GDDQAYC2JV.png') - no-repeat; - background-size: 100% auto; - display: flex; - padding-bottom: env(safe-area-inset-bottom); -} + /* padding-bottom: env(safe-area-inset-bottom); */ +} +.safe-area-inset-bottom { + width: 100%; + height: env(safe-area-inset-bottom); + background-color: #fff; +} +.tab-bar-content { + display: flex; + height: 48px; + width: 100%; + background: url('https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KN6H4Z5VTWGPRGQZ35CPYHF5.png') + center no-repeat; + background-size: 100%; +} .tab-bar-border { background-color: rgba(0, 0, 0, 0.33); position: absolute; diff --git a/dist/build/mp-weixin/pages/ai/chat.js b/dist/build/mp-weixin/pages/ai/chat.js index a468f04..a1abb6a 100644 --- a/dist/build/mp-weixin/pages/ai/chat.js +++ b/dist/build/mp-weixin/pages/ai/chat.js @@ -1 +1 @@ -"use strict";const e=require("../../common/vendor.js");require("../../common/libraries/request.js");const t=require("../../common/store/useWeAppAuthStore.js");require("../../common/store/useWorkStore.js");const o=require("../../common/libraries/upload.js");if(require("../../gen/Apis.js"),require("../../common/libraries/setTabBar.js"),require("../../common/libraries/apiLoading.js"),!Array){e.resolveComponent("uni-icons")()}Math;const a=e.defineComponent({__name:"chat",setup(a){e.dayjs.extend(e.relativeTime),e.dayjs.locale("zh-cn");const s=t.useWeAppAuthStore(),n=e.ref(""),l=e.ref([]),r=e.ref(!1),i=e.ref([{role:"ai",content:"您好!我是物业客服,有什么可以帮助您的吗?",quickQuestions:[]}]),u=e.ref(!1),c=e.ref("正在输入中...");let m=null,g=e.ref(!1);const d="https://kf-api-test.linyikj.com.cn",p=e.ref(1),v=e.ref(10),y=e.ref(!0),_=e.ref(!1),f=e.ref(""),h=e.ref(0),k=e.ref([]),S=e.ref(""),q=e.ref(!0),C=e.ref(0);e.onPageScroll((e=>{console.log(e.scrollTop,C.value),C.value>0&&C.value>e.scrollTop&&(q.value=!1),C.value-e.scrollTop<50&&(q.value=!0),(0===C.value||C.value{e.index.previewImage({current:t,urls:o})},A=t=>{t?e.index.setClipboardData({data:t,success:()=>{e.index.showToast({title:"复制成功",icon:"success"})},fail:()=>{e.index.showToast({title:"复制失败",icon:"none"})}}):e.index.showToast({title:"暂无内容可复制",icon:"none"})},x=t=>{if(!t)return"";try{const o=e.dayjs(t);return o.isValid()?o.fromNow():""}catch(o){return console.error("时间格式化错误:",o),""}},T=()=>{e.nextTick$1((()=>{e.index.pageScrollTo({scrollTop:999999,duration:300})}))},b=async(t=1)=>{var o,a;const n=null==(a=null==(o=s.data)?void 0:o.user)?void 0:a.phone;if(n){if(!_.value)try{_.value=!0;const o=(t-1)*v.value;h.value=o,console.log("分页信息 - 页码:",t,"每页数量:",v.value,"计算出的offset:",o);const a=await e.index.request({url:`${d}/api/public/customer/init`,method:"POST",data:{platform:"property",platform_user_id:n,limit:v.value,offset:o}});if(200===a.statusCode){const s=a.data;let n=[];s.conversation&&s.conversation.id?(f.value=s.conversation.id,console.log("获取到会话ID:",f.value)):s.conversation_id?(f.value=s.conversation_id,console.log("获取到会话ID:",f.value)):s.conversations&&s.conversations.id&&(f.value=s.conversations.id,console.log("获取到会话ID:",f.value)),s.messages&&Array.isArray(s.messages)?(n=s.messages.map((e=>{const t={role:"customer"===e.sender_type?"user":"ai",content:e.message||e.content||"",created_at:e.created_at||e.timestamp||(new Date).toISOString()};e.message_type&&(t.message_type=e.message_type);let o=null;return e.image_url&&Array.isArray(e.image_url)?o=e.image_url:e.images&&Array.isArray(e.images)?o=e.images:e.metadata&&e.metadata.image_url&&Array.isArray(e.metadata.image_url)&&(o=e.metadata.image_url),o&&(t.image_url=o,t.images=o),e.metadata&&(t.metadata=e.metadata),t})),console.log("从messages字段获取到历史记录:",n.length)):s.data&&Array.isArray(s.data)?(n=s.data.map((e=>{const t={role:"customer"===e.sender_type?"user":"ai",content:e.message||e.content||"",created_at:e.created_at||e.timestamp||(new Date).toISOString()};e.message_type&&(t.message_type=e.message_type);let o=null;return e.image_url&&Array.isArray(e.image_url)?o=e.image_url:e.images&&Array.isArray(e.images)?o=e.images:e.metadata&&e.metadata.image_url&&Array.isArray(e.metadata.image_url)&&(o=e.metadata.image_url),o&&(t.image_url=o,t.images=o),e.metadata&&(t.metadata=e.metadata),t})),console.log("从data字段获取到历史记录:",n.length)):s.list&&Array.isArray(s.list)&&(n=s.list.map((e=>{const t={role:"customer"===e.sender_type?"user":"ai",content:e.message||e.content||"",created_at:e.created_at||e.timestamp||(new Date).toISOString()};e.message_type&&(t.message_type=e.message_type);let o=null;return e.image_url&&Array.isArray(e.image_url)?o=e.image_url:e.images&&Array.isArray(e.images)?o=e.images:e.metadata&&e.metadata.image_url&&Array.isArray(e.metadata.image_url)&&(o=e.metadata.image_url),o&&(t.image_url=o,t.images=o),e.metadata&&(t.metadata=e.metadata),t})),console.log("从list字段获取到历史记录:",n.length)),1===t?(n.length>0?(i.value=n,console.log("第一页历史记录已加载,总共",n.length,"条消息")):(console.log("没有历史记录"),i.value=[]),e.nextTick$1((()=>{if(k.value.length>0){const e={role:"ai",content:"您好!我是物业客服,有什么可以帮助您的吗?",quickQuestions:k.value,created_at:(new Date).toISOString()};i.value.push(e),console.log("[Customer] 获取历史记录成功后,在历史记录后面push新开场白消息"),T()}}))):n.length>0&&setTimeout((()=>{i.value.unshift(...n),console.log("加载更多历史记录,新增",n.length,"条消息,总共",i.value.length,"条")}),300);const l=s.total||s.count||s.total_count||0;y.value=l>i.value.length,p.value=t,t>1&&!y.value&&(console.log("分页加载完成,当前页:",t,"hasMore:",y.value,"展示开场白"),setTimeout((()=>{W(!0)}),500)),console.log("第",t,"页数据加载完成,offset:",o,", limit:",v.value,", 总数据:",l,", 当前已加载:",i.value.length,", 是否有更多:",y.value),1===t&&(setTimeout((()=>{T()}),100),console.log("[Customer] 历史记录加载完成,开始建立WebSocket连接"),O())}else console.error("获取历史记录失败,状态码:",a.statusCode)}catch(l){console.error("获取历史记录异常:",l)}finally{_.value=!1}}else console.log("用户未登录,无法获取历史记录")};e.onPullDownRefresh((async()=>{if(_.value||!y.value)return console.log("正在加载或没有更多数据"),void e.index.stopPullDownRefresh();console.log("触发下拉分页,加载更多历史记录");const t=p.value+1;try{await b(t),await new Promise((e=>setTimeout(e,500)))}catch(o){console.error("加载历史记录失败:",o)}finally{e.index.stopPullDownRefresh()}}));const O=()=>{if(!m)try{const t="wss://kf-api-test.linyikj.com.cn/ws/socket.io/?EIO=4&transport=websocket";console.log("正在建立Socket.IO连接"),console.log("连接URL:",t),m=e.index.connectSocket({url:t,header:{"content-type":"application/json"}}),e.index.onSocketOpen((t=>{console.log("[Customer] WebSocket connected",t),g.value=!0;e.index.sendSocketMessage({data:'40/customer,{"jwt":""}',success:()=>{console.log("[Customer] Socket.IO连接包发送成功"),f.value&&setTimeout((()=>{const t=`42/customer,["join_conversation",{"conversation_id":"${f.value}"}]`;console.log("[Customer] 加入会话房间:",t),e.index.sendSocketMessage({data:t,success:()=>{console.log("[Customer] 成功加入会话房间")},fail:e=>{console.error("[Customer] 加入会话房间失败:",e)}})}),200)},fail:e=>{console.error("[Customer] Socket.IO连接包发送失败:",e)}})})),e.index.onSocketError((e=>{console.error("[Customer] WebSocket error:",e),g.value=!1,m=null})),e.index.onSocketClose((e=>{console.log("[Customer] WebSocket disconnected",e),g.value=!1,m=null})),e.index.onSocketMessage((t=>{console.log("收到WebSocket原始消息:",t),console.log("消息数据类型:",typeof t.data),console.log("消息内容:",t.data);const o=t.data;if("string"==typeof o)if(o.startsWith("42/customer,")){const e=o.substring(12);try{const t=JSON.parse(e);console.log("解析Socket.IO事件:",t),j(t)}catch(a){console.error("解析Socket.IO数据失败:",a,"原始数据:",e)}}else if(o.startsWith("40/customer"))console.log("Socket.IO连接确认");else if(o.startsWith("2"))e.index.sendSocketMessage({data:"3"});else if(o.startsWith("0"))console.log("Socket.IO握手成功");else try{const e=JSON.parse(o);console.log("解析JSON消息:",e),I(e)}catch(a){console.log("非JSON格式的字符串消息:",o)}else"object"==typeof o?(console.log("收到对象类型消息:",o),Q(o)):console.log("收到其他类型消息,类型:",typeof o)}))}catch(t){console.error("初始化Socket.IO异常:",t),g.value=!1,m=null}},j=e=>{if(Array.isArray(e)&&e.length>=2){const t=e[0],o=e[1];console.log("[Customer] Socket.IO事件类型:",t,"事件数据:",o),"new_message"===t?P(o):"join_conversation_response"===t?console.log("[Customer] Joined room:",o):"message"===t?P(o):"typing"===t?D(o):console.log("[Customer] 未处理的Socket.IO事件类型:",t)}},I=e=>{console.log("[Customer] 处理JSON消息:",e),"message"===e.type||"new_message"===e.event?P(e.data||e):"typing"===e.type||"typing"===e.event?D(e.data||e):e.message||e.content?P(e):console.log("[Customer] 未识别的JSON消息结构:",e)},Q=e=>{console.log("[Customer] 处理对象消息:",e),e.message||e.content||e.text?P(e):void 0!==e.is_typing?D(e):console.log("[Customer] 未识别的对象消息结构:",e)},D=e=>{console.log("[Customer] 处理typing指示器:",e),e.is_typing&&"staff"===e.user_type?(u.value=!0,c.value="客服正在输入..."):u.value=!1},W=(e=!1)=>{if(0===k.value.length)return;if(!(k.value.length>0))return;const t={role:"ai",content:"您好!我是物业客服,有什么可以帮助您的吗?",quickQuestions:k.value,created_at:(new Date).toISOString()};console.log("[Customer] 创建开场白消息,是否最后一页:",e),0===i.value.length?(i.value=[t],console.log("[Customer] 设置开场白为第一条消息")):(i.value.unshift(t),console.log("[Customer] 在第一条消息前面插入开场白"))},P=e=>{if(console.log("[Customer] 处理消息数据:",e),"customer"===e.sender_type||"user"===e.role)return void console.log("[Customer] 过滤掉客户消息");let t="";if(t="string"==typeof e?e:e.message||e.content||e.text||e.body||"收到回复","string"==typeof t&&(t=t.replace(/↵/g,"\n").replace(/\\n/g,"\n")),console.log("[Customer] 收到新消息内容:",t),t===S.value)return console.log("[Customer] 消息与HTTP返回的消息相同,跳过显示"),void(S.value="");u.value=!1;const o={role:"ai",content:t,created_at:e.created_at||e.timestamp||e.time||(new Date).toISOString()};e.suggested_questions&&Array.isArray(e.suggested_questions)&&e.suggested_questions.length>0?o.quickQuestions=e.suggested_questions:e.quickQuestions&&Array.isArray(e.quickQuestions)&&e.quickQuestions.length>0&&(o.quickQuestions=e.quickQuestions),void 0!==e.need_confirmation&&(o.needConfirmation=e.need_confirmation),void 0!==e.confirmation_type&&(o.confirmationType=e.confirmation_type),i.value.push(o),T()},z=(e,t)=>{void 0===e.selectedConfirmation&&(e.selectedConfirmation=t,setTimeout((()=>{n.value=t,J()}),300))},F=async()=>{if(l.value.length>=9)e.index.showToast({title:"最多选择9张图片",icon:"none"});else try{const t=9-l.value.length,a=await o.upload(t,2,["image"]);if(a&&Array.isArray(a)&&a.length>0){const t=a.map((e=>e.url));l.value.push(...t),e.index.showToast({title:"图片上传成功",icon:"success"})}}catch(t){console.error("选择图片失败:",t),e.index.showToast({title:"选择图片失败",icon:"none"})}},J=async()=>{var t,o,a,r,m,p;const v=n.value.trim(),y=l.value.length>0;if(!v&&!y||u.value)return;const _=null==(o=null==(t=s.data)?void 0:t.user)?void 0:o.phone,h=null==(r=null==(a=s.data)?void 0:a.selected_house)?void 0:r.asset_projects_id,k=null==(p=null==(m=s.data)?void 0:m.selected_house)?void 0:p.full_name;if(!_||!h)return void e.index.showToast({title:"请先登录并绑定房屋",icon:"none"});g.value||(O(),await new Promise((e=>setTimeout(e,1e3))));const q=l.value;let C="text";y&&v?C="mixed":y&&!v&&(C="image");const w={role:"user",content:v||"",created_at:(new Date).toISOString(),message_type:C,image_url:q.length>0?q:void 0,images:q.length>0?q:void 0};i.value.push(w),n.value="",l.value=[],T(),v&&v.includes("查询")?c.value="正在查询中请稍后...":c.value="正在输入中...",u.value=!0;try{const t=await e.index.request({url:`${d}/api/public/chat`,method:"POST",data:{platform:"property",message:v||"",tenant_project_id:h,tenant_project_name:k||"",platform_user_id:_,conversation_id:f.value,message_type:C,image_url:q.length>0?q:void 0},header:{"Content-Type":"application/json"}});if(200!==t.statusCode)throw new Error("请求失败");{const e=t.data;console.log("[Customer] HTTP接口响应数据:",e);let o=null,a=[],s=!1,n=null;if(e.reply&&"string"==typeof e.reply?(o=e.reply,a=e.suggested_questions||[],s=e.need_confirmation||!1,n=e.confirmation_type||null):e.reply&&e.reply.message?(o=e.reply.message,a=e.reply.suggested_questions||e.suggested_questions||[],s=e.reply.need_confirmation||e.need_confirmation||!1,n=e.reply.confirmation_type||e.confirmation_type||null):e.reply&&e.reply.content?(o=e.reply.content,a=e.reply.suggested_questions||e.suggested_questions||[],s=e.reply.need_confirmation||e.need_confirmation||!1,n=e.reply.confirmation_type||e.confirmation_type||null):e.message?(o=e.message,a=e.suggested_questions||[],s=e.need_confirmation||!1,n=e.confirmation_type||null):e.content?(o=e.content,a=e.suggested_questions||[],s=e.need_confirmation||!1,n=e.confirmation_type||null):e.answer?(o=e.answer,a=e.suggested_questions||[],s=e.need_confirmation||!1,n=e.confirmation_type||null):e.response?(o=e.response,a=e.suggested_questions||[],s=e.need_confirmation||!1,n=e.confirmation_type||null):"string"==typeof e&&(o=e),o){console.log("[Customer] HTTP接口返回回答消息:",o),console.log("[Customer] 建议问题:",a),console.log("[Customer] 需要确认:",s,"确认类型:",n);let e=o;"string"==typeof e&&(e=e.replace(/↵/g,"\n").replace(/\\n/g,"\n")),S.value=e,u.value=!1,i.value.push({role:"ai",content:e,created_at:(new Date).toISOString(),quickQuestions:a.length>0?a:void 0,needConfirmation:s,confirmationType:n}),T()}else console.log("[Customer] 消息发送成功,等待WebSocket回复")}}catch(A){console.error("发送消息失败:",A),e.index.showToast({title:"发送失败,请稍后重试",icon:"none"}),i.value.push({role:"ai",content:"抱歉,网络连接出现问题,请稍后再试。"}),u.value=!1,T()}};return e.onUnmounted((()=>{(m||g.value)&&(e.index.closeSocket(),m=null,g.value=!1,console.log("页面卸载,WebSocket连接已关闭"))})),e.onLoad((async t=>{var o;k.value=await(async()=>{try{const t=await e.index.request({url:`${d}/api/public/quick-questions`,method:"GET"});if(200===t.statusCode){const e=t.data;let o=[];return e.data&&Array.isArray(e.data)?o=e.data.map((e=>e.question||e.title||e.text||e)):e.questions&&Array.isArray(e.questions)?o=e.questions.map((e=>e.question||e.title||e.text||e)):Array.isArray(e)&&(o=e.map((e=>e.question||e.title||e.text||e))),console.log("获取到开场白按钮数据:",o),o}return console.error("获取开场白数据失败,状态码:",t.statusCode),[]}catch(t){return console.error("获取开场白数据异常:",t),[]}})(),console.log("页面加载时已获取开场白按钮数据:",k.value.length),b(1),(null==t?void 0:t.message)&&(o=t,n.value=o.message,J())})),(t,o)=>e.e({a:e.f(i.value,((t,o,a)=>{return e.e({a:"ai"===t.role},(t.role,{}),{b:t.image_url&&t.image_url.length>0},t.image_url&&t.image_url.length>0?{c:e.f(t.image_url,((o,a,s)=>({a:o,b:e.o((e=>w(o,t.image_url)),a),c:a}))),d:1===t.image_url.length?"widthFix":"aspectFill",e:1===t.image_url.length?1:""}:t.images&&t.images.length>0?{g:e.f(t.images,((o,a,s)=>({a:o,b:e.o((e=>w(o,t.images)),a),c:a}))),h:1===t.images.length?"widthFix":"aspectFill",i:1===t.images.length?1:""}:t.metadata&&t.metadata.image_url&&t.metadata.image_url.length>0?{k:e.f(t.metadata.image_url,((o,a,s)=>({a:o,b:e.o((e=>w(o,t.metadata.image_url)),a),c:a}))),l:1===t.metadata.image_url.length?"widthFix":"aspectFill",m:1===t.metadata.image_url.length?1:""}:{},{f:t.images&&t.images.length>0,j:t.metadata&&t.metadata.image_url&&t.metadata.image_url.length>0,n:t.content&&t.content.trim()},t.content&&t.content.trim()?{o:e.f((s=t.content,s&&"string"==typeof s?s.split("\n").filter((e=>""!==e.trim())):[""]),((t,o,a)=>({a:e.t(t),b:"text-"+o})))}:{},{p:t.quickQuestions&&t.quickQuestions.length>0},t.quickQuestions&&t.quickQuestions.length>0?{q:e.f(t.quickQuestions,((t,o,a)=>({a:e.t(t),b:o,c:e.o((e=>(e=>{n.value=e,J()})(t)),o)})))}:{},{r:t.needConfirmation},t.needConfirmation?{s:"是"===t.selectedConfirmation?1:"",t:void 0!==t.selectedConfirmation?1:"",v:e.o((e=>z(t,"是")),o),w:"否"===t.selectedConfirmation?1:"",x:void 0!==t.selectedConfirmation?1:"",y:e.o((e=>z(t,"否")),o)}:{},{z:t.created_at&&!t.quickQuestions},t.created_at&&!t.quickQuestions?e.e({A:"ai"===t.role},"ai"===t.role?{B:e.o((e=>A(t.content)),o)}:{},{C:e.t(x(t.created_at)),D:"user"===t.role},"user"===t.role?{E:e.o((e=>A(t.content)),o)}:{}):{},{F:o,G:`msg-${o}`,H:e.n("user"===t.role?"user-message":"ai-message")});var s})),b:u.value},u.value?{c:e.t(c.value)}:{},{d:l.value.length>0},l.value.length>0?e.e({e:e.f(l.value,((t,o,a)=>({a:t,b:"25c36616-0-"+a,c:e.o((e=>(e=>{l.value.splice(e,1)})(o)),o),d:o}))),f:e.p({type:"closeempty",size:"14",color:"#fff"}),g:l.value.length<9},l.value.length<9?{h:e.p({type:"plus",size:"30",color:"#999"}),i:e.o(F)}:{}):{},{j:e.o((e=>r.value=!0)),k:e.o((e=>r.value=!1)),l:e.o(J),m:n.value,n:e.o((e=>n.value=e.detail.value)),o:!n.value.trim()&&!r.value&&0===l.value.length},n.value.trim()||r.value||0!==l.value.length?{}:{p:e.p({type:"camera",size:"24",color:"#666"}),q:e.o(F)},{r:(n.value.trim()||r.value||l.value.length>0)&&!u.value},(n.value.trim()||r.value||l.value.length>0)&&!u.value?{s:e.p({type:"paperplane-filled",size:"20",color:"#fff"}),t:e.o(J)}:{},{v:u.value},u.value?{w:e.p({type:"spinner-cycle",size:"20",color:"#ccc"})}:{})}});a.__runtimeHooks=1,wx.createPage(a); +"use strict";const e=require("../../common/vendor.js");require("../../common/libraries/request.js");const t=require("../../common/store/useWeAppAuthStore.js");require("../../common/store/useWorkStore.js");const o=require("./method.js"),a=require("./model.js"),n=require("../../common/libraries/userUserLogin.js");if(require("../../gen/Apis.js"),require("../../common/libraries/setTabBar.js"),require("../../common/libraries/apiLoading.js"),require("../../common/libraries/upload.js"),!Array){(e.resolveComponent("uni-icons")+e.resolveComponent("hs-empty")+e.resolveComponent("hs-button"))()}Math||(s+(()=>"../../uni_modules/uni-icons/components/uni-icons/uni-icons.js")+(()=>"../../components/hs-empty/hs-empty.js")+(()=>"../../components/hs-button/hs-button.js"))();const s=()=>"./components/HeaderPrologue.js",l=e.defineComponent({__name:"chat",setup(s){e.dayjs.extend(e.relativeTime),e.dayjs.locale("zh-cn");const l=t.useWeAppAuthStore(),r=e.ref(!1),i=e.ref(""),u=e.ref(!1),c=e.ref([]),m=e.ref(!1),d=e.ref("正在输入中...");let g=null,v=e.ref(!1);const p=e.ref(1),_=e.ref(10),f=e.ref(!0),y=e.ref(!1),h=e.ref(""),S=e.ref(0),k=e.ref({}),q=e.ref(""),C=()=>{e.index.navigateTo({url:"/pages/login"})},A=()=>{e.nextTick$1((()=>{e.index.pageScrollTo({scrollTop:999999,duration:300})}))},w=async(e=1)=>{var t,a,n;const s=null==(a=null==(t=l.data)?void 0:t.user)?void 0:a.phone;if(s){if(!y.value)try{y.value=!0;const t=(e-1)*_.value;S.value=t;const a=await(null==(n=o.method)?void 0:n.customRequest("public/customer/init",{platform:"property",platform_user_id:s,limit:_.value,offset:t}));if(200===a.statusCode){const t=a.data;let o=[];t.conversation&&t.conversation.id?(h.value=t.conversation.id,console.log("获取到会话ID:",h.value)):t.conversation_id?(h.value=t.conversation_id,console.log("获取到会话ID:",h.value)):t.conversations&&t.conversations.id&&(h.value=t.conversations.id,console.log("获取到会话ID:",h.value)),t.messages&&Array.isArray(t.messages)?(o=t.messages.map((e=>{const t={role:"customer"===e.sender_type?"user":"ai",content:e.message||e.content||"",created_at:e.created_at||e.timestamp||(new Date).toISOString()};e.message_type&&(t.message_type=e.message_type);let o=null;return e.image_url&&Array.isArray(e.image_url)?o=e.image_url:e.images&&Array.isArray(e.images)?o=e.images:e.metadata&&e.metadata.image_url&&Array.isArray(e.metadata.image_url)&&(o=e.metadata.image_url),o&&(t.image_url=o,t.images=o),e.metadata&&(t.metadata=e.metadata),t})),console.log("从messages字段获取到历史记录:",o.length)):t.data&&Array.isArray(t.data)?(o=t.data.map((e=>{const t={role:"customer"===e.sender_type?"user":"ai",content:e.message||e.content||"",created_at:e.created_at||e.timestamp||(new Date).toISOString()};e.message_type&&(t.message_type=e.message_type);let o=null;return e.image_url&&Array.isArray(e.image_url)?o=e.image_url:e.images&&Array.isArray(e.images)?o=e.images:e.metadata&&e.metadata.image_url&&Array.isArray(e.metadata.image_url)&&(o=e.metadata.image_url),o&&(t.image_url=o,t.images=o),e.metadata&&(t.metadata=e.metadata),t})),console.log("从data字段获取到历史记录:",o.length)):t.list&&Array.isArray(t.list)&&(o=t.list.map((e=>{const t={role:"customer"===e.sender_type?"user":"ai",content:e.message||e.content||"",created_at:e.created_at||e.timestamp||(new Date).toISOString()};e.message_type&&(t.message_type=e.message_type);let o=null;return e.image_url&&Array.isArray(e.image_url)?o=e.image_url:e.images&&Array.isArray(e.images)?o=e.images:e.metadata&&e.metadata.image_url&&Array.isArray(e.metadata.image_url)&&(o=e.metadata.image_url),o&&(t.image_url=o,t.images=o),e.metadata&&(t.metadata=e.metadata),t})),console.log("从list字段获取到历史记录:",o.length)),1===e?o.length>0?(c.value=o,console.log("第一页历史记录已加载,总共",o.length,"条消息")):(console.log("没有历史记录"),c.value=[]):o.length>0&&setTimeout((()=>{c.value.unshift(...o),console.log("加载更多历史记录,新增",o.length,"条消息,总共",c.value.length,"条")}),300);const n=t.total||t.count||t.total_count||0;f.value=n>c.value.length,p.value=e,1===e&&(setTimeout((()=>{A()}),100),console.log("[Customer] 历史记录加载完成,开始建立WebSocket连接"),I())}else console.error("获取历史记录失败,状态码:",a.statusCode)}catch(r){console.error("获取历史记录异常:",r)}finally{y.value=!1}}else console.log("用户未登录,无法获取历史记录")};e.onPullDownRefresh((async()=>{if(y.value||!f.value)return console.log("正在加载或没有更多数据"),void e.index.stopPullDownRefresh();console.log("触发下拉分页,加载更多历史记录");const t=p.value+1;try{await w(t),await new Promise((e=>setTimeout(e,500)))}catch(o){console.error("加载历史记录失败:",o)}finally{e.index.stopPullDownRefresh()}}));const I=()=>{var t;if(!g)try{const o=`${null==(t=a.useModel)?void 0:t.WS_BASE_URL}/ws/socket.io/?EIO=4&transport=websocket`;g=e.index.connectSocket({url:o,header:{"content-type":"application/json"}}),e.index.onSocketOpen((t=>{v.value=!0;e.index.sendSocketMessage({data:'40/customer,{"jwt":""}',success:()=>{h.value&&setTimeout((()=>{const t=`42/customer,["join_conversation",{"conversation_id":"${h.value}"}]`;console.log("[Customer] 加入会话房间:",t),e.index.sendSocketMessage({data:t,success:()=>{console.log("[Customer] 成功加入会话房间")},fail:e=>{console.error("[Customer] 加入会话房间失败:",e)}})}),200)},fail:e=>{console.error("[Customer] Socket.IO连接包发送失败:",e)}})})),e.index.onSocketError((e=>{console.error("[Customer] WebSocket error:",e),v.value=!1,g=null})),e.index.onSocketClose((e=>{console.log("[Customer] WebSocket disconnected",e),v.value=!1,g=null})),e.index.onSocketMessage((t=>{const o=t.data;if("string"==typeof o)if(o.startsWith("42/customer,")){const e=o.substring(12);try{const t=JSON.parse(e);console.log("解析Socket.IO事件:",t),b(t)}catch(a){console.error("解析Socket.IO数据失败:",a,"原始数据:",e)}}else if(o.startsWith("40/customer"))console.log("Socket.IO连接确认");else if(o.startsWith("2"))e.index.sendSocketMessage({data:"3"});else if(o.startsWith("0"))console.log("Socket.IO握手成功");else try{const e=JSON.parse(o);console.log("解析JSON消息:",e),x(e)}catch(a){console.log("非JSON格式的字符串消息:",o)}else"object"==typeof o?(console.log("收到对象类型消息:",o),j(o)):console.log("收到其他类型消息,类型:",typeof o)}))}catch(o){console.error("初始化Socket.IO异常:",o),v.value=!1,g=null}},b=e=>{if(Array.isArray(e)&&e.length>=2){const t=e[0],o=e[1];console.log("[Customer] Socket.IO事件类型:",t,"事件数据:",o),"new_message"===t?O(o):"join_conversation_response"===t?console.log("[Customer] Joined room:",o):"message"===t?O(o):"typing"===t?T(o):console.log("[Customer] 未处理的Socket.IO事件类型:",t)}},x=e=>{console.log("[Customer] 处理JSON消息:",e),"message"===e.type||"new_message"===e.event?O(e.data||e):"typing"===e.type||"typing"===e.event?T(e.data||e):e.message||e.content?O(e):console.log("[Customer] 未识别的JSON消息结构:",e)},j=e=>{console.log("[Customer] 处理对象消息:",e),e.message||e.content||e.text?O(e):void 0!==e.is_typing?T(e):console.log("[Customer] 未识别的对象消息结构:",e)},T=e=>{e.is_typing&&"staff"===e.user_type?(m.value=!0,d.value="客服正在输入..."):m.value=!1},O=e=>{if("customer"===e.sender_type||"user"===e.role)return;let t="";if(t="string"==typeof e?e:e.message||e.content||e.text||e.body||"收到回复","string"==typeof t&&(t=t.replace(/↵/g,"\n").replace(/\\n/g,"\n")),console.log("[Customer] 收到新消息内容:",t),t===q.value)return console.log("[Customer] 消息与HTTP返回的消息相同,跳过显示"),void(q.value="");m.value=!1;const o={role:"ai",content:t,created_at:e.created_at||e.timestamp||e.time||(new Date).toISOString()};e.suggested_questions&&Array.isArray(e.suggested_questions)&&e.suggested_questions.length>0?o.quickQuestions=e.suggested_questions:e.quickQuestions&&Array.isArray(e.quickQuestions)&&e.quickQuestions.length>0&&(o.quickQuestions=e.quickQuestions),void 0!==e.need_confirmation&&(o.needConfirmation=e.need_confirmation),void 0!==e.confirmation_type&&(o.confirmationType=e.confirmation_type),c.value.push(o),A()},M=e=>{Q({message:e})},Q=e=>{i.value=e.message,W()},D=(e,t)=>{void 0===e.selectedConfirmation&&(e.selectedConfirmation=t,setTimeout((()=>{i.value=t,W()}),300))},W=async()=>{var t,n,s,r,u,g,p,_,f,y,S,k;const C=i.value.trim(),w=(null==(s=null==(n=null==(t=a.useModel)?void 0:t.selectedImages)?void 0:n.value)?void 0:s.length)>0;if(!C&&!w||m.value)return;const b=null==(u=null==(r=l.data)?void 0:r.user)?void 0:u.phone,x=null==(p=null==(g=l.data)?void 0:g.selected_house)?void 0:p.asset_projects_id,j=null==(f=null==(_=l.data)?void 0:_.selected_house)?void 0:f.full_name;if(!b||!x)return void e.index.showToast({title:"请先登录并绑定房屋",icon:"none"});v.value||(I(),await new Promise((e=>setTimeout(e,1e3))));const T=(null==(S=null==(y=a.useModel)?void 0:y.selectedImages)?void 0:S.value)||[];let O="text";w&&C?O="mixed":w&&!C&&(O="image");const M={role:"user",content:C||"",created_at:(new Date).toISOString(),message_type:O,image_url:T.length>0?T:void 0,images:T.length>0?T:void 0};c.value.push(M),i.value="",a.useModel.selectedImages.value=[],A(),C&&C.includes("查询")?d.value="正在查询中请稍后...":d.value="正在输入中...",m.value=!0;try{const e=await(null==(k=o.method)?void 0:k.customRequest("public/chat",{platform:"property",message:C||"",tenant_project_id:x,message_type:O,tenant_project_name:j||"",conversation_id:h.value,image_url:T.length>0?T:void 0}));if(200!==e.statusCode)throw new Error("请求失败");{const t=e.data;console.log("[Customer] HTTP接口响应数据:",t);let o=null,a=[],n=!1,s=null;if(t.reply&&"string"==typeof t.reply?(o=t.reply,a=t.suggested_questions||[],n=t.need_confirmation||!1,s=t.confirmation_type||null):t.reply&&t.reply.message?(o=t.reply.message,a=t.reply.suggested_questions||t.suggested_questions||[],n=t.reply.need_confirmation||t.need_confirmation||!1,s=t.reply.confirmation_type||t.confirmation_type||null):t.reply&&t.reply.content?(o=t.reply.content,a=t.reply.suggested_questions||t.suggested_questions||[],n=t.reply.need_confirmation||t.need_confirmation||!1,s=t.reply.confirmation_type||t.confirmation_type||null):t.message?(o=t.message,a=t.suggested_questions||[],n=t.need_confirmation||!1,s=t.confirmation_type||null):t.content?(o=t.content,a=t.suggested_questions||[],n=t.need_confirmation||!1,s=t.confirmation_type||null):t.answer?(o=t.answer,a=t.suggested_questions||[],n=t.need_confirmation||!1,s=t.confirmation_type||null):t.response?(o=t.response,a=t.suggested_questions||[],n=t.need_confirmation||!1,s=t.confirmation_type||null):"string"==typeof t&&(o=t),o){console.log("[Customer] HTTP接口返回回答消息:",o),console.log("[Customer] 建议问题:",a),console.log("[Customer] 需要确认:",n,"确认类型:",s);let e=o;"string"==typeof e&&(e=e.replace(/↵/g,"\n").replace(/\\n/g,"\n")),q.value=e,m.value=!1,c.value.push({role:"ai",content:e,created_at:(new Date).toISOString(),quickQuestions:a.length>0?a:void 0,needConfirmation:n,confirmationType:s}),A()}else console.log("[Customer] 消息发送成功,等待WebSocket回复")}}catch(Q){console.error("发送消息失败:",Q),e.index.showToast({title:"发送失败,请稍后重试",icon:"none"}),c.value.push({role:"ai",content:"抱歉,网络连接出现问题,请稍后再试。"}),m.value=!1,A()}};return e.onUnmounted((()=>{(g||v.value)&&(e.index.closeSocket(),g=null,v.value=!1,console.log("页面卸载,WebSocket连接已关闭"))})),e.onLoad((async t=>{var a,s,l;await(null==(a=e.getCurrentInstance())?void 0:a.appContext.config.globalProperties.$onLaunched),(null==(s=n.getUserLogin)?void 0:s.getLoginStatus())?(r.value=!0,k.value=await(null==(l=o.method)?void 0:l.getQuickQuestions()),w(1),(null==t?void 0:t.message)&&Q(t)):(r.value=!1,c.value=[])})),(t,n)=>{var s,l,g,v,p,_,f,y,h,S,k,q,A,w,I,b,x,j,T,O,Q,P,z,F,J,L;return e.e({a:r.value},r.value?e.e({b:e.o(M),c:e.f(c.value,((t,a,n)=>{var s,l;return e.e({a:"ai"===t.role},(t.role,{}),{b:t.image_url&&t.image_url.length>0},t.image_url&&t.image_url.length>0?{c:e.f(t.image_url,((a,n,s)=>({a:a,b:e.o((n=>{var s;return null==(s=e.unref(o.method))?void 0:s.previewImage(a,t.image_url)}),n),c:n}))),d:1===t.image_url.length?"widthFix":"aspectFill",e:1===t.image_url.length?1:""}:t.images&&t.images.length>0?{g:e.f(t.images,((a,n,s)=>({a:a,b:e.o((n=>{var s;return null==(s=e.unref(o.method))?void 0:s.previewImage(a,t.images)}),n),c:n}))),h:1===t.images.length?"widthFix":"aspectFill",i:1===t.images.length?1:""}:t.metadata&&t.metadata.image_url&&t.metadata.image_url.length>0?{k:e.f(t.metadata.image_url,((a,n,s)=>({a:a,b:e.o((n=>{var s;return null==(s=e.unref(o.method))?void 0:s.previewImage(a,t.metadata.image_url)}),n),c:n}))),l:1===t.metadata.image_url.length?"widthFix":"aspectFill",m:1===t.metadata.image_url.length?1:""}:{},{f:t.images&&t.images.length>0,j:t.metadata&&t.metadata.image_url&&t.metadata.image_url.length>0,n:t.content&&t.content.trim()},t.content&&t.content.trim()?{o:e.f(null==(s=e.unref(o.method))?void 0:s.formatMessageContent(t.content),((t,o,a)=>({a:e.t(t),b:"text-"+o})))}:{},{p:t.quickQuestions&&t.quickQuestions.length>0},t.quickQuestions&&t.quickQuestions.length>0?{q:e.f(t.quickQuestions,((t,o,a)=>({a:e.t(t),b:o,c:e.o((e=>(e=>{i.value=e,W()})(t)),o)})))}:{},{r:t.needConfirmation},t.needConfirmation?{s:"是"===t.selectedConfirmation?1:"",t:void 0!==t.selectedConfirmation?1:"",v:e.o((e=>D(t,"是")),a),w:"否"===t.selectedConfirmation?1:"",x:void 0!==t.selectedConfirmation?1:"",y:e.o((e=>D(t,"否")),a)}:{},{z:t.created_at&&!t.quickQuestions},t.created_at&&!t.quickQuestions?e.e({A:"ai"===t.role},"ai"===t.role?{B:e.o((a=>{var n;return null==(n=e.unref(o.method))?void 0:n.copyMessage(t.content)}),a)}:{},{C:e.t(null==(l=e.unref(o.method))?void 0:l.formatTime(t.created_at)),D:"user"===t.role},"user"===t.role?{E:e.o((a=>{var n;return null==(n=e.unref(o.method))?void 0:n.copyMessage(t.content)}),a)}:{}):{},{F:a,G:`msg-${a}`,H:e.n("user"===t.role?"user-message":"ai-message")})})),d:m.value},m.value?{e:e.t(d.value)}:{},{f:(null==(g=null==(l=null==(s=e.unref(a.useModel))?void 0:s.selectedImages)?void 0:l.value)?void 0:g.length)>0},(null==(_=null==(p=null==(v=e.unref(a.useModel))?void 0:v.selectedImages)?void 0:p.value)?void 0:_.length)>0?e.e({g:e.f(null==(y=null==(f=e.unref(a.useModel))?void 0:f.selectedImages)?void 0:y.value,((t,a,n)=>({a:t,b:"25c36616-1-"+n,c:e.o((t=>{var n;return null==(n=e.unref(o.method))?void 0:n.removeImage(a)}),a),d:a}))),h:e.p({type:"closeempty",size:"14",color:"#fff"}),i:(null==(k=null==(S=null==(h=e.unref(a.useModel))?void 0:h.selectedImages)?void 0:S.value)?void 0:k.length)<9},(null==(w=null==(A=null==(q=e.unref(a.useModel))?void 0:q.selectedImages)?void 0:A.value)?void 0:w.length)<9?{j:e.p({type:"plus",size:"30",color:"#999"}),k:e.o((t=>{var a;return null==(a=e.unref(o.method))?void 0:a.chooseImage()}))}:{}):{},{l:e.o((e=>u.value=!0)),m:e.o((e=>u.value=!1)),n:e.o(W),o:i.value,p:e.o((e=>i.value=e.detail.value)),q:!i.value.trim()&&!u.value&&0===(null==(x=null==(b=null==(I=e.unref(a.useModel))?void 0:I.selectedImages)?void 0:b.value)?void 0:x.length)},i.value.trim()||u.value||0!==(null==(O=null==(T=null==(j=e.unref(a.useModel))?void 0:j.selectedImages)?void 0:T.value)?void 0:O.length)?{}:{r:e.p({type:"camera",size:"24",color:"#666"}),s:e.o((t=>{var a;return null==(a=e.unref(o.method))?void 0:a.chooseImage()}))},{t:(i.value.trim()||u.value||(null==(z=null==(P=null==(Q=e.unref(a.useModel))?void 0:Q.selectedImages)?void 0:P.value)?void 0:z.length)>0)&&!m.value},(i.value.trim()||u.value||(null==(L=null==(J=null==(F=e.unref(a.useModel))?void 0:F.selectedImages)?void 0:J.value)?void 0:L.length)>0)&&!m.value?{v:e.p({type:"paperplane-filled",size:"20",color:"#fff"}),w:e.o(W)}:{},{x:m.value},m.value?{y:e.p({type:"spinner-cycle",size:"20",color:"#ccc"})}:{}):{z:e.p({height:"20vh",baseStyle:{paddingTop:"35%"},text:"登录体验更多功能"}),A:e.o(C),B:e.p({label:"去登录",size:"md",type:"primary"})})}}});l.__runtimeHooks=1,wx.createPage(l); diff --git a/dist/build/mp-weixin/pages/ai/chat.json b/dist/build/mp-weixin/pages/ai/chat.json index cab5d4c..54b1809 100644 --- a/dist/build/mp-weixin/pages/ai/chat.json +++ b/dist/build/mp-weixin/pages/ai/chat.json @@ -2,6 +2,9 @@ "navigationBarTitleText": "客服服务", "enablePullDownRefresh": true, "usingComponents": { - "uni-icons": "../../uni_modules/uni-icons/components/uni-icons/uni-icons" + "uni-icons": "../../uni_modules/uni-icons/components/uni-icons/uni-icons", + "hs-empty": "../../components/hs-empty/hs-empty", + "hs-button": "../../components/hs-button/hs-button", + "my-header-prologue": "./components/HeaderPrologue" } } \ No newline at end of file diff --git a/dist/build/mp-weixin/pages/ai/chat.wxml b/dist/build/mp-weixin/pages/ai/chat.wxml index 232818b..d27ba9d 100644 --- a/dist/build/mp-weixin/pages/ai/chat.wxml +++ b/dist/build/mp-weixin/pages/ai/chat.wxml @@ -1 +1 @@ - 我是管家-邻邻,有什么可以帮助您的吗? 房屋绑定 物业缴费 工单报事 社区服务 访客邀请 房屋管理 {{line.a}}{{question.a}}{{message.C}}{{c}}添加图片 \ No newline at end of file +{{line.a}}{{question.a}}{{message.C}}{{e}}添加图片 \ No newline at end of file diff --git a/dist/build/mp-weixin/pages/ai/chat.wxss b/dist/build/mp-weixin/pages/ai/chat.wxss index 9e08a0b..e59ad3d 100644 --- a/dist/build/mp-weixin/pages/ai/chat.wxss +++ b/dist/build/mp-weixin/pages/ai/chat.wxss @@ -1 +1 @@ -.chat_container_linear_gradient{position:fixed;z-index:1;top:0;left:0;width:100%;height:100vh;background:linear-gradient(180deg,rgba(208,229,255,.44) 0%,rgba(255,255,255,0) 300rpx),linear-gradient(159deg,#d3d7ff 0%,rgba(255,255,255,0) 150rpx),linear-gradient(188deg,#dffff3 -8%,#f7f7f7 300rpx);background-repeat:no-repeat}.chat_messages_body{position:relative;z-index:100}.chat-container{display:flex;flex-direction:column;min-height:100vh;width:100vw}.chat-messages{width:100%;padding:314rpx 30rpx 0;padding-bottom:calc(260rpx + env(safe-area-inset-bottom));box-sizing:border-box;flex:1}.message-item{display:flex;width:100%;box-sizing:border-box;margin-bottom:30rpx;animation:fadeIn .3s ease-in}.ai-message,.ai-message .message-content-wrapper{align-items:flex-start}.ai-message .message-content{background-color:#fff;color:#333;margin-left:12rpx;margin-right:0;flex-shrink:0}.ai-message .message-time{color:#999;font-size:22rpx;min-width:80rpx}.ai-message .message-meta{display:flex;align-items:center;justify-content:flex-start;margin-top:6rpx;gap:8rpx;margin-left:12rpx;flex-direction:row}.ai-message .message-avatar{margin-right:0;flex-shrink:0}.user-message{justify-content:flex-end;align-items:flex-start}.user-message .message-content-wrapper{align-items:flex-end}.user-message .message-content{background-color:#1c64f2;color:#fff;margin-right:0;flex-shrink:0}.user-message .message-content .message-images{margin-bottom:20rpx}.user-message .message-content .message-images .message-image-item{border-radius:8rpx}.user-message .message-time{color:#999;font-size:22rpx;margin-top:6rpx;text-align:right;min-width:80rpx}.user-message .message-meta{display:flex;align-items:center;justify-content:flex-end;margin-top:6rpx;gap:8rpx;flex-direction:row}@keyframes fadeIn{0%{opacity:0;transform:translateY(10rpx)}to{opacity:1;transform:translateY(0)}}.message-avatar{width:80rpx;height:80rpx;border-radius:50%;overflow:hidden;flex-shrink:0}.message-avatar image{width:100%;height:100%}.message-avatar .user-avatar-image{width:100%;height:100%;border-radius:50%}.message-avatar .user-avatar{width:100%;height:100%;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);display:flex;align-items:center;justify-content:center;color:#fff;font-size:24rpx;font-weight:500}.message-content-wrapper{display:flex;flex-direction:column;max-width:calc(100vw - 100rpx)}.message-content{padding:20rpx 24rpx;border-radius:16rpx;font-size:28rpx;line-height:1.5;word-wrap:break-word;word-break:break-all;box-sizing:border-box;background-color:#1c64f2}.message-content.loading{opacity:.7}.message-content:has(.message-images){padding:12rpx}.user-message .message-content:has(.message-images){padding:8rpx}.message-content view{display:block;width:100%;word-wrap:break-word;word-break:break-all}.message-content view:not(:last-child){margin-bottom:8rpx}.message-content text{display:inline;word-wrap:break-word;word-break:break-all}.quick-questions{margin-top:16rpx;display:flex;flex-direction:column;gap:12rpx;padding-left:12rpx}.question-btn{background-color:#f0f7ff;border:1px solid #d0e3ff;border-radius:12rpx;padding:16rpx 20rpx;font-size:26rpx;color:#1c64f2;line-height:1.4;transition:all .2s ease}.question-btn:active{background-color:#e6f2ff;transform:scale(.98)}.question-btn text{display:block;word-wrap:break-word;word-break:break-all}.confirmation-buttons{margin-top:16rpx;display:flex;gap:16rpx;justify-content:flex-start;padding-left:12rpx}.confirmation-btn{width:38rpx;border-radius:10rpx;padding:16rpx 22rpx;font-size:24rpx;line-height:1.4;text-align:center;transition:all .2s ease;background-color:#fff;color:#000;border:1px solid #e5e5e5}.confirmation-btn:active:not(.disabled){transform:scale(.98)}.confirmation-btn.selected{background-color:#1c64f2;color:#fff;border-color:#1c64f2}.confirmation-btn.disabled{opacity:.6;cursor:not-allowed}.confirmation-btn text{display:block;font-weight:500}.chat-input-area{position:fixed;bottom:0;left:0;right:0;background-color:#fff;border-top:1px solid #f8f8f8;padding:20rpx;padding-bottom:calc(155rpx + env(safe-area-inset-bottom));z-index:100}.input-container{display:flex;align-items:center;background-color:#f7f7f7;border-radius:50rpx;padding:10rpx 20rpx}.message-input{flex:1;height:70rpx;font-size:28rpx;padding:0 20rpx;background-color:transparent}.send-button{width:70rpx;height:70rpx;background:linear-gradient(135deg,#1c64f2 0%,#0e4aa7 100%);border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left:20rpx}.send-button.disabled{opacity:.5;pointer-events:none}.upload-button{width:70rpx;height:70rpx;background-color:#f7f7f7;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left:20rpx}.image-preview-area{margin-bottom:20rpx}.quick-actions-bar{display:flex;flex-wrap:wrap;gap:16rpx;padding:0 0 16rpx}.quick-action-btn{height:60rpx;padding:0 24rpx;background-color:#fff;border:1px solid #e5e5e5;border-radius:100rpx;font-size:23rpx;color:#333;display:flex;align-items:center;justify-content:center;transition:all .2s ease;white-space:nowrap}.quick-action-btn:active{transform:scale(.98);background-color:#f8f8f8}.quick-action-btn text{display:block}.image-preview-list{display:flex;flex-wrap:wrap;gap:16rpx}.image-preview-item{position:relative;width:120rpx;height:120rpx;border-radius:12rpx;overflow:hidden}.image-preview-item.add-more-button{background-color:#f5f5f5;border:2rpx dashed #ddd;display:flex;flex-direction:column;align-items:center;justify-content:center;cursor:pointer}.image-preview-item.add-more-button:active{background-color:#e8e8e8}.preview-image{width:100%;height:100%}.add-more-text{font-size:22rpx;color:#999;margin-top:8rpx}.remove-image{position:absolute;top:8rpx;right:8rpx;width:40rpx;height:40rpx;background-color:rgba(0,0,0,.6);border-radius:50%;display:flex;align-items:center;justify-content:center}.message-images{display:flex;flex-wrap:wrap;gap:12rpx;margin-bottom:12rpx;max-width:500rpx}.user-message .message-images{margin-bottom:0}.message-image-item{border-radius:12rpx;overflow:hidden}.message-image-item.single-image{max-width:500rpx;width:500rpx!important;height:auto!important}.user-message .message-image-item.single-image{max-width:450rpx;width:450rpx!important}.message-image-item:not(.single-image){width:200rpx;height:200rpx}.message-image{width:100%;height:100%;display:block}.message-text-line{margin-bottom:4rpx}.message-text-line:last-child{margin-bottom:0}.copy-button{width:32rpx;height:32rpx;display:flex;align-items:center;justify-content:center;border-radius:4rpx;transition:background-color .2s ease}.copy-button:active{background-color:rgba(0,0,0,.05)}.copy-button .copy-icon{width:26rpx;height:26rpx;opacity:.7}.opening_remarks{padding:30rpx 30rpx 10rpx;z-index:1000;position:fixed;top:0;left:0;right:0;background:linear-gradient(180deg,rgba(208,229,255,.44) 0%,rgba(255,255,255,0) 300rpx),linear-gradient(159deg,#d3d7ff 0%,rgba(255,255,255,0) 150rpx),linear-gradient(188deg,#dffff3 -8%,#f7f7f7 300rpx);background-repeat:no-repeat}.opening_remarks .opening_remarks_body{height:254rpx;border-radius:20rpx;border:1px solid #ffffff;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);display:flex;align-items:center;justify-content:center;background:linear-gradient(58deg,#e3faff 1%,rgba(255,255,255,0) 24%),linear-gradient(221deg,#dbe3ff 0%,rgba(255,255,255,0) 19%),rgba(255,255,255,.5)}.opening_remarks .opening_remarks_body .opening_remarks_server_img{width:56rpx;height:224rpx;margin:0 40rpx}.opening_remarks .opening_remarks_body .opening_remarks_server_img image{width:56rpx;height:224rpx}.opening_remarks .opening_remarks_body .opening_remarks_server_info{flex:1;padding-right:30rpx}.opening_remarks .opening_remarks_body .label{font-size:28rpx;color:#333;overflow:hidden;white-space:nowrap;width:0;display:inline-block;animation:typing 3s steps(30,end) forwards,blink .75s step-end infinite}.opening_remarks .opening_remarks_body .group_btn{display:flex;align-items:center;flex-wrap:wrap}.opening_remarks .opening_remarks_body .group_btn_item{background-color:#fff;border-radius:100rpx;font-size:24rpx;color:#333;padding:15rpx 25rpx;margin-top:15rpx;margin-right:30rpx}.opening_remarks .opening_remarks_body .group_btn_item:nth-child(3n){margin-right:0}@keyframes typing{0%{width:0}to{width:100%}} +.chat_container_linear_gradient{position:fixed;z-index:1;top:0;left:0;width:100%;height:100vh;background:linear-gradient(180deg,rgba(208,229,255,.44) 0%,rgba(255,255,255,0) 300rpx),linear-gradient(159deg,#d3d7ff 0%,rgba(255,255,255,0) 150rpx),linear-gradient(188deg,#dffff3 -8%,#f7f7f7 300rpx);background-repeat:no-repeat}.chat_messages_body{position:relative;z-index:100}.chat_messages_body .login_btn{padding:0 50rpx}.chat-container{display:flex;flex-direction:column;min-height:100vh;width:100vw}.chat-messages{width:100%;padding:314rpx 30rpx 0;padding-bottom:calc(260rpx + env(safe-area-inset-bottom));box-sizing:border-box;flex:1}.chat-messages-chat{padding-bottom:calc(160rpx + env(safe-area-inset-bottom))}.message-item{display:flex;width:100%;box-sizing:border-box;margin-bottom:30rpx;animation:fadeIn .3s ease-in}.ai-message,.ai-message .message-content-wrapper{align-items:flex-start}.ai-message .message-content{background-color:#fff;color:#333;margin-left:12rpx;margin-right:0;flex-shrink:0}.ai-message .message-time{color:#999;font-size:22rpx;min-width:80rpx}.ai-message .message-meta{display:flex;align-items:center;justify-content:flex-start;margin-top:6rpx;gap:8rpx;margin-left:12rpx;flex-direction:row}.ai-message .message-avatar{margin-right:0;flex-shrink:0}.user-message{justify-content:flex-end;align-items:flex-start}.user-message .message-content-wrapper{align-items:flex-end}.user-message .message-content{background-color:#1c64f2;color:#fff;margin-right:0;flex-shrink:0}.user-message .message-content .message-images{margin-bottom:20rpx}.user-message .message-content .message-images .message-image-item{border-radius:8rpx}.user-message .message-time{color:#999;font-size:22rpx;margin-top:6rpx;text-align:right;min-width:80rpx}.user-message .message-meta{display:flex;align-items:center;justify-content:flex-end;margin-top:6rpx;gap:8rpx;flex-direction:row}@keyframes fadeIn{0%{opacity:0;transform:translateY(10rpx)}to{opacity:1;transform:translateY(0)}}.message-avatar{width:80rpx;height:80rpx;border-radius:50%;overflow:hidden;flex-shrink:0}.message-avatar image{width:100%;height:100%}.message-avatar .user-avatar-image{width:100%;height:100%;border-radius:50%}.message-avatar .user-avatar{width:100%;height:100%;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);display:flex;align-items:center;justify-content:center;color:#fff;font-size:24rpx;font-weight:500}.message-content-wrapper{display:flex;flex-direction:column;max-width:calc(100vw - 100rpx)}.message-content{padding:20rpx 24rpx;border-radius:16rpx;font-size:28rpx;line-height:1.5;word-wrap:break-word;word-break:break-all;box-sizing:border-box;background-color:#1c64f2}.message-content.loading{opacity:.7}.message-content:has(.message-images){padding:12rpx}.user-message .message-content:has(.message-images){padding:8rpx}.message-content view{display:block;width:100%;word-wrap:break-word;word-break:break-all}.message-content view:not(:last-child){margin-bottom:8rpx}.message-content text{display:inline;word-wrap:break-word;word-break:break-all}.quick-questions{margin-top:16rpx;display:flex;flex-direction:column;gap:12rpx;padding-left:12rpx}.question-btn{background-color:#f0f7ff;border:1px solid #d0e3ff;border-radius:12rpx;padding:16rpx 20rpx;font-size:26rpx;color:#1c64f2;line-height:1.4;transition:all .2s ease}.question-btn:active{background-color:#e6f2ff;transform:scale(.98)}.question-btn text{display:block;word-wrap:break-word;word-break:break-all}.confirmation-buttons{margin-top:16rpx;display:flex;gap:16rpx;justify-content:flex-start;padding-left:12rpx}.confirmation-btn{width:38rpx;border-radius:10rpx;padding:16rpx 22rpx;font-size:24rpx;line-height:1.4;text-align:center;transition:all .2s ease;background-color:#fff;color:#000;border:1px solid #e5e5e5}.confirmation-btn:active:not(.disabled){transform:scale(.98)}.confirmation-btn.selected{background-color:#1c64f2;color:#fff;border-color:#1c64f2}.confirmation-btn.disabled{opacity:.6;cursor:not-allowed}.confirmation-btn text{display:block;font-weight:500}.chat-input-area{position:fixed;bottom:0;left:0;right:0;background-color:#fff;border-top:1px solid #f8f8f8;padding:20rpx;padding-bottom:calc(155rpx + env(safe-area-inset-bottom));z-index:100}.chat-input-area-chat{padding-bottom:calc(30rpx + env(safe-area-inset-bottom))}.input-container{display:flex;align-items:center;background-color:#f7f7f7;border-radius:50rpx;padding:10rpx 20rpx}.message-input{flex:1;height:70rpx;font-size:28rpx;padding:0 20rpx;background-color:transparent}.send-button{width:70rpx;height:70rpx;background:linear-gradient(135deg,#1c64f2 0%,#0e4aa7 100%);border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left:20rpx}.send-button.disabled{opacity:.5;pointer-events:none}.upload-button{width:70rpx;height:70rpx;background-color:#f7f7f7;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left:20rpx}.image-preview-area{margin-bottom:20rpx}.quick-actions-bar{display:flex;flex-wrap:wrap;gap:16rpx;padding:0 0 16rpx}.quick-action-btn{height:60rpx;padding:0 24rpx;background-color:#fff;border:1px solid #e5e5e5;border-radius:100rpx;font-size:23rpx;color:#333;display:flex;align-items:center;justify-content:center;transition:all .2s ease;white-space:nowrap}.quick-action-btn:active{transform:scale(.98);background-color:#f8f8f8}.quick-action-btn text{display:block}.image-preview-list{display:flex;flex-wrap:wrap;gap:16rpx}.image-preview-item{position:relative;width:120rpx;height:120rpx;border-radius:12rpx;overflow:hidden}.image-preview-item.add-more-button{background-color:#f5f5f5;border:2rpx dashed #ddd;display:flex;flex-direction:column;align-items:center;justify-content:center;cursor:pointer}.image-preview-item.add-more-button:active{background-color:#e8e8e8}.preview-image{width:100%;height:100%}.add-more-text{font-size:22rpx;color:#999;margin-top:8rpx}.remove-image{position:absolute;top:8rpx;right:8rpx;width:40rpx;height:40rpx;background-color:rgba(0,0,0,.6);border-radius:50%;display:flex;align-items:center;justify-content:center}.message-images{display:flex;flex-wrap:wrap;gap:12rpx;margin-bottom:12rpx;max-width:500rpx}.user-message .message-images{margin-bottom:0}.message-image-item{border-radius:12rpx;overflow:hidden}.message-image-item.single-image{max-width:500rpx;width:500rpx!important;height:auto!important}.user-message .message-image-item.single-image{max-width:450rpx;width:450rpx!important}.message-image-item:not(.single-image){width:200rpx;height:200rpx}.message-image{width:100%;height:100%;display:block}.message-text-line{margin-bottom:4rpx}.message-text-line:last-child{margin-bottom:0}.copy-button{width:32rpx;height:32rpx;display:flex;align-items:center;justify-content:center;border-radius:4rpx;transition:background-color .2s ease}.copy-button:active{background-color:rgba(0,0,0,.05)}.copy-button .copy-icon{width:26rpx;height:26rpx;opacity:.7}.opening_remarks{padding:30rpx 30rpx 10rpx;z-index:1000;position:fixed;top:0;left:0;right:0;background:linear-gradient(180deg,rgba(208,229,255,.44) 0%,rgba(255,255,255,0) 300rpx),linear-gradient(159deg,#d3d7ff 0%,rgba(255,255,255,0) 150rpx),linear-gradient(188deg,#dffff3 -8%,#f7f7f7 300rpx);background-repeat:no-repeat}.opening_remarks .opening_remarks_body{height:254rpx;border-radius:20rpx;border:1px solid #ffffff;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);display:flex;align-items:center;justify-content:center;background:linear-gradient(58deg,#e3faff 1%,rgba(255,255,255,0) 24%),linear-gradient(221deg,#dbe3ff 0%,rgba(255,255,255,0) 19%),rgba(255,255,255,.5)}.opening_remarks .opening_remarks_body .opening_remarks_server_img{width:56rpx;height:224rpx;margin:0 40rpx}.opening_remarks .opening_remarks_body .opening_remarks_server_img image{width:56rpx;height:224rpx}.opening_remarks .opening_remarks_body .opening_remarks_server_info{flex:1;padding-right:30rpx}.opening_remarks .opening_remarks_body .label{font-size:28rpx;color:#333;overflow:hidden;white-space:nowrap;width:0;display:inline-block;animation:typing 3s steps(30,end) forwards,blink .75s step-end infinite}.opening_remarks .opening_remarks_body .group_btn{display:flex;align-items:center;flex-wrap:wrap;overflow:hidden;height:160rpx}.opening_remarks .opening_remarks_body .group_btn_item{background-color:#fff;border-radius:100rpx;font-size:24rpx;color:#333;padding:15rpx 25rpx;margin-top:15rpx;margin-right:30rpx}.opening_remarks .opening_remarks_body .group_btn_item:nth-child(3n){margin-right:0}@keyframes typing{0%{width:0}to{width:100%}} diff --git a/dist/build/mp-weixin/static/svg/ai_icon.svg b/dist/build/mp-weixin/static/svg/ai_icon.svg deleted file mode 100644 index 74d6a34..0000000 --- a/dist/build/mp-weixin/static/svg/ai_icon.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/dist/dev/mp-weixin/pages/ai/chat.js b/dist/dev/mp-weixin/pages/ai/chat.js index 35befea..7014b41 100644 --- a/dist/dev/mp-weixin/pages/ai/chat.js +++ b/dist/dev/mp-weixin/pages/ai/chat.js @@ -3,11 +3,13 @@ const common_vendor = require("../../common/vendor.js"); require("../../common/libraries/request.js"); const common_store_useWeAppAuthStore = require("../../common/store/useWeAppAuthStore.js"); require("../../common/store/useWorkStore.js"); -const common_libraries_upload = require("../../common/libraries/upload.js"); +const pages_ai_method = require("./method.js"); +const pages_ai_model = require("./model.js"); const common_libraries_userUserLogin = require("../../common/libraries/userUserLogin.js"); require("../../gen/Apis.js"); require("../../common/libraries/setTabBar.js"); require("../../common/libraries/apiLoading.js"); +require("../../common/libraries/upload.js"); if (!Array) { const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons"); const _easycom_hs_empty2 = common_vendor.resolveComponent("hs-empty"); @@ -18,8 +20,9 @@ const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-ico const _easycom_hs_empty = () => "../../components/hs-empty/hs-empty.js"; const _easycom_hs_button = () => "../../components/hs-button/hs-button.js"; if (!Math) { - (_easycom_uni_icons + _easycom_hs_empty + _easycom_hs_button)(); + (MyHeaderPrologue + _easycom_uni_icons + _easycom_hs_empty + _easycom_hs_button)(); } +const MyHeaderPrologue = () => "./components/HeaderPrologue.js"; const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ __name: "chat", setup(__props) { @@ -28,15 +31,12 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ const auth = common_store_useWeAppAuthStore.useWeAppAuthStore(); const userLoginStatus = common_vendor.ref(false); const inputMessage = common_vendor.ref(""); - const selectedImages = common_vendor.ref([]); const isInputFocused = common_vendor.ref(false); const messages = common_vendor.ref([]); const loading = common_vendor.ref(false); const loadingText = common_vendor.ref("正在输入中..."); let socketTask = null; let isConnected = common_vendor.ref(false); - const API_BASE_URL = "https://kf-api-test.linyikj.com.cn"; - const WS_BASE_URL = "wss://kf-api-test.linyikj.com.cn"; const currentPage = common_vendor.ref(1); const pageSize = common_vendor.ref(10); const hasMore = common_vendor.ref(true); @@ -45,82 +45,11 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ const currentOffset = common_vendor.ref(0); const quickQuestionsData = common_vendor.ref({}); const lastMessageContent = common_vendor.ref(""); - const getQuickQuestions = async () => { - var _a; - try { - let selected_house = (_a = auth == null ? void 0 : auth.data) == null ? void 0 : _a.selected_house; - const response = await common_vendor.index.request({ - url: `${API_BASE_URL}/api/public/quick-questions?platform=property&company_id=${selected_house == null ? void 0 : selected_house.companies_id}&project_id=${selected_house == null ? void 0 : selected_house.asset_projects_id}`, - method: "GET" - }); - if (response.statusCode === 200) { - const result = response.data; - console.log("获取到开场白按钮数据2:", result); - return result; - } else { - console.error("获取开场白数据失败,状态码:", response.statusCode); - return []; - } - } catch (error) { - console.error("获取开场白数据异常:", error); - return []; - } - }; const goToPageLogin = () => { common_vendor.index.navigateTo({ url: "/pages/login" }); }; - const formatMessageContent = (content) => { - if (!content || typeof content !== "string") { - return [""]; - } - return content.split("\n").filter((line) => line.trim() !== ""); - }; - const previewImage = (currentImage, images) => { - common_vendor.index.previewImage({ - current: currentImage, - urls: images - }); - }; - const copyMessage = (content) => { - if (!content) { - common_vendor.index.showToast({ - title: "暂无内容可复制", - icon: "none" - }); - return; - } - common_vendor.index.setClipboardData({ - data: content, - success: () => { - common_vendor.index.showToast({ - title: "复制成功", - icon: "success" - }); - }, - fail: () => { - common_vendor.index.showToast({ - title: "复制失败", - icon: "none" - }); - } - }); - }; - const formatTime = (timeStr) => { - if (!timeStr) - return ""; - try { - const date = common_vendor.dayjs(timeStr); - if (!date.isValid()) { - return ""; - } - return date.fromNow(); - } catch (e) { - console.error("时间格式化错误:", e); - return ""; - } - }; const scrollToBottom = () => { common_vendor.nextTick$1(() => { common_vendor.index.pageScrollTo({ @@ -130,7 +59,7 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ }); }; const getHistoryMessages = async (page = 1) => { - var _a, _b; + var _a, _b, _c; const userPhone = (_b = (_a = auth.data) == null ? void 0 : _a.user) == null ? void 0 : _b.phone; if (!userPhone) { console.log("用户未登录,无法获取历史记录"); @@ -143,18 +72,13 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ isLoadingHistory.value = true; const offset = (page - 1) * pageSize.value; currentOffset.value = offset; - console.log("分页信息 - 页码:", page, "每页数量:", pageSize.value, "计算出的offset:", offset); - const response = await common_vendor.index.request({ - url: `${API_BASE_URL}/api/public/customer/init`, - method: "POST", - data: { - platform: "property", - platform_user_id: userPhone, - //userPhone - limit: pageSize.value, - offset - } - }); + const response = await ((_c = pages_ai_method.method) == null ? void 0 : _c.customRequest("public/customer/init", { + platform: "property", + platform_user_id: userPhone, + //userPhone + limit: pageSize.value, + offset + })); if (response.statusCode === 200) { const result = response.data; let historyMessages = []; @@ -278,26 +202,6 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ const totalItems = result.total || result.count || result.total_count || 0; hasMore.value = totalItems > messages.value.length; currentPage.value = page; - if (page > 1 && !hasMore.value) { - console.log("分页加载完成,当前页:", page, "hasMore:", hasMore.value, "展示开场白"); - setTimeout(() => { - addQuickQuestionsToFirstAIMessage(true); - }, 500); - } - console.log( - "第", - page, - "页数据加载完成,offset:", - offset, - ", limit:", - pageSize.value, - ", 总数据:", - totalItems, - ", 当前已加载:", - messages.value.length, - ", 是否有更多:", - hasMore.value - ); if (page === 1) { setTimeout(() => { scrollToBottom(); @@ -332,13 +236,12 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ } }); const initWebSocket = () => { + var _a; if (socketTask) { return; } try { - const wsUrl = `${WS_BASE_URL}/ws/socket.io/?EIO=4&transport=websocket`; - console.log("正在建立Socket.IO连接"); - console.log("连接URL:", wsUrl); + const wsUrl = `${(_a = pages_ai_model.useModel) == null ? void 0 : _a.WS_BASE_URL}/ws/socket.io/?EIO=4&transport=websocket`; socketTask = common_vendor.index.connectSocket({ url: wsUrl, header: { @@ -346,13 +249,11 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ } }); common_vendor.index.onSocketOpen((res) => { - console.log("[Customer] WebSocket connected", res); isConnected.value = true; const connectPacket = '40/customer,{"jwt":""}'; common_vendor.index.sendSocketMessage({ data: connectPacket, success: () => { - console.log("[Customer] Socket.IO连接包发送成功"); if (conversationId.value) { setTimeout(() => { const joinMessage = `42/customer,["join_conversation",{"conversation_id":"${conversationId.value}"}]`; @@ -385,9 +286,6 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ socketTask = null; }); common_vendor.index.onSocketMessage((res) => { - console.log("收到WebSocket原始消息:", res); - console.log("消息数据类型:", typeof res.data); - console.log("消息内容:", res.data); const data = res.data; if (typeof data === "string") { if (data.startsWith("42/customer,")) { @@ -470,7 +368,6 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ } }; const processTypingIndicator = (typingData) => { - console.log("[Customer] 处理typing指示器:", typingData); if (typingData.is_typing && typingData.user_type === "staff") { loading.value = true; loadingText.value = "客服正在输入..."; @@ -478,35 +375,8 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ loading.value = false; } }; - const checkShouldShowQuickQuestions = (isLastPage = false) => { - return quickQuestionsData.value.length > 0; - }; - const addQuickQuestionsToFirstAIMessage = (isLastPage = false) => { - if (quickQuestionsData.value.length === 0) { - return; - } - if (!checkShouldShowQuickQuestions(isLastPage)) { - return; - } - const welcomeMessage = { - role: "ai", - content: "您好!我是物业客服,有什么可以帮助您的吗?", - quickQuestions: quickQuestionsData.value, - created_at: new Date().toISOString() - }; - console.log("[Customer] 创建开场白消息,是否最后一页:", isLastPage); - if (messages.value.length === 0) { - messages.value = [welcomeMessage]; - console.log("[Customer] 设置开场白为第一条消息"); - } else { - messages.value.unshift(welcomeMessage); - console.log("[Customer] 在第一条消息前面插入开场白"); - } - }; const processMessage = (messageData) => { - console.log("[Customer] 处理消息数据:", messageData); if (messageData.sender_type === "customer" || messageData.role === "user") { - console.log("[Customer] 过滤掉客户消息"); return; } let messageContent = ""; @@ -565,46 +435,15 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ handleSendMessage(); }, 300); }; - const chooseImage = async () => { - const maxImages = 9; - if (selectedImages.value.length >= maxImages) { - common_vendor.index.showToast({ - title: "最多选择9张图片", - icon: "none" - }); - return; - } - try { - const remainingCount = maxImages - selectedImages.value.length; - const uploadResult = await common_libraries_upload.upload(remainingCount, 2, ["image"]); - if (uploadResult && Array.isArray(uploadResult) && uploadResult.length > 0) { - const imageUrls = uploadResult.map((item) => item.url); - selectedImages.value.push(...imageUrls); - common_vendor.index.showToast({ - title: "图片上传成功", - icon: "success" - }); - } - } catch (error) { - console.error("选择图片失败:", error); - common_vendor.index.showToast({ - title: "选择图片失败", - icon: "none" - }); - } - }; - const removeImage = (index) => { - selectedImages.value.splice(index, 1); - }; const handleSendMessage = async () => { - var _a, _b, _c, _d, _e, _f; + var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l; const message = inputMessage.value.trim(); - const hasImages = selectedImages.value.length > 0; + const hasImages = ((_c = (_b = (_a = pages_ai_model.useModel) == null ? void 0 : _a.selectedImages) == null ? void 0 : _b.value) == null ? void 0 : _c.length) > 0; if (!message && !hasImages || loading.value) return; - const userPhone = (_b = (_a = auth.data) == null ? void 0 : _a.user) == null ? void 0 : _b.phone; - const projectId = (_d = (_c = auth.data) == null ? void 0 : _c.selected_house) == null ? void 0 : _d.asset_projects_id; - const projectName = (_f = (_e = auth.data) == null ? void 0 : _e.selected_house) == null ? void 0 : _f.full_name; + const userPhone = (_e = (_d = auth.data) == null ? void 0 : _d.user) == null ? void 0 : _e.phone; + const projectId = (_g = (_f = auth.data) == null ? void 0 : _f.selected_house) == null ? void 0 : _g.asset_projects_id; + const projectName = (_i = (_h = auth.data) == null ? void 0 : _h.selected_house) == null ? void 0 : _i.full_name; if (!userPhone || !projectId) { common_vendor.index.showToast({ title: "请先登录并绑定房屋", @@ -616,7 +455,7 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ initWebSocket(); await new Promise((resolve) => setTimeout(resolve, 1e3)); } - const uploadedImages = selectedImages.value; + const uploadedImages = ((_k = (_j = pages_ai_model.useModel) == null ? void 0 : _j.selectedImages) == null ? void 0 : _k.value) || []; let messageType = "text"; if (hasImages && message) { messageType = "mixed"; @@ -634,7 +473,7 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ }; messages.value.push(userMessage); inputMessage.value = ""; - selectedImages.value = []; + pages_ai_model.useModel.selectedImages.value = []; scrollToBottom(); if (message && message.includes("查询")) { loadingText.value = "正在查询中请稍后..."; @@ -643,24 +482,16 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ } loading.value = true; try { - const response = await common_vendor.index.request({ - url: `${API_BASE_URL}/api/public/chat`, - method: "POST", - data: { - platform: "property", - message: message || "", - // 纯图片时传空字符串 - tenant_project_id: projectId, - tenant_project_name: projectName || "", - platform_user_id: userPhone, - conversation_id: conversationId.value, - message_type: messageType, - image_url: uploadedImages.length > 0 ? uploadedImages : void 0 - }, - header: { - "Content-Type": "application/json" - } - }); + const response = await ((_l = pages_ai_method.method) == null ? void 0 : _l.customRequest("public/chat", { + platform: "property", + message: message || "", + // 纯图片时传空字符串 + tenant_project_id: projectId, + message_type: messageType, + tenant_project_name: projectName || "", + conversation_id: conversationId.value, + image_url: uploadedImages.length > 0 ? uploadedImages : void 0 + })); if (response.statusCode === 200) { const result = response.data; console.log("[Customer] HTTP接口响应数据:", result); @@ -755,17 +586,10 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ }); common_vendor.onLoad(async (op) => { var _a, _b, _c; - console.log( - "页面加载时已获取开场白按钮数据1:", - quickQuestionsData.value.length, - (_a = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _a.getLoginStatus() - ); - await ((_b = common_vendor.getCurrentInstance()) == null ? void 0 : _b.appContext.config.globalProperties.$onLaunched); - if ((_c = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _c.getLoginStatus()) { + await ((_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$onLaunched); + if ((_b = common_libraries_userUserLogin.getUserLogin) == null ? void 0 : _b.getLoginStatus()) { userLoginStatus.value = true; - console.log("页面加载时已获取开场白按钮数据3:", quickQuestionsData.value.length); - quickQuestionsData.value = await getQuickQuestions(); - console.log("页面加载时已获取开场白按钮数据2:", quickQuestionsData.value.length); + quickQuestionsData.value = await ((_c = pages_ai_method.method) == null ? void 0 : _c.getQuickQuestions()); getHistoryMessages(1); if (op == null ? void 0 : op.message) { handleQuickAction(op); @@ -776,19 +600,13 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ } }); return (_ctx, _cache) => { - var _a, _b; + var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z; return common_vendor.e({ a: userLoginStatus.value }, userLoginStatus.value ? common_vendor.e({ - b: common_vendor.t(((_a = quickQuestionsData.value) == null ? void 0 : _a.greeting_text) || "我是管家-邻邻,有什么可以帮助您的吗?"), - c: common_vendor.f((_b = quickQuestionsData.value) == null ? void 0 : _b.questions, (i, index, i0) => { - return { - a: common_vendor.t(i), - b: `item_${index}`, - c: common_vendor.o(($event) => handleQuickFast(i), `item_${index}`) - }; - }), - d: common_vendor.f(messages.value, (message, index, i0) => { + b: common_vendor.o(handleQuickFast), + c: common_vendor.f(messages.value, (message, index, i0) => { + var _a2, _b2; return common_vendor.e({ a: message.role === "ai" }, message.role === "ai" ? {} : {}, { @@ -797,7 +615,10 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ c: common_vendor.f(message.image_url, (image, imgIndex, i1) => { return { a: image, - b: common_vendor.o(($event) => previewImage(image, message.image_url), imgIndex), + b: common_vendor.o(($event) => { + var _a3; + return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.previewImage(image, message.image_url); + }, imgIndex), c: imgIndex }; }), @@ -807,7 +628,10 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ g: common_vendor.f(message.images, (image, imgIndex, i1) => { return { a: image, - b: common_vendor.o(($event) => previewImage(image, message.images), imgIndex), + b: common_vendor.o(($event) => { + var _a3; + return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.previewImage(image, message.images); + }, imgIndex), c: imgIndex }; }), @@ -817,7 +641,10 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ k: common_vendor.f(message.metadata.image_url, (image, imgIndex, i1) => { return { a: image, - b: common_vendor.o(($event) => previewImage(image, message.metadata.image_url), imgIndex), + b: common_vendor.o(($event) => { + var _a3; + return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.previewImage(image, message.metadata.image_url); + }, imgIndex), c: imgIndex }; }), @@ -828,7 +655,7 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ j: message.metadata && message.metadata.image_url && message.metadata.image_url.length > 0, n: message.content && message.content.trim() }, message.content && message.content.trim() ? { - o: common_vendor.f(formatMessageContent(message.content), (line, lineIndex, i1) => { + o: common_vendor.f((_a2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a2.formatMessageContent(message.content), (line, lineIndex, i1) => { return { a: common_vendor.t(line), b: "text-" + lineIndex @@ -858,86 +685,101 @@ const _sfc_defineComponent = /* @__PURE__ */ common_vendor.defineComponent({ }, message.created_at && !message.quickQuestions ? common_vendor.e({ A: message.role === "ai" }, message.role === "ai" ? { - B: common_vendor.o(($event) => copyMessage(message.content), index) + B: common_vendor.o(($event) => { + var _a3; + return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.copyMessage(message.content); + }, index) } : {}, { - C: common_vendor.t(formatTime(message.created_at)), + C: common_vendor.t((_b2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _b2.formatTime(message.created_at)), D: message.role === "user" }, message.role === "user" ? { - E: common_vendor.o(($event) => copyMessage(message.content), index) + E: common_vendor.o(($event) => { + var _a3; + return (_a3 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a3.copyMessage(message.content); + }, index) } : {}) : {}, { F: index, G: `msg-${index}`, H: common_vendor.n(message.role === "user" ? "user-message" : "ai-message") }); }), - e: loading.value + d: loading.value }, loading.value ? { - f: common_vendor.t(loadingText.value) + e: common_vendor.t(loadingText.value) } : {}, { - g: selectedImages.value.length > 0 - }, selectedImages.value.length > 0 ? common_vendor.e({ - h: common_vendor.f(selectedImages.value, (image, index, i0) => { + f: ((_c = (_b = (_a = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _a.selectedImages) == null ? void 0 : _b.value) == null ? void 0 : _c.length) > 0 + }, ((_f = (_e = (_d = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _d.selectedImages) == null ? void 0 : _e.value) == null ? void 0 : _f.length) > 0 ? common_vendor.e({ + g: common_vendor.f((_h = (_g = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _g.selectedImages) == null ? void 0 : _h.value, (image, index, i0) => { return { a: image, - b: "25c36616-0-" + i0, - c: common_vendor.o(($event) => removeImage(index), index), + b: "25c36616-1-" + i0, + c: common_vendor.o(($event) => { + var _a2; + return (_a2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a2.removeImage(index); + }, index), d: index }; }), - i: common_vendor.p({ + h: common_vendor.p({ type: "closeempty", size: "14", color: "#fff" }), - j: selectedImages.value.length < 9 - }, selectedImages.value.length < 9 ? { - k: common_vendor.p({ + i: ((_k = (_j = (_i = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _i.selectedImages) == null ? void 0 : _j.value) == null ? void 0 : _k.length) < 9 + }, ((_n = (_m = (_l = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _l.selectedImages) == null ? void 0 : _m.value) == null ? void 0 : _n.length) < 9 ? { + j: common_vendor.p({ type: "plus", size: "30", color: "#999" }), - l: common_vendor.o(chooseImage) + k: common_vendor.o(($event) => { + var _a2; + return (_a2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a2.chooseImage(); + }) } : {}) : {}, { - m: common_vendor.o(($event) => isInputFocused.value = true), - n: common_vendor.o(($event) => isInputFocused.value = false), - o: common_vendor.o(handleSendMessage), - p: inputMessage.value, - q: common_vendor.o(($event) => inputMessage.value = $event.detail.value), - r: !inputMessage.value.trim() && !isInputFocused.value && selectedImages.value.length === 0 - }, !inputMessage.value.trim() && !isInputFocused.value && selectedImages.value.length === 0 ? { - s: common_vendor.p({ + l: common_vendor.o(($event) => isInputFocused.value = true), + m: common_vendor.o(($event) => isInputFocused.value = false), + n: common_vendor.o(handleSendMessage), + o: inputMessage.value, + p: common_vendor.o(($event) => inputMessage.value = $event.detail.value), + q: !inputMessage.value.trim() && !isInputFocused.value && ((_q = (_p = (_o = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _o.selectedImages) == null ? void 0 : _p.value) == null ? void 0 : _q.length) === 0 + }, !inputMessage.value.trim() && !isInputFocused.value && ((_t = (_s = (_r = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _r.selectedImages) == null ? void 0 : _s.value) == null ? void 0 : _t.length) === 0 ? { + r: common_vendor.p({ type: "camera", size: "24", color: "#666" }), - t: common_vendor.o(chooseImage) + s: common_vendor.o(($event) => { + var _a2; + return (_a2 = common_vendor.unref(pages_ai_method.method)) == null ? void 0 : _a2.chooseImage(); + }) } : {}, { - v: (inputMessage.value.trim() || isInputFocused.value || selectedImages.value.length > 0) && !loading.value - }, (inputMessage.value.trim() || isInputFocused.value || selectedImages.value.length > 0) && !loading.value ? { - w: common_vendor.p({ + t: (inputMessage.value.trim() || isInputFocused.value || ((_w = (_v = (_u = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _u.selectedImages) == null ? void 0 : _v.value) == null ? void 0 : _w.length) > 0) && !loading.value + }, (inputMessage.value.trim() || isInputFocused.value || ((_z = (_y = (_x = common_vendor.unref(pages_ai_model.useModel)) == null ? void 0 : _x.selectedImages) == null ? void 0 : _y.value) == null ? void 0 : _z.length) > 0) && !loading.value ? { + v: common_vendor.p({ type: "paperplane-filled", size: "20", color: "#fff" }), - x: common_vendor.o(handleSendMessage) + w: common_vendor.o(handleSendMessage) } : {}, { - y: loading.value + x: loading.value }, loading.value ? { - z: common_vendor.p({ + y: common_vendor.p({ type: "spinner-cycle", size: "20", color: "#ccc" }) } : {}) : { - A: common_vendor.p({ + z: common_vendor.p({ height: "20vh", baseStyle: { paddingTop: "35%" }, text: "登录体验更多功能" }), - B: common_vendor.o(goToPageLogin), - C: common_vendor.p({ + A: common_vendor.o(goToPageLogin), + B: common_vendor.p({ label: "去登录", size: "md", type: "primary" diff --git a/dist/dev/mp-weixin/pages/ai/chat.json b/dist/dev/mp-weixin/pages/ai/chat.json index bdb9392..54b1809 100644 --- a/dist/dev/mp-weixin/pages/ai/chat.json +++ b/dist/dev/mp-weixin/pages/ai/chat.json @@ -4,6 +4,7 @@ "usingComponents": { "uni-icons": "../../uni_modules/uni-icons/components/uni-icons/uni-icons", "hs-empty": "../../components/hs-empty/hs-empty", - "hs-button": "../../components/hs-button/hs-button" + "hs-button": "../../components/hs-button/hs-button", + "my-header-prologue": "./components/HeaderPrologue" } } \ No newline at end of file diff --git a/dist/dev/mp-weixin/pages/ai/chat.wxml b/dist/dev/mp-weixin/pages/ai/chat.wxml index ce9cbf7..d27ba9d 100644 --- a/dist/dev/mp-weixin/pages/ai/chat.wxml +++ b/dist/dev/mp-weixin/pages/ai/chat.wxml @@ -1 +1 @@ -{{b}}{{i.a}}{{line.a}}{{question.a}}{{message.C}}{{f}}添加图片 \ No newline at end of file +{{line.a}}{{question.a}}{{message.C}}{{e}}添加图片 \ No newline at end of file diff --git a/dist/dev/mp-weixin/project.private.config.json b/dist/dev/mp-weixin/project.private.config.json index 3c11075..f5fef16 100644 --- a/dist/dev/mp-weixin/project.private.config.json +++ b/dist/dev/mp-weixin/project.private.config.json @@ -21,6 +21,7 @@ }, "libVersion": "3.13.2", "setting": { - "bigPackageSizeSupport": false + "bigPackageSizeSupport": false, + "urlCheck": true } } \ No newline at end of file diff --git a/dist/dev/mp-weixin/static/svg/ai_icon.svg b/dist/dev/mp-weixin/static/svg/ai_icon.svg deleted file mode 100644 index 74d6a34..0000000 --- a/dist/dev/mp-weixin/static/svg/ai_icon.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/pages/ai/chat.vue b/src/pages/ai/chat.vue index e909d46..cedf61f 100644 --- a/src/pages/ai/chat.vue +++ b/src/pages/ai/chat.vue @@ -2,31 +2,7 @@ - - - - - - - - {{ quickQuestionsData?.greeting_text || '我是管家-邻邻,有什么可以帮助您的吗?' }} - - - - {{ i }} - - - - - + @@ -73,7 +49,7 @@ :src="image" :mode="message.images.length === 1 ? 'widthFix' : 'aspectFill'" class="message-image" - @click="previewImage(image, message.images!)" + @click="method?.previewImage(image, message.images!)" /> @@ -97,7 +73,7 @@ :src="image" :mode="message.metadata.image_url.length === 1 ? 'widthFix' : 'aspectFill'" class="message-image" - @click="previewImage(image, message.metadata.image_url!)" + @click="method?.previewImage(image, message.metadata.image_url!)" /> @@ -105,7 +81,7 @@ @@ -153,15 +129,15 @@ - {{ formatTime(message.created_at) }} + {{ method?.formatTime(message.created_at) }} @@ -171,7 +147,10 @@ - + {{ loadingText }} @@ -181,20 +160,24 @@ - + - + - + 添加图片 @@ -219,7 +202,9 @@ v-model="inputMessage" class="message-input" placeholder="请输入您的问题..." + adjust-position :confirm-type="'send'" + :cursor-spacing="15" @focus="isInputFocused = true" @blur="isInputFocused = false" @confirm="handleSendMessage" @@ -227,16 +212,25 @@ @@ -263,12 +257,14 @@ import { ref, nextTick, onUnmounted, getCurrentInstance } from 'vue' import { useWeAppAuthStore } from '@/common' import { onPullDownRefresh, onLoad, onPageScroll, onShow } from '@dcloudio/uni-app' +import method from './method' import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime' import 'dayjs/locale/zh-cn' -import { upload } from '@/common/libraries/upload' -import { quickActions, QuickAction } from '@/common/libraries/public' +import useModel from './model' +import { QuickAction } from '@/common/libraries/public' import getLoginStatus from '@/common/libraries/userUserLogin' +import MyHeaderPrologue from './components/HeaderPrologue.vue' // 配置dayjs dayjs.extend(relativeTime) @@ -294,7 +290,6 @@ interface Message { const auth = useWeAppAuthStore() const userLoginStatus = ref(false) const inputMessage = ref('') -const selectedImages = ref([]) // 选中的图片 const isInputFocused = ref(false) // 输入框是否聚焦 const messages = ref([]) const loading = ref(false) @@ -302,12 +297,6 @@ const loadingText = ref('正在输入中...') let socketTask: any = null let isConnected = ref(false) -// 接口域名配置 -// const API_BASE_URL = 'http://10.39.13.78:8000' //dev环境 -// const WS_BASE_URL = 'wss://10.39.13.78:8000' //dev环境 -const API_BASE_URL = 'https://kf-api-test.linyikj.com.cn' //测试环境 -const WS_BASE_URL = 'wss://kf-api-test.linyikj.com.cn' //测试环境 - // 历史记录相关 const currentPage = ref(1) const pageSize = ref(10) @@ -318,98 +307,13 @@ const currentOffset = ref(0) // 当前偏移量 const quickQuestionsData = ref({}) // 存储开场白数据 const lastMessageContent = ref('') // 用于防止重复显示相同的消息 -// 获取开场白按钮数据 -const getQuickQuestions = async () => { - try { - let selected_house = auth?.data?.selected_house - const response = await uni.request({ - url: `${API_BASE_URL}/api/public/quick-questions?platform=property&company_id=${selected_house?.companies_id}&project_id=${selected_house?.asset_projects_id}`, - method: 'GET' - }) - - if (response.statusCode === 200) { - const result = response.data as any - - console.log('获取到开场白按钮数据2:', result) - return result - } else { - console.error('获取开场白数据失败,状态码:', response.statusCode) - return [] - } - } catch (error) { - console.error('获取开场白数据异常:', error) - return [] - } -} - const goToPageLogin = () => { uni.navigateTo({ url: '/pages/login' }) } -// 格式化消息内容,处理换行符 -const formatMessageContent = (content: string) => { - if (!content || typeof content !== 'string') { - return [''] - } - return content.split('\n').filter(line => line.trim() !== '') -} - -// 预览图片 -const previewImage = (currentImage: string, images: string[]) => { - uni.previewImage({ - current: currentImage, - urls: images - }) -} - -// 复制消息内容 -const copyMessage = (content: string) => { - if (!content) { - uni.showToast({ - title: '暂无内容可复制', - icon: 'none' - }) - return - } - - uni.setClipboardData({ - data: content, - success: () => { - uni.showToast({ - title: '复制成功', - icon: 'success' - }) - }, - fail: () => { - uni.showToast({ - title: '复制失败', - icon: 'none' - }) - } - }) -} - // 时间格式化函数 -const formatTime = (timeStr: string) => { - if (!timeStr) return '' - - try { - const date = dayjs(timeStr) - - // 检查日期是否有效 - if (!date.isValid()) { - return '' - } - - // 使用相对时间显示 - return date.fromNow() - } catch (e) { - console.error('时间格式化错误:', e) - return '' - } -} const scrollToBottom = () => { nextTick(() => { @@ -441,17 +345,11 @@ const getHistoryMessages = async (page: number = 1) => { const offset = (page - 1) * pageSize.value currentOffset.value = offset - console.log('分页信息 - 页码:', page, '每页数量:', pageSize.value, '计算出的offset:', offset) - - const response = await uni.request({ - url: `${API_BASE_URL}/api/public/customer/init`, - method: 'POST', - data: { - platform: 'property', - platform_user_id: userPhone, //userPhone - limit: pageSize.value, - offset: offset - } + const response = await method?.customRequest('public/customer/init', { + platform: 'property', + platform_user_id: userPhone, //userPhone + limit: pageSize.value, + offset: offset }) if (response.statusCode === 200) { @@ -648,30 +546,6 @@ const getHistoryMessages = async (page: number = 1) => { hasMore.value = totalItems > messages.value.length currentPage.value = page - // 如果不是第一页且已经加载完所有数据,展示开场白 - if (page > 1 && !hasMore.value) { - console.log('分页加载完成,当前页:', page, 'hasMore:', hasMore.value, '展示开场白') - // 等待数据渲染完成后再添加开场白 - setTimeout(() => { - addQuickQuestionsToFirstAIMessage(true) - }, 500) - } - - console.log( - '第', - page, - '页数据加载完成,offset:', - offset, - ', limit:', - pageSize.value, - ', 总数据:', - totalItems, - ', 当前已加载:', - messages.value.length, - ', 是否有更多:', - hasMore.value - ) - // 如果是第一页,滚动到底部 if (page === 1) { setTimeout(() => { @@ -724,10 +598,7 @@ const initWebSocket = () => { try { // Socket.IO兼容的WebSocket连接,使用/customer命名空间 - const wsUrl = `${WS_BASE_URL}/ws/socket.io/?EIO=4&transport=websocket` - - console.log('正在建立Socket.IO连接') - console.log('连接URL:', wsUrl) + const wsUrl = `${useModel?.WS_BASE_URL}/ws/socket.io/?EIO=4&transport=websocket` socketTask = uni.connectSocket({ url: wsUrl, @@ -735,25 +606,19 @@ const initWebSocket = () => { 'content-type': 'application/json' } }) - // 监听Socket.IO连接打开事件 uni.onSocketOpen((res: any) => { - console.log('[Customer] WebSocket connected', res) isConnected.value = true - // 发送Socket.IO连接包到/customer命名空间 const connectPacket = '40/customer,{"jwt":""}' uni.sendSocketMessage({ data: connectPacket, success: () => { - console.log('[Customer] Socket.IO连接包发送成功') - // 加入会话房间 if (conversationId.value) { setTimeout(() => { const joinMessage = `42/customer,["join_conversation",{"conversation_id":"${conversationId.value}"}]` console.log('[Customer] 加入会话房间:', joinMessage) - uni.sendSocketMessage({ data: joinMessage, success: () => { @@ -788,10 +653,6 @@ const initWebSocket = () => { // 监听Socket.IO消息事件 uni.onSocketMessage((res: any) => { - console.log('收到WebSocket原始消息:', res) - console.log('消息数据类型:', typeof res.data) - console.log('消息内容:', res.data) - // 处理WebSocket消息 const data = res.data @@ -898,8 +759,6 @@ const handleObjectMessage = (objData: any) => { // 处理typing指示器 const processTypingIndicator = (typingData: any) => { - console.log('[Customer] 处理typing指示器:', typingData) - // 检查是否是客服正在输入 if (typingData.is_typing && typingData.user_type === 'staff') { loading.value = true @@ -909,52 +768,10 @@ const processTypingIndicator = (typingData: any) => { } } -// 检查是否应该展示开场白 -const checkShouldShowQuickQuestions = (isLastPage: boolean = false) => { - // 只要有开场白数据,就展示开场白 - return quickQuestionsData.value.length > 0 -} - -// 找到第一条AI消息并添加开场白 -const addQuickQuestionsToFirstAIMessage = (isLastPage: boolean = false) => { - if (quickQuestionsData.value.length === 0) { - return - } - - // 检查是否应该展示开场白 - if (!checkShouldShowQuickQuestions(isLastPage)) { - return - } - - // 创建开场白消息 - const welcomeMessage: Message = { - role: 'ai', - content: '您好!我是物业客服,有什么可以帮助您的吗?', - quickQuestions: quickQuestionsData.value, - created_at: new Date().toISOString() - } - - console.log('[Customer] 创建开场白消息,是否最后一页:', isLastPage) - - // 如果没有历史记录,直接设置开场白 - if (messages.value.length === 0) { - messages.value = [welcomeMessage] - console.log('[Customer] 设置开场白为第一条消息') - } - // 如果有历史记录,在第一条消息前面插入开场白 - else { - messages.value.unshift(welcomeMessage) - console.log('[Customer] 在第一条消息前面插入开场白') - } -} - // 处理消息内容的统一函数 const processMessage = (messageData: any) => { - console.log('[Customer] 处理消息数据:', messageData) - // 不显示自己发的消息(已经通过HTTP显示了) if (messageData.sender_type === 'customer' || messageData.role === 'user') { - console.log('[Customer] 过滤掉客户消息') return } @@ -1036,7 +853,7 @@ const handleQuickFast = (name: string) => { } // 处理快捷按钮点击 -const handleQuickAction = (action: QuickAction) => { +const handleQuickAction = (action: any) => { inputMessage.value = action.message handleSendMessage() } @@ -1057,45 +874,9 @@ const handleConfirmation = (message: Message, confirmation: string) => { }, 300) } -const chooseImage = async () => { - const maxImages = 9 - if (selectedImages.value.length >= maxImages) { - uni.showToast({ - title: '最多选择9张图片', - icon: 'none' - }) - return - } - - try { - const remainingCount = maxImages - selectedImages.value.length - const uploadResult = await upload(remainingCount, 2, ['image']) - - if (uploadResult && Array.isArray(uploadResult) && uploadResult.length > 0) { - const imageUrls = uploadResult.map((item: any) => item.url) - selectedImages.value.push(...imageUrls) - - uni.showToast({ - title: '图片上传成功', - icon: 'success' - }) - } - } catch (error) { - console.error('选择图片失败:', error) - uni.showToast({ - title: '选择图片失败', - icon: 'none' - }) - } -} - -const removeImage = (index: number) => { - selectedImages.value.splice(index, 1) -} - const handleSendMessage = async () => { const message = inputMessage.value.trim() - const hasImages = selectedImages.value.length > 0 + const hasImages = useModel?.selectedImages?.value?.length > 0 if ((!message && !hasImages) || loading.value) return @@ -1119,7 +900,7 @@ const handleSendMessage = async () => { } // 图片已经在上传时就存储了OSS链接,直接使用 - const uploadedImages = selectedImages.value + const uploadedImages = useModel?.selectedImages?.value || [] // 确定消息类型 let messageType: 'text' | 'image' | 'mixed' = 'text' @@ -1142,7 +923,7 @@ const handleSendMessage = async () => { messages.value.push(userMessage) inputMessage.value = '' - selectedImages.value = [] + useModel.selectedImages.value = [] scrollToBottom() // 判断消息中是否包含"查询"关键词,设置相应的loading文案 @@ -1156,22 +937,14 @@ const handleSendMessage = async () => { try { // 使用HTTP接口发送消息 - const response = await uni.request({ - url: `${API_BASE_URL}/api/public/chat`, - method: 'POST', - data: { - platform: 'property', - message: message || '', // 纯图片时传空字符串 - tenant_project_id: projectId, - tenant_project_name: projectName || '', - platform_user_id: userPhone, - conversation_id: conversationId.value, - message_type: messageType, - image_url: uploadedImages.length > 0 ? uploadedImages : undefined - }, - header: { - 'Content-Type': 'application/json' - } + const response = await method?.customRequest('public/chat', { + platform: 'property', + message: message || '', // 纯图片时传空字符串 + tenant_project_id: projectId, + message_type: messageType, + tenant_project_name: projectName || '', + conversation_id: conversationId.value, + image_url: uploadedImages.length > 0 ? uploadedImages : undefined }) if (response.statusCode === 200) { @@ -1290,17 +1063,10 @@ onUnmounted(() => { }) onLoad(async op => { - console.log( - '页面加载时已获取开场白按钮数据1:', - quickQuestionsData.value.length, - getLoginStatus?.getLoginStatus() - ) await getCurrentInstance()?.appContext.config.globalProperties.$onLaunched if (getLoginStatus?.getLoginStatus()) { userLoginStatus.value = true - console.log('页面加载时已获取开场白按钮数据3:', quickQuestionsData.value.length) - quickQuestionsData.value = await getQuickQuestions() - console.log('页面加载时已获取开场白按钮数据2:', quickQuestionsData.value.length) + quickQuestionsData.value = await method?.getQuickQuestions() // 获取历史记录(如果有历史记录,会在接口返回成功后自动在最前方插入开场白) getHistoryMessages(1) if (op?.message) { diff --git a/src/pages/ai/components/HeaderPrologue.vue b/src/pages/ai/components/HeaderPrologue.vue new file mode 100644 index 0000000..01b9d25 --- /dev/null +++ b/src/pages/ai/components/HeaderPrologue.vue @@ -0,0 +1,37 @@ + + diff --git a/src/pages/ai/index.vue b/src/pages/ai/index.vue new file mode 100644 index 0000000..4bf45c4 --- /dev/null +++ b/src/pages/ai/index.vue @@ -0,0 +1,1080 @@ + + + + diff --git a/src/pages/ai/method.ts b/src/pages/ai/method.ts new file mode 100644 index 0000000..5740c08 --- /dev/null +++ b/src/pages/ai/method.ts @@ -0,0 +1,141 @@ +import { ref, nextTick, onUnmounted, getCurrentInstance } from 'vue' +import { useWeAppAuthStore } from '@/common' +import { onPullDownRefresh, onLoad, onPageScroll, onShow } from '@dcloudio/uni-app' +import dayjs from 'dayjs' +import relativeTime from 'dayjs/plugin/relativeTime' +import 'dayjs/locale/zh-cn' +import useModel from './model' +import { upload } from '@/common/libraries/upload' + +const auth = useWeAppAuthStore() + +// 配置dayjs +dayjs.extend(relativeTime) +dayjs.locale('zh-cn') + +export default { + customRequest: async ( + url: string, + data: any, + type?: 'POST' | 'OPTIONS' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT' + ) => { + const selected_house: any = auth?.data?.selected_house + console.log('selected_house:', selected_house) + const response = await uni.request({ + url: `${useModel?.API_BASE_URL}/api/${url}`, + method: type || 'POST', + data: { ...data, tenant_company_id: selected_house?.companies_id }, + header: { + 'Content-Type': 'application/json' + } + }) + return response + }, + getQuickQuestions: async () => { + try { + const selected_house: any = auth?.data?.selected_house + + const response = await uni.request({ + url: `${useModel?.API_BASE_URL}/api/public/quick-questions?platform=property&company_id=${selected_house?.companies_id}&project_id=${selected_house?.asset_projects_id}`, + method: 'GET' + }) + if (response.statusCode === 200) { + const result = response.data as any + return result + } else { + return [] + } + } catch (error) { + return [] + } + }, + chooseImage: async () => { + const maxImages = 9 + if (useModel?.selectedImages?.value.length >= maxImages) { + uni.showToast({ + title: '最多选择9张图片', + icon: 'none' + }) + return + } + + try { + const remainingCount = maxImages - useModel?.selectedImages?.value.length + const uploadResult = await upload(remainingCount, 2, ['image']) + + if (uploadResult && Array.isArray(uploadResult) && uploadResult.length > 0) { + const imageUrls = uploadResult.map((item: any) => item.url) + useModel.selectedImages.value.push(...imageUrls) + + uni.showToast({ + title: '图片上传成功', + icon: 'success' + }) + } + } catch (error) { + console.error('选择图片失败:', error) + uni.showToast({ + title: '选择图片失败', + icon: 'none' + }) + } + }, + removeImage: (index: number) => { + useModel.selectedImages.value.splice(index, 1) + }, + previewImage: (currentImage: string, images: string[]) => { + uni.previewImage({ + current: currentImage, + urls: images + }) + }, + copyMessage: (content: string) => { + if (!content) { + uni.showToast({ + title: '暂无内容可复制', + icon: 'none' + }) + return + } + + uni.setClipboardData({ + data: content, + success: () => { + uni.showToast({ + title: '复制成功', + icon: 'success' + }) + }, + fail: () => { + uni.showToast({ + title: '复制失败', + icon: 'none' + }) + } + }) + }, + formatMessageContent: (content: string) => { + if (!content || typeof content !== 'string') { + return [''] + } + return content.split('\n').filter(line => line.trim() !== '') + }, + formatTime: (timeStr: string) => { + if (!timeStr) return '' + + try { + const date = dayjs(timeStr) + + // 检查日期是否有效 + if (!date.isValid()) { + return '' + } + + // 使用相对时间显示 + return date.fromNow() + } catch (e) { + console.error('时间格式化错误:', e) + return '' + } + } +} diff --git a/src/pages/ai/model.ts b/src/pages/ai/model.ts new file mode 100644 index 0000000..6a85724 --- /dev/null +++ b/src/pages/ai/model.ts @@ -0,0 +1,11 @@ +import { reactive, ref } from 'vue' +export default { + selectedImages: ref([]), // 选中的图片 + quickQuestionsData: ref({}), + // API_BASE_URL: 'http://10.39.13.78:8000', //dev环境 + // WS_BASE_URL: 'wss://10.39.13.78:8000' //dev环境 + // API_BASE_URL: 'https://kf-api-test.linyikj.com.cn', //测试环境 + // WS_BASE_URL: 'wss://kf-api-test.linyikj.com.cn' //测试环境 + API_BASE_URL: 'https://kf-api.linyikj.com.cn', //正式环境 + WS_BASE_URL: 'wss://kf-api.linyikj.com.cn' //正式环境 +} diff --git a/src/static/svg/ai_icon.svg b/src/static/svg/ai_icon.svg deleted file mode 100644 index 74d6a34..0000000 --- a/src/static/svg/ai_icon.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file