<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>个人资料</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
    <link rel="stylesheet" href="/admin/css/other/person.css" />
    <style>
        .userset {
            position: absolute;
            right: 20px;
            top: 20px;
            z-index: 999;
        }
    </style>
</head>

<body class="pear-container">
    <div style="padding: 8px;">
        <div class="layui-row layui-col-space16">
            <div class="layui-col-md4">
                <div class="layui-card">
                    <div class="userset"><a href="javascript:;" lay-on="setUser" title="设置">
                            <span class="icon pear-icon pear-icon-setting" style="font-size: 20px;"></span></a></div>
                    <div class="layui-card-body" style="padding: 25px;">
                        <div class="text-center layui-text">
                            <div class="user-info-head" id="userInfoHead">
                                <img src="/admin/images/avatar.jpg" id="userAvatar" width="115px" height="115px" alt="">
                            </div>
                            <h2 style="padding-top: 20px;font-size: 20px;">
                                <?php echo $nickname ?>
                            </h2>
                            <p style="padding-top: 8px;margin-top: 10px;font-size: 16px;">
                                <?php echo $username ?>
                            </p>
                        </div>
                    </div>
                    <div class="layui-elip"
                        style="height: 45px;border-top: 1px whitesmoke solid;text-align: center;line-height: 45px;font-size: 13.5px; padding: 0 32px;">
                        <span id="yiyan"></span>
                    </div>
                </div>

                <div class="layui-card">
                    <div class="layui-card-header">API 密钥</div>
                    <div class="layui-card-body">
                        <div class="layui-form layui-form-pane">
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">API 接口</label>
                                <div class="layui-input-block">
                                    <div class="layui-form-mid" style="margin-left: 10px;color: #5f5f5f;float: none;">
                                        <?php echo $url ?>
                                        <a href="javascript:;" lay-on="copyinfo" data-info="<?php echo $url ?>"
                                            style="float: right;" title="复制"><span
                                                class="icon pear-icon pear-icon-survey"></span></a>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">商户 PID</label>
                                <div class="layui-input-block">
                                    <div class="layui-form-mid" style="margin-left: 10px;color: #5f5f5f;float: none;">
                                        <?php echo $pid ?>
                                        <a href="javascript:;" lay-on="copyinfo" data-info="<?php echo $pid ?>"
                                            style="float: right;" title="复制"><span
                                                class="icon pear-icon pear-icon-survey"></span></a>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">商户密钥 <a href="javascript:;" lay-on="resetKey"
                                        title="重置密钥"><span class="icon pear-icon pear-icon-refresh"></span></a></label>
                                <div class="layui-input-block">
                                    <div class="layui-form-mid layui-elip"
                                        style="margin-left: 10px;color: #5f5f5f;float: none;">
                                        <?php echo $secret_key ?>
                                        <a href="javascript:;" lay-on="copyinfo" data-info="<?php echo $secret_key ?>"
                                            style="float: right;" title="复制"><span
                                                class="icon pear-icon pear-icon-survey"></span></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md8">
                <div class="layui-card">
                    <div class="layui-card-header">
                        我的文章
                    </div>
                    <div class="layui-card-body">

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="/component/layui/layui.js"></script>
    <script src="/component/pear/pear.js"></script>
    <script>
        layui.use(['layer', 'util'], () => {
            let util = layui.util;
            let layer = layui.layer;

            util.on({
                'copyinfo': (ele) => {
                    const info = ele.attr('data-info');
                    navigator.clipboard.writeText(info).then(() => { layer.msg('复制成功') });
                },
                'resetKey': (ele) => {
                    layer.confirm('重置密钥后，将无法使用原密钥，是否继续？', { icon: 3, title: '重置密钥' }, function (index) {
                        layer.close(index);
                        tool.resetKey();
                    });
                },
                'setUser': (ele) => {
                    tool.setUser();
                }
            });

            let tool = {};
            tool.resetKey = async (id) => {
                const res = await fetch(`/api/user/resetKey?id=${id}`);
                const data = await res.json();
                if (data.code === 0) {
                    layer.msg('密钥重置成功');
                    location.reload();
                }
            }
            tool.setUser = async () => {
                layer.open({
                    id: 'iframe-set-user',
                    type: 2,
                    title: '修改',
                    shade: 0.1,
                    area: ['500px', '400px'],
                    content: `/User/setUser`,
                });
            }

        });
        fetch('https://tenapi.cn/v2/yiyan').then(res => res.text()).then(data => { document.getElementById('yiyan').innerHTML = data || '人无横财不富，马无夜草不肥'; })


    </script>
</body>

</html>