<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/'} ">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="assets/js/vendor/viewer/viewer.min.css">
    <link href="assets/js/vendor/json-viewer/jquery.json-viewer.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form layui-form-pane" lay-filter="dataForm">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">Json数据<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <textarea id="jsonData" name="jsonData" value="" placeholder="请输入Json数据" class="layui-textarea" rows="8" style="height: auto; line-height: 39px">{}</textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-row" pane="">
                    <div class="layui-col-lg6">
                        <label class="layui-form-label">收缩节点<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="checkbox" value="1" id="collapsed" name="collapsed" lay-skin="switch" lay-text="是|否">
                        </div>
                    </div>
                    <div class="layui-col-lg6">
                        <label class="layui-form-label">添加引号<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="checkbox" value="1" id="with-quotes" name="with-quotes" lay-skin="switch" lay-text="是|否">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button type="button" class="layui-btn layui-btn-warm" lay-submit lay-filter="checkForm">校验数据</button>
                            <button type="button" class="layui-btn" lay-submit lay-filter="submitForm">校验数据并保存</button>
                            <button type="button" class="layui-btn layui-btn-primary close">返回上级</button>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <div class="layui-input-block">
                        <pre id="json-renderer"></pre>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="assets/js/vendor/wangEditor/wangEditor.min.js"></script>
<script src="assets/js/vendor/ckplayer/ckplayer/ckplayer.js"></script>
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script src="assets/js/vendor/json-viewer/jquery-1.11.0.min.js"></script>
<script src="assets/js/vendor/json-viewer/jquery.json-viewer.js"></script>
<script>

    function jsonRenderer(input, options) {
        $('#json-renderer').jsonViewer(input, options);
    }

    layui.config({
        base: 'assets/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'layer','form', 'laydate', 'laytpl'], function(){
        var $ = layui.$;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var wangEditor = window.wangEditor;
        var wangEditorObj = {};
        var viewerObj = {};
        var jsonData = top.restAjax.params(window.location.href).jsonData + '';

        function closeBox() {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

        // 初始化内容
        function initData() {
            var dataFormData = {'jsonData' : jsonData};
            form.val('dataForm', dataFormData);
            form.render(null, 'dataForm');
        }
        initData();
        // 提交表单
        form.on('submit(checkForm)', function(formData) {
            try {
                var input = eval('(' + formData.field.jsonData + ')');
            } catch (error) {
                return layer.msg("输入的Json数据不合法");
            }
            var options = {
                collapsed: $('#collapsed').is(':checked'),
                withQuotes: $('#with-quotes').is(':checked')
            };
            jsonRenderer(input, options);
        });

        // 提交表单
        form.on('submit(submitForm)', function(formData) {
            try {
                var input = eval('(' + formData.field.jsonData + ')');
                var options = {
                    collapsed: $('#collapsed').is(':checked'),
                    withQuotes: $('#with-quotes').is(':checked')
                };
                jsonRenderer(input, options);
            } catch (error) {
                return layer.msg("输入的Json数据不合法");
            }
            var reason = formData.field.jsonData.replace(/[\n\r]/gi,"").replace(/[ ]/g,"");
            top.dialog.dialogData.jsonViewerData = reason;
            closeBox();
        });

        $('.close').on('click', function() {
            top.dialog.dialogData.jsonViewerData = "";
            closeBox();
        });

        // 校验
        form.verify({
        });
    });
</script>
</body>
</html>