Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
吴磊(PHP)
/
admin-skeleton
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d9fdb78d
authored
Nov 18, 2025
by
wulei@ldy.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
1 parent
689f8ed4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
24 deletions
app/Admin/Extensions/Grid/ColumnExts.php
app/Http/Resources/Resource.php
app/Models/Model.php
app/Supports/helper.php
composer.json
app/Admin/Extensions/Grid/ColumnExts.php
View file @
d9fdb78
...
...
@@ -7,43 +7,41 @@ use Illuminate\Support\Arr;
class
ColumnExts
{
public
static
function
extend
()
{
Column
::
extend
(
'fen2yuan'
,
function
(
$value
)
{
return
fen2yuan
(
$value
);
});
static
$extends
=
[
'fen2yuan'
=>
function
(
$value
)
{
return
\bcdiv
(
$value
,
100
,
2
);
},
'unit'
=>
function
(
$value
,
$unit
,
$left
=
true
)
{
Column
::
extend
(
'unit'
,
function
(
$value
,
$unit
,
$left
=
true
)
{
if
(
\is_callable
(
$unit
))
{
$unit
=
\call_user_func
(
$unit
,
$this
);
}
return
$left
?
(
$unit
.
$value
)
:
(
$value
.
$unit
);
},
'multiline'
=>
function
(
$value
,
...
$keys
)
{
return
$value
.
'<br/>'
.
\implode
(
'<br/>'
,
\array_map
(
function
(
$key
)
{
});
Column
::
extend
(
'multiline'
,
function
(
$value
,
...
$keys
)
{
return
$value
.
'<br/>'
.
\implode
(
'<br/>'
,
\array_map
(
function
(
$key
)
{
return
Arr
::
get
(
$this
,
$key
,
''
);
},
$keys
));
},
'concat'
=>
function
(
$value
,
$keys
,
$separator
=
""
)
{
return
$value
.
$separator
.
\implode
(
$separator
,
\array_map
(
function
(
$key
)
{
});
Column
::
extend
(
'concat'
,
function
(
$value
,
$keys
,
$separator
=
""
)
{
return
$value
.
$separator
.
\implode
(
$separator
,
\array_map
(
function
(
$key
)
{
return
Arr
::
get
(
$this
,
$key
,
''
);
},
(
array
)
$keys
));
},
'ellipses'
=>
function
(
$value
,
$length
=
5
,
$symbol
=
'...'
)
{
});
Column
::
extend
(
'ellipses'
,
function
(
$value
,
$length
=
5
,
$symbol
=
'...'
)
{
$new
=
\mb_substr
(
$value
,
0
,
$length
);
if
(
\mb_strlen
(
$value
)
>
$length
)
{
$new
.=
$symbol
;
}
return
"<span title=
{
$value
}
>
{
$new
}
</span>"
;
},
'minute2hour'
=>
function
(
$value
)
{
return
\intval
(
$value
/
60
)
.
'小时'
.
(
$value
%
60
)
.
'分钟'
;
},
];
});
public
static
function
extend
()
{
foreach
(
static
::
$extends
as
$name
=>
$disaplayer
)
{
Column
::
extend
(
$name
,
$disaplayer
);
}
Column
::
extend
(
'minute2hour'
,
function
(
$value
)
{
return
\minute2hour
(
$value
);
});
}
}
\ No newline at end of file
app/Http/Resources/Resource.php
0 → 100644
View file @
d9fdb78
<?php
namespace
App\Http\Resources
;
use
Illuminate\Http\Resources\Json\JsonResource
;
use
Illuminate\Support\Arr
;
/**
* Class Resource.
*/
class
Resource
extends
JsonResource
{
protected
$only
=
[];
protected
$except
=
[];
public
function
__construct
(
$resource
,
$only
=
[],
$except
=
[])
{
parent
::
__construct
(
$resource
);
$resource
->
loadMissing
(
self
::
getRequestIncludes
());
$this
->
only
=
$only
;
$this
->
except
=
$except
;
}
public
static
function
collection
(
$resource
)
{
$resource
->
loadMissing
(
self
::
getRequestIncludes
());
$collection
=
parent
::
collection
(
$resource
);
if
(
$resource
instanceof
\Illuminate\Pagination\LengthAwarePaginator
)
{
return
new
JsonResource
([
'info'
=>
$resource
->
items
(),
'count_num'
=>
$resource
->
total
(),
'current_page'
=>
$resource
->
currentPage
(),
'total_pages'
=>
$resource
->
lastPage
(),
]);
}
return
$collection
;
}
public
static
function
getRequestIncludes
()
{
$request
=
request
();
if
(
$request
->
has
(
'include'
))
{
return
\array_map
(
'trim'
,
\explode
(
','
,
trim
(
$request
->
get
(
'include'
),
','
)));
}
return
[];
}
public
function
toArray
(
$request
)
{
if
(
$this
->
only
)
{
$data
=
$this
->
resource
->
only
(
$this
->
only
);
}
else
{
$data
=
$this
->
resource
->
toArray
();
}
return
Arr
::
except
(
$data
,
$this
->
except
);
}
}
app/Models/Model.php
View file @
d9fdb78
...
...
@@ -5,7 +5,9 @@ namespace App\Models;
use
Illuminate\Database\Eloquent\Model
as
EloquentModel
;
/**
* @method static Illuminate\Database\Eloquent\Builder|Illuminate\Database\Query\Builder where($column, $operator = null, $value = null, $boolean = 'and')
* @method static static|\Illuminate\Database\Eloquent\Builder|Illuminate\Database\Query\Builder where($column, $operator = null, $value = null, $boolean = 'and')
* @method static static|\Illuminate\Database\Eloquent\Builder|Illuminate\Database\Query\Builder whereIn($column, array $values)
* @method static static|\Illuminate\Database\Eloquent\Builder|Illuminate\Database\Query\Builder filter($data, $filterClass = null)
* @method static \Illuminate\Database\Eloquent\Collection|static[]|static|null find($id, $columns = ['*'])
* @method static \Illuminate\Database\Eloquent\Collection|static[]|static|null findOrFail($id, $columns = ['*'])
* @method static \Illuminate\Database\Eloquent\Collection|static[]|static|null findMany($ids, $columns = ['*'])
...
...
@@ -21,4 +23,8 @@ abstract class Model extends EloquentModel
parent
::
__construct
(
$attributes
);
}
protected
function
serializeDate
(
\DateTimeInterface
$date
)
{
return
$date
->
format
(
$this
->
getDateFormat
());
}
}
\ No newline at end of file
app/Supports/helper.php
0 → 100644
View file @
d9fdb78
<?php
function
fen2yuan
(
$value
)
{
return
bcdiv
(
$value
,
100
,
2
);
}
function
minute2hour
(
$value
)
{
return
intval
(
$value
/
60
)
.
'小时'
.
(
$value
%
60
)
.
'分钟'
;
}
composer.json
View file @
d9fdb78
...
...
@@ -25,6 +25,9 @@
"phpunit/phpunit"
:
"^9.5.10"
},
"autoload"
:
{
"files"
:
[
"app
\\
Supports
\\
helper.php"
],
"psr-4"
:
{
"App
\\
"
:
"app/"
,
"Database
\\
Factories
\\
"
:
"database/factories/"
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment