PostManIndex.cshtml 6.94 KB
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<div class="layui-body layui-tab-content">
    <div class="layui-tab-item layui-show">
        <div class="layui-main">
            <div id="LAY_preview">
                <form class="layui-form" action="" lay-filter="example" onsubmit="return false;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">URL<label class="lable-required">*</label></label>
                        <div class="layui-input-block">
                            <input type="text" name="URL" placeholder="请输入要请求的URL" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">请求方式</label>
                        <div class="layui-input-block">
                            <select name="Method">
                                <option value="post">post方式</option>
                                <option value="get">get方式</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">ContentType)</label>
                        <div class="layui-input-block">
                            <select name="ContentType">
                                <option value="application/json">application/json</option>
                                <option value="poapplication/x-www-form-urlencodedst">application/x-www-form-urlencoded</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">dataType返回格式</label>
                        <div class="layui-input-block">
                            <select name="dataType" id="dataType">
                                <option value="json">json</option>
                                <option value="text">text</option>
                                <option value="html">html</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">POST数据</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入数据(可选项GET时不需要写)&#13;&#10;contentType: 告诉服务器,我要发什么类型的数据&#13;&#10;dataType:告诉服务器,我要想什么类型的数据,如果没有指定,那么会自动推断" class="layui-textarea" name="Postdata"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">Referer</label>
                        <div class="layui-input-block">
                            <input type="text" name="Referer" placeholder="请输入Referer" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">设定Header</label>
                        <div class="layui-input-block">
                            <input type="text" name="HeaderStr" placeholder="Key:Value格式,可写多个请&$隔开不要有特殊符号" class="layui-input">
                        </div>
                    </div>
                    <br />
                    <div class="layui-form-item">
                        <label class="layui-form-label">返回结果</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea" id="result" rows="8" name="result"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" name="fromAdd" lay-filter="fromAdd" lay-submit>模拟请求</button>
                            <button type="button" class="layui-btn layui-btn-normal" id="btnCopyResult">复制返回结果</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                    <blockquote class="layui-elem-quote" style="margin-top: 10px;">
                        更多我们未能呈现的示例,还有待您在多提出Bug,去深入挖掘。
                    </blockquote>
                </form>
            </div>
        </div>
    </div>
</div>
@section Scripts
{

    <script>
        layui.config({
            base: "/js/",
            version: 333
        }).use(['system'], function () {
            var form = layui.form,
                sysU = new layui.system.u(),
                areaName = 'Planned',
                tableName = 'Tool';

            var app = {
                data: {
                    eleSubmit: "submit(fromAdd)",
                    eleResult: $("#result"),
                    eleCopy: $("#btnCopyResult"),
                    dataType: $("#dataType")
                },
                methods: {
                    postMan() {
                        form.on(app.data.eleSubmit, function (data) {
                            var result = sysU.requiredExtend(data.form);
                            if (!result) return false;
                            var ajaxConfig = {
                                data: { httpItem: data.field },
                                dataType: app.data.dataType.val(),
                                url: `/${areaName}/${tableName}/PostMan`,
                                success: function (json) {
                                    app.data.eleResult.val(JSON.stringify(json));
                                }
                            };
                            sysU.ajax(ajaxConfig);
                            return false;
                        });
                    },

                    copyResult() {
                        var result = document.getElementById("result");
                        if (result.value == "") return;
                        result.select();
                        document.execCommand("Copy");
                        layer.alert("已复制好,可贴粘。", { icon: 6, shade: 0.4, time: sysU.config.msgOpenTime });
                    }
                },
                registerEvent: function () {
                    app.data.eleCopy.click(function () {
                        app.methods.copyResult();
                    });
                },
                init: function () {
                    app.methods.postMan();
                    app.registerEvent();
                }
            };
            app.init();
        });
    </script>
}