Compare commits
15 Commits
09452bf600
...
fix-109
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e18c99161 | ||
|
|
6745e36a79 | ||
|
|
56ad450731 | ||
|
|
ea56695099 | ||
|
|
dfadb06934 | ||
|
|
f027685072 | ||
|
|
b7fbe99cd0 | ||
| 5027abc239 | |||
| a2ff08f090 | |||
| 37192b0ba4 | |||
| 8be21f8307 | |||
| 296781c506 | |||
| 9eb1dc6747 | |||
| 364e47b641 | |||
| a3c363cbc9 |
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"appid": "wx5e79df5996572539",
|
||||
"appid": "wx23f86d809ae80259",
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "3.8.10",
|
||||
"packOptions": {
|
||||
|
||||
12
src/App.vue
12
src/App.vue
@@ -2,10 +2,16 @@
|
||||
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import { getEvnUrl } from "@/request/api/config";
|
||||
import { refreshToken } from "@/hooks/useGoLogin";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
|
||||
onLaunch(() => {
|
||||
getEvnUrl({ versionValue: "1.0.1" });
|
||||
refreshToken();
|
||||
onLaunch(async () => {
|
||||
await getEvnUrl({ versionValue: "1.0.3" });
|
||||
|
||||
const token = getAccessToken();
|
||||
|
||||
if (token) {
|
||||
refreshToken();
|
||||
}
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
35
src/constant/token.js
Normal file
35
src/constant/token.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { currentClientType } from "@/constant/base";
|
||||
|
||||
// 存储在本地的认证 token 键名
|
||||
const CLIENT_TYPE = currentClientType();
|
||||
const ACCESS_TOKEN = `${CLIENT_TYPE}_ACCESS_TOKEN`;
|
||||
const REFRESH_ACCESS_TOKEN = `${CLIENT_TYPE}_REFRESH_ACCESS_TOKEN`;
|
||||
|
||||
// 设置本地存储的认证 token
|
||||
export const setAccessToken = (token) => {
|
||||
return uni.setStorageSync(ACCESS_TOKEN, token);
|
||||
};
|
||||
|
||||
// 设置本地存储的刷新 token
|
||||
export const setRefreshToken = (token) => {
|
||||
return uni.setStorageSync(REFRESH_ACCESS_TOKEN, token);
|
||||
};
|
||||
|
||||
// 获取本地存储的刷新 token
|
||||
export const getRefreshToken = () => {
|
||||
return uni.getStorageSync(REFRESH_ACCESS_TOKEN);
|
||||
};
|
||||
|
||||
// 获取本地存储的认证 token
|
||||
export const getAccessToken = () => {
|
||||
return uni.getStorageSync(ACCESS_TOKEN);
|
||||
};
|
||||
|
||||
// 移除本地存储的认证 token
|
||||
export const removeAccessToken = () => {
|
||||
return uni.removeStorageSync(ACCESS_TOKEN);
|
||||
};
|
||||
|
||||
export const removeRefreshToken = () => {
|
||||
return uni.removeStorageSync(REFRESH_ACCESS_TOKEN);
|
||||
};
|
||||
@@ -1,7 +1,8 @@
|
||||
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 { getAccessToken, setAccessToken } from "../constant/token";
|
||||
|
||||
// 跳转登录
|
||||
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
|
||||
@@ -21,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;
|
||||
@@ -47,7 +49,7 @@ export const onLogin = async (e) => {
|
||||
|
||||
// 检测token
|
||||
export const checkToken = () => {
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getAccessToken();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (!token) {
|
||||
@@ -60,31 +62,40 @@ export const checkToken = () => {
|
||||
};
|
||||
|
||||
// 刷新token
|
||||
export const refreshToken = () => {
|
||||
const token = uni.getStorageSync("token");
|
||||
export const refreshToken = (needLogin = false) => {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
const response = await wxLogin(params);
|
||||
|
||||
uni.login({
|
||||
provider: "weixin", //使用微信登录
|
||||
success: async ({ code }) => {
|
||||
console.log("refreshToken", code);
|
||||
const params = {
|
||||
openIdCode: [code],
|
||||
grant_type: "wechat",
|
||||
scope: "server",
|
||||
clientId: clientId,
|
||||
};
|
||||
console.log("获取到的微信授权params:", JSON.stringify(params));
|
||||
const response = await wxLogin(params);
|
||||
if (needLogin && response.access_token) {
|
||||
setAccessToken(response.access_token);
|
||||
}
|
||||
|
||||
if (response.access_token) {
|
||||
uni.setStorageSync("token", response.access_token);
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
}
|
||||
},
|
||||
if (response.access_token) {
|
||||
const checkRes = await checkUserPhone({
|
||||
token: response.access_token,
|
||||
});
|
||||
|
||||
if (checkRes.data) {
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@ app.$mount();
|
||||
import { createSSRApp } from "vue";
|
||||
import * as Pinia from "pinia";
|
||||
import { createUnistorage } from "pinia-plugin-unistorage";
|
||||
import noclick from "./utils/noclick";
|
||||
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App);
|
||||
@@ -25,7 +24,6 @@ export function createApp() {
|
||||
pinia.use(createUnistorage());
|
||||
app.use(pinia);
|
||||
app.use(share);
|
||||
app.use(noclick);
|
||||
|
||||
return {
|
||||
app,
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import {
|
||||
wxLogin,
|
||||
bindUserPhone,
|
||||
checkUserPhone,
|
||||
} from "../request/api/LoginApi";
|
||||
import { wxLogin, bindUserPhone } 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 { removeAccessToken, setAccessToken } from "../constant/token";
|
||||
|
||||
const loginAuth = (e) => {
|
||||
uni.setStorageSync("token", "");
|
||||
const appStore = useAppStore();
|
||||
removeAccessToken();
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const openIdCode = await getWeChatAuthCode(e);
|
||||
@@ -26,7 +21,9 @@ const loginAuth = (e) => {
|
||||
console.log("获取到的微信授权response:", response);
|
||||
|
||||
if (response.access_token) {
|
||||
uni.setStorageSync("token", response.access_token);
|
||||
console.log("进入条件");
|
||||
setAccessToken(response.access_token);
|
||||
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
resolve();
|
||||
@@ -45,9 +42,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
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
/>
|
||||
<text
|
||||
class="font-size-16 font-500 color-white"
|
||||
@click="$onMultipleClicks(() => 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,11 +55,39 @@ const count = computed({
|
||||
},
|
||||
});
|
||||
|
||||
const totalAmt = computed(() => {
|
||||
const { totalDays } = props.selectedDate;
|
||||
const { specificationPrice } = props.orderData;
|
||||
return count.value * Number(specificationPrice) * totalDays;
|
||||
watch(
|
||||
() => count.value,
|
||||
(newVal, oldVal) => {
|
||||
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>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
|
||||
<!-- 底部 -->
|
||||
<FooterSection
|
||||
v-if="Object.keys(orderData).length"
|
||||
v-model="quantity"
|
||||
:selectedDate="selectedDate"
|
||||
:orderData="orderData"
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
'bg-2D91FF': ['1', '2', '3', '4', '5', '6'].includes(statusCode),
|
||||
},
|
||||
]"
|
||||
@click="$onmultipleClicks(() => handleButtonClick(orderData))"
|
||||
@click="handleButtonClick(orderData)"
|
||||
>
|
||||
{{ buttonText }}
|
||||
</button>
|
||||
@@ -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,7 +65,7 @@ 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)) {
|
||||
@@ -130,7 +131,7 @@ const handleButtonClick = async (orderData) => {
|
||||
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>
|
||||
@@ -64,24 +48,22 @@ const props = defineProps({
|
||||
},
|
||||
selectedDate: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
default: () => { },
|
||||
},
|
||||
});
|
||||
|
||||
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">
|
||||
|
||||
@@ -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>
|
||||
@@ -159,6 +108,7 @@ import WebSocketManager from "@/utils/WebSocketManager";
|
||||
import { ThrottleUtils, IdUtils } from "@/utils";
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
|
||||
const appStore = useAppStore();
|
||||
/// 导航栏相关
|
||||
@@ -242,7 +192,7 @@ const handleScroll = ThrottleUtils.createThrottle(({ detail }) => {
|
||||
}, 50);
|
||||
|
||||
// 处理滚动到底部事件
|
||||
const handleScrollToLower = () => {};
|
||||
const handleScrollToLower = () => { };
|
||||
|
||||
// 滚动到底部 - 优化版本,确保打字机效果始终可见
|
||||
const scrollToBottom = () => {
|
||||
@@ -346,7 +296,7 @@ onLoad(() => {
|
||||
// token存在,初始化数据
|
||||
const initHandler = () => {
|
||||
console.log("initHandler");
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getAccessToken();
|
||||
|
||||
if (!token) return;
|
||||
loadRecentConversation();
|
||||
@@ -414,7 +364,7 @@ const initWebSocket = async () => {
|
||||
}
|
||||
|
||||
// 使用配置的WebSocket服务器地址
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getAccessToken();
|
||||
const wsUrl = `${appStore.serverConfig.wssUrl}?access_token=${token}`;
|
||||
|
||||
// 初始化WebSocket管理器
|
||||
@@ -473,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 = () => {
|
||||
@@ -550,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();
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
<template>
|
||||
<view
|
||||
class="quick-access flex flex-row ml-12 pt-8 pb-8 scroll-x whitespace-nowrap"
|
||||
>
|
||||
<view
|
||||
class="item border-box rounded-50 flex flex-row items-center"
|
||||
v-for="(item, index) in itemList"
|
||||
:key="index"
|
||||
@click="sendReply(item)"
|
||||
>
|
||||
<view class="quick-access flex flex-row ml-12 pt-8 pb-8 scroll-x whitespace-nowrap">
|
||||
<view class="item border-box rounded-50 flex flex-row items-center" v-for="(item, index) in itemList" :key="index"
|
||||
@click="sendReply(item)">
|
||||
<view class="flex items-center justify-center">
|
||||
<image v-if="item.icon" class="icon" :src="item.icon" />
|
||||
<text class="font-size-14 color-2D91FF line-height-20">
|
||||
@@ -22,6 +16,7 @@
|
||||
import { ref } from "vue";
|
||||
import { Command } from "@/model/ChatModel";
|
||||
import { SEND_MESSAGE_COMMAND_TYPE } from "@/constant/constant";
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
|
||||
const itemList = ref([
|
||||
{
|
||||
@@ -55,7 +50,9 @@ const sendReply = (item) => {
|
||||
|
||||
// 快速预定
|
||||
if (item.type === Command.quickBooking) {
|
||||
uni.navigateTo({ url: "/pages-quick/list" });
|
||||
checkToken().then(() => {
|
||||
uni.navigateTo({ url: "/pages-quick/list" });
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,12 @@
|
||||
<uni-popup ref="popup" type="bottom" :safe-area="false">
|
||||
<view class="popup-content border-box pt-12 pl-12 pr-12">
|
||||
<view class="header flex flex-items-center pb-12">
|
||||
<view
|
||||
class="title flex-full text-center font-size-17 color-000 font-500 ml-24"
|
||||
>更多服务</view
|
||||
>
|
||||
<view class="title flex-full text-center font-size-17 color-000 font-500 ml-24">更多服务</view>
|
||||
<uni-icons type="close" size="24" color="#CACFD8" @click="close" />
|
||||
</view>
|
||||
|
||||
<view class="list bg-white border-box pl-20 pr-20">
|
||||
<view
|
||||
class="item border-box border-bottom pt-20 pb-20"
|
||||
v-for="(item, index) in list"
|
||||
:key="index"
|
||||
>
|
||||
<view class="item border-box border-bottom pt-20 pb-20" v-for="(item, index) in list" :key="index">
|
||||
<view class="flex flex-items-center flex-justify-center">
|
||||
<image v-if="item.icon" class="left" :src="item.icon" />
|
||||
<view class="center flex-full">
|
||||
@@ -25,10 +18,7 @@
|
||||
{{ item.content }}
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
class="right border-box font-size-12 color-white line-height-16"
|
||||
@click="handleClick(item)"
|
||||
>
|
||||
<view class="right border-box font-size-12 color-white line-height-16" @click="handleClick(item)">
|
||||
{{ item.btnText }}
|
||||
</view>
|
||||
</view>
|
||||
@@ -42,6 +32,7 @@
|
||||
import { ref } from "vue";
|
||||
import { Command } from "@/model/ChatModel";
|
||||
import { SEND_MESSAGE_COMMAND_TYPE } from "@/constant/constant";
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
|
||||
const popup = ref(null);
|
||||
|
||||
@@ -100,7 +91,10 @@ const handleClick = (item) => {
|
||||
close();
|
||||
|
||||
if (item.path) {
|
||||
uni.navigateTo({ url: item.path });
|
||||
checkToken().then(() => {
|
||||
uni.navigateTo({ url: item.path });
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,49 +29,30 @@
|
||||
<view class="login-btn-area">
|
||||
<!-- 同意隐私协议并获取手机号按钮 -->
|
||||
|
||||
<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"
|
||||
@getphonenumber="getPhoneNumber"
|
||||
>
|
||||
<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>
|
||||
|
||||
<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 { zniconsMap } from "@/static/fonts/znicons";
|
||||
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 +63,11 @@ const logo = computed(() => getCurrentConfig().logo);
|
||||
|
||||
// 同意隐私协议并获取手机号
|
||||
const handleAgreeAndGetPhone = () => {
|
||||
// 如果需要微信登录,直接返回
|
||||
if (needWxLogin.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAgree.value) {
|
||||
uni.showToast({
|
||||
title: "请先同意服务协议和隐私协议",
|
||||
@@ -97,6 +75,8 @@ const handleAgreeAndGetPhone = () => {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
refreshToken(true).then(() => goBack());
|
||||
};
|
||||
|
||||
const getPhoneNumber = (e) => {
|
||||
@@ -108,7 +88,7 @@ const getPhoneNumber = (e) => {
|
||||
});
|
||||
goBack();
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch(() => { });
|
||||
};
|
||||
|
||||
// 处理同意协议点击事件
|
||||
@@ -141,10 +121,18 @@ const getPrivacyAgreementData = async () => {
|
||||
};
|
||||
|
||||
getPrivacyAgreementData();
|
||||
|
||||
// 页面显示时刷新token
|
||||
onShow(async () => {
|
||||
const res = await refreshToken();
|
||||
|
||||
needWxLogin.value = res;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import "./styles/index.scss";
|
||||
|
||||
@font-face {
|
||||
font-family: znicons;
|
||||
src: url("@/static/fonts/znicons.ttf");
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { goLogin } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
import { removeAccessToken } 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 = getAccessToken();
|
||||
const requestId = Date.now().toString(); // 生成唯一请求ID
|
||||
|
||||
// 重置状态
|
||||
@@ -130,7 +132,7 @@ const agentChatStream = (params, onChunk) => {
|
||||
res.statusCode
|
||||
);
|
||||
if (res.statusCode === 424) {
|
||||
uni.setStorageSync("token", "");
|
||||
removeAccessToken();
|
||||
goLogin();
|
||||
}
|
||||
if (onChunk) {
|
||||
|
||||
@@ -1,48 +1,49 @@
|
||||
import { removeAccessToken } from "@/constant/token";
|
||||
import request from "../base/request";
|
||||
|
||||
const wxLogin = (args) => {
|
||||
const config = {
|
||||
header: {
|
||||
Authorization: "Basic Y3VzdG9tOmN1c3RvbQ==", // 可在此动态设置 token
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
};
|
||||
const config = {
|
||||
header: {
|
||||
Authorization: "Basic Y3VzdG9tOmN1c3RvbQ==", // 可在此动态设置 token
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
};
|
||||
|
||||
uni.setStorageSync("token", "");
|
||||
removeAccessToken();
|
||||
|
||||
return request.post("/auth/oauth2/token", args, config);
|
||||
return request.post("/auth/oauth2/token", args, config);
|
||||
};
|
||||
|
||||
// 绑定用户手机号
|
||||
const bindUserPhone = (args) => {
|
||||
return request.post("/hotelBiz/user/bindUserPhone", args);
|
||||
return request.post("/hotelBiz/user/bindUserPhone", args);
|
||||
};
|
||||
|
||||
// 检测用户是否绑定手机号
|
||||
const checkUserPhone = (args) => {
|
||||
return request.get("/hotelBiz/user/checkUserHasBindPhone", args);
|
||||
const checkUserPhone = (config) => {
|
||||
return request.get("/hotelBiz/user/checkUserHasBindPhone", {}, config);
|
||||
};
|
||||
|
||||
// 获取登录用户手机号
|
||||
const getLoginUserPhone = (args) => {
|
||||
return request.get("/hotelBiz/user/getLoginUserPhone", args);
|
||||
return request.get("/hotelBiz/user/getLoginUserPhone", args);
|
||||
};
|
||||
|
||||
// 获取服务协议
|
||||
const getServiceAgreement = (args) => {
|
||||
return request.get("/hotelBiz/mainScene/serviceAgreement", args);
|
||||
return request.get("/hotelBiz/mainScene/serviceAgreement", args);
|
||||
};
|
||||
|
||||
// 获取隐私协议
|
||||
const getPrivacyAgreement = (args) => {
|
||||
return request.get("/hotelBiz/mainScene/privacyPolicy", args);
|
||||
return request.get("/hotelBiz/mainScene/privacyPolicy", args);
|
||||
};
|
||||
|
||||
export {
|
||||
wxLogin,
|
||||
bindUserPhone,
|
||||
checkUserPhone,
|
||||
getLoginUserPhone,
|
||||
getServiceAgreement,
|
||||
getPrivacyAgreement,
|
||||
wxLogin,
|
||||
bindUserPhone,
|
||||
checkUserPhone,
|
||||
getLoginUserPhone,
|
||||
getServiceAgreement,
|
||||
getPrivacyAgreement,
|
||||
};
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
|
||||
export const updateImageFile = (file) => {
|
||||
const { serverConfig } = useAppStore();
|
||||
const url = serverConfig.baseUrl + "/hotelBiz/hotBizCommon/upload";
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = getAccessToken();
|
||||
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 { getAccessToken } 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 = getAccessToken();
|
||||
|
||||
let header = {
|
||||
...defaultConfig.header,
|
||||
@@ -30,8 +31,8 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
if (customConfig.noToken) {
|
||||
delete header.Authorization;
|
||||
} else {
|
||||
if (token) {
|
||||
header.Authorization = `Bearer ${token}`;
|
||||
if (token || customConfig.token) {
|
||||
header.Authorization = `Bearer ${token || customConfig.token}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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", "");
|
||||
// removeAccessToken();
|
||||
uni.$emit(NOTICE_EVENT_LOGOUT);
|
||||
goLogin();
|
||||
// goLogin();
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// 防止处理多次点击
|
||||
// methods是需要点击后需要执行的函数, info是点击需要传的参数
|
||||
export function noMultipleClicks(fn, info, delay = 2000) {
|
||||
if (typeof fn !== 'function') return;
|
||||
// this 会是组件实例(因为通过 globalProperties 调用时 Vue 会把组件实例作为上下文)
|
||||
const ctx = this || {};
|
||||
if (!ctx.__noClickMap) ctx.__noClickMap = new WeakMap();
|
||||
|
||||
const map = ctx.__noClickMap;
|
||||
if (map.get(fn)) {
|
||||
console.log('请勿重复点击:', fn.name);
|
||||
return;
|
||||
}
|
||||
|
||||
map.set(fn, true);
|
||||
// 保留组件上下文调用方法
|
||||
fn.call(ctx, info);
|
||||
|
||||
setTimeout(() => {
|
||||
map.set(fn, false);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
export default {
|
||||
install(app) {
|
||||
app.config.globalProperties.$noMultipleClicks = noMultipleClicks;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user