| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 | <?php/** * Created by PhpStorm. * User         : zgcLives * CreateTime   : 2023/5/3 10:54 */namespace addons\exam\library;class FrontService{    /** 小程序页面列表 */    const PAGES        = [            [                'path'   => '/pages/index/index',                'name'   => '首页',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/search/index',                'name'   => '题目搜索',                'params' => [                    [                        'field'   => 'keyword',                        'name'    => '搜索关键词',                        'type'    => 'string',                        'require' => false,                        'value'   => '',                    ],                ],                'module' => '',            ],            [                'path'   => '/pages/paper/index',                'name'   => '试卷列表',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/paper/paper',                'name'   => '考试试卷',                'params' => [                    [                        'field'      => 'id',                        'name'       => '试卷ID',                        'type'       => 'selectpage',                        'require'    => true,                        'value'      => '',                        'selectpage' => [                            'source' => 'exam/paper/index',                            'field'  => 'title',                            'params' => [],                        ],                    ],                    [                        'field'      => 'room_id',                        'name'       => '考场ID',                        'type'       => 'selectpage',                        'require'    => false,                        'value'      => '',                        'selectpage' => [                            'source' => 'exam/room/index',                            'field'  => 'name',                            'params' => [],                        ],                    ],                ],                'module' => '',            ],            [                'path'   => '/pages/paper/grade',                'name'   => '考试记录',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/paper/rank',                'name'   => '考试排行榜',                'params' => [                    [                        'field'      => 'paper_id',                        'name'       => '试卷ID',                        'type'       => 'selectpage',                        'require'    => true,                        'value'      => '',                        'selectpage' => [                            'source' => 'exam/paper/index',                            'field'  => 'title',                            'params' => [],                        ],                    ],                ],                'module' => '',            ],            [                'path'   => '/pages/room/index',                'name'   => '考场列表',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/room/detail',                'name'   => '考场详情',                'params' => [                    [                        'field'      => 'id',                        'name'       => '考场ID',                        'type'       => 'selectpage',                        'require'    => true,                        'value'      => '',                        'selectpage' => [                            'source' => 'exam/room/index',                            'field'  => 'name',                            'params' => [],                        ],                    ],                ],                'module' => '',            ],            [                'path'   => '/pages/room/grade',                'name'   => '考场成绩',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/room/rank',                'name'   => '考场排行榜',                'params' => [                    [                        'field'      => 'paper_id',                        'name'       => '试卷ID',                        'type'       => 'selectpage',                        'require'    => true,                        'value'      => '',                        'selectpage' => [                            'source' => 'exam/paper/index',                            'field'  => 'title',                            'params' => [],                        ],                    ],                    [                        'field'      => 'room_id',                        'name'       => '考场ID',                        'type'       => 'selectpage',                        'require'    => true,                        'value'      => '',                        'selectpage' => [                            'source' => 'exam/room/index',                            'field'  => 'name',                            'params' => [],                        ],                    ],                ],                'module' => '',            ],            [                'path'   => '/pages/room/signup-index',                'name'   => '考场报名记录',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/user/user',                'name'   => '用户中心',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/user/set',                'name'   => '个人设置',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/user/my-cate',                'name'   => '常用题库设置',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/user/login-reg',                'name'   => '登录注册',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/collect/index',                'name'   => '我的收藏',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/wrong/index',                'name'   => '错题记录',                'params' => [],                'module' => '',            ],            [                'path'   => '/pages/webview/webview',                'name'   => '跳转网页',                'params' => [                    [                        'field'   => 'url',                        'name'    => '网页地址',                        'type'    => 'string',                        'require' => true,                        'value'   => '',                    ],                ],                'module' => '',            ],        ];    /**     * 获取小程序跳转路径及参数     * @return string     */    public static function buildUrl($path, $params = [])    {        return $path . '?' . http_build_query($params);    }    /**     * 替换内容里的图片CDN链接     * @param $title     * @return string     */    public static function replaceImgUrl($title)    {        $pattern = '/<img.*?src="(.*?)".*?>/i';        $title   = preg_replace_callback($pattern, function ($matches) {            $full = $matches[0];            if (!empty($matches[1])) {                return str_replace($matches[1], cdnurl($matches[1], true), $full);            }            $url      = $matches[1];            $host     = parse_url($url, PHP_URL_HOST);            $cdn_host = parse_url(cdnurl('', true), PHP_URL_HOST);            if ($host) {                if ($host != $cdn_host) {                    $url = str_replace($host, $cdn_host, $url);                }            } else {                $url = cdnurl($url, true);            }            // ddd($matches);            return '<img src="' . $url . '">';        }, $title);        return $title;    }}
 |