feat: 支持项目库自定义技术选型
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
<form method="post" action="{% url 'projects:plan_save' project.slug %}">
|
||||
{% csrf_token %}
|
||||
<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 %}
|
||||
<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 }}
|
||||
@@ -135,6 +135,11 @@
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</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>
|
||||
<textarea class="field" name="architecture" rows="3" placeholder="例如:纯前端单页,数据存在 IndexedDB,不做账号体系,导出走浏览器下载。">{{ project.architecture }}</textarea>
|
||||
|
||||
+9
-1
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user