mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-11-13 14:13:43 +08:00
修复安装时模板引用报错问题,
添加二维码图片上传功能,可以支持远程图片地址和生成二维码图片。
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">收款样式</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="type">
|
||||
<select name="type" lay-filter="type">
|
||||
<option value="">请选择</option>
|
||||
<option value="0">付款链接</option>
|
||||
<option value="1">图片地址</option>
|
||||
@@ -49,10 +49,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">付款地址</label>
|
||||
<label class="layui-form-label">收款码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="qrcode" autocomplete="off" lay-affix="upload-drag"
|
||||
lay-filter="scanning" class="layui-input">
|
||||
lay-filter="scanning" class="layui-input" data-type="<?php echo match ((int)$type) {0 => 'link',1 => 'img',default => ''}; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item" pane>
|
||||
@@ -98,8 +98,33 @@
|
||||
"type": '<?php echo $type ?>'
|
||||
});
|
||||
|
||||
form.on('input-affix(scanning)', function () {
|
||||
window.open('https://cli.im/deqr', '_blank');
|
||||
form.on('input-affix(scanning)', function (obj) {
|
||||
const type = obj.elem.getAttribute('data-type');
|
||||
if (type === '') {
|
||||
layer.msg('请先选择二维码类型!', { tips: 2, time: 1200 });
|
||||
return false;
|
||||
}
|
||||
if (type === 'img') {
|
||||
uploadCodeImg(obj.elem);
|
||||
return false;
|
||||
}
|
||||
if (type === 'link') {
|
||||
window.open('https://cli.im/deqr', '_blank');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
form.on('select(type)', function (data) {
|
||||
const form = data.elem.form;
|
||||
const value = data.value;
|
||||
const inuptelem = form.querySelector('input[name="qrcode"]');
|
||||
if (value === '0') {
|
||||
inuptelem.setAttribute('data-type', 'link');
|
||||
return false;
|
||||
}
|
||||
if (value === '1') {
|
||||
inuptelem.setAttribute('data-type', 'img');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
form.on('submit(save)', function (obj) {
|
||||
@@ -126,6 +151,40 @@
|
||||
})()
|
||||
return false;
|
||||
});
|
||||
// 上传二维码图片
|
||||
async function uploadCodeImg(elem) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/*';
|
||||
input.onchange = async (event) => {
|
||||
const file = event.target.files[0];
|
||||
if (file) {
|
||||
const formData = new FormData();
|
||||
formData.append('codeimg', file);
|
||||
try {
|
||||
const response = await fetch('/api/PayManage/uploadQrcode', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
if (result.code === 0) {
|
||||
layer.msg(result.msg, { icon: 1, time: 1200 });
|
||||
elem.value = result.data.imgpath;
|
||||
return result.data.imgpath;
|
||||
} else {
|
||||
layer.msg('上传失败:' + result.message, { tips: 2, time: 1200 });
|
||||
}
|
||||
} else {
|
||||
layer.msg('上传失败:服务器错误', { tips: 2, time: 1200 });
|
||||
}
|
||||
} catch (error) {
|
||||
layer.msg('上传失败:' + error.message, { tips: 2, time: 1200 });
|
||||
}
|
||||
}
|
||||
};
|
||||
input.click();
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user