101 lines
3.2 KiB
PHP
101 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
namespace Builder;
|
|
use Hyperf\HttpMessage\Stream\SwooleStream;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Builder\Entity\UISettingEntity;
|
|
use Hyperf\HttpServer\Response;
|
|
class View extends BaseResponse
|
|
{
|
|
|
|
public static $metaTitle;
|
|
public static function response($data, $message = '', $code = 200, $headers = [])
|
|
{
|
|
$re_data = [
|
|
'code' => $code,
|
|
'message' => $message,
|
|
];
|
|
if ($data) {
|
|
$re_data['data'] = $data;
|
|
}
|
|
$response = new Response();
|
|
return $response->withBody(new SwooleStream(json_encode($re_data, 256)));
|
|
}
|
|
|
|
public static function responseMessage($message = '', $code = 200)
|
|
{
|
|
return self::response([], $message, $code);
|
|
}
|
|
|
|
|
|
public static function responseError($message = '', $code = 400)
|
|
{
|
|
return self::response([], $message, $code);
|
|
}
|
|
|
|
/**
|
|
* @param $url
|
|
* @param bool $isVueRoute
|
|
* @param string $message
|
|
* @param string $type info/success/warning/error
|
|
*/
|
|
public static function responseRedirect($url, $isVueRoute = true, $message = null, $type = 'success')
|
|
{
|
|
return self::response([
|
|
'url' => $url,
|
|
'isVueRoute' => $isVueRoute,
|
|
'type' => $type,
|
|
], $message, 301);
|
|
}
|
|
|
|
/***
|
|
* 创建视图
|
|
* @param UISettingEntity $setting
|
|
* @param null $content
|
|
* @return ResponseInterface
|
|
*/
|
|
public static function make(UISettingEntity $setting, $content = null): ResponseInterface
|
|
{
|
|
$title = $setting->getTitle();
|
|
$logo = '/viewui/logo.svg';
|
|
$apiRoot = $setting->getApiRoot();
|
|
$homeUrl = $setting->getHomeUrl();
|
|
$token = $setting->getUser()->getToken();
|
|
$pageData = $setting->toArray();
|
|
$pageData = json_encode($pageData, 256);
|
|
if (!$content) {
|
|
$content =file_get_contents(BASE_PATH . '/public/viewui/index.html');
|
|
$str=[
|
|
'Tkview',
|
|
'logo.svg',
|
|
'$apiRoot',
|
|
'$homeUrl',
|
|
'$token',
|
|
'$pageData',
|
|
];
|
|
$data=[
|
|
$title,
|
|
$logo,
|
|
$apiRoot,
|
|
$homeUrl,
|
|
$token,
|
|
$pageData
|
|
];
|
|
$content=str_replace($str,$data,$content);
|
|
}
|
|
$response = new Response();
|
|
$request = $response->withHeader('content-type', 'text/html; charset=utf8')
|
|
->withBody(new SwooleStream($content));
|
|
return $request;
|
|
}
|
|
} |