diff --git a/Management.html b/Management.html index 1450c7a..4d22993 100644 --- a/Management.html +++ b/Management.html @@ -834,6 +834,11 @@ beginAtZero: true, ticks: { stepSize: 1 + }, + // 动态计算Y轴最大值,为顶部数字留出空间 + max: function(context) { + const max = Math.max(...context.chart.data.datasets[0].data); + return max + 1; } }, x: { @@ -871,6 +876,34 @@ }); } + // 添加Chart.js自定义插件用于显示数据标签 + Chart.register({ + id: 'customDataLabels', + afterDraw: function(chart) { + const ctx = chart.ctx; + chart.data.datasets.forEach(function(dataset, datasetIndex) { + const meta = chart.getDatasetMeta(datasetIndex); + if (meta.hidden) return; + + meta.data.forEach(function(element, index) { + // 获取柱子的位置 + const x = element.x; + const y = element.y; // 柱子顶部的Y坐标 + const value = dataset.data[index]; + + // 设置文本样式 + ctx.fillStyle = '#333'; + ctx.font = 'bold 14px Arial'; + ctx.textAlign = 'center'; + ctx.textBaseline = 'bottom'; + + // 在柱子顶部上方5像素处绘制数值 + ctx.fillText(value, x, y - 5); + }); + }); + } + }); + // 显示指定卖家的货源 async function showSuppliesBySeller(sellerId) { // 获取当前筛选条件和日期范围 @@ -1030,21 +1063,16 @@ const isVideo = mediaUrl.startsWith('data:video/') || mediaUrl.match(/\.(mp4|mov|avi|wmv|flv|webm|mkv)$/i); if (isVideo) { // 视频文件 - mediaElement = ``; + mediaElement = ``; } else { // 图片文件 - mediaElement = `${supply.productName}`; + mediaElement = `${supply.productName}`; } } // 构建详细信息HTML let detailsHTML = ''; - // 蛋黄 - if (supply.yolk) { - detailsHTML += `

蛋黄: ${supply.yolk}

`; - } - // 产品ID if (supply.productId) { detailsHTML += `

产品ID: ${supply.productId}

`; @@ -1132,44 +1160,25 @@ detailsHTML += ``; } - // 货源描述(限制显示长度) - if (supply.description) { - const shortDesc = supply.description.length > 50 ? `${supply.description.substring(0, 50)}...` : supply.description; - detailsHTML += `

货源描述: ${shortDesc}

`; - } - - // 货源类型 - if (supply.sourceType) { - detailsHTML += `

货源类型: ${supply.sourceType}

`; - } - - // 新鲜程度 - if (supply.freshness) { - detailsHTML += `

新鲜程度: ${supply.freshness}

`; - } - - // 产品包装 - if (supply.producting) { - detailsHTML += `

产品包装: ${supply.producting}

`; - } - // 商品地区 if (supply.region) { detailsHTML += `

商品地区: ${supply.region}

`; } - // 商品联系人信息 - if (supply.product_contact) { - detailsHTML += `

商品联系人: ${supply.product_contact}

`; - } - - if (supply.contact_phone) { - detailsHTML += `

联系电话: ${supply.contact_phone}

`; - } - - // 种类 - if (supply.category) { - detailsHTML += `

种类: ${supply.category}

`; + // 商品联系人和联系电话一行展示,只显示联系人名称和电话号码 + if (supply.product_contact || supply.contact_phone) { + let contactText = `商品联系人: `; + if (supply.product_contact) { + contactText += supply.product_contact; + } + if (supply.contact_phone) { + if (supply.product_contact) { + contactText += ` ${supply.contact_phone}`; + } else { + contactText += supply.contact_phone; + } + } + detailsHTML += `

${contactText}

`; } // 创建时间 @@ -1180,13 +1189,38 @@ detailsHTML += `

修改时间: ${new Date(supply.updated_at).toLocaleString()}

`; } + // 货源描述(限制显示长度)- 灰色背景放在修改时间后面 + if (supply.description) { + const shortDesc = supply.description.length > 50 ? `${supply.description.substring(0, 50)}...` : supply.description; + detailsHTML += `
+ 货源描述: +
${shortDesc}
+
`; + } + + + // 状态 detailsHTML += `${statusText}`; + // 第一行展示:种类|蛋黄|货源类型|产品包装|新鲜程度,只展示数据 + let firstLineParts = []; + if (supply.category) firstLineParts.push(supply.category); + if (supply.yolk) firstLineParts.push(supply.yolk); + if (supply.sourceType) firstLineParts.push(supply.sourceType); + if (supply.producting) firstLineParts.push(supply.producting); + if (supply.freshness) firstLineParts.push(supply.freshness); + + let firstLineHTML = ''; + if (firstLineParts.length > 0) { + firstLineHTML = `

${firstLineParts.join(' | ')}

`; + } + card.innerHTML = `
${mediaElement}
${supply.productName}
+ ${firstLineHTML}
${detailsHTML}