微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
@@ -1,8 +1,84 @@
|
||||
/* task-detail 系列页面共享 — 备注弹窗 + Toast */
|
||||
/* task-detail 系列页面共享 — 备注弹窗 + Toast + 星星打分 */
|
||||
|
||||
/* ---- 星星打分交互 ---- */
|
||||
function initNoteRatings() {
|
||||
document.querySelectorAll('.note-rating-row').forEach(function (row) {
|
||||
var stars = row.querySelectorAll('.nr-star');
|
||||
var dragging = false;
|
||||
|
||||
function setScore(idx) {
|
||||
row.dataset.score = idx + 1;
|
||||
stars.forEach(function (s, i) {
|
||||
s.classList.toggle('active', i <= idx);
|
||||
});
|
||||
}
|
||||
|
||||
/* 点击 */
|
||||
stars.forEach(function (star, idx) {
|
||||
star.addEventListener('click', function () { setScore(idx); });
|
||||
});
|
||||
|
||||
/* 触摸拖动 */
|
||||
row.addEventListener('touchstart', function (e) { dragging = true; handleTouch(e); }, { passive: false });
|
||||
row.addEventListener('touchmove', function (e) { if (dragging) { e.preventDefault(); handleTouch(e); } }, { passive: false });
|
||||
row.addEventListener('touchend', function () { dragging = false; });
|
||||
|
||||
function handleTouch(e) {
|
||||
var touch = e.touches[0];
|
||||
for (var i = 0; i < stars.length; i++) {
|
||||
var rect = stars[i].getBoundingClientRect();
|
||||
if (touch.clientX >= rect.left && touch.clientX < rect.right) {
|
||||
setScore(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 鼠标拖动 */
|
||||
row.addEventListener('mousedown', function (e) { dragging = true; handleMouse(e); });
|
||||
document.addEventListener('mousemove', function (e) { if (dragging) handleMouse(e); });
|
||||
document.addEventListener('mouseup', function () { dragging = false; });
|
||||
|
||||
function handleMouse(e) {
|
||||
for (var i = 0; i < stars.length; i++) {
|
||||
var rect = stars[i].getBoundingClientRect();
|
||||
if (e.clientX >= rect.left && e.clientX < rect.right) {
|
||||
setScore(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function resetNoteRatings() {
|
||||
document.querySelectorAll('.note-rating-row').forEach(function (row) {
|
||||
row.dataset.score = '0';
|
||||
row.querySelectorAll('.nr-star').forEach(function (s) { s.classList.remove('active'); });
|
||||
});
|
||||
}
|
||||
|
||||
/* 页面加载后初始化 */
|
||||
document.addEventListener('DOMContentLoaded', initNoteRatings);
|
||||
|
||||
/* ---- 弹窗控制 ---- */
|
||||
function showNoteModal() {
|
||||
document.getElementById('noteModal').classList.remove('hidden');
|
||||
document.getElementById('noteModal').classList.add('flex');
|
||||
document.getElementById('noteText').value = '';
|
||||
resetNoteRatings();
|
||||
/* 重置展开状态 */
|
||||
var sec = document.getElementById('noteRatingSection');
|
||||
var btn = document.getElementById('noteExpandBtn');
|
||||
if (sec) sec.classList.add('hidden');
|
||||
if (btn) btn.classList.remove('hidden');
|
||||
}
|
||||
|
||||
function expandNoteRating() {
|
||||
var sec = document.getElementById('noteRatingSection');
|
||||
var btn = document.getElementById('noteExpandBtn');
|
||||
if (sec) sec.classList.remove('hidden');
|
||||
if (btn) btn.classList.add('hidden');
|
||||
}
|
||||
|
||||
function hideNoteModal() {
|
||||
|
||||
Reference in New Issue
Block a user