Compare commits
3 Commits
b7fbe99cd0
...
ea56695099
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea56695099 | ||
|
|
dfadb06934 | ||
|
|
f027685072 |
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"appid": "wx5e79df5996572539",
|
||||
"appid": "wx23f86d809ae80259",
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "3.8.10",
|
||||
"packOptions": {
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import { getEvnUrl } from "@/request/api/config";
|
||||
import { refreshToken } from "@/hooks/useGoLogin";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
|
||||
onLaunch(async () => {
|
||||
await getEvnUrl({ versionValue: "1.0.3" });
|
||||
refreshToken();
|
||||
|
||||
const token = getStorageSyncToken();
|
||||
|
||||
if (token) {
|
||||
refreshToken();
|
||||
}
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
|
||||
@@ -12,7 +12,7 @@ import rawConfigs from '../../client-configs.json' with { type: 'json' };
|
||||
export const CLIENT_CONFIGS = rawConfigs;
|
||||
|
||||
// 获取当前用户端配置
|
||||
export const getCurrentConfig = () => CLIENT_CONFIGS.zhinian;
|
||||
export const getCurrentConfig = () => CLIENT_CONFIGS.duohua;
|
||||
export const clientId = getCurrentConfig().clientId;
|
||||
export const appId = getCurrentConfig().appId;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { wxLogin } from "../request/api/LoginApi";
|
||||
import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager";
|
||||
import { wxLogin, checkUserPhone } from "../request/api/LoginApi";
|
||||
import { loginAuth, bindPhone } from "@/manager/LoginManager";
|
||||
import { clientId } from "@/constant/base";
|
||||
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
|
||||
import { getStorageSyncToken, setStorageSyncToken } from "../constant/token";
|
||||
@@ -22,8 +22,9 @@ export const onLogin = async (e) => {
|
||||
}
|
||||
|
||||
await loginAuth(e).then(async () => {
|
||||
console.log("loginAuth resolve success");
|
||||
// 检查手机号是否绑定
|
||||
const checkRes = await checkPhone();
|
||||
const checkRes = await checkUserPhone();
|
||||
if (checkRes.data) {
|
||||
resolve();
|
||||
return;
|
||||
@@ -62,11 +63,11 @@ export const checkToken = () => {
|
||||
|
||||
// 刷新token
|
||||
export const refreshToken = () => {
|
||||
return new Promise((resolve) => {
|
||||
return new Promise(async (resolve) => {
|
||||
uni.login({
|
||||
provider: "weixin", //使用微信登录
|
||||
success: async ({ code }) => {
|
||||
console.log("refreshToken", code);
|
||||
console.log("进入 refreshToken success", code);
|
||||
const params = {
|
||||
openIdCode: [code],
|
||||
grant_type: "wechat",
|
||||
@@ -74,15 +75,13 @@ export const refreshToken = () => {
|
||||
clientId: clientId,
|
||||
};
|
||||
console.log("获取到的微信授权params:", JSON.stringify(params));
|
||||
|
||||
const response = await wxLogin(params);
|
||||
|
||||
if (response.access_token) {
|
||||
setStorageSyncToken(response.access_token);
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
resolve(false)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -4,14 +4,12 @@ import {
|
||||
checkUserPhone,
|
||||
} from "../request/api/LoginApi";
|
||||
import { getWeChatAuthCode } from "./AuthManager";
|
||||
import { useAppStore } from "@/store";
|
||||
import { clientId } from "@/constant/base";
|
||||
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
|
||||
import { removeStorageSyncToken, setStorageSyncToken } from "../constant/token";
|
||||
|
||||
const loginAuth = (e) => {
|
||||
removeStorageSyncToken();
|
||||
const appStore = useAppStore();
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const openIdCode = await getWeChatAuthCode(e);
|
||||
@@ -27,6 +25,7 @@ const loginAuth = (e) => {
|
||||
console.log("获取到的微信授权response:", response);
|
||||
|
||||
if (response.access_token) {
|
||||
console.log("进入条件");
|
||||
setStorageSyncToken(response.access_token);
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
@@ -46,9 +45,4 @@ const bindPhone = async (params) => {
|
||||
}
|
||||
};
|
||||
|
||||
const checkPhone = async () => {
|
||||
const response = await checkUserPhone();
|
||||
return response;
|
||||
};
|
||||
|
||||
export { loginAuth, bindPhone, checkPhone };
|
||||
export { loginAuth, bindPhone };
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
朵花:wx23f86d809ae80259
|
||||
*/
|
||||
"mp-weixin": {
|
||||
"appid": "wx5e79df5996572539",
|
||||
"appid": "wx23f86d809ae80259",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"minified": true
|
||||
|
||||
@@ -2,79 +2,42 @@
|
||||
<view class="flex flex-col h-screen">
|
||||
<!-- 顶部自定义导航栏 -->
|
||||
<view class="header" :style="{ paddingTop: statusBarHeight + 'px' }">
|
||||
<ChatTopNavBar
|
||||
ref="topNavBarRef"
|
||||
:mainPageDataModel="mainPageDataModel"
|
||||
/>
|
||||
<ChatTopNavBar ref="topNavBarRef" :mainPageDataModel="mainPageDataModel" />
|
||||
</view>
|
||||
|
||||
<!-- 消息列表(可滚动区域) -->
|
||||
<scroll-view
|
||||
class="main flex-full overflow-hidden scroll-y"
|
||||
scroll-y
|
||||
:scroll-top="scrollTop"
|
||||
:scroll-with-animation="true"
|
||||
@scroll="handleScroll"
|
||||
@scrolltolower="handleScrollToLower"
|
||||
>
|
||||
<scroll-view class="main flex-full overflow-hidden scroll-y" scroll-y :scroll-top="scrollTop"
|
||||
:scroll-with-animation="true" @scroll="handleScroll" @scrolltolower="handleScrollToLower">
|
||||
<!-- welcome栏 -->
|
||||
<ChatTopWelcome ref="welcomeRef" :mainPageDataModel="mainPageDataModel" />
|
||||
|
||||
<view
|
||||
class="area-msg-list-content"
|
||||
v-for="item in chatMsgList"
|
||||
:key="item.msgId"
|
||||
:id="item.msgId"
|
||||
>
|
||||
<view class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId">
|
||||
<template v-if="item.msgType === MessageRole.AI">
|
||||
<ChatCardAI
|
||||
class="flex flex-justify-start"
|
||||
:key="`ai-${item.msgId}-${item.msg ? item.msg.length : 0}`"
|
||||
:text="item.msg || ''"
|
||||
:isLoading="item.isLoading"
|
||||
>
|
||||
<ChatCardAI class="flex flex-justify-start" :key="`ai-${item.msgId}-${item.msg ? item.msg.length : 0}`"
|
||||
:text="item.msg || ''" :isLoading="item.isLoading">
|
||||
<template #content v-if="item.toolCall">
|
||||
<QuickBookingComponent
|
||||
v-if="item.toolCall.componentName === CompName.quickBookingCard"
|
||||
/>
|
||||
<DiscoveryCardComponent
|
||||
v-else-if="
|
||||
item.toolCall.componentName === CompName.discoveryCard
|
||||
"
|
||||
/>
|
||||
<CreateServiceOrder
|
||||
v-else-if="
|
||||
item.toolCall.componentName === CompName.callServiceCard
|
||||
"
|
||||
:toolCall="item.toolCall"
|
||||
/>
|
||||
<Feedback
|
||||
v-else-if="
|
||||
item.toolCall.componentName === CompName.feedbackCard
|
||||
"
|
||||
:toolCall="item.toolCall"
|
||||
/>
|
||||
<DetailCardCompontent
|
||||
v-else-if="
|
||||
item.toolCall.componentName ===
|
||||
CompName.pictureAndCommodityCard
|
||||
"
|
||||
:toolCall="item.toolCall"
|
||||
/>
|
||||
<AddCarCrad
|
||||
v-else-if="
|
||||
item.toolCall.componentName === CompName.enterLicensePlateCard
|
||||
"
|
||||
:toolCall="item.toolCall"
|
||||
/>
|
||||
<QuickBookingComponent v-if="item.toolCall.componentName === CompName.quickBookingCard" />
|
||||
<DiscoveryCardComponent v-else-if="
|
||||
item.toolCall.componentName === CompName.discoveryCard
|
||||
" />
|
||||
<CreateServiceOrder v-else-if="
|
||||
item.toolCall.componentName === CompName.callServiceCard
|
||||
" :toolCall="item.toolCall" />
|
||||
<Feedback v-else-if="
|
||||
item.toolCall.componentName === CompName.feedbackCard
|
||||
" :toolCall="item.toolCall" />
|
||||
<DetailCardCompontent v-else-if="
|
||||
item.toolCall.componentName ===
|
||||
CompName.pictureAndCommodityCard
|
||||
" :toolCall="item.toolCall" />
|
||||
<AddCarCrad v-else-if="
|
||||
item.toolCall.componentName === CompName.enterLicensePlateCard
|
||||
" :toolCall="item.toolCall" />
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<!-- 这个是底部 -->
|
||||
<AttachListComponent
|
||||
v-if="item.question"
|
||||
:question="item.question"
|
||||
/>
|
||||
<AttachListComponent v-if="item.question" :question="item.question" />
|
||||
</template>
|
||||
</ChatCardAI>
|
||||
</template>
|
||||
@@ -85,21 +48,15 @@
|
||||
|
||||
<template v-else>
|
||||
<ChatCardOther class="flex flex-justify-center" :text="item.msg">
|
||||
<ActivityListComponent
|
||||
v-if="
|
||||
mainPageDataModel.activityList &&
|
||||
mainPageDataModel.activityList.length > 0
|
||||
"
|
||||
:activityList="mainPageDataModel.activityList"
|
||||
/>
|
||||
<ActivityListComponent v-if="
|
||||
mainPageDataModel.activityList &&
|
||||
mainPageDataModel.activityList.length > 0
|
||||
" :activityList="mainPageDataModel.activityList" />
|
||||
|
||||
<RecommendPostsComponent
|
||||
v-if="
|
||||
mainPageDataModel.recommendTheme &&
|
||||
mainPageDataModel.recommendTheme.length > 0
|
||||
"
|
||||
:recommendThemeList="mainPageDataModel.recommendTheme"
|
||||
/>
|
||||
<RecommendPostsComponent v-if="
|
||||
mainPageDataModel.recommendTheme &&
|
||||
mainPageDataModel.recommendTheme.length > 0
|
||||
" :recommendThemeList="mainPageDataModel.recommendTheme" />
|
||||
</ChatCardOther>
|
||||
</template>
|
||||
</view>
|
||||
@@ -108,17 +65,9 @@
|
||||
<!-- 输入框区域 -->
|
||||
<view class="pb-safe-area">
|
||||
<ChatQuickAccess />
|
||||
<ChatInputArea
|
||||
ref="inputAreaRef"
|
||||
v-model="inputMessage"
|
||||
:holdKeyboard="holdKeyboard"
|
||||
:is-session-active="isSessionActive"
|
||||
:stop-request="stopRequest"
|
||||
@send="sendMessageAction"
|
||||
@noHideKeyboard="handleNoHideKeyboard"
|
||||
@keyboardShow="handleKeyboardShow"
|
||||
@keyboardHide="handleKeyboardHide"
|
||||
/>
|
||||
<ChatInputArea ref="inputAreaRef" v-model="inputMessage" :holdKeyboard="holdKeyboard"
|
||||
:is-session-active="isSessionActive" :stop-request="stopRequest" @send="sendMessageAction"
|
||||
@noHideKeyboard="handleNoHideKeyboard" @keyboardShow="handleKeyboardShow" @keyboardHide="handleKeyboardHide" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -243,7 +192,7 @@ const handleScroll = ThrottleUtils.createThrottle(({ detail }) => {
|
||||
}, 50);
|
||||
|
||||
// 处理滚动到底部事件
|
||||
const handleScrollToLower = () => {};
|
||||
const handleScrollToLower = () => { };
|
||||
|
||||
// 滚动到底部 - 优化版本,确保打字机效果始终可见
|
||||
const scrollToBottom = () => {
|
||||
@@ -474,53 +423,53 @@ const initWebSocket = async () => {
|
||||
};
|
||||
|
||||
// 处理WebSocket消息
|
||||
const handleWebSocketMessage = (data) => {
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) {
|
||||
console.error("处理WebSocket消息时找不到对应的AI消息项");
|
||||
return;
|
||||
}
|
||||
const handleWebSocketMessage = (data) => {
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) {
|
||||
console.error("处理WebSocket消息时找不到对应的AI消息项");
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保消息内容是字符串类型
|
||||
if (data.content && typeof data.content !== "string") {
|
||||
data.content = String(data.content);
|
||||
}
|
||||
// 确保消息内容是字符串类型
|
||||
if (data.content && typeof data.content !== "string") {
|
||||
data.content = String(data.content);
|
||||
}
|
||||
|
||||
// 直接拼接内容到AI消息
|
||||
if (data.content) {
|
||||
if (chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
// 直接拼接内容到AI消息
|
||||
if (data.content) {
|
||||
if (chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "";
|
||||
}
|
||||
chatMsgList.value[aiMsgIndex].msg += data.content;
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
nextTick(() => scrollToBottom());
|
||||
}
|
||||
|
||||
// 处理完成状态
|
||||
if (data.finish) {
|
||||
const msg = chatMsgList.value[aiMsgIndex].msg;
|
||||
if (!msg || chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试";
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "";
|
||||
}
|
||||
chatMsgList.value[aiMsgIndex].msg += data.content;
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
nextTick(() => scrollToBottom());
|
||||
}
|
||||
|
||||
// 处理完成状态
|
||||
if (data.finish) {
|
||||
const msg = chatMsgList.value[aiMsgIndex].msg;
|
||||
if (!msg || chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试";
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "";
|
||||
}
|
||||
}
|
||||
|
||||
// 处理toolCall
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].toolCall = data.toolCall;
|
||||
}
|
||||
|
||||
// 处理question
|
||||
if (data.question && data.question.length > 0) {
|
||||
chatMsgList.value[aiMsgIndex].question = data.question;
|
||||
}
|
||||
|
||||
// 重置会话状态
|
||||
isSessionActive.value = false;
|
||||
// 处理toolCall
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].toolCall = data.toolCall;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理question
|
||||
if (data.question && data.question.length > 0) {
|
||||
chatMsgList.value[aiMsgIndex].question = data.question;
|
||||
}
|
||||
|
||||
// 重置会话状态
|
||||
isSessionActive.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 重置消息状态
|
||||
const resetMessageState = () => {
|
||||
@@ -551,13 +500,13 @@ const sendMessage = async (message, isInstruct = false) => {
|
||||
uni.showLoading({
|
||||
title: "正在连接服务器...",
|
||||
});
|
||||
|
||||
|
||||
// 尝试重新初始化WebSocket连接
|
||||
try {
|
||||
await initWebSocket();
|
||||
// 等待短暂时间确保连接建立
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
|
||||
// 检查连接是否成功建立
|
||||
if (!webSocketConnectStatus) {
|
||||
uni.hideLoading();
|
||||
|
||||
@@ -17,17 +17,9 @@
|
||||
<view class="login-agreement flex flex-items-center">
|
||||
<CheckBox v-model="isAgree">
|
||||
<text class="font-size-12 color-525866">我已阅读并同意</text>
|
||||
<text
|
||||
class="font-size-12 color-2D91FF ml-4 mr-4"
|
||||
@click.stop="handleAgreeClick('service')"
|
||||
>《服务协议》</text
|
||||
>
|
||||
<text class="font-size-12 color-2D91FF ml-4 mr-4" @click.stop="handleAgreeClick('service')">《服务协议》</text>
|
||||
<text class="font-size-12 color-525866">和</text>
|
||||
<text
|
||||
class="font-size-12 color-2D91FF ml-4 mr-4"
|
||||
@click.stop="handleAgreeClick('privacy')"
|
||||
>《隐私协议》</text
|
||||
>
|
||||
<text class="font-size-12 color-2D91FF ml-4 mr-4" @click.stop="handleAgreeClick('privacy')">《隐私协议》</text>
|
||||
<text class="font-size-12 color-525866">,\n</text>
|
||||
<text class="font-size-12 color-525866 ml-30">授权与账号关联操作</text>
|
||||
</CheckBox>
|
||||
@@ -37,23 +29,13 @@
|
||||
<view class="login-btn-area">
|
||||
<!-- 同意隐私协议并获取手机号按钮 -->
|
||||
|
||||
<button
|
||||
class="login-btn"
|
||||
type="primary"
|
||||
:open-type="needWxLogin ? 'getPhoneNumber' : ''"
|
||||
@getphonenumber="getPhoneNumber"
|
||||
@click="handleAgreeAndGetPhone"
|
||||
>
|
||||
<button class="login-btn" type="primary" :open-type="needWxLogin ? 'getPhoneNumber' : ''"
|
||||
@getphonenumber="getPhoneNumber" @click="handleAgreeAndGetPhone">
|
||||
手机号快捷登录
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<AgreePopup
|
||||
ref="agreePopup"
|
||||
:visible="visible"
|
||||
:agreement="computedAgreement"
|
||||
@close="visible = false"
|
||||
/>
|
||||
<AgreePopup ref="agreePopup" :visible="visible" :agreement="computedAgreement" @close="visible = false" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -63,12 +45,14 @@ import { ref, computed } from "vue";
|
||||
import {
|
||||
getServiceAgreement,
|
||||
getPrivacyAgreement,
|
||||
checkUserPhone
|
||||
} from "@/request/api/LoginApi";
|
||||
import { onLogin, goBack, refreshToken } from "@/hooks/useGoLogin";
|
||||
import CheckBox from "@/components/CheckBox/index.vue";
|
||||
import AgreePopup from "./components/AgreePopup/index.vue";
|
||||
import { zniconsMap } from "@/static/fonts/znicons.js";
|
||||
import { zniconsMap } from "@/static/fonts/znicons";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
|
||||
const needWxLogin = ref(false);
|
||||
const isAgree = ref(false);
|
||||
@@ -83,7 +67,7 @@ const logo = computed(() => getCurrentConfig().logo);
|
||||
const handleAgreeAndGetPhone = () => {
|
||||
// 如果需要微信登录,直接返回
|
||||
if (needWxLogin.value) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAgree.value) {
|
||||
@@ -106,7 +90,7 @@ const getPhoneNumber = (e) => {
|
||||
});
|
||||
goBack();
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch(() => { });
|
||||
};
|
||||
|
||||
// 处理同意协议点击事件
|
||||
@@ -142,14 +126,21 @@ getPrivacyAgreementData();
|
||||
|
||||
// 页面显示时刷新token
|
||||
onShow(async () => {
|
||||
const res = await refreshToken();
|
||||
const token = getStorageSyncToken();
|
||||
|
||||
needWxLogin.value = res;
|
||||
if (token) {
|
||||
const res = await checkUserPhone();
|
||||
|
||||
needWxLogin.value = res.data;
|
||||
} else {
|
||||
needWxLogin.value = true;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import "./styles/index.scss";
|
||||
|
||||
@font-face {
|
||||
font-family: znicons;
|
||||
src: url("@/static/fonts/znicons.ttf");
|
||||
|
||||
Reference in New Issue
Block a user