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.
Files changed (56) hide show
  1. package/AGENTS.md +58 -0
  2. package/CONVENTIONS.md +54 -0
  3. package/LICENSE +21 -0
  4. package/README.md +233 -2
  5. package/bin/cli.js +297 -0
  6. package/lib/config.js +162 -0
  7. package/package.json +32 -10
  8. package/product/demo/pc/customer/customer_form.html +134 -0
  9. package/product/demo/pc/customer/customer_form.md +33 -0
  10. package/product/demo/pc/customer/customer_list.html +129 -0
  11. package/product/demo/pc/customer/customer_list.md +35 -0
  12. package/product/demo/pc/demo-data.js +23 -0
  13. package/product/demo/pc/index.html +1069 -0
  14. package/product/demo/pc/nav-tree.json +15 -0
  15. package/proto-kit.config.json +13 -0
  16. package/runtime/server.js +664 -0
  17. package/runtime/shared/ai-polish.js +159 -0
  18. package/runtime/shared/base-manager.js +168 -0
  19. package/runtime/shared/common/component-renderer.js +917 -0
  20. package/runtime/shared/common/copy-manager.js +134 -0
  21. package/runtime/shared/common/data-bridge.js +45 -0
  22. package/runtime/shared/common/form-renderer.js +211 -0
  23. package/runtime/shared/common/form.js +357 -0
  24. package/runtime/shared/common/formatter.js +78 -0
  25. package/runtime/shared/common/index.js +37 -0
  26. package/runtime/shared/common/line-chart.js +357 -0
  27. package/runtime/shared/common/modal-manager.js +82 -0
  28. package/runtime/shared/common/prd-panel.js +1014 -0
  29. package/runtime/shared/common/prd-popup.js +168 -0
  30. package/runtime/shared/common/search-renderer.js +95 -0
  31. package/runtime/shared/common/table-renderer.js +177 -0
  32. package/runtime/shared/common/table.js +160 -0
  33. package/runtime/shared/common/toast.js +99 -0
  34. package/runtime/shared/common/ui-preference-manager.js +74 -0
  35. package/runtime/shared/common/view-mode.js +30 -0
  36. package/runtime/shared/common.js +43 -0
  37. package/runtime/shared/constants/icons.js +28 -0
  38. package/runtime/shared/constants/status.js +67 -0
  39. package/runtime/shared/libs/marked.min.js +69 -0
  40. package/runtime/shared/prd-content.js +9 -0
  41. package/runtime/shared/styles.css +7673 -0
  42. package/runtime/shared/utils.js +110 -0
  43. package/runtime/shared/view-controls.js +148 -0
  44. package/runtime/shell/agent-panel.css +429 -0
  45. package/runtime/shell/agent-panel.js +629 -0
  46. package/scripts/check/run-checks.js +58 -0
  47. package/scripts/check/smoke-test.js +244 -0
  48. package/scripts/check/static-check.js +248 -0
  49. package/scripts/check/sync-nav-tree.js +139 -0
  50. package/templates/AGENTS.md +58 -0
  51. package/templates/CONVENTIONS.md +54 -0
  52. package/templates/gitignore +10 -0
  53. package/templates/product-shell/index.html +1069 -0
  54. package/templates/skills/auto-test/SKILL.md +62 -0
  55. package/templates/skills/xiaojia/SKILL.md +299 -0
  56. package/cli.js +0 -4
@@ -0,0 +1,357 @@
1
+ /**
2
+ * CommonForm 模块
3
+ * 通用表单管理器,处理表单渲染和数据提交
4
+ */
5
+
6
+ var CommonForm = {
7
+ config: null,
8
+ mode: 'add',
9
+ currentId: null,
10
+
11
+ init: function(config) {
12
+ this.config = config;
13
+ var params = new URLSearchParams(window.location.search);
14
+ this.currentId = params.get('id');
15
+ var copyMode = params.get('copy') === 'true' || params.get('mode') === 'copy';
16
+
17
+ if (copyMode) {
18
+ this.mode = 'copy';
19
+ this.loadCopyData();
20
+ } else if (this.currentId) {
21
+ this.mode = 'edit';
22
+ this.loadEditData();
23
+ } else {
24
+ this.mode = 'add';
25
+ this.renderForm();
26
+ }
27
+ },
28
+
29
+ renderForm: function(data) {
30
+ var container = document.querySelector(this.config.formSelector);
31
+ if (!container) return;
32
+
33
+ var html = '';
34
+ var self = this;
35
+ this.config.sections.forEach(function(section) {
36
+ var sectionVisibleStyle = section.visible === false ? 'style="display:none;"' : '';
37
+ var sectionId = section.id ? 'id="' + section.id + '"' : '';
38
+
39
+ html += '<div class="rx-form-section" ' + sectionId + ' ' + sectionVisibleStyle + '>';
40
+ html += '<h2 class="rx-section-title">' + section.title + '</h2>';
41
+ html += '<div class="rx-form-grid">';
42
+
43
+ section.fields.forEach(function(field) {
44
+ var value = data ? (data[field.id] || '') : (field.value || '');
45
+ var requiredMark = field.required ? '<span style="color: var(--danger); margin-right: 4px;">*</span>' : '';
46
+ var visibleStyle = field.visible === false ? 'style="display:none;"' : '';
47
+
48
+ if (field.type === 'custom' && field.render) {
49
+ html += '<div class="form-item" id="' + field.id + 'Item" ' + visibleStyle + '>';
50
+ if (field.label) {
51
+ html += '<label class="form-label">' + requiredMark + field.label + '</label>';
52
+ }
53
+ html += field.render.call(self, value, data || {});
54
+ html += '</div>';
55
+ return;
56
+ }
57
+
58
+ html += '<div class="form-item" id="' + field.id + 'Item" ' + visibleStyle + '>';
59
+ html += '<label class="form-label">' + requiredMark + field.label + '</label>';
60
+
61
+ if (field.type === 'select') {
62
+ html += '<select class="form-select" id="' + field.id + '" name="' + field.id + '"';
63
+ if (field.onChange) html += ' data-change-handler="' + field.onChange + '"';
64
+ html += '>';
65
+ if (field.options) {
66
+ field.options.forEach(function(opt) {
67
+ var selected = value === opt.value ? ' selected' : '';
68
+ html += '<option value="' + opt.value + '"' + selected + '>' + opt.label + '</option>';
69
+ });
70
+ }
71
+ html += '</select>';
72
+ } else if (field.type === 'textarea') {
73
+ html += '<textarea class="form-textarea" id="' + field.id + '" name="' + field.id + '" placeholder="' + (field.placeholder || '') + '"';
74
+ if (field.onChange) html += ' data-change-handler="' + field.onChange + '"';
75
+ html += '>' + value + '</textarea>';
76
+ } else if (field.type === 'radio') {
77
+ html += '<div class="radio-group">';
78
+ if (field.options) {
79
+ field.options.forEach(function(opt) {
80
+ var checked = value === opt.value ? ' checked' : '';
81
+ html += '<label class="radio-item"><input type="radio" name="' + field.id + '" value="' + opt.value + '"' + checked;
82
+ if (field.onChange) html += ' data-change-handler="' + field.onChange + '"';
83
+ html += '> ' + opt.label + '</label>';
84
+ });
85
+ }
86
+ html += '</div>';
87
+ } else if (field.type === 'number') {
88
+ html += '<input type="number" class="form-input" id="' + field.id + '" name="' + field.id + '" value="' + value + '" placeholder="' + (field.placeholder || '') + '"';
89
+ if (field.min !== undefined) html += ' min="' + field.min + '"';
90
+ if (field.max !== undefined) html += ' max="' + field.max + '"';
91
+ if (field.step) html += ' step="' + field.step + '"';
92
+ if (field.onChange) html += ' data-change-handler="' + field.onChange + '"';
93
+ html += '>';
94
+ } else if (field.type === 'display') {
95
+ html += '<span class="form-value" id="' + field.id + '">' + value + '</span>';
96
+ } else if (field.type === 'custom') {
97
+ html += '<div class="field-value" id="' + field.id + 'Container" data-field="' + field.id + '" data-custom-type="' + (field.customType || '') + '"></div>';
98
+ html += '<input type="hidden" id="' + field.id + '" name="' + field.id + '" value="' + value + '">';
99
+ } else if (field.type === 'yearMonth') {
100
+ html += '<div id="' + field.id + 'Container"></div>';
101
+ html += '<input type="hidden" id="' + field.id + '" name="' + field.id + '" value="' + value + '">';
102
+ } else if (field.type === 'yearQuarter') {
103
+ html += '<div id="' + field.id + 'Container"></div>';
104
+ html += '<input type="hidden" id="' + field.id + '" name="' + field.id + '" value="' + value + '">';
105
+ } else if (field.type === 'dateRange') {
106
+ html += '<div id="' + field.id + 'Container"></div>';
107
+ html += '<input type="hidden" id="' + field.id + 'Start" name="' + field.id + 'Start" value="">';
108
+ html += '<input type="hidden" id="' + field.id + 'End" name="' + field.id + 'End" value="">';
109
+ } else {
110
+ html += '<input type="text" class="form-input" id="' + field.id + '" name="' + field.id + '" value="' + value + '" placeholder="' + (field.placeholder || '') + '"';
111
+ if (field.readonly) html += ' readonly';
112
+ if (field.onChange) html += ' data-change-handler="' + field.onChange + '"';
113
+ html += '>';
114
+ }
115
+
116
+ html += '</div>';
117
+ });
118
+
119
+ html += '</div></div>';
120
+ });
121
+
122
+ container.innerHTML = html;
123
+ this._bindFieldChangeHandlers(container);
124
+
125
+ this._initPickerComponents(data);
126
+
127
+ if (this.config.onLoad) {
128
+ this.config.onLoad(data || {}, this.mode);
129
+ }
130
+ },
131
+
132
+ _bindFieldChangeHandlers: function(container) {
133
+ container.querySelectorAll('[data-change-handler]').forEach(function(el) {
134
+ el.addEventListener('change', function(event) {
135
+ var handlerName = el.getAttribute('data-change-handler');
136
+ var normalizedName = handlerName ? handlerName.replace(/\(.*\)$/, '') : '';
137
+ var handler = window[normalizedName];
138
+ if (typeof handler === 'function') {
139
+ handler(event);
140
+ }
141
+ });
142
+ });
143
+ },
144
+
145
+ _initPickerComponents: function(data) {
146
+ var self = this;
147
+ this.config.sections.forEach(function(section) {
148
+ section.fields.forEach(function(field) {
149
+ var value = data ? (data[field.id] || '') : (field.value || '');
150
+
151
+ if (field.type === 'yearMonth') {
152
+ var container = document.getElementById(field.id + 'Container');
153
+ if (container && typeof YearMonthPicker !== 'undefined') {
154
+ var instance = YearMonthPicker.render(field.id + 'Container', {
155
+ defaultValue: value || null,
156
+ onChange: function(val) {
157
+ var hiddenInput = document.getElementById(field.id);
158
+ if (hiddenInput) hiddenInput.value = val;
159
+ if (field.onChange) {
160
+ var fn = window[field.onChange];
161
+ if (typeof fn === 'function') fn(val);
162
+ }
163
+ }
164
+ });
165
+ container._yearMonthPickerInstance = instance;
166
+ }
167
+ } else if (field.type === 'yearQuarter') {
168
+ var container = document.getElementById(field.id + 'Container');
169
+ if (container && typeof YearQuarterPicker !== 'undefined') {
170
+ var parts = value ? value.split('-') : [];
171
+ var year = parts[0] ? parseInt(parts[0]) : null;
172
+ var quarter = parts[1] || null;
173
+ var instance = YearQuarterPicker.render(field.id + 'Container', {
174
+ defaultYear: year,
175
+ defaultQuarter: quarter,
176
+ onChange: function(val) {
177
+ var hiddenInput = document.getElementById(field.id);
178
+ if (hiddenInput) {
179
+ hiddenInput.value = val.year + (val.quarter ? '-' + val.quarter : '');
180
+ }
181
+ if (field.onChange) {
182
+ var fn = window[field.onChange];
183
+ if (typeof fn === 'function') fn(val);
184
+ }
185
+ }
186
+ });
187
+ container._yearQuarterPickerInstance = instance;
188
+ var hiddenInput = document.getElementById(field.id);
189
+ if (hiddenInput && year && quarter) {
190
+ hiddenInput.value = year + '-' + quarter;
191
+ }
192
+ }
193
+ } else if (field.type === 'dateRange') {
194
+ var container = document.getElementById(field.id + 'Container');
195
+ if (container && typeof DateRangePicker !== 'undefined') {
196
+ var startValue = data ? (data[field.id + 'Start'] || '') : '';
197
+ var endValue = data ? (data[field.id + 'End'] || '') : '';
198
+ var instance = DateRangePicker.render(field.id + 'Container', {
199
+ defaultStartDate: startValue || null,
200
+ defaultEndDate: endValue || null,
201
+ onChange: function(val) {
202
+ var startInput = document.getElementById(field.id + 'Start');
203
+ var endInput = document.getElementById(field.id + 'End');
204
+ if (startInput) startInput.value = val.startDate || '';
205
+ if (endInput) endInput.value = val.endDate || '';
206
+ if (field.onChange) {
207
+ var fn = window[field.onChange];
208
+ if (typeof fn === 'function') fn(val);
209
+ }
210
+ }
211
+ });
212
+ container._dateRangePickerInstance = instance;
213
+ }
214
+ }
215
+ });
216
+ });
217
+ },
218
+
219
+ loadEditData: function() {
220
+ var self = this;
221
+ var data = this.config.dataManager.getItemById ?
222
+ this.config.dataManager.getItemById(this.currentId) :
223
+ this.config.dataManager.getItem(this.currentId);
224
+
225
+ if (data) {
226
+ this.renderForm(data);
227
+ } else {
228
+ Toast.error('未找到数据');
229
+ window.location.href = this.config.listPage;
230
+ }
231
+ },
232
+
233
+ loadCopyData: function() {
234
+ var copyData = DataBridge.getData('kol_copy_data', true);
235
+ if (copyData) {
236
+ delete copyData.id;
237
+ delete copyData.kolId;
238
+ delete copyData.status;
239
+ delete copyData.createTime;
240
+ delete copyData.creator;
241
+ this.renderForm(copyData);
242
+ } else {
243
+ this.renderForm();
244
+ }
245
+ },
246
+
247
+ getFormData: function() {
248
+ var data = {};
249
+ if (this.currentId) data.id = this.currentId;
250
+
251
+ var self = this;
252
+ this.config.sections.forEach(function(section) {
253
+ section.fields.forEach(function(field) {
254
+ if (field.type === 'yearMonth') {
255
+ var container = document.getElementById(field.id + 'Container');
256
+ if (container && container._yearMonthPickerInstance) {
257
+ data[field.id] = container._yearMonthPickerInstance.getValue();
258
+ } else {
259
+ var el = document.getElementById(field.id);
260
+ if (el) data[field.id] = el.value;
261
+ }
262
+ } else if (field.type === 'yearQuarter') {
263
+ var container = document.getElementById(field.id + 'Container');
264
+ if (container && container._yearQuarterPickerInstance) {
265
+ var val = container._yearQuarterPickerInstance.getValue();
266
+ data[field.id] = val.year + (val.quarter ? '-' + val.quarter : '');
267
+ } else {
268
+ var el = document.getElementById(field.id);
269
+ if (el) data[field.id] = el.value;
270
+ }
271
+ } else if (field.type === 'dateRange') {
272
+ var container = document.getElementById(field.id + 'Container');
273
+ if (container && container._dateRangePickerInstance) {
274
+ var val = container._dateRangePickerInstance.getValue();
275
+ data[field.id + 'Start'] = val.startDate || '';
276
+ data[field.id + 'End'] = val.endDate || '';
277
+ } else {
278
+ var startEl = document.getElementById(field.id + 'Start');
279
+ var endEl = document.getElementById(field.id + 'End');
280
+ if (startEl) data[field.id + 'Start'] = startEl.value;
281
+ if (endEl) data[field.id + 'End'] = endEl.value;
282
+ }
283
+ } else if (field.type === 'radio') {
284
+ var checked = document.querySelector('input[name="' + field.id + '"]:checked');
285
+ data[field.id] = checked ? checked.value : '';
286
+ } else {
287
+ var el = document.getElementById(field.id);
288
+ if (el) {
289
+ data[field.id] = el.value;
290
+ }
291
+ }
292
+ });
293
+ });
294
+
295
+ return data;
296
+ },
297
+
298
+ saveForm: function() {
299
+ var data = this.getFormData();
300
+
301
+ if (this.config.onSave) {
302
+ data = this.config.onSave(data);
303
+ }
304
+
305
+ if (!data) {
306
+ return;
307
+ }
308
+
309
+ var existingItem = data.id ? this.config.dataManager.getItem(data.id) : null;
310
+
311
+ if (existingItem) {
312
+ this.config.dataManager.saveItem(data);
313
+ } else {
314
+ if (!data.id) {
315
+ data.id = Date.now().toString();
316
+ }
317
+ if (this.config.dataManager.addItem) {
318
+ this.config.dataManager.addItem(data);
319
+ } else {
320
+ this.config.dataManager.saveItem(data);
321
+ }
322
+ }
323
+
324
+ Toast.success('保存成功');
325
+ window.location.href = this.config.listPage;
326
+ },
327
+
328
+ submitForm: function() {
329
+ var data = this.getFormData();
330
+
331
+ if (this.config.onSubmit) {
332
+ data = this.config.onSubmit(data);
333
+ }
334
+
335
+ if (!data) {
336
+ return;
337
+ }
338
+
339
+ var existingItem = data.id ? this.config.dataManager.getItem(data.id) : null;
340
+
341
+ if (existingItem) {
342
+ this.config.dataManager.saveItem(data);
343
+ } else {
344
+ if (!data.id) {
345
+ data.id = Date.now().toString();
346
+ }
347
+ if (this.config.dataManager.addItem) {
348
+ this.config.dataManager.addItem(data);
349
+ } else {
350
+ this.config.dataManager.saveItem(data);
351
+ }
352
+ }
353
+
354
+ Toast.success('提交成功');
355
+ window.location.href = this.config.listPage;
356
+ }
357
+ };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Formatter 模块
3
+ * 全局格式化工具,统一管理常用字段格式化逻辑
4
+ */
5
+
6
+ var Formatter = {
7
+ fansCount: function(count) {
8
+ if (!count) return '-';
9
+ var num = parseInt(count);
10
+ if (isNaN(num)) return '-';
11
+ if (num >= 10000) {
12
+ return (num / 10000).toFixed(1) + '万';
13
+ }
14
+ return num.toLocaleString();
15
+ },
16
+
17
+ tier: function(tier) {
18
+ if (!tier) return '-';
19
+ var tierMap = {
20
+ '头部': '<span class="status-tag" style="background:#fff1f0;color:#cf1322;border-color:#ffa39e;">头部</span>',
21
+ '肩部': '<span class="status-tag" style="background:#fff7e6;color:#d46b08;border-color:#ffd591;">肩部</span>',
22
+ '腰部': '<span class="status-tag" style="background:#e6fffb;color:#08979c;border-color:#87e8de;">腰部</span>',
23
+ '尾部': '<span class="status-tag" style="background:#f9f0ff;color:#531dab;border-color:#d3adf7;">尾部</span>'
24
+ };
25
+ return tierMap[tier] || tier;
26
+ },
27
+
28
+ dockingSubject: function(subject) {
29
+ if (!subject) return '-';
30
+ return subject;
31
+ },
32
+
33
+ status: function(status) {
34
+ if (!status) return '-';
35
+ var labelMap = Object.assign(
36
+ {},
37
+ typeof STATUS_LABELS !== 'undefined' ? STATUS_LABELS : {},
38
+ typeof ENABLED_STATUS !== 'undefined' ? ENABLED_STATUS : {}
39
+ );
40
+ var classMap = typeof STATUS_STYLE_MAP !== 'undefined' ? STATUS_STYLE_MAP : {};
41
+ var label = labelMap[status] || status;
42
+ var cls = classMap[status] || 'status-tag-default';
43
+ return '<span class="status-tag ' + cls + '">' + label + '</span>';
44
+ }
45
+ };
46
+
47
+ function icon(name) {
48
+ if (typeof ICON_MAP !== 'undefined' && ICON_MAP[name]) {
49
+ return ICON_MAP[name];
50
+ }
51
+ return '';
52
+ }
53
+
54
+ function getIndicatorsByActivityType(typeId) {
55
+ if (typeof INDICATOR_MAP !== 'undefined' && INDICATOR_MAP[typeId]) {
56
+ return INDICATOR_MAP[typeId];
57
+ }
58
+ return ['曝光量', '点击率', '转化率', 'ROI'];
59
+ }
60
+
61
+ function renderIndicatorsCell(detail, activityType, isReadonly) {
62
+ var indicators = getIndicatorsByActivityType(activityType || (detail && detail.activityType) || '');
63
+ var list = (detail && detail.indicators) || [];
64
+ if (isReadonly) {
65
+ if (!list || list.length === 0) return '-';
66
+ return list.map(function(ind) {
67
+ return '<div style="display:flex;align-items:center;gap:8px;"><span style="flex-shrink:0;min-width:72px;">' + (ind.name || '-') + '</span><span style="flex:1;">' + (ind.value || '-') + '</span></div>';
68
+ }).join('');
69
+ }
70
+ if (!activityType && !detail.activityType) return '<span style="color:var(--text-secondary);">请先选择活动类型</span>';
71
+ return indicators.map(function(name) {
72
+ var found = list.find(function(i) { return i.name === name; });
73
+ var val = found ? found.value : '';
74
+ return '<div style="display:flex;gap:8px;align-items:center;margin-bottom:6px;">' +
75
+ '<span style="flex-shrink:0;min-width:72px;">' + name + '</span>' +
76
+ '<input type="text" class="detail-row-input" style="flex:1;" placeholder="请输入指标值" value="' + val + '"></div>';
77
+ }).join('');
78
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * common 模块入口文件
3
+ * 按顺序加载所有拆分后的模块文件
4
+ *
5
+ * 加载顺序:
6
+ * 1. prd-panel.js - PRD 面板相关
7
+ * 2. table.js - CommonTable 对象
8
+ * 3. form.js - CommonForm 对象
9
+ * 4. formatter.js - Formatter 对象和 icon 函数
10
+ * 5. component-renderer.js - ComponentRenderer 对象
11
+ * 6. modal-manager.js - ModalManager 对象
12
+ * 7. form-renderer.js - FormRenderer 对象
13
+ * 8. table-renderer.js - TableRenderer 对象
14
+ */
15
+
16
+ (function() {
17
+ var currentScript = document.currentScript;
18
+ var sharedBasePath = currentScript && currentScript.getAttribute('src')
19
+ ? currentScript.getAttribute('src').replace(/common\/index\.js(?:\?.*)?$/, '')
20
+ : 'shared/';
21
+ var basePath = sharedBasePath + 'common/';
22
+ var files = [
23
+ 'prd-panel.js',
24
+ 'table.js',
25
+ 'form.js',
26
+ 'formatter.js',
27
+ 'component-renderer.js',
28
+ 'line-chart.js',
29
+ 'modal-manager.js',
30
+ 'form-renderer.js',
31
+ 'table-renderer.js'
32
+ ];
33
+
34
+ files.forEach(function(file) {
35
+ document.write('<script src="' + basePath + file + '"><\/script>');
36
+ });
37
+ })();