IndexQRCode.cshtml 5.52 KB
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@section header
{    
    <style type="text/css">
        .layui-col-sm6{
            /*display:flex;*/
        }
        .layui-input-block2:{
            width:80%;
        }
        .label {
            height:240px !important;
        }
        .text {
            border-top:1px solid #eee;
            border-bottom:1px solid #eee;
            border-right:1px solid #eee;
            display: flex;
            justify-content: center;
            width: 80%;
            height: 240px;
        }
        .qrCode {
            width:200px; 
            height:200px; 
        }
        .layui-input{
            width:80%;
        }
     </style>
}
<div class="layui-form layui-form-pane">
    <div class="layui-row">
        <div class="layui-form-item">
            <p>请在下面文本框输入数据,然后按回车键。</p>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-sm6">
                <label class="layui-form-label">二维码数据1</label>
                <div class="layui-input-block2">
                    <input id="qrCode1" type="text" class="layui-input">
                </div>
            </div>
            <div class="layui-col-sm6">
                <label class="layui-form-label">二维码数据2</label>
                <div class="layui-input-block2">
                    <input id="qrCode2" type="text" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-sm6">
                <label class="layui-form-label label">二维码生成1</label>
                <div class="text layui-input-block2">
                    <div id="qrCodeData1" class="qrCode" style="margin-bottom:20px;"></div>
                </div>
            </div>
            <div class="layui-col-sm6">
                <label class="layui-form-label label">二维码生成2</label>
                <div class="text layui-input-block2">
                    <div id="qrCodeData2" class="qrCode" style="margin-bottom:20px;"></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-sm6">
                <label class="layui-form-label">二维码数据3</label>
                <div class="layui-input-block2">
                    <input id="qrCode3" type="text" class="layui-input">
                </div>
            </div>
            <div class="layui-col-sm6">
                <label class="layui-form-label">二维码数据4</label>
                <div class="layui-input-block2">
                    <input id="qrCode4" type="text" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-sm6">
                <label class="layui-form-label label">二维码生成3</label>
                <div class="text layui-input-block2">
                    <div id="qrCodeData3" class="qrCode" style="margin-top:20px;"></div>
                </div>
            </div>
            <div class="layui-col-sm6">
                <label class="layui-form-label label">二维码生成4</label>
                <div class="text layui-input-block2">
                    <div id="qrCodeData4" class="qrCode" style="margin-top:20px;"></div>
                </div>
            </div>
        </div>
    </div>
</div>

@section Scripts
{
    <script  type="text/javascript" src="~/js/qrcode.js"></script>
    <script type="text/javascript">
        var qrCodeData1 = new QRCode(document.getElementById("qrCodeData1"), { width: 200, height: 200 });
        var qrCodeData2 = new QRCode(document.getElementById("qrCodeData2"), { width: 200, height: 200 });
        var qrCodeData3 = new QRCode(document.getElementById("qrCodeData3"), { width: 200, height: 200 });
        var qrCodeData4 = new QRCode(document.getElementById("qrCodeData4"), { width: 200, height: 200 });
        var inputQRCode1 = document.getElementById("qrCode1");
        var inputQRCode2 = document.getElementById("qrCode2");
        var inputQRCode3 = document.getElementById("qrCode3");
        var inputQRCode4 = document.getElementById("qrCode4");
        function makeCode() {
            if (inputQRCode1.value) {
                qrCodeData1.makeCode(inputQRCode1.value);
            }
            if (inputQRCode2.value) {
                qrCodeData2.makeCode(inputQRCode2.value);
            }
            if (inputQRCode3.value) {
                qrCodeData3.makeCode(inputQRCode3.value);
            }
            if (inputQRCode4.value) {
                qrCodeData4.makeCode(inputQRCode4.value);
            }
        }
        makeCode();
        inputQRCode1.addEventListener("keydown", (e) => {
            if (e.keyCode == 13) {
                makeCode();
            }
        });
        inputQRCode2.addEventListener("keydown", (e) => {
            if (e.keyCode == 13) {
                makeCode();
            }
        });
        inputQRCode3.addEventListener("keydown", (e) => {
            if (e.keyCode == 13) {
                makeCode();
            }
        });
        inputQRCode4.addEventListener("keydown", (e) => {
            if (e.keyCode == 13) {
                makeCode();
            }
        });
        inputQRCode1.addEventListener("blur", makeCode);
        inputQRCode2.addEventListener("blur", makeCode);
        inputQRCode3.addEventListener("blur", makeCode);
        inputQRCode4.addEventListener("blur", makeCode);
    </script>
}