Dcat知识点

一、Dcat Admin列表页增加列表切换功能**在这里插入图片描述

第一步
增加tab选项卡。并且给每个选项卡设置链接,代码如下:

   $grid->header(function () {
        $tab = Tab::make();
        
        $tab->addLink('所有客户', '?source_id=0',true);
        $tab->addLink('我的客户', '?source_id=1');
        $tab->addLink('分享给我', '?source_id=2');
        return $tab;
    });

看到上面的代码,大家应该知道什么意思了。通过浏览器的参数来判断选项卡和查询条件。
现在我们可以试着访问

http://网址/xxx?source_id=0
http://网址/xxx?source_id=1
http://网址/xxx?source_id=2

页面的确是重新渲染了。

然后现在我们只需要获取浏览器的参数,然后判断不同的查询条件就可以。代码如下

构造方法获取浏览器参数
   public function __construct(Request $request)
    {
        $this->source_id = $request->source_id;
        return $this;
    }
然后在列表方法里使用
 if ($this->source_id == 0) {
                $grid->model()->where(查询条件1);
            } elseif ($this->source_id == 2) {
               $grid->model()->where(查询条件2);
            } else {
                $grid->model()->where(其他查询);
            }

基本已经完成了。

我们还需要完善一下选项卡的默认显示选项,加个判断即可
$grid->header(function () {
                $tab = Tab::make();

                $tab->addLink('我的客户', '?source_id=1',$this->source_id==1 ? true : false);
                $tab->addLink('分享给我', '?source_id=2',$this->source_id==2 ? true : false);
                $tab->addLink('公海客户', '?source_id=3',$this->source_id==3 ? true : false);
                return $tab;
            });

二、Dcat Admin新增个人信息字段

在这里插入图片描述

把扩展中的管理员模型复制到models:
<?php

namespace App\Models;

use Dcat\Admin\Models\Administrator as AdminUser;

class Administrator extends AdminUser
{
public function timer()
{
return $this->belongsTo(Department::class);
}
}

新建迁移文件

php artisan make:migration add_userinfo_admin_users

迁移文件内容:

class AddUserinfoAdminUsers extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('admin_users',function (Blueprint $table) {
            $table->char('mobile')->after('name')->nullable();
            $table->char('qq')->after('name')->nullable();
            $table->string('wechat')->after('name')->nullable();
            $table->date('birthday')->after('name')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('admin_users', function (Blueprint $table) {
            $table->dropColumn('mobile');
            $table->dropColumn('qq');
            $table->dropColumn('wechat');
            $table->dropColumn('birthday');
        });
    }
}

执行迁移

php artisan migrate

找到以下文件

vendor\dcat\laravel-admin\src\Http\Controllers\AuthController.php

增加以下字段

           $form->mobile('mobile', trans('admin.mobile'))->required();
            $form->text('qq', trans('admin.qq'));
            $form->text('wechat', trans('admin.wechat'));
            $form->date('birthday', trans('admin.birthday'));

三、让Laravel应用默认直接访问Dcat Admin的办法

找到routes\web.php修改为

Route::redirect('/', '/admin');

s://wyz.xyz/d/71-dact-admin-100)

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值