Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a2ee69d0f | ||
|
|
d513177c74 | ||
|
|
0705b9a38d | ||
|
|
feb26660e8 | ||
|
|
b8ccf1542b | ||
|
|
74122885f1 | ||
|
|
f5813dec99 | ||
|
|
db0ac015f0 | ||
|
|
bdabac7cff | ||
|
|
bd9cb6a3af | ||
|
|
3aaf030b89 | ||
|
|
16975c4ee8 | ||
|
|
666598cd30 | ||
|
|
b9f764e4d0 | ||
|
|
bc03616e43 | ||
|
|
8aba56c8c2 | ||
|
|
150e0ecd23 | ||
|
|
e9ed0cd8f6 | ||
|
|
187d4343b3 | ||
|
|
9bc0185b6b | ||
|
|
652b17d6a6 | ||
|
|
ed8c3d545b | ||
|
|
12b38c7bf5 | ||
|
|
fc202be987 | ||
|
|
71e069712a | ||
|
|
ca4080d5e6 | ||
|
|
4bbe287626 | ||
|
|
e316cd40e0 |
@@ -109,24 +109,21 @@ class Ajax extends AdminController
|
|||||||
*/
|
*/
|
||||||
public function getUploadFiles(Request $request): Json
|
public function getUploadFiles(Request $request): Json
|
||||||
{
|
{
|
||||||
$get = $request->get();
|
$get = $request->get();
|
||||||
$page = !empty($get['page']) ? $get['page'] : 1;
|
$page = !empty($get['page']) ? $get['page'] : 1;
|
||||||
$limit = !empty($get['limit']) ? $get['limit'] : 10;
|
$limit = !empty($get['limit']) ? $get['limit'] : 10;
|
||||||
$title = !empty($get['title']) ? $get['title'] : null;
|
$title = !empty($get['title']) ? $get['title'] : null;
|
||||||
$this->model = new SystemUploadfile();
|
$count = SystemUploadfile::where(function(Query $query) use ($title) {
|
||||||
$count = $this->model
|
!empty($title) && $query->where('original_name', 'like', "%{$title}%");
|
||||||
->where(function (Query $query) use ($title) {
|
})
|
||||||
!empty($title) && $query->where('original_name', 'like', "%{$title}%");
|
|
||||||
})
|
|
||||||
->count();
|
->count();
|
||||||
$list = $this->model
|
$list = SystemUploadfile::where(function(Query $query) use ($title) {
|
||||||
->where(function (Query $query) use ($title) {
|
!empty($title) && $query->where('original_name', 'like', "%{$title}%");
|
||||||
!empty($title) && $query->where('original_name', 'like', "%{$title}%");
|
})
|
||||||
})
|
|
||||||
->page($page, $limit)
|
->page($page, $limit)
|
||||||
->order($this->sort)
|
->order($this->sort)
|
||||||
->select()->toArray();
|
->select()->toArray();
|
||||||
$data = [
|
$data = [
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '',
|
'msg' => '',
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
@@ -149,7 +146,7 @@ class Ajax extends AdminController
|
|||||||
$upload_allow_size = $uploadConfig['upload_allow_size'];
|
$upload_allow_size = $uploadConfig['upload_allow_size'];
|
||||||
$_upload_allow_ext = explode(',', $uploadConfig['upload_allow_ext']);
|
$_upload_allow_ext = explode(',', $uploadConfig['upload_allow_ext']);
|
||||||
$upload_allow_ext = [];
|
$upload_allow_ext = [];
|
||||||
array_map(function ($value) use (&$upload_allow_ext) {
|
array_map(function($value) use (&$upload_allow_ext) {
|
||||||
$upload_allow_ext[] = '.' . $value;
|
$upload_allow_ext[] = '.' . $value;
|
||||||
}, $_upload_allow_ext);
|
}, $_upload_allow_ext);
|
||||||
$config = [
|
$config = [
|
||||||
@@ -213,4 +210,23 @@ class Ajax extends AdminController
|
|||||||
return json($config);
|
return json($config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function composerInfo(): Json
|
||||||
|
{
|
||||||
|
$lockFilePath = root_path() . '/composer.lock';
|
||||||
|
$list = [];
|
||||||
|
if (file_exists($lockFilePath)) {
|
||||||
|
$lockFileContent = file_get_contents($lockFilePath);
|
||||||
|
if ($lockFileContent !== false) {
|
||||||
|
$lockData = json_decode($lockFileContent, true);
|
||||||
|
if (!empty($lockData['packages'])) {
|
||||||
|
foreach ($lockData['packages'] as $package) {
|
||||||
|
$list[] = ['name' => $package['name'], 'version' => $package['version']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->success('success', $list);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ class Cate extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new MallCate();
|
self::$model = MallCate::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,8 +24,8 @@ class Goods extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new MallGoods();
|
self::$model = MallGoods::class;
|
||||||
$this->assign('cate', (new MallCate())->column('title', 'id'));
|
$this->assign('cate', MallCate::column('title', 'id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NodeAnnotation(title: '列表', auth: true)]
|
#[NodeAnnotation(title: '列表', auth: true)]
|
||||||
@@ -34,8 +34,8 @@ class Goods extends AdminController
|
|||||||
if ($request->isAjax()) {
|
if ($request->isAjax()) {
|
||||||
if (input('selectFields')) return $this->selectList();
|
if (input('selectFields')) return $this->selectList();
|
||||||
list($page, $limit, $where) = $this->buildTableParams();
|
list($page, $limit, $where) = $this->buildTableParams();
|
||||||
$count = $this->model->where($where)->count();
|
$count = self::$model::where($where)->count();
|
||||||
$list = $this->model->with(['cate'])->where($where)->page($page, $limit)->order($this->sort)->select()->toArray();
|
$list = self::$model::with(['cate'])->where($where)->page($page, $limit)->order($this->sort)->select()->toArray();
|
||||||
$data = [
|
$data = [
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '',
|
'msg' => '',
|
||||||
@@ -50,7 +50,7 @@ class Goods extends AdminController
|
|||||||
#[NodeAnnotation(title: '入库', auth: true)]
|
#[NodeAnnotation(title: '入库', auth: true)]
|
||||||
public function stock(Request $request, $id): string
|
public function stock(Request $request, $id): string
|
||||||
{
|
{
|
||||||
$row = $this->model->find($id);
|
$row = self::$model::find($id);
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
if ($request->isPost()) {
|
if ($request->isPost()) {
|
||||||
$post = $request->post();
|
$post = $request->post();
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ class Admin extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new SystemAdmin();
|
self::$model = SystemAdmin::class;
|
||||||
$this->assign('auth_list', $this->model->getAuthList());
|
$this->assign('auth_list', self::$model::getAuthList());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NodeAnnotation(title: '列表', auth: true)]
|
#[NodeAnnotation(title: '列表', auth: true)]
|
||||||
@@ -36,11 +36,8 @@ class Admin extends AdminController
|
|||||||
return $this->selectList();
|
return $this->selectList();
|
||||||
}
|
}
|
||||||
list($page, $limit, $where) = $this->buildTableParams();
|
list($page, $limit, $where) = $this->buildTableParams();
|
||||||
$count = $this->model
|
$count = self::$model::where($where)->count();
|
||||||
->where($where)
|
$list = self::$model::withoutField('password')
|
||||||
->count();
|
|
||||||
$list = $this->model
|
|
||||||
->withoutField('password')
|
|
||||||
->where($where)
|
->where($where)
|
||||||
->page($page, $limit)
|
->page($page, $limit)
|
||||||
->order($this->sort)
|
->order($this->sort)
|
||||||
@@ -68,9 +65,9 @@ class Admin extends AdminController
|
|||||||
if (empty($post['password'])) $post['password'] = '123456';
|
if (empty($post['password'])) $post['password'] = '123456';
|
||||||
$post['password'] = password($post['password']);
|
$post['password'] = password($post['password']);
|
||||||
try {
|
try {
|
||||||
$save = $this->model->save($post);
|
$save = self::$model::create($post);
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
$this->error('保存失败');
|
$this->error('保存失败' . $e->getMessage());
|
||||||
}
|
}
|
||||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||||
}
|
}
|
||||||
@@ -80,7 +77,7 @@ class Admin extends AdminController
|
|||||||
#[NodeAnnotation(title: '编辑', auth: true)]
|
#[NodeAnnotation(title: '编辑', auth: true)]
|
||||||
public function edit(Request $request, $id = 0): string
|
public function edit(Request $request, $id = 0): string
|
||||||
{
|
{
|
||||||
$row = $this->model->find($id);
|
$row = self::$model::find($id);
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
if ($request->isPost()) {
|
if ($request->isPost()) {
|
||||||
$post = $request->post();
|
$post = $request->post();
|
||||||
@@ -88,18 +85,14 @@ class Admin extends AdminController
|
|||||||
$post['auth_ids'] = implode(',', array_keys($authIds));
|
$post['auth_ids'] = implode(',', array_keys($authIds));
|
||||||
$rule = [];
|
$rule = [];
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
if (isset($row['password'])) {
|
|
||||||
unset($row['password']);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
$save = $row->save($post);
|
$save = $row->save($post);
|
||||||
TriggerService::updateMenu($id);
|
TriggerService::updateMenu($id);
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
$this->error('保存失败');
|
$this->error('保存失败' . $e->getMessage());
|
||||||
}
|
}
|
||||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||||
}
|
}
|
||||||
$row->auth_ids = explode(',', $row->auth_ids ?: '');
|
|
||||||
$this->assign('row', $row);
|
$this->assign('row', $row);
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
@@ -107,7 +100,7 @@ class Admin extends AdminController
|
|||||||
#[NodeAnnotation(title: '设置密码', auth: true)]
|
#[NodeAnnotation(title: '设置密码', auth: true)]
|
||||||
public function password(Request $request, $id): string
|
public function password(Request $request, $id): string
|
||||||
{
|
{
|
||||||
$row = $this->model->find($id);
|
$row = self::$model::find($id);
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
if ($request->isAjax()) {
|
if ($request->isAjax()) {
|
||||||
$post = $request->post();
|
$post = $request->post();
|
||||||
@@ -128,7 +121,6 @@ class Admin extends AdminController
|
|||||||
}
|
}
|
||||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||||
}
|
}
|
||||||
$row->auth_ids = explode(',', $row->auth_ids ?: '');
|
|
||||||
$this->assign('row', $row);
|
$this->assign('row', $row);
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
@@ -138,7 +130,7 @@ class Admin extends AdminController
|
|||||||
{
|
{
|
||||||
$this->checkPostRequest();
|
$this->checkPostRequest();
|
||||||
$id = $request->param('id');
|
$id = $request->param('id');
|
||||||
$row = $this->model->whereIn('id', $id)->select();
|
$row = self::$model::whereIn('id', $id)->select();
|
||||||
$row->isEmpty() && $this->error('数据不存在');
|
$row->isEmpty() && $this->error('数据不存在');
|
||||||
$id == AdminConstant::SUPER_ADMIN_ID && $this->error('超级管理员不允许修改');
|
$id == AdminConstant::SUPER_ADMIN_ID && $this->error('超级管理员不允许修改');
|
||||||
if (is_array($id)) {
|
if (is_array($id)) {
|
||||||
@@ -171,7 +163,7 @@ class Admin extends AdminController
|
|||||||
if ($post['id'] == AdminConstant::SUPER_ADMIN_ID && $post['field'] == 'status') {
|
if ($post['id'] == AdminConstant::SUPER_ADMIN_ID && $post['field'] == 'status') {
|
||||||
$this->error('超级管理员状态不允许修改');
|
$this->error('超级管理员状态不允许修改');
|
||||||
}
|
}
|
||||||
$row = $this->model->find($post['id']);
|
$row = self::$model::find($post['id']);
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
try {
|
try {
|
||||||
$row->save([
|
$row->save([
|
||||||
|
|||||||
@@ -23,16 +23,16 @@ class Auth extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new SystemAuth();
|
self::$model = SystemAuth::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NodeAnnotation(title: '授权', auth: true)]
|
#[NodeAnnotation(title: '授权', auth: true)]
|
||||||
public function authorize(Request $request, $id): string
|
public function authorize(Request $request, $id): string
|
||||||
{
|
{
|
||||||
$row = $this->model->find($id);
|
$row = self::$model::find($id);
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
if ($request->isAjax()) {
|
if ($request->isAjax()) {
|
||||||
$list = $this->model->getAuthorizeNodeListByAdminId($id);
|
$list = self::$model::getAuthorizeNodeListByAdminId($id);
|
||||||
$this->success('获取成功', $list);
|
$this->success('获取成功', $list);
|
||||||
}
|
}
|
||||||
$this->assign('row', $row);
|
$this->assign('row', $row);
|
||||||
@@ -46,7 +46,7 @@ class Auth extends AdminController
|
|||||||
$id = $request->post('id');
|
$id = $request->post('id');
|
||||||
$node = $request->post('node', "[]");
|
$node = $request->post('node', "[]");
|
||||||
$node = json_decode($node, true);
|
$node = json_decode($node, true);
|
||||||
$row = $this->model->find($id);
|
$row = self::$model::find($id);
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
try {
|
try {
|
||||||
$authNode = new SystemAuthNode();
|
$authNode = new SystemAuthNode();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use app\admin\service\annotation\ControllerAnnotation;
|
|||||||
use app\admin\service\annotation\NodeAnnotation;
|
use app\admin\service\annotation\NodeAnnotation;
|
||||||
use app\Request;
|
use app\Request;
|
||||||
use think\App;
|
use think\App;
|
||||||
|
use think\facade\Cache;
|
||||||
use think\response\Json;
|
use think\response\Json;
|
||||||
|
|
||||||
#[ControllerAnnotation(title: '系统配置管理')]
|
#[ControllerAnnotation(title: '系统配置管理')]
|
||||||
@@ -18,7 +19,7 @@ class Config extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new SystemConfig();
|
self::$model = SystemConfig::class;
|
||||||
$this->assign('upload_types', config('admin.upload_types'));
|
$this->assign('upload_types', config('admin.upload_types'));
|
||||||
$this->assign('editor_types', config('admin.editor_types'));
|
$this->assign('editor_types', config('admin.editor_types'));
|
||||||
}
|
}
|
||||||
@@ -41,25 +42,26 @@ class Config extends AdminController
|
|||||||
if ($group == 'upload') {
|
if ($group == 'upload') {
|
||||||
$upload_types = config('admin.upload_types');
|
$upload_types = config('admin.upload_types');
|
||||||
// 兼容旧版本
|
// 兼容旧版本
|
||||||
$this->model->where('name', 'upload_allow_type')->update(['value' => implode(',', array_keys($upload_types))]);
|
self::$model::where('name', 'upload_allow_type')->update(['value' => implode(',', array_keys($upload_types))]);
|
||||||
}
|
}
|
||||||
foreach ($post as $key => $val) {
|
foreach ($post as $key => $val) {
|
||||||
if (in_array($key, $notAddFields)) continue;
|
if (in_array($key, $notAddFields)) continue;
|
||||||
if ($this->model->where('name', $key)->count()) {
|
if (self::$model::where('name', $key)->count()) {
|
||||||
$this->model->where('name', $key)->update(['value' => $val,]);
|
self::$model::where('name', $key)->update(['value' => $val,]);
|
||||||
}else {
|
}else {
|
||||||
$this->model->create(
|
self::$model::create(
|
||||||
[
|
[
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'value' => $val,
|
'value' => $val,
|
||||||
'group' => $group,
|
'group' => $group,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
if (Cache::has($key)) Cache::set($key, $val);
|
||||||
}
|
}
|
||||||
TriggerService::updateMenu();
|
TriggerService::updateMenu();
|
||||||
TriggerService::updateSysConfig();
|
TriggerService::updateSysConfig();
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
$this->error('保存失败');
|
$this->error('保存失败' . $e->getMessage());
|
||||||
}
|
}
|
||||||
$this->success('保存成功');
|
$this->success('保存成功');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class Log extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new SystemLog();
|
self::$model = SystemLog::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NodeAnnotation(title: '列表', auth: true)]
|
#[NodeAnnotation(title: '列表', auth: true)]
|
||||||
@@ -34,7 +34,7 @@ class Log extends AdminController
|
|||||||
}
|
}
|
||||||
[$page, $limit, $where, $excludeFields] = $this->buildTableParams(['month']);
|
[$page, $limit, $where, $excludeFields] = $this->buildTableParams(['month']);
|
||||||
$month = !empty($excludeFields['month']) ? date('Ym', strtotime($excludeFields['month'])) : date('Ym');
|
$month = !empty($excludeFields['month']) ? date('Ym', strtotime($excludeFields['month'])) : date('Ym');
|
||||||
$model = $this->model->setMonth($month)->with('admin')->where($where);
|
$model = (new self::$model)->setSuffix("_$month")->with('admin')->where($where);
|
||||||
try {
|
try {
|
||||||
$count = $model->count();
|
$count = $model->count();
|
||||||
$list = $model->page($page, $limit)->order($this->sort)->select();
|
$list = $model->page($page, $limit)->order($this->sort)->select();
|
||||||
@@ -54,13 +54,14 @@ class Log extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[NodeAnnotation(title: '导出', auth: true)]
|
#[NodeAnnotation(title: '导出', auth: true)]
|
||||||
public function export(): bool
|
public function export()
|
||||||
{
|
{
|
||||||
if (env('EASYADMIN.IS_DEMO', false)) {
|
if (env('EASYADMIN.IS_DEMO', false)) {
|
||||||
$this->error('演示环境下不允许操作');
|
$this->error('演示环境下不允许操作');
|
||||||
}
|
}
|
||||||
[$page, $limit, $where, $excludeFields] = $this->buildTableParams(['month']);
|
[$page, $limit, $where, $excludeFields] = $this->buildTableParams(['month']);
|
||||||
$tableName = $this->model->getName();
|
$month = !empty($excludeFields['month']) ? date('Ym', strtotime($excludeFields['month'])) : date('Ym');
|
||||||
|
$tableName = (new self::$model)->setSuffix("_$month")->getName();
|
||||||
$tableName = CommonTool::humpToLine(lcfirst($tableName));
|
$tableName = CommonTool::humpToLine(lcfirst($tableName));
|
||||||
$prefix = config('database.connections.mysql.prefix');
|
$prefix = config('database.connections.mysql.prefix');
|
||||||
$dbList = Db::query("show full columns from {$prefix}{$tableName}");
|
$dbList = Db::query("show full columns from {$prefix}{$tableName}");
|
||||||
@@ -71,20 +72,21 @@ class Log extends AdminController
|
|||||||
$header[] = [$comment, $vo['Field']];
|
$header[] = [$comment, $vo['Field']];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$month = !empty($excludeFields['month']) ? date('Ym', strtotime($excludeFields['month'])) : date('Ym');
|
$model = (new self::$model)->setSuffix("_$month")->with('admin')->where($where);
|
||||||
$model = $this->model->setMonth($month)->with('admin')->where($where);
|
|
||||||
try {
|
try {
|
||||||
$list = $model
|
$list = $model
|
||||||
->where($where)
|
->limit(10000)
|
||||||
->limit(100000)
|
|
||||||
->order('id', 'desc')
|
->order('id', 'desc')
|
||||||
->select()
|
->select()
|
||||||
->toArray();
|
->toArray();
|
||||||
}catch (PDOException|DbException $exception) {
|
foreach ($list as &$vo) {
|
||||||
|
$vo['content'] = json_encode($vo['content'], JSON_UNESCAPED_UNICODE);
|
||||||
|
$vo['response'] = json_encode($vo['response'], JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
exportExcel($header, $list, '操作日志');
|
||||||
|
}catch (\Throwable $exception) {
|
||||||
$this->error($exception->getMessage());
|
$this->error($exception->getMessage());
|
||||||
}
|
}
|
||||||
$fileName = time();
|
|
||||||
return Excel::exportData($list, $header, $fileName, 'xlsx');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class Menu extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new SystemMenu();
|
self::$model = SystemMenu::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NodeAnnotation(title: '列表', auth: true)]
|
#[NodeAnnotation(title: '列表', auth: true)]
|
||||||
@@ -35,8 +35,8 @@ class Menu extends AdminController
|
|||||||
if (input('selectFields')) {
|
if (input('selectFields')) {
|
||||||
return $this->selectList();
|
return $this->selectList();
|
||||||
}
|
}
|
||||||
$count = $this->model->count();
|
$count = self::$model::count();
|
||||||
$list = $this->model->order($this->sort)->select()->toArray();
|
$list = self::$model::order($this->sort)->select()->toArray();
|
||||||
$data = [
|
$data = [
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '',
|
'msg' => '',
|
||||||
@@ -52,7 +52,7 @@ class Menu extends AdminController
|
|||||||
public function add(Request $request): string
|
public function add(Request $request): string
|
||||||
{
|
{
|
||||||
$id = $request->param('id');
|
$id = $request->param('id');
|
||||||
$homeId = $this->model->where(['pid' => MenuConstant::HOME_PID,])->value('id');
|
$homeId = self::$model::where(['pid' => MenuConstant::HOME_PID,])->value('id');
|
||||||
if ($id == $homeId) {
|
if ($id == $homeId) {
|
||||||
$this->error('首页不能添加子菜单');
|
$this->error('首页不能添加子菜单');
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ class Menu extends AdminController
|
|||||||
];
|
];
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
try {
|
try {
|
||||||
$save = $this->model->save($post);
|
$save = self::$model::create($post);
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
$this->error('保存失败');
|
$this->error('保存失败');
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ class Menu extends AdminController
|
|||||||
$this->error('保存失败');
|
$this->error('保存失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$pidMenuList = $this->model->getPidMenuList();
|
$pidMenuList = self::$model::getPidMenuList();
|
||||||
$this->assign('id', $id);
|
$this->assign('id', $id);
|
||||||
$this->assign('pidMenuList', $pidMenuList);
|
$this->assign('pidMenuList', $pidMenuList);
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
@@ -85,7 +85,7 @@ class Menu extends AdminController
|
|||||||
#[NodeAnnotation(title: '编辑', auth: true)]
|
#[NodeAnnotation(title: '编辑', auth: true)]
|
||||||
public function edit(Request $request, $id = 0): string
|
public function edit(Request $request, $id = 0): string
|
||||||
{
|
{
|
||||||
$row = $this->model->find($id);
|
$row = self::$model::find($id);
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
if ($request->isPost()) {
|
if ($request->isPost()) {
|
||||||
$post = $request->post();
|
$post = $request->post();
|
||||||
@@ -108,7 +108,7 @@ class Menu extends AdminController
|
|||||||
$this->error('保存失败');
|
$this->error('保存失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$pidMenuList = $this->model->getPidMenuList();
|
$pidMenuList = self::$model::getPidMenuList();
|
||||||
$this->assign([
|
$this->assign([
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'pidMenuList' => $pidMenuList,
|
'pidMenuList' => $pidMenuList,
|
||||||
@@ -122,7 +122,7 @@ class Menu extends AdminController
|
|||||||
{
|
{
|
||||||
$this->checkPostRequest();
|
$this->checkPostRequest();
|
||||||
$id = $request->param('id');
|
$id = $request->param('id');
|
||||||
$row = $this->model->whereIn('id', $id)->select();
|
$row = self::$model::whereIn('id', $id)->select();
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
try {
|
try {
|
||||||
$save = $row->delete();
|
$save = $row->delete();
|
||||||
@@ -148,17 +148,16 @@ class Menu extends AdminController
|
|||||||
'value|值' => 'require',
|
'value|值' => 'require',
|
||||||
];
|
];
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
$row = $this->model->find($post['id']);
|
$row = self::$model::find($post['id']);
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
$this->error('数据不存在');
|
$this->error('数据不存在');
|
||||||
}
|
}
|
||||||
if (!in_array($post['field'], $this->allowModifyFields)) {
|
if (!in_array($post['field'], $this->allowModifyFields)) {
|
||||||
$this->error('该字段不允许修改:' . $post['field']);
|
$this->error('该字段不允许修改:' . $post['field']);
|
||||||
}
|
}
|
||||||
$homeId = $this->model
|
$homeId = self::$model::where([
|
||||||
->where([
|
'pid' => MenuConstant::HOME_PID,
|
||||||
'pid' => MenuConstant::HOME_PID,
|
])
|
||||||
])
|
|
||||||
->value('id');
|
->value('id');
|
||||||
if ($post['id'] == $homeId && $post['field'] == 'status') {
|
if ($post['id'] == $homeId && $post['field'] == 'status') {
|
||||||
$this->error('首页状态不允许关闭');
|
$this->error('首页状态不允许关闭');
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ use app\admin\service\annotation\NodeAnnotation;
|
|||||||
use app\admin\service\NodeService;
|
use app\admin\service\NodeService;
|
||||||
use app\Request;
|
use app\Request;
|
||||||
use think\App;
|
use think\App;
|
||||||
|
use think\db\exception\DataNotFoundException;
|
||||||
|
use think\db\exception\DbException;
|
||||||
|
use think\db\exception\ModelNotFoundException;
|
||||||
use think\response\Json;
|
use think\response\Json;
|
||||||
|
|
||||||
#[ControllerAnnotation(title: '系统节点管理')]
|
#[ControllerAnnotation(title: '系统节点管理')]
|
||||||
@@ -19,7 +22,7 @@ class Node extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new SystemNode();
|
self::$model = SystemNode::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NodeAnnotation(title: '列表', auth: true)]
|
#[NodeAnnotation(title: '列表', auth: true)]
|
||||||
@@ -29,10 +32,8 @@ class Node extends AdminController
|
|||||||
if (input('selectFields')) {
|
if (input('selectFields')) {
|
||||||
return $this->selectList();
|
return $this->selectList();
|
||||||
}
|
}
|
||||||
$count = $this->model
|
$count = self::$model::count();
|
||||||
->count();
|
$list = self::$model::getNodeTreeList();
|
||||||
$list = $this->model
|
|
||||||
->getNodeTreeList();
|
|
||||||
$data = [
|
$data = [
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '',
|
'msg' => '',
|
||||||
@@ -51,15 +52,14 @@ class Node extends AdminController
|
|||||||
$this->checkPostRequest();
|
$this->checkPostRequest();
|
||||||
$nodeList = (new NodeService())->getNodeList();
|
$nodeList = (new NodeService())->getNodeList();
|
||||||
empty($nodeList) && $this->error('暂无需要更新的系统节点');
|
empty($nodeList) && $this->error('暂无需要更新的系统节点');
|
||||||
$model = new SystemNode();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($force == 1) {
|
if ($force == 1) {
|
||||||
$updateNodeList = $model->whereIn('node', array_column($nodeList, 'node'))->select();
|
$updateNodeList = self::$model::whereIn('node', array_column($nodeList, 'node'))->select();
|
||||||
$formatNodeList = array_format_key($nodeList, 'node');
|
$formatNodeList = array_format_key($nodeList, 'node');
|
||||||
foreach ($updateNodeList as $vo) {
|
foreach ($updateNodeList as $vo) {
|
||||||
isset($formatNodeList[$vo['node']])
|
isset($formatNodeList[$vo['node']])
|
||||||
&& $model->where('id', $vo['id'])->update(
|
&& self::$model::where('id', $vo['id'])->update(
|
||||||
[
|
[
|
||||||
'title' => $formatNodeList[$vo['node']]['title'],
|
'title' => $formatNodeList[$vo['node']]['title'],
|
||||||
'is_auth' => $formatNodeList[$vo['node']]['is_auth'],
|
'is_auth' => $formatNodeList[$vo['node']]['is_auth'],
|
||||||
@@ -67,7 +67,7 @@ class Node extends AdminController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$existNodeList = $model->field('node,title,type,is_auth')->select();
|
$existNodeList = self::$model::field('node,title,type,is_auth')->select();
|
||||||
foreach ($nodeList as $key => $vo) {
|
foreach ($nodeList as $key => $vo) {
|
||||||
foreach ($existNodeList as $v) {
|
foreach ($existNodeList as $v) {
|
||||||
if ($vo['node'] == $v->node) {
|
if ($vo['node'] == $v->node) {
|
||||||
@@ -76,8 +76,10 @@ class Node extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$model->saveAll($nodeList);
|
if (!empty($nodeList)) {
|
||||||
TriggerService::updateNode();
|
(new self::$model)->saveAll($nodeList);
|
||||||
|
TriggerService::updateNode();
|
||||||
|
}
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
$this->error('节点更新失败');
|
$this->error('节点更新失败');
|
||||||
}
|
}
|
||||||
@@ -89,12 +91,11 @@ class Node extends AdminController
|
|||||||
{
|
{
|
||||||
$this->checkPostRequest();
|
$this->checkPostRequest();
|
||||||
$nodeList = (new NodeService())->getNodeList();
|
$nodeList = (new NodeService())->getNodeList();
|
||||||
$model = new SystemNode();
|
|
||||||
try {
|
try {
|
||||||
$existNodeList = $model->field('id,node,title,type,is_auth')->select()->toArray();
|
$existNodeList = self::$model::field('id,node,title,type,is_auth')->select()->toArray();
|
||||||
$formatNodeList = array_format_key($nodeList, 'node');
|
$formatNodeList = array_format_key($nodeList, 'node');
|
||||||
foreach ($existNodeList as $vo) {
|
foreach ($existNodeList as $vo) {
|
||||||
!isset($formatNodeList[$vo['node']]) && $model->where('id', $vo['id'])->delete();
|
!isset($formatNodeList[$vo['node']]) && self::$model::where('id', $vo['id'])->delete();
|
||||||
}
|
}
|
||||||
TriggerService::updateNode();
|
TriggerService::updateNode();
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Quick extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new SystemQuick();
|
self::$model = SystemQuick::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ class Uploadfile extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new SystemUploadfile();
|
self::$model = SystemUploadfile::class;
|
||||||
$this->assign('upload_types', config('admin.upload_types'));
|
$this->assign('upload_types', config('admin.upload_types'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ use app\common\model\TimeModel;
|
|||||||
class MallCate extends TimeModel
|
class MallCate extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'deleteTime' => 'delete_time',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,10 +8,12 @@ use think\model\relation\HasOne;
|
|||||||
|
|
||||||
class MallGoods extends TimeModel
|
class MallGoods extends TimeModel
|
||||||
{
|
{
|
||||||
|
protected function getOptions(): array
|
||||||
protected $table = "";
|
{
|
||||||
|
return [
|
||||||
protected $deleteTime = 'delete_time';
|
'deleteTime' => 'delete_time',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
// * +++++++++++++++++++++++++++
|
// * +++++++++++++++++++++++++++
|
||||||
// | 以下两种写法适用于 with 关联
|
// | 以下两种写法适用于 with 关联
|
||||||
|
|||||||
@@ -8,7 +8,12 @@ use app\common\model\TimeModel;
|
|||||||
class SystemAdmin extends TimeModel
|
class SystemAdmin extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'deleteTime' => 'delete_time',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public array $notes = [
|
public array $notes = [
|
||||||
'login_type' => [
|
'login_type' => [
|
||||||
@@ -17,12 +22,15 @@ class SystemAdmin extends TimeModel
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getAuthList()
|
public static function getAuthIdsAttr($value): array
|
||||||
{
|
{
|
||||||
$list = (new SystemAuth())
|
if (!$value) return [];
|
||||||
->where('status', 1)
|
return explode(',', $value);
|
||||||
->column('title', 'id');
|
}
|
||||||
return $list;
|
|
||||||
|
public static function getAuthList(): array
|
||||||
|
{
|
||||||
|
return SystemAuth::where('status', 1)->column('title', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,44 +3,52 @@
|
|||||||
namespace app\admin\model;
|
namespace app\admin\model;
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
use app\common\model\TimeModel;
|
||||||
|
use think\db\exception\DataNotFoundException;
|
||||||
|
use think\db\exception\DbException;
|
||||||
|
use think\db\exception\ModelNotFoundException;
|
||||||
|
|
||||||
class SystemAuth extends TimeModel
|
class SystemAuth extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'deleteTime' => 'delete_time',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID获取授权节点
|
* 根据角色ID获取授权节点
|
||||||
* @param $authId
|
* @param $authId
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws DataNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getAuthorizeNodeListByAdminId($authId)
|
public static function getAuthorizeNodeListByAdminId($authId): array
|
||||||
{
|
{
|
||||||
$checkNodeList = (new SystemAuthNode())
|
$checkNodeList = (new SystemAuthNode())
|
||||||
->where('auth_id', $authId)
|
->where('auth_id', $authId)
|
||||||
->column('node_id');
|
->column('node_id');
|
||||||
$systemNode = new SystemNode();
|
$systemNode = new SystemNode();
|
||||||
$nodelList = $systemNode
|
$nodeList = $systemNode
|
||||||
->where('is_auth', 1)
|
->where('is_auth', 1)
|
||||||
->field('id,node,title,type,is_auth')
|
->field('id,node,title,type,is_auth')
|
||||||
->select()
|
->select()
|
||||||
->toArray();
|
->toArray();
|
||||||
$newNodeList = [];
|
$newNodeList = [];
|
||||||
foreach ($nodelList as $vo) {
|
foreach ($nodeList as $vo) {
|
||||||
if ($vo['type'] == 1) {
|
if ($vo['type'] == 1) {
|
||||||
$vo = array_merge($vo, ['field' => 'node', 'spread' => true]);
|
$vo = array_merge($vo, ['field' => 'node', 'spread' => true]);
|
||||||
$vo['checked'] = false;
|
$vo['checked'] = false;
|
||||||
$vo['title'] = "{$vo['title']}【{$vo['node']}】";
|
$vo['title'] = "{$vo['title']}【{$vo['node']}】";
|
||||||
$children = [];
|
$children = [];
|
||||||
foreach ($nodelList as $v) {
|
foreach ($nodeList as $v) {
|
||||||
if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
|
if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
|
||||||
$v = array_merge($v, ['field' => 'node', 'spread' => true]);
|
$v = array_merge($v, ['field' => 'node', 'spread' => true]);
|
||||||
$v['checked'] = in_array($v['id'], $checkNodeList) ? true : false;
|
$v['checked'] = in_array($v['id'], $checkNodeList) ? true : false;
|
||||||
$v['title'] = "{$v['title']}【{$v['node']}】";
|
$v['title'] = "{$v['title']}【{$v['node']}】";
|
||||||
$children[] = $v;
|
$children[] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
!empty($children) && $vo['children'] = $children;
|
!empty($children) && $vo['children'] = $children;
|
||||||
|
|||||||
@@ -4,24 +4,23 @@ namespace app\admin\model;
|
|||||||
|
|
||||||
use app\admin\service\SystemLogService;
|
use app\admin\service\SystemLogService;
|
||||||
use app\common\model\TimeModel;
|
use app\common\model\TimeModel;
|
||||||
|
use think\model\relation\BelongsTo;
|
||||||
|
|
||||||
class SystemLog extends TimeModel
|
class SystemLog extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct(array $data = [])
|
protected array $type = [
|
||||||
{
|
'content' => 'json',
|
||||||
parent::__construct($data);
|
'response' => 'json',
|
||||||
$this->name = 'system_log_' . date('Ym');
|
];
|
||||||
}
|
|
||||||
|
|
||||||
public function setMonth($month)
|
protected function init(): void
|
||||||
{
|
{
|
||||||
SystemLogService::instance()->detectTable();
|
SystemLogService::instance()->detectTable();
|
||||||
$this->name = 'system_log_' . $month;
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function admin()
|
|
||||||
|
public function admin(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo('app\admin\model\SystemAdmin', 'admin_id', 'id');
|
return $this->belongsTo('app\admin\model\SystemAdmin', 'admin_id', 'id');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,31 +4,41 @@ namespace app\admin\model;
|
|||||||
|
|
||||||
use app\common\constants\MenuConstant;
|
use app\common\constants\MenuConstant;
|
||||||
use app\common\model\TimeModel;
|
use app\common\model\TimeModel;
|
||||||
|
use think\db\exception\DataNotFoundException;
|
||||||
|
use think\db\exception\DbException;
|
||||||
|
use think\db\exception\ModelNotFoundException;
|
||||||
|
|
||||||
class SystemMenu extends TimeModel
|
class SystemMenu extends TimeModel
|
||||||
{
|
{
|
||||||
|
protected function getOptions(): array
|
||||||
protected $deleteTime = 'delete_time';
|
|
||||||
|
|
||||||
public function getPidMenuList()
|
|
||||||
{
|
{
|
||||||
$list = $this->field('id,pid,title')
|
return [
|
||||||
->where([
|
'deleteTime' => 'delete_time',
|
||||||
['pid', '<>', MenuConstant::HOME_PID],
|
];
|
||||||
['status', '=', 1],
|
}
|
||||||
])
|
|
||||||
->select()
|
|
||||||
->toArray();
|
/**
|
||||||
$pidMenuList = $this->buildPidMenu(0, $list);
|
* @throws ModelNotFoundException
|
||||||
$pidMenuList = array_merge([[
|
* @throws DbException
|
||||||
|
* @throws DataNotFoundException
|
||||||
|
*/
|
||||||
|
public static function getPidMenuList(): array
|
||||||
|
{
|
||||||
|
$list = self::field('id,pid,title')->where([
|
||||||
|
['pid', '<>', MenuConstant::HOME_PID],
|
||||||
|
['status', '=', 1],
|
||||||
|
])->select()->toArray();
|
||||||
|
|
||||||
|
$pidMenuList = self::buildPidMenu(0, $list);
|
||||||
|
return array_merge([[
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
'pid' => 0,
|
'pid' => 0,
|
||||||
'title' => '顶级菜单',
|
'title' => '顶级菜单',
|
||||||
]], $pidMenuList);
|
]], $pidMenuList);
|
||||||
return $pidMenuList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildPidMenu($pid, $list, $level = 0)
|
protected static function buildPidMenu($pid, $list, $level = 0): array
|
||||||
{
|
{
|
||||||
$newList = [];
|
$newList = [];
|
||||||
foreach ($list as $vo) {
|
foreach ($list as $vo) {
|
||||||
@@ -47,7 +57,7 @@ class SystemMenu extends TimeModel
|
|||||||
$vo['title'] = $markString . $vo['title'];
|
$vo['title'] = $markString . $vo['title'];
|
||||||
}
|
}
|
||||||
$newList[] = $vo;
|
$newList[] = $vo;
|
||||||
$childList = $this->buildPidMenu($vo['id'], $list, $level);
|
$childList = self::buildPidMenu($vo['id'], $list, $level);
|
||||||
!empty($childList) && $newList = array_merge($newList, $childList);
|
!empty($childList) && $newList = array_merge($newList, $childList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,22 +7,21 @@ use app\common\model\TimeModel;
|
|||||||
class SystemNode extends TimeModel
|
class SystemNode extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getNodeTreeList()
|
public static function getNodeTreeList(): array
|
||||||
{
|
{
|
||||||
$list = $this->select()->toArray();
|
$list = self::select()->toArray();
|
||||||
$list = $this->buildNodeTree($list);
|
return self::buildNodeTree($list);
|
||||||
return $list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildNodeTree($list)
|
protected static function buildNodeTree($list): array
|
||||||
{
|
{
|
||||||
$newList = [];
|
$newList = [];
|
||||||
$repeatString = " ";
|
$repeatString = " ";
|
||||||
foreach ($list as $vo) {
|
foreach ($list as $vo) {
|
||||||
if ($vo['type'] == 1) {
|
if ($vo['type'] == 1) {
|
||||||
$newList[] = $vo;
|
$newList[] = $vo;
|
||||||
foreach ($list as $v) {
|
foreach ($list as $v) {
|
||||||
if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
|
if ($v['type'] == 2 && str_contains($v['node'], $vo['node'] . '/')) {
|
||||||
$v['node'] = "{$repeatString}├{$repeatString}" . $v['node'];
|
$v['node'] = "{$repeatString}├{$repeatString}" . $v['node'];
|
||||||
$newList[] = $v;
|
$newList[] = $v;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ use app\common\model\TimeModel;
|
|||||||
class SystemQuick extends TimeModel
|
class SystemQuick extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'deleteTime' => 'delete_time',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,11 +9,10 @@ class ConfigService
|
|||||||
|
|
||||||
public static function getVersion()
|
public static function getVersion()
|
||||||
{
|
{
|
||||||
$version = cache('version');
|
$version = cache('site_version');
|
||||||
if (empty($version)) {
|
if (empty($version)) {
|
||||||
$version = sysConfig('site', 'site_version');
|
$version = sysConfig('site', 'site_version');
|
||||||
cache('site_version', $version);
|
cache('site_version', $version);
|
||||||
Cache::set('version', $version, 3600);
|
|
||||||
}
|
}
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -355,6 +355,7 @@ class BuildCurd
|
|||||||
if (!empty($bindSelectField) && !in_array($bindSelectField, array_column($columns, 'Field'))) {
|
if (!empty($bindSelectField) && !in_array($bindSelectField, array_column($columns, 'Field'))) {
|
||||||
throw new TableException("关联表{$relationTable}不存在该字段: {$bindSelectField}");
|
throw new TableException("关联表{$relationTable}不存在该字段: {$bindSelectField}");
|
||||||
}
|
}
|
||||||
|
$onlyFields = [];
|
||||||
foreach ($columns as $vo) {
|
foreach ($columns as $vo) {
|
||||||
if (empty($primaryKey) && $vo['Key'] == 'PRI') {
|
if (empty($primaryKey) && $vo['Key'] == 'PRI') {
|
||||||
$primaryKey = $vo['Field'];
|
$primaryKey = $vo['Field'];
|
||||||
@@ -362,6 +363,7 @@ class BuildCurd
|
|||||||
if (!empty($onlyShowFields) && !in_array($vo['Field'], $onlyShowFields)) {
|
if (!empty($onlyShowFields) && !in_array($vo['Field'], $onlyShowFields)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!empty($onlyShowFields)) $onlyFields[] = $vo['Field'];
|
||||||
$colum = [
|
$colum = [
|
||||||
'type' => $vo['Type'],
|
'type' => $vo['Type'],
|
||||||
'comment' => $vo['Comment'],
|
'comment' => $vo['Comment'],
|
||||||
@@ -388,6 +390,7 @@ class BuildCurd
|
|||||||
'bindSelectField' => $bindSelectField,
|
'bindSelectField' => $bindSelectField,
|
||||||
'delete' => $delete,
|
'delete' => $delete,
|
||||||
'tableColumns' => $formatColumns,
|
'tableColumns' => $formatColumns,
|
||||||
|
'onlyFields' => $onlyFields,
|
||||||
];
|
];
|
||||||
if (!empty($bindSelectField)) {
|
if (!empty($bindSelectField)) {
|
||||||
$relationArray = explode('\\', $modelFilename);
|
$relationArray = explode('\\', $modelFilename);
|
||||||
@@ -1038,7 +1041,7 @@ class BuildCurd
|
|||||||
$relationCode = '';
|
$relationCode = '';
|
||||||
foreach ($this->relationArray as $key => $val) {
|
foreach ($this->relationArray as $key => $val) {
|
||||||
$relation = CommonTool::lineToHump($key);
|
$relation = CommonTool::lineToHump($key);
|
||||||
$relationCode = "->withJoin('{$relation}', 'LEFT')\r";
|
$relationCode = "with(['{$relation}'])";
|
||||||
if (!empty($val['bindSelectField']) && !empty($val['primaryKey'])) {
|
if (!empty($val['bindSelectField']) && !empty($val['primaryKey'])) {
|
||||||
$constructRelation = '$notes["' . lcfirst($val['foreignKey']) . '"] = \app\admin\model\\' . $val['modelFilename'] . '::column("' . $val['bindSelectField'] . '", "' . $val['primaryKey'] . '");';
|
$constructRelation = '$notes["' . lcfirst($val['foreignKey']) . '"] = \app\admin\model\\' . $val['modelFilename'] . '::column("' . $val['bindSelectField'] . '", "' . $val['primaryKey'] . '");';
|
||||||
}
|
}
|
||||||
@@ -1092,16 +1095,17 @@ class BuildCurd
|
|||||||
$relationList = '';
|
$relationList = '';
|
||||||
if (!empty($this->relationArray)) {
|
if (!empty($this->relationArray)) {
|
||||||
foreach ($this->relationArray as $key => $val) {
|
foreach ($this->relationArray as $key => $val) {
|
||||||
$relation = CommonTool::lineToHump($key);
|
$relation = CommonTool::lineToHump($key);
|
||||||
// $relationCode = CommonTool::replaceTemplate(
|
$relationCode = CommonTool::replaceTemplate(
|
||||||
// $this->getTemplate("model{$this->DS}relation"),
|
$this->getTemplate("model{$this->DS}relation"),
|
||||||
// [
|
[
|
||||||
// 'relationMethod' => $relation,
|
'relationMethod' => $relation,
|
||||||
// 'relationModel' => "\app\admin\model\\{$val['modelFilename']}",
|
'relationModel' => "{$val['modelFilename']}::class",
|
||||||
// 'foreignKey' => $val['foreignKey'],
|
'foreignKey' => $val['primaryKey'],
|
||||||
// 'primaryKey' => $val['primaryKey'],
|
'primaryKey' => $val['foreignKey'],
|
||||||
// ]);
|
'relationFields' => empty($val['onlyFields']) ? "" : "->field('{$val['primaryKey']}," . implode(',', $val['onlyFields']) . "')",
|
||||||
// $relationList .= $relationCode;
|
]);
|
||||||
|
$relationList .= $relationCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1343,6 +1347,15 @@ class BuildCurd
|
|||||||
);
|
);
|
||||||
$this->fileList[$viewEditFile] = $viewEditValue;
|
$this->fileList[$viewEditFile] = $viewEditValue;
|
||||||
|
|
||||||
|
$viewRecycleFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}recycle.html";
|
||||||
|
$viewRecycleValue = CommonTool::replaceTemplate(
|
||||||
|
$this->getTemplate("view{$this->DS}recycle"),
|
||||||
|
[
|
||||||
|
'controllerUrl' => $this->controllerUrl,
|
||||||
|
'notesScript' => $this->formatNotesScript(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$this->fileList[$viewRecycleFile] = $viewRecycleValue;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1363,7 +1376,7 @@ class BuildCurd
|
|||||||
$templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ea.table.image}";
|
$templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ea.table.image}";
|
||||||
} elseif ($val['formType'] == 'datetime') {
|
} elseif ($val['formType'] == 'datetime') {
|
||||||
$templateValue = "{field: '{$field}', search: 'range', title: '{$val['comment']}'}";
|
$templateValue = "{field: '{$field}', search: 'range', title: '{$val['comment']}'}";
|
||||||
} elseif ($val['formType'] == 'images') {
|
} elseif ($val['formType'] == 'images') {
|
||||||
continue;
|
continue;
|
||||||
} elseif ($val['formType'] == 'file') {
|
} elseif ($val['formType'] == 'file') {
|
||||||
$templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ea.table.url}";
|
$templateValue = "{field: '{$field}', title: '{$val['comment']}', templet: ea.table.url}";
|
||||||
@@ -1424,13 +1437,15 @@ class BuildCurd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$indexCols .= $this->formatColsRow("{width: 250, title: '操作', templet: ea.table.tool},\r");
|
$recycleCols = $indexCols;
|
||||||
|
$indexCols .= $this->formatColsRow("{width: 250, title: '操作', templet: ea.table.tool},\r");
|
||||||
|
|
||||||
$jsValue = CommonTool::replaceTemplate(
|
$jsValue = CommonTool::replaceTemplate(
|
||||||
$this->getTemplate("static{$this->DS}js"),
|
$this->getTemplate("static{$this->DS}js"),
|
||||||
[
|
[
|
||||||
'controllerUrl' => $this->controllerUrl,
|
'controllerUrl' => $this->controllerUrl,
|
||||||
'indexCols' => $indexCols,
|
'indexCols' => $indexCols,
|
||||||
|
'recycleCols' => $recycleCols,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->fileList[$jsFile] = $jsValue;
|
$this->fileList[$jsFile] = $jsValue;
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ class {{controllerName}} extends AdminController
|
|||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->model = new {{modelFilename}}();
|
self::$model = {{modelFilename}}::class;
|
||||||
$this->notes = $notes = $this->model->notes;
|
$notes = self::$model::$notes;
|
||||||
{{constructRelation}}
|
{{constructRelation}}
|
||||||
|
$this->notes =$notes;
|
||||||
$this->assign(compact('notes'));
|
$this->assign(compact('notes'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
#[NodeAnnotation(title: '列表', auth: true)]
|
||||||
|
public function index(\app\Request $request): \think\response\Json|string
|
||||||
|
{
|
||||||
|
if ($request->isAjax()) {
|
||||||
|
if (input('selectFields')) {
|
||||||
|
return $this->selectList();
|
||||||
|
}
|
||||||
|
list($page, $limit, $where) = $this->buildTableParams();
|
||||||
|
$count = self::$model::where($where)->count();
|
||||||
|
$list = self::$model::where($where)->{{relationIndexMethod}}->page($page, $limit)->order($this->sort)->select()->toArray();
|
||||||
|
$data = [
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '',
|
||||||
|
'count' => $count,
|
||||||
|
'data' => $list,
|
||||||
|
];
|
||||||
|
return json($data);
|
||||||
|
}
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
@@ -7,12 +7,17 @@ use app\common\model\TimeModel;
|
|||||||
class {{modelName}} extends TimeModel
|
class {{modelName}} extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $name = "{{table}}";
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => "{{table}}",
|
||||||
|
'table' => "{{prefix_table}}",
|
||||||
|
'deleteTime' => {{deleteTime}},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
protected $table = "{{prefix_table}}";
|
public static array $notes = {{selectArrays}};
|
||||||
|
|
||||||
protected $deleteTime = {{deleteTime}};
|
{{relationList}}
|
||||||
|
|
||||||
public array $notes = {{selectArrays}};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
public function {{relationMethod}}()
|
public function {{relationMethod}}()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('{{relationModel}}', '{{foreignKey}}', '{{primaryKey}}');
|
return $this->hasOne({{relationModel}}, '{{foreignKey}}', '{{primaryKey}}'){{relationFields}};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
delete_url: '{{controllerUrl}}/delete',
|
delete_url: '{{controllerUrl}}/delete',
|
||||||
export_url: '{{controllerUrl}}/export',
|
export_url: '{{controllerUrl}}/export',
|
||||||
modify_url: '{{controllerUrl}}/modify',
|
modify_url: '{{controllerUrl}}/modify',
|
||||||
|
recycle_url: '{{controllerUrl}}/recycle',
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -29,5 +30,62 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
edit: function () {
|
edit: function () {
|
||||||
ea.listen();
|
ea.listen();
|
||||||
},
|
},
|
||||||
|
recycle: function () {
|
||||||
|
init.index_url = init.recycle_url;
|
||||||
|
ea.table.render({
|
||||||
|
init: init,
|
||||||
|
toolbar: ['refresh',
|
||||||
|
[{
|
||||||
|
class: 'layui-btn layui-btn-sm',
|
||||||
|
method: 'get',
|
||||||
|
field: 'id',
|
||||||
|
icon: 'fa fa-refresh',
|
||||||
|
text: '全部恢复',
|
||||||
|
title: '确定恢复?',
|
||||||
|
auth: 'recycle',
|
||||||
|
url: init.recycle_url + '?type=restore',
|
||||||
|
checkbox: true
|
||||||
|
}, {
|
||||||
|
class: 'layui-btn layui-btn-danger layui-btn-sm',
|
||||||
|
method: 'get',
|
||||||
|
field: 'id',
|
||||||
|
icon: 'fa fa-delete',
|
||||||
|
text: '彻底删除',
|
||||||
|
title: '确定彻底删除?',
|
||||||
|
auth: 'recycle',
|
||||||
|
url: init.recycle_url + '?type=delete',
|
||||||
|
checkbox: true
|
||||||
|
}], 'export',
|
||||||
|
],
|
||||||
|
cols: [[
|
||||||
|
{{recycleCols}}
|
||||||
|
{
|
||||||
|
width: 250,
|
||||||
|
title: '操作',
|
||||||
|
templet: ea.table.tool,
|
||||||
|
operat: [
|
||||||
|
[{
|
||||||
|
title: '确认恢复?',
|
||||||
|
text: '恢复数据',
|
||||||
|
filed: 'id',
|
||||||
|
url: init.recycle_url + '?type=restore',
|
||||||
|
method: 'get',
|
||||||
|
auth: 'recycle',
|
||||||
|
class: 'layui-btn layui-btn-xs layui-btn-success',
|
||||||
|
}, {
|
||||||
|
title: '想好了吗?',
|
||||||
|
text: '彻底删除',
|
||||||
|
filed: 'id',
|
||||||
|
method: 'get',
|
||||||
|
url: init.recycle_url + '?type=delete',
|
||||||
|
auth: 'recycle',
|
||||||
|
class: 'layui-btn layui-btn-xs layui-btn-normal layui-bg-red',
|
||||||
|
}]]
|
||||||
|
}
|
||||||
|
]],
|
||||||
|
});
|
||||||
|
|
||||||
|
ea.listen();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
data-auth-add="{:auth('{{controllerUrl}}/add')}"
|
data-auth-add="{:auth('{{controllerUrl}}/add')}"
|
||||||
data-auth-edit="{:auth('{{controllerUrl}}/edit')}"
|
data-auth-edit="{:auth('{{controllerUrl}}/edit')}"
|
||||||
data-auth-delete="{:auth('{{controllerUrl}}/delete')}"
|
data-auth-delete="{:auth('{{controllerUrl}}/delete')}"
|
||||||
|
data-auth-recycle="{:auth('{{controllerUrl}}/recycle')}"
|
||||||
lay-filter="currentTable">
|
lay-filter="currentTable">
|
||||||
<!-- searchTableShow="false" 隐藏搜索框 -->
|
<!-- searchTableShow="false" 隐藏搜索框 -->
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
13
app/admin/service/curd/templates/view/recycle.code
Normal file
13
app/admin/service/curd/templates/view/recycle.code
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<div class="layuimini-container">
|
||||||
|
<div class="layuimini-main">
|
||||||
|
<table id="currentTable" class="layui-table layui-hide"
|
||||||
|
data-auth-recycle="{:auth('{{controllerUrl}}/recycle')}"
|
||||||
|
lay-filter="currentTable">
|
||||||
|
<!-- searchTableShow="false" 隐藏搜索框 -->
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
{{notesScript}}
|
||||||
|
</script>
|
||||||
@@ -100,6 +100,9 @@ class CommonTool
|
|||||||
{
|
{
|
||||||
$arrayString = str_replace('array (', '[', $arrayString);
|
$arrayString = str_replace('array (', '[', $arrayString);
|
||||||
$arrayString = str_replace(')', ']', $arrayString);
|
$arrayString = str_replace(')', ']', $arrayString);
|
||||||
|
$arrayString = str_replace('=>
|
||||||
|
[', '=> [', $arrayString);
|
||||||
return $arrayString;
|
return $arrayString;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ namespace app\admin\traits;
|
|||||||
use app\admin\service\annotation\NodeAnnotation;
|
use app\admin\service\annotation\NodeAnnotation;
|
||||||
use app\admin\service\tool\CommonTool;
|
use app\admin\service\tool\CommonTool;
|
||||||
use app\Request;
|
use app\Request;
|
||||||
use jianyan\excel\Excel;
|
use think\db\exception\PDOException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use think\response\Json;
|
use think\response\Json;
|
||||||
|
|
||||||
@@ -25,8 +25,8 @@ trait Curd
|
|||||||
return $this->selectList();
|
return $this->selectList();
|
||||||
}
|
}
|
||||||
list($page, $limit, $where) = $this->buildTableParams();
|
list($page, $limit, $where) = $this->buildTableParams();
|
||||||
$count = $this->model->where($where)->count();
|
$count = self::$model::where($where)->count();
|
||||||
$list = $this->model->where($where)->page($page, $limit)->order($this->sort)->select()->toArray();
|
$list = self::$model::where($where)->page($page, $limit)->order($this->sort)->select()->toArray();
|
||||||
$data = [
|
$data = [
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '',
|
'msg' => '',
|
||||||
@@ -46,8 +46,8 @@ trait Curd
|
|||||||
$rule = [];
|
$rule = [];
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
try {
|
try {
|
||||||
Db::transaction(function () use ($post, &$save) {
|
Db::transaction(function() use ($post, &$save) {
|
||||||
$save = $this->model->save($post);
|
$save = self::$model::create($post);
|
||||||
});
|
});
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
$this->error('新增失败:' . $e->getMessage());
|
$this->error('新增失败:' . $e->getMessage());
|
||||||
@@ -60,14 +60,14 @@ trait Curd
|
|||||||
#[NodeAnnotation(title: '编辑', auth: true)]
|
#[NodeAnnotation(title: '编辑', auth: true)]
|
||||||
public function edit(Request $request, $id = 0): string
|
public function edit(Request $request, $id = 0): string
|
||||||
{
|
{
|
||||||
$row = $this->model->find($id);
|
$row = self::$model::find($id);
|
||||||
empty($row) && $this->error('数据不存在');
|
empty($row) && $this->error('数据不存在');
|
||||||
if ($request->isPost()) {
|
if ($request->isPost()) {
|
||||||
$post = $request->post();
|
$post = $request->post();
|
||||||
$rule = [];
|
$rule = [];
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
try {
|
try {
|
||||||
Db::transaction(function () use ($post, $row, &$save) {
|
Db::transaction(function() use ($post, $row, &$save) {
|
||||||
$save = $row->save($post);
|
$save = $row->save($post);
|
||||||
});
|
});
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
@@ -85,7 +85,7 @@ trait Curd
|
|||||||
// 如果不是id作为主键 请在对应的控制器中覆盖重写
|
// 如果不是id作为主键 请在对应的控制器中覆盖重写
|
||||||
$id = $request->param('id', []);
|
$id = $request->param('id', []);
|
||||||
$this->checkPostRequest();
|
$this->checkPostRequest();
|
||||||
$row = $this->model->whereIn('id', $id)->select();
|
$row = self::$model::whereIn('id', $id)->select();
|
||||||
$row->isEmpty() && $this->error('数据不存在');
|
$row->isEmpty() && $this->error('数据不存在');
|
||||||
try {
|
try {
|
||||||
$save = $row->delete();
|
$save = $row->delete();
|
||||||
@@ -102,7 +102,7 @@ trait Curd
|
|||||||
$this->error('演示环境下不允许操作');
|
$this->error('演示环境下不允许操作');
|
||||||
}
|
}
|
||||||
list($page, $limit, $where) = $this->buildTableParams();
|
list($page, $limit, $where) = $this->buildTableParams();
|
||||||
$tableName = $this->model->getName();
|
$tableName = (new self::$model)->getName();
|
||||||
$tableName = CommonTool::humpToLine(lcfirst($tableName));
|
$tableName = CommonTool::humpToLine(lcfirst($tableName));
|
||||||
$prefix = config('database.connections.mysql.prefix');
|
$prefix = config('database.connections.mysql.prefix');
|
||||||
$dbList = Db::query("show full columns from {$prefix}{$tableName}");
|
$dbList = Db::query("show full columns from {$prefix}{$tableName}");
|
||||||
@@ -113,14 +113,16 @@ trait Curd
|
|||||||
$header[] = [$comment, $vo['Field']];
|
$header[] = [$comment, $vo['Field']];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$list = $this->model
|
$list = self::$model::where($where)
|
||||||
->where($where)
|
|
||||||
->limit(100000)
|
->limit(100000)
|
||||||
->order('id', 'desc')
|
->order($this->sort)
|
||||||
->select()
|
->select()
|
||||||
->toArray();
|
->toArray();
|
||||||
$fileName = time();
|
try {
|
||||||
return Excel::exportData($list, $header, $fileName, 'xlsx');
|
exportExcel($header, $list);
|
||||||
|
}catch (\Throwable $exception) {
|
||||||
|
$this->error('导出失败: ' . $exception->getMessage() . PHP_EOL . $exception->getFile() . PHP_EOL . $exception->getLine());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[NodeAnnotation(title: '属性修改', auth: true)]
|
#[NodeAnnotation(title: '属性修改', auth: true)]
|
||||||
@@ -134,7 +136,7 @@ trait Curd
|
|||||||
'value|值' => 'require',
|
'value|值' => 'require',
|
||||||
];
|
];
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
$row = $this->model->find($post['id']);
|
$row = self::$model::find($post['id']);
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
$this->error('数据不存在');
|
$this->error('数据不存在');
|
||||||
}
|
}
|
||||||
@@ -142,7 +144,7 @@ trait Curd
|
|||||||
$this->error('该字段不允许修改:' . $post['field']);
|
$this->error('该字段不允许修改:' . $post['field']);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Db::transaction(function () use ($post, $row) {
|
Db::transaction(function() use ($post, $row) {
|
||||||
$row->save([
|
$row->save([
|
||||||
$post['field'] => $post['value'],
|
$post['field'] => $post['value'],
|
||||||
]);
|
]);
|
||||||
@@ -153,4 +155,49 @@ trait Curd
|
|||||||
$this->success('保存成功');
|
$this->success('保存成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[NodeAnnotation(title: '回收站', auth: true)]
|
||||||
|
public function recycle(Request $request): Json|string
|
||||||
|
{
|
||||||
|
if (!$request->isAjax()) {
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
$id = $request->param('id', []);
|
||||||
|
$type = $request->param('type', '');
|
||||||
|
$deleteTimeField = (new self::$model)->getOption('deleteTime'); // 获取软删除字段
|
||||||
|
$defaultErrorMsg = 'Model 中未设置软删除 deleteTime 对应字段 或 数据表中不存在该字段';
|
||||||
|
if (!$deleteTimeField) $this->success($defaultErrorMsg);
|
||||||
|
switch ($type) {
|
||||||
|
case 'restore':
|
||||||
|
self::$model::withTrashed()->whereIn('id', $id)->strict(false)->update([$deleteTimeField => null, 'update_time' => time()]);
|
||||||
|
$this->success('success');
|
||||||
|
break;
|
||||||
|
case 'delete':
|
||||||
|
self::$model::destroy($id, true);
|
||||||
|
$this->success('success');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
list($page, $limit, $where) = $this->buildTableParams();
|
||||||
|
try {
|
||||||
|
$count = self::$model::withTrashed()->where($where)->whereNotNull($deleteTimeField)->count();
|
||||||
|
$list = self::$model::withTrashed()->where($where)->page($page, $limit)->order($this->sort)->whereNotNull($deleteTimeField)->select()->toArray();
|
||||||
|
$data = [
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => '',
|
||||||
|
'count' => $count,
|
||||||
|
'data' => $list,
|
||||||
|
];
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$error = $e->getMessage();
|
||||||
|
if ($e instanceof PDOException) $error .= '<br>' . $defaultErrorMsg;
|
||||||
|
$data = [
|
||||||
|
'code' => -1,
|
||||||
|
'msg' => $error,
|
||||||
|
'count' => 0,
|
||||||
|
'data' => [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,12 +151,18 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>DEBUG模式</td>
|
<td>DEBUG模式</td>
|
||||||
<td>
|
<td>
|
||||||
<button type="button" class="layui-btn layui-btn-xs {:env('APP_DEBUG')?'layui-btn-warm':'layui-bg-gray'}">
|
<button type="button" class="layui-btn layui-btn-xs {:env('APP_DEBUG')?'layui-bg-cyan':'layui-bg-gray'}">
|
||||||
{:env('APP_DEBUG')?'开启中':'已关闭'}
|
{:env('APP_DEBUG')?'开启中':'已关闭'}
|
||||||
</button>
|
</button>
|
||||||
<span class="layui-badge layui-bg-gray">建议线上环境关闭 APP_DEBUG</span>
|
<span class="layui-badge layui-bg-gray">建议线上环境关闭 APP_DEBUG</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>composer信息</td>
|
||||||
|
<td>
|
||||||
|
<button type="button" class="layui-btn layui-btn-xs layui-bg-cyan" lay-on="showComposerInfo">点击查看</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>主要特色</td>
|
<td>主要特色</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-col-xs2">
|
<div class="layui-col-xs2">
|
||||||
<button class="layui-btn layui-bg-purple layui-btn-fluid" type="button" lay-on="AiOptimization">AI优化</button>
|
<button class="layui-btn layui-bg-purple" type="button" lay-on="AiOptimization">AI优化</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
data-auth-edit="{:auth('mall.goods/edit')}"
|
data-auth-edit="{:auth('mall.goods/edit')}"
|
||||||
data-auth-delete="{:auth('mall.goods/delete')}"
|
data-auth-delete="{:auth('mall.goods/delete')}"
|
||||||
data-auth-stock="{:auth('mall.goods/stock')}"
|
data-auth-stock="{:auth('mall.goods/stock')}"
|
||||||
|
data-auth-recycle="{:auth('mall.goods/recycle')}"
|
||||||
lay-filter="currentTable">
|
lay-filter="currentTable">
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
11
app/admin/view/mall/goods/recycle.html
Normal file
11
app/admin/view/mall/goods/recycle.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<div class="layuimini-container">
|
||||||
|
<div class="layuimini-main">
|
||||||
|
<table id="currentTable" class="layui-table layui-hide"
|
||||||
|
data-auth-recycle="{:auth('mall.goods/recycle')}"
|
||||||
|
lay-filter="currentTable">
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
let cateSelects = JSON.parse('{$cate|json_encode=256|raw}')
|
||||||
|
</script>
|
||||||
@@ -1,22 +1,16 @@
|
|||||||
<div class="layuimini-container">
|
<div class="layuimini-container">
|
||||||
<div class="layuimini-main" id="app">
|
<div class="layuimini-main" id="app">
|
||||||
|
|
||||||
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
|
<div class="layui-tabs layui-tabs-card layui-panel " id="docDemoTabBrief">
|
||||||
<ul class="layui-tab-title">
|
<ul class="layui-tabs-header layui-bg-tint">
|
||||||
<li class="layui-this" data-group="site">网站设置</li>
|
<li class="layui-this" data-group="site">网站设置</li>
|
||||||
<li data-group="logo">LOGO配置</li>
|
<li data-group="logo">LOGO配置</li>
|
||||||
<li data-group="upload">上传配置</li>
|
<li data-group="upload">上传配置</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="layui-tab-content">
|
<div class="layui-tabs-body">
|
||||||
<div class="layui-tab-item layui-show">
|
<div class="layui-tabs-item layui-show"> {include file="system/config/site" /}</div>
|
||||||
{include file="system/config/site" /}
|
<div class="layui-tabs-item"> {include file="system/config/logo" /}</div>
|
||||||
</div>
|
<div class="layui-tabs-item">{include file="system/config/upload" /}</div>
|
||||||
<div class="layui-tab-item">
|
|
||||||
{include file="system/config/logo" /}
|
|
||||||
</div>
|
|
||||||
<div class="layui-tab-item">
|
|
||||||
{include file="system/config/upload" /}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// 应用公共文件
|
// 应用公共文件
|
||||||
|
|
||||||
use app\common\service\AuthService;
|
use app\common\service\AuthService;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
use think\db\exception\DataNotFoundException;
|
use think\db\exception\DataNotFoundException;
|
||||||
use think\db\exception\DbException;
|
use think\db\exception\DbException;
|
||||||
use think\db\exception\ModelNotFoundException;
|
use think\db\exception\ModelNotFoundException;
|
||||||
@@ -100,21 +102,63 @@ if (!function_exists('auth')) {
|
|||||||
$authService = new AuthService(session('admin.id'));
|
$authService = new AuthService(session('admin.id'));
|
||||||
return $authService->checkNode($node);
|
return $authService->checkNode($node);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $detail
|
* @param string|null $detail
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $placeholder
|
* @param string $placeholder
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function editor_textarea(?string $detail, string $name = 'desc', string $placeholder = '请输入'): string
|
function editor_textarea(?string $detail, string $name = 'desc', string $placeholder = '请输入'): string
|
||||||
{
|
{
|
||||||
$editor_type = sysConfig('site', 'editor_type');
|
$editor_type = sysConfig('site', 'editor_type');
|
||||||
return match ($editor_type) {
|
return match ($editor_type) {
|
||||||
'ckeditor' => "<textarea name='{$name}' rows='20' class='layui-textarea editor' placeholder='{$placeholder}'>{$detail}</textarea>",
|
'ckeditor' => "<textarea name='{$name}' rows='20' class='layui-textarea editor' placeholder='{$placeholder}'>{$detail}</textarea>",
|
||||||
'ueditor' => "<script type='text/plain' id='{$name}' name='{$name}' class='editor' data-content='{$detail}'></script>",
|
'ueditor' => "<script type='text/plain' id='{$name}' name='{$name}' class='editor' data-content='{$detail}'></script>",
|
||||||
'EasyMDE' => "<textarea id='{$name}' class='editor' name='{$name}'>{$detail}</textarea>",
|
'EasyMDE' => "<textarea id='{$name}' class='editor' name='{$name}'>{$detail}</textarea>",
|
||||||
default => "<div class='wangEditor_div'><textarea name='{$name}' rows='20' class='layui-textarea editor layui-hide'>{$detail}</textarea><div id='editor_toolbar_{$name}'></div><div id='editor_{$name}' style='height: 300px'></div></div>",
|
default => "<div class='wangEditor_div'><textarea name='{$name}' rows='20' class='layui-textarea editor layui-hide'>{$detail}</textarea><div id='editor_toolbar_{$name}'></div><div id='editor_{$name}' style='height: 500px'></div></div>",
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc 导出excel
|
||||||
|
* @tip 追求性能请使用 xlsWriter https://xlswriter-docs.viest.me/zh-cn
|
||||||
|
* @param array $header
|
||||||
|
* @param array $list
|
||||||
|
* @param string $fileName
|
||||||
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
function exportExcel(array $header = [], array $list = [], string $fileName = ''): void
|
||||||
|
{
|
||||||
|
if (empty($fileName)) $fileName = time();
|
||||||
|
if (empty($header) || empty($list)) throw new \Exception('导出数据不能为空');
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
$headers = array_column($header, 0) ?? array_keys($list[0]);
|
||||||
|
$sheet->fromArray([$headers], null, 'A1');
|
||||||
|
$rowIndex = 2;
|
||||||
|
foreach ($list as $row) {
|
||||||
|
$rowData = [];
|
||||||
|
foreach ($header as $item) {
|
||||||
|
$value = $row[$item[1]] ?? '';
|
||||||
|
if ($value === null) {
|
||||||
|
$rowData[] = '';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$rowData[] = $value;
|
||||||
|
}
|
||||||
|
$sheet->fromArray([$rowData], null, "A{$rowIndex}");
|
||||||
|
$rowIndex++;
|
||||||
}
|
}
|
||||||
|
foreach (range('A', $sheet->getHighestColumn()) as $col) {
|
||||||
|
$sheet->getColumnDimension($col)->setAutoSize(true);
|
||||||
|
}
|
||||||
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||||
|
header('Content-Disposition: attachment;filename="' . $fileName . '.xlsx"');
|
||||||
|
header('Cache-Control: max-age=0');
|
||||||
|
$writer = new Xlsx($spreadsheet);
|
||||||
|
$writer->save('php://output');
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
@@ -19,9 +19,9 @@ class AdminController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 当前模型
|
* 当前模型
|
||||||
* @Model
|
* @Model
|
||||||
* @var object
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
protected object $model;
|
protected static mixed $model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段排序
|
* 字段排序
|
||||||
@@ -172,7 +172,7 @@ class AdminController extends BaseController
|
|||||||
$where = [];
|
$where = [];
|
||||||
$excludes = [];
|
$excludes = [];
|
||||||
// 判断是否关联查询
|
// 判断是否关联查询
|
||||||
$tableName = Str::snake(lcfirst($this->model->getName()));
|
$tableName = Str::snake(lcfirst((new self::$model)->getName()));
|
||||||
foreach ($filters as $key => $val) {
|
foreach ($filters as $key => $val) {
|
||||||
if (in_array($key, $excludeFields)) {
|
if (in_array($key, $excludeFields)) {
|
||||||
$excludes[$key] = $val;
|
$excludes[$key] = $val;
|
||||||
@@ -218,7 +218,7 @@ class AdminController extends BaseController
|
|||||||
public function selectList(): Json
|
public function selectList(): Json
|
||||||
{
|
{
|
||||||
$fields = input('selectFields');
|
$fields = input('selectFields');
|
||||||
$data = $this->model->where($this->selectWhere)->field($fields)->select()->toArray();
|
$data = self::$model::where($this->selectWhere)->field($fields)->select()->toArray();
|
||||||
$this->success(null, $data);
|
$this->success(null, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,28 +13,20 @@ use think\model\concern\SoftDelete;
|
|||||||
class TimeModel extends Model
|
class TimeModel extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动时间戳类型
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $autoWriteTimestamp = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加时间
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $createTime = 'create_time';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $updateTime = 'update_time';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 软删除
|
* 软删除
|
||||||
*/
|
*/
|
||||||
use SoftDelete;
|
use SoftDelete;
|
||||||
protected $deleteTime = false;
|
|
||||||
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'autoWriteTimestamp' => true,
|
||||||
|
'createTime' => 'create_time',
|
||||||
|
'updateTime' => 'update_time',
|
||||||
|
'deleteTime' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -27,11 +27,10 @@
|
|||||||
"topthink/think-view": "^2.0",
|
"topthink/think-view": "^2.0",
|
||||||
"topthink/think-captcha": "^3.0",
|
"topthink/think-captcha": "^3.0",
|
||||||
"topthink/think-filesystem": "^2.0",
|
"topthink/think-filesystem": "^2.0",
|
||||||
"aliyuncs/oss-sdk-php": "^2.6",
|
"aliyuncs/oss-sdk-php": "^2.7.2",
|
||||||
"qcloud/cos-sdk-v5": "^2.6",
|
"qcloud/cos-sdk-v5": "^2.6",
|
||||||
"jianyan74/php-excel": "^1.0.2",
|
|
||||||
"doctrine/annotations": "^2.0.0",
|
"doctrine/annotations": "^2.0.0",
|
||||||
"phpoffice/phpspreadsheet": "^1.28",
|
"phpoffice/phpspreadsheet": "^4.1.0",
|
||||||
"myclabs/php-enum": "^1.8",
|
"myclabs/php-enum": "^1.8",
|
||||||
"qiniu/php-sdk": "^7.11.0",
|
"qiniu/php-sdk": "^7.11.0",
|
||||||
"wolf-leo/phplogviewer": "^0.11.3",
|
"wolf-leo/phplogviewer": "^0.11.3",
|
||||||
|
|||||||
@@ -571,3 +571,22 @@ INSERT INTO `ea_system_uploadfile`
|
|||||||
VALUES ('290', 'oss', 'image/jpeg', 'https://lxn-99php.oss-cn-shenzhen.aliyuncs.com/upload/20191111/2c412adf1b30c8be3a913e603c7b6e4a.jpg', '', '', '', '0', 'image/jpeg', '0', 'jpg', '', 1573612437, null, null);
|
VALUES ('290', 'oss', 'image/jpeg', 'https://lxn-99php.oss-cn-shenzhen.aliyuncs.com/upload/20191111/2c412adf1b30c8be3a913e603c7b6e4a.jpg', '', '', '', '0', 'image/jpeg', '0', 'jpg', '', 1573612437, null, null);
|
||||||
INSERT INTO `ea_system_uploadfile`
|
INSERT INTO `ea_system_uploadfile`
|
||||||
VALUES ('296', 'cos', 'image/jpeg', 'https://easyadmin-1251997243.cos.ap-guangzhou.myqcloud.com/upload/20191114/2381eaf81208ac188fa994b6f2579953.jpg', '', '', '', '0', 'image/jpeg', '0', 'jpg', '', 1573612437, null, null);
|
VALUES ('296', 'cos', 'image/jpeg', 'https://easyadmin-1251997243.cos.ap-guangzhou.myqcloud.com/upload/20191114/2381eaf81208ac188fa994b6f2579953.jpg', '', '', '', '0', 'image/jpeg', '0', 'jpg', '', 1573612437, null, null);
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for ea_system_log
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `ea_system_log`;
|
||||||
|
CREATE TABLE `ea_system_log`
|
||||||
|
(
|
||||||
|
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||||
|
`admin_id` int unsigned DEFAULT '0' COMMENT '管理员ID',
|
||||||
|
`url` varchar(1500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '操作页面',
|
||||||
|
`method` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '请求方法',
|
||||||
|
`title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '日志标题',
|
||||||
|
`content` json NOT NULL COMMENT '请求数据',
|
||||||
|
`response` json DEFAULT NULL COMMENT '回调数据',
|
||||||
|
`ip` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'IP',
|
||||||
|
`useragent` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT 'User-Agent',
|
||||||
|
`create_time` int DEFAULT NULL COMMENT '操作时间',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPACT COMMENT='后台操作日志表 - 202412';
|
||||||
|
|||||||
2
log.md
2
log.md
@@ -1,3 +1,5 @@
|
|||||||
|
> 2025年03月27日 重构了 `model` 的调用方式 原因查看 [https://github.com/top-think/think-orm/issues/704](https://github.com/top-think/think-orm/issues/704)
|
||||||
|
>
|
||||||
> 2025年01月01日 `PHP` 要求升级到 `8.1+`
|
> 2025年01月01日 `PHP` 要求升级到 `8.1+`
|
||||||
>
|
>
|
||||||
> 2024年05月 更新 `EasyAdmin8` 重置版,多处语法、写法进行变更
|
> 2024年05月 更新 `EasyAdmin8` 重置版,多处语法、写法进行变更
|
||||||
@@ -75,8 +75,8 @@ body {
|
|||||||
|
|
||||||
/**重写layui表格自适应*/
|
/**重写layui表格自适应*/
|
||||||
.layuimini-container .layui-table-cell {
|
.layuimini-container .layui-table-cell {
|
||||||
height: 100%;
|
height: 50px;
|
||||||
max-width: 100%;
|
line-height: 42px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**数据表格-搜索表单样式*/
|
/**数据表格-搜索表单样式*/
|
||||||
|
|||||||
@@ -140,6 +140,39 @@ define(["jquery", "easy-admin", "echarts", "echarts-theme", "miniAdmin", "miniTh
|
|||||||
echartsRecords.resize();
|
echartsRecords.resize();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let util = layui.util;
|
||||||
|
util.on({
|
||||||
|
showComposerInfo: function () {
|
||||||
|
// <div style="padding: 25px;">12313</div>
|
||||||
|
let html = ``
|
||||||
|
ea.request.post({
|
||||||
|
url: ea.url('ajax/composerInfo'),
|
||||||
|
}, function (success) {
|
||||||
|
let data = success.data
|
||||||
|
data.forEach(function (item) {
|
||||||
|
html += `${item.name} ${item.version}\r\n`
|
||||||
|
})
|
||||||
|
html = `<pre class="layui-code code-demo">${html}</pre>`
|
||||||
|
layer.open({
|
||||||
|
type: 1,
|
||||||
|
title: 'composer 信息',
|
||||||
|
area: ['50%', '90%'],
|
||||||
|
shade: 0.8,
|
||||||
|
shadeClose: true,
|
||||||
|
scrollbar: false,
|
||||||
|
content: html,
|
||||||
|
success: function () {
|
||||||
|
layui.code({elem: '.code-demo', theme: 'dark', lang: 'php'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, function (error) {
|
||||||
|
console.error(error)
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
editAdmin: function () {
|
editAdmin: function () {
|
||||||
let form = layui.form
|
let form = layui.form
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
export_url: 'mall.goods/export',
|
export_url: 'mall.goods/export',
|
||||||
modify_url: 'mall.goods/modify',
|
modify_url: 'mall.goods/modify',
|
||||||
stock_url: 'mall.goods/stock',
|
stock_url: 'mall.goods/stock',
|
||||||
|
recycle_url: 'mall.goods/recycle',
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -27,7 +28,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
icon: 'fa fa-plus ',
|
icon: 'fa fa-plus ',
|
||||||
extend: 'data-width="90%" data-height="95%"',
|
extend: 'data-width="90%" data-height="95%"',
|
||||||
}],
|
}],
|
||||||
'delete', 'export'],
|
'delete', 'export', 'recycle'],
|
||||||
cols: [[
|
cols: [[
|
||||||
{type: "checkbox"},
|
{type: "checkbox"},
|
||||||
{field: 'id', width: 80, title: 'ID', searchOp: '='},
|
{field: 'id', width: 80, title: 'ID', searchOp: '='},
|
||||||
@@ -107,6 +108,78 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
stock: function () {
|
stock: function () {
|
||||||
ea.listen();
|
ea.listen();
|
||||||
},
|
},
|
||||||
|
recycle: function () {
|
||||||
|
init.index_url = init.recycle_url;
|
||||||
|
ea.table.render({
|
||||||
|
init: init,
|
||||||
|
toolbar: ['refresh',
|
||||||
|
[{
|
||||||
|
class: 'layui-btn layui-btn-sm',
|
||||||
|
method: 'get',
|
||||||
|
field: 'id',
|
||||||
|
icon: 'fa fa-refresh',
|
||||||
|
text: '全部恢复',
|
||||||
|
title: '确定恢复?',
|
||||||
|
auth: 'recycle',
|
||||||
|
url: init.recycle_url + '?type=restore',
|
||||||
|
checkbox: true
|
||||||
|
}, {
|
||||||
|
class: 'layui-btn layui-btn-danger layui-btn-sm',
|
||||||
|
method: 'get',
|
||||||
|
field: 'id',
|
||||||
|
icon: 'fa fa-delete',
|
||||||
|
text: '彻底删除',
|
||||||
|
title: '确定彻底删除?',
|
||||||
|
auth: 'recycle',
|
||||||
|
url: init.recycle_url + '?type=delete',
|
||||||
|
checkbox: true
|
||||||
|
}], 'export',
|
||||||
|
],
|
||||||
|
cols: [[
|
||||||
|
{type: "checkbox"},
|
||||||
|
{field: 'id', width: 80, title: 'ID', searchOp: '='},
|
||||||
|
{field: 'sort', width: 80, title: '排序', edit: 'text'},
|
||||||
|
{field: 'cate_id', minWidth: 80, title: '商品分类', search: 'select', selectList: cateSelects, laySearch: true},
|
||||||
|
{field: 'title', minWidth: 80, title: '商品名称'},
|
||||||
|
{field: 'logo', minWidth: 80, title: '分类图片', search: false, templet: ea.table.image},
|
||||||
|
{field: 'status', title: '状态', width: 85, selectList: {0: '禁用', 1: '启用'}},
|
||||||
|
// 演示多选,实际数据库并无 status2 字段,搜索后会报错
|
||||||
|
{
|
||||||
|
field: 'status2', title: '演示多选', width: 105, search: 'xmSelect', selectList: {1: '模拟选项1', 2: '模拟选项2', 3: '模拟选项3', 4: '模拟选项4', 5: '模拟选项5'},
|
||||||
|
searchOp: 'in', templet: function (res) {
|
||||||
|
// 根据自己实际项目进行输出
|
||||||
|
return res?.status2 || '模拟数据'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'},
|
||||||
|
{field: 'delete_time', minWidth: 80, title: '删除时间', search: 'range'},
|
||||||
|
{
|
||||||
|
width: 250,
|
||||||
|
title: '操作',
|
||||||
|
templet: ea.table.tool,
|
||||||
|
operat: [
|
||||||
|
[{
|
||||||
|
title: '确认恢复?',
|
||||||
|
text: '恢复数据',
|
||||||
|
filed: 'id',
|
||||||
|
url: init.recycle_url + '?type=restore',
|
||||||
|
method: 'get',
|
||||||
|
auth: 'recycle',
|
||||||
|
class: 'layui-btn layui-btn-xs layui-btn-success',
|
||||||
|
}, {
|
||||||
|
title: '想好了吗?',
|
||||||
|
text: '彻底删除',
|
||||||
|
filed: 'id',
|
||||||
|
method: 'get',
|
||||||
|
url: init.recycle_url + '?type=delete',
|
||||||
|
auth: 'recycle',
|
||||||
|
class: 'layui-btn layui-btn-xs layui-btn-normal layui-bg-red',
|
||||||
|
}]]
|
||||||
|
}
|
||||||
|
]],
|
||||||
|
});
|
||||||
|
ea.listen();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function aiOptimization(data) {
|
function aiOptimization(data) {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
define(["jquery", "easy-admin", "vue"], function ($, ea, Vue) {
|
define(["jquery", "easy-admin"], function ($, ea) {
|
||||||
|
|
||||||
var form = layui.form;
|
var form = layui.form;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
index: function () {
|
index: function () {
|
||||||
var _group = 'site'
|
var _group = 'site'
|
||||||
var element = layui.element;
|
let tabs = layui.tabs
|
||||||
element.on('tab(docDemoTabBrief)', function (data) {
|
var TABS_ID = 'docDemoTabBrief';
|
||||||
|
tabs.on(`afterChange(${TABS_ID})`, function (data) {
|
||||||
_group = $(this).data('group')
|
_group = $(this).data('group')
|
||||||
});
|
})
|
||||||
|
|
||||||
let _upload_type = upload_type || 'local'
|
let _upload_type = upload_type || 'local'
|
||||||
$('.upload_type').addClass('layui-hide')
|
$('.upload_type').addClass('layui-hide')
|
||||||
$('.' + _upload_type).removeClass('layui-hide')
|
$('.' + _upload_type).removeClass('layui-hide')
|
||||||
@@ -20,12 +20,15 @@ define(["jquery", "easy-admin", "vue"], function ($, ea, Vue) {
|
|||||||
$('.' + _upload_type).removeClass('layui-hide')
|
$('.' + _upload_type).removeClass('layui-hide')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
form.on("submit", function (data) {
|
form.on("submit", function (data) {
|
||||||
data.field['group'] = _group
|
data.field['group'] = _group
|
||||||
});
|
});
|
||||||
|
|
||||||
ea.listen();
|
ea.listen('', function (res) {
|
||||||
|
ea.msg.success(res.msg);
|
||||||
|
}, function (err) {
|
||||||
|
ea.msg.error(err.msg);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -18,7 +18,7 @@ define(["jquery", "easy-admin", "miniTab"], function ($, ea, miniTab) {
|
|||||||
<fieldset class="layui-elem-field">
|
<fieldset class="layui-elem-field">
|
||||||
<legend>提示</legend>
|
<legend>提示</legend>
|
||||||
<div class="layui-field-box">
|
<div class="layui-field-box">
|
||||||
<p><a class="layui-font-blue" target="_blank" rel="nofollow" href="https://edocs.easyadmin8.top/curd/command.html">命令可查询文档</a></p>
|
<p><a class="layui-font-blue" target="_blank" rel="nofollow" href="https://edocs.easyadmin8.top/#/md/curd/command">命令可查询文档</a></p>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<form class="layui-form layui-form-pane" action="">
|
<form class="layui-form layui-form-pane" action="">
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
field: 'content', minWidth: 200, title: '请求数据', align: "left", templet: function (res) {
|
field: 'content', minWidth: 200, title: '请求数据', align: "left", templet: function (res) {
|
||||||
let html = '<div class="layui-colla-item">' +
|
let html = '<div class="layui-colla-item">' +
|
||||||
'<div class="layui-colla-title">点击预览</div>' +
|
'<div class="layui-colla-title">点击预览</div>' +
|
||||||
'<div class="layui-colla-content">' + prettyFormat(res.content) + '</div>' +
|
'<div class="layui-colla-content">' + prettyFormat(JSON.stringify(res.content)) + '</div>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
return '<div class="layui-collapse" lay-accordion>' + html + '</div>'
|
return '<div class="layui-collapse" lay-accordion>' + html + '</div>'
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
field: 'response', minWidth: 200, title: '回调数据', align: "left", templet: function (res) {
|
field: 'response', minWidth: 200, title: '回调数据', align: "left", templet: function (res) {
|
||||||
let html = '<div class="layui-colla-item">' +
|
let html = '<div class="layui-colla-item">' +
|
||||||
'<div class="layui-colla-title">点击预览</div>' +
|
'<div class="layui-colla-title">点击预览</div>' +
|
||||||
'<div class="layui-colla-content">' + prettyFormat(res.response) + '</div>' +
|
'<div class="layui-colla-content">' + prettyFormat(JSON.stringify(res.response)) + '</div>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
return '<div class="layui-collapse" lay-accordion>' + html + '</div>'
|
return '<div class="layui-collapse" lay-accordion>' + html + '</div>'
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
public/static/common/images/loading.gif
Normal file
BIN
public/static/common/images/loading.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
@@ -22,6 +22,7 @@ require.config({
|
|||||||
"vue": ["plugs/vue-2.6.10/vue.min"],
|
"vue": ["plugs/vue-2.6.10/vue.min"],
|
||||||
"swiper": ["plugs/swiper/swiper-bundle.min"],
|
"swiper": ["plugs/swiper/swiper-bundle.min"],
|
||||||
"colorMode": ["plugs/colorMode/colorMode"],
|
"colorMode": ["plugs/colorMode/colorMode"],
|
||||||
|
"lazyload": ["plugs/lazyload/lazyload.min"],
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSelect, miniTheme, xmSelect) {
|
define(["jquery", "tableSelect", "miniTheme", "xmSelect", "lazyload"], function ($, tableSelect, miniTheme, xmSelect, lazyload) {
|
||||||
|
|
||||||
//切换日夜模式
|
//切换日夜模式
|
||||||
window.onInitElemStyle = function () {
|
window.onInitElemStyle = function () {
|
||||||
@@ -253,7 +253,7 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 初始化表格左上方工具栏
|
// 初始化表格左上方工具栏
|
||||||
options.toolbar = options.toolbar || ['refresh', 'add', 'delete', 'export'];
|
options.toolbar = options.toolbar || ['refresh', 'add', 'delete', 'export', 'recycle'];
|
||||||
options.toolbar = admin.table.renderToolbar(options.toolbar, options.elem, options.id, options.init);
|
options.toolbar = admin.table.renderToolbar(options.toolbar, options.elem, options.id, options.init);
|
||||||
|
|
||||||
// 判断是否有操作列表权限
|
// 判断是否有操作列表权限
|
||||||
@@ -312,6 +312,14 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
if (admin.checkAuth('export', elem)) {
|
if (admin.checkAuth('export', elem)) {
|
||||||
toolbarHtml += '<button class="layui-btn layui-btn-sm layui-btn-success easyadmin-export-btn" data-url="' + init.export_url + '" data-table-export="' + tableId + '"><i class="fa fa-file-excel-o"></i> 导出</button>\n';
|
toolbarHtml += '<button class="layui-btn layui-btn-sm layui-btn-success easyadmin-export-btn" data-url="' + init.export_url + '" data-table-export="' + tableId + '"><i class="fa fa-file-excel-o"></i> 导出</button>\n';
|
||||||
}
|
}
|
||||||
|
} else if (v === 'recycle') {
|
||||||
|
if (init.recycle_url === undefined) {
|
||||||
|
console.warn('未定义回收站地址 init.recycle_url')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (admin.checkAuth('recycle', elem)) {
|
||||||
|
toolbarHtml += '<button class="layui-btn layui-btn-sm layui-bg-orange" data-open="' + init.recycle_url + '" data-title="回收站"><i class="fa fa-recycle"></i> 回收站</button>\n';
|
||||||
|
}
|
||||||
} else if (typeof v === "object") {
|
} else if (typeof v === "object") {
|
||||||
$.each(v, function (ii, vv) {
|
$.each(v, function (ii, vv) {
|
||||||
vv.class = vv.class || '';
|
vv.class = vv.class || '';
|
||||||
@@ -748,8 +756,11 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
var values = value.split(option.imageSplit),
|
var values = value.split(option.imageSplit),
|
||||||
valuesHtml = [];
|
valuesHtml = [];
|
||||||
values.forEach((value, index) => {
|
values.forEach((value, index) => {
|
||||||
valuesHtml.push('<img style="max-width: ' + option.imageWidth + 'px; max-height: ' + option.imageHeight + 'px;" src="' + value + '" data-image="' + title + '">');
|
valuesHtml.push('<img style="max-width: ' + option.imageWidth + 'px; max-height: ' + option.imageHeight + 'px;" class="lazyload" src="/static/common/images/loading.gif" data-src="' + value + '" data-image="' + title + '">');
|
||||||
});
|
});
|
||||||
|
$(function () {
|
||||||
|
$("img.lazyload").lazyload({threshold: 1});
|
||||||
|
})
|
||||||
return valuesHtml.join(option.imageJoin);
|
return valuesHtml.join(option.imageJoin);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -983,7 +994,21 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
},
|
},
|
||||||
listenSort: function (options) {
|
listenSort: function (options) {
|
||||||
table.on('sort(' + options.layFilter + ')', function (obj) {
|
table.on('sort(' + options.layFilter + ')', function (obj) {
|
||||||
let defaultWhere = options.where || {}
|
let defaultWhere = {}
|
||||||
|
$.each(options.cols, function (_, colsV) {
|
||||||
|
let formatFilter = {}
|
||||||
|
let formatOp = {}
|
||||||
|
$.each(colsV, function (i, v) {
|
||||||
|
if (v.field) {
|
||||||
|
if ($('#c-' + v.field).val()) {
|
||||||
|
formatFilter[v.field] = $('#c-' + v.field).val()
|
||||||
|
formatOp[v.field] = v.searchOp || '='
|
||||||
|
defaultWhere['filter'] = JSON.stringify(formatFilter);
|
||||||
|
defaultWhere['op'] = JSON.stringify(formatOp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
let sortWhere = {tableOrder: obj.field + ' ' + obj.type}
|
let sortWhere = {tableOrder: obj.field + ' ' + obj.type}
|
||||||
table.reload(options.id, {
|
table.reload(options.id, {
|
||||||
where: {...defaultWhere, ...sortWhere}
|
where: {...defaultWhere, ...sortWhere}
|
||||||
@@ -1020,8 +1045,9 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
maxmin: true,
|
maxmin: true,
|
||||||
anim: 0,
|
anim: 0,
|
||||||
moveOut: true,
|
moveOut: true,
|
||||||
move: false,
|
shade: 0.3,
|
||||||
shadeClose: shadeClose,
|
shadeClose: shadeClose,
|
||||||
|
scrollbar: false,
|
||||||
before: function () {
|
before: function () {
|
||||||
},
|
},
|
||||||
success: function (layero, index) {
|
success: function (layero, index) {
|
||||||
@@ -1593,7 +1619,7 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
cols: [[
|
cols: [[
|
||||||
{type: selectCheck},
|
{type: selectCheck},
|
||||||
{field: 'id', title: 'ID'},
|
{field: 'id', title: 'ID'},
|
||||||
{field: 'url', minWidth: 80, search: false, title: '图片信息', imageHeight: 40, align: "center", templet: admin.table.image},
|
{field: 'url', minWidth: 80, search: false, title: '图片信息', imageHeight: 30, align: "center", templet: admin.table.image},
|
||||||
{field: 'original_name', width: 150, title: '文件原名', align: "center"},
|
{field: 'original_name', width: 150, title: '文件原名', align: "center"},
|
||||||
{field: 'mime_type', width: 120, title: 'mime类型', align: "center"},
|
{field: 'mime_type', width: 120, title: 'mime类型', align: "center"},
|
||||||
{field: 'create_time', width: 200, title: '创建时间', align: "center", search: 'range'},
|
{field: 'create_time', width: 200, title: '创建时间', align: "center", search: 'range'},
|
||||||
@@ -1767,7 +1793,7 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
layer.open({
|
layer.open({
|
||||||
'title': options?.title || 'AI建议',
|
'title': options?.title || 'AI建议',
|
||||||
type: 1,
|
type: 1,
|
||||||
area: options?.area || ['42%', '60%'],
|
area: options?.area || (admin.checkMobile() ? ['95%', '60%'] : ['50%', '60%']),
|
||||||
shade: options?.shade || 0,
|
shade: options?.shade || 0,
|
||||||
shadeClose: options?.shadeClose || false,
|
shadeClose: options?.shadeClose || false,
|
||||||
scrollbar: options?.scrollbar || false,
|
scrollbar: options?.scrollbar || false,
|
||||||
@@ -1777,11 +1803,23 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
success: function (layero, index) {
|
success: function (layero, index) {
|
||||||
let elem = document.getElementById(id)
|
let elem = document.getElementById(id)
|
||||||
if (options?.stream) {
|
if (options?.stream) {
|
||||||
clearTimeout(aiStreamTimeout)
|
let index = 0;
|
||||||
aiStreamCurrentIndex = 0
|
let lastTime = performance.now();
|
||||||
setTimeout(() => {
|
const interval = options.interval || 100;
|
||||||
admin.ai.streamOutput(elem, content)
|
|
||||||
}, 300)
|
function typeCharacter(currentTime) {
|
||||||
|
if (index < content.length) {
|
||||||
|
if (currentTime - lastTime >= interval) {
|
||||||
|
elem.innerHTML += content.charAt(index);
|
||||||
|
index++;
|
||||||
|
lastTime = currentTime;
|
||||||
|
elem.scrollIntoView({behavior: "smooth", block: "end"});
|
||||||
|
}
|
||||||
|
requestAnimationFrame(typeCharacter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(typeCharacter);
|
||||||
} else {
|
} else {
|
||||||
content = content.replace(/\r\n/g, '<br>').replace(/\n/g, '<br>')
|
content = content.replace(/\r\n/g, '<br>').replace(/\n/g, '<br>')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -1794,28 +1832,8 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
streamOutput: function (dom, htmlContent) {
|
|
||||||
const chunkSize = 1;
|
|
||||||
let length = htmlContent.length;
|
|
||||||
if (aiStreamCurrentIndex < length) {
|
|
||||||
const endIndex = Math.min(aiStreamCurrentIndex + chunkSize, length);
|
|
||||||
const chunk = htmlContent.slice(aiStreamCurrentIndex, endIndex);
|
|
||||||
const tempDiv = document.createElement('div');
|
|
||||||
tempDiv.innerHTML = chunk;
|
|
||||||
while (tempDiv.firstChild) {
|
|
||||||
dom.appendChild(tempDiv.firstChild);
|
|
||||||
}
|
|
||||||
aiStreamCurrentIndex = endIndex;
|
|
||||||
aiStreamTimeout = setTimeout(() => {
|
|
||||||
admin.ai.streamOutput(dom, htmlContent);
|
|
||||||
dom.scrollIntoView({behavior: "smooth", block: "end"});
|
|
||||||
}, 60);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
var aiStreamCurrentIndex = 0;
|
|
||||||
var aiStreamTimeout = null;
|
|
||||||
|
|
||||||
return admin;
|
return admin;
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
public/static/plugs/lazyload/lazyload.min.js
vendored
Normal file
2
public/static/plugs/lazyload/lazyload.min.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/*! Lazy Load 2.0.0-rc.2 - MIT license - Copyright 2007-2019 Mika Tuupola */
|
||||||
|
!function(t,e){"object"==typeof exports?module.exports=e(t):"function"==typeof define&&define.amd?define([],e):t.LazyLoad=e(t)}("undefined"!=typeof global?global:this.window||this.global,function(t){"use strict";function e(t,e){this.settings=s(r,e||{}),this.images=t||document.querySelectorAll(this.settings.selector),this.observer=null,this.init()}"function"==typeof define&&define.amd&&(t=window);const r={src:"data-src",srcset:"data-srcset",selector:".lazyload",root:null,rootMargin:"0px",threshold:0},s=function(){let t={},e=!1,r=0,o=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(e=arguments[0],r++);for(;r<o;r++)!function(r){for(let o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e&&"[object Object]"===Object.prototype.toString.call(r[o])?t[o]=s(!0,t[o],r[o]):t[o]=r[o])}(arguments[r]);return t};if(e.prototype={init:function(){if(!t.IntersectionObserver)return void this.loadImages();let e=this,r={root:this.settings.root,rootMargin:this.settings.rootMargin,threshold:[this.settings.threshold]};this.observer=new IntersectionObserver(function(t){Array.prototype.forEach.call(t,function(t){if(t.isIntersecting){e.observer.unobserve(t.target);let r=t.target.getAttribute(e.settings.src),s=t.target.getAttribute(e.settings.srcset);"img"===t.target.tagName.toLowerCase()?(r&&(t.target.src=r),s&&(t.target.srcset=s)):t.target.style.backgroundImage="url("+r+")"}})},r),Array.prototype.forEach.call(this.images,function(t){e.observer.observe(t)})},loadAndDestroy:function(){this.settings&&(this.loadImages(),this.destroy())},loadImages:function(){if(!this.settings)return;let t=this;Array.prototype.forEach.call(this.images,function(e){let r=e.getAttribute(t.settings.src),s=e.getAttribute(t.settings.srcset);"img"===e.tagName.toLowerCase()?(r&&(e.src=r),s&&(e.srcset=s)):e.style.backgroundImage="url('"+r+"')"})},destroy:function(){this.settings&&(this.observer.disconnect(),this.settings=null)}},t.lazyload=function(t,r){return new e(t,r)},t.jQuery){const r=t.jQuery;r.fn.lazyload=function(t){return t=t||{},t.attribute=t.attribute||"data-src",new e(r.makeArray(this),t),this}}return e});
|
||||||
Reference in New Issue
Block a user