Compare commits
6 Commits
94ab8c5c04
...
V1.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ea6546f04 | |||
| f70920a25c | |||
| d666dce813 | |||
| 7aa8c72005 | |||
| 19b6b5b321 | |||
| f632e9c821 |
@@ -50,7 +50,13 @@
|
|||||||
{{ dateInfo.label }}
|
{{ dateInfo.label }}
|
||||||
</text>
|
</text>
|
||||||
<text class="date-number">{{ dateInfo.day }}</text>
|
<text class="date-number">{{ dateInfo.day }}</text>
|
||||||
<text class="date-price" v-if="dateInfo.price !== null && dateInfo.price !== undefined">¥{{ dateInfo.price }}</text>
|
<text
|
||||||
|
class="date-price"
|
||||||
|
v-if="
|
||||||
|
dateInfo.price !== null && dateInfo.price !== undefined
|
||||||
|
"
|
||||||
|
>¥{{ dateInfo.price }}</text
|
||||||
|
>
|
||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -253,7 +259,7 @@ const generateCalendarGrid = (year, month) => {
|
|||||||
// 填充日期
|
// 填充日期
|
||||||
for (let day = 1; day <= daysInMonth; day++) {
|
for (let day = 1; day <= daysInMonth; day++) {
|
||||||
const dateStr = `${year}-${String(month).padStart(2, "0")}-${String(
|
const dateStr = `${year}-${String(month).padStart(2, "0")}-${String(
|
||||||
day
|
day,
|
||||||
).padStart(2, "0")}`;
|
).padStart(2, "0")}`;
|
||||||
const priceItem = getPriceItem(dateStr);
|
const priceItem = getPriceItem(dateStr);
|
||||||
grid.push({
|
grid.push({
|
||||||
@@ -344,7 +350,11 @@ const getDateCellClass = (dateInfo) => {
|
|||||||
if (dateInfo.selected) classes.push("date-cell-selected");
|
if (dateInfo.selected) classes.push("date-cell-selected");
|
||||||
if (dateInfo.inRange) classes.push("date-cell-in-range");
|
if (dateInfo.inRange) classes.push("date-cell-in-range");
|
||||||
// 标注无价格但可选的日期(用于视觉区分)
|
// 标注无价格但可选的日期(用于视觉区分)
|
||||||
if (dateInfo.price === null || dateInfo.price === undefined || dateInfo.price === "-") {
|
if (
|
||||||
|
dateInfo.price === null ||
|
||||||
|
dateInfo.price === undefined ||
|
||||||
|
dateInfo.price === "-"
|
||||||
|
) {
|
||||||
classes.push("date-cell-no-price");
|
classes.push("date-cell-no-price");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,13 +414,19 @@ const handleRangeSelection = (dateInfo) => {
|
|||||||
if (!rangeStart.value || (rangeStart.value && rangeEnd.value)) {
|
if (!rangeStart.value || (rangeStart.value && rangeEnd.value)) {
|
||||||
// 开始新的范围选择:当作为价格区间选择器时,开始日必须有价格且有库存
|
// 开始新的范围选择:当作为价格区间选择器时,开始日必须有价格且有库存
|
||||||
if (props.rangeRequirePrice) {
|
if (props.rangeRequirePrice) {
|
||||||
const hasPrice = dateInfo.price !== null && dateInfo.price !== undefined && dateInfo.price !== "-";
|
const hasPrice =
|
||||||
|
dateInfo.price !== null &&
|
||||||
|
dateInfo.price !== undefined &&
|
||||||
|
dateInfo.price !== "-";
|
||||||
if (!hasPrice) {
|
if (!hasPrice) {
|
||||||
uni.showToast({ title: "所选日期不可预订,请重新选择", icon: "none" });
|
uni.showToast({ title: "所选日期不可预订,请重新选择", icon: "none" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (dateInfo.stock !== undefined && Number(dateInfo.stock) <= 0) {
|
if (dateInfo.stock !== undefined && Number(dateInfo.stock) <= 0) {
|
||||||
uni.showToast({ title: "所选日期库存不足,请选择其他日期", icon: "none" });
|
uni.showToast({
|
||||||
|
title: "所选日期库存不足,请选择其他日期",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -421,11 +437,16 @@ const handleRangeSelection = (dateInfo) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 否则为结束日期(完成选择)——结束日允许无价格(如为紧接有价日的下一天),但区间内的夜晚必须有价格
|
// 否则为结束日期(完成选择)
|
||||||
|
if (rangeStart.value === dateInfo.date) {
|
||||||
|
uni.showToast({ title: "离店日期不能与入住日期相同", icon: "none" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
rangeEnd.value = dateInfo.date;
|
rangeEnd.value = dateInfo.date;
|
||||||
isRangeSelecting.value = false;
|
isRangeSelecting.value = false;
|
||||||
|
|
||||||
// 允许选择相同日期,但确保开始日期不大于结束日期
|
// 确保开始日期不大于结束日期
|
||||||
if (new Date(rangeStart.value) > new Date(rangeEnd.value)) {
|
if (new Date(rangeStart.value) > new Date(rangeEnd.value)) {
|
||||||
[rangeStart.value, rangeEnd.value] = [rangeEnd.value, rangeStart.value];
|
[rangeStart.value, rangeEnd.value] = [rangeEnd.value, rangeStart.value];
|
||||||
}
|
}
|
||||||
@@ -433,7 +454,11 @@ const handleRangeSelection = (dateInfo) => {
|
|||||||
// 检查日期跨度是否超过28天
|
// 检查日期跨度是否超过28天
|
||||||
const daysBetween = calculateDaysBetween(rangeStart.value, rangeEnd.value);
|
const daysBetween = calculateDaysBetween(rangeStart.value, rangeEnd.value);
|
||||||
if (daysBetween > 28) {
|
if (daysBetween > 28) {
|
||||||
uni.showToast({ title: "预定时间不能超过28天", icon: "none", duration: 3000 });
|
uni.showToast({
|
||||||
|
title: "预定时间不能超过28天",
|
||||||
|
icon: "none",
|
||||||
|
duration: 3000,
|
||||||
|
});
|
||||||
rangeStart.value = null;
|
rangeStart.value = null;
|
||||||
rangeEnd.value = null;
|
rangeEnd.value = null;
|
||||||
isRangeSelecting.value = false;
|
isRangeSelecting.value = false;
|
||||||
@@ -443,9 +468,14 @@ const handleRangeSelection = (dateInfo) => {
|
|||||||
// 如果作为价格区间选择器,验证夜晚(不包含离店日)是否都有价格/库存
|
// 如果作为价格区间选择器,验证夜晚(不包含离店日)是否都有价格/库存
|
||||||
if (props.rangeRequirePrice) {
|
if (props.rangeRequirePrice) {
|
||||||
const nights = generateNightsRange(rangeStart.value, rangeEnd.value);
|
const nights = generateNightsRange(rangeStart.value, rangeEnd.value);
|
||||||
const missing = nights.find((d) => d.price === null || d.price === undefined || d.price === "-");
|
const missing = nights.find(
|
||||||
|
(d) => d.price === null || d.price === undefined || d.price === "-",
|
||||||
|
);
|
||||||
if (missing) {
|
if (missing) {
|
||||||
uni.showToast({ title: "所选区间包含无价格日期,请重新选择", icon: "none" });
|
uni.showToast({
|
||||||
|
title: "所选区间包含无价格日期,请重新选择",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
rangeStart.value = null;
|
rangeStart.value = null;
|
||||||
rangeEnd.value = null;
|
rangeEnd.value = null;
|
||||||
return;
|
return;
|
||||||
@@ -456,7 +486,10 @@ const handleRangeSelection = (dateInfo) => {
|
|||||||
return item && item.stock !== undefined && Number(item.stock) <= 0;
|
return item && item.stock !== undefined && Number(item.stock) <= 0;
|
||||||
});
|
});
|
||||||
if (badStock) {
|
if (badStock) {
|
||||||
uni.showToast({ title: "所选区间包含库存不足的日期,请重新选择", icon: "none" });
|
uni.showToast({
|
||||||
|
title: "所选区间包含库存不足的日期,请重新选择",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
rangeStart.value = null;
|
rangeStart.value = null;
|
||||||
rangeEnd.value = null;
|
rangeEnd.value = null;
|
||||||
return;
|
return;
|
||||||
@@ -551,7 +584,7 @@ watch(
|
|||||||
popup.value?.close();
|
popup.value?.close();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
// 生命周期钩子
|
// 生命周期钩子
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="bg-white rounded-12 overflow-hidden mb-12">
|
<view class="bg-white rounded-12 overflow-hidden mb-12">
|
||||||
<view
|
<view class="border-box font-size-16 font-500 color-000 line-height-24 p-12"
|
||||||
class="border-box font-size-16 font-500 color-000 line-height-24 p-12"
|
|
||||||
>使用日期</view
|
>使用日期</view
|
||||||
>
|
>
|
||||||
<view class="flex flex-items-center border-box ">
|
<view class="flex flex-items-center border-box">
|
||||||
<scroll-view class="date-scroll" scroll-x>
|
<scroll-view class="date-scroll" scroll-x>
|
||||||
<view class="date-list">
|
<view class="date-list">
|
||||||
<block v-for="(item) in dates" :key="item.date">
|
<block v-for="item in openDateRangeList" :key="item.date">
|
||||||
<view
|
<view
|
||||||
class="date-item"
|
class="date-item"
|
||||||
:class="{ selected: isSameDate(selectedDate, item.date) }"
|
:class="{ selected: isSameDate(selectedDate, item.date) }"
|
||||||
@click="onDateClick(item)"
|
@click="onDateClick(item)"
|
||||||
>
|
>
|
||||||
<view class="label font-size-12">{{ item.label }}</view>
|
<view class="label font-size-12">{{ item.weekDesc }}</view>
|
||||||
<view class="md font-size-16 font-600">{{ formatMD(item.date) }}</view>
|
<view class="md font-size-16 font-600">{{
|
||||||
<view class="status font-size-12">可订</view>
|
formatMD(item.date)
|
||||||
<view v-if="isSameDate(selectedDate, item.date)" class="check">✔</view>
|
}}</view>
|
||||||
|
<view class="status font-size-12">{{ item.canOrder }}</view>
|
||||||
|
<view v-if="isSameDate(selectedDate, item.date)" class="check"
|
||||||
|
>✔</view
|
||||||
|
>
|
||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
</view>
|
</view>
|
||||||
@@ -26,50 +29,35 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, watch } from 'vue';
|
import { ref, watch } from "vue";
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
selectedDate: { type: String, default: null },
|
selectedDate: { type: String, default: null },
|
||||||
days: { type: Number, default: 14 }
|
openDateRangeList: { type: Array, default: () => [] },
|
||||||
});
|
});
|
||||||
const emit = defineEmits(['update:selectedDate']);
|
const emit = defineEmits(["update:selectedDate"]);
|
||||||
|
|
||||||
const dates = ref([]);
|
|
||||||
const selectedDate = ref(props.selectedDate);
|
const selectedDate = ref(props.selectedDate);
|
||||||
|
|
||||||
watch(() => props.selectedDate, (v) => {
|
watch(
|
||||||
|
() => props.selectedDate,
|
||||||
|
(v) => {
|
||||||
selectedDate.value = v;
|
selectedDate.value = v;
|
||||||
});
|
},
|
||||||
|
);
|
||||||
const initDates = (days = props.days) => {
|
|
||||||
const arr = [];
|
|
||||||
const today = new Date();
|
|
||||||
for (let i = 0; i < days; i++) {
|
|
||||||
const d = new Date(today);
|
|
||||||
d.setDate(today.getDate() + i);
|
|
||||||
const iso = d.toISOString().slice(0, 10);
|
|
||||||
arr.push({ date: iso, day: i, disabled: false, label: getLabel(i, d) });
|
|
||||||
}
|
|
||||||
dates.value = arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getLabel = (i, d) => {
|
|
||||||
if (i === 0) return '今天';
|
|
||||||
if (i === 1) return '明天';
|
|
||||||
const week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
|
||||||
return week[d.getDay()];
|
|
||||||
}
|
|
||||||
|
|
||||||
const formatMD = (dateStr) => {
|
|
||||||
const d = new Date(dateStr);
|
|
||||||
const mm = String(d.getMonth() + 1).padStart(2, '0');
|
|
||||||
const dd = String(d.getDate()).padStart(2, '0');
|
|
||||||
return `${mm}-${dd}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSameDate = (a, b) => {
|
const isSameDate = (a, b) => {
|
||||||
if (!a || !b) return false;
|
if (!a || !b) return false;
|
||||||
return a === b;
|
return a === b;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// 格式化展示日期,将 2026-04-13 转换为 04-13
|
||||||
|
const formatMD = (dateStr) => {
|
||||||
|
if (!dateStr || typeof dateStr !== "string") return "";
|
||||||
|
const parts = dateStr.split("-");
|
||||||
|
if (parts.length >= 3) {
|
||||||
|
return `${parts[1]}-${parts[2]}`;
|
||||||
|
}
|
||||||
|
return dateStr;
|
||||||
|
};
|
||||||
|
|
||||||
const onDateClick = (item) => {
|
const onDateClick = (item) => {
|
||||||
const date = item.date;
|
const date = item.date;
|
||||||
@@ -78,9 +66,9 @@ const onDateClick = (item) => {
|
|||||||
} else {
|
} else {
|
||||||
selectedDate.value = date;
|
selectedDate.value = date;
|
||||||
}
|
}
|
||||||
emit('update:selectedDate', selectedDate.value);
|
console.log("selectedDate:", selectedDate.value);
|
||||||
}
|
emit("update:selectedDate", selectedDate.value);
|
||||||
onMounted(() => initDates());
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
@@ -16,7 +16,12 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<UseDateRange v-if="reservationEnabled" v-model:selectedDate="reservationDate"/>
|
<!-- 使用日期 -->
|
||||||
|
<UseDateRange
|
||||||
|
v-if="orderData.reservationEnabled"
|
||||||
|
:openDateRangeList="orderData.openDateRangeList"
|
||||||
|
v-model:selectedDate="reservationDate"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- 联系方式 -->
|
<!-- 联系方式 -->
|
||||||
<view class="bg-white rounded-12 overflow-hidden">
|
<view class="bg-white rounded-12 overflow-hidden">
|
||||||
@@ -57,9 +62,9 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
reservationEnabled: {
|
orderData: {
|
||||||
type: Boolean,
|
type: Object,
|
||||||
default: false,
|
default: () => ({}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
v-model="quantity"
|
v-model="quantity"
|
||||||
:userFormList="userFormList"
|
:userFormList="userFormList"
|
||||||
v-model:reservationDate="selectedReservationDate"
|
v-model:reservationDate="selectedReservationDate"
|
||||||
:reservationEnabled="orderData.reservationEnabled"
|
:orderData="orderData"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 酒店类型 -->
|
<!-- 酒店类型 -->
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<view class="order-detail-wrapper border-box flex-full overflow-hidden scroll-y">
|
<view class="order-detail-wrapper border-box flex-full overflow-hidden scroll-y">
|
||||||
<OrderStatusInfo :orderData="orderData" />
|
<OrderStatusInfo :orderData="orderData" />
|
||||||
|
|
||||||
<VoucherList v-if="orderData.orderStatus === '2'" :orderData="orderData" @selected="handleSelectedVoucher" />
|
<VoucherList v-if="orderData.orderType != 0 && orderData.orderStatus === '2'" :orderData="orderData" @selected="handleSelectedVoucher" />
|
||||||
|
|
||||||
<AmtSection :orderData="orderData" @click="refundVisible = true" />
|
<AmtSection :orderData="orderData" @click="refundVisible = true" />
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,8 @@ const lookDetailAction = () => {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
uni.navigateTo({ url: `/pages/long-answer/index?streamId=${encodeURIComponent(streamId)}` });
|
// 传递 finished 参数,完成状态下不自动滚到底部
|
||||||
|
uni.navigateTo({ url: `/pages/long-answer/index?streamId=${encodeURIComponent(streamId)}&finished=${props.finish ? '1' : '0'}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- ✅ 滚动区域 -->
|
<!-- ✅ 滚动区域 -->
|
||||||
<scroll-view class="flex-full overflow-hidden" scroll-y :scroll-into-view="scrollIntoViewId" scroll-with-animation>
|
<scroll-view class="flex-full overflow-hidden chat-scroll" scroll-y :scroll-into-view="scrollIntoViewId" scroll-with-animation @scroll="onScroll" @touchstart="onTouchStart" @touchend="onTouchEnd" @touchcancel="onTouchEnd">
|
||||||
<view class="pt-12 px-12 pb-24 border-box">
|
<view class="pt-12 px-12 pb-24 border-box">
|
||||||
<!-- ✅ 答案内容,支持markdown -->
|
<!-- ✅ 内容,支持markdown -->
|
||||||
<ChatMarkdown :text="answerText" />
|
<ChatMarkdown :text="answerText" />
|
||||||
|
|
||||||
<!-- ✅ 底部锚点(必须存在) -->
|
<!-- ✅ 底部锚点(必须存在) -->
|
||||||
@@ -40,20 +40,91 @@ let unsubscribe = null;
|
|||||||
/** ✅ scroll-into-view 控制 */
|
/** ✅ scroll-into-view 控制 */
|
||||||
const scrollIntoViewId = ref("");
|
const scrollIntoViewId = ref("");
|
||||||
|
|
||||||
|
/** 滚动控制状态 */
|
||||||
|
const isNearBottom = ref(true);
|
||||||
|
const scrollViewHeight = ref(0);
|
||||||
|
const SCROLL_THRESHOLD = 150; // px
|
||||||
|
|
||||||
|
/** 用户交互状态,用户滚动/触摸时临时禁用自动滚动 */
|
||||||
|
const userInteracting = ref(false);
|
||||||
|
let interactionTimer = null;
|
||||||
|
|
||||||
|
/** 是否已完成(从 URL 参数判断),完成状态下不初始初自动滚到底部 */
|
||||||
|
let isFinishedOnInit = false;
|
||||||
|
|
||||||
/** ✅ 防抖 */
|
/** ✅ 防抖 */
|
||||||
let scrollTimer = null;
|
let scrollTimer = null;
|
||||||
|
|
||||||
function scrollToBottom() {
|
const measureScrollViewHeight = () => {
|
||||||
|
try {
|
||||||
|
// 使用 uni.createSelectorQuery 获取 scroll-view 的准确高度
|
||||||
|
uni.createSelectorQuery()
|
||||||
|
.select(".chat-scroll")
|
||||||
|
.boundingClientRect((rect) => {
|
||||||
|
if (rect && rect.height) {
|
||||||
|
scrollViewHeight.value = rect.height;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.exec();
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 生成展示用标题:去除前导 `#` 并截取前 6 字符(超过加省略号) */
|
||||||
|
const computeTitle = (text = "") => {
|
||||||
|
const t = (text || "").replace(/^#+\s*/, "");
|
||||||
|
return t.length > 8 ? t.substring(0, 8) + "..." : t;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onScroll = (e) => {
|
||||||
|
try {
|
||||||
|
const { scrollTop = 0, scrollHeight = 0 } = e.detail || {};
|
||||||
|
|
||||||
|
// 计算距离底部的距离(使用准确的 scroll-view 高度)
|
||||||
|
const viewHeight = scrollViewHeight.value;
|
||||||
|
const distanceToBottom = scrollHeight - scrollTop - viewHeight;
|
||||||
|
|
||||||
|
// 判断是否在底部附近(允许 SCROLL_THRESHOLD 的误差范围)
|
||||||
|
// 注意:只更新 isNearBottom,不在滚动时强制改变 userInteracting
|
||||||
|
const atBottom = distanceToBottom <= SCROLL_THRESHOLD;
|
||||||
|
isNearBottom.value = atBottom;
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
const onTouchStart = () => {
|
||||||
|
// 触摸开始时,立即标记为用户交互状态
|
||||||
|
userInteracting.value = true;
|
||||||
|
clearTimeout(interactionTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
const onTouchEnd = () => {
|
||||||
|
// 触摸结束后延迟一段时间再取消交互状态
|
||||||
|
// 这样即使用户快速滚动,也不会被中途打断
|
||||||
|
clearTimeout(interactionTimer);
|
||||||
|
interactionTimer = setTimeout(() => {
|
||||||
|
userInteracting.value = false;
|
||||||
|
}, 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
const scrollToBottom = () => {
|
||||||
if (scrollTimer) return;
|
if (scrollTimer) return;
|
||||||
|
if (isFinishedOnInit) return;
|
||||||
|
|
||||||
scrollTimer = setTimeout(() => {
|
scrollTimer = setTimeout(() => {
|
||||||
// ❗关键:强制触发滚动(小程序必须这样)
|
// ❗关键:强制触发滚动(小程序必须这样)
|
||||||
|
// 如果用户正在交互,则跳过本次自动滚动
|
||||||
|
if (userInteracting.value) {
|
||||||
|
scrollTimer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
scrollIntoViewId.value = "";
|
scrollIntoViewId.value = "";
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
// 再次 nextTick + 延迟,兼容 markdown 渲染延迟
|
// 再次 nextTick + 延迟,兼容 markdown 渲染延迟
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
scrollIntoViewId.value = "bottom-anchor";
|
scrollIntoViewId.value = "bottom-anchor";
|
||||||
|
// 测量高度以便后续滚动判断准确
|
||||||
|
measureScrollViewHeight();
|
||||||
}, 50);
|
}, 50);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -61,32 +132,47 @@ function scrollToBottom() {
|
|||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoad(({ message = "", streamId = "" }) => {
|
onLoad(({ message = "", streamId = "", finished = "0" }) => {
|
||||||
|
// 记录初始完成状态
|
||||||
|
isFinishedOnInit = finished === "1";
|
||||||
|
|
||||||
|
console.log("LongAnswer onLoad with params:", { message, streamId, finished });
|
||||||
|
|
||||||
|
// 初次测量 scroll-view 高度
|
||||||
|
nextTick(() => {
|
||||||
|
measureScrollViewHeight();
|
||||||
|
});
|
||||||
|
|
||||||
if (streamId) {
|
if (streamId) {
|
||||||
// ✅ 流式数据
|
// ✅ 流式数据
|
||||||
unsubscribe = StreamManager.subscribe(
|
unsubscribe = StreamManager.subscribe(
|
||||||
streamId,
|
streamId,
|
||||||
(text = "", finished = false) => {
|
(text = "", finished = false) => {
|
||||||
answerText.value = text || "";
|
answerText.value = text || "";
|
||||||
|
title.value = computeTitle(answerText.value);
|
||||||
if (answerText.value.length > 6) {
|
|
||||||
title.value = answerText.value.substring(0, 6) + "...";
|
|
||||||
}
|
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
|
// 每次接收数据都重新测量高度(content size 可能变化,比如加载图)
|
||||||
|
measureScrollViewHeight();
|
||||||
|
|
||||||
|
// 流式完成时强制滚动到底部
|
||||||
|
if (finished) {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
|
}
|
||||||
|
// 流式中的数据更新:只有在用户未交互且接近底部时才自动滚动
|
||||||
|
else if (!userInteracting.value && isNearBottom.value) {
|
||||||
|
scrollToBottom();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// ✅ 非流式
|
// ✅ 非流式
|
||||||
answerText.value = decodeURIComponent(message || "");
|
answerText.value = decodeURIComponent(message || "");
|
||||||
|
title.value = computeTitle(answerText.value);
|
||||||
if (answerText.value.length > 6) {
|
|
||||||
title.value = answerText.value.substring(0, 6) + "...";
|
|
||||||
}
|
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
|
// 只有在初始化为非完成状态时才自动滚到底部
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -96,6 +182,11 @@ onUnload(() => {
|
|||||||
try {
|
try {
|
||||||
unsubscribe && unsubscribe();
|
unsubscribe && unsubscribe();
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
|
// 清理定时器,避免内存泄漏
|
||||||
|
try { clearTimeout(scrollTimer); } catch (e) { }
|
||||||
|
try { clearTimeout(interactionTimer); } catch (e) { }
|
||||||
|
scrollTimer = null;
|
||||||
|
interactionTimer = null;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import { devUrl, wssDevUrl } from "./baseUrl";
|
|||||||
import { getServiceUrl } from "../api/GetServiceUrlApi";
|
import { getServiceUrl } from "../api/GetServiceUrlApi";
|
||||||
|
|
||||||
/// 版本号, 每次发版本前增加
|
/// 版本号, 每次发版本前增加
|
||||||
const versionValue = "1.0.4";
|
const versionValue = "1.1.1";
|
||||||
|
|
||||||
/// 是否是测试版本, 测试版本为true, 发布版本为false
|
/// 是否是测试版本, 测试版本为true, 发布版本为false
|
||||||
const developVersion = true;
|
const developVersion = false;
|
||||||
|
|
||||||
// 获取服务地址
|
// 获取服务地址
|
||||||
const getEvnUrl = async () => {
|
const getEvnUrl = async () => {
|
||||||
/// 智念客户端不需要获取环境地址
|
/// 不需要获取环境地址
|
||||||
if (isZhiNian || developVersion) {
|
if (developVersion) {
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
appStore.setServerConfig({
|
appStore.setServerConfig({
|
||||||
baseUrl: devUrl, // 服务器基础地址
|
baseUrl: devUrl, // 服务器基础地址
|
||||||
|
|||||||
Reference in New Issue
Block a user