| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>更新售后归档项目状态为已完成</title>
- <script src="https://cdn.jsdelivr.net/npm/parse@5.3.0/dist/parse.min.js"></script>
- <style>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
-
- body {
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- min-height: 100vh;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 20px;
- }
-
- .container {
- background: white;
- border-radius: 16px;
- box-shadow: 0 20px 60px rgba(0,0,0,0.2);
- padding: 40px;
- max-width: 800px;
- width: 100%;
- }
-
- h1 {
- color: #333;
- margin-bottom: 10px;
- font-size: 28px;
- font-weight: 600;
- }
-
- .subtitle {
- color: #666;
- margin-bottom: 30px;
- font-size: 14px;
- }
-
- .info-box {
- background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
- color: white;
- padding: 20px;
- border-radius: 12px;
- margin-bottom: 30px;
- line-height: 1.6;
- }
-
- .info-box strong {
- display: block;
- margin-bottom: 10px;
- font-size: 16px;
- }
-
- .info-box ul {
- margin-left: 20px;
- margin-top: 10px;
- }
-
- .info-box li {
- margin: 5px 0;
- }
-
- .btn-group {
- display: flex;
- gap: 15px;
- margin-bottom: 30px;
- }
-
- button {
- flex: 1;
- padding: 14px 24px;
- border: none;
- border-radius: 10px;
- font-size: 16px;
- font-weight: 600;
- cursor: pointer;
- transition: all 0.3s ease;
- font-family: inherit;
- }
-
- .btn-primary {
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: white;
- box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
- }
-
- .btn-primary:hover:not(:disabled) {
- transform: translateY(-2px);
- box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
- }
-
- .btn-secondary {
- background: #e0e0e0;
- color: #666;
- }
-
- .btn-secondary:hover:not(:disabled) {
- background: #d0d0d0;
- }
-
- button:disabled {
- opacity: 0.6;
- cursor: not-allowed;
- }
-
- .log-container {
- background: #f8f9fa;
- border: 1px solid #dee2e6;
- border-radius: 10px;
- padding: 20px;
- max-height: 500px;
- overflow-y: auto;
- font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
- font-size: 13px;
- line-height: 1.8;
- }
-
- .log-entry {
- margin: 8px 0;
- padding: 8px 12px;
- border-radius: 6px;
- display: flex;
- align-items: flex-start;
- gap: 10px;
- }
-
- .log-icon {
- flex-shrink: 0;
- font-size: 18px;
- }
-
- .log-info {
- background: #e3f2fd;
- border-left: 3px solid #2196f3;
- }
-
- .log-success {
- background: #e8f5e9;
- border-left: 3px solid #4caf50;
- }
-
- .log-warning {
- background: #fff3e0;
- border-left: 3px solid #ff9800;
- }
-
- .log-error {
- background: #ffebee;
- border-left: 3px solid #f44336;
- }
-
- .summary {
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: white;
- padding: 20px;
- border-radius: 10px;
- margin-top: 20px;
- display: none;
- }
-
- .summary.show {
- display: block;
- }
-
- .summary h3 {
- margin-bottom: 15px;
- font-size: 18px;
- }
-
- .summary-stats {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
- gap: 15px;
- }
-
- .stat-item {
- background: rgba(255,255,255,0.2);
- padding: 12px;
- border-radius: 8px;
- text-align: center;
- }
-
- .stat-value {
- display: block;
- font-size: 28px;
- font-weight: bold;
- margin-bottom: 5px;
- }
-
- .stat-label {
- font-size: 13px;
- opacity: 0.9;
- }
-
- .loading {
- display: inline-block;
- width: 20px;
- height: 20px;
- border: 3px solid rgba(255,255,255,0.3);
- border-radius: 50%;
- border-top-color: white;
- animation: spin 1s linear infinite;
- margin-left: 10px;
- }
-
- @keyframes spin {
- to { transform: rotate(360deg); }
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>🔄 更新售后归档项目状态</h1>
- <p class="subtitle">将所有 currentStage 为"售后归档"的项目状态更新为"已完成"</p>
-
- <div class="info-box">
- <strong>📋 操作说明</strong>
- <ul>
- <li>本工具会查询所有 <code>currentStage = '售后归档'</code> 的项目</li>
- <li>将这些项目的 <code>status</code> 字段更新为 <code>'已完成'</code></li>
- <li>更新后会在管理员端项目列表中正确显示为"已完成"状态</li>
- <li>此操作不可逆,请谨慎执行</li>
- </ul>
- </div>
-
- <div class="btn-group">
- <button class="btn-primary" id="updateBtn" onclick="updateProjects()">
- 🚀 开始更新
- </button>
- <button class="btn-secondary" onclick="clearLogs()">
- 🗑️ 清空日志
- </button>
- </div>
-
- <div class="log-container" id="logContainer"></div>
-
- <div class="summary" id="summary">
- <h3>📊 更新统计</h3>
- <div class="summary-stats">
- <div class="stat-item">
- <span class="stat-value" id="totalCount">0</span>
- <span class="stat-label">查询到的项目</span>
- </div>
- <div class="stat-item">
- <span class="stat-value" id="updatedCount">0</span>
- <span class="stat-label">成功更新</span>
- </div>
- <div class="stat-item">
- <span class="stat-value" id="failedCount">0</span>
- <span class="stat-label">更新失败</span>
- </div>
- <div class="stat-item">
- <span class="stat-value" id="skippedCount">0</span>
- <span class="stat-label">已经是已完成</span>
- </div>
- </div>
- </div>
- </div>
- <script>
- // 初始化 Parse
- Parse.initialize("fmode");
- Parse.serverURL = "https://server.fmode.cn/parse";
- Parse.masterKey = "F_MODE_MASTER_KEY"; // 请替换为实际的 Master Key
- function log(message, type = 'info') {
- const logContainer = document.getElementById('logContainer');
- const logEntry = document.createElement('div');
- logEntry.className = `log-entry log-${type}`;
-
- const icons = {
- info: 'ℹ️',
- success: '✅',
- warning: '⚠️',
- error: '❌'
- };
-
- logEntry.innerHTML = `
- <span class="log-icon">${icons[type]}</span>
- <div>${message}</div>
- `;
-
- logContainer.appendChild(logEntry);
- logContainer.scrollTop = logContainer.scrollHeight;
- }
- function clearLogs() {
- document.getElementById('logContainer').innerHTML = '';
- document.getElementById('summary').classList.remove('show');
- }
- async function updateProjects() {
- const updateBtn = document.getElementById('updateBtn');
- updateBtn.disabled = true;
- updateBtn.innerHTML = '更新中... <span class="loading"></span>';
-
- clearLogs();
-
- let totalCount = 0;
- let updatedCount = 0;
- let failedCount = 0;
- let skippedCount = 0;
-
- try {
- log('🔍 开始查询售后归档的项目...', 'info');
-
- // 查询所有 currentStage 为 '售后归档' 的项目
- const query = new Parse.Query('Project');
- query.equalTo('currentStage', '售后归档');
- query.notEqualTo('isDeleted', true);
- query.limit(1000);
-
- const projects = await query.find();
- totalCount = projects.length;
-
- log(`📊 找到 ${totalCount} 个售后归档的项目`, 'info');
-
- if (totalCount === 0) {
- log('✨ 没有需要更新的项目', 'warning');
- updateBtn.disabled = false;
- updateBtn.innerHTML = '🚀 开始更新';
- return;
- }
-
- log('', 'info');
- log('🔄 开始批量更新项目状态...', 'info');
-
- // 批量更新
- for (let i = 0; i < projects.length; i++) {
- const project = projects[i];
- const title = project.get('title') || '未命名项目';
- const currentStatus = project.get('status');
-
- try {
- // 如果已经是"已完成"状态,跳过
- if (currentStatus === '已完成') {
- log(`⏭️ [${i + 1}/${totalCount}] "${title}" - 已经是已完成状态,跳过`, 'warning');
- skippedCount++;
- continue;
- }
-
- // 更新状态
- project.set('status', '已完成');
- await project.save();
-
- updatedCount++;
- log(`✅ [${i + 1}/${totalCount}] 成功更新 "${title}" (${currentStatus} → 已完成)`, 'success');
- } catch (error) {
- failedCount++;
- log(`❌ [${i + 1}/${totalCount}] 更新失败 "${title}": ${error.message}`, 'error');
- }
- }
-
- // 显示统计摘要
- log('', 'info');
- log('🎉 更新完成!', 'success');
-
- document.getElementById('totalCount').textContent = totalCount;
- document.getElementById('updatedCount').textContent = updatedCount;
- document.getElementById('failedCount').textContent = failedCount;
- document.getElementById('skippedCount').textContent = skippedCount;
- document.getElementById('summary').classList.add('show');
-
- } catch (error) {
- log(`❌ 批量更新失败: ${error.message}`, 'error');
- console.error('更新错误:', error);
- } finally {
- updateBtn.disabled = false;
- updateBtn.innerHTML = '🚀 开始更新';
- }
- }
- // 页面加载时显示提示
- window.addEventListener('load', () => {
- log('👋 欢迎使用售后归档项目状态更新工具', 'info');
- log('📝 请点击"开始更新"按钮来执行批量更新', 'info');
- });
- </script>
- </body>
- </html>
|