diff --git a/projects/static/projects/projects.css b/projects/static/projects/projects.css index 5273de3..539e11e 100644 --- a/projects/static/projects/projects.css +++ b/projects/static/projects/projects.css @@ -510,3 +510,8 @@ h1,h2,h3 { font-family: var(--serif); } .trow .x:hover { color:var(--bad); } .hint { font-size:12px;color:var(--muted); } .repo-card .tag { display:inline-block; } + +/* 自定义技术选型 */ +.custom-stack-row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-top:10px; } +.custom-stack-row .field { max-width:360px; padding:7px 10px; font-size:12px; } +.custom-stack-row .hint { font-size:11px; } diff --git a/projects/static/projects/projects.js b/projects/static/projects/projects.js index 007dbf0..8d365c6 100644 --- a/projects/static/projects/projects.js +++ b/projects/static/projects/projects.js @@ -32,4 +32,47 @@ if (chip) chip.classList.toggle('on', cb.checked); }); }); + + var stackChips = document.getElementById('stackChips'); + var customStack = document.getElementById('customStack'); + var addCustomStack = document.getElementById('addCustomStack'); + + function addCustomStackValues() { + if (!stackChips || !customStack) return; + var values = (customStack.value || '').split(/[,,\n]+/); + values.forEach(function (raw) { + var value = (raw || '').trim(); + if (!value) return; + var exists = Array.prototype.some.call( + stackChips.querySelectorAll('input[name="stack"]'), + function (input) { return input.value === value; } + ); + if (exists) return; + var label = document.createElement('label'); + label.className = 'chip on'; + var input = document.createElement('input'); + input.type = 'checkbox'; + input.name = 'stack'; + input.value = value; + input.checked = true; + input.addEventListener('change', function () { + label.classList.toggle('on', input.checked); + }); + label.appendChild(input); + label.appendChild(document.createTextNode(value)); + stackChips.appendChild(label); + }); + customStack.value = ''; + customStack.focus(); + } + + if (addCustomStack) addCustomStack.addEventListener('click', addCustomStackValues); + if (customStack) { + customStack.addEventListener('keydown', function (event) { + if (event.key === 'Enter') { + event.preventDefault(); + addCustomStackValues(); + } + }); + } })(); diff --git a/projects/templates/projects/detail.html b/projects/templates/projects/detail.html index e773565..5e19a2e 100644 --- a/projects/templates/projects/detail.html +++ b/projects/templates/projects/detail.html @@ -123,7 +123,7 @@
{% csrf_token %}

技术选型(可多选)

{{ project.tech_stack|length }} 项
-
+
{% for opt in stack_options %}
+
+ + + 不在上面的选项里?直接写进来,保存后会作为可取消的选项保留。 +

用一句话说清架构

diff --git a/projects/views.py b/projects/views.py index ee75354..393fe66 100644 --- a/projects/views.py +++ b/projects/views.py @@ -2,6 +2,7 @@ import hmac import json +import re import time from datetime import datetime, timezone as dt_timezone from functools import wraps @@ -572,7 +573,14 @@ def plan_save(request, slug): item = item.strip() if item and item not in stack: stack.append(item[:40]) - project.tech_stack = stack + # 自定义技术:逗号 / 中文逗号 / 换行分隔,去重后一并入库 + raw_custom = (request.POST.get("custom_stack") or "").strip() + if raw_custom: + for item in re.split(r"[,,\n]+", raw_custom): + item = item.strip() + if item and item not in stack: + stack.append(item[:40]) + project.tech_stack = stack[:40] project.architecture = (request.POST.get("architecture") or "").strip() project.non_goals = [ line.strip()[:160]