16 Commits

Author SHA1 Message Date
duanshuwen
ea56695099 feat: 登录异常问题调整 2025-12-26 22:59:44 +08:00
duanshuwen
dfadb06934 feat: 登录逻辑问题调整 2025-12-25 23:04:51 +08:00
duanshuwen
f027685072 feat: 调整登录逻辑 2025-12-25 22:45:55 +08:00
duanshuwen
b7fbe99cd0 feat: 商品详情日期初始化问题修复 2025-12-22 21:58:32 +08:00
5027abc239 fix: 处理日期范围选择 2025-12-22 20:13:09 +08:00
a2ff08f090 feat: 价格计算 2025-12-22 19:51:22 +08:00
37192b0ba4 fix: 支付防抖 2025-12-22 18:51:28 +08:00
8be21f8307 fix: 修复支付问题 2025-12-22 18:05:15 +08:00
296781c506 feat: 优化登录流程 2025-12-15 22:33:22 +08:00
9eb1dc6747 feat: 登录的逻辑调整 2025-12-15 21:04:03 +08:00
364e47b641 feat: 图片样式调整 2025-12-15 18:38:48 +08:00
a3c363cbc9 feat: 区别不同的小程序的缓存问题 2025-12-15 16:26:45 +08:00
09452bf600 feat: 提交订单的loading 添加 2025-12-01 16:55:10 +08:00
c20563ecf5 feat: 修复了连接断开之后重连的逻辑 2025-12-01 16:39:55 +08:00
172bae663b feat: 支付的时候防止重复点击 2025-12-01 15:15:48 +08:00
9632f5c065 fix: 禁止分享登录页面 2025-12-01 14:18:37 +08:00
23 changed files with 408 additions and 345 deletions

View File

@@ -1,5 +1,5 @@
{ {
"appid": "wx5e79df5996572539", "appid": "wx23f86d809ae80259",
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "3.8.10", "libVersion": "3.8.10",
"packOptions": { "packOptions": {

View File

@@ -2,10 +2,16 @@
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"; import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { getEvnUrl } from "@/request/api/config"; import { getEvnUrl } from "@/request/api/config";
import { refreshToken } from "@/hooks/useGoLogin"; import { refreshToken } from "@/hooks/useGoLogin";
import { getStorageSyncToken } from "@/constant/token";
onLaunch(() => { onLaunch(async () => {
getEvnUrl({ versionValue: "1.0.1" }); await getEvnUrl({ versionValue: "1.0.3" });
refreshToken();
const token = getStorageSyncToken();
if (token) {
refreshToken();
}
}); });
onShow(() => { onShow(() => {

View File

@@ -352,6 +352,14 @@ const handleSingleSelect = (dateInfo) => {
// 处理范围选择 // 处理范围选择
const handleRangeSelection = (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)) { if (!rangeStart.value || (rangeStart.value && rangeEnd.value)) {
// 开始新的范围选择 // 开始新的范围选择
rangeStart.value = dateInfo.date; rangeStart.value = dateInfo.date;

View File

@@ -80,7 +80,8 @@ const refundTitle = computed(() => {
}); });
const commodityPurchaseInstruction = computed(() => { const commodityPurchaseInstruction = computed(() => {
if (props.orderData.commodityPurchaseInstruction) { if (props.orderData.commodityPurchaseInstruction &&
props.orderData.commodityPurchaseInstruction.refundContent) {
// 以换行符为分隔符,将字符串转换为数组 // 以换行符为分隔符,将字符串转换为数组
return props.orderData.commodityPurchaseInstruction.refundContent.split( return props.orderData.commodityPurchaseInstruction.refundContent.split(
"\n" "\n"

View File

@@ -14,7 +14,7 @@
<view class="inner-card bg-white"> <view class="inner-card bg-white">
<!-- 商品大图部分自适应剩余空间 --> <!-- 商品大图部分自适应剩余空间 -->
<view class="goods-image-wrapper relative"> <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 <view
class="goods-title absolute left-0 right-0 bottom-0 border-box p-12" class="goods-title absolute left-0 right-0 bottom-0 border-box p-12"
> >

View File

@@ -12,7 +12,7 @@ import rawConfigs from '../../client-configs.json' with { type: 'json' };
export const CLIENT_CONFIGS = rawConfigs; export const CLIENT_CONFIGS = rawConfigs;
// 获取当前用户端配置 // 获取当前用户端配置
export const getCurrentConfig = () => CLIENT_CONFIGS.zhinian; export const getCurrentConfig = () => CLIENT_CONFIGS.duohua;
export const clientId = getCurrentConfig().clientId; export const clientId = getCurrentConfig().clientId;
export const appId = getCurrentConfig().appId; export const appId = getCurrentConfig().appId;

19
src/constant/token.js Normal file
View 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, "");
};

View File

@@ -1,7 +1,8 @@
import { wxLogin } from "../request/api/LoginApi"; import { wxLogin, checkUserPhone } from "../request/api/LoginApi";
import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager"; import { loginAuth, bindPhone } from "@/manager/LoginManager";
import { clientId } from "@/constant/base"; import { clientId } from "@/constant/base";
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant"; import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
import { getStorageSyncToken, setStorageSyncToken } from "../constant/token";
// 跳转登录 // 跳转登录
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" }); export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
@@ -21,8 +22,9 @@ export const onLogin = async (e) => {
} }
await loginAuth(e).then(async () => { await loginAuth(e).then(async () => {
console.log("loginAuth resolve success");
// 检查手机号是否绑定 // 检查手机号是否绑定
const checkRes = await checkPhone(); const checkRes = await checkUserPhone();
if (checkRes.data) { if (checkRes.data) {
resolve(); resolve();
return; return;
@@ -47,7 +49,7 @@ export const onLogin = async (e) => {
// 检测token // 检测token
export const checkToken = () => { export const checkToken = () => {
const token = uni.getStorageSync("token"); const token = getStorageSyncToken();
return new Promise((resolve) => { return new Promise((resolve) => {
if (!token) { if (!token) {
@@ -61,30 +63,27 @@ export const checkToken = () => {
// 刷新token // 刷新token
export const refreshToken = () => { export const refreshToken = () => {
const token = uni.getStorageSync("token"); return new Promise(async (resolve) => {
uni.login({
provider: "weixin", //使用微信登录
success: async ({ code }) => {
console.log("进入 refreshToken success", code);
const params = {
openIdCode: [code],
grant_type: "wechat",
scope: "server",
clientId: clientId,
};
console.log("获取到的微信授权params:", JSON.stringify(params));
if (!token) { const response = await wxLogin(params);
return;
}
uni.login({ if (response.access_token) {
provider: "weixin", //使用微信登录 setStorageSyncToken(response.access_token);
success: async ({ code }) => { // 登录成功后,触发登录成功事件
console.log("refreshToken", code); uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
const params = { }
openIdCode: [code], },
grant_type: "wechat", });
scope: "server",
clientId: clientId,
};
console.log("获取到的微信授权params:", JSON.stringify(params));
const response = await wxLogin(params);
if (response.access_token) {
uni.setStorageSync("token", response.access_token);
// 登录成功后,触发登录成功事件
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
}
},
}); });
}; };

View File

@@ -16,6 +16,7 @@ app.$mount();
import { createSSRApp } from "vue"; import { createSSRApp } from "vue";
import * as Pinia from "pinia"; import * as Pinia from "pinia";
import { createUnistorage } from "pinia-plugin-unistorage"; import { createUnistorage } from "pinia-plugin-unistorage";
export function createApp() { export function createApp() {
const app = createSSRApp(App); const app = createSSRApp(App);
const pinia = Pinia.createPinia(); const pinia = Pinia.createPinia();
@@ -29,4 +30,4 @@ export function createApp() {
pinia, pinia,
}; };
} }
// #endif // #endif

View File

@@ -4,13 +4,12 @@ import {
checkUserPhone, checkUserPhone,
} from "../request/api/LoginApi"; } from "../request/api/LoginApi";
import { getWeChatAuthCode } from "./AuthManager"; import { getWeChatAuthCode } from "./AuthManager";
import { useAppStore } from "@/store";
import { clientId } from "@/constant/base"; import { clientId } from "@/constant/base";
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant"; import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
import { removeStorageSyncToken, setStorageSyncToken } from "../constant/token";
const loginAuth = (e) => { const loginAuth = (e) => {
uni.setStorageSync("token", ""); removeStorageSyncToken();
const appStore = useAppStore();
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const openIdCode = await getWeChatAuthCode(e); const openIdCode = await getWeChatAuthCode(e);
@@ -26,7 +25,8 @@ const loginAuth = (e) => {
console.log("获取到的微信授权response:", response); console.log("获取到的微信授权response:", response);
if (response.access_token) { if (response.access_token) {
uni.setStorageSync("token", response.access_token); console.log("进入条件");
setStorageSyncToken(response.access_token);
// 登录成功后,触发登录成功事件 // 登录成功后,触发登录成功事件
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS); uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
resolve(); resolve();
@@ -45,9 +45,4 @@ const bindPhone = async (params) => {
} }
}; };
const checkPhone = async () => { export { loginAuth, bindPhone };
const response = await checkUserPhone();
return response;
};
export { loginAuth, bindPhone, checkPhone };

View File

@@ -60,7 +60,7 @@
wx23f86d809ae80259 wx23f86d809ae80259
*/ */
"mp-weixin": { "mp-weixin": {
"appid": "wx5e79df5996572539", "appid": "wx23f86d809ae80259",
"setting": { "setting": {
"urlCheck": false, "urlCheck": false,
"minified": true "minified": true

View File

@@ -21,7 +21,6 @@
/> />
<text <text
class="font-size-16 font-500 color-white" class="font-size-16 font-500 color-white"
@click="emit('payClick', orderData)"
>立即支付</text >立即支付</text
> >
</view> </view>
@@ -29,7 +28,9 @@
</template> </template>
<script setup> <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({ const props = defineProps({
modelValue: { modelValue: {
@@ -54,11 +55,39 @@ const count = computed({
}, },
}); });
const totalAmt = computed(() => { watch(
const { totalDays } = props.selectedDate; () => count.value,
const { specificationPrice } = props.orderData; (newVal, oldVal) => {
return count.value * Number(specificationPrice) * totalDays; if (newVal !== oldVal) {
preOrderPay();
}
}
);
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> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@@ -79,6 +79,7 @@
<!-- 底部 --> <!-- 底部 -->
<FooterSection <FooterSection
v-if="Object.keys(orderData).length"
v-model="quantity" v-model="quantity"
:selectedDate="selectedDate" :selectedDate="selectedDate"
:orderData="orderData" :orderData="orderData"
@@ -203,96 +204,107 @@ const validateUserForms = () => {
// 处理支付点击事件 // 处理支付点击事件
const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => { const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
console.log("处理支付点击事件", userFormList.value); // 点击后立即展示 loading
// 判断是酒店类型 uni.showLoading({ title: "正在提交订单..." });
if (goodsData.commodityTypeCode === "0") {
// 校验用户姓名 try {
if (!validateUserForms()) { 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; return;
} }
// 购买的商品id
const commodityId = goodsData.commodityId;
// 消费者信息
const consumerInfoEntityList = userFormList.value;
// 购买数量
const purchaseAmount = consumerInfoEntityList.length;
// 支付方式 0-微信 1-支付宝 2-云闪付
const payWay = "0";
// 支付渠道 0-app 1-小程序 2-h5
const paySource = "1";
const params = {
commodityId,
purchaseAmount,
payWay,
paySource,
consumerInfoEntityList,
};
//酒店类型添加入住时间、离店时间
if (goodsData.commodityTypeCode === "0" && selectedDate.value) {
const { startDate, endDate } = selectedDate.value;
// 入住时间
params.checkInData = startDate;
// 离店时间
params.checkOutData = endDate;
}
const res = await orderPay(params);
console.log("确认订单---2:", res);
// 检查接口返回数据
if (!res || !res.data) {
uni.hideLoading();
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
return;
}
const { data } = res;
const { nonceStr, packageVal, paySign, signType, timeStamp } = data;
// 验证支付参数是否完整
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
uni.hideLoading();
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
return;
}
// 在发起微信支付前关闭 loading避免与原生支付 UI 冲突)
uni.hideLoading();
// 调用微信支付
uni.requestPayment({
provider: "wxpay",
timeStamp: String(timeStamp), // 确保为字符串类型
nonceStr: String(nonceStr),
package: String(packageVal), // 确保为字符串类型
signType: String(signType),
paySign: String(paySign),
success: () => {
uni.showToast({
title: "支付成功",
icon: "success",
success: () => {
uni.navigateTo({
url: "/pages-order/order/list",
});
},
});
},
fail: () => {
uni.showToast({ title: "支付失败,请重试", icon: "none" });
},
});
} catch (error) {
console.error(error);
uni.showToast({ title: "请求出错,请重试", icon: "none" });
} finally {
// 防止某些分支忘记 hide确保最终关闭 loadingrequestPayment 后也可以安全调用 hide
uni.hideLoading();
} }
// 校验手机号
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
return;
}
// 购买的商品id
const commodityId = goodsData.commodityId;
// 消费者信息
const consumerInfoEntityList = userFormList.value;
// 购买数量
const purchaseAmount = consumerInfoEntityList.length;
// 支付方式 0-微信 1-支付宝 2-云闪付
const payWay = "0";
// 支付渠道 0-app 1-小程序 2-h5
const paySource = "1";
const params = {
commodityId,
purchaseAmount,
payWay,
paySource,
consumerInfoEntityList,
};
//酒店类型添加入住时间、离店时间
if (goodsData.commodityTypeCode === "0" && selectedDate.value) {
const { startDate, endDate } = selectedDate.value;
// 入住时间
params.checkInData = startDate;
// 离店时间
params.checkOutData = endDate;
}
const res = await orderPay(params);
console.log("确认订单---2:", res);
// 检查接口返回数据
if (!res || !res.data) {
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
return;
}
const { data } = res;
const { nonceStr, packageVal, paySign, signType, timeStamp } = data;
// 验证支付参数是否完整
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
// console.error("支付参数不完整:", {
// nonceStr: !!nonceStr,
// packageVal: !!packageVal,
// paySign: !!paySign,
// signType: !!signType,
// timeStamp: !!timeStamp,
// });
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
return;
}
// 调用微信支付
uni.requestPayment({
provider: "wxpay",
timeStamp: String(timeStamp), // 确保为字符串类型
nonceStr: String(nonceStr),
package: String(packageVal), // 确保为字符串类型
signType: String(signType),
paySign: String(paySign),
success: () => {
uni.showToast({
title: "支付成功",
icon: "success",
success: () => {
uni.navigateTo({
url: "/pages-order/order/list",
});
},
});
},
fail: () => {
uni.showToast({ title: "支付失败,请重试", icon: "none" });
},
});
}, 1000); }, 1000);
</script> </script>

View File

@@ -27,6 +27,7 @@
<script setup> <script setup>
import { defineProps, defineEmits, computed } from "vue"; import { defineProps, defineEmits, computed } from "vue";
import { orderPayNow } from "@/request/api/OrderApi"; import { orderPayNow } from "@/request/api/OrderApi";
import { DebounceUtils } from "@/utils";
const props = defineProps({ const props = defineProps({
orderData: { orderData: {
@@ -64,17 +65,21 @@ const buttonText = computed(() => {
const emit = defineEmits(["refund", "refresh"]); const emit = defineEmits(["refund", "refresh"]);
// 处理按钮点击事件 // 处理按钮点击事件
const handleButtonClick = async (orderData) => { const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
try { try {
// 再次预定跳转商品详情 // 再次预定跳转商品详情
if (["1", "2", "3", "4", "5", "6"].includes(statusCode.value)) { if (["1", "2", "3", "4", "5", "6"].includes(statusCode.value)) {
uni.navigateTo({ uni.navigateTo({
url: `/pages/goods/index?commodityId=${orderData.commodityId}`, url: `/pages/goods/index?commodityId=${orderData.commodityId}`,
}); });
return;
} }
// 待支付状态,调用支付接口 // 待支付状态,调用支付接口
if (statusCode.value === "0") { if (statusCode.value === "0") {
// 显示 loading
uni.showLoading({ title: "正在提交订单..." });
const orderId = orderData.orderId; const orderId = orderData.orderId;
const payWay = orderData.payWay; const payWay = orderData.payWay;
const paySource = orderData.paySource; const paySource = orderData.paySource;
@@ -84,6 +89,7 @@ const handleButtonClick = async (orderData) => {
// 检查接口返回数据 // 检查接口返回数据
if (!res || !res.data) { if (!res || !res.data) {
uni.hideLoading();
uni.showToast({ title: "订单创建失败,请重试", icon: "none" }); uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
return; return;
} }
@@ -93,17 +99,14 @@ const handleButtonClick = async (orderData) => {
// 验证支付参数是否完整 // 验证支付参数是否完整
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) { if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
// console.error("支付参数不完整:", { uni.hideLoading();
// nonceStr: !!nonceStr,
// packageVal: !!packageVal,
// paySign: !!paySign,
// signType: !!signType,
// timeStamp: !!timeStamp,
// });
uni.showToast({ title: "支付参数错误,请重试", icon: "none" }); uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
return; return;
} }
// 在发起微信支付前关闭 loading避免与原生支付 UI 冲突)
uni.hideLoading();
// 调用微信支付 // 调用微信支付
uni.requestPayment({ uni.requestPayment({
provider: "wxpay", provider: "wxpay",
@@ -126,8 +129,9 @@ const handleButtonClick = async (orderData) => {
} }
} catch (error) { } catch (error) {
console.error("操作失败:", error); console.error("操作失败:", error);
uni.hideLoading();
} }
}; }, 1000);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -1,21 +1,11 @@
<template> <template>
<view <view class="card bg-white border-box p-8 rounded-12 flex flex-items-start m-12" @click.stop="handleClick(item)">
class="card bg-white border-box p-8 rounded-12 flex flex-items-start m-12" <image class="left rounded-10" :src="item.commodityPhoto" mode="aspectFill" />
@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="right border-box flex-full pl-12">
<view class="font-size-16 line-height-24 color-171717 mb-4"> <view class="font-size-16 line-height-24 color-171717 mb-4">
{{ item.commodityName }} {{ item.commodityName }}
</view> </view>
<view <view v-if="item.commodityFacility" class="font-size-12 line-height-16 color-99A0AE mb-4 ellipsis-1">
v-if="item.commodityFacility"
class="font-size-12 line-height-16 color-99A0AE mb-4 ellipsis-1"
>
{{ item.commodityFacility.join(" ") }} {{ item.commodityFacility.join(" ") }}
</view> </view>
<view class="font-size-12 line-height-18 color-43669A"> <view class="font-size-12 line-height-18 color-43669A">
@@ -23,19 +13,13 @@
</view> </view>
<view class="flex flex-items-center flex-justify-end"> <view class="flex flex-items-center flex-justify-end">
<text <text class="amt font-size-18 font-500 font-family-misans-vf line-height-24 color-FF3D60 mr-4">
class="amt font-size-18 font-500 font-family-misans-vf line-height-24 color-FF3D60 mr-4"
>
{{ item.specificationPrice }} {{ item.specificationPrice }}
</text> </text>
<text class="font-size-12 line-height-16 color-99A0AE"> <text class="font-size-12 line-height-16 color-99A0AE">
/{{ item.stockUnitLabel }} /{{ item.stockUnitLabel }}
</text> </text>
<text <text class="btn border-box rounded-10 color-white ml-16" @click.stop="handleBooking(item)"></text>
class="btn border-box rounded-10 color-white ml-16"
@click.stop="handleBooking(item)"
></text
>
</view> </view>
</view> </view>
</view> </view>
@@ -64,24 +48,22 @@ const props = defineProps({
}, },
selectedDate: { selectedDate: {
type: Object, type: Object,
default: () => {}, default: () => { },
}, },
}); });
const handleClick = ({ commodityId }) => {
uni.navigateTo({ url: `/pages/goods/index?commodityId=${commodityId}` });
};
const selectedDateStore = useSelectedDateStore(); 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 }); selectedDateStore.setData({ startDate, endDate, totalDays });
uni.navigateTo({ uni.navigateTo({ url: `${path}?commodityId=${commodityId}` });
url: `/pages-booking/index?commodityId=${commodityId}`,
});
}; };
const handleClick = ({ commodityId }) => navigateToPage(commodityId, "/pages/goods/index")
const handleBooking = ({ commodityId }) => navigateToPage(commodityId, "/pages-booking/index")
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@@ -2,79 +2,42 @@
<view class="flex flex-col h-screen"> <view class="flex flex-col h-screen">
<!-- 顶部自定义导航栏 --> <!-- 顶部自定义导航栏 -->
<view class="header" :style="{ paddingTop: statusBarHeight + 'px' }"> <view class="header" :style="{ paddingTop: statusBarHeight + 'px' }">
<ChatTopNavBar <ChatTopNavBar ref="topNavBarRef" :mainPageDataModel="mainPageDataModel" />
ref="topNavBarRef"
:mainPageDataModel="mainPageDataModel"
/>
</view> </view>
<!-- 消息列表可滚动区域 --> <!-- 消息列表可滚动区域 -->
<scroll-view <scroll-view class="main flex-full overflow-hidden scroll-y" scroll-y :scroll-top="scrollTop"
class="main flex-full overflow-hidden scroll-y" :scroll-with-animation="true" @scroll="handleScroll" @scrolltolower="handleScrollToLower">
scroll-y
:scroll-top="scrollTop"
:scroll-with-animation="true"
@scroll="handleScroll"
@scrolltolower="handleScrollToLower"
>
<!-- welcome栏 --> <!-- welcome栏 -->
<ChatTopWelcome ref="welcomeRef" :mainPageDataModel="mainPageDataModel" /> <ChatTopWelcome ref="welcomeRef" :mainPageDataModel="mainPageDataModel" />
<view <view class="area-msg-list-content" v-for="item in chatMsgList" :key="item.msgId" :id="item.msgId">
class="area-msg-list-content"
v-for="item in chatMsgList"
:key="item.msgId"
:id="item.msgId"
>
<template v-if="item.msgType === MessageRole.AI"> <template v-if="item.msgType === MessageRole.AI">
<ChatCardAI <ChatCardAI class="flex flex-justify-start" :key="`ai-${item.msgId}-${item.msg ? item.msg.length : 0}`"
class="flex flex-justify-start" :text="item.msg || ''" :isLoading="item.isLoading">
:key="`ai-${item.msgId}-${item.msg ? item.msg.length : 0}`"
:text="item.msg || ''"
:isLoading="item.isLoading"
>
<template #content v-if="item.toolCall"> <template #content v-if="item.toolCall">
<QuickBookingComponent <QuickBookingComponent v-if="item.toolCall.componentName === CompName.quickBookingCard" />
v-if="item.toolCall.componentName === CompName.quickBookingCard" <DiscoveryCardComponent v-else-if="
/> item.toolCall.componentName === CompName.discoveryCard
<DiscoveryCardComponent " />
v-else-if=" <CreateServiceOrder v-else-if="
item.toolCall.componentName === CompName.discoveryCard item.toolCall.componentName === CompName.callServiceCard
" " :toolCall="item.toolCall" />
/> <Feedback v-else-if="
<CreateServiceOrder item.toolCall.componentName === CompName.feedbackCard
v-else-if=" " :toolCall="item.toolCall" />
item.toolCall.componentName === CompName.callServiceCard <DetailCardCompontent v-else-if="
" item.toolCall.componentName ===
:toolCall="item.toolCall" CompName.pictureAndCommodityCard
/> " :toolCall="item.toolCall" />
<Feedback <AddCarCrad v-else-if="
v-else-if=" item.toolCall.componentName === CompName.enterLicensePlateCard
item.toolCall.componentName === CompName.feedbackCard " :toolCall="item.toolCall" />
"
: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>
<template #footer> <template #footer>
<!-- 这个是底部 --> <!-- 这个是底部 -->
<AttachListComponent <AttachListComponent v-if="item.question" :question="item.question" />
v-if="item.question"
:question="item.question"
/>
</template> </template>
</ChatCardAI> </ChatCardAI>
</template> </template>
@@ -85,21 +48,15 @@
<template v-else> <template v-else>
<ChatCardOther class="flex flex-justify-center" :text="item.msg"> <ChatCardOther class="flex flex-justify-center" :text="item.msg">
<ActivityListComponent <ActivityListComponent v-if="
v-if=" mainPageDataModel.activityList &&
mainPageDataModel.activityList && mainPageDataModel.activityList.length > 0
mainPageDataModel.activityList.length > 0 " :activityList="mainPageDataModel.activityList" />
"
:activityList="mainPageDataModel.activityList"
/>
<RecommendPostsComponent <RecommendPostsComponent v-if="
v-if=" mainPageDataModel.recommendTheme &&
mainPageDataModel.recommendTheme && mainPageDataModel.recommendTheme.length > 0
mainPageDataModel.recommendTheme.length > 0 " :recommendThemeList="mainPageDataModel.recommendTheme" />
"
:recommendThemeList="mainPageDataModel.recommendTheme"
/>
</ChatCardOther> </ChatCardOther>
</template> </template>
</view> </view>
@@ -108,17 +65,9 @@
<!-- 输入框区域 --> <!-- 输入框区域 -->
<view class="pb-safe-area"> <view class="pb-safe-area">
<ChatQuickAccess /> <ChatQuickAccess />
<ChatInputArea <ChatInputArea ref="inputAreaRef" v-model="inputMessage" :holdKeyboard="holdKeyboard"
ref="inputAreaRef" :is-session-active="isSessionActive" :stop-request="stopRequest" @send="sendMessageAction"
v-model="inputMessage" @noHideKeyboard="handleNoHideKeyboard" @keyboardShow="handleKeyboardShow" @keyboardHide="handleKeyboardHide" />
:holdKeyboard="holdKeyboard"
:is-session-active="isSessionActive"
:stop-request="stopRequest"
@send="sendMessageAction"
@noHideKeyboard="handleNoHideKeyboard"
@keyboardShow="handleKeyboardShow"
@keyboardHide="handleKeyboardHide"
/>
</view> </view>
</view> </view>
</template> </template>
@@ -159,6 +108,7 @@ import WebSocketManager from "@/utils/WebSocketManager";
import { ThrottleUtils, IdUtils } from "@/utils"; import { ThrottleUtils, IdUtils } from "@/utils";
import { checkToken } from "@/hooks/useGoLogin"; import { checkToken } from "@/hooks/useGoLogin";
import { useAppStore } from "@/store"; import { useAppStore } from "@/store";
import { getStorageSyncToken } from "@/constant/token";
const appStore = useAppStore(); const appStore = useAppStore();
/// 导航栏相关 /// 导航栏相关
@@ -242,7 +192,7 @@ const handleScroll = ThrottleUtils.createThrottle(({ detail }) => {
}, 50); }, 50);
// 处理滚动到底部事件 // 处理滚动到底部事件
const handleScrollToLower = () => {}; const handleScrollToLower = () => { };
// 滚动到底部 - 优化版本,确保打字机效果始终可见 // 滚动到底部 - 优化版本,确保打字机效果始终可见
const scrollToBottom = () => { const scrollToBottom = () => {
@@ -346,7 +296,7 @@ onLoad(() => {
// token存在初始化数据 // token存在初始化数据
const initHandler = () => { const initHandler = () => {
console.log("initHandler"); console.log("initHandler");
const token = uni.getStorageSync("token"); const token = getStorageSyncToken();
if (!token) return; if (!token) return;
loadRecentConversation(); loadRecentConversation();
@@ -407,14 +357,14 @@ const getMainPageData = async () => {
/// =============对话↓================ /// =============对话↓================
// 初始化WebSocket // 初始化WebSocket
const initWebSocket = () => { const initWebSocket = async () => {
// 清理旧实例 // 清理旧实例
if (webSocketManager) { if (webSocketManager) {
webSocketManager.destroy(); webSocketManager.destroy();
} }
// 使用配置的WebSocket服务器地址 // 使用配置的WebSocket服务器地址
const token = uni.getStorageSync("token"); const token = getStorageSyncToken();
const wsUrl = `${appStore.serverConfig.wssUrl}?access_token=${token}`; const wsUrl = `${appStore.serverConfig.wssUrl}?access_token=${token}`;
// 初始化WebSocket管理器 // 初始化WebSocket管理器
@@ -426,9 +376,10 @@ const initWebSocket = () => {
// 连接成功回调 // 连接成功回调
onOpen: (event) => { onOpen: (event) => {
console.log("WebSocket连接成功");
// 重置会话状态 // 重置会话状态
webSocketConnectStatus = true; webSocketConnectStatus = true;
isSessionActive.value = true; isSessionActive.value = false; // 连接成功时重置会话状态,避免影响新消息发送
}, },
// 连接断开回调 // 连接断开回调
@@ -441,9 +392,9 @@ const initWebSocket = () => {
// 错误回调 // 错误回调
onError: (error) => { onError: (error) => {
console.error("WebSocket错误:", error);
webSocketConnectStatus = false; webSocketConnectStatus = false;
isSessionActive.value = false; isSessionActive.value = false;
console.error("WebSocket错误:", error);
}, },
// 消息回调 // 消息回调
@@ -458,21 +409,24 @@ const initWebSocket = () => {
getAgentId: () => agentId.value, getAgentId: () => agentId.value,
}); });
// 初始化连接 try {
webSocketManager // 初始化连接
.connect() await webSocketManager.connect();
.then(() => { console.log("WebSocket连接初始化成功");
webSocketConnectStatus = true; webSocketConnectStatus = true;
}) return true;
.catch((error) => { } catch (error) {
console.error("WebSocket连接失败:", error); console.error("WebSocket连接失败:", error);
}); webSocketConnectStatus = false;
return false;
}
}; };
// 处理WebSocket消息 // 处理WebSocket消息
const handleWebSocketMessage = (data) => { const handleWebSocketMessage = (data) => {
const aiMsgIndex = chatMsgList.value.length - 1; const aiMsgIndex = chatMsgList.value.length - 1;
if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) { if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) {
console.error("处理WebSocket消息时找不到对应的AI消息项");
return; return;
} }
@@ -518,7 +472,10 @@ const handleWebSocketMessage = (data) => {
}; };
// 重置消息状态 // 重置消息状态
const resetMessageState = () => {}; const resetMessageState = () => {
// 重置当前会话消息ID
currentSessionMessageId = null;
};
// 初始化数据 首次数据加载的时候 // 初始化数据 首次数据加载的时候
const initData = () => { const initData = () => {
@@ -536,12 +493,39 @@ const sendMessage = async (message, isInstruct = false) => {
await checkToken(); await checkToken();
// 检查WebSocket连接状态如果未连接尝试重新连接
if (!webSocketConnectStatus) { if (!webSocketConnectStatus) {
uni.showToast({ console.log("WebSocket未连接尝试重新连接...");
title: "当前网络异常,请稍后重试", // 显示加载提示
icon: "none", uni.showLoading({
title: "正在连接服务器...",
}); });
return;
// 尝试重新初始化WebSocket连接
try {
await initWebSocket();
// 等待短暂时间确保连接建立
await new Promise(resolve => setTimeout(resolve, 1000));
// 检查连接是否成功建立
if (!webSocketConnectStatus) {
uni.hideLoading();
uni.showToast({
title: "连接服务器失败,请稍后重试",
icon: "none",
});
return;
}
uni.hideLoading();
} catch (error) {
console.error("重新连接WebSocket失败:", error);
uni.hideLoading();
uni.showToast({
title: "连接服务器失败,请稍后重试",
icon: "none",
});
return;
}
} }
if (isSessionActive.value) { if (isSessionActive.value) {
@@ -563,6 +547,8 @@ const sendMessage = async (message, isInstruct = false) => {
}; };
chatMsgList.value.push(newMsg); chatMsgList.value.push(newMsg);
inputMessage.value = ""; inputMessage.value = "";
// 发送消息后滚动到底部
setTimeoutScrollToBottom();
sendChat(message, isInstruct); sendChat(message, isInstruct);
console.log("发送的新消息:", JSON.stringify(newMsg)); console.log("发送的新消息:", JSON.stringify(newMsg));
}; };
@@ -578,9 +564,11 @@ const sendWebSocketMessage = (messageType, messageContent, options = {}) => {
}; };
try { try {
webSocketManager.sendMessage(args); // 直接调用webSocketManagersendMessage方法,利用其内部的消息队列机制
// 即使当前连接断开,消息也会被加入队列,等待连接恢复后发送
const result = webSocketManager.sendMessage(args);
console.log(`WebSocket消息已发送 [类型:${messageType}]:`, args); console.log(`WebSocket消息已发送 [类型:${messageType}]:`, args);
return true; return result;
} catch (error) { } catch (error) {
console.error("发送WebSocket消息失败:", error); console.error("发送WebSocket消息失败:", error);
isSessionActive.value = false; isSessionActive.value = false;
@@ -590,9 +578,26 @@ const sendWebSocketMessage = (messageType, messageContent, options = {}) => {
// 发送获取AI聊天消息 // 发送获取AI聊天消息
const sendChat = (message, isInstruct = false) => { const sendChat = (message, isInstruct = false) => {
if (!webSocketManager || !webSocketManager.isConnected()) { // 检查WebSocket管理器是否存在如果不存在尝试重新初始化
console.error("WebSocket未连接"); if (!webSocketManager) {
isSessionActive.value = false; 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; return;
} }
@@ -615,6 +620,8 @@ const sendChat = (message, isInstruct = false) => {
}, },
}; };
chatMsgList.value.push(aiMsg); chatMsgList.value.push(aiMsg);
// 添加AI消息后滚动到底部
setTimeoutScrollToBottom();
const aiMsgIndex = chatMsgList.value.length - 1; const aiMsgIndex = chatMsgList.value.length - 1;
// 发送消息 // 发送消息
@@ -678,6 +685,7 @@ const resetConfig = () => {
// 重置消息状态 // 重置消息状态
resetMessageState(); resetMessageState();
isSessionActive.value = false;
// 清理定时器 // 清理定时器
if (holdKeyboardTimer.value) { if (holdKeyboardTimer.value) {

View File

@@ -17,17 +17,9 @@
<view class="login-agreement flex flex-items-center"> <view class="login-agreement flex flex-items-center">
<CheckBox v-model="isAgree"> <CheckBox v-model="isAgree">
<text class="font-size-12 color-525866">我已阅读并同意</text> <text class="font-size-12 color-525866">我已阅读并同意</text>
<text <text class="font-size-12 color-2D91FF ml-4 mr-4" @click.stop="handleAgreeClick('service')">服务协议</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-525866"></text>
<text <text class="font-size-12 color-2D91FF ml-4 mr-4" @click.stop="handleAgreeClick('privacy')">隐私协议</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">\n</text>
<text class="font-size-12 color-525866 ml-30">授权与账号关联操作</text> <text class="font-size-12 color-525866 ml-30">授权与账号关联操作</text>
</CheckBox> </CheckBox>
@@ -37,49 +29,32 @@
<view class="login-btn-area"> <view class="login-btn-area">
<!-- 同意隐私协议并获取手机号按钮 --> <!-- 同意隐私协议并获取手机号按钮 -->
<button <button class="login-btn" type="primary" :open-type="needWxLogin ? 'getPhoneNumber' : ''"
v-if="!isAgree" @getphonenumber="getPhoneNumber" @click="handleAgreeAndGetPhone">
class="login-btn"
type="primary"
@click="handleAgreeAndGetPhone"
>
手机号快捷登录
</button>
<button
v-if="isAgree && !appStore.tokenExpired"
class="login-btn"
type="primary"
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
>
手机号快捷登录 手机号快捷登录
</button> </button>
</view> </view>
<AgreePopup <AgreePopup ref="agreePopup" :visible="visible" :agreement="computedAgreement" @close="visible = false" />
ref="agreePopup"
:visible="visible"
:agreement="computedAgreement"
@close="visible = false"
/>
</view> </view>
</template> </template>
<script setup> <script setup>
import { onShow } from "@dcloudio/uni-app";
import { ref, computed } from "vue"; import { ref, computed } from "vue";
import { import {
getServiceAgreement, getServiceAgreement,
getPrivacyAgreement, getPrivacyAgreement,
checkUserPhone
} from "@/request/api/LoginApi"; } 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 CheckBox from "@/components/CheckBox/index.vue";
import AgreePopup from "./components/AgreePopup/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 { getCurrentConfig } from "@/constant/base";
import { useAppStore } from "@/store"; import { getStorageSyncToken } from "@/constant/token";
const appStore = useAppStore();
const needWxLogin = ref(false);
const isAgree = ref(false); const isAgree = ref(false);
const visible = ref(false); const visible = ref(false);
const serviceAgreement = ref(""); const serviceAgreement = ref("");
@@ -90,6 +65,11 @@ const logo = computed(() => getCurrentConfig().logo);
// 同意隐私协议并获取手机号 // 同意隐私协议并获取手机号
const handleAgreeAndGetPhone = () => { const handleAgreeAndGetPhone = () => {
// 如果需要微信登录,直接返回
if (needWxLogin.value) {
return;
}
if (!isAgree.value) { if (!isAgree.value) {
uni.showToast({ uni.showToast({
title: "请先同意服务协议和隐私协议", title: "请先同意服务协议和隐私协议",
@@ -97,6 +77,8 @@ const handleAgreeAndGetPhone = () => {
}); });
return; return;
} }
refreshToken().then(() => goBack());
}; };
const getPhoneNumber = (e) => { const getPhoneNumber = (e) => {
@@ -108,7 +90,7 @@ const getPhoneNumber = (e) => {
}); });
goBack(); goBack();
}) })
.catch(() => {}); .catch(() => { });
}; };
// 处理同意协议点击事件 // 处理同意协议点击事件
@@ -141,10 +123,24 @@ const getPrivacyAgreementData = async () => {
}; };
getPrivacyAgreementData(); getPrivacyAgreementData();
// 页面显示时刷新token
onShow(async () => {
const token = getStorageSyncToken();
if (token) {
const res = await checkUserPhone();
needWxLogin.value = res.data;
} else {
needWxLogin.value = true;
}
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "./styles/index.scss"; @import "./styles/index.scss";
@font-face { @font-face {
font-family: znicons; font-family: znicons;
src: url("@/static/fonts/znicons.ttf"); src: url("@/static/fonts/znicons.ttf");

View File

@@ -1,5 +1,7 @@
import { goLogin } from "@/hooks/useGoLogin"; import { goLogin } from "@/hooks/useGoLogin";
import { useAppStore } from "@/store"; import { useAppStore } from "@/store";
import { getStorageSyncToken } from "@/constant/token";
import { removeStorageSyncToken } from "@/constant/token";
/// 请求流式数据的API /// 请求流式数据的API
const API = "/agent/assistant/chat"; const API = "/agent/assistant/chat";
@@ -72,7 +74,7 @@ const stopAbortTask = () => {
const agentChatStream = (params, onChunk) => { const agentChatStream = (params, onChunk) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const token = uni.getStorageSync("token"); const token = getStorageSyncToken();
const requestId = Date.now().toString(); // 生成唯一请求ID const requestId = Date.now().toString(); // 生成唯一请求ID
// 重置状态 // 重置状态
@@ -130,7 +132,7 @@ const agentChatStream = (params, onChunk) => {
res.statusCode res.statusCode
); );
if (res.statusCode === 424) { if (res.statusCode === 424) {
uni.setStorageSync("token", ""); removeStorageSyncToken();
goLogin(); goLogin();
} }
if (onChunk) { if (onChunk) {
@@ -144,8 +146,7 @@ const agentChatStream = (params, onChunk) => {
} }
} else { } else {
console.log( console.log(
`❌ 请求 [${requestId}] ${ `❌ 请求 [${requestId}] ${isAborted ? "已终止" : "已过期"
isAborted ? "已终止" : "已过期"
}忽略complete回调` }忽略complete回调`
); );
} }
@@ -240,7 +241,7 @@ const weAtob = (string) => {
r2, r2,
i = 0; i = 0;
for (; i < string.length; ) { for (; i < string.length;) {
bitmap = bitmap =
(b64.indexOf(string.charAt(i++)) << 18) | (b64.indexOf(string.charAt(i++)) << 18) |
(b64.indexOf(string.charAt(i++)) << 12) | (b64.indexOf(string.charAt(i++)) << 12) |

View File

@@ -1,3 +1,4 @@
import { removeStorageSyncToken } from "@/constant/token";
import request from "../base/request"; import request from "../base/request";
const wxLogin = (args) => { const wxLogin = (args) => {
@@ -8,7 +9,7 @@ const wxLogin = (args) => {
}, },
}; };
uni.setStorageSync("token", ""); removeStorageSyncToken();
return request.post("/auth/oauth2/token", args, config); return request.post("/auth/oauth2/token", args, config);
}; };

View File

@@ -1,10 +1,11 @@
import { getCurrentConfig } from "@/constant/base"; import { getCurrentConfig } from "@/constant/base";
import { useAppStore } from "@/store"; import { useAppStore } from "@/store";
import { getStorageSyncToken } from "@/constant/token";
export const updateImageFile = (file) => { export const updateImageFile = (file) => {
const { serverConfig } = useAppStore(); const { serverConfig } = useAppStore();
const url = serverConfig.baseUrl + "/hotelBiz/hotBizCommon/upload"; const url = serverConfig.baseUrl + "/hotelBiz/hotBizCommon/upload";
const token = uni.getStorageSync("token"); const token = getStorageSyncToken();
const clientId = getCurrentConfig().clientId; const clientId = getCurrentConfig().clientId;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@@ -3,14 +3,11 @@ import { isProd } from "@/constant/base";
import { useAppStore } from "@/store"; import { useAppStore } from "@/store";
// 获取服务地址 // 获取服务地址
const getEvnUrl = (args) => { const getEvnUrl = async (args) => {
if (isProd) { const res = await request.post("https://biz.nianxx.cn/hotelBiz/mainScene/getServiceUrl", args)
if (res && res.code == 0 && res.data) {
const appStore = useAppStore(); const appStore = useAppStore();
request appStore.setServerConfig(res.data);
.post("https://biz.nianxx.cn/hotelBiz/mainScene/getServiceUrl", args)
.then(({ data }) => {
appStore.setServerConfig(data);
});
} }
}; };

View File

@@ -2,6 +2,7 @@ import { goLogin } from "../../hooks/useGoLogin";
import { getCurrentConfig } from "@/constant/base"; import { getCurrentConfig } from "@/constant/base";
import { useAppStore } from "@/store"; import { useAppStore } from "@/store";
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant"; import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
import { getStorageSyncToken } from "@/constant/token";
const clientId = getCurrentConfig().clientId; const clientId = getCurrentConfig().clientId;
const defaultConfig = { const defaultConfig = {
@@ -19,7 +20,7 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
url = appStore.serverConfig?.baseUrl + url; url = appStore.serverConfig?.baseUrl + url;
} }
// 动态获取 token // 动态获取 token
const token = uni.getStorageSync("token"); const token = getStorageSyncToken();
let header = { let header = {
...defaultConfig.header, ...defaultConfig.header,
@@ -58,9 +59,9 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
resolve(res.data); resolve(res.data);
if (res.statusCode && res.statusCode === 424) { if (res.statusCode && res.statusCode === 424) {
console.log("424错误重新登录"); console.log("424错误重新登录");
uni.setStorageSync("token", ""); // removeStorageSyncToken();
uni.$emit(NOTICE_EVENT_LOGOUT); uni.$emit(NOTICE_EVENT_LOGOUT);
goLogin(); // goLogin();
} }
}, },
fail: (err) => { fail: (err) => {

View File

@@ -3,7 +3,9 @@ export default {
app.mixin({ app.mixin({
onLoad() { onLoad() {
const page = getCurrentPages().pop(); 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({ uni.showShareMenu({
withShareTicket: true, withShareTicket: true,
menus: ["shareAppMessage", "shareTimeline"], menus: ["shareAppMessage", "shareTimeline"],