Skip to content

Commit

Permalink
feat(admin): Support form multi file component & fixed richtext error
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Mar 8, 2020
1 parent 34bf64a commit 121621f
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 122 deletions.
17 changes: 13 additions & 4 deletions adminlte/resource/adminlte/adminlte.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@
display: inline-block;
}

.w-e-toolbar {
overflow: scroll;
}

.navbar-static-top .nav-tabs > li.active > a, navbar-static-top .nav-tabs > li.active > a:focus, navbar-static-top .nav-tabs > li.active > a:hover {
color: #555;
cursor: default;
Expand Down Expand Up @@ -135,4 +131,17 @@ form .select2-selection.select2-selection--single {

form .select2-selection__rendered {
line-height: 28px !important;
}

form .select2-selection.select2-selection--multiple .select2-selection__choice {
height: 24px;
line-height: 19px;
}

form .select2-selection.select2-selection--multiple {
height: 34px;
}

form .select2-selection.select2-selection--multiple .select2-selection__clear {
margin-top: 3px !important;
}
66 changes: 33 additions & 33 deletions adminlte/resource/assets.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion adminlte/resource/assets/dist/css/all.min.css

Large diffs are not rendered by default.

37 changes: 22 additions & 15 deletions adminlte/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,7 @@ var TemplateList = map[string]string{"admin_panel":`{{define "admin_panel"}}
data-initial-caption="{{.Value}}">
<input type="hidden" value="0" name="{{.Field}}__delete_flag" class="{{.Field}}__delete_flag">
<script>
$("input.{{.Field}}").fileinput({
"overwriteInitial": true,
"initialPreviewAsData": true,
"browseLabel": "Browse",
"showRemove": false,
"previewClass": "preview-{{.Field}}",
"showUpload": false,
"allowedFileTypes": ["image"]
});
$("input.{{.Field}}").fileinput({{.OptionExt}});
$(".preview-{{.Field}} .close.fileinput-remove").on("click", function (e) {
$(".{{.Field}}__delete_flag").val("1")
});
Expand Down Expand Up @@ -275,6 +267,16 @@ var TemplateList = map[string]string{"admin_panel":`{{define "admin_panel"}}
value='{{.Value}}' class="form-control json"
placeholder="{{.Placeholder}}">
</div>
{{end}}`,"components/form/multi_file":`{{define "form_multi_file"}}
<input type="file" class="{{.Field}}" name="{{.Field}}" multiple data-initial-preview="{{.Value2}}"
data-initial-caption="{{.Value}}">
<input type="hidden" value="0" name="{{.Field}}__delete_flag" class="{{.Field}}__delete_flag">
<script>
$("input.{{.Field}}").fileinput({{.OptionExt}});
$(".preview-{{.Field}} .close.fileinput-remove").on("click", function (e) {
$(".{{.Field}}__delete_flag").val("1")
});
</script>
{{end}}`,"components/form/number":`{{define "form_number"}}
<div class="input-group">
<input {{if .Must}}required="1"{{end}} style="width: 100px; text-align: center;" type="text" id="{{.Field}}"
Expand Down Expand Up @@ -354,19 +356,22 @@ var TemplateList = map[string]string{"admin_panel":`{{define "admin_panel"}}
</script>
{{end}}`,"components/form/richtext":`{{define "form_rich_text"}}
<div id="{{.Field}}-editor">
<p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
</div>
<input type="hidden" id="{{.Field}}" name="{{.Field}}" value='{{.Value}}'
placeholder="{{.Placeholder}}">
<script type="text/javascript">
editor = new window.wangEditor('#{{.Field}}-editor');
editor.customConfig.onchange = function (html) {
{{$field := (js .Field)}}
{{$field}}editor = new window.wangEditor('#{{.Field}}-editor');
{{$field}}editor.customConfig.onchange = function (html) {
$('#{{.Field}}').val(html)
};
editor.create();
editor.txt.html('{{.Value}}');
{{$field}}editor.customConfig.uploadImgServer = '/editor/imgs/upload';
{{$field}}editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
{{$field}}editor.customConfig.uploadImgMaxLength = 5;
{{$field}}editor.create();
{{$field}}editor.txt.html('{{.Value}}');
{{if not .Editable}}
editor.$textElem.attr('contenteditable', false);
{{$field}}editor.$textElem.attr('contenteditable', false);
{{end}}
</script>
{{end}}`,"components/form/select":`{{define "form_select"}}
Expand Down Expand Up @@ -532,6 +537,8 @@ var TemplateList = map[string]string{"admin_panel":`{{define "admin_panel"}}
{{ template "form_text" . }}
{{else if eq .FormType.String "file"}}
{{ template "form_file" . }}
{{else if eq .FormType.String "multi_file"}}
{{ template "form_multi_file" . }}
{{else if eq .FormType.String "password"}}
{{ template "form_password" . }}
{{else if eq .FormType.String "selectbox"}}
Expand Down
2 changes: 1 addition & 1 deletion common/assets/js/form/3_wangEditor.min.js

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions common/pages/components/form/file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
data-initial-caption="{{.Value}}">
<input type="hidden" value="0" name="{{.Field}}__delete_flag" class="{{.Field}}__delete_flag">
<script>
$("input.{{.Field}}").fileinput({
"overwriteInitial": true,
"initialPreviewAsData": true,
"browseLabel": "Browse",
"showRemove": false,
"previewClass": "preview-{{.Field}}",
"showUpload": false,
"allowedFileTypes": ["image"]
});
$("input.{{.Field}}").fileinput({{.OptionExt}});
$(".preview-{{.Field}} .close.fileinput-remove").on("click", function (e) {
$(".{{.Field}}__delete_flag").val("1")
});
Expand Down
11 changes: 11 additions & 0 deletions common/pages/components/form/multi_file.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{define "form_multi_file"}}
<input type="file" class="{{.Field}}" name="{{.Field}}" multiple data-initial-preview="{{.Value2}}"
data-initial-caption="{{.Value}}">
<input type="hidden" value="0" name="{{.Field}}__delete_flag" class="{{.Field}}__delete_flag">
<script>
$("input.{{.Field}}").fileinput({{.OptionExt}});
$(".preview-{{.Field}} .close.fileinput-remove").on("click", function (e) {
$(".{{.Field}}__delete_flag").val("1")
});
</script>
{{end}}
15 changes: 9 additions & 6 deletions common/pages/components/form/richtext.tmpl
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{{define "form_rich_text"}}
<div id="{{.Field}}-editor">
<p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
</div>
<input type="hidden" id="{{.Field}}" name="{{.Field}}" value='{{.Value}}'
placeholder="{{.Placeholder}}">
<script type="text/javascript">
editor = new window.wangEditor('#{{.Field}}-editor');
editor.customConfig.onchange = function (html) {
{{$field := (js .Field)}}
{{$field}}editor = new window.wangEditor('#{{.Field}}-editor');
{{$field}}editor.customConfig.onchange = function (html) {
$('#{{.Field}}').val(html)
};
editor.create();
editor.txt.html('{{.Value}}');
{{$field}}editor.customConfig.uploadImgServer = '/editor/imgs/upload';
{{$field}}editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
{{$field}}editor.customConfig.uploadImgMaxLength = 5;
{{$field}}editor.create();
{{$field}}editor.txt.html('{{.Value}}');
{{if not .Editable}}
editor.$textElem.attr('contenteditable', false);
{{$field}}editor.$textElem.attr('contenteditable', false);
{{end}}
</script>
{{end}}
2 changes: 2 additions & 0 deletions common/pages/components/form_components.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{{ template "form_text" . }}
{{else if eq .FormType.String "file"}}
{{ template "form_file" . }}
{{else if eq .FormType.String "multi_file"}}
{{ template "form_multi_file" . }}
{{else if eq .FormType.String "password"}}
{{ template "form_password" . }}
{{else if eq .FormType.String "selectbox"}}
Expand Down
66 changes: 33 additions & 33 deletions sword/resource/assets.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sword/resource/assets/dist/css/all.min.css

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions sword/resource/sword/sword.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ body {
background-color: #04142a !important;
}

.w-e-toolbar {
overflow: scroll;
}

.navbar-static-top .nav-tabs > li.active > a, navbar-static-top .nav-tabs > li.active > a:focus, navbar-static-top .nav-tabs > li.active > a:hover {
color: #555;
cursor: default;
Expand Down Expand Up @@ -537,4 +533,17 @@ form .select2-selection.select2-selection--single {

form .select2-selection__rendered {
line-height: 28px !important;
}

form .select2-selection.select2-selection--multiple .select2-selection__choice {
height: 24px;
line-height: 19px;
}

form .select2-selection.select2-selection--multiple {
height: 34px;
}

form .select2-selection.select2-selection--multiple .select2-selection__clear {
margin-top: 3px !important;
}
37 changes: 22 additions & 15 deletions sword/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,7 @@ var TemplateList = map[string]string{"admin_panel":`{{define "admin_panel"}}
data-initial-caption="{{.Value}}">
<input type="hidden" value="0" name="{{.Field}}__delete_flag" class="{{.Field}}__delete_flag">
<script>
$("input.{{.Field}}").fileinput({
"overwriteInitial": true,
"initialPreviewAsData": true,
"browseLabel": "Browse",
"showRemove": false,
"previewClass": "preview-{{.Field}}",
"showUpload": false,
"allowedFileTypes": ["image"]
});
$("input.{{.Field}}").fileinput({{.OptionExt}});
$(".preview-{{.Field}} .close.fileinput-remove").on("click", function (e) {
$(".{{.Field}}__delete_flag").val("1")
});
Expand Down Expand Up @@ -269,6 +261,16 @@ var TemplateList = map[string]string{"admin_panel":`{{define "admin_panel"}}
value='{{.Value}}' class="form-control json"
placeholder="{{.Placeholder}}">
</div>
{{end}}`,"components/form/multi_file":`{{define "form_multi_file"}}
<input type="file" class="{{.Field}}" name="{{.Field}}" multiple data-initial-preview="{{.Value2}}"
data-initial-caption="{{.Value}}">
<input type="hidden" value="0" name="{{.Field}}__delete_flag" class="{{.Field}}__delete_flag">
<script>
$("input.{{.Field}}").fileinput({{.OptionExt}});
$(".preview-{{.Field}} .close.fileinput-remove").on("click", function (e) {
$(".{{.Field}}__delete_flag").val("1")
});
</script>
{{end}}`,"components/form/number":`{{define "form_number"}}
<div class="input-group">
<input {{if .Must}}required="1"{{end}} style="width: 100px; text-align: center;" type="text" id="{{.Field}}"
Expand Down Expand Up @@ -348,19 +350,22 @@ var TemplateList = map[string]string{"admin_panel":`{{define "admin_panel"}}
</script>
{{end}}`,"components/form/richtext":`{{define "form_rich_text"}}
<div id="{{.Field}}-editor">
<p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
</div>
<input type="hidden" id="{{.Field}}" name="{{.Field}}" value='{{.Value}}'
placeholder="{{.Placeholder}}">
<script type="text/javascript">
editor = new window.wangEditor('#{{.Field}}-editor');
editor.customConfig.onchange = function (html) {
{{$field := (js .Field)}}
{{$field}}editor = new window.wangEditor('#{{.Field}}-editor');
{{$field}}editor.customConfig.onchange = function (html) {
$('#{{.Field}}').val(html)
};
editor.create();
editor.txt.html('{{.Value}}');
{{$field}}editor.customConfig.uploadImgServer = '/editor/imgs/upload';
{{$field}}editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
{{$field}}editor.customConfig.uploadImgMaxLength = 5;
{{$field}}editor.create();
{{$field}}editor.txt.html('{{.Value}}');
{{if not .Editable}}
editor.$textElem.attr('contenteditable', false);
{{$field}}editor.$textElem.attr('contenteditable', false);
{{end}}
</script>
{{end}}`,"components/form/select":`{{define "form_select"}}
Expand Down Expand Up @@ -526,6 +531,8 @@ var TemplateList = map[string]string{"admin_panel":`{{define "admin_panel"}}
{{ template "form_text" . }}
{{else if eq .FormType.String "file"}}
{{ template "form_file" . }}
{{else if eq .FormType.String "multi_file"}}
{{ template "form_multi_file" . }}
{{else if eq .FormType.String "password"}}
{{ template "form_password" . }}
{{else if eq .FormType.String "selectbox"}}
Expand Down

0 comments on commit 121621f

Please sign in to comment.