Compare commits
17 Commits
V1.0.1
...
b7fbe99cd0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7fbe99cd0 | ||
| 5027abc239 | |||
| a2ff08f090 | |||
| 37192b0ba4 | |||
| 8be21f8307 | |||
| 296781c506 | |||
| 9eb1dc6747 | |||
| 364e47b641 | |||
| a3c363cbc9 | |||
| 09452bf600 | |||
| c20563ecf5 | |||
| 172bae663b | |||
| 9632f5c065 | |||
| 3f803b662a | |||
| 84b77b3fe6 | |||
| 92f981769f | |||
| f69225dbff |
@@ -3,8 +3,8 @@ import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import { getEvnUrl } from "@/request/api/config";
|
||||
import { refreshToken } from "@/hooks/useGoLogin";
|
||||
|
||||
onLaunch(() => {
|
||||
getEvnUrl({ versionValue: "1.0.1" });
|
||||
onLaunch(async () => {
|
||||
await getEvnUrl({ versionValue: "1.0.3" });
|
||||
refreshToken();
|
||||
});
|
||||
|
||||
|
||||
@@ -352,6 +352,14 @@ const handleSingleSelect = (dateInfo) => {
|
||||
|
||||
// 处理范围选择
|
||||
const handleRangeSelection = (dateInfo) => {
|
||||
if (dateInfo.price === undefined || dateInfo.price === null || dateInfo.stock === '' || dateInfo.price === '-') {
|
||||
uni.showToast({
|
||||
title: "所选日期不可预订,请重新选择",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rangeStart.value || (rangeStart.value && rangeEnd.value)) {
|
||||
// 开始新的范围选择
|
||||
rangeStart.value = dateInfo.date;
|
||||
|
||||
@@ -80,7 +80,8 @@ const refundTitle = computed(() => {
|
||||
});
|
||||
|
||||
const commodityPurchaseInstruction = computed(() => {
|
||||
if (props.orderData.commodityPurchaseInstruction) {
|
||||
if (props.orderData.commodityPurchaseInstruction &&
|
||||
props.orderData.commodityPurchaseInstruction.refundContent) {
|
||||
// 以换行符为分隔符,将字符串转换为数组
|
||||
return props.orderData.commodityPurchaseInstruction.refundContent.split(
|
||||
"\n"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<view class="inner-card bg-white">
|
||||
<!-- 商品大图部分:自适应剩余空间 -->
|
||||
<view class="goods-image-wrapper relative">
|
||||
<image class="w-full h-full" :src="card.commodityPhoto" />
|
||||
<image class="w-full h-full" :src="card.commodityPhoto" mode="aspectFill"/>
|
||||
<view
|
||||
class="goods-title absolute left-0 right-0 bottom-0 border-box p-12"
|
||||
>
|
||||
|
||||
19
src/constant/token.js
Normal file
19
src/constant/token.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { appId, clientId } from "@/constant/base";
|
||||
|
||||
/// 存储在本地的认证 token 键名
|
||||
export const clientAuthToken = "AUTH_TOKEN_" + clientId + "_" + appId;
|
||||
|
||||
/// 设置本地存储的认证 token
|
||||
export const setStorageSyncToken = (token) => {
|
||||
uni.setStorageSync(clientAuthToken, token);
|
||||
};
|
||||
|
||||
/// 获取本地存储的认证 token
|
||||
export const getStorageSyncToken = () => {
|
||||
return uni.getStorageSync(clientAuthToken);
|
||||
};
|
||||
|
||||
/// 移除本地存储的认证 token
|
||||
export const removeStorageSyncToken = () => {
|
||||
uni.setStorageSync(clientAuthToken, "");
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import { wxLogin } from "../request/api/LoginApi";
|
||||
import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager";
|
||||
import { clientId } from "@/constant/base";
|
||||
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
|
||||
import { getStorageSyncToken, setStorageSyncToken } from "../constant/token";
|
||||
|
||||
// 跳转登录
|
||||
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
|
||||
@@ -47,7 +48,7 @@ export const onLogin = async (e) => {
|
||||
|
||||
// 检测token
|
||||
export const checkToken = () => {
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getStorageSyncToken();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (!token) {
|
||||
@@ -61,12 +62,7 @@ export const checkToken = () => {
|
||||
|
||||
// 刷新token
|
||||
export const refreshToken = () => {
|
||||
const token = uni.getStorageSync("token");
|
||||
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
uni.login({
|
||||
provider: "weixin", //使用微信登录
|
||||
success: async ({ code }) => {
|
||||
@@ -81,10 +77,14 @@ export const refreshToken = () => {
|
||||
const response = await wxLogin(params);
|
||||
|
||||
if (response.access_token) {
|
||||
uni.setStorageSync("token", response.access_token);
|
||||
setStorageSyncToken(response.access_token);
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
resolve(false)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@ app.$mount();
|
||||
import { createSSRApp } from "vue";
|
||||
import * as Pinia from "pinia";
|
||||
import { createUnistorage } from "pinia-plugin-unistorage";
|
||||
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App);
|
||||
const pinia = Pinia.createPinia();
|
||||
|
||||
@@ -7,9 +7,10 @@ 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) => {
|
||||
uni.setStorageSync("token", "");
|
||||
removeStorageSyncToken();
|
||||
const appStore = useAppStore();
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
@@ -26,7 +27,7 @@ const loginAuth = (e) => {
|
||||
console.log("获取到的微信授权response:", response);
|
||||
|
||||
if (response.access_token) {
|
||||
uni.setStorageSync("token", response.access_token);
|
||||
setStorageSyncToken(response.access_token);
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
resolve();
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
/>
|
||||
<text
|
||||
class="font-size-16 font-500 color-white"
|
||||
@click="emit('payClick', orderData)"
|
||||
>立即支付</text
|
||||
>
|
||||
</view>
|
||||
@@ -29,7 +28,9 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, defineProps, defineEmits } from "vue";
|
||||
import { computed, defineProps, defineEmits, ref, onMounted, watch } from "vue";
|
||||
import { DebounceUtils } from "@/utils";
|
||||
import { preOrder } from "@/request/api/OrderApi";
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
@@ -54,12 +55,39 @@ const count = computed({
|
||||
},
|
||||
});
|
||||
|
||||
const totalAmt = computed(() => {
|
||||
const { totalDays } = props.selectedDate;
|
||||
const { specificationPrice } = props.orderData;
|
||||
watch(
|
||||
() => count.value,
|
||||
(newVal, oldVal) => {
|
||||
if (newVal !== oldVal) {
|
||||
preOrderPay();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return count.value * Number(specificationPrice) * totalDays;
|
||||
onMounted(() => {
|
||||
preOrderPay();
|
||||
});
|
||||
|
||||
const totalAmt = ref(props.orderData.specificationPrice);
|
||||
|
||||
const preOrderPay = async () => {
|
||||
preOrder({
|
||||
"commodityId": props.orderData.commodityId,
|
||||
"purchaseAmount": count.value,
|
||||
"checkInData": props.selectedDate.startDate,
|
||||
"checkOutData": props.selectedDate.endDate,
|
||||
}).then((res) => {
|
||||
console.log("预支付金额计算结果:", res);
|
||||
totalAmt.value = res.data.payAmt;
|
||||
}).catch((err) => {
|
||||
console.error("预支付金额计算失败:", err);
|
||||
});
|
||||
}
|
||||
|
||||
const handleBooking = DebounceUtils.createDebounce(() => {
|
||||
emit("payClick", props.orderData);
|
||||
}, 1000);
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
|
||||
<!-- 底部 -->
|
||||
<FooterSection
|
||||
v-if="Object.keys(orderData).length"
|
||||
v-model="quantity"
|
||||
:selectedDate="selectedDate"
|
||||
:orderData="orderData"
|
||||
@@ -128,11 +129,6 @@ const isDeleting = ref(false); // 标志位,防止删除时watch冲突
|
||||
watch(
|
||||
quantity,
|
||||
async (newQuantity) => {
|
||||
// 非酒店类型,不处理
|
||||
if (orderData.value.commodityTypeCode !== "0") {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果正在执行删除操作,跳过watch逻辑
|
||||
if (isDeleting.value) {
|
||||
isDeleting.value = false;
|
||||
@@ -208,16 +204,22 @@ const validateUserForms = () => {
|
||||
|
||||
// 处理支付点击事件
|
||||
const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
// 点击后立即展示 loading
|
||||
uni.showLoading({ title: "正在提交订单..." });
|
||||
|
||||
try {
|
||||
console.log("处理支付点击事件", userFormList.value);
|
||||
// 判断是酒店类型
|
||||
if (goodsData.commodityTypeCode === "0") {
|
||||
// 校验用户姓名
|
||||
if (!validateUserForms()) {
|
||||
uni.hideLoading();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 校验手机号
|
||||
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
|
||||
return;
|
||||
}
|
||||
@@ -255,6 +257,7 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
||||
return;
|
||||
}
|
||||
@@ -264,17 +267,14 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
// console.error("支付参数不完整:", {
|
||||
// nonceStr: !!nonceStr,
|
||||
// packageVal: !!packageVal,
|
||||
// paySign: !!paySign,
|
||||
// signType: !!signType,
|
||||
// timeStamp: !!timeStamp,
|
||||
// });
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||
uni.hideLoading();
|
||||
|
||||
// 调用微信支付
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
@@ -298,6 +298,13 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
uni.showToast({ title: "支付失败,请重试", icon: "none" });
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
uni.showToast({ title: "请求出错,请重试", icon: "none" });
|
||||
} finally {
|
||||
// 防止某些分支忘记 hide,确保最终关闭 loading(requestPayment 后也可以安全调用 hide)
|
||||
uni.hideLoading();
|
||||
}
|
||||
}, 1000);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<script setup>
|
||||
import { defineProps, defineEmits, computed } from "vue";
|
||||
import { orderPayNow } from "@/request/api/OrderApi";
|
||||
import { DebounceUtils } from "@/utils";
|
||||
|
||||
const props = defineProps({
|
||||
orderData: {
|
||||
@@ -64,17 +65,21 @@ const buttonText = computed(() => {
|
||||
const emit = defineEmits(["refund", "refresh"]);
|
||||
|
||||
// 处理按钮点击事件
|
||||
const handleButtonClick = async (orderData) => {
|
||||
const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
|
||||
try {
|
||||
// 再次预定跳转商品详情
|
||||
if (["1", "2", "3", "4", "5", "6"].includes(statusCode.value)) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/goods/index?commodityId=${orderData.commodityId}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 待支付状态,调用支付接口
|
||||
if (statusCode.value === "0") {
|
||||
// 显示 loading
|
||||
uni.showLoading({ title: "正在提交订单..." });
|
||||
|
||||
const orderId = orderData.orderId;
|
||||
const payWay = orderData.payWay;
|
||||
const paySource = orderData.paySource;
|
||||
@@ -84,6 +89,7 @@ const handleButtonClick = async (orderData) => {
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
||||
return;
|
||||
}
|
||||
@@ -93,17 +99,14 @@ const handleButtonClick = async (orderData) => {
|
||||
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
// console.error("支付参数不完整:", {
|
||||
// nonceStr: !!nonceStr,
|
||||
// packageVal: !!packageVal,
|
||||
// paySign: !!paySign,
|
||||
// signType: !!signType,
|
||||
// timeStamp: !!timeStamp,
|
||||
// });
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||
uni.hideLoading();
|
||||
|
||||
// 调用微信支付
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
@@ -126,8 +129,9 @@ const handleButtonClick = async (orderData) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("操作失败:", error);
|
||||
uni.hideLoading();
|
||||
}
|
||||
};
|
||||
}, 1000);
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
<template>
|
||||
<view
|
||||
class="card bg-white border-box p-8 rounded-12 flex flex-items-start m-12"
|
||||
@click.stop="handleClick(item)"
|
||||
>
|
||||
<image
|
||||
class="left rounded-10"
|
||||
:src="item.commodityPhoto"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view class="card bg-white border-box p-8 rounded-12 flex flex-items-start m-12" @click.stop="handleClick(item)">
|
||||
<image class="left rounded-10" :src="item.commodityPhoto" mode="aspectFill" />
|
||||
<view class="right border-box flex-full pl-12">
|
||||
<view class="font-size-16 line-height-24 color-171717 mb-4">
|
||||
{{ item.commodityName }}
|
||||
</view>
|
||||
<view
|
||||
v-if="item.commodityFacility"
|
||||
class="font-size-12 line-height-16 color-99A0AE mb-4 ellipsis-1"
|
||||
>
|
||||
<view v-if="item.commodityFacility" class="font-size-12 line-height-16 color-99A0AE mb-4 ellipsis-1">
|
||||
{{ item.commodityFacility.join(" ") }}
|
||||
</view>
|
||||
<view class="font-size-12 line-height-18 color-43669A">
|
||||
@@ -23,19 +13,13 @@
|
||||
</view>
|
||||
|
||||
<view class="flex flex-items-center flex-justify-end">
|
||||
<text
|
||||
class="amt font-size-18 font-500 font-family-misans-vf line-height-24 color-FF3D60 mr-4"
|
||||
>
|
||||
<text class="amt font-size-18 font-500 font-family-misans-vf line-height-24 color-FF3D60 mr-4">
|
||||
{{ item.specificationPrice }}
|
||||
</text>
|
||||
<text class="font-size-12 line-height-16 color-99A0AE">
|
||||
/{{ item.stockUnitLabel }}
|
||||
</text>
|
||||
<text
|
||||
class="btn border-box rounded-10 color-white ml-16"
|
||||
@click.stop="handleBooking(item)"
|
||||
>订</text
|
||||
>
|
||||
<text class="btn border-box rounded-10 color-white ml-16" @click.stop="handleBooking(item)">订</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -68,20 +52,18 @@ const props = defineProps({
|
||||
},
|
||||
});
|
||||
|
||||
const handleClick = ({ commodityId }) => {
|
||||
uni.navigateTo({ url: `/pages/goods/index?commodityId=${commodityId}` });
|
||||
};
|
||||
|
||||
const selectedDateStore = useSelectedDateStore();
|
||||
const handleBooking = ({ commodityId }) => {
|
||||
const { startDate, endDate, totalDays } = props.selectedDate;
|
||||
|
||||
const navigateToPage = (commodityId, path) => {
|
||||
const { startDate, endDate, totalDays } = props.selectedDate;
|
||||
selectedDateStore.setData({ startDate, endDate, totalDays });
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages-booking/index?commodityId=${commodityId}`,
|
||||
});
|
||||
uni.navigateTo({ url: `${path}?commodityId=${commodityId}` });
|
||||
};
|
||||
|
||||
const handleClick = ({ commodityId }) => navigateToPage(commodityId, "/pages/goods/index")
|
||||
|
||||
const handleBooking = ({ commodityId }) => navigateToPage(commodityId, "/pages-booking/index")
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -159,6 +159,7 @@ import WebSocketManager from "@/utils/WebSocketManager";
|
||||
import { ThrottleUtils, IdUtils } from "@/utils";
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
|
||||
const appStore = useAppStore();
|
||||
/// 导航栏相关
|
||||
@@ -346,7 +347,7 @@ onLoad(() => {
|
||||
// token存在,初始化数据
|
||||
const initHandler = () => {
|
||||
console.log("initHandler");
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getStorageSyncToken();
|
||||
|
||||
if (!token) return;
|
||||
loadRecentConversation();
|
||||
@@ -407,14 +408,14 @@ const getMainPageData = async () => {
|
||||
|
||||
/// =============对话↓================
|
||||
// 初始化WebSocket
|
||||
const initWebSocket = () => {
|
||||
const initWebSocket = async () => {
|
||||
// 清理旧实例
|
||||
if (webSocketManager) {
|
||||
webSocketManager.destroy();
|
||||
}
|
||||
|
||||
// 使用配置的WebSocket服务器地址
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getStorageSyncToken();
|
||||
const wsUrl = `${appStore.serverConfig.wssUrl}?access_token=${token}`;
|
||||
|
||||
// 初始化WebSocket管理器
|
||||
@@ -426,9 +427,10 @@ const initWebSocket = () => {
|
||||
|
||||
// 连接成功回调
|
||||
onOpen: (event) => {
|
||||
console.log("WebSocket连接成功");
|
||||
// 重置会话状态
|
||||
webSocketConnectStatus = true;
|
||||
isSessionActive.value = true;
|
||||
isSessionActive.value = false; // 连接成功时重置会话状态,避免影响新消息发送
|
||||
},
|
||||
|
||||
// 连接断开回调
|
||||
@@ -441,9 +443,9 @@ const initWebSocket = () => {
|
||||
|
||||
// 错误回调
|
||||
onError: (error) => {
|
||||
console.error("WebSocket错误:", error);
|
||||
webSocketConnectStatus = false;
|
||||
isSessionActive.value = false;
|
||||
console.error("WebSocket错误:", error);
|
||||
},
|
||||
|
||||
// 消息回调
|
||||
@@ -458,21 +460,24 @@ const initWebSocket = () => {
|
||||
getAgentId: () => agentId.value,
|
||||
});
|
||||
|
||||
try {
|
||||
// 初始化连接
|
||||
webSocketManager
|
||||
.connect()
|
||||
.then(() => {
|
||||
await webSocketManager.connect();
|
||||
console.log("WebSocket连接初始化成功");
|
||||
webSocketConnectStatus = true;
|
||||
})
|
||||
.catch((error) => {
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("WebSocket连接失败:", error);
|
||||
});
|
||||
webSocketConnectStatus = false;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理WebSocket消息
|
||||
const handleWebSocketMessage = (data) => {
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) {
|
||||
console.error("处理WebSocket消息时找不到对应的AI消息项");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -518,7 +523,10 @@ const handleWebSocketMessage = (data) => {
|
||||
};
|
||||
|
||||
// 重置消息状态
|
||||
const resetMessageState = () => {};
|
||||
const resetMessageState = () => {
|
||||
// 重置当前会话消息ID
|
||||
currentSessionMessageId = null;
|
||||
};
|
||||
|
||||
// 初始化数据 首次数据加载的时候
|
||||
const initData = () => {
|
||||
@@ -536,13 +544,40 @@ const sendMessage = async (message, isInstruct = false) => {
|
||||
|
||||
await checkToken();
|
||||
|
||||
// 检查WebSocket连接状态,如果未连接,尝试重新连接
|
||||
if (!webSocketConnectStatus) {
|
||||
console.log("WebSocket未连接,尝试重新连接...");
|
||||
// 显示加载提示
|
||||
uni.showLoading({
|
||||
title: "正在连接服务器...",
|
||||
});
|
||||
|
||||
// 尝试重新初始化WebSocket连接
|
||||
try {
|
||||
await initWebSocket();
|
||||
// 等待短暂时间确保连接建立
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
// 检查连接是否成功建立
|
||||
if (!webSocketConnectStatus) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "当前网络异常,请稍后重试",
|
||||
title: "连接服务器失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.hideLoading();
|
||||
} catch (error) {
|
||||
console.error("重新连接WebSocket失败:", error);
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "连接服务器失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSessionActive.value) {
|
||||
uni.showToast({
|
||||
@@ -563,6 +598,8 @@ const sendMessage = async (message, isInstruct = false) => {
|
||||
};
|
||||
chatMsgList.value.push(newMsg);
|
||||
inputMessage.value = "";
|
||||
// 发送消息后滚动到底部
|
||||
setTimeoutScrollToBottom();
|
||||
sendChat(message, isInstruct);
|
||||
console.log("发送的新消息:", JSON.stringify(newMsg));
|
||||
};
|
||||
@@ -578,9 +615,11 @@ const sendWebSocketMessage = (messageType, messageContent, options = {}) => {
|
||||
};
|
||||
|
||||
try {
|
||||
webSocketManager.sendMessage(args);
|
||||
// 直接调用webSocketManager的sendMessage方法,利用其内部的消息队列机制
|
||||
// 即使当前连接断开,消息也会被加入队列,等待连接恢复后发送
|
||||
const result = webSocketManager.sendMessage(args);
|
||||
console.log(`WebSocket消息已发送 [类型:${messageType}]:`, args);
|
||||
return true;
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("发送WebSocket消息失败:", error);
|
||||
isSessionActive.value = false;
|
||||
@@ -590,9 +629,26 @@ const sendWebSocketMessage = (messageType, messageContent, options = {}) => {
|
||||
|
||||
// 发送获取AI聊天消息
|
||||
const sendChat = (message, isInstruct = false) => {
|
||||
if (!webSocketManager || !webSocketManager.isConnected()) {
|
||||
console.error("WebSocket未连接");
|
||||
// 检查WebSocket管理器是否存在,如果不存在,尝试重新初始化
|
||||
if (!webSocketManager) {
|
||||
console.error("WebSocket管理器不存在,尝试重新初始化...");
|
||||
initWebSocket();
|
||||
// 短暂延迟后再次检查连接状态
|
||||
setTimeout(() => {
|
||||
if (webSocketManager && webSocketManager.isConnected()) {
|
||||
// 连接成功后重新发送消息
|
||||
sendChat(message, isInstruct);
|
||||
} else {
|
||||
console.error("WebSocket重新初始化失败");
|
||||
isSessionActive.value = false;
|
||||
// 更新AI消息状态为失败
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (aiMsgIndex >= 0 && chatMsgList.value[aiMsgIndex].msgType === MessageRole.AI) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "发送消息失败,请重试";
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -615,6 +671,8 @@ const sendChat = (message, isInstruct = false) => {
|
||||
},
|
||||
};
|
||||
chatMsgList.value.push(aiMsg);
|
||||
// 添加AI消息后滚动到底部
|
||||
setTimeoutScrollToBottom();
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
|
||||
// 发送消息
|
||||
@@ -678,6 +736,7 @@ const resetConfig = () => {
|
||||
|
||||
// 重置消息状态
|
||||
resetMessageState();
|
||||
isSessionActive.value = false;
|
||||
|
||||
// 清理定时器
|
||||
if (holdKeyboardTimer.value) {
|
||||
|
||||
@@ -3,11 +3,21 @@
|
||||
}
|
||||
|
||||
.ip {
|
||||
position: relative;
|
||||
flex: 0 0 158px;
|
||||
width: 158px;
|
||||
height: 134px;
|
||||
animation: sprite-play calc(var(--ipLargeTime) * 1s)
|
||||
steps(var(--ipLargeImageStep)) infinite;
|
||||
&::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
background-color: #f9fcfd;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes sprite-play {
|
||||
|
||||
@@ -38,20 +38,11 @@
|
||||
<!-- 同意隐私协议并获取手机号按钮 -->
|
||||
|
||||
<button
|
||||
v-if="!isAgree"
|
||||
class="login-btn"
|
||||
type="primary"
|
||||
@click="handleAgreeAndGetPhone"
|
||||
>
|
||||
手机号快捷登录
|
||||
</button>
|
||||
|
||||
<button
|
||||
v-if="isAgree && !appStore.tokenExpired"
|
||||
class="login-btn"
|
||||
type="primary"
|
||||
open-type="getPhoneNumber"
|
||||
:open-type="needWxLogin ? 'getPhoneNumber' : ''"
|
||||
@getphonenumber="getPhoneNumber"
|
||||
@click="handleAgreeAndGetPhone"
|
||||
>
|
||||
手机号快捷登录
|
||||
</button>
|
||||
@@ -67,19 +58,19 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onShow } from "@dcloudio/uni-app";
|
||||
import { ref, computed } from "vue";
|
||||
import {
|
||||
getServiceAgreement,
|
||||
getPrivacyAgreement,
|
||||
} from "@/request/api/LoginApi";
|
||||
import { onLogin, goBack } from "@/hooks/useGoLogin";
|
||||
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 { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
const appStore = useAppStore();
|
||||
|
||||
const needWxLogin = ref(false);
|
||||
const isAgree = ref(false);
|
||||
const visible = ref(false);
|
||||
const serviceAgreement = ref("");
|
||||
@@ -90,6 +81,11 @@ const logo = computed(() => getCurrentConfig().logo);
|
||||
|
||||
// 同意隐私协议并获取手机号
|
||||
const handleAgreeAndGetPhone = () => {
|
||||
// 如果需要微信登录,直接返回
|
||||
if (needWxLogin.value) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!isAgree.value) {
|
||||
uni.showToast({
|
||||
title: "请先同意服务协议和隐私协议",
|
||||
@@ -97,6 +93,8 @@ const handleAgreeAndGetPhone = () => {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
refreshToken().then(() => goBack());
|
||||
};
|
||||
|
||||
const getPhoneNumber = (e) => {
|
||||
@@ -141,6 +139,13 @@ const getPrivacyAgreementData = async () => {
|
||||
};
|
||||
|
||||
getPrivacyAgreementData();
|
||||
|
||||
// 页面显示时刷新token
|
||||
onShow(async () => {
|
||||
const res = await refreshToken();
|
||||
|
||||
needWxLogin.value = res;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { goLogin } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
import { removeStorageSyncToken } from "@/constant/token";
|
||||
|
||||
/// 请求流式数据的API
|
||||
const API = "/agent/assistant/chat";
|
||||
@@ -72,7 +74,7 @@ const stopAbortTask = () => {
|
||||
|
||||
const agentChatStream = (params, onChunk) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getStorageSyncToken();
|
||||
const requestId = Date.now().toString(); // 生成唯一请求ID
|
||||
|
||||
// 重置状态
|
||||
@@ -130,7 +132,7 @@ const agentChatStream = (params, onChunk) => {
|
||||
res.statusCode
|
||||
);
|
||||
if (res.statusCode === 424) {
|
||||
uni.setStorageSync("token", "");
|
||||
removeStorageSyncToken();
|
||||
goLogin();
|
||||
}
|
||||
if (onChunk) {
|
||||
@@ -144,8 +146,7 @@ const agentChatStream = (params, onChunk) => {
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
`❌ 请求 [${requestId}] ${
|
||||
isAborted ? "已终止" : "已过期"
|
||||
`❌ 请求 [${requestId}] ${isAborted ? "已终止" : "已过期"
|
||||
},忽略complete回调`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { removeStorageSyncToken } from "@/constant/token";
|
||||
import request from "../base/request";
|
||||
|
||||
const wxLogin = (args) => {
|
||||
@@ -8,7 +9,7 @@ const wxLogin = (args) => {
|
||||
},
|
||||
};
|
||||
|
||||
uni.setStorageSync("token", "");
|
||||
removeStorageSyncToken();
|
||||
|
||||
return request.post("/auth/oauth2/token", args, config);
|
||||
};
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
|
||||
export const updateImageFile = (file) => {
|
||||
const { serverConfig } = useAppStore();
|
||||
const url = serverConfig.baseUrl + "/hotelBiz/hotBizCommon/upload";
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getStorageSyncToken();
|
||||
const clientId = getCurrentConfig().clientId;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -3,14 +3,11 @@ import { isProd } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
|
||||
// 获取服务地址
|
||||
const getEvnUrl = (args) => {
|
||||
if (isProd) {
|
||||
const getEvnUrl = async (args) => {
|
||||
const res = await request.post("https://biz.nianxx.cn/hotelBiz/mainScene/getServiceUrl", args)
|
||||
if (res && res.code == 0 && res.data) {
|
||||
const appStore = useAppStore();
|
||||
request
|
||||
.post("https://biz.nianxx.cn/hotelBiz/mainScene/getServiceUrl", args)
|
||||
.then(({ data }) => {
|
||||
appStore.setServerConfig(data);
|
||||
});
|
||||
appStore.setServerConfig(res.data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { goLogin } from "../../hooks/useGoLogin";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
|
||||
const clientId = getCurrentConfig().clientId;
|
||||
const defaultConfig = {
|
||||
@@ -19,7 +20,7 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
url = appStore.serverConfig?.baseUrl + url;
|
||||
}
|
||||
// 动态获取 token
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getStorageSyncToken();
|
||||
|
||||
let header = {
|
||||
...defaultConfig.header,
|
||||
@@ -58,9 +59,9 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
resolve(res.data);
|
||||
if (res.statusCode && res.statusCode === 424) {
|
||||
console.log("424错误,重新登录");
|
||||
uni.setStorageSync("token", "");
|
||||
// removeStorageSyncToken();
|
||||
uni.$emit(NOTICE_EVENT_LOGOUT);
|
||||
goLogin();
|
||||
// goLogin();
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
|
||||
@@ -3,7 +3,11 @@ import { defineStore } from "pinia";
|
||||
export const useSelectedDateStore = defineStore("selectedDate", {
|
||||
state() {
|
||||
return {
|
||||
selectedDate: {},
|
||||
selectedDate: {
|
||||
startDate: "",
|
||||
endDate: "",
|
||||
totalDays: 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ export default {
|
||||
app.mixin({
|
||||
onLoad() {
|
||||
const page = getCurrentPages().pop();
|
||||
if (page) {
|
||||
console.log("Current page:", page);
|
||||
const allowShare = page && page.route && page.route !== "pages/login/index";
|
||||
if (allowShare) {
|
||||
uni.showShareMenu({
|
||||
withShareTicket: true,
|
||||
menus: ["shareAppMessage", "shareTimeline"],
|
||||
|
||||
Reference in New Issue
Block a user