refactor: 移除调试日志并优化代码结构
- 删除多个组件中的console.log调试语句 - 优化axios错误处理中的可选链操作 - 重构wechat-btn组件的事件监听逻辑 - 清理ai.vue中的冗余代码和注释 - 改进页面可见性变化的处理逻辑
This commit is contained in:
@@ -107,7 +107,6 @@ let imageShow = ref(false); // 查看大图弹窗的状态
|
|||||||
let imageList = ref([]); // 查看大图弹窗的状态
|
let imageList = ref([]); // 查看大图弹窗的状态
|
||||||
let imageIndex = ref(0); // 查看大图弹窗的状态
|
let imageIndex = ref(0); // 查看大图弹窗的状态
|
||||||
const openImageShow = (list, index) => {
|
const openImageShow = (list, index) => {
|
||||||
console.log("list", list);
|
|
||||||
let arr = [];
|
let arr = [];
|
||||||
list.forEach((item) => {
|
list.forEach((item) => {
|
||||||
arr.push({
|
arr.push({
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="circle-pop flexacenter" v-if="circleState">
|
<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="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" />
|
<img class="circle-bj-green" src="@/assets/img/publicImage/wechat-pop-green.svg" />
|
||||||
<div class="circle-title flexacenter">
|
<div class="circle-title flexacenter">
|
||||||
欢迎联系 <b>{{ wechat["nickname"] }}</b> 咨询公寓
|
欢迎联系 <b>{{ wechat["nickname"] }}</b> 咨询公寓
|
||||||
@@ -19,12 +18,43 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, toRefs } from "vue";
|
|
||||||
import { useStore } from "vuex";
|
import { useStore } from "vuex";
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const { wechat } = toRefs(store.state);
|
const { wechat } = toRefs(store.state);
|
||||||
|
import { reactive, onMounted, ref, toRefs, nextTick, onBeforeUnmount, watch, getCurrentInstance, onUnmounted } from "vue";
|
||||||
|
|
||||||
let circleState = ref(false);
|
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>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
@@ -77,7 +107,7 @@ let circleState = ref(false);
|
|||||||
|
|
||||||
.circle-pop {
|
.circle-pop {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 45px;
|
bottom: 40px;
|
||||||
// right: 65px;
|
// right: 65px;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
height: 300px;
|
height: 300px;
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ const $post = (url, params) => {
|
|||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.data.code == 401) resolve(err.data);
|
if (err?.data?.code == 401) resolve(err.data);
|
||||||
else reject(err.data);
|
else reject(err.data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -104,15 +104,13 @@ const $post = (url, params) => {
|
|||||||
|
|
||||||
const $postV2 = (url, params) => {
|
const $postV2 = (url, params) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log("params", params);
|
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(url, JSON.stringify(params), { headers: { "Content-Type": "application/json" }, timeout: 100000, ...(params.noMask !== undefined ? { noMask: params.noMask } : {}) })
|
.post(url, JSON.stringify(params), { headers: { "Content-Type": "application/json" }, timeout: 100000, ...(params.noMask !== undefined ? { noMask: params.noMask } : {}) })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.data.code == 401) resolve(err.data);
|
if (err?.data?.code == 401) resolve(err.data);
|
||||||
else reject(err.data);
|
else reject(err.data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -64,15 +64,10 @@ const handleInput = (e) => {
|
|||||||
// 全局滚动到顶部监听函数
|
// 全局滚动到顶部监听函数
|
||||||
const handleScrollToTop = () => {
|
const handleScrollToTop = () => {
|
||||||
const isAtTop = window.scrollY === 0;
|
const isAtTop = window.scrollY === 0;
|
||||||
if (isAtTop) {
|
if (isAtTop) getHistory();
|
||||||
console.log("页面已滚动到顶部");
|
|
||||||
// 这里可以添加滚动到顶部后的业务逻辑
|
|
||||||
getHistory();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
console.log("onMounted");
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||||
@@ -136,11 +131,7 @@ const scrollEnd = async () => {
|
|||||||
|
|
||||||
// 滚动到指定位置
|
// 滚动到指定位置
|
||||||
const scrollItem = (id) => {
|
const scrollItem = (id) => {
|
||||||
console.log("id", id);
|
|
||||||
|
|
||||||
const element = contentRef.value.querySelector(`#item${id}`);
|
const element = contentRef.value.querySelector(`#item${id}`);
|
||||||
console.log("element", element);
|
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
// 计算元素顶部位置并减去50px偏移
|
// 计算元素顶部位置并减去50px偏移
|
||||||
const rect = element.getBoundingClientRect();
|
const rect = element.getBoundingClientRect();
|
||||||
@@ -171,7 +162,6 @@ const getHistory = () => {
|
|||||||
limit,
|
limit,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
|
||||||
if (res.code != 200) return;
|
if (res.code != 200) return;
|
||||||
let data = res.data || {};
|
let data = res.data || {};
|
||||||
// data.count = 0
|
// data.count = 0
|
||||||
@@ -188,8 +178,6 @@ const getHistory = () => {
|
|||||||
list.value.push(obj);
|
list.value.push(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("history", history);
|
|
||||||
|
|
||||||
historyList.value = history;
|
historyList.value = history;
|
||||||
isLogo.value = history.length == 0 ? true : false;
|
isLogo.value = history.length == 0 ? true : false;
|
||||||
|
|
||||||
@@ -246,14 +234,12 @@ let generateState = false;
|
|||||||
let input = ref("");
|
let input = ref("");
|
||||||
|
|
||||||
const send = () => {
|
const send = () => {
|
||||||
console.log("send");
|
|
||||||
if (generateState) {
|
if (generateState) {
|
||||||
ElMessage.error("生成中,请等待!");
|
ElMessage.error("生成中,请等待!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputValue = input.value;
|
const inputValue = input.value;
|
||||||
console.log("inputValue", inputValue);
|
|
||||||
|
|
||||||
if (!inputValue) {
|
if (!inputValue) {
|
||||||
ElMessage.error("请输入内容");
|
ElMessage.error("请输入内容");
|
||||||
@@ -302,7 +288,6 @@ const send = () => {
|
|||||||
listValue[listValue.length - 2] = Object.assign(listValue[listValue.length - 2], itemUser);
|
listValue[listValue.length - 2] = Object.assign(listValue[listValue.length - 2], itemUser);
|
||||||
|
|
||||||
let itemAssis = history.findLast((item) => item.role === "assistant");
|
let itemAssis = history.findLast((item) => item.role === "assistant");
|
||||||
console.log("history", history);
|
|
||||||
|
|
||||||
itemAssis = handleData(itemAssis);
|
itemAssis = handleData(itemAssis);
|
||||||
|
|
||||||
@@ -373,7 +358,6 @@ const handleData = (obj) => {
|
|||||||
if (Array.isArray(element.district)) element.district = element.district.join("、");
|
if (Array.isArray(element.district)) element.district = element.district.join("、");
|
||||||
let url = `/apartmentDetail?uniqid=${element.uniqid}`;
|
let url = `/apartmentDetail?uniqid=${element.uniqid}`;
|
||||||
if (["person", "agent"].includes(element.type)) url = `/detail?id=${element.uniqid}`;
|
if (["person", "agent"].includes(element.type)) url = `/detail?id=${element.uniqid}`;
|
||||||
console.log("url", url);
|
|
||||||
|
|
||||||
element["url"] = url;
|
element["url"] = url;
|
||||||
element["score"] = Math.floor(element.recommendation_score);
|
element["score"] = Math.floor(element.recommendation_score);
|
||||||
@@ -397,12 +381,10 @@ const chatError = (listValue, inputValue, hint) => {
|
|||||||
target = Object.assign(target, obj);
|
target = Object.assign(target, obj);
|
||||||
|
|
||||||
listValue[listValue.length - 1] = target;
|
listValue[listValue.length - 1] = target;
|
||||||
console.log("target", listValue);
|
|
||||||
|
|
||||||
generateState = false;
|
generateState = false;
|
||||||
list.value = [...listValue];
|
list.value = [...listValue];
|
||||||
input.value = inputValue;
|
input.value = inputValue;
|
||||||
console.log(list.value);
|
|
||||||
nextTick(() => autoResize());
|
nextTick(() => autoResize());
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -410,7 +392,7 @@ const chatError = (listValue, inputValue, hint) => {
|
|||||||
const handleResume = () => {
|
const handleResume = () => {
|
||||||
if (!session_id || !initState) return;
|
if (!session_id || !initState) return;
|
||||||
api.alResume({ session_id }).then((res) => {
|
api.alResume({ session_id }).then((res) => {
|
||||||
console.log("res", res);
|
// console.log("res", res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -425,7 +407,7 @@ const endChat = () => {
|
|||||||
session_id,
|
session_id,
|
||||||
history: listValue,
|
history: listValue,
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
console.log("res", res);
|
// console.log("res", res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -433,8 +415,6 @@ let inputRef = ref(null);
|
|||||||
|
|
||||||
// 自动输入框增高
|
// 自动输入框增高
|
||||||
const autoResize = (e) => {
|
const autoResize = (e) => {
|
||||||
console.log("inputRef", inputRef.value);
|
|
||||||
|
|
||||||
inputRef.value.style.height = "auto"; // 重置高度
|
inputRef.value.style.height = "auto"; // 重置高度
|
||||||
inputRef.value.style.height = `${inputRef.value.scrollHeight + 1}px`; // 设置为内容高度
|
inputRef.value.style.height = `${inputRef.value.scrollHeight + 1}px`; // 设置为内容高度
|
||||||
};
|
};
|
||||||
@@ -540,15 +520,8 @@ const handleVisibilityChange = () => {
|
|||||||
lastChangeTime.value = new Date().toLocaleTimeString();
|
lastChangeTime.value = new Date().toLocaleTimeString();
|
||||||
|
|
||||||
// 根据状态执行不同操作
|
// 根据状态执行不同操作
|
||||||
if (document.visibilityState === "visible") {
|
if (document.visibilityState === "visible") handleResume();
|
||||||
console.log("页面已显示(用户切回标签页/窗口)");
|
else endChat(); // 可执行暂停操作:如暂停视频、保存临时数据等
|
||||||
// 可执行恢复操作:如重新请求数据、播放视频等
|
|
||||||
handleResume();
|
|
||||||
} else {
|
|
||||||
console.log("页面已隐藏(用户切换标签页/最小化窗口)");
|
|
||||||
// 可执行暂停操作:如暂停视频、保存临时数据等
|
|
||||||
endChat();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const randomString = () => {
|
const randomString = () => {
|
||||||
|
|||||||
@@ -832,8 +832,6 @@ const cloaseImageShow = (list, index, type) => {
|
|||||||
imageIndex.value = index;
|
imageIndex.value = index;
|
||||||
imageType = type;
|
imageType = type;
|
||||||
}
|
}
|
||||||
console.log(imageList.value);
|
|
||||||
|
|
||||||
imageShow.value = !imageShow.value;
|
imageShow.value = !imageShow.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1582,9 +1580,6 @@ const getMapDistance = () => {
|
|||||||
|
|
||||||
if (pitch == null) pitch = distance[0];
|
if (pitch == null) pitch = distance[0];
|
||||||
|
|
||||||
console.log("distance",distance);
|
|
||||||
|
|
||||||
|
|
||||||
distanceList.value = distance;
|
distanceList.value = distance;
|
||||||
distancePitch.value = pitch;
|
distancePitch.value = pitch;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1152,7 +1152,7 @@ export default {
|
|||||||
// 上传视频 和 图片
|
// 上传视频 和 图片
|
||||||
uploadVideo(type, target) {
|
uploadVideo(type, target) {
|
||||||
let config = this.$store.state.upload;
|
let config = this.$store.state.upload;
|
||||||
console.log("config",config);
|
// console.log("config",config);
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append(config.requestName, target); // 文件数据
|
formData.append(config.requestName, target); // 文件数据
|
||||||
|
|||||||
Reference in New Issue
Block a user