Merge branch 'feat/personnel_channel' into dev/1.0
This commit is contained in:
@@ -1,64 +1,43 @@
|
||||
<template>
|
||||
<view v-if="pageCount == 1 || need" class="fixed-box"
|
||||
:style="[customContainerStyle, {
|
||||
height: fixBtnShow ? '400rpx' : '320rpx',
|
||||
backgroundImage: bgUrl ? `url(${bgUrl})` : '',
|
||||
backgroundSize: 'cover'
|
||||
}]">
|
||||
|
||||
<!-- AI 智能助手(优先显示) -->
|
||||
<view
|
||||
v-if="fixBtnShow && enableAIChat"
|
||||
class="btn-item common-bg"
|
||||
@click="openAIChat"
|
||||
:style="{ backgroundImage: aiAgentimg ? `url(${aiAgentimg})` : '', backgroundSize: '100% 100%' }"
|
||||
>
|
||||
<text class="ai-icon" v-if="!aiAgentimg">🤖</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通客服(仅当未启用 AI 时显示) -->
|
||||
<template v-else-if="fixBtnShow">
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button
|
||||
class="btn-item common-bg"
|
||||
hoverClass="none"
|
||||
openType="contact"
|
||||
sessionFrom="weapp"
|
||||
showMessageCard="true"
|
||||
:style="[{ backgroundImage: kefuimg ? `url(${kefuimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]"
|
||||
>
|
||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||
</button>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<button
|
||||
class="btn-item common-bg"
|
||||
hoverClass="none"
|
||||
@click="openKefuSelectPopup"
|
||||
:style="[{ backgroundImage: kefuimg ? `url(${kefuimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]"
|
||||
>
|
||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||
</button>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
<!-- 悬浮按钮 -->
|
||||
<view v-if="pageCount == 1 || need" class="fixed-box" :style="[customContainerStyle, {
|
||||
height: fixBtnShow ? '400rpx' : '320rpx',
|
||||
backgroundImage: bgUrl ? `url(${bgUrl})` : '',
|
||||
backgroundSize: 'cover'
|
||||
}]">
|
||||
|
||||
<!-- 中英文切换按钮 -->
|
||||
<view
|
||||
v-if="isLanguageSwitchEnabled && fixBtnShow"
|
||||
class="btn-item common-bg"
|
||||
@click="toggleLanguage"
|
||||
>
|
||||
<view v-if="isLanguageSwitchEnabled && fixBtnShow" class="btn-item common-bg" @click="toggleLanguage">
|
||||
<text>{{ currentLangDisplayName }}</text>
|
||||
</view>
|
||||
|
||||
<!-- AI 智能助手 -->
|
||||
<view v-if="fixBtnShow && enableAIChat" class="btn-item common-bg" @click="openAIChat"
|
||||
:style="{ backgroundImage: aiAgentimg ? `url(${aiAgentimg})` : '', backgroundSize: '100% 100%' }">
|
||||
<text class="ai-icon" v-if="!aiAgentimg">🤖</text>
|
||||
</view>
|
||||
|
||||
<!-- 微信小程序客服按钮 -->
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button class="btn-item common-bg" hoverClass="none" openType="contact" sessionFrom="weapp" showMessageCard="true"
|
||||
:style="[{ backgroundImage: kefuimg ? `url(${kefuimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]">
|
||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||
</button>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- 普通客服(仅当未启用 AI 时显示) -->
|
||||
<!-- #ifdef H5 -->
|
||||
<template v-if="fixBtnShow">
|
||||
<button class="btn-item common-bg" hoverClass="none" @click="openCustomerSelectPopup"
|
||||
:style="[{ backgroundImage: kefuimg ? `url(${kefuimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]">
|
||||
<text class="icox icox-kefu" v-if="!kefuimg"></text>
|
||||
</button>
|
||||
</template>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- 电话按钮(始终显示) -->
|
||||
<view
|
||||
v-if="fixBtnShow"
|
||||
class="btn-item common-bg"
|
||||
@click="call()"
|
||||
:style="[{ backgroundImage: phoneimg ? `url(${phoneimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]"
|
||||
>
|
||||
<view v-if="fixBtnShow" class="btn-item common-bg" @click="call()"
|
||||
:style="[{ backgroundImage: phoneimg ? `url(${phoneimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]">
|
||||
<text class="iconfont icon-dianhua" v-if="!phoneimg"></text>
|
||||
</view>
|
||||
|
||||
@@ -77,17 +56,12 @@ export default {
|
||||
return {
|
||||
pageCount: 0,
|
||||
fixBtnShow: true,
|
||||
|
||||
shopInfo: null,
|
||||
currentLangIndex: 0,
|
||||
langIndexMap: {},
|
||||
kefuList: [
|
||||
{ id: 'weixin-official', name: '微信官方客服', isOfficial: true, type: 'weapp' },
|
||||
{ id: 'custom-kefu', name: '自定义在线客服', isOfficial: false, type: 'custom' },
|
||||
{ id: 'qyweixin-kefu', name: '企业微信客服', isOfficial: false, type: 'qyweixin' }
|
||||
],
|
||||
selectedKefu: null,
|
||||
|
||||
customerService: null,
|
||||
buttonConfig: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -111,13 +85,8 @@ export default {
|
||||
return !!this.shopInfo?.ischina;
|
||||
},
|
||||
enableAIChat() {
|
||||
const defaultEnable = true;
|
||||
if (!this.shopInfo) return defaultEnable;
|
||||
return this.shopInfo.hasOwnProperty('enableAIChat')
|
||||
? !!this.shopInfo.enableAIChat
|
||||
: defaultEnable;
|
||||
return !!this.shopInfo?.enableAIChat;
|
||||
},
|
||||
|
||||
currentLangDisplayName() {
|
||||
const lang = this.langIndexMap[this.currentLangIndex];
|
||||
return lang === 'zh-cn' ? 'EN' : 'CN';
|
||||
@@ -127,39 +96,22 @@ export default {
|
||||
},
|
||||
customButtonStyle() {
|
||||
return this.shopInfo?.floatingButton?.button || {};
|
||||
},
|
||||
customTextStyle() {
|
||||
return this.shopInfo?.floatingButton?.text || {};
|
||||
},
|
||||
unreadCount() {
|
||||
return this.$store.state.aiUnreadCount || 0;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
shopInfo: {
|
||||
handler(newVal) {
|
||||
// 可在此添加额外逻辑(如埋点、通知等),当前无需操作
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.customerService = createCustomerService(this);
|
||||
this.initLanguage();
|
||||
this.pageCount = getCurrentPages().length;
|
||||
|
||||
uni.getStorage({
|
||||
key: 'shopInfo',
|
||||
success: (e) => {
|
||||
console.log('【调试】当前 shopInfo:', e.data);
|
||||
this.shopInfo = e.data;
|
||||
},
|
||||
fail: () => {
|
||||
console.warn('未获取到 shopInfo,使用默认设置');
|
||||
// shopInfo 为 null,computed 会自动返回默认值,无需手动赋值
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 初始化多语言配置
|
||||
*/
|
||||
initLanguage() {
|
||||
this.langList = this.$langConfig.list();
|
||||
this.langIndexMap = {};
|
||||
@@ -178,78 +130,41 @@ export default {
|
||||
this.currentLangIndex = 0;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 电话联系客服
|
||||
*/
|
||||
call() {
|
||||
if (this.tel) {
|
||||
uni.makePhoneCall({ phoneNumber: this.tel + '' });
|
||||
} else {
|
||||
uni.showToast({ title: '暂无联系电话', icon: 'none' });
|
||||
}
|
||||
this.customerService.makePhoneCall(this.tel);
|
||||
},
|
||||
/**
|
||||
* 切换中英文语言,并刷新当前页面(保留所有参数)
|
||||
*/
|
||||
toggleLanguage() {
|
||||
this.currentLangIndex = this.currentLangIndex === 0 ? 1 : 0;
|
||||
const targetLang = this.langIndexMap[this.currentLangIndex];
|
||||
|
||||
// 调用语言切换逻辑(设置 storage + 清空缓存)
|
||||
this.$langConfig.change(targetLang);
|
||||
|
||||
// H5 环境需要强制刷新页面才能生效
|
||||
if (uni.getSystemInfoSync().platform === 'browser') {
|
||||
// 延迟 100ms 确保 change() 执行完成
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
openKefuSelectPopup() {
|
||||
const kefuNames = this.kefuList.map(item => item.name);
|
||||
uni.showActionSheet({
|
||||
itemList: kefuNames,
|
||||
success: (res) => {
|
||||
this.selectedKefu = this.kefuList[res.tapIndex];
|
||||
this.reinitCustomerService(this.selectedKefu);
|
||||
this.handleSelectedKefu();
|
||||
}
|
||||
});
|
||||
},
|
||||
reinitCustomerService(kefu) {
|
||||
this.customerService = createCustomerService(this, kefu);
|
||||
this.buttonConfig = this.customerService.getButtonConfig();
|
||||
},
|
||||
handleSelectedKefu() {
|
||||
const kefu = this.selectedKefu;
|
||||
if (!kefu) return;
|
||||
toggleLanguage() {
|
||||
this.currentLangIndex = this.currentLangIndex === 0 ? 1 : 0;
|
||||
const targetLang = this.langIndexMap[this.currentLangIndex];
|
||||
|
||||
if (kefu.isOfficial) {
|
||||
uni.openCustomerServiceConversation({
|
||||
sessionFrom: 'weapp',
|
||||
showMessageCard: true
|
||||
});
|
||||
} else if (kefu.id === 'custom-kefu') {
|
||||
this.customerService.handleCustomerClick();
|
||||
} else if (kefu.id === 'qyweixin-kefu') {
|
||||
this.customerService.handleQyWeixinKefuClick();
|
||||
}
|
||||
// 调用语言切换逻辑(设置 storage + 清空缓存)
|
||||
this.$langConfig.change(targetLang);
|
||||
},
|
||||
|
||||
/**
|
||||
* 打开 AI 智能助手
|
||||
*/
|
||||
openAIChat() {
|
||||
uni.navigateTo({
|
||||
url: '/pages_tool/ai-chat/index',
|
||||
success: () => {
|
||||
console.log('✅ AI 客服跳转成功');
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('❌ 跳转失败:', err);
|
||||
uni.showToast({ title: '跳转失败,请重试', icon: 'none' });
|
||||
}
|
||||
});
|
||||
this.$util.redirectTo(this.$util.AI_CHAT_PAGE_URL);
|
||||
},
|
||||
openCustomerSelectPopup() {
|
||||
if (this.customerService) {
|
||||
this.customerService.openCustomerSelectPopupDialog();
|
||||
} else {
|
||||
uni.showToast({ title: '客服初始化中,请稍后重试', icon: 'none' });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
<style lang="scss" scoped>
|
||||
.fixed-box {
|
||||
position: fixed;
|
||||
right: 0rpx;
|
||||
@@ -287,7 +202,8 @@ export default {
|
||||
|
||||
/* 定义共同的背景颜色 */
|
||||
.common-bg {
|
||||
background-color: var(--hover-nav-bg-color); /* 使用变量以保持一致性 */
|
||||
background-color: var(--hover-nav-bg-color);
|
||||
/* 使用变量以保持一致性 */
|
||||
}
|
||||
|
||||
.btn-item text {
|
||||
@@ -304,7 +220,6 @@ export default {
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin: 14rpx 0;
|
||||
background: #fff;
|
||||
border-radius: 50rpx;
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
@@ -318,21 +233,7 @@ export default {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.unread-badge {
|
||||
position: absolute;
|
||||
top: -5rpx;
|
||||
right: -5rpx;
|
||||
background-color: #ff4544;
|
||||
color: white;
|
||||
border-radius: 20rpx;
|
||||
min-width: 30rpx;
|
||||
height: 30rpx;
|
||||
font-size: 20rpx;
|
||||
line-height: 30rpx;
|
||||
text-align: center;
|
||||
padding: 0 8rpx;
|
||||
box-shadow: 0 2rpx 10rpx rgba(255, 69, 68, 0.3);
|
||||
}
|
||||
|
||||
|
||||
.ai-icon {
|
||||
font-size: 40rpx;
|
||||
|
||||
Reference in New Issue
Block a user