openprototype 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +58 -0
- package/CONVENTIONS.md +54 -0
- package/LICENSE +21 -0
- package/README.md +233 -2
- package/bin/cli.js +297 -0
- package/lib/config.js +162 -0
- package/package.json +32 -10
- package/product/demo/pc/customer/customer_form.html +134 -0
- package/product/demo/pc/customer/customer_form.md +33 -0
- package/product/demo/pc/customer/customer_list.html +129 -0
- package/product/demo/pc/customer/customer_list.md +35 -0
- package/product/demo/pc/demo-data.js +23 -0
- package/product/demo/pc/index.html +1069 -0
- package/product/demo/pc/nav-tree.json +15 -0
- package/proto-kit.config.json +13 -0
- package/runtime/server.js +664 -0
- package/runtime/shared/ai-polish.js +159 -0
- package/runtime/shared/base-manager.js +168 -0
- package/runtime/shared/common/component-renderer.js +917 -0
- package/runtime/shared/common/copy-manager.js +134 -0
- package/runtime/shared/common/data-bridge.js +45 -0
- package/runtime/shared/common/form-renderer.js +211 -0
- package/runtime/shared/common/form.js +357 -0
- package/runtime/shared/common/formatter.js +78 -0
- package/runtime/shared/common/index.js +37 -0
- package/runtime/shared/common/line-chart.js +357 -0
- package/runtime/shared/common/modal-manager.js +82 -0
- package/runtime/shared/common/prd-panel.js +1014 -0
- package/runtime/shared/common/prd-popup.js +168 -0
- package/runtime/shared/common/search-renderer.js +95 -0
- package/runtime/shared/common/table-renderer.js +177 -0
- package/runtime/shared/common/table.js +160 -0
- package/runtime/shared/common/toast.js +99 -0
- package/runtime/shared/common/ui-preference-manager.js +74 -0
- package/runtime/shared/common/view-mode.js +30 -0
- package/runtime/shared/common.js +43 -0
- package/runtime/shared/constants/icons.js +28 -0
- package/runtime/shared/constants/status.js +67 -0
- package/runtime/shared/libs/marked.min.js +69 -0
- package/runtime/shared/prd-content.js +9 -0
- package/runtime/shared/styles.css +7673 -0
- package/runtime/shared/utils.js +110 -0
- package/runtime/shared/view-controls.js +148 -0
- package/runtime/shell/agent-panel.css +429 -0
- package/runtime/shell/agent-panel.js +629 -0
- package/scripts/check/run-checks.js +58 -0
- package/scripts/check/smoke-test.js +244 -0
- package/scripts/check/static-check.js +248 -0
- package/scripts/check/sync-nav-tree.js +139 -0
- package/templates/AGENTS.md +58 -0
- package/templates/CONVENTIONS.md +54 -0
- package/templates/gitignore +10 -0
- package/templates/product-shell/index.html +1069 -0
- package/templates/skills/auto-test/SKILL.md +62 -0
- package/templates/skills/xiaojia/SKILL.md +299 -0
- package/cli.js +0 -4
package/lib/config.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 配置加载 + OpenCode 二进制自动探测。
|
|
5
|
+
* 所有"写死的"东西(端口、OpenCode 路径/模型、产品根目录)都在这里集中收口,
|
|
6
|
+
* server.js / scripts 只读这里,不再各自硬编码。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const { spawnSync } = require('child_process');
|
|
13
|
+
|
|
14
|
+
const CONFIG_FILENAME = 'proto-kit.config.json';
|
|
15
|
+
|
|
16
|
+
const DEFAULTS = {
|
|
17
|
+
port: 8082,
|
|
18
|
+
// 服务器监听地址。默认只绑本机;需要给局域网同事演示时改成 '0.0.0.0'
|
|
19
|
+
// (写入 / Agent 类 /api/* 接口始终只接受本机请求,不随该项放开)。
|
|
20
|
+
host: '127.0.0.1',
|
|
21
|
+
opencode: {
|
|
22
|
+
bin: 'auto',
|
|
23
|
+
model: 'deepseek/deepseek-v4-flash',
|
|
24
|
+
agent: 'build',
|
|
25
|
+
host: '127.0.0.1',
|
|
26
|
+
port: 4097,
|
|
27
|
+
startTimeoutMs: 15000
|
|
28
|
+
},
|
|
29
|
+
// 每个产品一个入口目录;roots 目前只支持 'pc'('h5' 后续再加)
|
|
30
|
+
products: [{ id: 'demo', roots: ['pc'] }]
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function deepMerge(base, override) {
|
|
34
|
+
if (!override || typeof override !== 'object') return base;
|
|
35
|
+
const out = Array.isArray(base) ? base.slice() : Object.assign({}, base);
|
|
36
|
+
Object.keys(override).forEach((key) => {
|
|
37
|
+
const value = override[key];
|
|
38
|
+
if (value && typeof value === 'object' && !Array.isArray(value) && base && typeof base[key] === 'object') {
|
|
39
|
+
out[key] = deepMerge(base[key], value);
|
|
40
|
+
} else {
|
|
41
|
+
out[key] = value;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function findProjectRoot(startDir) {
|
|
48
|
+
let dir = path.resolve(startDir || process.cwd());
|
|
49
|
+
while (true) {
|
|
50
|
+
if (fs.existsSync(path.join(dir, CONFIG_FILENAME))) return dir;
|
|
51
|
+
const parent = path.dirname(dir);
|
|
52
|
+
if (parent === dir) break;
|
|
53
|
+
dir = parent;
|
|
54
|
+
}
|
|
55
|
+
// 没找到配置文件时,退回到起始目录(首次运行 / 未初始化的场景)
|
|
56
|
+
return path.resolve(startDir || process.cwd());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function loadRawConfig(rootDir) {
|
|
60
|
+
const file = path.join(rootDir, CONFIG_FILENAME);
|
|
61
|
+
if (!fs.existsSync(file)) return {};
|
|
62
|
+
try {
|
|
63
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
64
|
+
} catch (err) {
|
|
65
|
+
throw new Error(`${CONFIG_FILENAME} 解析失败:${err.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 跨平台探测 opencode 可执行文件。
|
|
71
|
+
* 顺序:显式路径 → PATH(which/where) → 常见安装位。找不到返回 null(由调用方给安装引导)。
|
|
72
|
+
*/
|
|
73
|
+
function detectOpenCodeBin(explicit) {
|
|
74
|
+
if (explicit && explicit !== 'auto') {
|
|
75
|
+
return fs.existsSync(explicit) ? explicit : explicit; // 用户写死了就用它,存在与否交给 spawn 报错
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const isWin = process.platform === 'win32';
|
|
79
|
+
const lookup = isWin ? 'where' : 'which';
|
|
80
|
+
try {
|
|
81
|
+
const result = spawnSync(lookup, ['opencode'], { encoding: 'utf8' });
|
|
82
|
+
if (result.status === 0 && result.stdout) {
|
|
83
|
+
const first = result.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0];
|
|
84
|
+
if (first && fs.existsSync(first)) return first;
|
|
85
|
+
}
|
|
86
|
+
} catch (err) {
|
|
87
|
+
// ignore,继续查常见位置
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const home = os.homedir();
|
|
91
|
+
const candidates = isWin
|
|
92
|
+
? [
|
|
93
|
+
path.join(process.env.APPDATA || '', 'npm', 'opencode.cmd'),
|
|
94
|
+
path.join(home, 'AppData', 'Local', 'opencode', 'opencode.exe'),
|
|
95
|
+
path.join(home, '.opencode', 'bin', 'opencode.exe')
|
|
96
|
+
]
|
|
97
|
+
: [
|
|
98
|
+
'/opt/homebrew/bin/opencode',
|
|
99
|
+
'/usr/local/bin/opencode',
|
|
100
|
+
path.join(home, '.opencode', 'bin', 'opencode'),
|
|
101
|
+
path.join(home, '.local', 'bin', 'opencode')
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
for (const candidate of candidates) {
|
|
105
|
+
if (candidate && fs.existsSync(candidate)) return candidate;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 返回归一化后的运行时配置。
|
|
112
|
+
* @param {string} [startDir] 从哪个目录起找配置(默认 cwd)
|
|
113
|
+
*/
|
|
114
|
+
function loadConfig(startDir) {
|
|
115
|
+
const rootDir = findProjectRoot(startDir);
|
|
116
|
+
const raw = loadRawConfig(rootDir);
|
|
117
|
+
|
|
118
|
+
const merged = deepMerge(DEFAULTS, raw);
|
|
119
|
+
|
|
120
|
+
// 环境变量优先级最高(方便 CI / 临时覆盖)
|
|
121
|
+
if (process.env.PROTO_KIT_PORT) merged.port = Number(process.env.PROTO_KIT_PORT);
|
|
122
|
+
if (process.env.PROTO_KIT_HOST) merged.host = process.env.PROTO_KIT_HOST;
|
|
123
|
+
if (process.env.OPENCODE_BIN) merged.opencode.bin = process.env.OPENCODE_BIN;
|
|
124
|
+
if (process.env.OPENCODE_MODEL) merged.opencode.model = process.env.OPENCODE_MODEL;
|
|
125
|
+
if (process.env.OPENCODE_PORT) merged.opencode.port = Number(process.env.OPENCODE_PORT);
|
|
126
|
+
|
|
127
|
+
const resolvedBin = detectOpenCodeBin(merged.opencode.bin);
|
|
128
|
+
|
|
129
|
+
// 每个产品入口目录的绝对路径,供 Agent 写入白名单 & 静态服务使用
|
|
130
|
+
const productRoots = [];
|
|
131
|
+
(merged.products || []).forEach((product) => {
|
|
132
|
+
(product.roots || ['pc']).forEach((root) => {
|
|
133
|
+
productRoots.push({
|
|
134
|
+
id: product.id,
|
|
135
|
+
surface: root,
|
|
136
|
+
dir: path.resolve(rootDir, 'product', product.id, root)
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
rootDir,
|
|
143
|
+
configFile: path.join(rootDir, CONFIG_FILENAME),
|
|
144
|
+
hasConfigFile: fs.existsSync(path.join(rootDir, CONFIG_FILENAME)),
|
|
145
|
+
port: merged.port,
|
|
146
|
+
host: merged.host,
|
|
147
|
+
opencode: {
|
|
148
|
+
bin: resolvedBin, // null 表示没找到
|
|
149
|
+
binConfigured: merged.opencode.bin,
|
|
150
|
+
model: merged.opencode.model,
|
|
151
|
+
agent: merged.opencode.agent,
|
|
152
|
+
host: merged.opencode.host,
|
|
153
|
+
port: merged.opencode.port,
|
|
154
|
+
baseUrl: `http://${merged.opencode.host}:${merged.opencode.port}`,
|
|
155
|
+
startTimeoutMs: merged.opencode.startTimeoutMs
|
|
156
|
+
},
|
|
157
|
+
products: merged.products || [],
|
|
158
|
+
productRoots
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = { loadConfig, detectOpenCodeBin, findProjectRoot, DEFAULTS, CONFIG_FILENAME };
|
package/package.json
CHANGED
|
@@ -1,32 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openprototype",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "本地原型工作台:左侧树形导航 + 中间原型预览 + 右侧 AI Agent(OpenCode)。PRD 与 HTML/JS 原型协作,含自动化检查。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prototype",
|
|
7
7
|
"prd",
|
|
8
8
|
"opencode",
|
|
9
9
|
"agent",
|
|
10
|
-
"scaffold"
|
|
10
|
+
"scaffold",
|
|
11
|
+
"product-manager"
|
|
11
12
|
],
|
|
12
13
|
"license": "MIT",
|
|
13
14
|
"author": "lightdoodleh",
|
|
14
15
|
"repository": {
|
|
15
16
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/lightdoodleh/
|
|
17
|
+
"url": "git+https://github.com/lightdoodleh/openprototype.git"
|
|
17
18
|
},
|
|
18
|
-
"homepage": "https://github.com/lightdoodleh/
|
|
19
|
-
"bugs": "https://github.com/lightdoodleh/
|
|
19
|
+
"homepage": "https://github.com/lightdoodleh/openprototype#readme",
|
|
20
|
+
"bugs": "https://github.com/lightdoodleh/openprototype/issues",
|
|
20
21
|
"engines": {
|
|
21
22
|
"node": ">=16"
|
|
22
23
|
},
|
|
23
24
|
"bin": {
|
|
24
|
-
"openprototype": "cli.js"
|
|
25
|
+
"openprototype": "bin/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"main": "runtime/server.js",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"serve": "node runtime/server.js",
|
|
30
|
+
"start": "node runtime/server.js",
|
|
31
|
+
"check": "node scripts/check/run-checks.js",
|
|
32
|
+
"check:changed": "node scripts/check/run-checks.js --changed",
|
|
33
|
+
"check:static": "node scripts/check/static-check.js",
|
|
34
|
+
"check:smoke": "node scripts/check/smoke-test.js",
|
|
35
|
+
"nav:sync": "node scripts/check/sync-nav-tree.js",
|
|
36
|
+
"doctor": "node bin/cli.js doctor",
|
|
37
|
+
"postinstall:browser": "playwright install chromium"
|
|
25
38
|
},
|
|
26
39
|
"files": [
|
|
27
|
-
"
|
|
40
|
+
"bin/",
|
|
41
|
+
"lib/",
|
|
42
|
+
"runtime/",
|
|
43
|
+
"scripts/",
|
|
44
|
+
"templates/",
|
|
45
|
+
"product/demo/",
|
|
46
|
+
"proto-kit.config.json",
|
|
47
|
+
"AGENTS.md",
|
|
48
|
+
"CONVENTIONS.md",
|
|
49
|
+
"README.md"
|
|
28
50
|
],
|
|
29
|
-
"
|
|
30
|
-
"
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"playwright": "^1.49.0"
|
|
31
53
|
}
|
|
32
54
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>客户表单 - Demo</title>
|
|
7
|
+
<style>
|
|
8
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
9
|
+
body {
|
|
10
|
+
margin: 0;
|
|
11
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
|
|
12
|
+
font-size: 13px; color: #20242d; background: #f3f5f8; padding: 20px;
|
|
13
|
+
}
|
|
14
|
+
.page-title { font-size: 18px; font-weight: 600; margin: 0 0 16px; }
|
|
15
|
+
.panel { background: #fff; border: 1px solid #e6ebf2; border-radius: 8px; padding: 20px; }
|
|
16
|
+
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
|
|
17
|
+
.form-item { display: flex; flex-direction: column; gap: 6px; }
|
|
18
|
+
.form-item.span-3 { grid-column: 1 / -1; }
|
|
19
|
+
.form-item label { font-size: 12px; color: #6b7482; }
|
|
20
|
+
.form-item .req::before { content: '*'; color: #e53935; margin-right: 2px; }
|
|
21
|
+
.form-item input, .form-item select, .form-item textarea {
|
|
22
|
+
min-height: 32px; padding: 6px 10px; border: 1px solid #dfe5ee; border-radius: 6px; font-size: 13px; outline: none; width: 100%;
|
|
23
|
+
}
|
|
24
|
+
.form-item input:focus, .form-item select:focus, .form-item textarea:focus { border-color: #1677ff; }
|
|
25
|
+
.readonly-text { min-height: 32px; padding: 6px 0; color: #20242d; }
|
|
26
|
+
.footer { display: flex; gap: 10px; margin-top: 24px; }
|
|
27
|
+
.btn { height: 34px; padding: 0 20px; border-radius: 6px; font-size: 13px; cursor: pointer; border: 1px solid #dfe5ee; background: #fff; color: #4f5665; }
|
|
28
|
+
.btn-primary { background: #1677ff; border-color: #1677ff; color: #fff; }
|
|
29
|
+
.btn-primary:hover { background: #0d5edb; }
|
|
30
|
+
</style>
|
|
31
|
+
</head>
|
|
32
|
+
<body>
|
|
33
|
+
<h1 class="page-title" id="pageTitle">新增客户</h1>
|
|
34
|
+
|
|
35
|
+
<div class="panel">
|
|
36
|
+
<div class="form-grid">
|
|
37
|
+
<div class="form-item">
|
|
38
|
+
<label class="req">客户名称</label>
|
|
39
|
+
<input id="fName" type="text" placeholder="请输入">
|
|
40
|
+
<div class="readonly-text" id="vName" style="display:none"></div>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="form-item">
|
|
43
|
+
<label class="req">联系人</label>
|
|
44
|
+
<input id="fContact" type="text" placeholder="请输入">
|
|
45
|
+
<div class="readonly-text" id="vContact" style="display:none"></div>
|
|
46
|
+
</div>
|
|
47
|
+
<div class="form-item">
|
|
48
|
+
<label>联系电话</label>
|
|
49
|
+
<input id="fPhone" type="text" placeholder="请输入">
|
|
50
|
+
<div class="readonly-text" id="vPhone" style="display:none"></div>
|
|
51
|
+
</div>
|
|
52
|
+
<div class="form-item">
|
|
53
|
+
<label>客户等级</label>
|
|
54
|
+
<select id="fLevel">
|
|
55
|
+
<option value="A">A 类</option>
|
|
56
|
+
<option value="B">B 类</option>
|
|
57
|
+
<option value="C">C 类</option>
|
|
58
|
+
</select>
|
|
59
|
+
<div class="readonly-text" id="vLevel" style="display:none"></div>
|
|
60
|
+
</div>
|
|
61
|
+
<div class="form-item">
|
|
62
|
+
<label>状态</label>
|
|
63
|
+
<select id="fStatus">
|
|
64
|
+
<option value="active">启用</option>
|
|
65
|
+
<option value="disabled">停用</option>
|
|
66
|
+
</select>
|
|
67
|
+
<div class="readonly-text" id="vStatus" style="display:none"></div>
|
|
68
|
+
</div>
|
|
69
|
+
<div class="form-item span-3">
|
|
70
|
+
<label>备注</label>
|
|
71
|
+
<textarea id="fRemark" rows="3" placeholder="请输入"></textarea>
|
|
72
|
+
<div class="readonly-text" id="vRemark" style="display:none"></div>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div class="footer" id="footer">
|
|
77
|
+
<button class="btn btn-primary" id="btnSave">保存</button>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<script src="/_kit/shared/base-manager.js"></script>
|
|
82
|
+
<script src="/product/demo/pc/demo-data.js"></script>
|
|
83
|
+
<script>
|
|
84
|
+
const params = new URLSearchParams(location.search);
|
|
85
|
+
const mode = params.get('mode');
|
|
86
|
+
const id = params.get('id');
|
|
87
|
+
const isView = mode === 'view';
|
|
88
|
+
|
|
89
|
+
const fields = ['Name', 'Contact', 'Phone', 'Level', 'Status', 'Remark'];
|
|
90
|
+
const keyMap = { Name: 'name', Contact: 'contact', Phone: 'phone', Level: 'level', Status: 'status', Remark: 'remark' };
|
|
91
|
+
const labelMap = { Level: DEMO_LEVEL_LABELS, Status: DEMO_STATUS_LABELS };
|
|
92
|
+
|
|
93
|
+
if (id) {
|
|
94
|
+
const item = demoCustomerManager.getItemById(id) || {};
|
|
95
|
+
fields.forEach(f => {
|
|
96
|
+
const el = document.getElementById('f' + f);
|
|
97
|
+
if (el) el.value = item[keyMap[f]] || (f === 'Level' ? 'A' : f === 'Status' ? 'active' : '');
|
|
98
|
+
});
|
|
99
|
+
document.getElementById('pageTitle').textContent = isView ? '查看客户' : '编辑客户';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 红线 4:mode=view 物理隐藏所有输入控件与提交按钮,改显示只读文本
|
|
103
|
+
if (isView) {
|
|
104
|
+
fields.forEach(f => {
|
|
105
|
+
const input = document.getElementById('f' + f);
|
|
106
|
+
const view = document.getElementById('v' + f);
|
|
107
|
+
if (input) input.style.display = 'none';
|
|
108
|
+
if (view) {
|
|
109
|
+
let val = input ? input.value : '';
|
|
110
|
+
if (labelMap[f]) val = labelMap[f][val] || val;
|
|
111
|
+
view.textContent = val || '-';
|
|
112
|
+
view.style.display = 'block';
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
document.getElementById('footer').style.display = 'none';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
document.getElementById('btnSave').addEventListener('click', () => {
|
|
119
|
+
const item = {
|
|
120
|
+
id: id || demoCustomerManager.getNextId(),
|
|
121
|
+
name: document.getElementById('fName').value.trim(),
|
|
122
|
+
contact: document.getElementById('fContact').value.trim(),
|
|
123
|
+
phone: document.getElementById('fPhone').value.trim(),
|
|
124
|
+
level: document.getElementById('fLevel').value,
|
|
125
|
+
status: document.getElementById('fStatus').value,
|
|
126
|
+
remark: document.getElementById('fRemark').value.trim()
|
|
127
|
+
};
|
|
128
|
+
if (!item.name) { alert('请填写客户名称'); return; }
|
|
129
|
+
demoCustomerManager.saveItem(item);
|
|
130
|
+
window.location.href = 'customer_list.html';
|
|
131
|
+
});
|
|
132
|
+
</script>
|
|
133
|
+
</body>
|
|
134
|
+
</html>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 客户表单 PRD(示例)
|
|
2
|
+
|
|
3
|
+
> 这是 openprototype 的示例 PRD。真实项目请按 `templates/docs/rules/form-page-prd-template.md` 编写。
|
|
4
|
+
|
|
5
|
+
## 一、页面信息
|
|
6
|
+
|
|
7
|
+
| 项 | 内容 |
|
|
8
|
+
|----|------|
|
|
9
|
+
| 页面名称 | 客户表单 |
|
|
10
|
+
| 页面文件 | customer_form.html |
|
|
11
|
+
| 页面类型 | 表单页(新增 / 编辑 / 查看) |
|
|
12
|
+
|
|
13
|
+
## 二、字段表
|
|
14
|
+
|
|
15
|
+
| 字段 | 控件 | 必填 | 只读(view) | 备注 |
|
|
16
|
+
|------|------|------|-----------|------|
|
|
17
|
+
| 客户名称 | 输入框 | 是 | 是 | |
|
|
18
|
+
| 联系人 | 输入框 | 是 | 是 | |
|
|
19
|
+
| 联系电话 | 输入框 | 否 | 是 | |
|
|
20
|
+
| 客户等级 | 下拉 | 否 | 是 | A / B / C 类 |
|
|
21
|
+
| 状态 | 下拉 | 否 | 是 | 启用 / 停用 |
|
|
22
|
+
| 备注 | 多行文本 | 否 | 是 | 占满一行 |
|
|
23
|
+
|
|
24
|
+
## 三、交互说明
|
|
25
|
+
|
|
26
|
+
- `?mode=view` 时所有输入控件与保存按钮**物理隐藏**(`display:none`),改显示只读文本(对应红线 4)。
|
|
27
|
+
- 保存写入 `demo-customer-list`(走 BaseDataManager,页面不直接读写 localStorage)。
|
|
28
|
+
|
|
29
|
+
## 修订记录
|
|
30
|
+
|
|
31
|
+
| 版本 | 日期 | 修订人 | 说明 |
|
|
32
|
+
|------|------|--------|------|
|
|
33
|
+
| V1.0.0 | 2026-07-10 | 维护人 | 示例初版 |
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>客户列表 - Demo</title>
|
|
7
|
+
<style>
|
|
8
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
9
|
+
body {
|
|
10
|
+
margin: 0;
|
|
11
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
|
|
12
|
+
font-size: 13px; color: #20242d; background: #f3f5f8; padding: 20px;
|
|
13
|
+
}
|
|
14
|
+
.page-title { font-size: 18px; font-weight: 600; margin: 0 0 16px; }
|
|
15
|
+
.panel { background: #fff; border: 1px solid #e6ebf2; border-radius: 8px; padding: 16px; margin-bottom: 16px; }
|
|
16
|
+
.search-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
|
|
17
|
+
.form-item { display: flex; flex-direction: column; gap: 4px; }
|
|
18
|
+
.form-item label { font-size: 12px; color: #6b7482; }
|
|
19
|
+
.form-item input, .form-item select {
|
|
20
|
+
height: 32px; min-width: 180px; padding: 0 10px; border: 1px solid #dfe5ee; border-radius: 6px; font-size: 13px; outline: none;
|
|
21
|
+
}
|
|
22
|
+
.form-item input:focus, .form-item select:focus { border-color: #1677ff; }
|
|
23
|
+
.search-actions { display: flex; gap: 8px; margin-left: auto; }
|
|
24
|
+
.btn { height: 32px; padding: 0 16px; border-radius: 6px; font-size: 13px; cursor: pointer; border: 1px solid #dfe5ee; background: #fff; color: #4f5665; }
|
|
25
|
+
.btn:hover { background: #f0f5ff; color: #1677ff; border-color: #bfdbff; }
|
|
26
|
+
.btn-primary { background: #1677ff; border-color: #1677ff; color: #fff; }
|
|
27
|
+
.btn-primary:hover { background: #0d5edb; }
|
|
28
|
+
table { width: 100%; border-collapse: collapse; }
|
|
29
|
+
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #eef1f6; font-size: 13px; }
|
|
30
|
+
th { color: #6b7482; font-weight: 600; background: #fafbfc; }
|
|
31
|
+
tr:hover td { background: #f7faff; }
|
|
32
|
+
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; }
|
|
33
|
+
.tag-active { background: #e9faea; color: #0f9f31; }
|
|
34
|
+
.tag-disabled { background: #f3f4f6; color: #8a94a6; }
|
|
35
|
+
.link { color: #1677ff; cursor: pointer; }
|
|
36
|
+
.link:hover { text-decoration: underline; }
|
|
37
|
+
</style>
|
|
38
|
+
</head>
|
|
39
|
+
<body>
|
|
40
|
+
<h1 class="page-title">客户列表</h1>
|
|
41
|
+
|
|
42
|
+
<div class="panel">
|
|
43
|
+
<div class="search-form">
|
|
44
|
+
<div class="form-item">
|
|
45
|
+
<label>客户名称</label>
|
|
46
|
+
<input id="kwName" type="text" placeholder="请输入客户名称">
|
|
47
|
+
</div>
|
|
48
|
+
<div class="form-item">
|
|
49
|
+
<label>状态</label>
|
|
50
|
+
<select id="kwStatus">
|
|
51
|
+
<option value="">全部</option>
|
|
52
|
+
<option value="active">启用</option>
|
|
53
|
+
<option value="disabled">停用</option>
|
|
54
|
+
</select>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="search-actions">
|
|
57
|
+
<button class="btn btn-primary" id="btnSearch">查询</button>
|
|
58
|
+
<button class="btn" id="btnReset">重置</button>
|
|
59
|
+
<button class="btn btn-primary" id="btnAdd">新增</button>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div class="panel">
|
|
65
|
+
<table>
|
|
66
|
+
<thead>
|
|
67
|
+
<tr><th>编号</th><th>客户名称</th><th>联系人</th><th>联系电话</th><th>等级</th><th>状态</th><th>操作</th></tr>
|
|
68
|
+
</thead>
|
|
69
|
+
<tbody id="tbody"></tbody>
|
|
70
|
+
</table>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<script src="/_kit/shared/base-manager.js"></script>
|
|
74
|
+
<script src="/product/demo/pc/demo-data.js"></script>
|
|
75
|
+
<script>
|
|
76
|
+
function render(rows) {
|
|
77
|
+
const tbody = document.getElementById('tbody');
|
|
78
|
+
tbody.replaceChildren();
|
|
79
|
+
if (!rows.length) {
|
|
80
|
+
const tr = document.createElement('tr');
|
|
81
|
+
tr.innerHTML = '<td colspan="7" style="text-align:center;color:#a8b2c3;padding:24px">暂无数据</td>';
|
|
82
|
+
tbody.appendChild(tr);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
rows.forEach(row => {
|
|
86
|
+
const tr = document.createElement('tr');
|
|
87
|
+
const statusTag = row.status === 'active'
|
|
88
|
+
? '<span class="tag tag-active">' + DEMO_STATUS_LABELS.active + '</span>'
|
|
89
|
+
: '<span class="tag tag-disabled">' + DEMO_STATUS_LABELS.disabled + '</span>';
|
|
90
|
+
tr.innerHTML =
|
|
91
|
+
'<td>' + row.id + '</td>' +
|
|
92
|
+
'<td>' + row.name + '</td>' +
|
|
93
|
+
'<td>' + row.contact + '</td>' +
|
|
94
|
+
'<td>' + row.phone + '</td>' +
|
|
95
|
+
'<td>' + (DEMO_LEVEL_LABELS[row.level] || row.level) + '</td>' +
|
|
96
|
+
'<td>' + statusTag + '</td>' +
|
|
97
|
+
'<td><span class="link" data-id="' + row.id + '">编辑</span></td>';
|
|
98
|
+
tbody.appendChild(tr);
|
|
99
|
+
});
|
|
100
|
+
tbody.querySelectorAll('.link').forEach(el => {
|
|
101
|
+
el.addEventListener('click', () => {
|
|
102
|
+
window.location.href = 'customer_form.html?mode=view&id=' + el.getAttribute('data-id');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function doSearch() {
|
|
108
|
+
const criteria = {};
|
|
109
|
+
const status = document.getElementById('kwStatus').value;
|
|
110
|
+
if (status) criteria.status = status;
|
|
111
|
+
let rows = demoCustomerManager.filter(criteria);
|
|
112
|
+
const kw = document.getElementById('kwName').value.trim();
|
|
113
|
+
if (kw) rows = rows.filter(r => r.name.includes(kw));
|
|
114
|
+
render(rows);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
document.getElementById('btnSearch').addEventListener('click', doSearch);
|
|
118
|
+
document.getElementById('btnReset').addEventListener('click', () => {
|
|
119
|
+
document.getElementById('kwName').value = '';
|
|
120
|
+
document.getElementById('kwStatus').value = '';
|
|
121
|
+
doSearch();
|
|
122
|
+
});
|
|
123
|
+
document.getElementById('btnAdd').addEventListener('click', () => {
|
|
124
|
+
window.location.href = 'customer_form.html';
|
|
125
|
+
});
|
|
126
|
+
render(demoCustomerManager.getData());
|
|
127
|
+
</script>
|
|
128
|
+
</body>
|
|
129
|
+
</html>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# 客户列表 PRD(示例)
|
|
2
|
+
|
|
3
|
+
> 这是 openprototype 的示例 PRD。真实项目请按 `templates/docs/rules/list-page-prd-template.md` 编写。
|
|
4
|
+
> 右侧 Agent 会自动携带「当前页面 + 当前 PRD」,可直接说"把某字段改成 XX",Agent 会同步改页面与本 PRD。
|
|
5
|
+
|
|
6
|
+
## 一、页面信息
|
|
7
|
+
|
|
8
|
+
| 项 | 内容 |
|
|
9
|
+
|----|------|
|
|
10
|
+
| 页面名称 | 客户列表 |
|
|
11
|
+
| 页面文件 | customer_list.html |
|
|
12
|
+
| 页面类型 | 列表页 |
|
|
13
|
+
|
|
14
|
+
## 二、字段表
|
|
15
|
+
|
|
16
|
+
| 字段 | 说明 | 必填 | 备注 |
|
|
17
|
+
|------|------|------|------|
|
|
18
|
+
| 客户名称 | 支持模糊查询 | 否 | 查询条件 |
|
|
19
|
+
| 状态 | 启用 / 停用 | 否 | 下拉,来自状态常量 |
|
|
20
|
+
| 客户等级 | A / B / C 类 | 否 | 列表展示 |
|
|
21
|
+
|
|
22
|
+
## 三、操作按钮
|
|
23
|
+
|
|
24
|
+
| 按钮 | 说明 |
|
|
25
|
+
|------|------|
|
|
26
|
+
| 查询 | 按条件过滤列表 |
|
|
27
|
+
| 重置 | 清空查询条件 |
|
|
28
|
+
| 新增 | 跳转客户表单新增 |
|
|
29
|
+
| 编辑 | 跳转客户表单查看/编辑 |
|
|
30
|
+
|
|
31
|
+
## 修订记录
|
|
32
|
+
|
|
33
|
+
| 版本 | 日期 | 修订人 | 说明 |
|
|
34
|
+
|------|------|--------|------|
|
|
35
|
+
| V1.0.0 | 2026-07-10 | 维护人 | 示例初版 |
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo 产品的数据层示例:一个继承 BaseDataManager 的客户 Manager。
|
|
3
|
+
* 真实产品请按 AGENTS.md §2.2 把每个实体的 Manager 放到 product/{id}/shared/data/ 下。
|
|
4
|
+
*/
|
|
5
|
+
class DemoCustomerManager extends BaseDataManager {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('demo-customer-list');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
initSampleData() {
|
|
11
|
+
return [
|
|
12
|
+
{ id: '000001', name: '示例科技有限公司', contact: '张三', phone: '13800000001', level: 'A', status: 'active' },
|
|
13
|
+
{ id: '000002', name: '样板医疗器械公司', contact: '李四', phone: '13800000002', level: 'B', status: 'active' },
|
|
14
|
+
{ id: '000003', name: '演示健康管理集团', contact: '王五', phone: '13800000003', level: 'A', status: 'disabled' }
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const demoCustomerManager = new DemoCustomerManager();
|
|
20
|
+
|
|
21
|
+
// 状态文案集中在一处(对应红线 3:状态值常量化的思路)
|
|
22
|
+
const DEMO_STATUS_LABELS = { active: '启用', disabled: '停用' };
|
|
23
|
+
const DEMO_LEVEL_LABELS = { A: 'A 类', B: 'B 类', C: 'C 类' };
|