Browse Source

修改时间,前台展示逻辑

master
maziyang 3 months ago
parent
commit
4053c78efe
  1. 38
      adminConfig.html
  2. 36
      adminDetail.html
  3. 31
      index.html

38
adminConfig.html

@ -196,7 +196,7 @@
<script type="module">
import { getLandingListApi, addLandingApi } from './src/api/member.js';
(function () {
const FILE_UPLOAD_URL = 'http://tjapi.hlquant.com/hljwgo/api/file/upload';
const FILE_UPLOAD_URL = 'https://tjapi.hlquant.com/hljwgo/api/file/upload';
// 状态
let tableData = [];
let currentPage = 1;
@ -236,7 +236,6 @@
const popupPreviewContainer = document.getElementById('popupPreviewContainer');
const loadingIndicator = document.getElementById('loadingIndicator');
const noData = document.getElementById('noData');
// 工具:显示消息(简单替代 ElMessage)
function showMessage(text, type = 'success', duration = 3000) {
let el = document.getElementById('msgBoxTop');
@ -302,6 +301,13 @@ function showMessage(text, type = 'success', duration = 3000) {
}
}
// 更严格的判断(使用 Date)
function isDialogTimeRangeValid() {
if (!fldStart.value || !fldEnd.value) return true; // 有空值不强制
const s = new Date(fldStart.value);
const e = new Date(fldEnd.value);
return e >= s;
}
function renderTable() {
tableBody.innerHTML = '';
if (!tableData || tableData.length === 0) {
@ -330,7 +336,7 @@ function showMessage(text, type = 'success', duration = 3000) {
const btnDetail = document.createElement('button'); btnDetail.className = 'btn'; btnDetail.textContent = '详情';
btnDetail.addEventListener('click', () => {
window.location.href = `/adminDetail.html?id=${row.id}`;
window.location.href = `/parkActivity/adminDetail.html?id=${row.id}`;
});
tdOps.appendChild(btnDetail);
@ -363,14 +369,6 @@ function showMessage(text, type = 'success', duration = 3000) {
currentPage = 1;
getLandingList();
});
// gotoBtn.addEventListener('click', () => {
// const v = parseInt(gotoInput.value, 10);
// if (!isNaN(v) && v >= 1) {
// currentPage = v;
// getLandingList();
// }
// });
// 打开新增弹窗
btnAdd.addEventListener('click', () => {
openAddDialog();
@ -443,6 +441,13 @@ function showMessage(text, type = 'success', duration = 3000) {
inputLanding.addEventListener('change', (e) => {
const f = e.target.files[0];
if (!f) return;
if (f.size > 2 * 1024 * 1024) {
showMessage('图片大小不能超过 2MB', 'error');
e.target.value = '';
if (typeof landingFile !== 'undefined') landingFile = null;
if (landingPreviewContainer) landingPreviewContainer.innerHTML = '';
return;
}
const reader = new FileReader();
reader.onload = function (ev) {
const img = new Image();
@ -469,6 +474,13 @@ function showMessage(text, type = 'success', duration = 3000) {
inputPopup.addEventListener('change', (e) => {
const f = e.target.files[0];
if (!f) return;
if (f.size > 2 * 1024 * 1024) {
showMessage('图片大小不能超过 2MB', 'error');
e.target.value = '';
if (typeof popupFile !== 'undefined') popupFile = null;
if (popupPreviewContainer) popupPreviewContainer.innerHTML = '';
return;
}
const reader = new FileReader();
reader.onload = function (ev) {
popupFile = f;
@ -491,6 +503,10 @@ function showMessage(text, type = 'success', duration = 3000) {
if (!introduction) { showMessage('请输入活动简介', 'error'); return; }
if (!startTime) { showMessage('请选择开始时间', 'error'); return; }
if (!endTime) { showMessage('请选择结束时间', 'error'); return; }
if (!isDialogTimeRangeValid()) {
showMessage('结束时间不能早于开始时间,请调整后保存', 'error');
return;
}
// 如果既没有已上传的 url,也没有本地文件,则提示
if (!landingUploadedUrl && !landingFile) { showMessage('请上传活动落地页', 'error'); return; }
if (!popupUploadedUrl && !popupFile) { showMessage('请上传落地页弹窗', 'error'); return; }

36
adminDetail.html

@ -231,7 +231,42 @@ function showMessage(text, type = 'success', duration = 3000) {
const sp = new URLSearchParams(location.search);
return sp.get(name);
}
function syncEndMinWithStart() {
if (!filterStart || !filterEnd) return;
// set min attribute on end input so browser picker enforces it
if (filterStart.value) {
filterEnd.min = filterStart.value;
} else {
filterEnd.removeAttribute('min');
}
}
function isTimeRangeValid() {
if (!filterStart.value || !filterEnd.value) return true; // 空值不做强制(按需求可改)
// Compare strings directly is OK for datetime-local "YYYY-MM-DDTHH:MM" format
return filterEnd.value >= filterStart.value;
}
// 绑定事件:开始时间变化时更新 end.min,并修正 end 小于 start 的情况
filterStart && filterStart.addEventListener('change', () => {
syncEndMinWithStart();
if (filterEnd.value && filterEnd.value < filterStart.value) {
// 把结束时间自动设为开始时间,提示用户
filterEnd.value = filterStart.value;
showMessage('结束时间已被调整为不早于开始时间', 'error');
}
});
// 绑定事件:结束时间变化时校验,如果不合法则阻止并提示(并回退到开始时间或清空)
filterEnd && filterEnd.addEventListener('change', () => {
if (!isTimeRangeValid()) {
showMessage('结束时间不能早于开始时间,请调整', 'error');
// 方案:把结束时间重置为开始时间(更直观),也可选择清空
if (filterStart.value) {
filterEnd.value = filterStart.value;
} else {
filterEnd.value = '';
}
}
});
// 构建列表查询参数对象
function buildQueryParams() {
const id = parseQueryParam('id');
@ -287,6 +322,7 @@ function showMessage(text, type = 'success', duration = 3000) {
tableBody.innerHTML = '';
if (!tableData || tableData.length === 0) {
noData.style.display = 'block';
return
} else {
noData.style.display = 'none';
}

31
index.html

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>新时代、新龙头、新节奏</title>
<title></title>
<style>
* {
margin: 0;
@ -122,11 +122,13 @@
if (res.code == 200 && res.data) {
return {
landingImageUrl: res.data.list[0].landing_page,
popupImageUrl: res.data.list[0].landing_page_popup
popupImageUrl: res.data.list[0].landing_page_popup,
title: res.data.list[0].name
};
} else {
console.warn('网络错误,请稍后重试');
return null;
return {
msg:res.msg
};
}
} catch (error) {
console.error('网络错误,请稍后重试');
@ -150,7 +152,26 @@
// 确定最终落地图和是否展示弹窗
let finalLandingUrl;
let shouldShowPopup = false;
document.title = imagePaths.title?imagePaths.title:imagePaths.msg
if(imagePaths?.msg){
document.body.innerHTML = `
<div style="
display:flex;
align-items:center;
justify-content:center;
height:100vh;
font-size:40px;
color:#333;
font-family:'PingFang SC', 'Microsoft Yahei', Arial, sans-serif;
text-align:center;
padding:20px;
box-sizing:border-box;
">
${imagePaths.msg}
</div>
`;
return
}
if (imagePaths?.landingImageUrl) {
finalLandingUrl = imagePaths.landingImageUrl;
// if (!cachedImage || cachedImage.url !== finalLandingUrl) {

Loading…
Cancel
Save