refactor: 移除调试日志并优化代码结构

- 删除多个组件中的console.log调试语句
- 优化axios错误处理中的可选链操作
- 重构wechat-btn组件的事件监听逻辑
- 清理ai.vue中的冗余代码和注释
- 改进页面可见性变化的处理逻辑
This commit is contained in:
DESKTOP-RQ919RC\Pc
2025-08-25 18:53:18 +08:00
parent 411494dd1b
commit 5fd6f68a7c
6 changed files with 44 additions and 49 deletions

View File

@@ -107,7 +107,6 @@ let imageShow = ref(false); // 查看大图弹窗的状态
let imageList = ref([]); // 查看大图弹窗的状态
let imageIndex = ref(0); // 查看大图弹窗的状态
const openImageShow = (list, index) => {
console.log("list", list);
let arr = [];
list.forEach((item) => {
arr.push({

View File

@@ -5,7 +5,6 @@
</div>
<div class="circle-pop flexacenter" v-if="circleState">
<img class="close-icon" src="@/assets/img/publicImage/circle-close.png" alt="" @click.stop="circleState = !circleState" />
<!-- <img class="circle-bj" src="@/assets/img/publicImage/circle-pop-bj.svg"> -->
<img class="circle-bj-green" src="@/assets/img/publicImage/wechat-pop-green.svg" />
<div class="circle-title flexacenter">
欢迎联系 <b>{{ wechat["nickname"] }}</b> 咨询公寓
@@ -19,12 +18,43 @@
</template>
<script setup>
import { ref, toRefs } from "vue";
import { useStore } from "vuex";
const store = useStore();
const { wechat } = toRefs(store.state);
import { reactive, onMounted, ref, toRefs, nextTick, onBeforeUnmount, watch, getCurrentInstance, onUnmounted } from "vue";
let circleState = ref(false);
// 定义点击事件处理函数
const handleDocumentClick = (e) => {
// 点击关闭按钮关闭
if (e.target.classList.contains("close-icon")) {
circleState.value = false;
return;
}
// 点击其他地方且弹窗显示时关闭
if (circleState.value) {
circleState.value = false;
}
};
// 监听 circleState 变化,状态为 true 时开始监听,为 false 时停止监听
watch(circleState, (newVal) => {
if (newVal) {
setTimeout(() => {
document.addEventListener("click", handleDocumentClick);
}, 1000);
} else {
setTimeout(() => {
document.removeEventListener("click", handleDocumentClick);
}, 1000);
}
});
// 组件卸载时移除事件监听,避免内存泄漏
onUnmounted(() => {
document.removeEventListener("click", handleDocumentClick);
});
</script>
<style lang="less" scoped>
@@ -77,7 +107,7 @@ let circleState = ref(false);
.circle-pop {
position: absolute;
bottom: 45px;
bottom: 40px;
// right: 65px;
width: 300px;
height: 300px;

View File

@@ -96,7 +96,7 @@ const $post = (url, params) => {
resolve(res.data);
})
.catch((err) => {
if (err.data.code == 401) resolve(err.data);
if (err?.data?.code == 401) resolve(err.data);
else reject(err.data);
});
});
@@ -104,15 +104,13 @@ const $post = (url, params) => {
const $postV2 = (url, params) => {
return new Promise((resolve, reject) => {
console.log("params", params);
axios
.post(url, JSON.stringify(params), { headers: { "Content-Type": "application/json" }, timeout: 100000, ...(params.noMask !== undefined ? { noMask: params.noMask } : {}) })
.then((res) => {
resolve(res.data);
})
.catch((err) => {
if (err.data.code == 401) resolve(err.data);
if (err?.data?.code == 401) resolve(err.data);
else reject(err.data);
});
});

View File

@@ -64,15 +64,10 @@ const handleInput = (e) => {
// 全局滚动到顶部监听函数
const handleScrollToTop = () => {
const isAtTop = window.scrollY === 0;
if (isAtTop) {
console.log("页面已滚动到顶部");
// 这里可以添加滚动到顶部后的业务逻辑
getHistory();
}
if (isAtTop) getHistory();
};
onMounted(() => {
console.log("onMounted");
init();
document.addEventListener("visibilitychange", handleVisibilityChange);
@@ -136,11 +131,7 @@ const scrollEnd = async () => {
// 滚动到指定位置
const scrollItem = (id) => {
console.log("id", id);
const element = contentRef.value.querySelector(`#item${id}`);
console.log("element", element);
if (element) {
// 计算元素顶部位置并减去50px偏移
const rect = element.getBoundingClientRect();
@@ -171,7 +162,6 @@ const getHistory = () => {
limit,
})
.then((res) => {
console.log(res);
if (res.code != 200) return;
let data = res.data || {};
// data.count = 0
@@ -188,8 +178,6 @@ const getHistory = () => {
list.value.push(obj);
}
console.log("history", history);
historyList.value = history;
isLogo.value = history.length == 0 ? true : false;
@@ -246,14 +234,12 @@ let generateState = false;
let input = ref("");
const send = () => {
console.log("send");
if (generateState) {
ElMessage.error("生成中,请等待!");
return;
}
const inputValue = input.value;
console.log("inputValue", inputValue);
if (!inputValue) {
ElMessage.error("请输入内容");
@@ -302,7 +288,6 @@ const send = () => {
listValue[listValue.length - 2] = Object.assign(listValue[listValue.length - 2], itemUser);
let itemAssis = history.findLast((item) => item.role === "assistant");
console.log("history", history);
itemAssis = handleData(itemAssis);
@@ -373,7 +358,6 @@ const handleData = (obj) => {
if (Array.isArray(element.district)) element.district = element.district.join("、");
let url = `/apartmentDetail?uniqid=${element.uniqid}`;
if (["person", "agent"].includes(element.type)) url = `/detail?id=${element.uniqid}`;
console.log("url", url);
element["url"] = url;
element["score"] = Math.floor(element.recommendation_score);
@@ -397,12 +381,10 @@ const chatError = (listValue, inputValue, hint) => {
target = Object.assign(target, obj);
listValue[listValue.length - 1] = target;
console.log("target", listValue);
generateState = false;
list.value = [...listValue];
input.value = inputValue;
console.log(list.value);
nextTick(() => autoResize());
};
@@ -410,7 +392,7 @@ const chatError = (listValue, inputValue, hint) => {
const handleResume = () => {
if (!session_id || !initState) return;
api.alResume({ session_id }).then((res) => {
console.log("res", res);
// console.log("res", res);
});
};
@@ -425,7 +407,7 @@ const endChat = () => {
session_id,
history: listValue,
}).then((res) => {
console.log("res", res);
// console.log("res", res);
});
};
@@ -433,8 +415,6 @@ let inputRef = ref(null);
// 自动输入框增高
const autoResize = (e) => {
console.log("inputRef", inputRef.value);
inputRef.value.style.height = "auto"; // 重置高度
inputRef.value.style.height = `${inputRef.value.scrollHeight + 1}px`; // 设置为内容高度
};
@@ -540,15 +520,8 @@ const handleVisibilityChange = () => {
lastChangeTime.value = new Date().toLocaleTimeString();
// 根据状态执行不同操作
if (document.visibilityState === "visible") {
console.log("页面已显示(用户切回标签页/窗口)");
// 可执行恢复操作:如重新请求数据、播放视频等
handleResume();
} else {
console.log("页面已隐藏(用户切换标签页/最小化窗口)");
// 可执行暂停操作:如暂停视频、保存临时数据等
endChat();
}
if (document.visibilityState === "visible") handleResume();
else endChat(); // 可执行暂停操作:如暂停视频、保存临时数据等
};
const randomString = () => {

View File

@@ -832,8 +832,6 @@ const cloaseImageShow = (list, index, type) => {
imageIndex.value = index;
imageType = type;
}
console.log(imageList.value);
imageShow.value = !imageShow.value;
};
@@ -1582,9 +1580,6 @@ const getMapDistance = () => {
if (pitch == null) pitch = distance[0];
console.log("distance",distance);
distanceList.value = distance;
distancePitch.value = pitch;
});

View File

@@ -1152,7 +1152,7 @@ export default {
// 上传视频 和 图片
uploadVideo(type, target) {
let config = this.$store.state.upload;
console.log("config",config);
// console.log("config",config);
const formData = new FormData();
formData.append(config.requestName, target); // 文件数据