From aa8b4dbbeb231034f14b24270e2a4c23071ac4a1 Mon Sep 17 00:00:00 2001 From: june Date: Sun, 21 Jul 2024 20:31:04 +0800 Subject: [PATCH] =?UTF-8?q?[2024-07-21](UPDATE):=20=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/modal.js | 40 ++++++++++++++++++++++++++++++++++++++++ view/layout.html | 31 ++++++++++++++++++++++--------- view/picture.html | 26 ++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 static/js/modal.js diff --git a/static/js/modal.js b/static/js/modal.js new file mode 100644 index 0000000..0e94cfc --- /dev/null +++ b/static/js/modal.js @@ -0,0 +1,40 @@ +function Modal(modalTitle, fields, onSubmit) { + this.modalTitle = modalTitle + this.fields = fields + this.onSubmit = onSubmit +} + +Modal.prototype.GenericModalForm = function () { + let self = this + // 设置表单标题 + $('#genericFormModalLabel').text(self.modalTitle) + // 生成表单内容 + let $form = $('#genericForm') + $form.empty() + self.fields.forEach(function(field) { + let $formGroup = $('
') + $formGroup.append('') + + let $input + if (field.type === 'textarea') { + $input = $('') + } else { + $input = $('') + } + + $formGroup.append($input) + $form.append($formGroup) + }) + // 显示模态框 + $('#genericFormModal').modal('show'); + + // 处理表单提交 + $('#genericFormSubmit').off('click').on('click', function() { + let formData = {} + $form.serializeArray().forEach(function(item) { + formData[item.name] = item.value + }) + self.onSubmit(formData) + $('#genericFormModal').modal('hide') + }) +} \ No newline at end of file diff --git a/view/layout.html b/view/layout.html index 929f2db..0dfa2df 100644 --- a/view/layout.html +++ b/view/layout.html @@ -49,15 +49,28 @@ {{ .csrfField }} {{template "content" .}} - + + {{template "script" .}} diff --git a/view/picture.html b/view/picture.html index 65916ad..8b89223 100644 --- a/view/picture.html +++ b/view/picture.html @@ -2,9 +2,31 @@ {{end}} {{define "content"}} -

Picture

-

Picture page content goes here.

+

通用弹出表单示例

+ + {{end}} {{define "script"}} + + {{end}}