第一步、建实体表
drop table fa_adminext;CREATE TABLE `fa_adminext` ( `id` int(10) UNSIGNED NOT NULL COMMENT 'ID', `adminid` int(10) UNSIGNED NOT NULL COMMENT 'ADMINID', `nickname` varchar(50) DEFAULT NULL COMMENT '昵称', `email` varchar(100) DEFAULT '' COMMENT '外部邮箱', `mobile` varchar(11) DEFAULT '' COMMENT '手机号码', `weixh` varchar(50) DEFAULT '' COMMENT '微信号码', `qqh` varchar(50) DEFAULT '' COMMENT 'QQ号码', `gender` enum('男','女','未知') DEFAULT '未知' COMMENT '性别', `birthday` date DEFAULT NULL COMMENT '出生日期', `bzcontent` text COMMENT '备注', `prevtime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '上次登录时间', `logintime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '登录时间', `loginip` varchar(50) NOT NULL DEFAULT '' COMMENT '登录IP', `joinip` varchar(50) NOT NULL DEFAULT '' COMMENT '加入IP', `jointime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '加入时间', `czy` varchar(50) NOT NULL COMMENT '操作员', `createtime` int(10) UNSIGNED DEFAULT '0' COMMENT '创建时间', `updatetime` int(10) UNSIGNED DEFAULT '0' COMMENT '更新时间', `status` enum('normal','hidden') NOT NULL DEFAULT 'normal' COMMENT '状态', `state` enum('0','1','2') NOT NULL DEFAULT '1' COMMENT '状态值:0=禁用,1=正常,2=推荐', `weigh` int(11) NOT NULL DEFAULT '0' COMMENT '权重') ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='个人扩展信息';ALTER TABLE `fa_adminext` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `adminid` (`adminid`);ALTER TABLE `fa_adminext` MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID', AUTO_INCREMENT=1;
第二步、创建控制器、菜单
php think crud -t adminext -c adminextphp think menu -c adminext
第三步,精雕细琢
1、修改时默认IP
fastadminapplicationadmincontrollerAdminext.phppublic function edit($ids = NULL) { $loginip = request()->ip(); $this->view->assign("setloginip", $loginip); return parent::edit($ids); }C:wampwwwfastadminapplicationadminviewadminextedit.html <input id="c-joinip" data-rule="required" class="form-control" name="row[joinip]" type="text" value="{$row.joinip}"> change <input id="c-loginip" data-rule="required" class="form-control" name="row[loginip]" type="text" value="{$setloginip}">
2.调整菜单、加权限
3.初始化表格
fastadmin/public/assets/js/backend|adminext.js table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'weigh', strictSearch:false, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'adminid', title: __('Adminid')}, {field: 'nickname', title: __('Nickname'),operate: 'LIKE %...%'}, {field: 'email', title: __('Email'), visible:false,operate: 'LIKE %...%'}, {field: 'mobile', title: __('Mobile'), operate: 'LIKE %...%'}, {field: 'weixh', title: __('Weixh'), visible:false,operate: 'LIKE %...%'}, {field: 'qqh', title: __('Qqh'), visible:false,operate: 'LIKE %...%'}, {field: 'gender_text', title: __('Gender'), visible:false, operate:false}, {field: 'birthday', title: __('Birthday'),visible:false, formatter: Table.api.formatter.date, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'}, {field: 'prevtime', title: __('Prevtime'), formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'}, {field: 'logintime', title: __('Logintime'), visible:false, formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'}, {field: 'loginip', title: __('Loginip')}, {field: 'joinip', title: __('Joinip'),visible:false}, {field: 'jointime', title: __('Jointime'), visible:false, formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'}, {field: 'czy', title: __('Czy'),visible:false, operate: 'LIKE %...%'}, {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime,visible:false,operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'}, {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime,visible:false,operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'}, {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {'normal': __('Normal'), 'hidden': __('Hidden')}, style: 'min-width:100px;'}, {field: 'state_text', title: __('State'), operate:false}, {field: 'weigh', title: __('Weigh'),visible:false,operate: false}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] });
4.调整快速查询字段
fastadminapplicationadmincontrollerAdminext.phpprotected $searchFields = 'id,adminid,nickname,mobile';
5.操作员默认显示
fastadminapplicationadminviewadminextedit.html
改两处readonly="readonly",value="{$admin.username}"
<input id="c-czy" data-rule="required" readonly="readonly" class="form-control" name="row[czy]" type="text" value="{$admin.username}">Loginip value="{$setloginip}">
6.修改不可改文本框
fastadminapplicationadminviewadminextedit.htmlreadonly="readonly"
7,不允许在本控制器下直接新增
fastadmin/public/assets/js/backend|adminext.jsadd_url: 'adminext/add',
置为空
add_url: '',
del_url: 'adminext/del',
置为空
del_url: '',
8.修改显示按钮
fastadminapplicationadminviewadminextindex.html{:build_toolbar()}
置为
{:build_toolbar('refresh,edit')}
9.新增联动控制
fastadminapplicationadmincontrollerauthAdmin.phpuse thinkRequest;use appadminmodelAdminext;use thinkSession;use thinkDb;
/** * 添加 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $params['salt'] = Random::alnum(); $params['password'] = md5(md5($params['password']) . $params['salt']); $params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。 $admin = $this->model->create($params); $group = $this->request->post("group/a"); //过滤不允许的组别,避免越权 $group = array_intersect($this->childrenGroupIds, $group); $dataset = []; foreach ($group as $value) { $dataset[] = ['uid' => $admin->id, 'group_id' => $value]; } model('AuthGroupAccess')->saveAll($dataset); $adminext = new Adminext; $adminext->adminid = $admin->id; $adminext->nickname = $admin->nickname; $adminext->gender = '未知'; $adminext->prevtime = ''; $adminext->logintime = ''; $adminext->jointime = time(); $joinip = request()->ip(); $adminext->joinip = $joinip; $sysadmin=Session::get("admin"); $adminext->czy = $sysadmin["username"]; $adminext->save(); $this->success(); } $this->error(); } return $this->view->fetch(); }public function syncadminext($adminid,$nickname){ $adminext = new Adminext; $adminext->adminid = $adminid; $adminext->nickname = $nickname; $adminext->gender = '未知'; $adminext->birthday = 'thinkphp@qq.com'; $joinip = request()->ip(); $adminext->joinip = $joinip; $adminext->save(); }
10.修改联动控制
//同步更新adminext表model('Adminext')->where('adminid', $row->id)->update(["nickname"=>$row->nickname]);
11.删除联动控制
//同步删除adminext表model('Adminext')->where('adminid', 'in', $deleteIds)->delete();
12.登陆失败超过3次,禁用10分钟
fastadminapplicationadminlangzh-cnindex.php'Username or password is incorrect' => '用户名或密码不正确', 'userpass3' => '登陆失败超过3次,禁用10分钟',
13.短信验证码
C:wampwwwfastadminapplicationadminlangzh-cn.php'Password' => '密码', 'Yzm' => '验证码',fastadminpublicassetslibsnice-validatordistlocalzh-CN.js,password: [/^[S]{6,16}$/, "请填写6-16位字符,不能包含空格"] ,yzm: [/^[S]{6,6}$/, "请填写6位验证码,不能包含空格"]主要修改这4个文件C:wampwwwfastadminapplicationadmincontrollerIndex.phpC:wampwwwfastadminapplicationadminlibraryAuth.phpC:wampwwwfastadminapplicationcommoncontrollerBackend.phpC:wampwwwfastadminapplicationadminviewindexlogin.html
14.替换右侧按钮图标
C:wampwwwfastadminpublicassetslibsfont-awesomecssfont-awesome.css fa-refresh
15.替换右侧按钮样式
C:wampwwwfastadminpublicassetslibsjspdfexamplesbootstrapcssbootstrap.css.btn-info
希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, Fastadmin, ClassCMS, LeCMS, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。