openprototype 0.1.0 → 0.2.1
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 +234 -3
- 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 +137 -0
- package/product/demo/pc/customer/customer_form.md +33 -0
- package/product/demo/pc/customer/customer_list.html +132 -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 +1082 -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.css +395 -0
- package/runtime/shared/common/prd-panel.js +1280 -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 +12 -0
- package/templates/product-shell/index.html +1082 -0
- package/templates/skills/auto-test/SKILL.md +62 -0
- package/templates/skills/xiaojia/SKILL.md +299 -0
- package/cli.js +0 -4
|
@@ -0,0 +1,917 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ComponentRenderer 模块
|
|
3
|
+
* 组件渲染器,统一渲染常用 UI 组件
|
|
4
|
+
*
|
|
5
|
+
* 事件委托:按钮不再使用内联 onclick,改用 data-action 属性。
|
|
6
|
+
* 全局委托监听器在 document 上,通过 data-action 值在全局作用域解析回调函数。
|
|
7
|
+
* 注册自定义回调:ComponentRenderer.registerAction('name', fn)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var ComponentRenderer = {
|
|
11
|
+
_actionCallbacks: {},
|
|
12
|
+
|
|
13
|
+
registerAction: function(name, fn) {
|
|
14
|
+
this._actionCallbacks[name] = fn;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
_resolveAction: function(name) {
|
|
18
|
+
return this._actionCallbacks[name] || (typeof window !== 'undefined' ? window[name] : null);
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
_attr: function(s) { return (s || '').replace(/"/g, '"'); },
|
|
22
|
+
|
|
23
|
+
renderTableActions: function(id, status, config) {
|
|
24
|
+
config = config || {};
|
|
25
|
+
var showEdit = config.showEdit !== false;
|
|
26
|
+
var showToggle = config.showToggle !== false;
|
|
27
|
+
var showDelete = config.showDelete === true;
|
|
28
|
+
var editCallback = config.editCallback || 'editItem';
|
|
29
|
+
var toggleCallback = config.toggleCallback || 'toggleStatus';
|
|
30
|
+
var deleteCallback = config.deleteCallback || 'deleteItem';
|
|
31
|
+
var customButtons = config.customButtons || [];
|
|
32
|
+
|
|
33
|
+
var html = '<div class="action-btns">';
|
|
34
|
+
|
|
35
|
+
if (showEdit) {
|
|
36
|
+
html += '<button class="action-icon-btn" data-action="' + this._attr(editCallback) + '" data-action-id="' + id + '" data-tooltip="编辑">' +
|
|
37
|
+
ICON_MAP.edit +
|
|
38
|
+
'</button>';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (showToggle) {
|
|
42
|
+
var isActive = status === ENABLED_STATUS.enabled || status === ENABLED_STATUS.active;
|
|
43
|
+
var tooltip = isActive ? ENABLED_STATUS.inactive : ENABLED_STATUS.active;
|
|
44
|
+
var icon = isActive ? ICON_MAP.ban : ICON_MAP.power;
|
|
45
|
+
html += '<button class="action-icon-btn" data-action="' + this._attr(toggleCallback) + '" data-action-id="' + id + '" data-tooltip="' + tooltip + '">' +
|
|
46
|
+
icon +
|
|
47
|
+
'</button>';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (showDelete) {
|
|
51
|
+
html += '<button class="action-icon-btn delete" data-action="' + this._attr(deleteCallback) + '" data-action-id="' + id + '" data-tooltip="删除">' +
|
|
52
|
+
ICON_MAP.delete +
|
|
53
|
+
'</button>';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
customButtons.forEach(function(btn) {
|
|
57
|
+
html += '<button class="action-icon-btn' + (btn.className ? ' ' + btn.className : '') + '" data-action="' + ComponentRenderer._attr(btn.callback) + '" data-action-id="' + id + '" data-tooltip="' + btn.tooltip + '">' +
|
|
58
|
+
btn.icon +
|
|
59
|
+
'</button>';
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
html += '</div>';
|
|
63
|
+
return html;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
renderStatusTag: function(status, defaultText) {
|
|
67
|
+
var statusClass = STATUS_STYLE_MAP[status] || 'status-inactive';
|
|
68
|
+
var displayText = status || defaultText || '-';
|
|
69
|
+
return '<span class="' + statusClass + '">' + displayText + '</span>';
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
renderButton: function(iconKey, text, className, actionName) {
|
|
73
|
+
var icon = ICON_MAP[iconKey] || '';
|
|
74
|
+
return '<button class="' + className + '" data-action="' + this._attr(actionName) + '">' +
|
|
75
|
+
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;">' + icon + '</svg>' +
|
|
76
|
+
text +
|
|
77
|
+
'</button>';
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
renderUploader: function(containerId, options) {
|
|
81
|
+
options = options || {};
|
|
82
|
+
var container = document.getElementById(containerId);
|
|
83
|
+
if (!container) return null;
|
|
84
|
+
|
|
85
|
+
var accept = options.accept || '.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.jpg,.png';
|
|
86
|
+
var maxFiles = options.maxFiles || 5;
|
|
87
|
+
var maxSizeMB = options.maxSizeMB || 10;
|
|
88
|
+
var label = options.label || '上传附件';
|
|
89
|
+
var uploaderId = containerId + '-uploader';
|
|
90
|
+
|
|
91
|
+
container.innerHTML = '<div class="upload-area" id="' + uploaderId + '">' +
|
|
92
|
+
'<button type="button" class="btn btn-default upload-btn">' +
|
|
93
|
+
'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>' +
|
|
94
|
+
label + '</button>' +
|
|
95
|
+
'<input type="file" class="upload-input" multiple accept="' + accept + '" style="display:none">' +
|
|
96
|
+
'<span class="upload-hint">支持 ' + accept + ' 格式,单个文件不超过 ' + maxSizeMB + 'MB,最多 ' + maxFiles + ' 个文件</span>' +
|
|
97
|
+
'</div><div class="upload-file-list"></div>';
|
|
98
|
+
|
|
99
|
+
var instance = {
|
|
100
|
+
container: container,
|
|
101
|
+
files: [],
|
|
102
|
+
addFile: function(file) {
|
|
103
|
+
if (this.files.length >= maxFiles) { Toast.warning('最多上传 ' + maxFiles + ' 个文件'); return; }
|
|
104
|
+
if (file.size > maxSizeMB * 1024 * 1024) { Toast.warning('文件大小不能超过 ' + maxSizeMB + 'MB'); return; }
|
|
105
|
+
this.files.push({ name: file.name, size: file.size, type: file.type, file: file });
|
|
106
|
+
this.render();
|
|
107
|
+
},
|
|
108
|
+
removeFile: function(index) { this.files.splice(index, 1); this.render(); },
|
|
109
|
+
render: function() {
|
|
110
|
+
var listEl = container.querySelector('.upload-file-list');
|
|
111
|
+
var html = '';
|
|
112
|
+
for (var i = 0; i < this.files.length; i++) {
|
|
113
|
+
var f = this.files[i];
|
|
114
|
+
html += '<div class="upload-file-item">' +
|
|
115
|
+
'<svg class="upload-file-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>' +
|
|
116
|
+
'<span class="upload-file-name">' + f.name + '</span>' +
|
|
117
|
+
'<span class="upload-file-size">' + (f.size / 1024).toFixed(1) + 'KB</span>' +
|
|
118
|
+
'<span class="upload-file-remove" data-index="' + i + '">×</span></div>';
|
|
119
|
+
}
|
|
120
|
+
listEl.innerHTML = html;
|
|
121
|
+
var self = this;
|
|
122
|
+
listEl.querySelectorAll('.upload-file-remove').forEach(function(btn) {
|
|
123
|
+
btn.addEventListener('click', function() { self.removeFile(parseInt(this.dataset.index)); });
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
getFiles: function() { return this.files; },
|
|
127
|
+
setFiles: function(files) { this.files = files || []; this.render(); }
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
var btn = container.querySelector('.upload-btn');
|
|
131
|
+
var input = container.querySelector('.upload-input');
|
|
132
|
+
btn.addEventListener('click', function() { input.click(); });
|
|
133
|
+
input.addEventListener('change', function(e) {
|
|
134
|
+
Array.from(e.target.files).forEach(function(f) { instance.addFile(f); });
|
|
135
|
+
input.value = '';
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
container._uploaderInstance = instance;
|
|
139
|
+
return instance;
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
renderImageUploader: function(containerId, options) {
|
|
143
|
+
options = options || {};
|
|
144
|
+
var container = document.getElementById(containerId);
|
|
145
|
+
if (!container) return null;
|
|
146
|
+
|
|
147
|
+
var maxSizeMB = options.maxSizeMB || 2;
|
|
148
|
+
var uploaderId = containerId + '-img-uploader';
|
|
149
|
+
|
|
150
|
+
container.innerHTML = '<div class="icon-upload-container" id="' + uploaderId + '">' +
|
|
151
|
+
'<div class="icon-upload-box"><span class="upload-icon">+</span><span class="upload-hint">上传图片</span>' +
|
|
152
|
+
'<img src="" alt="" style="display:none"><button type="button" class="delete-btn">×</button>' +
|
|
153
|
+
'<input type="file" accept="image/*" style="display:none"></div></div>';
|
|
154
|
+
|
|
155
|
+
var instance = {
|
|
156
|
+
container: container,
|
|
157
|
+
imageData: null,
|
|
158
|
+
setImage: function(src) {
|
|
159
|
+
this.imageData = src;
|
|
160
|
+
var box = container.querySelector('.icon-upload-box');
|
|
161
|
+
var img = box.querySelector('img');
|
|
162
|
+
if (src) { img.src = src; img.style.display = 'block'; box.classList.add('has-image'); }
|
|
163
|
+
else { img.src = ''; img.style.display = 'none'; box.classList.remove('has-image'); }
|
|
164
|
+
},
|
|
165
|
+
getImage: function() { return this.imageData; }
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
var box = container.querySelector('.icon-upload-box');
|
|
169
|
+
var input = box.querySelector('input[type="file"]');
|
|
170
|
+
var deleteBtn = box.querySelector('.delete-btn');
|
|
171
|
+
|
|
172
|
+
box.addEventListener('click', function(e) { if (!e.target.closest('.delete-btn')) input.click(); });
|
|
173
|
+
input.addEventListener('change', function(e) {
|
|
174
|
+
var file = e.target.files[0];
|
|
175
|
+
if (!file) return;
|
|
176
|
+
if (file.size > maxSizeMB * 1024 * 1024) { Toast.warning('图片大小不能超过 ' + maxSizeMB + 'MB'); return; }
|
|
177
|
+
var reader = new FileReader();
|
|
178
|
+
reader.onload = function(ev) { instance.setImage(ev.target.result); };
|
|
179
|
+
reader.readAsDataURL(file);
|
|
180
|
+
});
|
|
181
|
+
deleteBtn.addEventListener('click', function(e) { e.stopPropagation(); instance.setImage(null); input.value = ''; });
|
|
182
|
+
|
|
183
|
+
container._imageUploaderInstance = instance;
|
|
184
|
+
return instance;
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
renderYearQuarterPicker: function(containerId, options) {
|
|
188
|
+
options = options || {};
|
|
189
|
+
var container = document.getElementById(containerId);
|
|
190
|
+
if (!container) return null;
|
|
191
|
+
|
|
192
|
+
var showQuarter = options.showQuarter !== false;
|
|
193
|
+
var currentYear = new Date().getFullYear();
|
|
194
|
+
var years = [];
|
|
195
|
+
for (var i = currentYear - 2; i <= currentYear + 3; i++) years.push(i);
|
|
196
|
+
|
|
197
|
+
var yearOptions = years.map(function(y) { return '<option value="' + y + '"' + (y === currentYear ? ' selected' : '') + '>' + y + '年</option>'; }).join('');
|
|
198
|
+
var quarterHtml = showQuarter ? '<select class="form-select quarter-select"><option value="Q1">Q1</option><option value="Q2">Q2</option><option value="Q3">Q3</option><option value="Q4">Q4</option></select>' : '';
|
|
199
|
+
|
|
200
|
+
container.innerHTML = '<div class="year-quarter-picker" style="display:flex;gap:8px;align-items:center;">' +
|
|
201
|
+
'<select class="form-select year-select">' + yearOptions + '</select>' + quarterHtml + '</div>';
|
|
202
|
+
|
|
203
|
+
var instance = {
|
|
204
|
+
container: container,
|
|
205
|
+
getValue: function() {
|
|
206
|
+
var year = container.querySelector('.year-select').value;
|
|
207
|
+
var quarterEl = container.querySelector('.quarter-select');
|
|
208
|
+
return { year: year, quarter: quarterEl ? quarterEl.value : null };
|
|
209
|
+
},
|
|
210
|
+
setValue: function(year, quarter) {
|
|
211
|
+
container.querySelector('.year-select').value = year;
|
|
212
|
+
var quarterEl = container.querySelector('.quarter-select');
|
|
213
|
+
if (quarterEl && quarter) quarterEl.value = quarter;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
container._yearQuarterPickerInstance = instance;
|
|
218
|
+
return instance;
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
renderYearMonthPicker: function(containerId, options) {
|
|
222
|
+
options = options || {};
|
|
223
|
+
|
|
224
|
+
if (typeof YearMonthPicker !== 'undefined' && YearMonthPicker.render) {
|
|
225
|
+
return YearMonthPicker.render(containerId, options);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var container = document.getElementById(containerId);
|
|
229
|
+
if (!container) return null;
|
|
230
|
+
|
|
231
|
+
var currentYear = new Date().getFullYear();
|
|
232
|
+
var currentMonth = new Date().getMonth() + 1;
|
|
233
|
+
var years = [];
|
|
234
|
+
for (var i = currentYear - 5; i <= currentYear + 1; i++) years.push(i);
|
|
235
|
+
|
|
236
|
+
var yearOptions = years.map(function(y) { return '<option value="' + y + '"' + (y === currentYear ? ' selected' : '') + '>' + y + '年</option>'; }).join('');
|
|
237
|
+
var monthOptions = '';
|
|
238
|
+
for (var m = 1; m <= 12; m++) {
|
|
239
|
+
monthOptions += '<option value="' + m + '"' + (m === currentMonth ? ' selected' : '') + '>' + m + '月</option>';
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
container.innerHTML = '<div class="year-month-picker" style="display:flex;gap:8px;align-items:center;">' +
|
|
243
|
+
'<select class="form-select year-select">' + yearOptions + '</select>' +
|
|
244
|
+
'<select class="form-select month-select">' + monthOptions + '</select></div>';
|
|
245
|
+
|
|
246
|
+
var yearSelect = container.querySelector('.year-select');
|
|
247
|
+
var monthSelect = container.querySelector('.month-select');
|
|
248
|
+
|
|
249
|
+
var instance = {
|
|
250
|
+
container: container,
|
|
251
|
+
yearSelect: yearSelect,
|
|
252
|
+
monthSelect: monthSelect,
|
|
253
|
+
_onChange: options.onChange || null,
|
|
254
|
+
|
|
255
|
+
getValue: function() {
|
|
256
|
+
var year = yearSelect.value;
|
|
257
|
+
var month = monthSelect.value;
|
|
258
|
+
return year + '-' + String(month).padStart(2, '0');
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
getValueObject: function() {
|
|
262
|
+
var year = yearSelect.value;
|
|
263
|
+
var month = monthSelect.value;
|
|
264
|
+
return {
|
|
265
|
+
year: year ? parseInt(year) : null,
|
|
266
|
+
month: month ? parseInt(month) : null,
|
|
267
|
+
formatted: this.getValue()
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
setValue: function(value) {
|
|
272
|
+
if (!value) return;
|
|
273
|
+
var parts = value.split('-');
|
|
274
|
+
if (parts[0]) yearSelect.value = parts[0];
|
|
275
|
+
if (parts[1]) monthSelect.value = parseInt(parts[1]);
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
clear: function() {
|
|
279
|
+
yearSelect.selectedIndex = 0;
|
|
280
|
+
monthSelect.selectedIndex = 0;
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
destroy: function() {
|
|
284
|
+
yearSelect.removeEventListener('change', this._handleChange);
|
|
285
|
+
monthSelect.removeEventListener('change', this._handleChange);
|
|
286
|
+
container.innerHTML = '';
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
_handleChange: function() {
|
|
290
|
+
if (this._onChange) {
|
|
291
|
+
this._onChange(this.getValue(), this.getValueObject());
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
instance._handleChange = instance._handleChange.bind(instance);
|
|
297
|
+
|
|
298
|
+
yearSelect.addEventListener('change', function() {
|
|
299
|
+
instance._handleChange();
|
|
300
|
+
});
|
|
301
|
+
monthSelect.addEventListener('change', function() {
|
|
302
|
+
instance._handleChange();
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
container._yearMonthPickerInstance = instance;
|
|
306
|
+
return instance;
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
renderDateRangePicker: function(containerId, options) {
|
|
310
|
+
options = options || {};
|
|
311
|
+
|
|
312
|
+
if (typeof DateRangePicker !== 'undefined' && DateRangePicker.render) {
|
|
313
|
+
return DateRangePicker.render(containerId, options);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
var container = document.getElementById(containerId);
|
|
317
|
+
if (!container) return null;
|
|
318
|
+
|
|
319
|
+
container.innerHTML = '<div class="date-range-picker" style="display:flex;gap:8px;align-items:center;">' +
|
|
320
|
+
'<input type="date" class="form-input date-start" style="width:140px;">' +
|
|
321
|
+
'<span style="color:var(--text-secondary);">至</span>' +
|
|
322
|
+
'<input type="date" class="form-input date-end" style="width:140px;"></div>';
|
|
323
|
+
|
|
324
|
+
if (options.defaultStartDate) {
|
|
325
|
+
container.querySelector('.date-start').value = options.defaultStartDate;
|
|
326
|
+
}
|
|
327
|
+
if (options.defaultEndDate) {
|
|
328
|
+
container.querySelector('.date-end').value = options.defaultEndDate;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
var instance = {
|
|
332
|
+
container: container,
|
|
333
|
+
getValue: function() {
|
|
334
|
+
return {
|
|
335
|
+
startDate: container.querySelector('.date-start').value || null,
|
|
336
|
+
endDate: container.querySelector('.date-end').value || null
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
setValue: function(startDate, endDate) {
|
|
340
|
+
container.querySelector('.date-start').value = startDate || '';
|
|
341
|
+
container.querySelector('.date-end').value = endDate || '';
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
container._dateRangePickerInstance = instance;
|
|
346
|
+
return instance;
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
renderProductGroupPicker: function(containerId, options) {
|
|
350
|
+
options = options || {};
|
|
351
|
+
|
|
352
|
+
if (!options.items || options.items.length === 0) {
|
|
353
|
+
if (typeof financeManager !== 'undefined' && financeManager.getProductGroupOptions) {
|
|
354
|
+
options.items = financeManager.getProductGroupOptions();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (typeof ProductGroupPicker !== 'undefined' && ProductGroupPicker.render) {
|
|
359
|
+
return ProductGroupPicker.render(containerId, options);
|
|
360
|
+
}
|
|
361
|
+
console.warn('ProductGroupPicker 组件未加载');
|
|
362
|
+
return null;
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
renderOrgSelect: function(callback, options) {
|
|
366
|
+
options = options || {};
|
|
367
|
+
|
|
368
|
+
if (!options.orgData) {
|
|
369
|
+
if (typeof financeManager !== 'undefined' && financeManager.getOrganizationTreeData) {
|
|
370
|
+
options.orgData = financeManager.getOrganizationTreeData();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (typeof OrgSelect !== 'undefined' && OrgSelect.openOrg) {
|
|
375
|
+
OrgSelect.openOrg(callback, options);
|
|
376
|
+
} else {
|
|
377
|
+
console.warn('OrgSelect 组件未加载');
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
renderUserSelect: function(callback, options) {
|
|
382
|
+
options = options || {};
|
|
383
|
+
|
|
384
|
+
if (!options.orgData) {
|
|
385
|
+
if (typeof financeManager !== 'undefined' && financeManager.getOrganizationTreeData) {
|
|
386
|
+
options.orgData = financeManager.getOrganizationTreeData();
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (!options.users) {
|
|
390
|
+
if (typeof MockData !== 'undefined' && MockData.users) {
|
|
391
|
+
options.users = MockData.users;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (typeof OrgSelect !== 'undefined' && OrgSelect.openUser) {
|
|
396
|
+
OrgSelect.openUser(callback, options);
|
|
397
|
+
} else {
|
|
398
|
+
console.warn('OrgSelect 组件未加载');
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
|
|
402
|
+
renderDoctorSelect: function(callback, options) {
|
|
403
|
+
options = options || {};
|
|
404
|
+
|
|
405
|
+
if (!options.doctors) {
|
|
406
|
+
if (typeof doctorManager !== 'undefined' && doctorManager.getData) {
|
|
407
|
+
options.doctors = doctorManager.getData();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (typeof DoctorSelect !== 'undefined' && DoctorSelect.open) {
|
|
412
|
+
DoctorSelect.open(callback, options);
|
|
413
|
+
} else {
|
|
414
|
+
console.warn('DoctorSelect 组件未加载');
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
renderPersonPicker: function(containerId, options) {
|
|
419
|
+
options = options || {};
|
|
420
|
+
var container = document.getElementById(containerId);
|
|
421
|
+
if (!container) return null;
|
|
422
|
+
|
|
423
|
+
var placeholder = options.placeholder || '请选择人员';
|
|
424
|
+
container.innerHTML = '<div class="person-picker-wrapper" style="position:relative;">' +
|
|
425
|
+
'<input type="text" class="form-input person-picker-input" placeholder="' + placeholder + '" readonly>' +
|
|
426
|
+
'<div class="person-picker-dropdown" style="display:none;position:absolute;top:100%;left:0;z-index:1000;background:#fff;border:1px solid var(--border-color);border-radius:2px;box-shadow:0 2px 8px rgba(0,0,0,0.15);min-width:200px;margin-top:4px;max-height:200px;overflow-y:auto;"></div></div>';
|
|
427
|
+
|
|
428
|
+
var instance = {
|
|
429
|
+
container: container,
|
|
430
|
+
selectedPerson: null,
|
|
431
|
+
getValue: function() { return this.selectedPerson; },
|
|
432
|
+
setValue: function(person) { this.selectedPerson = person; container.querySelector('.person-picker-input').value = person ? person.name : ''; }
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
var input = container.querySelector('.person-picker-input');
|
|
436
|
+
var dropdown = container.querySelector('.person-picker-dropdown');
|
|
437
|
+
|
|
438
|
+
input.addEventListener('focus', function() {
|
|
439
|
+
dropdown.style.display = 'block';
|
|
440
|
+
var persons = [{ id: 'U001', name: '张三' }, { id: 'U002', name: '李四' }, { id: 'U003', name: '王五' }];
|
|
441
|
+
dropdown.innerHTML = persons.map(function(p) {
|
|
442
|
+
return '<div class="person-picker-item" data-id="' + p.id + '" data-name="' + p.name + '" style="padding:8px 12px;cursor:pointer;font-size:14px;">' + p.name + '</div>';
|
|
443
|
+
}).join('');
|
|
444
|
+
dropdown.querySelectorAll('.person-picker-item').forEach(function(item) {
|
|
445
|
+
item.addEventListener('click', function() { instance.setValue({ id: this.dataset.id, name: this.dataset.name }); dropdown.style.display = 'none'; });
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
input.addEventListener('blur', function() { setTimeout(function() { dropdown.style.display = 'none'; }, 200); });
|
|
449
|
+
|
|
450
|
+
container._personPickerInstance = instance;
|
|
451
|
+
return instance;
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
renderPagination: function(containerId, totalCount, currentPage, pageSize, onChange) {
|
|
455
|
+
var container = document.getElementById(containerId);
|
|
456
|
+
if (!container) return null;
|
|
457
|
+
|
|
458
|
+
var totalPages = Math.max(1, Math.ceil(totalCount / pageSize));
|
|
459
|
+
var html = '<span class="pagination-info">共 ' + totalCount + ' 条</span>';
|
|
460
|
+
html += '<select class="pagination-select" data-action="changePageSize">' +
|
|
461
|
+
'<option value="10"' + (pageSize === 10 ? ' selected' : '') + '>10条/页</option>' +
|
|
462
|
+
'<option value="20"' + (pageSize === 20 ? ' selected' : '') + '>20条/页</option>' +
|
|
463
|
+
'<option value="50"' + (pageSize === 50 ? ' selected' : '') + '>50条/页</option></select>';
|
|
464
|
+
html += '<div class="pagination-btns">';
|
|
465
|
+
html += '<button class="pagination-btn" data-action="changePage" data-page="' + (currentPage - 1) + '"' + (currentPage === 1 ? ' disabled' : '') + '><</button>';
|
|
466
|
+
|
|
467
|
+
if (totalPages <= 7) {
|
|
468
|
+
for (var i = 1; i <= totalPages; i++) {
|
|
469
|
+
html += '<button class="pagination-btn' + (i === currentPage ? ' active' : '') + '" data-action="changePage" data-page="' + i + '">' + i + '</button>';
|
|
470
|
+
}
|
|
471
|
+
} else if (currentPage <= 4) {
|
|
472
|
+
for (var i = 1; i <= 5; i++) { html += '<button class="pagination-btn' + (i === currentPage ? ' active' : '') + '" data-action="changePage" data-page="' + i + '">' + i + '</button>'; }
|
|
473
|
+
html += '<span class="pagination-ellipsis">...</span>';
|
|
474
|
+
html += '<button class="pagination-btn" data-action="changePage" data-page="' + totalPages + '">' + totalPages + '</button>';
|
|
475
|
+
} else if (currentPage >= totalPages - 3) {
|
|
476
|
+
html += '<button class="pagination-btn" data-action="changePage" data-page="1">1</button><span class="pagination-ellipsis">...</span>';
|
|
477
|
+
for (var i = totalPages - 4; i <= totalPages; i++) { html += '<button class="pagination-btn' + (i === currentPage ? ' active' : '') + '" data-action="changePage" data-page="' + i + '">' + i + '</button>'; }
|
|
478
|
+
} else {
|
|
479
|
+
html += '<button class="pagination-btn" data-action="changePage" data-page="1">1</button><span class="pagination-ellipsis">...</span>';
|
|
480
|
+
for (var i = currentPage - 1; i <= currentPage + 1; i++) { html += '<button class="pagination-btn' + (i === currentPage ? ' active' : '') + '" data-action="changePage" data-page="' + i + '">' + i + '</button>'; }
|
|
481
|
+
html += '<span class="pagination-ellipsis">...</span><button class="pagination-btn" data-action="changePage" data-page="' + totalPages + '">' + totalPages + '</button>';
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
html += '<button class="pagination-btn" data-action="changePage" data-page="' + (currentPage + 1) + '"' + (currentPage === totalPages ? ' disabled' : '') + '>></button></div>';
|
|
485
|
+
html += '<div class="pagination-jump"><span>跳至</span><input type="number" class="form-input" min="1" data-action="handleJumpPage"><span>页</span></div>';
|
|
486
|
+
|
|
487
|
+
container.innerHTML = html;
|
|
488
|
+
|
|
489
|
+
var jumpInput = container.querySelector('[data-action="handleJumpPage"]');
|
|
490
|
+
if (jumpInput) {
|
|
491
|
+
jumpInput.addEventListener('keypress', function(e) {
|
|
492
|
+
if (e.key === 'Enter') {
|
|
493
|
+
var page = parseInt(this.value);
|
|
494
|
+
if (page >= 1 && page <= totalPages) {
|
|
495
|
+
var fn = ComponentRenderer._resolveAction('changePage');
|
|
496
|
+
if (typeof fn === 'function') fn(page);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return container;
|
|
503
|
+
},
|
|
504
|
+
|
|
505
|
+
renderExportModal: function(containerId, config) {
|
|
506
|
+
config = config || {};
|
|
507
|
+
var container = document.getElementById(containerId);
|
|
508
|
+
if (!container) return null;
|
|
509
|
+
|
|
510
|
+
var title = config.title || '导出数据';
|
|
511
|
+
var fields = config.fields || [];
|
|
512
|
+
var defaultFields = config.defaultFields || [];
|
|
513
|
+
var exportKey = config.exportKey;
|
|
514
|
+
|
|
515
|
+
var exportViews = exportKey ? UIPreferenceManager.getExportViews(exportKey) : [];
|
|
516
|
+
var currentFields = defaultFields;
|
|
517
|
+
var currentViewId = null;
|
|
518
|
+
|
|
519
|
+
function renderFields(selectedFields) {
|
|
520
|
+
var fieldsHtml = fields.map(function(f) {
|
|
521
|
+
return '<label class="checkbox-item"><input type="checkbox" value="' + f.key + '"' + (selectedFields.includes(f.key) ? ' checked' : '') + '><label>' + f.label + '</label></label>';
|
|
522
|
+
}).join('');
|
|
523
|
+
container.querySelector('.export-fields-grid').innerHTML = fieldsHtml;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function renderViewOptions() {
|
|
527
|
+
var optionsHtml = '<option value="">-- 选择视图 --</option>';
|
|
528
|
+
exportViews.forEach(function(view) {
|
|
529
|
+
optionsHtml += '<option value="' + view.id + '">' + view.name + '</option>';
|
|
530
|
+
});
|
|
531
|
+
return optionsHtml;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
container.innerHTML = '<div class="modal-overlay export-modal-overlay">' +
|
|
535
|
+
'<div class="modal modal-lg"><div class="modal-header"><h3>' + title + '</h3>' +
|
|
536
|
+
'<button class="modal-close export-modal-close">×</button></div>' +
|
|
537
|
+
'<div class="modal-body"><div class="export-fields-section">' +
|
|
538
|
+
'<div class="export-view-controls">' +
|
|
539
|
+
'<select class="form-select export-view-select">' + renderViewOptions() + '</select>' +
|
|
540
|
+
'<div class="export-view-buttons">' +
|
|
541
|
+
'<button type="button" class="btn btn-default btn-sm export-save-view">保存视图</button>' +
|
|
542
|
+
'<button type="button" class="btn btn-default btn-sm export-save-as-view">另存为视图</button>' +
|
|
543
|
+
'<button type="button" class="btn btn-danger btn-sm export-delete-view" style="display:none;">删除视图</button>' +
|
|
544
|
+
'</div>' +
|
|
545
|
+
'</div>' +
|
|
546
|
+
'<div style="margin-bottom:12px;display:flex;justify-content:space-between;align-items:center;">' +
|
|
547
|
+
'<span style="font-size:14px;font-weight:500;">选择导出字段</span>' +
|
|
548
|
+
'<div style="display:flex;gap:8px;"><button type="button" class="btn btn-default btn-sm export-select-all">全选</button>' +
|
|
549
|
+
'<button type="button" class="btn btn-default btn-sm export-deselect-all">取消全选</button></div></div>' +
|
|
550
|
+
'<div class="export-fields-grid"></div></div></div>' +
|
|
551
|
+
'<div class="modal-footer"><button type="button" class="btn btn-default export-cancel-btn">取消</button>' +
|
|
552
|
+
'<button type="button" class="btn btn-primary export-confirm-btn">确认导出</button></div></div></div>';
|
|
553
|
+
|
|
554
|
+
renderFields(currentFields);
|
|
555
|
+
|
|
556
|
+
var instance = {
|
|
557
|
+
container: container,
|
|
558
|
+
getSelectedFields: function() {
|
|
559
|
+
return Array.from(container.querySelectorAll('.export-fields-grid input[type="checkbox"]:checked')).map(function(cb) { return cb.value; });
|
|
560
|
+
},
|
|
561
|
+
show: function() { container.querySelector('.export-modal-overlay').classList.add('active'); },
|
|
562
|
+
hide: function() { container.querySelector('.export-modal-overlay').classList.remove('active'); },
|
|
563
|
+
onExport: null
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
container.querySelector('.export-modal-close').addEventListener('click', function() { instance.hide(); });
|
|
567
|
+
container.querySelector('.export-cancel-btn').addEventListener('click', function() { instance.hide(); });
|
|
568
|
+
container.querySelector('.export-select-all').addEventListener('click', function() {
|
|
569
|
+
container.querySelectorAll('.export-fields-grid input[type="checkbox"]').forEach(function(cb) { cb.checked = true; });
|
|
570
|
+
});
|
|
571
|
+
container.querySelector('.export-deselect-all').addEventListener('click', function() {
|
|
572
|
+
container.querySelectorAll('.export-fields-grid input[type="checkbox"]').forEach(function(cb) { cb.checked = false; });
|
|
573
|
+
});
|
|
574
|
+
container.querySelector('.export-confirm-btn').addEventListener('click', function() {
|
|
575
|
+
var selectedFields = instance.getSelectedFields();
|
|
576
|
+
if (selectedFields.length === 0) { Toast.warning('请至少选择一个导出字段'); return; }
|
|
577
|
+
if (instance.onExport) instance.onExport(selectedFields);
|
|
578
|
+
instance.hide();
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
container.querySelector('.export-view-select').addEventListener('change', function(e) {
|
|
582
|
+
var viewId = e.target.value;
|
|
583
|
+
currentViewId = viewId;
|
|
584
|
+
var deleteBtn = container.querySelector('.export-delete-view');
|
|
585
|
+
|
|
586
|
+
if (viewId) {
|
|
587
|
+
var view = exportViews.find(function(v) { return v.id === viewId; });
|
|
588
|
+
if (view) {
|
|
589
|
+
currentFields = view.fields;
|
|
590
|
+
renderFields(currentFields);
|
|
591
|
+
deleteBtn.style.display = 'inline-block';
|
|
592
|
+
}
|
|
593
|
+
} else {
|
|
594
|
+
currentFields = defaultFields;
|
|
595
|
+
renderFields(currentFields);
|
|
596
|
+
deleteBtn.style.display = 'none';
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
container.querySelector('.export-save-view').addEventListener('click', function() {
|
|
601
|
+
if (!exportKey) return;
|
|
602
|
+
var selectedFields = instance.getSelectedFields();
|
|
603
|
+
if (selectedFields.length === 0) { Toast.warning('请至少选择一个导出字段'); return; }
|
|
604
|
+
|
|
605
|
+
if (currentViewId) {
|
|
606
|
+
var view = exportViews.find(function(v) { return v.id === currentViewId; });
|
|
607
|
+
if (view) {
|
|
608
|
+
view.fields = selectedFields;
|
|
609
|
+
UIPreferenceManager.saveExportViews(exportKey, exportViews);
|
|
610
|
+
Toast.success('视图保存成功');
|
|
611
|
+
}
|
|
612
|
+
} else {
|
|
613
|
+
var name = prompt('请输入视图名称:');
|
|
614
|
+
if (!name) return;
|
|
615
|
+
|
|
616
|
+
var id = 'view_' + Date.now();
|
|
617
|
+
exportViews.push({ id: id, name: name, fields: selectedFields });
|
|
618
|
+
UIPreferenceManager.saveExportViews(exportKey, exportViews);
|
|
619
|
+
|
|
620
|
+
var select = container.querySelector('.export-view-select');
|
|
621
|
+
var option = document.createElement('option');
|
|
622
|
+
option.value = id;
|
|
623
|
+
option.textContent = name;
|
|
624
|
+
select.appendChild(option);
|
|
625
|
+
select.value = id;
|
|
626
|
+
currentViewId = id;
|
|
627
|
+
container.querySelector('.export-delete-view').style.display = 'inline-block';
|
|
628
|
+
Toast.success('视图保存成功');
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
container.querySelector('.export-save-as-view').addEventListener('click', function() {
|
|
633
|
+
if (!exportKey) return;
|
|
634
|
+
var selectedFields = instance.getSelectedFields();
|
|
635
|
+
if (selectedFields.length === 0) { Toast.warning('请至少选择一个导出字段'); return; }
|
|
636
|
+
|
|
637
|
+
var name = prompt('请输入视图名称:');
|
|
638
|
+
if (!name) return;
|
|
639
|
+
|
|
640
|
+
var id = 'view_' + Date.now();
|
|
641
|
+
exportViews.push({ id: id, name: name, fields: selectedFields });
|
|
642
|
+
UIPreferenceManager.saveExportViews(exportKey, exportViews);
|
|
643
|
+
|
|
644
|
+
var select = container.querySelector('.export-view-select');
|
|
645
|
+
var option = document.createElement('option');
|
|
646
|
+
option.value = id;
|
|
647
|
+
option.textContent = name;
|
|
648
|
+
select.appendChild(option);
|
|
649
|
+
select.value = id;
|
|
650
|
+
currentViewId = id;
|
|
651
|
+
container.querySelector('.export-delete-view').style.display = 'inline-block';
|
|
652
|
+
Toast.success('视图保存成功');
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
container.querySelector('.export-delete-view').addEventListener('click', function() {
|
|
656
|
+
if (!exportKey || !currentViewId) return;
|
|
657
|
+
|
|
658
|
+
if (confirm('确定要删除此视图吗?')) {
|
|
659
|
+
exportViews = exportViews.filter(function(v) { return v.id !== currentViewId; });
|
|
660
|
+
UIPreferenceManager.saveExportViews(exportKey, exportViews);
|
|
661
|
+
|
|
662
|
+
var select = container.querySelector('.export-view-select');
|
|
663
|
+
select.removeChild(select.querySelector('option[value="' + currentViewId + '"]'));
|
|
664
|
+
select.value = '';
|
|
665
|
+
currentViewId = null;
|
|
666
|
+
container.querySelector('.export-delete-view').style.display = 'none';
|
|
667
|
+
currentFields = defaultFields;
|
|
668
|
+
renderFields(currentFields);
|
|
669
|
+
Toast.success('视图删除成功');
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
container._exportModalInstance = instance;
|
|
674
|
+
return instance;
|
|
675
|
+
},
|
|
676
|
+
|
|
677
|
+
renderApprovalModal: function(containerId, options) {
|
|
678
|
+
options = options || {};
|
|
679
|
+
var container = document.getElementById(containerId);
|
|
680
|
+
if (!container) return null;
|
|
681
|
+
|
|
682
|
+
var title = options.title || '审批操作';
|
|
683
|
+
var quickReplies = options.quickReplies || ['同意', '已确认', '请修改后重新提交'];
|
|
684
|
+
var action = options.action || 'approve';
|
|
685
|
+
var actionConfig = {
|
|
686
|
+
approve: { label: '同意', className: 'btn-primary', callback: 'onApprove' },
|
|
687
|
+
return: { label: '打回', className: 'btn-warning', callback: 'onReturn' },
|
|
688
|
+
reject: { label: '否决', className: 'btn-danger', callback: 'onReject' }
|
|
689
|
+
};
|
|
690
|
+
var currentAction = actionConfig[action] || actionConfig.approve;
|
|
691
|
+
|
|
692
|
+
var quickRepliesHtml = quickReplies.map(function(r) { return '<button type="button" class="quick-reply-btn">' + r + '</button>'; }).join('');
|
|
693
|
+
|
|
694
|
+
container.innerHTML = '<div class="approval-drawer-overlay">' +
|
|
695
|
+
'<section class="approval-drawer" role="dialog" aria-modal="true" aria-label="' + title + '"><div class="approval-drawer-header">' +
|
|
696
|
+
'<h3 class="approval-drawer-title">' + title + '</h3>' +
|
|
697
|
+
'<button type="button" class="approval-drawer-close" aria-label="关闭">×</button></div>' +
|
|
698
|
+
'<div class="approval-drawer-body"><div class="approval-comment-section">' +
|
|
699
|
+
'<label class="approval-comment-label">审批意见</label>' +
|
|
700
|
+
'<div class="approval-comment-textarea-wrapper">' +
|
|
701
|
+
'<textarea class="approval-comment-textarea" placeholder="请输入审批意见..." maxlength="500"></textarea>' +
|
|
702
|
+
'<div class="approval-comment-footer"><span class="approval-comment-count">0/500</span>' +
|
|
703
|
+
'<button type="button" class="ai-polish-btn-large">' +
|
|
704
|
+
'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">' +
|
|
705
|
+
'<path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg> AI润色</button></div></div></div>' +
|
|
706
|
+
'<div class="quick-reply-section"><div class="quick-reply-header"><span class="quick-reply-title">快捷回复</span></div>' +
|
|
707
|
+
'<div class="quick-reply-buttons">' + quickRepliesHtml + '</div></div></div>' +
|
|
708
|
+
'<div class="approval-drawer-footer"><button type="button" class="btn btn-default approval-cancel-btn">取消</button>' +
|
|
709
|
+
'<button type="button" class="btn ' + currentAction.className + ' approval-confirm-btn">确认' + currentAction.label + '</button></div></section></div>';
|
|
710
|
+
|
|
711
|
+
var instance = {
|
|
712
|
+
container: container,
|
|
713
|
+
comment: '',
|
|
714
|
+
onApprove: null,
|
|
715
|
+
onReject: null,
|
|
716
|
+
onReturn: null,
|
|
717
|
+
show: function() {
|
|
718
|
+
container.querySelector('.approval-drawer-overlay').classList.add('active');
|
|
719
|
+
textarea.focus();
|
|
720
|
+
},
|
|
721
|
+
hide: function() { container.querySelector('.approval-drawer-overlay').classList.remove('active'); },
|
|
722
|
+
getComment: function() { return container.querySelector('.approval-comment-textarea').value; }
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
var textarea = container.querySelector('.approval-comment-textarea');
|
|
726
|
+
var countEl = container.querySelector('.approval-comment-count');
|
|
727
|
+
|
|
728
|
+
textarea.addEventListener('input', function() { countEl.textContent = textarea.value.length + '/500'; });
|
|
729
|
+
container.querySelector('.approval-drawer-close').addEventListener('click', function() { instance.hide(); });
|
|
730
|
+
container.querySelector('.approval-cancel-btn').addEventListener('click', function() { instance.hide(); });
|
|
731
|
+
container.querySelector('.approval-confirm-btn').addEventListener('click', function() {
|
|
732
|
+
if (instance[currentAction.callback]) instance[currentAction.callback](instance.getComment());
|
|
733
|
+
instance.hide();
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
container.querySelectorAll('.quick-reply-btn').forEach(function(btn) {
|
|
737
|
+
btn.addEventListener('click', function() {
|
|
738
|
+
textarea.value = btn.textContent;
|
|
739
|
+
countEl.textContent = textarea.value.length + '/500';
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
container._approvalModalInstance = instance;
|
|
744
|
+
return instance;
|
|
745
|
+
},
|
|
746
|
+
|
|
747
|
+
renderPaginationInstance: function(containerId, options) {
|
|
748
|
+
options = options || {};
|
|
749
|
+
var container = document.getElementById(containerId);
|
|
750
|
+
if (!container) return null;
|
|
751
|
+
|
|
752
|
+
var pageSize = options.pageSize || 10;
|
|
753
|
+
var pageSizeOptions = options.pageSizeOptions || [10, 20, 50, 100];
|
|
754
|
+
|
|
755
|
+
container.innerHTML = '<div class="pagination"><span class="pagination-info">共 <span class="total-count">0</span> 条</span>' +
|
|
756
|
+
'<div class="pagination-btns"></div><div class="pagination-jump">' +
|
|
757
|
+
'<select class="pagination-select page-size-select">' +
|
|
758
|
+
pageSizeOptions.map(function(s) { return '<option value="' + s + '"' + (s === pageSize ? ' selected' : '') + '>' + s + '条/页</option>'; }).join('') +
|
|
759
|
+
'</select><span style="font-size:14px;color:var(--text-secondary);">跳至</span>' +
|
|
760
|
+
'<input type="number" class="form-input jump-input" min="1" style="width:60px;text-align:center;">' +
|
|
761
|
+
'<span style="font-size:14px;color:var(--text-secondary);">页</span></div></div>';
|
|
762
|
+
|
|
763
|
+
var instance = {
|
|
764
|
+
container: container,
|
|
765
|
+
currentPage: 1,
|
|
766
|
+
pageSize: pageSize,
|
|
767
|
+
totalCount: 0,
|
|
768
|
+
onChange: null,
|
|
769
|
+
setTotalCount: function(count) {
|
|
770
|
+
this.totalCount = count;
|
|
771
|
+
container.querySelector('.total-count').textContent = count;
|
|
772
|
+
this._renderPages();
|
|
773
|
+
},
|
|
774
|
+
_renderPages: function() {
|
|
775
|
+
var totalPages = Math.max(1, Math.ceil(this.totalCount / this.pageSize));
|
|
776
|
+
if (this.currentPage > totalPages) this.currentPage = totalPages;
|
|
777
|
+
var btnsEl = container.querySelector('.pagination-btns');
|
|
778
|
+
var html = '<button class="pagination-btn" data-page="prev" ' + (this.currentPage <= 1 ? 'disabled' : '') + '><</button>';
|
|
779
|
+
for (var i = 1; i <= totalPages; i++) {
|
|
780
|
+
if (totalPages <= 7 || i === 1 || i === totalPages || Math.abs(i - this.currentPage) <= 1) {
|
|
781
|
+
html += '<button class="pagination-btn ' + (i === this.currentPage ? 'active' : '') + '" data-page="' + i + '">' + i + '</button>';
|
|
782
|
+
} else if (i === this.currentPage - 2 || i === this.currentPage + 2) {
|
|
783
|
+
html += '<span class="pagination-ellipsis">...</span>';
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
html += '<button class="pagination-btn" data-page="next" ' + (this.currentPage >= totalPages ? 'disabled' : '') + '>></button>';
|
|
787
|
+
btnsEl.innerHTML = html;
|
|
788
|
+
this._bindPageEvents();
|
|
789
|
+
},
|
|
790
|
+
_bindPageEvents: function() {
|
|
791
|
+
var self = this;
|
|
792
|
+
container.querySelectorAll('.pagination-btn[data-page]').forEach(function(btn) {
|
|
793
|
+
btn.addEventListener('click', function() {
|
|
794
|
+
var page = btn.dataset.page;
|
|
795
|
+
var totalPages = Math.max(1, Math.ceil(self.totalCount / self.pageSize));
|
|
796
|
+
if (page === 'prev' && self.currentPage > 1) self.currentPage--;
|
|
797
|
+
else if (page === 'next' && self.currentPage < totalPages) self.currentPage++;
|
|
798
|
+
else if (page !== 'prev' && page !== 'next') self.currentPage = parseInt(page);
|
|
799
|
+
self._renderPages();
|
|
800
|
+
if (self.onChange) self.onChange(self.currentPage, self.pageSize);
|
|
801
|
+
});
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
container.querySelector('.page-size-select').addEventListener('change', function(e) {
|
|
807
|
+
instance.pageSize = parseInt(e.target.value);
|
|
808
|
+
instance.currentPage = 1;
|
|
809
|
+
instance._renderPages();
|
|
810
|
+
if (instance.onChange) instance.onChange(instance.currentPage, instance.pageSize);
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
container.querySelector('.jump-input').addEventListener('keydown', function(e) {
|
|
814
|
+
if (e.key === 'Enter') {
|
|
815
|
+
var totalPages = Math.max(1, Math.ceil(instance.totalCount / instance.pageSize));
|
|
816
|
+
var page = parseInt(e.target.value);
|
|
817
|
+
if (page >= 1 && page <= totalPages) {
|
|
818
|
+
instance.currentPage = page;
|
|
819
|
+
instance._renderPages();
|
|
820
|
+
if (instance.onChange) instance.onChange(instance.currentPage, instance.pageSize);
|
|
821
|
+
}
|
|
822
|
+
e.target.value = '';
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
container._paginationInstance = instance;
|
|
827
|
+
return instance;
|
|
828
|
+
},
|
|
829
|
+
|
|
830
|
+
renderApprovalButtons: function(containerId, options) {
|
|
831
|
+
options = options || {};
|
|
832
|
+
var container = document.getElementById(containerId);
|
|
833
|
+
if (!container) return null;
|
|
834
|
+
|
|
835
|
+
var approveBtnId = options.approveBtnId || 'approveBtn';
|
|
836
|
+
var rejectBtnId = options.rejectBtnId || 'rejectBtn';
|
|
837
|
+
var returnBtnId = options.returnBtnId || 'returnBtn';
|
|
838
|
+
var withdrawBtnId = options.withdrawBtnId || 'withdrawBtn';
|
|
839
|
+
var deprecateBtnId = options.deprecateBtnId || 'deprecateBtn';
|
|
840
|
+
var showIcons = options.showIcons !== false;
|
|
841
|
+
var showWithdraw = options.showWithdraw !== false;
|
|
842
|
+
var showDeprecate = options.showDeprecate !== false;
|
|
843
|
+
|
|
844
|
+
var onApprove = options.onApprove || null;
|
|
845
|
+
var onReject = options.onReject || null;
|
|
846
|
+
var onReturn = options.onReturn || null;
|
|
847
|
+
var onWithdraw = options.onWithdraw || null;
|
|
848
|
+
var onDeprecate = options.onDeprecate || null;
|
|
849
|
+
|
|
850
|
+
var checkIcon = showIcons ? '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>' : '';
|
|
851
|
+
var closeIcon = showIcons ? '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>' : '';
|
|
852
|
+
var returnIcon = showIcons ? '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><polyline points="1 4 1 10 7 10"></polyline><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path></svg>' : '';
|
|
853
|
+
var withdrawIcon = showIcons ? '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><polyline points="1 4 1 10 7 10"></polyline><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path></svg>' : '';
|
|
854
|
+
var deprecateIcon = showIcons ? '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>' : '';
|
|
855
|
+
|
|
856
|
+
var html = '<div class="form-actions form-actions-fixed" style="justify-content:center;">';
|
|
857
|
+
if (showWithdraw) {
|
|
858
|
+
html += '<button type="button" class="btn btn-warning" id="' + withdrawBtnId + '">' + withdrawIcon + ' 撤回</button>';
|
|
859
|
+
}
|
|
860
|
+
if (showDeprecate) {
|
|
861
|
+
html += '<button type="button" class="btn btn-danger" id="' + deprecateBtnId + '">' + deprecateIcon + ' 废弃</button>';
|
|
862
|
+
}
|
|
863
|
+
html += '<button type="button" class="btn btn-primary" id="' + approveBtnId + '">' + checkIcon + ' 同意</button>' +
|
|
864
|
+
'<button type="button" class="btn btn-danger" id="' + rejectBtnId + '">' + closeIcon + ' 不同意</button>' +
|
|
865
|
+
'<button type="button" class="btn btn-warning" id="' + returnBtnId + '">' + returnIcon + ' 打回</button>' +
|
|
866
|
+
'</div>';
|
|
867
|
+
|
|
868
|
+
container.innerHTML = html;
|
|
869
|
+
|
|
870
|
+
if (onApprove) container.querySelector('#' + approveBtnId).addEventListener('click', onApprove);
|
|
871
|
+
if (onReject) container.querySelector('#' + rejectBtnId).addEventListener('click', onReject);
|
|
872
|
+
if (onReturn) container.querySelector('#' + returnBtnId).addEventListener('click', onReturn);
|
|
873
|
+
if (onWithdraw && showWithdraw) container.querySelector('#' + withdrawBtnId).addEventListener('click', onWithdraw);
|
|
874
|
+
if (onDeprecate && showDeprecate) container.querySelector('#' + deprecateBtnId).addEventListener('click', onDeprecate);
|
|
875
|
+
|
|
876
|
+
var instance = {
|
|
877
|
+
container: container,
|
|
878
|
+
getApproveBtn: function() { return container.querySelector('#' + approveBtnId); },
|
|
879
|
+
getRejectBtn: function() { return container.querySelector('#' + rejectBtnId); },
|
|
880
|
+
getReturnBtn: function() { return container.querySelector('#' + returnBtnId); },
|
|
881
|
+
getWithdrawBtn: function() { return showWithdraw ? container.querySelector('#' + withdrawBtnId) : null; },
|
|
882
|
+
getDeprecateBtn: function() { return showDeprecate ? container.querySelector('#' + deprecateBtnId) : null; }
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
container._approvalButtonsInstance = instance;
|
|
886
|
+
return instance;
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
// 全局事件委托:替代内联 onclick / onchange
|
|
891
|
+
// 通过 data-action 属性查找回调函数,优先查 ComponentRenderer._actionCallbacks,其次全局作用域
|
|
892
|
+
(function() {
|
|
893
|
+
if (ComponentRenderer._delegationBound) return;
|
|
894
|
+
ComponentRenderer._delegationBound = true;
|
|
895
|
+
|
|
896
|
+
document.addEventListener('click', function(e) {
|
|
897
|
+
var el = e.target.closest('[data-action]');
|
|
898
|
+
if (!el) return;
|
|
899
|
+
var action = el.dataset.action;
|
|
900
|
+
if (!action) return;
|
|
901
|
+
var fn = ComponentRenderer._resolveAction(action);
|
|
902
|
+
if (typeof fn === 'function') {
|
|
903
|
+
var id = el.dataset.actionId || el.dataset.id;
|
|
904
|
+
var page = el.dataset.page;
|
|
905
|
+
fn(id !== undefined ? id : page);
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
document.addEventListener('change', function(e) {
|
|
910
|
+
var el = e.target.closest('select[data-action]');
|
|
911
|
+
if (!el) return;
|
|
912
|
+
var action = el.dataset.action;
|
|
913
|
+
if (!action) return;
|
|
914
|
+
var fn = ComponentRenderer._resolveAction(action);
|
|
915
|
+
if (typeof fn === 'function') fn(el.value);
|
|
916
|
+
});
|
|
917
|
+
})();
|