68 lines
2.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | 作者:修缘 联系QQ278896498 QQ群1054861244
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
// | 另接php业务网站制作、代理后台、gm后台、支付对接等
// +----------------------------------------------------------------------
// | 创建时间: 2022/1/7 21:38
// +----------------------------------------------------------------------
use think\exception\HttpResponseException;
use think\Response;
use think\response\Redirect;
/** 不做任何操作 */
const URL_CURRENT = 'url://current';
/** 刷新页面 */
const URL_RELOAD = 'url://reload';
/** 返回上一个页面 */
const URL_BACK = 'url://back';
/** 关闭当前layer弹窗 */
const URL_CLOSE_LAYER = 'url://close-layer';
/** 关闭当前弹窗并刷新父级 */
const URL_CLOSE_REFRESH = 'url://close-refresh';
if (!function_exists('success')) {
function success($msg = '操作成功', $url = URL_BACK, $data = '', $wait = 0, array $header = [])
{
result(1, $msg, $data, $url, $wait, $header);
}
}
if (!function_exists('error')) {
function error($msg = '操作失败', $url = URL_CURRENT, $data = '', $wait = 0, array $header = [])
{
result(0, $msg, $data, $url, $wait, $header);
}
}
if (!function_exists('result')) {
function result($code = 0, $msg = 'unknown', $data = '', $url = null, $wait = 3, array $header = [])
{
if (request()->isPost()) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : url($url);
$result = [
'code' => $code,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
$response = Response::create($result, 'json')->header($header);
throw new HttpResponseException($response);
}
if ($url === null) {
$url = request()->server('HTTP_REFERER') ?? 'admin/index/index';
}
$response = new Redirect($url);
$response->code(302)->params($data)->with([$code ? 'success_message' : 'error_message' => $msg, 'url' => $url]);
throw new HttpResponseException($response);
}
}