作者 景琛

学生分数维度模块

  1 +<?php
  2 +
  3 +namespace app\admin\controller;
  4 +
  5 +use app\common\controller\Backend;
  6 +
  7 +/**
  8 + *
  9 + *
  10 + * @icon fa fa-circle-o
  11 + */
  12 +class RadarScore extends Backend
  13 +{
  14 +
  15 + /**
  16 + * RadarScore模型对象
  17 + * @var \app\admin\model\RadarScore
  18 + */
  19 + protected $model = null;
  20 +
  21 + public function _initialize()
  22 + {
  23 + parent::_initialize();
  24 + $this->model = new \app\admin\model\RadarScore;
  25 +
  26 + }
  27 +
  28 +
  29 +
  30 + /**
  31 + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  32 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  33 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  34 + */
  35 +
  36 +
  37 + /**
  38 + * 查看
  39 + */
  40 + public function index()
  41 + {
  42 + //当前是否为关联查询
  43 + $this->relationSearch = true;
  44 + //设置过滤方法
  45 + $this->request->filter(['strip_tags', 'trim']);
  46 + if ($this->request->isAjax()) {
  47 + //如果发送的来源是Selectpage,则转发到Selectpage
  48 + if ($this->request->request('keyField')) {
  49 + return $this->selectpage();
  50 + }
  51 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  52 +
  53 + $list = $this->model
  54 + ->with(['study','campus','radar'])
  55 + ->where($where)
  56 + ->order($sort, $order)
  57 + ->paginate($limit);
  58 +
  59 + foreach ($list as $row) {
  60 +
  61 + $row->getRelation('study')->visible(['name']);
  62 + $row->getRelation('campus')->visible(['title']);
  63 + $row->getRelation('radar')->visible(['title']);
  64 + }
  65 +
  66 + $result = array("total" => $list->total(), "rows" => $list->items());
  67 +
  68 + return json($result);
  69 + }
  70 + return $this->view->fetch();
  71 + }
  72 +
  73 +}
  1 +<?php
  2 +
  3 +return [
  4 + 'Id' => 'ID',
  5 + 'Study_id' => '学生ID',
  6 + 'Campus_id' => '界次ID',
  7 + 'Radar_id' => '维度ID',
  8 + 'Score' => '维度所获分数',
  9 + 'Createtime' => '创建时间',
  10 + 'Updatetime' => '更新时间',
  11 + 'Study.name' => '姓名',
  12 + 'Campus.title' => '校区名称',
  13 + 'Radar.title' => '维度名称'
  14 +];
  1 +<?php
  2 +
  3 +namespace app\admin\model;
  4 +
  5 +use think\Model;
  6 +
  7 +
  8 +class RadarScore extends Model
  9 +{
  10 +
  11 +
  12 +
  13 +
  14 +
  15 + // 表名
  16 + protected $name = 'radar_score';
  17 +
  18 + // 自动写入时间戳字段
  19 + protected $autoWriteTimestamp = 'integer';
  20 +
  21 + // 定义时间戳字段名
  22 + protected $createTime = 'createtime';
  23 + protected $updateTime = 'updatetime';
  24 + protected $deleteTime = false;
  25 +
  26 + // 追加属性
  27 + protected $append = [
  28 +
  29 + ];
  30 +
  31 +
  32 +
  33 +
  34 +
  35 +
  36 +
  37 +
  38 +
  39 +
  40 + public function study()
  41 + {
  42 + return $this->belongsTo('Study', 'study_id', 'id', [], 'LEFT')->setEagerlyType(0);
  43 + }
  44 +
  45 +
  46 + public function campus()
  47 + {
  48 + return $this->belongsTo('Campus', 'campus_id', 'id', [], 'LEFT')->setEagerlyType(0);
  49 + }
  50 +
  51 +
  52 + public function radar()
  53 + {
  54 + return $this->belongsTo('Radar', 'radar_id', 'id', [], 'LEFT')->setEagerlyType(0);
  55 + }
  56 +}
  1 +<?php
  2 +
  3 +namespace app\admin\validate;
  4 +
  5 +use think\Validate;
  6 +
  7 +class RadarScore extends Validate
  8 +{
  9 + /**
  10 + * 验证规则
  11 + */
  12 + protected $rule = [
  13 + ];
  14 + /**
  15 + * 提示消息
  16 + */
  17 + protected $message = [
  18 + ];
  19 + /**
  20 + * 验证场景
  21 + */
  22 + protected $scene = [
  23 + 'add' => [],
  24 + 'edit' => [],
  25 + ];
  26 +
  27 +}
  1 +<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Study_id')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-study_id" data-rule="required" data-source="study/index" class="form-control selectpage" name="row[study_id]" type="text" value="">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('Campus_id')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-campus_id" data-rule="required" data-source="campus/index" data-field="title" class="form-control selectpage" name="row[campus_id]" type="text" value="">
  13 + </div>
  14 + </div>
  15 + <div class="form-group">
  16 + <label class="control-label col-xs-12 col-sm-2">{:__('Radar_id')}:</label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <input id="c-radar_id" data-rule="required" data-source="radar/index" data-field="title" class="form-control selectpage" name="row[radar_id]" type="text" value="">
  19 + </div>
  20 + </div>
  21 + <div class="form-group">
  22 + <label class="control-label col-xs-12 col-sm-2">{:__('Score')}:</label>
  23 + <div class="col-xs-12 col-sm-8">
  24 + <input id="c-score" class="form-control" step="0.01" name="row[score]" type="number">
  25 + </div>
  26 + </div>
  27 + <div class="form-group layer-footer">
  28 + <label class="control-label col-xs-12 col-sm-2"></label>
  29 + <div class="col-xs-12 col-sm-8">
  30 + <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
  31 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  32 + </div>
  33 + </div>
  34 +</form>
  1 +<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Study_id')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-study_id" data-rule="required" data-source="study/index" class="form-control selectpage" name="row[study_id]" type="text" value="{$row.study_id|htmlentities}">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('Campus_id')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-campus_id" data-rule="required" data-source="campus/index" data-field="title" class="form-control selectpage" name="row[campus_id]" type="text" value="{$row.campus_id|htmlentities}">
  13 + </div>
  14 + </div>
  15 + <div class="form-group">
  16 + <label class="control-label col-xs-12 col-sm-2">{:__('Radar_id')}:</label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <input id="c-radar_id" data-rule="required" data-source="radar/index" data-field="title" class="form-control selectpage" name="row[radar_id]" type="text" value="{$row.radar_id|htmlentities}">
  19 + </div>
  20 + </div>
  21 + <div class="form-group">
  22 + <label class="control-label col-xs-12 col-sm-2">{:__('Score')}:</label>
  23 + <div class="col-xs-12 col-sm-8">
  24 + <input id="c-score" class="form-control" step="0.01" name="row[score]" type="number" value="{$row.score|htmlentities}">
  25 + </div>
  26 + </div>
  27 + <div class="form-group layer-footer">
  28 + <label class="control-label col-xs-12 col-sm-2"></label>
  29 + <div class="col-xs-12 col-sm-8">
  30 + <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
  31 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  32 + </div>
  33 + </div>
  34 +</form>
  1 +<div class="panel panel-default panel-intro">
  2 + {:build_heading()}
  3 +
  4 + <div class="panel-body">
  5 + <div id="myTabContent" class="tab-content">
  6 + <div class="tab-pane fade active in" id="one">
  7 + <div class="widget-body no-padding">
  8 + <div id="toolbar" class="toolbar">
  9 + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  10 + <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('radar_score/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
  11 + <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('radar_score/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
  12 + <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('radar_score/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
  13 +
  14 +
  15 + <div class="dropdown btn-group {:$auth->check('radar_score/multi')?'':'hide'}">
  16 + <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
  17 + <ul class="dropdown-menu text-left" role="menu">
  18 + <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
  19 + <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
  20 + </ul>
  21 + </div>
  22 +
  23 +
  24 + </div>
  25 + <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
  26 + data-operate-edit="{:$auth->check('radar_score/edit')}"
  27 + data-operate-del="{:$auth->check('radar_score/del')}"
  28 + width="100%">
  29 + </table>
  30 + </div>
  31 + </div>
  32 +
  33 + </div>
  34 + </div>
  35 +</div>
  1 +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2 +
  3 + var Controller = {
  4 + index: function () {
  5 + // 初始化表格参数配置
  6 + Table.api.init({
  7 + extend: {
  8 + index_url: 'radar_score/index' + location.search,
  9 + add_url: 'radar_score/add',
  10 + edit_url: 'radar_score/edit',
  11 + del_url: 'radar_score/del',
  12 + multi_url: 'radar_score/multi',
  13 + import_url: 'radar_score/import',
  14 + table: 'radar_score',
  15 + }
  16 + });
  17 +
  18 + var table = $("#table");
  19 +
  20 + // 初始化表格
  21 + table.bootstrapTable({
  22 + url: $.fn.bootstrapTable.defaults.extend.index_url,
  23 + pk: 'id',
  24 + sortName: 'id',
  25 + columns: [
  26 + [
  27 + {checkbox: true},
  28 + {field: 'id', title: __('Id')},
  29 + //{field: 'study_id', title: __('Study_id')},
  30 + //{field: 'campus_id', title: __('Campus_id')},
  31 + //{field: 'radar_id', title: __('Radar_id')},
  32 + {field: 'campus.title', title: __('Campus.title'), operate: 'LIKE'},
  33 + {field: 'radar.title', title: __('Radar.title'), operate: 'LIKE'},
  34 + {field: 'study.name', title: __('Study.name'), operate: 'LIKE'},
  35 + {field: 'score', title: __('Score'), operate:'BETWEEN'},
  36 + {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  37 + {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  38 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  39 + ]
  40 + ]
  41 + });
  42 +
  43 + // 为表格绑定事件
  44 + Table.api.bindevent(table);
  45 + },
  46 + add: function () {
  47 + Controller.api.bindevent();
  48 + },
  49 + edit: function () {
  50 + Controller.api.bindevent();
  51 + },
  52 + api: {
  53 + bindevent: function () {
  54 + Form.api.bindevent($("form[role=form]"));
  55 + }
  56 + }
  57 + };
  58 + return Controller;
  59 +});