|
|
@@ -4,7 +4,7 @@
|
|
|
<th:block th:include="include :: header('修改赛事发布')" />
|
|
|
<th:block th:include="include :: datetimepicker-css" />
|
|
|
<th:block th:include="include :: summernote-css" />
|
|
|
- <th:block th:include="include :: bootstrap-fileinput-css"/>
|
|
|
+ <th:block th:include="include :: image-upload-css"/>
|
|
|
<!-- 自定义 CSS -->
|
|
|
<style>
|
|
|
/* 修改文本域的背景颜色和文字颜色 */
|
|
|
@@ -15,266 +15,319 @@
|
|
|
</style>
|
|
|
</head>
|
|
|
<body class="white-bg">
|
|
|
- <div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
|
|
- <form class="form-horizontal m" id="form-competition-edit" th:object="${competition}">
|
|
|
- <input name="id" th:field="*{id}" type="hidden">
|
|
|
- <div class="col-xs-12">
|
|
|
- <div class="form-group">
|
|
|
- <label class="col-sm-2 control-label is-required">赛事标题:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <input name="competitionTitle" th:field="*{competitionTitle}" class="form-control" type="text" maxlength="50" required>
|
|
|
- </div>
|
|
|
- <label class="col-sm-2 control-label is-required">赛事类型:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <select name="competitionType" class="form-control" th:with="type=${@dict.getType('competition_type')}">
|
|
|
- <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{competitionType}"></option>
|
|
|
- </select>
|
|
|
- </div>
|
|
|
+<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
|
|
+ <form class="form-horizontal m" id="form-competition-edit" th:object="${competition}">
|
|
|
+ <input name="id" th:field="*{id}" type="hidden">
|
|
|
+ <div class="col-xs-12">
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-2 control-label is-required">赛事标题:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <input name="competitionTitle" th:field="*{competitionTitle}" class="form-control" type="text" maxlength="50" required>
|
|
|
+ </div>
|
|
|
+ <label class="col-sm-2 control-label is-required">赛事类型:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <select name="competitionType" class="form-control" th:with="type=${@dict.getType('competition_type')}">
|
|
|
+ <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{competitionType}"></option>
|
|
|
+ </select>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="col-xs-12">
|
|
|
- <div class="form-group">
|
|
|
- <label class="col-sm-2 control-label is-required">最大人数/团队数:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <input name="teamMax" th:field="*{teamMax}" class="form-control" type="text" required>
|
|
|
- </div>
|
|
|
- <label class="col-sm-2 control-label">场地:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <select name="competitionPlace" class="form-control" th:value="${competition.competitionPlace}">
|
|
|
- <option th:each="site : ${siteList}"
|
|
|
- th:value="${site.id}"
|
|
|
- th:text="${site.name}"
|
|
|
- th:selected="${site.name == competition.competitionPlace}">
|
|
|
- </option>
|
|
|
- </select>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ <div class="col-xs-12">
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-2 control-label is-required">最大人数/团队数:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <input name="teamMax" th:field="*{teamMax}" class="form-control" type="text" required>
|
|
|
+ </div>
|
|
|
+ <label class="col-sm-2 control-label">场地:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <select name="competitionPlace" class="form-control" th:value="${competition.competitionPlace}">
|
|
|
+ <option th:each="site : ${siteList}"
|
|
|
+ th:value="${site.id}"
|
|
|
+ th:text="${site.name}"
|
|
|
+ th:selected="${site.name == competition.competitionPlace}">
|
|
|
+ </option>
|
|
|
+ </select>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="col-xs-12">
|
|
|
- <div class="form-group">
|
|
|
- <label class="col-sm-2 control-label is-required">报名费用:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <input name="competitionExpense" th:field="*{competitionExpense}" class="form-control" type="text" required>
|
|
|
- </div>
|
|
|
- <label class="col-sm-2 control-label is-required">观看费用:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <input name="viewingTicket" th:field="*{viewingTicket}" class="form-control" type="text" required>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ <div class="col-xs-12">
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-2 control-label is-required">报名费用:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <input name="competitionExpense" th:field="*{competitionExpense}" class="form-control" type="text" required>
|
|
|
+ </div>
|
|
|
+ <label class="col-sm-2 control-label is-required">观看费用:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <input name="viewingTicket" th:field="*{viewingTicket}" class="form-control" type="text" required>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="col-xs-12">
|
|
|
- <div class="form-group">
|
|
|
- <label class="col-sm-2 control-label is-required">赛事开始时间:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <div class="input-group date">
|
|
|
- <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
|
|
|
- <input name="applyStartTime" th:value="${#dates.format(competition.applyStartTime, 'yyyy-MM-dd HH:mm')}" type="text" class="form-control" id="applyStartTime" placeholder="年-月-日 时:分" required>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <label class="col-sm-2 control-label is-required">赛事结束时间:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <div class="input-group date">
|
|
|
- <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
|
|
|
- <input name="applyEndTime" th:value="${#dates.format(competition.applyEndTime, 'yyyy-MM-dd HH:mm')}" type="text" class="form-control" id="applyEndTime" placeholder="年-月-日 时:分" required>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ <div class="col-xs-12">
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-2 control-label is-required">赛事开始时间:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <div class="input-group date">
|
|
|
+ <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
|
|
|
+ <input name="applyStartTime" th:value="${#dates.format(competition.applyStartTime, 'yyyy-MM-dd HH:mm')}" type="text" class="form-control" id="applyStartTime" placeholder="年-月-日 时:分" required>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- <div class="col-xs-12">
|
|
|
- <div class="form-group">
|
|
|
- <label class="col-sm-2 control-label is-required">取消报名截至时间:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <select th:field="*{applyBeforeTime}" name="applyBeforeTime" class="form-control">
|
|
|
- <option value="1">赛事开始前1小时</option>
|
|
|
- <option value="2">赛事开始前2小时</option>
|
|
|
- <option value="3">赛事开始前3小时</option>
|
|
|
- <option value="6">赛事开始前6小时</option>
|
|
|
- <option value="12">赛事开始前12小时</option>
|
|
|
- <option value="24">赛事开始前24小时</option>
|
|
|
- <option value="48">赛事开始前48小时</option>
|
|
|
- </select>
|
|
|
+ <label class="col-sm-2 control-label is-required">赛事结束时间:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <div class="input-group date">
|
|
|
+ <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
|
|
|
+ <input name="applyEndTime" th:value="${#dates.format(competition.applyEndTime, 'yyyy-MM-dd HH:mm')}" type="text" class="form-control" id="applyEndTime" placeholder="年-月-日 时:分" required>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
-
|
|
|
- <div class="col-xs-12">
|
|
|
- <div class="form-group">
|
|
|
- <label class="col-sm-2 control-label is-required">赛事详情:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <input type="hidden" class="form-control" th:field="*{competitionDetails}" required>
|
|
|
- <div class="summernote" id="competitionDetails"></div>
|
|
|
- </div>
|
|
|
- <label class="col-sm-2 control-label">报名须知:</label>
|
|
|
- <div class="col-sm-4">
|
|
|
- <input type="hidden" class="form-control" th:field="*{registrationNotes}">
|
|
|
- <div class="summernote" id="registrationNotes"></div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ <div class="col-xs-12">
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-2 control-label is-required">取消报名截至时间:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <select th:field="*{applyBeforeTime}" name="applyBeforeTime" class="form-control">
|
|
|
+ <option value="1">赛事开始前1小时</option>
|
|
|
+ <option value="2">赛事开始前2小时</option>
|
|
|
+ <option value="3">赛事开始前3小时</option>
|
|
|
+ <option value="6">赛事开始前6小时</option>
|
|
|
+ <option value="12">赛事开始前12小时</option>
|
|
|
+ <option value="24">赛事开始前24小时</option>
|
|
|
+ <option value="48">赛事开始前48小时</option>
|
|
|
+ </select>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="col-xs-12">
|
|
|
<div class="form-group">
|
|
|
- <label class="col-sm-2 control-label">图片:</label>
|
|
|
- <div class="col-sm-10">
|
|
|
- <input type="hidden" name="noticeImg" th:field="*{competitionImg}">
|
|
|
- <div class="file-loading">
|
|
|
- <input class="form-control file-upload" id="competitionImg" name="file" type="file" >
|
|
|
- </div>
|
|
|
+ <label class="col-sm-2 control-label is-required">赛事详情:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <input type="hidden" class="form-control" th:field="*{competitionDetails}" required>
|
|
|
+ <div class="summernote" id="competitionDetails"></div>
|
|
|
+ </div>
|
|
|
+ <label class="col-sm-2 control-label">报名须知:</label>
|
|
|
+ <div class="col-sm-4">
|
|
|
+ <input type="hidden" class="form-control" th:field="*{registrationNotes}">
|
|
|
+ <div class="summernote" id="registrationNotes"></div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </form>
|
|
|
- </div>
|
|
|
- <th:block th:include="include :: footer" />
|
|
|
- <th:block th:include="include :: datetimepicker-js" />
|
|
|
- <th:block th:include="include :: summernote-js" />
|
|
|
- <th:block th:include="include :: bootstrap-fileinput-js"/>
|
|
|
- <script th:inline="javascript">
|
|
|
- var prefix = ctx + "competition";
|
|
|
- $("#form-competition-edit").validate({
|
|
|
- focusCleanup: true,
|
|
|
- rules: {
|
|
|
- teamMax: {
|
|
|
- digits: true
|
|
|
- },
|
|
|
- competitionExpense: {
|
|
|
- required: true, // 必填
|
|
|
- digits: true, // 必须为整数
|
|
|
- min: 1 // 最小值为1,确保为正整数
|
|
|
- },
|
|
|
- viewingTicket: {
|
|
|
- required: true, // 必填
|
|
|
- digits: true, // 必须为整数
|
|
|
- min: 1 // 最小值为1,确保为正整数
|
|
|
- }
|
|
|
+ </div>
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-2 control-label">封面:</label>
|
|
|
+ <div class="col-sm-10">
|
|
|
+ <div id="image-upload-container"></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
+</div>
|
|
|
+<th:block th:include="include :: footer" />
|
|
|
+<th:block th:include="include :: datetimepicker-js" />
|
|
|
+<th:block th:include="include :: summernote-js" />
|
|
|
+<th:block th:include="include :: image-upload-js"/>
|
|
|
+<script th:inline="javascript">
|
|
|
+ var prefix = ctx + "competition";
|
|
|
+ $("#form-competition-edit").validate({
|
|
|
+ focusCleanup: true,
|
|
|
+ rules: {
|
|
|
+ teamMax: {
|
|
|
+ digits: true
|
|
|
},
|
|
|
- messages: {
|
|
|
- competitionExpense: {
|
|
|
- required: "报名费用不能为空",
|
|
|
- digits: "报名费用必须为整数",
|
|
|
- min: "报名费用必须大于0"
|
|
|
- },
|
|
|
- viewingTicket: {
|
|
|
- required: "观看费用不能为空",
|
|
|
- digits: "观看费用必须为整数",
|
|
|
- min: "观看费用必须大于0"
|
|
|
- }
|
|
|
+ competitionExpense: {
|
|
|
+ required: true, // 必填
|
|
|
+ digits: true, // 必须为整数
|
|
|
+ min: 1 // 最小值为1,确保为正整数
|
|
|
+ },
|
|
|
+ viewingTicket: {
|
|
|
+ required: true, // 必填
|
|
|
+ digits: true, // 必须为整数
|
|
|
+ min: 1 // 最小值为1,确保为正整数
|
|
|
}
|
|
|
- });
|
|
|
+ // 注意:这里不再验证 hidden 字段,由组件自己管理
|
|
|
+ },
|
|
|
+ messages: {
|
|
|
+ competitionExpense: {
|
|
|
+ required: "报名费用不能为空",
|
|
|
+ digits: "报名费用必须为整数",
|
|
|
+ min: "报名费用必须大于0"
|
|
|
+ },
|
|
|
+ viewingTicket: {
|
|
|
+ required: "观看费用不能为空",
|
|
|
+ digits: "观看费用必须为整数",
|
|
|
+ min: "观看费用必须大于0"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- function submitHandler() {
|
|
|
+ function submitHandler() {
|
|
|
+ var applyStartTime = $('#applyStartTime').val()
|
|
|
+ var applyEndTime = $('#applyEndTime').val()
|
|
|
+ var currentTime = getNowDate(); // 当前时间,格式为 YYYY-MM-DD HH:MM
|
|
|
|
|
|
- var applyStartTime = $('#applyStartTime').val()
|
|
|
- var applyEndTime = $('#applyEndTime').val()
|
|
|
- var currentTime = getNowDate(); // 当前时间,格式为 YYYY-MM-DD HH:MM
|
|
|
+ if ($.validate.form()) {
|
|
|
+ // 获取上传组件实例
|
|
|
+ var uploadInstance = $('#image-upload-container').data('imageUpload');
|
|
|
|
|
|
- if ($.validate.form()) {
|
|
|
+ // 检查是否有上传的图片
|
|
|
+ if (uploadInstance) {
|
|
|
+ var uploadedFiles = uploadInstance.getFiles();
|
|
|
+ console.log('已上传的图片:', uploadedFiles);
|
|
|
|
|
|
- // 检查赛事开始时间不能小于当前时间
|
|
|
- if (applyStartTime < currentTime) {
|
|
|
- $.modal.alertWarning("赛事开始时间不能小于当前时间");
|
|
|
+ // 检查封面图片是否上传
|
|
|
+ if (uploadedFiles.length === 0) {
|
|
|
+ $.modal.alertWarning("请上传封面图片");
|
|
|
return false;
|
|
|
}
|
|
|
+ // 组件会自动更新隐藏字段,我们不需要额外处理
|
|
|
+ } else {
|
|
|
+ // 如果没有上传组件实例,检查是否有隐藏字段
|
|
|
+ var existingImages = $('#form-competition-edit input[name="competitionImg"]').map(function() {
|
|
|
+ return $(this).val();
|
|
|
+ }).get().filter(function(val) {
|
|
|
+ return val && val.trim() !== '';
|
|
|
+ });
|
|
|
|
|
|
- // 检查赛事结束时间不能小于赛事开始时间
|
|
|
- if (applyEndTime < applyStartTime) {
|
|
|
- $.modal.alertWarning("赛事结束时间不能小于赛事开始时间");
|
|
|
+ if (existingImages.length === 0) {
|
|
|
+ $.modal.alertWarning("请上传封面图片");
|
|
|
return false;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- $.operate.save(prefix + "/edit", $('#form-competition-edit').serialize());
|
|
|
+ // 检查赛事开始时间不能小于当前时间
|
|
|
+ if (applyStartTime < currentTime) {
|
|
|
+ $.modal.alertWarning("赛事开始时间不能小于当前时间");
|
|
|
+ return false;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- $("input[name='applyStartTime']").datetimepicker({
|
|
|
- format: "yyyy-mm-dd hh:ii",
|
|
|
- autoclose: true
|
|
|
- });
|
|
|
+ // 检查赛事结束时间不能小于赛事开始时间
|
|
|
+ if (applyEndTime < applyStartTime) {
|
|
|
+ $.modal.alertWarning("赛事结束时间不能小于赛事开始时间");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- $("input[name='applyEndTime']").datetimepicker({
|
|
|
- format: "yyyy-mm-dd hh:ii",
|
|
|
- autoclose: true
|
|
|
- });
|
|
|
+ $.operate.save(prefix + "/edit", $('#form-competition-edit').serialize());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- function getNowDate(){
|
|
|
- // 获取当前时间
|
|
|
- var now = new Date();
|
|
|
+ $("input[name='applyStartTime']").datetimepicker({
|
|
|
+ format: "yyyy-mm-dd hh:ii",
|
|
|
+ autoclose: true
|
|
|
+ });
|
|
|
|
|
|
- // 格式化日期和时间
|
|
|
- var year = now.getFullYear(); // 获取年份
|
|
|
- var month = ("0" + (now.getMonth() + 1)).slice(-2); // 获取月份,加1是因为 getMonth() 返回的月份是从0开始的
|
|
|
- var day = ("0" + now.getDate()).slice(-2); // 获取日期
|
|
|
- var hours = ("0" + now.getHours()).slice(-2); // 获取小时
|
|
|
- var minutes = ("0" + now.getMinutes()).slice(-2); // 获取分钟
|
|
|
+ $("input[name='applyEndTime']").datetimepicker({
|
|
|
+ format: "yyyy-mm-dd hh:ii",
|
|
|
+ autoclose: true
|
|
|
+ });
|
|
|
|
|
|
- // 拼接成所需的格式
|
|
|
- return year + "-" + month + "-" + day + " " + hours + ":" + minutes;
|
|
|
+ function getNowDate(){
|
|
|
+ // 获取当前时间
|
|
|
+ var now = new Date();
|
|
|
|
|
|
- }
|
|
|
+ // 格式化日期和时间
|
|
|
+ var year = now.getFullYear(); // 获取年份
|
|
|
+ var month = ("0" + (now.getMonth() + 1)).slice(-2); // 获取月份,加1是因为 getMonth() 返回的月份是从0开始的
|
|
|
+ var day = ("0" + now.getDate()).slice(-2); // 获取日期
|
|
|
+ var hours = ("0" + now.getHours()).slice(-2); // 获取小时
|
|
|
+ var minutes = ("0" + now.getMinutes()).slice(-2); // 获取分钟
|
|
|
+
|
|
|
+ // 拼接成所需的格式
|
|
|
+ return year + "-" + month + "-" + day + " " + hours + ":" + minutes;
|
|
|
|
|
|
- $(function() {
|
|
|
+ }
|
|
|
|
|
|
- $('.summernote').each(function(i) {
|
|
|
- $('#' + this.id).summernote({
|
|
|
- lang: 'zh-CN',
|
|
|
- dialogsInBody: true,
|
|
|
- height: 400,
|
|
|
- callbacks: {
|
|
|
- onChange: function(contents, $edittable) {
|
|
|
- $("input[name='" + this.id + "']").val(contents);
|
|
|
- },
|
|
|
- onImageUpload: function(files) {
|
|
|
- var obj = this;
|
|
|
- var data = new FormData();
|
|
|
- data.append("file", files[0]);
|
|
|
- $.ajax({
|
|
|
- type: "post",
|
|
|
- url: ctx + "common/upload",
|
|
|
- data: data,
|
|
|
- cache: false,
|
|
|
- contentType: false,
|
|
|
- processData: false,
|
|
|
- dataType: 'json',
|
|
|
- success: function(result) {
|
|
|
- if (result.code == web_status.SUCCESS) {
|
|
|
- $('#' + obj.id).summernote('insertImage', result.url);
|
|
|
- } else {
|
|
|
- $.modal.alertError(result.msg);
|
|
|
- }
|
|
|
- },
|
|
|
- error: function(error) {
|
|
|
- $.modal.alertWarning("图片上传失败。");
|
|
|
+ $(function() {
|
|
|
+ // 初始化 summernote 编辑器
|
|
|
+ $('.summernote').each(function(i) {
|
|
|
+ $('#' + this.id).summernote({
|
|
|
+ lang: 'zh-CN',
|
|
|
+ dialogsInBody: true,
|
|
|
+ height: 400,
|
|
|
+ callbacks: {
|
|
|
+ onChange: function(contents, $edittable) {
|
|
|
+ $("input[name='" + this.id + "']").val(contents);
|
|
|
+ },
|
|
|
+ onImageUpload: function(files) {
|
|
|
+ var obj = this;
|
|
|
+ var data = new FormData();
|
|
|
+ data.append("file", files[0]);
|
|
|
+ $.ajax({
|
|
|
+ type: "post",
|
|
|
+ url: ctx + "common/upload",
|
|
|
+ data: data,
|
|
|
+ cache: false,
|
|
|
+ contentType: false,
|
|
|
+ processData: false,
|
|
|
+ dataType: 'json',
|
|
|
+ success: function(result) {
|
|
|
+ if (result.code == web_status.SUCCESS) {
|
|
|
+ $('#' + obj.id).summernote('insertImage', result.url);
|
|
|
+ } else {
|
|
|
+ $.modal.alertError(result.msg);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ },
|
|
|
+ error: function(error) {
|
|
|
+ $.modal.alertWarning("图片上传失败。");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- });
|
|
|
- var content = $("input[name='" + this.id + "']").val();
|
|
|
- $('#' + this.id).summernote('code', content);
|
|
|
- })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ var content = $("input[name='" + this.id + "']").val();
|
|
|
+ $('#' + this.id).summernote('code', content);
|
|
|
});
|
|
|
|
|
|
- $(".file-upload").each(function (i) {
|
|
|
- var inputName = this.id;
|
|
|
- var val = $("input[name='" + inputName + "']").val();
|
|
|
- // 将已上传的图片路径分割成数组
|
|
|
- var initialPreview = val ? val.split(',') : [];
|
|
|
- $(this).fileinput({
|
|
|
- uploadUrl: ctx + 'common/upload',
|
|
|
- initialPreviewAsData: true,
|
|
|
- initialPreview: initialPreview,
|
|
|
- maxFileCount: 1,
|
|
|
- allowedFileExtensions: ['jpg', 'png'],
|
|
|
- maxFileSize: 10240,
|
|
|
- multiple: false,
|
|
|
- }).on('fileuploaded', function (event, data, previewId, index) {
|
|
|
- var inputName = event.currentTarget.id;
|
|
|
- var fullUrl = data.response.url; // 获取完整的URL
|
|
|
- $("input[name='" + inputName + "']").val(fullUrl); // 只保留最新的图片 URL
|
|
|
- }).on('fileremoved', function (event, id, index) {
|
|
|
- var inputName = event.currentTarget.id;
|
|
|
- $("input[name='" + inputName + "']").val(''); // 移除后清空输入框
|
|
|
+ // ============ 修复:初始化图片上传组件并回显已有图片 ============
|
|
|
+ // 获取已有的封面图片数据(逗号分隔的字符串)
|
|
|
+ var imgStr = [[${competition.competitionImg}]];
|
|
|
+ var existingImages = [];
|
|
|
+
|
|
|
+ console.log('原始图片字符串:', imgStr);
|
|
|
+
|
|
|
+ if (imgStr && imgStr.trim() !== '') {
|
|
|
+ // 分割逗号分隔的图片字符串
|
|
|
+ existingImages = imgStr.split(',').map(function(img) {
|
|
|
+ return img.trim();
|
|
|
+ }).filter(function(img) {
|
|
|
+ // 过滤掉空字符串和无效的URL
|
|
|
+ return img !== '' && img !== null && img !== undefined;
|
|
|
});
|
|
|
|
|
|
- $(this).fileinput('_initFileActions');
|
|
|
+ console.log('解析后的图片数组:', existingImages);
|
|
|
+ console.log('图片数量:', existingImages.length);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化图片上传组件
|
|
|
+ var imageUploadConfig = {
|
|
|
+ uploadUrl: ctx + "common/upload",
|
|
|
+ maxFiles: 1,
|
|
|
+ maxSize: 5 * 1024 * 1024,
|
|
|
+ allowedTypes: ['image/jpeg', 'image/png'],
|
|
|
+ previewWidth: 200,
|
|
|
+ previewHeight: 150,
|
|
|
+ inputName: 'competitionImg'
|
|
|
+ };
|
|
|
+
|
|
|
+ // 只有在有图片时才传递 initialFiles
|
|
|
+ if (existingImages.length > 0) {
|
|
|
+ imageUploadConfig.initialFiles = existingImages;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('图片上传配置:', imageUploadConfig);
|
|
|
+
|
|
|
+ $('#image-upload-container').imageUpload(imageUploadConfig);
|
|
|
+
|
|
|
+ // 监听事件(可选)
|
|
|
+ $('#image-upload-container').on('upload.success', function(e, data) {
|
|
|
+ console.log('上传成功:', data.url);
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#image-upload-container').on('upload.error', function(e, data) {
|
|
|
+ console.error('上传失败:', data.error);
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#image-upload-container').on('files.set', function(e, data) {
|
|
|
+ console.log('图片已设置:', data.urls);
|
|
|
});
|
|
|
- </script>
|
|
|
+ // ============ 修复结束 ============
|
|
|
+ });
|
|
|
+</script>
|
|
|
</body>
|
|
|
</html>
|