feat: 支持项目库自定义技术选型

This commit is contained in:
2026-11-26 20:45:14 +08:00
parent 0c4ff1df5e
commit ef79950a3f
4 changed files with 63 additions and 2 deletions
+5
View File
@@ -510,3 +510,8 @@ h1,h2,h3 { font-family: var(--serif); }
.trow .x:hover { color:var(--bad); } .trow .x:hover { color:var(--bad); }
.hint { font-size:12px;color:var(--muted); } .hint { font-size:12px;color:var(--muted); }
.repo-card .tag { display:inline-block; } .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; }
+43
View File
@@ -32,4 +32,47 @@
if (chip) chip.classList.toggle('on', cb.checked); 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();
}
});
}
})(); })();
+6 -1
View File
@@ -123,7 +123,7 @@
<form method="post" action="{% url 'projects:plan_save' project.slug %}"> <form method="post" action="{% url 'projects:plan_save' project.slug %}">
{% csrf_token %} {% csrf_token %}
<div class="sec"><h3>技术选型(可多选)</h3><span class="cnt">{{ project.tech_stack|length }} 项</span></div> <div class="sec"><h3>技术选型(可多选)</h3><span class="cnt">{{ project.tech_stack|length }} 项</span></div>
<div class="chips"> <div class="chips" id="stackChips">
{% for opt in stack_options %} {% for opt in stack_options %}
<label class="chip {% if opt in project.tech_stack %}on{% endif %}"> <label class="chip {% if opt in project.tech_stack %}on{% endif %}">
<input type="checkbox" name="stack" value="{{ opt }}" {% if opt in project.tech_stack %}checked{% endif %}>{{ opt }} <input type="checkbox" name="stack" value="{{ opt }}" {% if opt in project.tech_stack %}checked{% endif %}>{{ opt }}
@@ -135,6 +135,11 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
<div class="custom-stack-row">
<input class="field" id="customStack" name="custom_stack" placeholder="添加自定义技术,多个用逗号分隔,例如:FastAPI, Astro">
<button class="mini" type="button" id="addCustomStack">添加</button>
<span class="hint">不在上面的选项里?直接写进来,保存后会作为可取消的选项保留。</span>
</div>
<div class="sec"><h3>用一句话说清架构</h3></div> <div class="sec"><h3>用一句话说清架构</h3></div>
<textarea class="field" name="architecture" rows="3" placeholder="例如:纯前端单页,数据存在 IndexedDB,不做账号体系,导出走浏览器下载。">{{ project.architecture }}</textarea> <textarea class="field" name="architecture" rows="3" placeholder="例如:纯前端单页,数据存在 IndexedDB,不做账号体系,导出走浏览器下载。">{{ project.architecture }}</textarea>
+9 -1
View File
@@ -2,6 +2,7 @@
import hmac import hmac
import json import json
import re
import time import time
from datetime import datetime, timezone as dt_timezone from datetime import datetime, timezone as dt_timezone
from functools import wraps from functools import wraps
@@ -572,7 +573,14 @@ def plan_save(request, slug):
item = item.strip() item = item.strip()
if item and item not in stack: if item and item not in stack:
stack.append(item[:40]) 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.architecture = (request.POST.get("architecture") or "").strip()
project.non_goals = [ project.non_goals = [
line.strip()[:160] line.strip()[:160]