<?php
  require __DIR__.'/head.html';
  require __DIR__.'/header.html';
  $File_Ming = 'addapi';
  require __DIR__.'/nav.html';
  ?>
<style>
    #admin-addapi .close {
        background-color: transparent;
        border: 0;
        -webkit-appearance: none;
    }
</style>
<!-- 主体 -->
<main class="app-content">
    <div class="app-title">
        <ul class="app-breadcrumb breadcrumb">
            <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
            <li class="breadcrumb-item">添加接口</li>
        </ul>
    </div>
    <div class="row">
        <div class="col-md-12">
            <form id="admin-addapi">
                <div class="tile">
                    <div class="bs-component">
                        <div class="alert alert-dismissible alert-success">
                            <input class="close" type="button" value="x" data-dismiss="alert">
                            1.别名用做访问识别，请认真填写;<br />
                            2.接口地址格式：域名/api/别名?参数<br />
                            3.返回格式于请求方式仅共参考使用,不是作为接口访问类型<br />
                            4.数据接口仅调用当前程序数据库中的数据，可自行加表，上传文件的接口不用开启<br />
                            5.接口收费开启后才能设置价格，否则不起作用<br />
                            6.接口上架如果不选仅添加，但不进行推广，不会显示在前台和用户的商品中<br />
                            7.非数据类型接口需要上传接口文件到根目录下的【view/api/新建文件夹名称为别名】<br />
                            8.上传的接口文件如果附带其他文件，引用时请在地址前边加上 【__DIR__】函数，例：__DIR__."/a.png";
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-6">

                            <div class="form-group">
                                <label for="title">接口标题</label>
                                <input class="form-control" id="title" type="text" aria-describedby="title" name="title"
                                    value="" placeholder="短网址生成">
                            </div>

                            <div class="form-group">
                                <label for="alias">别名（用于区分访问）</label>
                                <input class="form-control" id="alias" type="text" aria-describedby="alias" name="alias"
                                    value="" placeholder="dwz">
                            </div>

                            <div class="form-group">
                                <label for="desc">简介说明</label>
                                <input class="form-control" id="desc" type="text" aria-describedby="desc" name="desc"
                                    value="" placeholder="将长网址进行缩短，支持百度、新浪、腾讯短网址等等。">
                            </div>
                            <div class="form-group">
                                <label for="address">接口地址</label>
                                <input class="form-control" id="address" type="text" aria-describedby="address"
                                    name="address" value="" placeholder="https://api.aa1.cn/api/dwz?url=">
                            </div>
                            <div class="form-group">
                                <label for="format">返回格式</label>
                                <input class="form-control" id="format" type="text" aria-describedby="format"
                                    name="format" value="" placeholder="JSON">
                            </div>
                            <div class="form-group">
                                <label for="mode">请求方式</label>
                                <input class="form-control" id="mode" type="text" aria-describedby="mode" name="mode"
                                    value="" placeholder="GET">
                            </div>
                            <div class="form-group">
                                <label for="ask">请求示例</label>
                                <input class="form-control" id="ask" type="text" aria-describedby="ask" name="ask"
                                    value="" placeholder="https://apiv.aa1.cn/api/dwz?url=">
                            </div>


                        </div>

                        <div class="col-lg-6">
<div class="form-group">
                                <label for="tuimg">接口图片</label>
                                <input class="form-control" id="tuimg" type="text" aria-describedby="tuimg" name="tuimg"
                                    value="" placeholder="https://cdn.wpon.cn/logo.img">
                            </div>
                            <div class="form-group">
                                <label for="example">返回示例</label>
                                <textarea class="form-control" id="example" name="example" rows="5" placeholder='{
    "code": 1, 
    "msg": "生成成功", 
    "url": "http://blog.oioweb.cn", 
    "data": {
        "tcn": "http://t.cn/RuewNC3", 
        "url": "https://url.cn/59WAm1B"
    }
}'></textarea>
                            </div>

                            <div class="form-group">
                                <label for="demo">代码示例</label>
                                <p>暂无示例,站长交流群：938564996 进行交流</p>
                                <textarea class="form-control" id="demo" name="demo" rows="4"
                                    placeholder='暂无示例,站长交流群：938564996 进行交流' value='暂无示例,站长交流群：938564996 进行交流'></textarea>
                            </div>

                            <div class="form-group">
                                <label for="details">数据接口（判断是否调用自定义数据库数据）</label>
                                <div class="toggle-flip">
                                    <label>
                                        <input type="checkbox" value="1" name="datatype"><span class="flip-indecator"
                                            data-toggle-on="ON" data-toggle-off="OFF"></span>
                                    </label>
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="details">接口收费<span class="help-block" style="color:red">
                                        （接口收费请在接口列表编辑中设置）</span></label>
                                <div class="toggle-flip">
                                    <label>
                                        <input type="checkbox" value="1" name="pay"><span class="flip-indecator"
                                            data-toggle-on="ON" data-toggle-off="OFF"></span>
                                    </label>
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="details">接口上架</label>
                                <div class="toggle-flip">
                                    <label>
                                        <input type="checkbox" value="1" name="show"><span class="flip-indecator"
                                            data-toggle-on="ON" data-toggle-off="OFF"></span>
                                    </label>
                                </div>

                            </div>

                        </div>

                    </div>
                    <div class="tile-footer">
                        <input type="hidden" value="addapi" name="target" style="display: none">
                        <button type="button" class="btn btn-primary">添加</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <?php  require __DIR__.'/fooer.html'; ?>
    <script>
        $('#admin-addapi button').click(function () {
            fd = new FormData(document.getElementById('admin-addapi'));
            $.ajax({
                url: '/admin/addapi',
                type: "POST",
                timeout: "5000",
                dataType: "json",
                contentType: 'application/x-www-form-urlencoded;charset=utf-8',
                data: fd,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data.code == "200") {
                        layer.msg(data.msg, function () {
                            location.reload();
                        });
                    } else {
                        layer.msg(data.msg);
                    }
                },
                error: function (XMLResponse) {
                    layer.msg(XMLResponse.error);
                }
            });
        });

        //初始化地址
        var apiUrl = "<?php echo $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/api/';?>";

        //监听别名
        $('#alias').bind('input propertychange', function () {
            if ($(this).val()) {
                $('#address').val(apiUrl + $(this).val());
                $('#ask').val(apiUrl + $(this).val());
            } else {
                $('#address').val('');
                $('#ask').val('');
            }
        })

    </script>
    </body>

    </html>