This commit is contained in:
BianLzhaoMin 2025-02-25 17:04:56 +08:00
parent 9d53fe2681
commit fdbd209b6f
1 changed files with 37 additions and 15 deletions

View File

@ -26,8 +26,8 @@
</div> </div>
<div class="layui-form-item" style="display: none"> <div class="layui-form-item" style="display: none">
<div class="layui-input-block"> <div class="layui-input-block">
<button type="submit" class="layui-btn subBtn" id="commit" lay-submit lay-filter="formDemo">提交 <!-- <button type="submit" class="layui-btn subBtn" id="commit" lay-submit lay-filter="formDemo">提交
</button> </button> -->
</div> </div>
</div> </div>
</form> </form>
@ -52,7 +52,7 @@
tableLoading = layer.load(2, { shade: [0.1, '#fff'] }); tableLoading = layer.load(2, { shade: [0.1, '#fff'] });
initTable(); initTable();
form.on('submit(formDemo)', function (data) { form.on('submit(formDemo)', function (data) {
getTableData(); // getTableData();
return false; return false;
}); });
}); });
@ -238,7 +238,7 @@
let innerHtml = '' let innerHtml = ''
dialogLabelList.forEach((e, index) => { dialogLabelList.forEach((e, index) => {
innerHtml += `<div style="display: flex; align-items: center;"> innerHtml += `<div style="padding:6px 0;display: flex; align-items: center;">
<div style="margin-right: 10px;width: 200px";>${e.title}</div> <div style="margin-right: 10px;width: 200px";>${e.title}</div>
<input type="text" data-id="${dialogLabelInfo[index].field}" id="numberInput" name="numberInput" min="0.01" step="0.01" placeholder="请输入大于0的数字" style=";width:180px; padding:1px 5px;" value="${tableList[rowIndex][dialogLabelInfo[index].field]}"> <input type="text" data-id="${dialogLabelInfo[index].field}" id="numberInput" name="numberInput" min="0.01" step="0.01" placeholder="请输入大于0的数字" style=";width:180px; padding:1px 5px;" value="${tableList[rowIndex][dialogLabelInfo[index].field]}">
<button type="button" id="uploadBtn" style="color: #4CAF50; border: none; margin-left: 10px; cursor: pointer;"> <button type="button" id="uploadBtn" style="color: #4CAF50; border: none; margin-left: 10px; cursor: pointer;">
@ -268,18 +268,35 @@
event.preventDefault(); // 阻止默认行为 event.preventDefault(); // 阻止默认行为
console.log('上传附件按钮被点击了'); console.log('上传附件按钮被点击了');
layui.use('upload', function () {
var upload = layui.upload;
// 执行上传功能
var uploadInst = upload.render({
elem: '#uploadBtn', // 上传按钮
url: '/upload/', // 文件上传接口(这里要根据实际接口替换)
accept: 'file', // 选择文件类型
multiple: false, // 支持多文件上传
auto: false, // 禁用自动上传,点击确定按钮后上传
bindAction: '#uploadConfirm', // 确定按钮触发上传
choose: function (obj) {
// 当选择文件时会触发这个方法
var files = obj.pushFile(); // 获取文件列表
console.log(files);
},
done: function (res) {
// 上传完毕回调
console.log('文件上传成功');
console.log(res);
},
error: function () {
// 请求异常回调
console.log('文件上传失败');
}
});
});
// 在这里可以添加附件上传的逻辑,例如打开文件选择器等 // 在这里可以添加附件上传的逻辑,例如打开文件选择器等
}); });
// 表单提交前验证输入是否大于0
$('#uploadForm').on('submit', function (event) {
var inputValue = $('#numberInput').val();
if (parseFloat(inputValue) <= 0) {
alert('请输入大于 0 的数字');
event.preventDefault(); // 阻止表单提交
}
});
}, },
yes: function (index, layero) { yes: function (index, layero) {
// 点击"确定"按钮时的逻辑 // 点击"确定"按钮时的逻辑
@ -288,9 +305,14 @@
let fields = dialogLabelInfo.map((e) => e.field) let fields = dialogLabelInfo.map((e) => e.field)
$('#uploadForm input').each(function () { $('#uploadForm input').each(function () {
let inputValue = $(this).val(); let inputValue = $(this).val();
let dataId = $(this).data('id'); // 获取 data-id
if (parseFloat(inputValue) < 0) {
layer.msg('请输入大于0的数字')
return false
}
let dataId = $(this).data('id') // 获取 data-id
if (dataId && inputValue) { if (dataId && inputValue) {
formData[dataId] = inputValue; // 将 data-id 作为键,输入框的值作为值 formData[dataId] = inputValue * 1 // 将 data-id 作为键,输入框的值作为值
} }
}) })
const currentRows = tableList[rowIndex] const currentRows = tableList[rowIndex]