mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-05-20 22:09:15 +08:00
Update extend/service/ToolsService.php
This commit is contained in:
parent
f5dffb2b79
commit
a1e6e0495e
@ -33,15 +33,12 @@ class ToolsService
|
|||||||
*/
|
*/
|
||||||
public static function corsOptionsHandler()
|
public static function corsOptionsHandler()
|
||||||
{
|
{
|
||||||
if (PHP_SESSION_ACTIVE !== session_status()) {
|
if (PHP_SESSION_ACTIVE !== session_status()) Session::init(config('session.'));
|
||||||
Session::init(config('session.'));
|
try {
|
||||||
}
|
$token = request()->header('token', input('token', ''));
|
||||||
$token = request()->header('token', '');
|
list($name, $value) = explode('=', decode($token) . '=');
|
||||||
empty($token) && $token = request()->get('token', '');
|
if (!empty($value) && session_name() === $name) session_id($value);
|
||||||
empty($token) && $token = request()->post('token', '');
|
} catch (\Exception $e) {
|
||||||
list($name, $value) = explode('=', decode($token) . '=');
|
|
||||||
if (!empty($value) && session_name() === $name) {
|
|
||||||
session_id($value);
|
|
||||||
}
|
}
|
||||||
if (request()->isOptions()) {
|
if (request()->isOptions()) {
|
||||||
header('Access-Control-Allow-Origin:*');
|
header('Access-Control-Allow-Origin:*');
|
||||||
@ -129,16 +126,10 @@ class ToolsService
|
|||||||
public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub')
|
public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub')
|
||||||
{
|
{
|
||||||
list($tree, $map) = [[], []];
|
list($tree, $map) = [[], []];
|
||||||
foreach ($list as $item) {
|
foreach ($list as $item) $map[$item[$id]] = $item;
|
||||||
$map[$item[$id]] = $item;
|
foreach ($list as $item) if (isset($item[$pid]) && isset($map[$item[$pid]])) {
|
||||||
}
|
$map[$item[$pid]][$son][] = &$map[$item[$id]];
|
||||||
foreach ($list as $item) {
|
} else $tree[] = &$map[$item[$id]];
|
||||||
if (isset($item[$pid]) && isset($map[$item[$pid]])) {
|
|
||||||
$map[$item[$pid]][$son][] = &$map[$item[$id]];
|
|
||||||
} else {
|
|
||||||
$tree[] = &$map[$item[$id]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($map);
|
unset($map);
|
||||||
return $tree;
|
return $tree;
|
||||||
}
|
}
|
||||||
@ -163,9 +154,7 @@ class ToolsService
|
|||||||
$sub = $attr['sub'];
|
$sub = $attr['sub'];
|
||||||
unset($attr['sub']);
|
unset($attr['sub']);
|
||||||
$tree[] = $attr;
|
$tree[] = $attr;
|
||||||
if (!empty($sub)) {
|
if (!empty($sub)) $tree = array_merge($tree, self::arr2table($sub, $id, $pid, $path, $attr[$path]));
|
||||||
$tree = array_merge($tree, self::arr2table($sub, $id, $pid, $path, $attr[$path]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $tree;
|
return $tree;
|
||||||
}
|
}
|
||||||
@ -181,10 +170,8 @@ class ToolsService
|
|||||||
public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid')
|
public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid')
|
||||||
{
|
{
|
||||||
$ids = [intval($id)];
|
$ids = [intval($id)];
|
||||||
foreach ($list as $vo) {
|
foreach ($list as $vo) if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) === intval($id)) {
|
||||||
if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) === intval($id)) {
|
$ids = array_merge($ids, self::getArrSubIds($list, intval($vo[$key]), $key, $pkey));
|
||||||
$ids = array_merge($ids, self::getArrSubIds($list, intval($vo[$key]), $key, $pkey));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $ids;
|
return $ids;
|
||||||
}
|
}
|
||||||
@ -228,9 +215,7 @@ class ToolsService
|
|||||||
private static function parseKeyDot(array $data, $rule)
|
private static function parseKeyDot(array $data, $rule)
|
||||||
{
|
{
|
||||||
list($temp, $attr) = [$data, explode('.', trim($rule, '.'))];
|
list($temp, $attr) = [$data, explode('.', trim($rule, '.'))];
|
||||||
while ($key = array_shift($attr)) {
|
while ($key = array_shift($attr)) $temp = isset($temp[$key]) ? $temp[$key] : $temp;
|
||||||
$temp = isset($temp[$key]) ? $temp[$key] : $temp;
|
|
||||||
}
|
|
||||||
return (is_string($temp) || is_numeric($temp)) ? str_replace('"', '""', "\t{$temp}") : '';
|
return (is_string($temp) || is_numeric($temp)) ? str_replace('"', '""', "\t{$temp}") : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user