Add render data

This commit is contained in:
root 2025-03-30 15:12:52 +05:00
parent 71a2bec099
commit cceca6b8bf
4 changed files with 97 additions and 25 deletions

View File

@ -10,5 +10,27 @@ body {
}
table {
width: 100%;
}
td {
padding: 5px 10px;
}
.none {
display: none;
}
#loader span {
animation: 1500ms infinite loader;
animation-delay: calc(var(--i) * 500ms);
}
@keyframes loader {
from {
opacity: 1;
}
to {
opacity: 0;
}
}

View File

@ -7,8 +7,7 @@
<script src="/js/index.js?v=1" defer></script>
</head>
<body>
id, название сделки, бюджет, название контакта номер телефона.
<table>
<table id="table">
<tr>
<th>ID</th>
<th>Название</th>
@ -16,15 +15,12 @@
<th>Контакт</th>
<th>Телефон</th>
</tr>
<div id="table-content">
<tr>
<td>1111</td>
<td>Название</td>
<td>Бюджет</td>
<td>Контакт</td>
<td>Телефон</td>
</tr>
</div>
</table>
<div id="loader">
<span style="--i:1">*</span>
<span style="--i:2">*</span>
<span style="--i:3">*</span>
</div>
</body>
</html>

33
index.html.save Normal file
View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0">
<link rel="stylesheet" href="/css/style.css?v=1">
<script src="/js/index.js?v=1" defer></script>
</head>
<body>
id, название сделки, бюджет, название контакта номер телефона.
<table>
<tr>
<th>ID</th>
<th>Название</th>
<th>Бюджет</th>
<th>Контакт</th>
<th>Телефон</th>
</tr>
<div id="table-content">
<tr>
<td>1111</td>
<td>Название</td>
<td>Бюджет</td>
<td>Контакт</td>
<td>Телефон</td>
</tr>
</div>
</table>
<div id="loading">
<span>
</body>
</html>

View File

@ -57,14 +57,14 @@ const getContact = async id => {
return data
} catch (error) {
console.error('Ошибка при получении токенов:', error)
console.error('Ошибка при получении контактов:', error)
throw error
}
}
const getLeads = async (page = 1, limit = 2) => {
try {
const response = await fetch(`https://${DOMAIN}/api/v4/leads?page=${page}&limit=${limit}&with=contacts`, {
const response = await fetch(`https://${DOMAIN}/api/v4/leads?page=${page}&limit=${limit}&with=contacts&order[id]=desc`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${ACCESS_TOKEN}`,
@ -78,22 +78,21 @@ const getLeads = async (page = 1, limit = 2) => {
const data = await response.json()
const leads = []
data._embedded.leads.forEach(async lead => {
const contact =
lead._embedded.contacts.length
? await getContact(lead._embedded.contacts[0].id)
: null
const leads = await Promise.all(data._embedded.leads.map(async lead => {
const contact =
lead._embedded.contacts.length
? await getContact(lead._embedded.contacts[0].id)
: null
leads.push({
return {
lead: lead,
contact: contact
})
})
}
}))
return leads
} catch (error) {
console.error('Ошибка при получении токенов:', error)
console.error('Заявок больше нет')
throw error
}
}
@ -103,7 +102,29 @@ const getAllLeads = async () => {
while (true) {
try {
const leads = await getLeads(page++)
console.log(leads)
for (const lead of leads) {
console.log(lead)
const row = document.getElementById('table').insertRow()
const cell1 = row.insertCell()
const cell2 = row.insertCell()
const cell3 = row.insertCell()
const cell4 = row.insertCell()
const cell5 = row.insertCell()
cell1.textContent = lead.lead.id
cell2.textContent = lead.lead.name
cell3.textContent = lead.lead.price
cell4.textContent = lead.contact?.name
cell5.textContent = lead.contact
?.custom_fields_values[0]
?.values[0]?.value
}
} catch (error) {
document.getElementById('loader').classList.add('none')
console.log(error)
throw error
break
}
await sleep(1000)
@ -112,5 +133,5 @@ const getAllLeads = async () => {
(async () => {
await getAllLeads()
})()