这里没有layui知识的小伙伴会有一个疑问,页面中的数据和按钮是怎么出来的,上章定义路由的过程中,每一个路由都需要一个对应的js文件,这里的表单和按钮就是在哪里设置的,内容如下:
- define(["jquery", "easy-admin"], function ($, ea) {
-
- var init = {
- table_elem: '#currentTable',
- table_render_id: 'currentTableRenderId',
- index_url: 'mall.goodsone/index',
- add_url: 'mall.goodsone/add',
- edit_url: 'mall.goodsone/edit',
- delete_url: 'mall.goodsone/delete',
- export_url: 'mall.goodsone/export',
- modify_url: 'mall.goodsone/modify',
- stock_url: 'mall.goodsone/stock',
- };
-
- var Controller = {
-
- index: function () {
- ea.table.render({
- init: init,
- toolbar: ['refresh',
- [{
- text: '添加',
- url: init.add_url,
- method: 'open',
- auth: 'add',
- class: 'layui-btn layui-btn-normal layui-btn-sm',
- icon: 'fa fa-plus ',
- extend: 'data-full="true"',
- }],
- 'delete', 'export'],
- cols: [[
- {type: "checkbox"},
- {field: 'id', width: 80, title: 'ID'},
- {field: 'sort', width: 80, title: '排序', edit: 'text'},
- {field: 'cate.title', minWidth: 80, title: '商品分类'},
- {field: 'title', minWidth: 80, title: '商品名称'},
- {field: 'logo', minWidth: 80, title: '分类图片', search: false, templet: ea.table.image},
- {field: 'market_price', width: 100, title: '市场价', templet: ea.table.price},
- {field: 'discount_price', width: 100, title: '折扣价', templet: ea.table.price},
- {field: 'total_stock', width: 100, title: '库存统计'},
- {field: 'stock', width: 100, title: '剩余库存'},
- {field: 'virtual_sales', width: 100, title: '虚拟销量'},
- {field: 'sales', width: 80, title: '销量'},
- {field: 'status', title: '状态', width: 85, search: 'select',selectList: {0: '禁用', 1: '启用'}, templet: ea.table.switch},
- {field: 'create_time', minWidth: 80, title: '创建时间'},
- {
- width: 250,
- title: '操作',
- templet: ea.table.tool,
- operat: [
- [{
- text: '编辑',
- url: init.edit_url,
- method: 'open',
- auth: 'edit',
- class: 'layui-btn layui-btn-xs layui-btn-success',
- extend: 'data-full="true"',
- },
- // {
- // text: '入库',
- // url: init.stock_url,
- // method: 'open',
- // auth: 'stock',
- // class: 'layui-btn layui-btn-xs layui-btn-normal',
- // }
- ],
- 'delete']
- }
- ]],
- });
-
- ea.listen();
- },
- add: function () {
- ea.listen();
- },
- edit: function () {
- ea.listen();
- },
- stock: function () {
- ea.listen();
- },
- };
- return Controller;
- });
上方的代码大家可以清晰的看到各个增删查改的路由,直接照抄即可,layui大佬可以直接根据项目来修改,而对应的路由代码是放在controller层,代码如下大家而可以参考:
- <?php
-
-
- namespace app\admin\controller\mall;
-
-
- use app\admin\model\MallGoodsOne;
- use app\admin\traits\Curd;
- use app\common\controller\AdminController;
- use EasyAdmin\annotation\ControllerAnnotation;
- use EasyAdmin\annotation\NodeAnotation;
- use think\Facade\Db;
- use think\App;
-
- /**
- * Class Goods
- * @package app\admin\controller\mall
- * @ControllerAnnotation(title="商城商品管理")
- */
- class GoodsOne extends AdminController
- {
-
- use Curd;
-
- protected $relationSearch = true;
-
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->model = new MallGoodsOne();
- }
-
- /**
- * @NodeAnotation(title="列表")
- */
- public function index()
- {
- //var_dump($this->request->isAjax());exit();
- if ($this->request->isAjax()) {
- if (input('selectFields')) {
- return $this->selectList();
- }
- list($page, $limit, $where) = $this->buildTableParames();
- $count = $this->model
- ->withJoin('cate', 'LEFT')
- ->where($where)
- ->count();
- $list = $this->model
- ->withJoin('cate', 'LEFT')
- ->where($where)
- ->page($page, $limit)
- ->order($this->sort)
- ->select();
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'count' => $count,
- 'data' => $list,
- ];
- return json($data);
- }
- return $this->fetch();
- }
- }