Skip to content

Commit 2a14dc4

Browse files
committed
修改https情况下生成url问题
1 parent 5935744 commit 2a14dc4

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

src/Form.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ public function __construct($model = null)
9494
{
9595
$this->attrs = new FormAttrs();
9696
$this->model = $model;
97-
$this->dataUrl = request()->getUri();
98-
97+
$this->dataUrl = admin_api_url(request()->path());
9998
$this->isGetData = request('get_data') == "true";
10099
}
101100

src/Grid.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@ class Grid extends Component
8787
public function __construct(Eloquent $model = null)
8888
{
8989
$this->attributes = new Attributes();
90-
$this->dataUrl = request()->getUri();
90+
$this->dataUrl = admin_api_url(request()->path());
9191
$this->model = new Model($model, $this);
9292
if ($model) {
9393
$this->keyName = $model->getKeyName();
9494
$this->defaultSort($model->getKeyName(), "asc");
9595
}
96-
97-
9896
$this->isGetData = request('get_data') == "true";
9997
$this->toolbars = new Toolbars($this);
10098
$this->batchActions = new BatchActions();

src/helpers.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ function admin_base_path($path = '')
4343
}
4444
}
4545

46+
if (!function_exists('admin_api_base_path')) {
47+
/**
48+
* Get admin url.
49+
*
50+
* @param string $path
51+
*
52+
* @return string
53+
*/
54+
function admin_api_base_path($path = '')
55+
{
56+
$prefix = '/' . trim(config('admin.route.prefix_api'), '/');
57+
58+
$prefix = ($prefix == '/') ? '' : $prefix;
59+
60+
$path = trim($path, '/');
61+
62+
if (is_null($path) || strlen($path) == 0) {
63+
return $prefix ?: '/';
64+
}
65+
66+
return $prefix . '/' . $path;
67+
}
68+
}
69+
4670
if (!function_exists('admin_url')) {
4771
/**
4872
* Get admin url.
@@ -63,6 +87,26 @@ function admin_url($path = '', $parameters = [], $secure = null)
6387
}
6488
}
6589

90+
if (!function_exists('admin_api_url')) {
91+
/**
92+
* Get admin url.
93+
*
94+
* @param string $path
95+
* @param mixed $parameters
96+
* @param bool $secure
97+
*
98+
* @return string
99+
*/
100+
function admin_api_url($path = '', $parameters = [], $secure = null)
101+
{
102+
if (\Illuminate\Support\Facades\URL::isValidUrl($path)) {
103+
return $path;
104+
}
105+
$secure = $secure ?: (config('admin.https') || config('admin.secure'));
106+
return url(admin_api_base_path($path), $parameters, $secure);
107+
}
108+
}
109+
66110
if (!function_exists('admin_file_url')) {
67111
function admin_file_url($path)
68112
{

0 commit comments

Comments
 (0)