AI根据用户点击次数显示弹窗
This commit is contained in:
264
index.html
264
index.html
@@ -38,13 +38,18 @@
|
||||
font-size: 15px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
z-index: 9999;
|
||||
z-index: 9999999999;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.toast.success {
|
||||
background-color: #09db45;
|
||||
}
|
||||
|
||||
|
||||
/* 侧边栏 */
|
||||
.sidebar {
|
||||
width: 240px;
|
||||
@@ -55,6 +60,7 @@
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.04);
|
||||
z-index: 10;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.sidebar.collapsed {
|
||||
@@ -172,7 +178,8 @@
|
||||
flex-direction: column;
|
||||
background: #f9fcff;
|
||||
justify-content: space-between;
|
||||
width: calc(100% - 240px)
|
||||
width: calc(100% - 240px);
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.chat-container .content {
|
||||
@@ -520,6 +527,7 @@
|
||||
|
||||
/* 手机端适配 */
|
||||
@media (max-width: 768px) {
|
||||
|
||||
.mobilelogo {
|
||||
|
||||
display: flex;
|
||||
@@ -543,6 +551,7 @@
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
height: 100%;
|
||||
left: 0px;
|
||||
}
|
||||
|
||||
.sidebar.sidebar.collapsed>.toggle-btn {
|
||||
@@ -752,6 +761,105 @@
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background: #f5f5f5;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.popbgc {
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
position: fixed;
|
||||
left: 0px;
|
||||
right: 0px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 999999;
|
||||
transition: all 0.3s ease-in-out;
|
||||
backdrop-filter: blur(2px);
|
||||
|
||||
}
|
||||
|
||||
.popup {
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
||||
width: 400px;
|
||||
|
||||
}
|
||||
|
||||
.popup h2 {
|
||||
margin-top: 0;
|
||||
font-size: 18px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
input,
|
||||
select,
|
||||
button {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
margin: 5px 0;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.options {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.option {
|
||||
/* flex: 1 1 calc(50% - 5px); */
|
||||
width: 28%;
|
||||
text-align: center;
|
||||
padding: 8px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.option.selected {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.popbgc.none {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.popbgc {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.popup {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -910,6 +1018,51 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="popbgc none">
|
||||
<div class="popup">
|
||||
<h2>开启光伏运维智能化!</h2>
|
||||
<form id="popupForm">
|
||||
<input type="text" name="company" placeholder="请输入您的公司" required>
|
||||
|
||||
<!-- <select name="need" required>
|
||||
<option value="">您的需求是什么?</option>
|
||||
<option value="杂草清理">杂草清理</option>
|
||||
<option value="组件积灰清扫">组件积灰清扫</option>
|
||||
<option value="EL/IR缺陷识别">EL/IR缺陷识别</option>
|
||||
<option value="热斑检测">热斑检测</option>
|
||||
<option value="需要运维机器人">需要运维机器人</option>
|
||||
<option value="定制机器人">定制机器人</option>
|
||||
</select> -->
|
||||
|
||||
<div>
|
||||
<p>您对以下哪些场景感兴趣?</p>
|
||||
<div class="options" id="scenes">
|
||||
<div class="option">山地光伏</div>
|
||||
<div class="option">荒漠 / 戈壁</div>
|
||||
<div class="option">农光互补电站</div>
|
||||
<div class="option">渔光互补电站</div>
|
||||
<div class="option">滩涂 / 盐碱地</div>
|
||||
<div class="option">平原 / 草原</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p>您的需求?</p>
|
||||
<div class="options" id="needs">
|
||||
<div class="option">杂草清理</div>
|
||||
<div class="option">组件积灰清扫</div>
|
||||
<div class="option">EL/IR缺陷识别</div>
|
||||
<div class="option">热斑检测</div>
|
||||
<div class="option">需要运维机器人</div>
|
||||
<div class="option">定制机器人</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit">立即使用</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
@@ -1127,10 +1280,10 @@
|
||||
console.error("请求异常:", err);
|
||||
}
|
||||
}
|
||||
function showToast(message) {
|
||||
function showToast(message, type = '') {
|
||||
// 创建元素
|
||||
const toast = document.createElement("div");
|
||||
toast.className = "toast";
|
||||
toast.className = `toast${type == "success" ? " success" : ""}`;
|
||||
toast.innerText = message;
|
||||
document.body.appendChild(toast);
|
||||
|
||||
@@ -1242,6 +1395,34 @@
|
||||
});
|
||||
setTimeout(scrollToBottom, 0);
|
||||
}
|
||||
function setCookie(name, value) {
|
||||
const d = new Date();
|
||||
d.setFullYear(d.getFullYear() + 100); // +100 年
|
||||
document.cookie = `${name}=${value};expires=${d.toUTCString()};path=/`;
|
||||
}
|
||||
function getCookie(name) {
|
||||
const cookies = document.cookie.split("; ");
|
||||
for (let c of cookies) {
|
||||
const [key, val] = c.split("=");
|
||||
if (key === name) return val;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function showPop(userId) {
|
||||
if (!userId) {
|
||||
console.error("userId 缺失,无法记录点击次数");
|
||||
return;
|
||||
}
|
||||
const cookieName = `popupClickCount_${userId}`;
|
||||
let clickCount = parseInt(getCookie(cookieName) || "0", 10);
|
||||
clickCount++;
|
||||
setCookie(cookieName, clickCount, 7);
|
||||
console.log(`用户 ${userId} 当前点击次数:`, clickCount);
|
||||
if (clickCount == 10) {
|
||||
document.querySelector(".popbgc").classList.remove("none");
|
||||
}
|
||||
}
|
||||
// 内容 角色 图片 创造时间
|
||||
function addMessage(content = '', role = "assistant", imgUrl = null, time = null) {
|
||||
const msg = document.createElement("div");
|
||||
@@ -1391,6 +1572,7 @@
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
let buffer = "";
|
||||
msgDiv.classList.remove("thinking");
|
||||
showPop(userId);
|
||||
clearInterval(interval);
|
||||
console.log(isStopped, '是否点击停止')
|
||||
|
||||
@@ -1749,6 +1931,80 @@
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// 1. 分别获取「场景选项」和「需求选项」(通过父容器ID精准筛选,避免混淆)
|
||||
const sceneOptions = document.querySelectorAll('#scenes .option'); // 场景类选项(父容器#scenes)
|
||||
const needOptions = document.querySelectorAll('#needs .option'); // 需求类选项(父容器#needs)
|
||||
|
||||
// 2. 创建两个隐藏输入框,分别存「场景」和「需求」数据
|
||||
const scenesInput = document.createElement('input');
|
||||
scenesInput.type = 'hidden';
|
||||
scenesInput.name = 'scenes'; // 后端接收「场景」的字段名
|
||||
|
||||
const needsInput = document.createElement('input');
|
||||
needsInput.type = 'hidden';
|
||||
needsInput.name = 'needs'; // 后端接收「需求」的字段名
|
||||
|
||||
// 3. 把两个隐藏框添加到表单中
|
||||
const form = document.getElementById('popupForm');
|
||||
form.appendChild(scenesInput);
|
||||
form.appendChild(needsInput);
|
||||
|
||||
// 4. 场景选项的点击事件:收集选中的场景
|
||||
sceneOptions.forEach(opt => {
|
||||
opt.addEventListener('click', () => {
|
||||
opt.classList.toggle('selected'); // 切换选中样式
|
||||
// 筛选选中的场景,提取文本并拼接成字符串(如:"山地光伏,农光互补电站")
|
||||
const selectedScenes = Array.from(sceneOptions)
|
||||
.filter(o => o.classList.contains('selected'))
|
||||
.map(o => o.textContent);
|
||||
scenesInput.value = selectedScenes.join(','); // 同步到场景隐藏框
|
||||
});
|
||||
});
|
||||
|
||||
// 5. 需求选项的点击事件:收集选中的需求
|
||||
needOptions.forEach(opt => {
|
||||
opt.addEventListener('click', () => {
|
||||
opt.classList.toggle('selected'); // 切换选中样式
|
||||
// 筛选选中的需求,提取文本并拼接成字符串(如:"杂草清理,热斑检测")
|
||||
const selectedNeeds = Array.from(needOptions)
|
||||
.filter(o => o.classList.contains('selected'))
|
||||
.map(o => o.textContent);
|
||||
needsInput.value = selectedNeeds.join(','); // 同步到需求隐藏框
|
||||
});
|
||||
});
|
||||
|
||||
// 6. 表单提交:异步发送所有数据(公司名 + 场景 + 需求)
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault(); // 阻止表单默认刷新提交
|
||||
const formData = new FormData(e.target); // 自动收集表单所有数据
|
||||
const data = { ...Object.fromEntries(formData.entries()), userId: userId }; // 转成普通对象
|
||||
if (!data.needs) {
|
||||
showToast("请选择需求");
|
||||
return;
|
||||
|
||||
}
|
||||
if (!data.scenes) {
|
||||
showToast("请选择场景");
|
||||
return;
|
||||
}
|
||||
console.log(data, "收集信息")
|
||||
|
||||
// 发送POST请求到后端
|
||||
const res = await fetch('/api/submit', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data) // 数据格式:{ company: "xxx", scenes: "xxx,xxx", needs: "xxx,xxx" }
|
||||
});
|
||||
|
||||
const result = await res.json();
|
||||
if (result.code == 200) {
|
||||
document.querySelector('.popbgc').classList.add('none');
|
||||
showToast("提交成功", 'success')
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
22
server2.js
22
server2.js
@@ -729,6 +729,28 @@ app.post("/stop", express.json(), (req, res) => {
|
||||
console.log(stopFlags,"消息id");
|
||||
res.json({ ok: true });
|
||||
});
|
||||
app.post('/submit',async (req, res) => {
|
||||
const { company, scenes, needs, userId } = req.body;
|
||||
|
||||
console.log("收到数据:", company, scenes, needs, userId);
|
||||
|
||||
if (!company || !needs || !userId) {
|
||||
return res.status(400).json({ message: "缺少必要字段" });
|
||||
}
|
||||
|
||||
try {
|
||||
const sql =
|
||||
"INSERT INTO pv_form (company, scenes, needs, userId) VALUES (?, ?, ?, ?)";
|
||||
|
||||
await pool.query(sql, [company, scenes, needs, userId || null]);
|
||||
|
||||
res.json({ code:200,message: "提交成功!" });
|
||||
} catch (err) {
|
||||
console.error("数据库插入失败:", err);
|
||||
res.status(500).json({ message: "数据库写入失败" });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user