正在显示
66 个修改的文件
包含
4764 行增加
和
0 行删除
addons/command/Command.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\command; | ||
4 | + | ||
5 | +use app\common\library\Menu; | ||
6 | +use think\Addons; | ||
7 | + | ||
8 | +/** | ||
9 | + * 在线命令插件 | ||
10 | + */ | ||
11 | +class Command extends Addons | ||
12 | +{ | ||
13 | + | ||
14 | + /** | ||
15 | + * 插件安装方法 | ||
16 | + * @return bool | ||
17 | + */ | ||
18 | + public function install() | ||
19 | + { | ||
20 | + $menu = [ | ||
21 | + [ | ||
22 | + 'name' => 'command', | ||
23 | + 'title' => '在线命令管理', | ||
24 | + 'icon' => 'fa fa-terminal', | ||
25 | + 'sublist' => [ | ||
26 | + ['name' => 'command/index', 'title' => '查看'], | ||
27 | + ['name' => 'command/add', 'title' => '添加'], | ||
28 | + ['name' => 'command/detail', 'title' => '详情'], | ||
29 | + ['name' => 'command/execute', 'title' => '运行'], | ||
30 | + ['name' => 'command/del', 'title' => '删除'], | ||
31 | + ['name' => 'command/multi', 'title' => '批量更新'], | ||
32 | + ] | ||
33 | + ] | ||
34 | + ]; | ||
35 | + Menu::create($menu); | ||
36 | + return true; | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * 插件卸载方法 | ||
41 | + * @return bool | ||
42 | + */ | ||
43 | + public function uninstall() | ||
44 | + { | ||
45 | + Menu::delete('command'); | ||
46 | + return true; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * 插件启用方法 | ||
51 | + * @return bool | ||
52 | + */ | ||
53 | + public function enable() | ||
54 | + { | ||
55 | + Menu::enable('command'); | ||
56 | + return true; | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * 插件禁用方法 | ||
61 | + * @return bool | ||
62 | + */ | ||
63 | + public function disable() | ||
64 | + { | ||
65 | + Menu::disable('command'); | ||
66 | + return true; | ||
67 | + } | ||
68 | + | ||
69 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Config; | ||
7 | +use think\console\Input; | ||
8 | +use think\Db; | ||
9 | +use think\Exception; | ||
10 | + | ||
11 | +/** | ||
12 | + * 在线命令管理 | ||
13 | + * | ||
14 | + * @icon fa fa-circle-o | ||
15 | + */ | ||
16 | +class Command extends Backend | ||
17 | +{ | ||
18 | + | ||
19 | + /** | ||
20 | + * Command模型对象 | ||
21 | + */ | ||
22 | + protected $model = null; | ||
23 | + protected $noNeedRight = ['get_controller_list', 'get_field_list']; | ||
24 | + | ||
25 | + public function _initialize() | ||
26 | + { | ||
27 | + parent::_initialize(); | ||
28 | + $this->model = model('Command'); | ||
29 | + $this->view->assign("statusList", $this->model->getStatusList()); | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * 添加 | ||
34 | + */ | ||
35 | + public function add() | ||
36 | + { | ||
37 | + | ||
38 | + $tableList = []; | ||
39 | + $list = \think\Db::query("SHOW TABLES"); | ||
40 | + foreach ($list as $key => $row) { | ||
41 | + $tableList[reset($row)] = reset($row); | ||
42 | + } | ||
43 | + | ||
44 | + $this->view->assign("tableList", $tableList); | ||
45 | + return $this->view->fetch(); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * 获取字段列表 | ||
50 | + * @internal | ||
51 | + */ | ||
52 | + public function get_field_list() | ||
53 | + { | ||
54 | + $dbname = Config::get('database.database'); | ||
55 | + $prefix = Config::get('database.prefix'); | ||
56 | + $table = $this->request->request('table'); | ||
57 | + //从数据库中获取表字段信息 | ||
58 | + $sql = "SELECT * FROM `information_schema`.`columns` " | ||
59 | + . "WHERE TABLE_SCHEMA = ? AND table_name = ? " | ||
60 | + . "ORDER BY ORDINAL_POSITION"; | ||
61 | + //加载主表的列 | ||
62 | + $columnList = Db::query($sql, [$dbname, $table]); | ||
63 | + $fieldlist = []; | ||
64 | + foreach ($columnList as $index => $item) { | ||
65 | + $fieldlist[] = $item['COLUMN_NAME']; | ||
66 | + } | ||
67 | + $this->success("", null, ['fieldlist' => $fieldlist]); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * 获取控制器列表 | ||
72 | + * @internal | ||
73 | + */ | ||
74 | + public function get_controller_list() | ||
75 | + { | ||
76 | + //搜索关键词,客户端输入以空格分开,这里接收为数组 | ||
77 | + $word = (array)$this->request->request("q_word/a"); | ||
78 | + $word = implode('', $word); | ||
79 | + | ||
80 | + $adminPath = dirname(__DIR__) . DS; | ||
81 | + $controllerDir = $adminPath . 'controller' . DS; | ||
82 | + $files = new \RecursiveIteratorIterator( | ||
83 | + new \RecursiveDirectoryIterator($controllerDir), \RecursiveIteratorIterator::LEAVES_ONLY | ||
84 | + ); | ||
85 | + $list = []; | ||
86 | + foreach ($files as $name => $file) { | ||
87 | + if (!$file->isDir()) { | ||
88 | + $filePath = $file->getRealPath(); | ||
89 | + $name = str_replace($controllerDir, '', $filePath); | ||
90 | + $name = str_replace(DS, "/", $name); | ||
91 | + if (!preg_match("/(.*)\.php\$/", $name)) { | ||
92 | + continue; | ||
93 | + } | ||
94 | + if (!$word || stripos($name, $word) !== false) { | ||
95 | + $list[] = ['id' => $name, 'name' => $name]; | ||
96 | + } | ||
97 | + } | ||
98 | + } | ||
99 | + $pageNumber = $this->request->request("pageNumber"); | ||
100 | + $pageSize = $this->request->request("pageSize"); | ||
101 | + return json(['list' => array_slice($list, ($pageNumber - 1) * $pageSize, $pageSize), 'total' => count($list)]); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * 详情 | ||
106 | + */ | ||
107 | + public function detail($ids) | ||
108 | + { | ||
109 | + $row = $this->model->get($ids); | ||
110 | + if (!$row) { | ||
111 | + $this->error(__('No Results were found')); | ||
112 | + } | ||
113 | + $this->view->assign("row", $row); | ||
114 | + return $this->view->fetch(); | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * 执行 | ||
119 | + */ | ||
120 | + public function execute($ids) | ||
121 | + { | ||
122 | + $row = $this->model->get($ids); | ||
123 | + if (!$row) { | ||
124 | + $this->error(__('No Results were found')); | ||
125 | + } | ||
126 | + $result = $this->doexecute($row['type'], json_decode($row['params'], true)); | ||
127 | + $this->success("", null, ['result' => $result]); | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * 执行命令 | ||
132 | + */ | ||
133 | + public function command($action = '') | ||
134 | + { | ||
135 | + $commandtype = $this->request->request("commandtype"); | ||
136 | + $params = $this->request->request(); | ||
137 | + $allowfields = [ | ||
138 | + 'crud' => 'table,controller,model,fields,force,local,delete,menu', | ||
139 | + 'menu' => 'controller,delete', | ||
140 | + 'min' => 'module,resource,optimize', | ||
141 | + 'api' => 'url,module,output,template,force,title,author,class,language', | ||
142 | + ]; | ||
143 | + $argv = []; | ||
144 | + $allowfields = isset($allowfields[$commandtype]) ? explode(',', $allowfields[$commandtype]) : []; | ||
145 | + $allowfields = array_filter(array_intersect_key($params, array_flip($allowfields))); | ||
146 | + if (isset($params['local']) && !$params['local']) { | ||
147 | + $allowfields['local'] = $params['local']; | ||
148 | + } else { | ||
149 | + unset($allowfields['local']); | ||
150 | + } | ||
151 | + foreach ($allowfields as $key => $param) { | ||
152 | + $argv[] = "--{$key}=" . (is_array($param) ? implode(',', $param) : $param); | ||
153 | + } | ||
154 | + if ($commandtype == 'crud') { | ||
155 | + $extend = 'setcheckboxsuffix,enumradiosuffix,imagefield,filefield,intdatesuffix,switchsuffix,citysuffix,selectpagesuffix,selectpagessuffix,ignorefields,sortfield,editorsuffix,headingfilterfield'; | ||
156 | + $extendArr = explode(',', $extend); | ||
157 | + foreach ($params as $index => $item) { | ||
158 | + if (in_array($index, $extendArr)) { | ||
159 | + foreach (explode(',', $item) as $key => $value) { | ||
160 | + if ($value) { | ||
161 | + $argv[] = "--{$index}={$value}"; | ||
162 | + } | ||
163 | + } | ||
164 | + } | ||
165 | + } | ||
166 | + $isrelation = (int)$this->request->request('isrelation'); | ||
167 | + if ($isrelation && isset($params['relation'])) { | ||
168 | + foreach ($params['relation'] as $index => $relation) { | ||
169 | + foreach ($relation as $key => $value) { | ||
170 | + $argv[] = "--{$key}=" . (is_array($value) ? implode(',', $value) : $value); | ||
171 | + } | ||
172 | + } | ||
173 | + } | ||
174 | + } else { | ||
175 | + if ($commandtype == 'menu') { | ||
176 | + if (isset($params['allcontroller']) && $params['allcontroller']) { | ||
177 | + $argv[] = "--controller=all-controller"; | ||
178 | + } else { | ||
179 | + foreach (explode(',', $params['controllerfile']) as $index => $param) { | ||
180 | + if ($param) { | ||
181 | + $argv[] = "--controller=" . substr($param, 0, -4); | ||
182 | + } | ||
183 | + } | ||
184 | + } | ||
185 | + } else { | ||
186 | + if ($commandtype == 'min') { | ||
187 | + | ||
188 | + } else { | ||
189 | + if ($commandtype == 'api') { | ||
190 | + | ||
191 | + } else { | ||
192 | + | ||
193 | + } | ||
194 | + } | ||
195 | + } | ||
196 | + } | ||
197 | + if ($action == 'execute') { | ||
198 | + $result = $this->doexecute($commandtype, $argv); | ||
199 | + $this->success("", null, ['result' => $result]); | ||
200 | + } else { | ||
201 | + $this->success("", null, ['command' => "php think {$commandtype} " . implode(' ', $argv)]); | ||
202 | + } | ||
203 | + | ||
204 | + return; | ||
205 | + } | ||
206 | + | ||
207 | + protected function doexecute($commandtype, $argv) | ||
208 | + { | ||
209 | + $commandName = "\\app\\admin\\command\\" . ucfirst($commandtype); | ||
210 | + $input = new Input($argv); | ||
211 | + $output = new \addons\command\library\Output(); | ||
212 | + $command = new $commandName($commandtype); | ||
213 | + $data = [ | ||
214 | + 'type' => $commandtype, | ||
215 | + 'params' => json_encode($argv), | ||
216 | + 'command' => "php think {$commandtype} " . implode(' ', $argv), | ||
217 | + 'executetime' => time(), | ||
218 | + ]; | ||
219 | + $this->model->save($data); | ||
220 | + try { | ||
221 | + $command->run($input, $output); | ||
222 | + $result = implode("\n", $output->getMessage()); | ||
223 | + $this->model->status = 'successed'; | ||
224 | + } catch (Exception $e) { | ||
225 | + $result = implode("\n", $output->getMessage()) . "\n"; | ||
226 | + $result .= $e->getMessage(); | ||
227 | + $this->model->status = 'failured'; | ||
228 | + } | ||
229 | + $result = trim($result); | ||
230 | + $this->model->content = $result; | ||
231 | + $this->model->save(); | ||
232 | + return $result; | ||
233 | + } | ||
234 | + | ||
235 | + | ||
236 | +} |
1 | +<?php | ||
2 | + | ||
3 | +return [ | ||
4 | + 'Id' => 'ID', | ||
5 | + 'Type' => '类型', | ||
6 | + 'Params' => '参数', | ||
7 | + 'Command' => '命令', | ||
8 | + 'Content' => '返回结果', | ||
9 | + 'Executetime' => '执行时间', | ||
10 | + 'Createtime' => '创建时间', | ||
11 | + 'Updatetime' => '更新时间', | ||
12 | + 'Execute again' => '再次执行', | ||
13 | + 'Successed' => '成功', | ||
14 | + 'Failured' => '失败', | ||
15 | + 'Status' => '状态' | ||
16 | +]; |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\model; | ||
4 | + | ||
5 | +use think\Model; | ||
6 | + | ||
7 | +class Command extends Model | ||
8 | +{ | ||
9 | + // 表名 | ||
10 | + protected $name = 'command'; | ||
11 | + | ||
12 | + // 自动写入时间戳字段 | ||
13 | + protected $autoWriteTimestamp = 'int'; | ||
14 | + | ||
15 | + // 定义时间戳字段名 | ||
16 | + protected $createTime = 'createtime'; | ||
17 | + protected $updateTime = 'updatetime'; | ||
18 | + | ||
19 | + // 追加属性 | ||
20 | + protected $append = [ | ||
21 | + 'executetime_text', | ||
22 | + 'type_text', | ||
23 | + 'status_text' | ||
24 | + ]; | ||
25 | + | ||
26 | + | ||
27 | + public function getStatusList() | ||
28 | + { | ||
29 | + return ['successed' => __('Successed'), 'failured' => __('Failured')]; | ||
30 | + } | ||
31 | + | ||
32 | + | ||
33 | + public function getExecutetimeTextAttr($value, $data) | ||
34 | + { | ||
35 | + $value = $value ? $value : $data['executetime']; | ||
36 | + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; | ||
37 | + } | ||
38 | + | ||
39 | + public function getTypeTextAttr($value, $data) | ||
40 | + { | ||
41 | + $value = $value ? $value : $data['type']; | ||
42 | + $list = ['crud' => '一键生成CRUD', 'menu' => '一键生成菜单', 'min' => '一键压缩打包', 'api' => '一键生成文档']; | ||
43 | + return isset($list[$value]) ? $list[$value] : ''; | ||
44 | + } | ||
45 | + | ||
46 | + public function getStatusTextAttr($value, $data) | ||
47 | + { | ||
48 | + $value = $value ? $value : $data['status']; | ||
49 | + $list = $this->getStatusList(); | ||
50 | + return isset($list[$value]) ? $list[$value] : ''; | ||
51 | + } | ||
52 | + | ||
53 | + protected function setExecutetimeAttr($value) | ||
54 | + { | ||
55 | + return $value && !is_numeric($value) ? strtotime($value) : $value; | ||
56 | + } | ||
57 | + | ||
58 | + | ||
59 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\validate; | ||
4 | + | ||
5 | +use think\Validate; | ||
6 | + | ||
7 | +class Command 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 | +<style> | ||
2 | + .relation-item {margin-top:10px;} | ||
3 | + legend {padding-bottom:5px;font-size:14px;font-weight:600;} | ||
4 | + label {font-weight:normal;} | ||
5 | + .form-control{padding:6px 8px;} | ||
6 | + #extend-zone .col-xs-2 {margin-top:10px;padding-right:0;} | ||
7 | + #extend-zone .col-xs-2:nth-child(6n+0) {padding-right:15px;} | ||
8 | +</style> | ||
9 | +<div class="panel panel-default panel-intro"> | ||
10 | + <div class="panel-heading"> | ||
11 | + <ul class="nav nav-tabs"> | ||
12 | + <li class="active"><a href="#crud" data-toggle="tab">{:__('一键生成CRUD')}</a></li> | ||
13 | + <li><a href="#menu" data-toggle="tab">{:__('一键生成菜单')}</a></li> | ||
14 | + <li><a href="#min" data-toggle="tab">{:__('一键压缩打包')}</a></li> | ||
15 | + <li><a href="#api" data-toggle="tab">{:__('一键生成API文档')}</a></li> | ||
16 | + </ul> | ||
17 | + </div> | ||
18 | + <div class="panel-body"> | ||
19 | + <div id="myTabContent" class="tab-content"> | ||
20 | + <div class="tab-pane fade active in" id="crud"> | ||
21 | + <div class="row"> | ||
22 | + <div class="col-xs-12"> | ||
23 | + <form role="form"> | ||
24 | + <input type="hidden" name="commandtype" value="crud" /> | ||
25 | + <div class="form-group"> | ||
26 | + <div class="row"> | ||
27 | + <div class="col-xs-3"> | ||
28 | + <input checked="" name="isrelation" type="hidden" value="0"> | ||
29 | + <label class="control-label" data-toggle="tooltip" title="当前只支持生成1对1关联模型,选中后请配置关联表和字段"> | ||
30 | + <input name="isrelation" type="checkbox" value="1"> | ||
31 | + 关联模型 | ||
32 | + </label> | ||
33 | + </div> | ||
34 | + <div class="col-xs-3"> | ||
35 | + <input checked="" name="local" type="hidden" value="1"> | ||
36 | + <label class="control-label" data-toggle="tooltip" title="默认模型生成在application/admin/model目录下,选中后将生成在application/common/model目录下"> | ||
37 | + <input name="local" type="checkbox" value="0"> 全局模型类 | ||
38 | + </label> | ||
39 | + </div> | ||
40 | + <div class="col-xs-3"> | ||
41 | + <input checked="" name="delete" type="hidden" value="0"> | ||
42 | + <label class="control-label" data-toggle="tooltip" title="删除CRUD生成的相关文件"> | ||
43 | + <input name="delete" type="checkbox" value="1"> 删除模式 | ||
44 | + </label> | ||
45 | + </div> | ||
46 | + <div class="col-xs-3"> | ||
47 | + <input checked="" name="force" type="hidden" value="0"> | ||
48 | + <label class="control-label" data-toggle="tooltip" title="选中后,如果已经存在同名文件将被覆盖。如果是删除将不再提醒"> | ||
49 | + <input name="force" type="checkbox" value="1"> | ||
50 | + 强制覆盖模式 | ||
51 | + </label> | ||
52 | + </div> | ||
53 | + <!-- | ||
54 | + <div class="col-xs-3"> | ||
55 | + <input checked="" name="menu" type="hidden" value="0"> | ||
56 | + <label class="control-label" data-toggle="tooltip" title="选中后,将同时生成后台菜单规则"> | ||
57 | + <input name="menu" type="checkbox" value="1"> | ||
58 | + 生成菜单 | ||
59 | + </label> | ||
60 | + </div> | ||
61 | + --> | ||
62 | + </div> | ||
63 | + </div> | ||
64 | + <div class="form-group"> | ||
65 | + <legend>主表设置</legend> | ||
66 | + <div class="row"> | ||
67 | + <div class="col-xs-3"> | ||
68 | + <label>请选择主表</label> | ||
69 | + {:build_select('table',$tableList,null,['class'=>'form-control selectpicker', 'data-live-search'=>'true']);} | ||
70 | + </div> | ||
71 | + <div class="col-xs-3"> | ||
72 | + <label>自定义控制器名</label> | ||
73 | + <input type="text" class="form-control" name="controller" data-toggle="tooltip" title="默认根据表名自动生成,如果需要放在二级目录请手动填写" placeholder="支持目录层级,以/分隔"> | ||
74 | + </div> | ||
75 | + <div class="col-xs-3"> | ||
76 | + <label>自定义模型名</label> | ||
77 | + <input type="text" class="form-control" name="model" data-toggle="tooltip" title="默认根据表名自动生成" placeholder="不支持目录层级"> | ||
78 | + </div> | ||
79 | + <div class="col-xs-3"> | ||
80 | + <label>请选择显示字段(默认全部)</label> | ||
81 | + <select name="fields[]" id="fields" multiple style="height:30px;" class="form-control selectpicker"></select> | ||
82 | + </div> | ||
83 | + | ||
84 | + </div> | ||
85 | + | ||
86 | + </div> | ||
87 | + | ||
88 | + <div class="form-group hide" id="relation-zone"> | ||
89 | + <legend>关联表设置</legend> | ||
90 | + | ||
91 | + <div class="row" style="margin-top:15px;"> | ||
92 | + <div class="col-xs-12"> | ||
93 | + <a href="javascript:;" class="btn btn-primary btn-sm btn-newrelation" data-index="1">追加关联模型</a> | ||
94 | + </div> | ||
95 | + </div> | ||
96 | + </div> | ||
97 | + | ||
98 | + <hr> | ||
99 | + <div class="form-group" id="extend-zone"> | ||
100 | + <legend>字段识别设置 <span style="font-size:12px;font-weight: normal;">(与之匹配的字段都将生成相应组件)</span></legend> | ||
101 | + <div class="row"> | ||
102 | + <div class="col-xs-2"> | ||
103 | + <label>复选框后缀</label> | ||
104 | + <input type="text" class="form-control" name="setcheckboxsuffix" placeholder="默认为set类型" /> | ||
105 | + </div> | ||
106 | + <div class="col-xs-2"> | ||
107 | + <label>单选框后缀</label> | ||
108 | + <input type="text" class="form-control" name="enumradiosuffix" placeholder="默认为enum类型" /> | ||
109 | + </div> | ||
110 | + <div class="col-xs-2"> | ||
111 | + <label>图片类型后缀</label> | ||
112 | + <input type="text" class="form-control" name="imagefield" placeholder="默认为image,images,avatar,avatars" /> | ||
113 | + </div> | ||
114 | + <div class="col-xs-2"> | ||
115 | + <label>文件类型后缀</label> | ||
116 | + <input type="text" class="form-control" name="filefield" placeholder="默认为file,files" /> | ||
117 | + </div> | ||
118 | + <div class="col-xs-2"> | ||
119 | + <label>日期时间后缀</label> | ||
120 | + <input type="text" class="form-control" name="intdatesuffix" placeholder="默认为time" /> | ||
121 | + </div> | ||
122 | + <div class="col-xs-2"> | ||
123 | + <label>开关后缀</label> | ||
124 | + <input type="text" class="form-control" name="switchsuffix" placeholder="默认为switch" /> | ||
125 | + </div> | ||
126 | + <div class="col-xs-2"> | ||
127 | + <label>城市选择后缀</label> | ||
128 | + <input type="text" class="form-control" name="citysuffix" placeholder="默认为city" /> | ||
129 | + </div> | ||
130 | + <div class="col-xs-2"> | ||
131 | + <label>动态下拉后缀(单)</label> | ||
132 | + <input type="text" class="form-control" name="selectpagesuffix" placeholder="默认为_id" /> | ||
133 | + </div> | ||
134 | + <div class="col-xs-2"> | ||
135 | + <label>动态下拉后缀(多)</label> | ||
136 | + <input type="text" class="form-control" name="selectpagessuffix" placeholder="默认为_ids" /> | ||
137 | + </div> | ||
138 | + <div class="col-xs-2"> | ||
139 | + <label>忽略的字段</label> | ||
140 | + <input type="text" class="form-control" name="ignorefields" placeholder="默认无" /> | ||
141 | + </div> | ||
142 | + <div class="col-xs-2"> | ||
143 | + <label>排序字段</label> | ||
144 | + <input type="text" class="form-control" name="sortfield" placeholder="默认为weigh" /> | ||
145 | + </div> | ||
146 | + <div class="col-xs-2"> | ||
147 | + <label>富文本编辑器</label> | ||
148 | + <input type="text" class="form-control" name="editorsuffix" placeholder="默认为content" /> | ||
149 | + </div> | ||
150 | + <div class="col-xs-2"> | ||
151 | + <label>选项卡过滤字段</label> | ||
152 | + <input type="text" class="form-control" name="headingfilterfield" placeholder="默认为status" /> | ||
153 | + </div> | ||
154 | + | ||
155 | + </div> | ||
156 | + | ||
157 | + </div> | ||
158 | + | ||
159 | + <div class="form-group"> | ||
160 | + <legend>生成命令行</legend> | ||
161 | + <textarea class="form-control" data-toggle="tooltip" title="如果在线执行命令失败,可以将命令复制到命令行进行执行" rel="command" rows="1" placeholder="请点击生成命令行"></textarea> | ||
162 | + </div> | ||
163 | + | ||
164 | + <div class="form-group"> | ||
165 | + <legend>返回结果</legend> | ||
166 | + <textarea class="form-control" rel="result" rows="5" placeholder="请点击立即执行"></textarea> | ||
167 | + </div> | ||
168 | + | ||
169 | + <div class="form-group"> | ||
170 | + <button type="button" class="btn btn-info btn-embossed btn-command">{:__('生成命令行')}</button> | ||
171 | + <button type="button" class="btn btn-success btn-embossed btn-execute">{:__('立即执行')}</button> | ||
172 | + </div> | ||
173 | + | ||
174 | + </form> | ||
175 | + </div> | ||
176 | + </div> | ||
177 | + </div> | ||
178 | + <div class="tab-pane fade" id="menu"> | ||
179 | + <div class="row"> | ||
180 | + <div class="col-xs-12"> | ||
181 | + <form role="form"> | ||
182 | + <input type="hidden" name="commandtype" value="menu" /> | ||
183 | + <div class="form-group"> | ||
184 | + <div class="row"> | ||
185 | + <div class="col-xs-3"> | ||
186 | + <input checked="" name="allcontroller" type="hidden" value="0"> | ||
187 | + <label class="control-label"> | ||
188 | + <input name="allcontroller" data-toggle="collapse" data-target="#controller" type="checkbox" value="1"> 一键生成全部控制器 | ||
189 | + </label> | ||
190 | + </div> | ||
191 | + <div class="col-xs-3"> | ||
192 | + <input checked="" name="delete" type="hidden" value="0"> | ||
193 | + <label class="control-label"> | ||
194 | + <input name="delete" type="checkbox" value="1"> 删除模式 | ||
195 | + </label> | ||
196 | + </div> | ||
197 | + <div class="col-xs-3"> | ||
198 | + <input checked="" name="force" type="hidden" value="0"> | ||
199 | + <label class="control-label"> | ||
200 | + <input name="force" type="checkbox" value="1"> 强制覆盖模式 | ||
201 | + </label> | ||
202 | + </div> | ||
203 | + </div> | ||
204 | + </div> | ||
205 | + | ||
206 | + <div class="form-group in" id="controller"> | ||
207 | + <legend>控制器设置</legend> | ||
208 | + | ||
209 | + <div class="row" style="margin-top:15px;"> | ||
210 | + <div class="col-xs-12"> | ||
211 | + <input type="text" name="controllerfile" class="form-control selectpage" style="width:720px;" data-source="command/get_controller_list" data-multiple="true" name="controller" placeholder="请选择控制器" /> | ||
212 | + </div> | ||
213 | + </div> | ||
214 | + </div> | ||
215 | + | ||
216 | + <div class="form-group"> | ||
217 | + <legend>生成命令行</legend> | ||
218 | + <textarea class="form-control" rel="command" rows="1" placeholder="请点击生成命令行"></textarea> | ||
219 | + </div> | ||
220 | + | ||
221 | + <div class="form-group"> | ||
222 | + <legend>返回结果</legend> | ||
223 | + <textarea class="form-control" rel="result" rows="5" placeholder="请点击立即执行"></textarea> | ||
224 | + </div> | ||
225 | + | ||
226 | + <div class="form-group"> | ||
227 | + <button type="button" class="btn btn-info btn-embossed btn-command">{:__('生成命令行')}</button> | ||
228 | + <button type="button" class="btn btn-success btn-embossed btn-execute">{:__('立即执行')}</button> | ||
229 | + </div> | ||
230 | + | ||
231 | + </form> | ||
232 | + </div> | ||
233 | + </div> | ||
234 | + </div> | ||
235 | + <div class="tab-pane fade" id="min"> | ||
236 | + <div class="row"> | ||
237 | + <div class="col-xs-12"> | ||
238 | + <form role="form"> | ||
239 | + <input type="hidden" name="commandtype" value="min" /> | ||
240 | + <div class="form-group"> | ||
241 | + <legend>基础设置</legend> | ||
242 | + <div class="row"> | ||
243 | + <div class="col-xs-3"> | ||
244 | + <label>请选择压缩模块</label> | ||
245 | + <select name="module" class="form-control selectpicker"> | ||
246 | + <option value="all" selected>全部</option> | ||
247 | + <option value="backend">后台Backend</option> | ||
248 | + <option value="frontend">前台Frontend</option> | ||
249 | + </select> | ||
250 | + </div> | ||
251 | + <div class="col-xs-3"> | ||
252 | + <label>请选择压缩资源</label> | ||
253 | + <select name="resource" class="form-control selectpicker"> | ||
254 | + <option value="all" selected>全部</option> | ||
255 | + <option value="js">JS</option> | ||
256 | + <option value="css">CSS</option> | ||
257 | + </select> | ||
258 | + </div> | ||
259 | + <div class="col-xs-3"> | ||
260 | + <label>请选择压缩模式</label> | ||
261 | + <select name="optimize" class="form-control selectpicker"> | ||
262 | + <option value="">无</option> | ||
263 | + <option value="uglify">uglify</option> | ||
264 | + <option value="closure">closure</option> | ||
265 | + </select> | ||
266 | + </div> | ||
267 | + </div> | ||
268 | + </div> | ||
269 | + | ||
270 | + <div class="form-group in"> | ||
271 | + <legend>控制器设置</legend> | ||
272 | + | ||
273 | + <div class="row" style="margin-top:15px;"> | ||
274 | + <div class="col-xs-12"> | ||
275 | + | ||
276 | + </div> | ||
277 | + </div> | ||
278 | + </div> | ||
279 | + | ||
280 | + <div class="form-group"> | ||
281 | + <legend>生成命令行</legend> | ||
282 | + <textarea class="form-control" rel="command" rows="1" placeholder="请点击生成命令行"></textarea> | ||
283 | + </div> | ||
284 | + | ||
285 | + <div class="form-group"> | ||
286 | + <legend>返回结果</legend> | ||
287 | + <textarea class="form-control" rel="result" rows="5" placeholder="请点击立即执行"></textarea> | ||
288 | + </div> | ||
289 | + | ||
290 | + <div class="form-group"> | ||
291 | + <button type="button" class="btn btn-info btn-embossed btn-command">{:__('生成命令行')}</button> | ||
292 | + <button type="button" class="btn btn-success btn-embossed btn-execute">{:__('立即执行')}</button> | ||
293 | + </div> | ||
294 | + | ||
295 | + </form> | ||
296 | + </div> | ||
297 | + </div> | ||
298 | + </div> | ||
299 | + <div class="tab-pane fade" id="api"> | ||
300 | + <div class="row"> | ||
301 | + <div class="col-xs-12"> | ||
302 | + <form role="form"> | ||
303 | + <input type="hidden" name="commandtype" value="api" /> | ||
304 | + <div class="form-group"> | ||
305 | + <div class="row"> | ||
306 | + <div class="col-xs-3"> | ||
307 | + <input checked="" name="force" type="hidden" value="0"> | ||
308 | + <label class="control-label"> | ||
309 | + <input name="force" type="checkbox" value="1"> | ||
310 | + 覆盖模式 | ||
311 | + </label> | ||
312 | + </div> | ||
313 | + </div> | ||
314 | + </div> | ||
315 | + <div class="form-group"> | ||
316 | + <legend>文档设置</legend> | ||
317 | + <div class="row"> | ||
318 | + <div class="col-xs-3"> | ||
319 | + <label>请输入接口URL</label> | ||
320 | + <input type="text" name="url" class="form-control" placeholder="API URL,可留空" /> | ||
321 | + </div> | ||
322 | + <div class="col-xs-3"> | ||
323 | + <label>接口生成文件</label> | ||
324 | + <input type="text" name="output" class="form-control" placeholder="留空则使用api.html" /> | ||
325 | + </div> | ||
326 | + <div class="col-xs-3"> | ||
327 | + <label>模板文件</label> | ||
328 | + <input type="text" name="template" class="form-control" placeholder="如果不清楚请留空" /> | ||
329 | + </div> | ||
330 | + </div> | ||
331 | + <div class="row" style="margin-top:10px;"> | ||
332 | + <div class="col-xs-3"> | ||
333 | + <label>文档标题</label> | ||
334 | + <input type="text" name="title" class="form-control" placeholder="默认为FastAdmin" /> | ||
335 | + </div> | ||
336 | + <div class="col-xs-3"> | ||
337 | + <label>文档作者</label> | ||
338 | + <input type="text" name="author" class="form-control" placeholder="默认为FastAdmin" /> | ||
339 | + </div> | ||
340 | + <div class="col-xs-3"> | ||
341 | + <label>文档语言</label> | ||
342 | + <select name="language" class="form-control"> | ||
343 | + <option value="" selected>请选择语言</option> | ||
344 | + <option value="zh-cn">中文</option> | ||
345 | + <option value="en">英文</option> | ||
346 | + </select> | ||
347 | + </div> | ||
348 | + </div> | ||
349 | + </div> | ||
350 | + | ||
351 | + <div class="form-group"> | ||
352 | + <legend>生成命令行</legend> | ||
353 | + <textarea class="form-control" rel="command" rows="1" placeholder="请点击生成命令行"></textarea> | ||
354 | + </div> | ||
355 | + | ||
356 | + <div class="form-group"> | ||
357 | + <legend>返回结果</legend> | ||
358 | + <textarea class="form-control" rel="result" rows="5" placeholder="请点击立即执行"></textarea> | ||
359 | + </div> | ||
360 | + | ||
361 | + <div class="form-group"> | ||
362 | + <button type="button" class="btn btn-info btn-embossed btn-command">{:__('生成命令行')}</button> | ||
363 | + <button type="button" class="btn btn-success btn-embossed btn-execute">{:__('立即执行')}</button> | ||
364 | + </div> | ||
365 | + | ||
366 | + </form> | ||
367 | + </div> | ||
368 | + </div> | ||
369 | + </div> | ||
370 | + </div> | ||
371 | + </div> | ||
372 | +</div> | ||
373 | +<script id="relationtpl" type="text/html"> | ||
374 | + <div class="row relation-item"> | ||
375 | + <div class="col-xs-2"> | ||
376 | + <label>请选择关联表</label> | ||
377 | + <select name="relation[<%=index%>][relation]" class="form-control relationtable" data-live-search="true"></select> | ||
378 | + </div> | ||
379 | + <div class="col-xs-2"> | ||
380 | + <label>请选择关联类型</label> | ||
381 | + <select name="relation[<%=index%>][relationmode]" class="form-control relationmode"></select> | ||
382 | + </div> | ||
383 | + <div class="col-xs-2"> | ||
384 | + <label>关联外键</label> | ||
385 | + <select name="relation[<%=index%>][relationforeignkey]" class="form-control relationforeignkey"></select> | ||
386 | + </div> | ||
387 | + <div class="col-xs-2"> | ||
388 | + <label>关联主键</label> | ||
389 | + <select name="relation[<%=index%>][relationprimarykey]" class="form-control relationprimarykey"></select> | ||
390 | + </div> | ||
391 | + <div class="col-xs-2"> | ||
392 | + <label>请选择显示字段</label> | ||
393 | + <select name="relation[<%=index%>][relationfields][]" multiple class="form-control relationfields"></select> | ||
394 | + </div> | ||
395 | + <div class="col-xs-2"> | ||
396 | + <label> </label> | ||
397 | + <a href="javascript:;" class="btn btn-danger btn-block btn-removerelation">移除</a> | ||
398 | + </div> | ||
399 | + </div> | ||
400 | +</script> |
1 | +<table class="table table-striped"> | ||
2 | + <thead> | ||
3 | + <tr> | ||
4 | + <th>{:__('Title')}</th> | ||
5 | + <th>{:__('Content')}</th> | ||
6 | + </tr> | ||
7 | + </thead> | ||
8 | + <tbody> | ||
9 | + <tr> | ||
10 | + <td>{:__('Type')}</td> | ||
11 | + <td>{$row.type}({$row.type_text})</td> | ||
12 | + </tr> | ||
13 | + <tr> | ||
14 | + <td>{:__('Params')}</td> | ||
15 | + <td>{$row.params}</td> | ||
16 | + </tr> | ||
17 | + <tr> | ||
18 | + <td>{:__('Command')}</td> | ||
19 | + <td>{$row.command}</td> | ||
20 | + </tr> | ||
21 | + <tr> | ||
22 | + <td>{:__('Content')}</td> | ||
23 | + <td> | ||
24 | + <textarea class="form-control" name="" id="" cols="60" rows="10">{$row.content}</textarea> | ||
25 | + </td> | ||
26 | + </tr> | ||
27 | + <tr> | ||
28 | + <td>{:__('Executetime')}</td> | ||
29 | + <td>{$row.executetime|datetime}</td> | ||
30 | + </tr> | ||
31 | + <tr> | ||
32 | + <td>{:__('Status')}</td> | ||
33 | + <td>{$row.status_text}</td> | ||
34 | + </tr> | ||
35 | + </tbody> | ||
36 | +</table> | ||
37 | +<div class="hide layer-footer"> | ||
38 | + <label class="control-label col-xs-12 col-sm-2"></label> | ||
39 | + <div class="col-xs-12 col-sm-8"> | ||
40 | + <button type="reset" class="btn btn-primary btn-embossed btn-close" onclick="Layer.closeAll();">{:__('Close')}</button> | ||
41 | + </div> | ||
42 | +</div> |
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('command/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> | ||
11 | + <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('command/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> | ||
12 | + | ||
13 | + </div> | ||
14 | + <table id="table" class="table table-striped table-bordered table-hover" | ||
15 | + data-operate-detail="{:$auth->check('command/detail')}" | ||
16 | + data-operate-execute="{:$auth->check('command/execute')}" | ||
17 | + data-operate-del="{:$auth->check('command/del')}" | ||
18 | + width="100%"> | ||
19 | + </table> | ||
20 | + </div> | ||
21 | + </div> | ||
22 | + | ||
23 | + </div> | ||
24 | + </div> | ||
25 | +</div> |
addons/command/config.php
0 → 100644
addons/command/controller/Index.php
0 → 100644
addons/command/info.ini
0 → 100644
addons/command/install.sql
0 → 100644
1 | +CREATE TABLE IF NOT EXISTS `__PREFIX__command` ( | ||
2 | + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID', | ||
3 | + `type` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '类型', | ||
4 | + `params` varchar(1500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '参数', | ||
5 | + `command` varchar(1500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '命令', | ||
6 | + `content` text COMMENT '返回结果', | ||
7 | + `executetime` int(10) UNSIGNED DEFAULT NULL COMMENT '执行时间', | ||
8 | + `createtime` int(10) UNSIGNED DEFAULT NULL COMMENT '创建时间', | ||
9 | + `updatetime` int(10) UNSIGNED DEFAULT NULL COMMENT '更新时间', | ||
10 | + `status` enum('successed','failured') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'failured' COMMENT '状态', | ||
11 | + PRIMARY KEY (`id`) USING BTREE | ||
12 | +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '在线命令表'; |
addons/command/library/Output.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\command\library; | ||
4 | + | ||
5 | +/** | ||
6 | + * Class Output | ||
7 | + */ | ||
8 | +class Output extends \think\console\Output | ||
9 | +{ | ||
10 | + | ||
11 | + protected $message = []; | ||
12 | + | ||
13 | + public function __construct($driver = 'console') | ||
14 | + { | ||
15 | + parent::__construct($driver); | ||
16 | + } | ||
17 | + | ||
18 | + protected function block($style, $message) | ||
19 | + { | ||
20 | + $this->message[] = $message; | ||
21 | + } | ||
22 | + | ||
23 | + public function getMessage() | ||
24 | + { | ||
25 | + return $this->message; | ||
26 | + } | ||
27 | + | ||
28 | +} |
1 | +define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) { | ||
2 | + | ||
3 | + var Controller = { | ||
4 | + index: function () { | ||
5 | + // 初始化表格参数配置 | ||
6 | + Table.api.init({ | ||
7 | + extend: { | ||
8 | + index_url: 'command/index', | ||
9 | + add_url: 'command/add', | ||
10 | + edit_url: '', | ||
11 | + del_url: 'command/del', | ||
12 | + multi_url: 'command/multi', | ||
13 | + table: 'command', | ||
14 | + } | ||
15 | + }); | ||
16 | + | ||
17 | + var table = $("#table"); | ||
18 | + | ||
19 | + // 初始化表格 | ||
20 | + table.bootstrapTable({ | ||
21 | + url: $.fn.bootstrapTable.defaults.extend.index_url, | ||
22 | + pk: 'id', | ||
23 | + sortName: 'id', | ||
24 | + columns: [ | ||
25 | + [ | ||
26 | + {checkbox: true}, | ||
27 | + {field: 'id', title: __('Id')}, | ||
28 | + {field: 'type', title: __('Type'), formatter: Table.api.formatter.search}, | ||
29 | + {field: 'type_text', title: __('Type')}, | ||
30 | + { | ||
31 | + field: 'command', title: __('Command'), formatter: function (value, row, index) { | ||
32 | + return '<input type="text" class="form-control" value="' + value + '">'; | ||
33 | + } | ||
34 | + }, | ||
35 | + { | ||
36 | + field: 'executetime', | ||
37 | + title: __('Executetime'), | ||
38 | + operate: 'RANGE', | ||
39 | + addclass: 'datetimerange', | ||
40 | + formatter: Table.api.formatter.datetime | ||
41 | + }, | ||
42 | + { | ||
43 | + field: 'createtime', | ||
44 | + title: __('Createtime'), | ||
45 | + operate: 'RANGE', | ||
46 | + addclass: 'datetimerange', | ||
47 | + formatter: Table.api.formatter.datetime | ||
48 | + }, | ||
49 | + { | ||
50 | + field: 'updatetime', | ||
51 | + title: __('Updatetime'), | ||
52 | + operate: 'RANGE', | ||
53 | + addclass: 'datetimerange', | ||
54 | + formatter: Table.api.formatter.datetime | ||
55 | + }, | ||
56 | + { | ||
57 | + field: 'status', | ||
58 | + title: __('Status'), | ||
59 | + table: table, | ||
60 | + custom: {"successed": 'success', "failured": 'danger'}, | ||
61 | + searchList: {"successed": __('Successed'), "failured": __('Failured')}, | ||
62 | + formatter: Table.api.formatter.status | ||
63 | + }, | ||
64 | + { | ||
65 | + field: 'operate', | ||
66 | + title: __('Operate'), | ||
67 | + buttons: [ | ||
68 | + { | ||
69 | + name: 'execute', | ||
70 | + title: __('Execute again'), | ||
71 | + text: __('Execute again'), | ||
72 | + url: 'command/execute', | ||
73 | + icon: 'fa fa-repeat', | ||
74 | + classname: 'btn btn-success btn-xs btn-execute btn-ajax', | ||
75 | + success: function (data) { | ||
76 | + Layer.alert("<textarea class='form-control' cols='60' rows='5'>" + data.result + "</textarea>", { | ||
77 | + title: __("执行结果"), | ||
78 | + shadeClose: true | ||
79 | + }); | ||
80 | + table.bootstrapTable('refresh'); | ||
81 | + return false; | ||
82 | + } | ||
83 | + }, | ||
84 | + { | ||
85 | + name: 'execute', | ||
86 | + title: __('Detail'), | ||
87 | + text: __('Detail'), | ||
88 | + url: 'command/detail', | ||
89 | + icon: 'fa fa-list', | ||
90 | + classname: 'btn btn-info btn-xs btn-execute btn-dialog' | ||
91 | + } | ||
92 | + ], | ||
93 | + table: table, | ||
94 | + events: Table.api.events.operate, | ||
95 | + formatter: Table.api.formatter.operate | ||
96 | + } | ||
97 | + ] | ||
98 | + ] | ||
99 | + }); | ||
100 | + | ||
101 | + // 为表格绑定事件 | ||
102 | + Table.api.bindevent(table); | ||
103 | + }, | ||
104 | + add: function () { | ||
105 | + require(['bootstrap-select', 'bootstrap-select-lang']); | ||
106 | + var mainfields = []; | ||
107 | + var relationfields = {}; | ||
108 | + var maintable = []; | ||
109 | + var relationtable = []; | ||
110 | + var relationmode = ["belongsto", "hasone"]; | ||
111 | + | ||
112 | + var renderselect = function (select, data) { | ||
113 | + var html = []; | ||
114 | + for (var i = 0; i < data.length; i++) { | ||
115 | + html.push("<option value='" + data[i] + "'>" + data[i] + "</option>"); | ||
116 | + } | ||
117 | + $(select).html(html.join("")); | ||
118 | + select.trigger("change"); | ||
119 | + if (select.data("selectpicker")) { | ||
120 | + select.selectpicker('refresh'); | ||
121 | + } | ||
122 | + return select; | ||
123 | + }; | ||
124 | + | ||
125 | + $("select[name=table] option").each(function () { | ||
126 | + maintable.push($(this).val()); | ||
127 | + }); | ||
128 | + $(document).on('change', "input[name='isrelation']", function () { | ||
129 | + $("#relation-zone").toggleClass("hide", !$(this).prop("checked")); | ||
130 | + }); | ||
131 | + $(document).on('change', "select[name='table']", function () { | ||
132 | + var that = this; | ||
133 | + Fast.api.ajax({ | ||
134 | + url: "command/get_field_list", | ||
135 | + data: {table: $(that).val()}, | ||
136 | + }, function (data, ret) { | ||
137 | + mainfields = data.fieldlist; | ||
138 | + $("#relation-zone .relation-item").remove(); | ||
139 | + renderselect($("#fields"), mainfields); | ||
140 | + return false; | ||
141 | + }); | ||
142 | + return false; | ||
143 | + }); | ||
144 | + $(document).on('click', "a.btn-newrelation", function () { | ||
145 | + var that = this; | ||
146 | + var index = parseInt($(that).data("index")) + 1; | ||
147 | + var content = Template("relationtpl", {index: index}); | ||
148 | + content = $(content.replace(/\[index\]/, index)); | ||
149 | + $(this).data("index", index); | ||
150 | + $(content).insertBefore($(that).closest(".row")); | ||
151 | + $('select', content).selectpicker(); | ||
152 | + var exists = [$("select[name='table']").val()]; | ||
153 | + $("select.relationtable").each(function () { | ||
154 | + exists.push($(this).val()); | ||
155 | + }); | ||
156 | + relationtable = []; | ||
157 | + $.each(maintable, function (i, j) { | ||
158 | + if ($.inArray(j, exists) < 0) { | ||
159 | + relationtable.push(j); | ||
160 | + } | ||
161 | + }); | ||
162 | + renderselect($("select.relationtable", content), relationtable); | ||
163 | + $("select.relationtable", content).trigger("change"); | ||
164 | + }); | ||
165 | + $(document).on('click', "a.btn-removerelation", function () { | ||
166 | + $(this).closest(".row").remove(); | ||
167 | + }); | ||
168 | + $(document).on('change', "#relation-zone select.relationmode", function () { | ||
169 | + var table = $("select.relationtable", $(this).closest(".row")).val(); | ||
170 | + var that = this; | ||
171 | + Fast.api.ajax({ | ||
172 | + url: "command/get_field_list", | ||
173 | + data: {table: table}, | ||
174 | + }, function (data, ret) { | ||
175 | + renderselect($(that).closest(".row").find("select.relationprimarykey"), $(that).val() == 'belongsto' ? data.fieldlist : mainfields); | ||
176 | + renderselect($(that).closest(".row").find("select.relationforeignkey"), $(that).val() == 'hasone' ? data.fieldlist : mainfields); | ||
177 | + return false; | ||
178 | + }); | ||
179 | + }); | ||
180 | + $(document).on('change', "#relation-zone select.relationtable", function () { | ||
181 | + var that = this; | ||
182 | + Fast.api.ajax({ | ||
183 | + url: "command/get_field_list", | ||
184 | + data: {table: $(that).val()}, | ||
185 | + }, function (data, ret) { | ||
186 | + renderselect($(that).closest(".row").find("select.relationmode"), relationmode); | ||
187 | + renderselect($(that).closest(".row").find("select.relationfields"), mainfields) | ||
188 | + renderselect($(that).closest(".row").find("select.relationforeignkey"), data.fieldlist) | ||
189 | + renderselect($(that).closest(".row").find("select.relationfields"), data.fieldlist) | ||
190 | + return false; | ||
191 | + }); | ||
192 | + }); | ||
193 | + $(document).on('click', ".btn-command", function () { | ||
194 | + var form = $(this).closest("form"); | ||
195 | + var textarea = $("textarea[rel=command]", form); | ||
196 | + textarea.val(''); | ||
197 | + Fast.api.ajax({ | ||
198 | + url: "command/command/action/command", | ||
199 | + data: form.serialize(), | ||
200 | + }, function (data, ret) { | ||
201 | + textarea.val(data.command); | ||
202 | + return false; | ||
203 | + }); | ||
204 | + }); | ||
205 | + $(document).on('click', ".btn-execute", function () { | ||
206 | + var form = $(this).closest("form"); | ||
207 | + var textarea = $("textarea[rel=result]", form); | ||
208 | + textarea.val(''); | ||
209 | + Fast.api.ajax({ | ||
210 | + url: "command/command/action/execute", | ||
211 | + data: form.serialize(), | ||
212 | + }, function (data, ret) { | ||
213 | + textarea.val(data.result); | ||
214 | + window.parent.$(".toolbar .btn-refresh").trigger('click'); | ||
215 | + top.window.Fast.api.refreshmenu(); | ||
216 | + return false; | ||
217 | + }, function () { | ||
218 | + window.parent.$(".toolbar .btn-refresh").trigger('click'); | ||
219 | + }); | ||
220 | + }); | ||
221 | + $("select[name='table']").trigger("change"); | ||
222 | + Controller.api.bindevent(); | ||
223 | + }, | ||
224 | + edit: function () { | ||
225 | + Controller.api.bindevent(); | ||
226 | + }, | ||
227 | + api: { | ||
228 | + bindevent: function () { | ||
229 | + Form.api.bindevent($("form[role=form]")); | ||
230 | + } | ||
231 | + } | ||
232 | + }; | ||
233 | + return Controller; | ||
234 | +}); |
addons/database/Database.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\database; | ||
4 | + | ||
5 | +use app\common\library\Menu; | ||
6 | +use think\Addons; | ||
7 | + | ||
8 | +/** | ||
9 | + * 数据库插件 | ||
10 | + */ | ||
11 | +class Database extends Addons | ||
12 | +{ | ||
13 | + | ||
14 | + /** | ||
15 | + * 插件安装方法 | ||
16 | + * @return bool | ||
17 | + */ | ||
18 | + public function install() | ||
19 | + { | ||
20 | + $menu = [ | ||
21 | + [ | ||
22 | + 'name' => 'general/database', | ||
23 | + 'title' => '数据库管理', | ||
24 | + 'icon' => 'fa fa-database', | ||
25 | + 'remark' => '可在线进行一些简单的数据库表优化或修复,查看表结构和数据,也可以进行SQL语句的操作', | ||
26 | + 'sublist' => [ | ||
27 | + ['name' => 'general/database/index', 'title' => '查看'], | ||
28 | + ['name' => 'general/database/query', 'title' => '查询'], | ||
29 | + ['name' => 'general/database/backup', 'title' => '备份'], | ||
30 | + ['name' => 'general/database/restore', 'title' => '恢复'], | ||
31 | + ] | ||
32 | + ] | ||
33 | + ]; | ||
34 | + Menu::create($menu, 'general'); | ||
35 | + return true; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * 插件卸载方法 | ||
40 | + * @return bool | ||
41 | + */ | ||
42 | + public function uninstall() | ||
43 | + { | ||
44 | + | ||
45 | + Menu::delete('general/database'); | ||
46 | + return true; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * 插件启用方法 | ||
51 | + */ | ||
52 | + public function enable() | ||
53 | + { | ||
54 | + Menu::enable('general/database'); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * 插件禁用方法 | ||
59 | + */ | ||
60 | + public function disable() | ||
61 | + { | ||
62 | + Menu::disable('general/database'); | ||
63 | + } | ||
64 | + | ||
65 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\general; | ||
4 | + | ||
5 | +use addons\database\library\Backup; | ||
6 | +use app\common\controller\Backend; | ||
7 | +use think\Db; | ||
8 | +use think\Debug; | ||
9 | +use think\Exception; | ||
10 | +use think\exception\PDOException; | ||
11 | +use ZipArchive; | ||
12 | + | ||
13 | +/** | ||
14 | + * 数据库管理 | ||
15 | + * | ||
16 | + * @icon fa fa-database | ||
17 | + * @remark 可在线进行一些简单的数据库表优化或修复,查看表结构和数据。也可以进行SQL语句的操作 | ||
18 | + */ | ||
19 | +class Database extends Backend | ||
20 | +{ | ||
21 | + protected $noNeedRight = ['backuplist']; | ||
22 | + | ||
23 | + public function _initialize() | ||
24 | + { | ||
25 | + if (!config("app_debug")) { | ||
26 | + $this->error("数据库管理插件只允许在开发环境下使用"); | ||
27 | + } | ||
28 | + return parent::_initialize(); | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * 查看 | ||
33 | + */ | ||
34 | + public function index() | ||
35 | + { | ||
36 | + $tables_data_length = $tables_index_length = $tables_free_length = $tables_data_count = 0; | ||
37 | + $tables = $list = []; | ||
38 | + $list = Db::query("SHOW TABLES"); | ||
39 | + foreach ($list as $key => $row) { | ||
40 | + $tables[] = ['name' => reset($row), 'rows' => 0]; | ||
41 | + } | ||
42 | + $data['tables'] = $tables; | ||
43 | + $data['saved_sql'] = []; | ||
44 | + $this->view->assign($data); | ||
45 | + return $this->view->fetch(); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * SQL查询 | ||
50 | + */ | ||
51 | + public function query() | ||
52 | + { | ||
53 | + $do_action = $this->request->post('do_action'); | ||
54 | + | ||
55 | + echo '<style type="text/css"> | ||
56 | + xmp,body{margin:0;padding:0;line-height:18px;font-size:12px;font-family:"Helvetica Neue", Helvetica, Microsoft Yahei, Hiragino Sans GB, WenQuanYi Micro Hei, sans-serif;} | ||
57 | + hr{height:1px;margin:5px 1px;background:#e3e3e3;border:none;} | ||
58 | + </style>'; | ||
59 | + if ($do_action == '') { | ||
60 | + exit(__('Invalid parameters')); | ||
61 | + } | ||
62 | + | ||
63 | + $tablename = $this->request->post("tablename/a"); | ||
64 | + | ||
65 | + if (in_array($do_action, array('doquery', 'optimizeall', 'repairall'))) { | ||
66 | + $this->$do_action(); | ||
67 | + } elseif (count($tablename) == 0) { | ||
68 | + exit(__('Invalid parameters')); | ||
69 | + } else { | ||
70 | + foreach ($tablename as $table) { | ||
71 | + $this->$do_action($table); | ||
72 | + echo "<br />"; | ||
73 | + } | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * 备份列表 | ||
79 | + * @internal | ||
80 | + */ | ||
81 | + public function backuplist() | ||
82 | + { | ||
83 | + $config = get_addon_config('database'); | ||
84 | + $backupDir = ROOT_PATH . 'public' . DS . $config['backupDir']; | ||
85 | + | ||
86 | + $backuplist = []; | ||
87 | + foreach (glob($backupDir . "*.zip") as $filename) { | ||
88 | + $time = filemtime($filename); | ||
89 | + $backuplist[$time] = | ||
90 | + [ | ||
91 | + 'file' => str_replace($backupDir, '', $filename), | ||
92 | + 'date' => date("Y-m-d H:i:s", $time), | ||
93 | + 'size' => format_bytes(filesize($filename)) | ||
94 | + ]; | ||
95 | + } | ||
96 | + krsort($backuplist); | ||
97 | + | ||
98 | + $this->success("", null, ['backuplist' => array_values($backuplist)]); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * 还原 | ||
103 | + */ | ||
104 | + public function restore($ids = '') | ||
105 | + { | ||
106 | + $config = get_addon_config('database'); | ||
107 | + $backupDir = ROOT_PATH . 'public' . DS . $config['backupDir']; | ||
108 | + if ($this->request->isPost()) { | ||
109 | + $action = $this->request->request('action'); | ||
110 | + $file = $this->request->request('file'); | ||
111 | + if (!preg_match("/^backup\-([a-z0-9\-]+)\.zip$/i", $file)) { | ||
112 | + $this->error(__("Invalid parameters")); | ||
113 | + } | ||
114 | + $file = $backupDir . $file; | ||
115 | + if ($action == 'restore') { | ||
116 | + if (!class_exists('ZipArchive')) { | ||
117 | + $this->error("服务器缺少php-zip组件,无法进行还原操作"); | ||
118 | + } | ||
119 | + try { | ||
120 | + $dir = RUNTIME_PATH . 'database' . DS; | ||
121 | + if (!is_dir($dir)) { | ||
122 | + mkdir($dir, 0755); | ||
123 | + } | ||
124 | + | ||
125 | + $zip = new ZipArchive; | ||
126 | + if ($zip->open($file) !== true) { | ||
127 | + throw new Exception(__('Can not open zip file')); | ||
128 | + } | ||
129 | + if (!$zip->extractTo($dir)) { | ||
130 | + $zip->close(); | ||
131 | + throw new Exception(__('Can not unzip file')); | ||
132 | + } | ||
133 | + $zip->close(); | ||
134 | + $filename = basename($file); | ||
135 | + $sqlFile = $dir . str_replace('.zip', '.sql', $filename); | ||
136 | + if (!is_file($sqlFile)) { | ||
137 | + throw new Exception(__('Sql file not found')); | ||
138 | + } | ||
139 | + $filesize = filesize($sqlFile); | ||
140 | + $list = Db::query('SELECT @@global.max_allowed_packet'); | ||
141 | + if (isset($list[0]['@@global.max_allowed_packet']) && $filesize >= $list[0]['@@global.max_allowed_packet']) { | ||
142 | + Db::execute('SET @@global.max_allowed_packet = ' . ($filesize + 1024)); | ||
143 | + //throw new Exception('备份文件超过配置max_allowed_packet大小,请修改Mysql服务器配置'); | ||
144 | + } | ||
145 | + $sql = file_get_contents($sqlFile); | ||
146 | + | ||
147 | + Db::clear(); | ||
148 | + //必须重连一次 | ||
149 | + Db::connect([], true)->query("select 1"); | ||
150 | + Db::getPdo()->exec($sql); | ||
151 | + } catch (Exception $e) { | ||
152 | + $this->error($e->getMessage()); | ||
153 | + } catch (PDOException $e) { | ||
154 | + $this->error($e->getMessage()); | ||
155 | + } | ||
156 | + $this->success(__('Restore successful')); | ||
157 | + } elseif ($action == 'delete') { | ||
158 | + unlink($file); | ||
159 | + $this->success(__('Delete successful')); | ||
160 | + } | ||
161 | + } | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * 备份 | ||
166 | + */ | ||
167 | + public function backup() | ||
168 | + { | ||
169 | + $config = get_addon_config('database'); | ||
170 | + $backupDir = ROOT_PATH . 'public' . DS . $config['backupDir']; | ||
171 | + if ($this->request->isPost()) { | ||
172 | + if (!class_exists('ZipArchive')) { | ||
173 | + $this->error("服务器缺少php-zip组件,无法进行备份操作"); | ||
174 | + } | ||
175 | + $database = config('database'); | ||
176 | + try { | ||
177 | + $backup = new Backup($database['hostname'], $database['username'], $database['database'], $database['password'], $database['hostport']); | ||
178 | + $backup->setIgnoreTable($config['backupIgnoreTables'])->backup($backupDir); | ||
179 | + } catch (Exception $e) { | ||
180 | + $this->error($e->getMessage()); | ||
181 | + } | ||
182 | + $this->success(__('Backup successful')); | ||
183 | + } | ||
184 | + return; | ||
185 | + } | ||
186 | + | ||
187 | + private function viewinfo($name) | ||
188 | + { | ||
189 | + $row = Db::query("SHOW CREATE TABLE `{$name}`"); | ||
190 | + $row = array_values($row[0]); | ||
191 | + $info = $row[1]; | ||
192 | + echo "<xmp>{$info};</xmp>"; | ||
193 | + } | ||
194 | + | ||
195 | + private function viewdata($name = '') | ||
196 | + { | ||
197 | + $sqlquery = "SELECT * FROM `{$name}`"; | ||
198 | + $this->doquery($sqlquery); | ||
199 | + } | ||
200 | + | ||
201 | + private function optimize($name = '') | ||
202 | + { | ||
203 | + if (Db::execute("OPTIMIZE TABLE `{$name}`")) { | ||
204 | + echo __('Optimize table %s done', $name); | ||
205 | + } else { | ||
206 | + echo __('Optimize table %s fail', $name); | ||
207 | + } | ||
208 | + } | ||
209 | + | ||
210 | + private function optimizeall($name = '') | ||
211 | + { | ||
212 | + $list = Db::query("SHOW TABLES"); | ||
213 | + foreach ($list as $key => $row) { | ||
214 | + $name = reset($row); | ||
215 | + if (Db::execute("OPTIMIZE TABLE {$name}")) { | ||
216 | + echo __('Optimize table %s done', $name); | ||
217 | + } else { | ||
218 | + echo __('Optimize table %s fail', $name); | ||
219 | + } | ||
220 | + echo "<br />"; | ||
221 | + } | ||
222 | + } | ||
223 | + | ||
224 | + private function repair($name = '') | ||
225 | + { | ||
226 | + if (Db::execute("REPAIR TABLE `{$name}`")) { | ||
227 | + echo __('Repair table %s done', $name); | ||
228 | + } else { | ||
229 | + echo __('Repair table %s fail', $name); | ||
230 | + } | ||
231 | + } | ||
232 | + | ||
233 | + private function repairall($name = '') | ||
234 | + { | ||
235 | + $list = Db::query("SHOW TABLES"); | ||
236 | + foreach ($list as $key => $row) { | ||
237 | + $name = reset($row); | ||
238 | + if (Db::execute("REPAIR TABLE {$name}")) { | ||
239 | + echo __('Repair table %s done', $name); | ||
240 | + } else { | ||
241 | + echo __('Repair table %s fail', $name); | ||
242 | + } | ||
243 | + echo "<br />"; | ||
244 | + } | ||
245 | + } | ||
246 | + | ||
247 | + private function doquery($sql = null) | ||
248 | + { | ||
249 | + $sqlquery = $sql ? $sql : $this->request->post('sqlquery'); | ||
250 | + if ($sqlquery == '') { | ||
251 | + exit(__('SQL can not be empty')); | ||
252 | + } | ||
253 | + $sqlquery = str_replace('__PREFIX__', config('database.prefix'), $sqlquery); | ||
254 | + $sqlquery = str_replace("\r", "", $sqlquery); | ||
255 | + $sqls = preg_split("/;[ \t]{0,}\n/i", $sqlquery); | ||
256 | + $maxreturn = 100; | ||
257 | + $r = ''; | ||
258 | + foreach ($sqls as $key => $val) { | ||
259 | + if (trim($val) == '') { | ||
260 | + continue; | ||
261 | + } | ||
262 | + $val = rtrim($val, ';'); | ||
263 | + $r .= "SQL:<span style='color:green;'>{$val}</span> "; | ||
264 | + if (preg_match("/^(select|explain)(.*)/i ", $val)) { | ||
265 | + Debug::remark("begin"); | ||
266 | + $limit = stripos(strtolower($val), "limit") !== false ? true : false; | ||
267 | + $count = Db::execute($val); | ||
268 | + if ($count > 0) { | ||
269 | + $resultlist = Db::query($val . (!$limit && $count > $maxreturn ? ' LIMIT ' . $maxreturn : '')); | ||
270 | + } else { | ||
271 | + $resultlist = []; | ||
272 | + } | ||
273 | + Debug::remark("end"); | ||
274 | + $time = Debug::getRangeTime('begin', 'end', 4); | ||
275 | + | ||
276 | + $usedseconds = __('Query took %s seconds', $time) . "<br />"; | ||
277 | + if ($count <= 0) { | ||
278 | + $r .= __('Query returned an empty result'); | ||
279 | + } else { | ||
280 | + $r .= (__('Total:%s', $count) . (!$limit && $count > $maxreturn ? ',' . __('Max output:%s', $maxreturn) : "")); | ||
281 | + } | ||
282 | + $r = $r . ',' . $usedseconds; | ||
283 | + $j = 0; | ||
284 | + foreach ($resultlist as $m => $n) { | ||
285 | + $j++; | ||
286 | + if (!$limit && $j > $maxreturn) { | ||
287 | + break; | ||
288 | + } | ||
289 | + $r .= "<hr/>"; | ||
290 | + $r .= "<font color='red'>" . __('Row:%s', $j) . "</font><br />"; | ||
291 | + foreach ($n as $k => $v) { | ||
292 | + $r .= "<font color='blue'>{$k}:</font>{$v}<br/>\r\n"; | ||
293 | + } | ||
294 | + } | ||
295 | + } else { | ||
296 | + Debug::remark("begin"); | ||
297 | + $count = Db::getPdo()->exec($val); | ||
298 | + Debug::remark("end"); | ||
299 | + $time = Debug::getRangeTime('begin', 'end', 4); | ||
300 | + $r .= __('Query affected %s rows and took %s seconds', $count, $time) . "<br />"; | ||
301 | + } | ||
302 | + } | ||
303 | + echo $r; | ||
304 | + } | ||
305 | +} |
1 | +<?php | ||
2 | + | ||
3 | +return [ | ||
4 | + 'SQL Result' => '查询结果', | ||
5 | + 'Basic query' => '基础查询', | ||
6 | + 'View structure' => '查看表结构', | ||
7 | + 'View data' => '查看表数据', | ||
8 | + 'Backup and Restore' => '备份与还原', | ||
9 | + 'Backup now' => '立即备份', | ||
10 | + 'File' => '文件', | ||
11 | + 'Size' => '大小', | ||
12 | + 'Date' => '备份日期', | ||
13 | + 'Restore' => '还原', | ||
14 | + 'Delete' => '删除', | ||
15 | + 'Optimize' => '优化表', | ||
16 | + 'Repair' => '修复表', | ||
17 | + 'Optimize all' => '优化全部表', | ||
18 | + 'Repair all' => '修复全部表', | ||
19 | + 'Backup successful' => '备份成功', | ||
20 | + 'Restore successful' => '还原成功', | ||
21 | + 'Delete successful' => '删除成功', | ||
22 | + 'Can not open zip file' => '无法打开备份文件', | ||
23 | + 'Can not unzip file' => '无法解压备份文件', | ||
24 | + 'Sql file not found' => '未找到SQL文件', | ||
25 | + 'Table:%s' => '总计:%s个表', | ||
26 | + 'Record:%s' => '记录:%s条', | ||
27 | + 'Data:%s' => '占用:%s', | ||
28 | + 'Index:%s' => '索引:%s', | ||
29 | + 'SQL Result:' => '查询结果:', | ||
30 | + 'SQL can not be empty' => 'SQL语句不能为空', | ||
31 | + 'Max output:%s' => '最大返回%s条', | ||
32 | + 'Total:%s' => '共有%s条记录! ', | ||
33 | + 'Row:%s' => '记录:%s', | ||
34 | + 'Executes one or multiple queries which are concatenated by a semicolon' => '请输入SQL语句,支持批量查询,多条SQL以分号(;)分格', | ||
35 | + 'Query affected %s rows and took %s seconds' => '共影响%s条记录! 耗时:%s秒!', | ||
36 | + 'Query returned an empty result' => '返回结果为空!', | ||
37 | + 'Query took %s seconds' => '耗时%s秒!', | ||
38 | + 'Optimize table %s done' => '优化表[%s]成功', | ||
39 | + 'Repair table %s done' => '修复表[%s]成功', | ||
40 | + 'Optimize table %s fail' => '优化表[%s]失败', | ||
41 | + 'Repair table %s fail' => '修复表[%s]失败' | ||
42 | +]; | ||
43 | + |
1 | +<style type="text/css"> | ||
2 | + #searchfloat {position:absolute;top:40px;right:20px;background:#F7F0A0;padding:10px;} | ||
3 | + #saved {position: relative;} | ||
4 | + #saved_sql {position:absolute;bottom:0;height:300px;background:#F7F0A0;width:100%;overflow:auto;display:none;} | ||
5 | + #saved_sql li {display:block;clear:both;width:100%;float:left;line-height:18px;padding:1px 0} | ||
6 | + #saved_sql li a{float:left;text-decoration: none;display:block;padding:0 5px;} | ||
7 | + #saved_sql li i{display:none;float:left;color:#06f;font-size: 14px;font-style: normal;margin-left:2px;line-height:18px;} | ||
8 | + #saved_sql li:hover{background:#fff;} | ||
9 | + #saved_sql li:hover i{display:block;cursor:pointer;} | ||
10 | + #database #tablename {height:205px;width:100%;padding:5px;} | ||
11 | + #database #tablename option{height:18px;} | ||
12 | + #database #subaction {height:210px;width:100%;} | ||
13 | + #database .select-striped > option:nth-of-type(odd) {background-color: #f9f9f9;} | ||
14 | + #database .dropdown-menu ul {margin:-3px 0;} | ||
15 | + #database .dropdown-menu ul li{margin:3px 0;} | ||
16 | + #database .dropdown-menu.row .col-xs-6{padding:0 5px;} | ||
17 | + #sqlquery {font-size:12px;color:#444;} | ||
18 | + #resultparent {padding:5px;} | ||
19 | +</style> | ||
20 | +<div class="panel panel-default panel-intro"> | ||
21 | + {:build_heading()} | ||
22 | + | ||
23 | + <div class="panel-body"> | ||
24 | + <div id="database" class="tab-content"> | ||
25 | + <div class="tab-pane fade active in" id="one"> | ||
26 | + <div class="widget-body no-padding"> | ||
27 | + {if $auth->check('general/database/query')} | ||
28 | + <div class="row"> | ||
29 | + <div class="col-xs-4"> | ||
30 | + <h4>{:__('SQL Result')}:</h4> | ||
31 | + </div> | ||
32 | + <div class="col-xs-8 text-right"> | ||
33 | + <form action="{:url('general.database/query')}" method="post" name="infoform" target="resultframe"> | ||
34 | + <input type="hidden" name="do_action" id="topaction" /> | ||
35 | + <a href="javascript:;" class="btn btn-success btn-compress"><i class="fa fa-compress"></i> {:__('Backup and Restore')}</a> | ||
36 | + <div class="btn-group"> | ||
37 | + <button data-toggle="dropdown" class="btn btn-primary btn-embossed dropdown-toggle" type="button">{:__('Basic query')} <span class="caret"></span></button> | ||
38 | + <div class="row dropdown-menu pull-right" style="width:300px;"> | ||
39 | + <div class="col-xs-6"> | ||
40 | + <select class="form-control select-striped" id="tablename" name="tablename[]" multiple="multiple"> | ||
41 | + {foreach $tables as $table} | ||
42 | + <option value="{$table.name}" title="">{$table.name}<!--({$table.rows})--></option> | ||
43 | + {/foreach} | ||
44 | + </select> | ||
45 | + </div> | ||
46 | + <div class="col-xs-6"> | ||
47 | + <ul id="subaction" class="list-unstyled"> | ||
48 | + <li><input type="submit" name="submit1" value="{:__('View structure')}" rel="viewinfo" class="btn btn-primary btn-embossed btn-sm btn-block"/></li> | ||
49 | + <li><input type="submit" name="submit2" value="{:__('View data')}" rel="viewdata" class="btn btn-primary btn-embossed btn-sm btn-block"/></li> | ||
50 | + <li><input type="submit" name="submit3" value="{:__('Optimize')}" rel="optimize" class="btn btn-primary btn-embossed btn-sm btn-block" /></li> | ||
51 | + <li><input type="submit" name="submit4" value="{:__('Repair')}" rel="repair" class="btn btn-primary btn-embossed btn-sm btn-block"/></li> | ||
52 | + <li><input type="submit" name="submit5" value="{:__('Optimize all')}" rel="optimizeall" class="btn btn-primary btn-embossed btn-sm btn-block" /></li> | ||
53 | + <li><input type="submit" name="submit6" value="{:__('Repair all')}" rel="repairall" class="btn btn-primary btn-embossed btn-sm btn-block" /></li> | ||
54 | + </ul> | ||
55 | + </div> | ||
56 | + <div class="clear"></div> | ||
57 | + </div> | ||
58 | + | ||
59 | + </div> | ||
60 | + </form> | ||
61 | + </div> | ||
62 | + | ||
63 | + </div> | ||
64 | + <div class="well" id="resultparent"> | ||
65 | + <iframe name="resultframe" frameborder="0" id="resultframe" style="height:100%;" width="100%" height="100%"></iframe> | ||
66 | + </div> | ||
67 | + <form action="{:url('general.database/query')}" method="post" id="sqlexecute" name="form1" target="resultframe"> | ||
68 | + <input type="hidden" name="do_action" value="doquery" /> | ||
69 | + <div class="form-group"> | ||
70 | + <textarea name="sqlquery" placeholder="{:__('Executes one or multiple queries which are concatenated by a semicolon')}" cols="60" rows="5" class="form-control" id="sqlquery"></textarea> | ||
71 | + </div> | ||
72 | + | ||
73 | + <input type="submit" class="btn btn-success btn-embossed" value="{:__('Execute')}" /> | ||
74 | + <input type="reset" class="btn btn-default btn-embossed" value="{:__('Reset')}" /> | ||
75 | + </form> | ||
76 | + {else /} | ||
77 | + <div id="backuplist"></div> | ||
78 | + {/if} | ||
79 | + </div> | ||
80 | + </div> | ||
81 | + | ||
82 | + </div> | ||
83 | + </div> | ||
84 | +</div> | ||
85 | + | ||
86 | +<script id="backuptpl" type="text/html"> | ||
87 | + <p> | ||
88 | + <a href="javascript:;" class="btn btn-success btn-backup"><i class="fa fa-compress"></i> {:__('Backup now')}</a> | ||
89 | + <span class="text-danger">如果你的数据过大,不建议采用此方式进行备份,会导致内存溢出的错误。</span> | ||
90 | + </p> | ||
91 | + | ||
92 | + <table id="dt_basic" class="table table-striped table-bordered table-hover" width="100%" style="min-width:500px;font-size:12px;"> | ||
93 | + <thead> | ||
94 | + <tr> | ||
95 | + <th>ID</th> | ||
96 | + <th>{:__('File')}</th> | ||
97 | + <th>{:__('Size')}</th> | ||
98 | + <th>{:__('Date')}</th> | ||
99 | + <th>{:__('Operate')}</th> | ||
100 | + </tr> | ||
101 | + </thead> | ||
102 | + <tbody> | ||
103 | + <%for (var i=0;i<backuplist.length;i++){%> | ||
104 | + <tr> | ||
105 | + <td><%=i+1%></td> | ||
106 | + <td><%=backuplist[i].file%></td> | ||
107 | + <td><%=backuplist[i].size%></td> | ||
108 | + <td><%=backuplist[i].date%></td> | ||
109 | + <td> | ||
110 | + <a href="javascript:;" class="btn btn-primary btn-restore btn-xs" data-file="<%=backuplist[i].file%>"><i class="fa fa-reply"></i> {:__('Restore')}</a> | ||
111 | + <a href="javascript:;" class="btn btn-danger btn-delete btn-xs" data-file="<%=backuplist[i].file%>"><i class="fa fa-times"></i> {:__('Delete')}</a> | ||
112 | + </td> | ||
113 | + </tr> | ||
114 | + <%}%> | ||
115 | + </tbody> | ||
116 | + </table> | ||
117 | +</script> |
addons/database/config.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +return array( | ||
4 | + array( | ||
5 | + 'name' => 'backupDir', | ||
6 | + 'title' => '备份存放目录', | ||
7 | + 'type' => 'string', | ||
8 | + 'content' => | ||
9 | + array(), | ||
10 | + 'value' => '../data/', | ||
11 | + 'rule' => 'required', | ||
12 | + 'msg' => '', | ||
13 | + 'tip' => '备份目录,请使用相对目录', | ||
14 | + 'ok' => '', | ||
15 | + 'extend' => '', | ||
16 | + ), | ||
17 | + array( | ||
18 | + 'name' => 'backupIgnoreTables', | ||
19 | + 'title' => '备份忽略的表', | ||
20 | + 'type' => 'string', | ||
21 | + 'content' => | ||
22 | + array(), | ||
23 | + 'value' => 'fa_admin_log', | ||
24 | + 'rule' => '', | ||
25 | + 'msg' => '', | ||
26 | + 'tip' => '忽略备份的表,多个表以,进行分隔', | ||
27 | + 'ok' => '', | ||
28 | + 'extend' => '', | ||
29 | + ), | ||
30 | + array( | ||
31 | + 'name' => '__tips__', | ||
32 | + 'title' => '温馨提示', | ||
33 | + 'type' => '', | ||
34 | + 'content' => | ||
35 | + array(), | ||
36 | + 'value' => '请做好数据库离线备份工作,建议此插件仅用于开发阶段,项目正式上线建议卸载此插件', | ||
37 | + 'rule' => '', | ||
38 | + 'msg' => '', | ||
39 | + 'tip' => '', | ||
40 | + 'ok' => '', | ||
41 | + 'extend' => '', | ||
42 | + ), | ||
43 | +); |
addons/database/controller/Index.php
0 → 100644
addons/database/info.ini
0 → 100644
addons/database/library/Backup.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\database\library; | ||
4 | + | ||
5 | +use Exception; | ||
6 | +use PDO; | ||
7 | +use ZipArchive; | ||
8 | + | ||
9 | +class Backup | ||
10 | +{ | ||
11 | + | ||
12 | + private $host = ''; | ||
13 | + private $user = ''; | ||
14 | + private $name = ''; | ||
15 | + private $pass = ''; | ||
16 | + private $port = ''; | ||
17 | + private $tables = ['*']; | ||
18 | + private $ignoreTables = []; | ||
19 | + private $db; | ||
20 | + private $ds = "\n"; | ||
21 | + | ||
22 | + public function __construct($host = null, $user = null, $name = null, $pass = null, $port = 3306) | ||
23 | + { | ||
24 | + if ($host !== null) { | ||
25 | + $this->host = $host; | ||
26 | + $this->name = $name; | ||
27 | + $this->port = $port; | ||
28 | + $this->pass = $pass; | ||
29 | + $this->user = $user; | ||
30 | + } | ||
31 | + $this->db = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->name . '; port=' . $port, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); | ||
32 | + | ||
33 | + $this->db->exec('SET NAMES "utf8"'); | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * 设置备份表 | ||
38 | + * @param $table | ||
39 | + * @return $this | ||
40 | + */ | ||
41 | + public function setTable($table) | ||
42 | + { | ||
43 | + if ($table) { | ||
44 | + $this->tables = is_array($table) ? $table : explode(',', $table); | ||
45 | + } | ||
46 | + return $this; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * 设置忽略备份的表 | ||
51 | + * @param $table | ||
52 | + * @return $this | ||
53 | + */ | ||
54 | + public function setIgnoreTable($table) | ||
55 | + { | ||
56 | + if ($table) { | ||
57 | + $this->ignoreTables = is_array($table) ? $table : explode(',', preg_replace('/\s+/', '', $table)); | ||
58 | + } | ||
59 | + return $this; | ||
60 | + } | ||
61 | + | ||
62 | + public function backup($backUpdir = 'download/') | ||
63 | + { | ||
64 | + $sql = $this->_init(); | ||
65 | + $zip = new ZipArchive(); | ||
66 | + $date = date('YmdHis'); | ||
67 | + if (!is_dir($backUpdir)) { | ||
68 | + @mkdir($backUpdir, 0755); | ||
69 | + } | ||
70 | + $name = "backup-{$this->name}-{$date}"; | ||
71 | + $filename = $backUpdir . $name . ".zip"; | ||
72 | + | ||
73 | + if ($zip->open($filename, ZIPARCHIVE::CREATE) !== true) { | ||
74 | + throw new Exception("Could not open <$filename>\n"); | ||
75 | + } | ||
76 | + $zip->addFromString($name . ".sql", $sql); | ||
77 | + $zip->close(); | ||
78 | + } | ||
79 | + | ||
80 | + private function _init() | ||
81 | + { | ||
82 | + # COUNT | ||
83 | + $ct = 0; | ||
84 | + # CONTENT | ||
85 | + $sqldump = ''; | ||
86 | + # COPYRIGHT & OPTIONS | ||
87 | + $sqldump .= "-- SQL Dump by Erik Edgren\n"; | ||
88 | + $sqldump .= "-- version 1.0\n"; | ||
89 | + $sqldump .= "--\n"; | ||
90 | + $sqldump .= "-- SQL Dump created: " . date('F jS, Y \@ g:i a') . "\n\n"; | ||
91 | + $sqldump .= "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";"; | ||
92 | + $sqldump .= "\n\n\n\n-- --------------------------------------------------------\n\n\n\n"; | ||
93 | + $tables = $this->db->query("SHOW FULL TABLES WHERE Table_Type != 'VIEW'"); | ||
94 | + # LOOP: Get the tables | ||
95 | + foreach ($tables AS $table) { | ||
96 | + // 忽略表 | ||
97 | + if (in_array($table[0], $this->ignoreTables)) { | ||
98 | + continue; | ||
99 | + } | ||
100 | + # COUNT | ||
101 | + $ct++; | ||
102 | + /** ** ** ** ** **/ | ||
103 | + # DATABASE: Count the rows in each tables | ||
104 | + $count_rows = $this->db->prepare("SELECT * FROM " . $table[0]); | ||
105 | + $count_rows->execute(); | ||
106 | + $c_rows = $count_rows->columnCount(); | ||
107 | + # DATABASE: Count the columns in each tables | ||
108 | + $count_columns = $this->db->prepare("SELECT COUNT(*) FROM " . $table[0]); | ||
109 | + $count_columns->execute(); | ||
110 | + $c_columns = $count_columns->fetchColumn(); | ||
111 | + /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ | ||
112 | + # MYSQL DUMP: Remove tables if they exists | ||
113 | + $sqldump .= "--\n"; | ||
114 | + $sqldump .= "-- Remove the table if it exists\n"; | ||
115 | + $sqldump .= "--\n\n"; | ||
116 | + $sqldump .= "DROP TABLE IF EXISTS `" . $table[0] . "`;\n\n\n"; | ||
117 | + /** ** ** ** ** **/ | ||
118 | + # MYSQL DUMP: Create table if they do not exists | ||
119 | + $sqldump .= "--\n"; | ||
120 | + $sqldump .= "-- Create the table if it not exists\n"; | ||
121 | + $sqldump .= "--\n\n"; | ||
122 | + # LOOP: Get the fields for the table | ||
123 | + foreach ($this->db->query("SHOW CREATE TABLE " . $table[0]) AS $field) { | ||
124 | + $sqldump .= str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $field['Create Table']); | ||
125 | + } | ||
126 | + # MYSQL DUMP: New rows | ||
127 | + $sqldump .= ";\n\n\n"; | ||
128 | + /** ** ** ** ** **/ | ||
129 | + # CHECK: There are one or more columns | ||
130 | + if ($c_columns != 0) { | ||
131 | + # MYSQL DUMP: List the data for each table | ||
132 | + $sqldump .= "--\n"; | ||
133 | + $sqldump .= "-- List the data for the table\n"; | ||
134 | + $sqldump .= "--\n\n"; | ||
135 | + # MYSQL DUMP: Insert into each table | ||
136 | + $sqldump .= "INSERT INTO `" . $table[0] . "` ("; | ||
137 | + # ARRAY | ||
138 | + $rows = Array(); | ||
139 | + # LOOP: Get the tables | ||
140 | + foreach ($this->db->query("DESCRIBE " . $table[0]) AS $row) { | ||
141 | + $rows[] = "`" . $row[0] . "`"; | ||
142 | + } | ||
143 | + $sqldump .= implode(', ', $rows); | ||
144 | + $sqldump .= ") VALUES\n"; | ||
145 | + # COUNT | ||
146 | + $c = 0; | ||
147 | + # LOOP: Get the tables | ||
148 | + foreach ($this->db->query("SELECT * FROM " . $table[0]) AS $data) { | ||
149 | + # COUNT | ||
150 | + $c++; | ||
151 | + /** ** ** ** ** **/ | ||
152 | + $sqldump .= "("; | ||
153 | + # ARRAY | ||
154 | + $cdata = Array(); | ||
155 | + # LOOP | ||
156 | + for ($i = 0; $i < $c_rows; $i++) { | ||
157 | + if (is_null($data[$i])) { | ||
158 | + $cdata[] = "null"; | ||
159 | + } else { | ||
160 | + $new_lines = preg_replace('/\s\s+/', '\r\n\r\n', addslashes($data[$i])); | ||
161 | + $cdata[] = "'" . $new_lines . "'"; | ||
162 | + } | ||
163 | + } | ||
164 | + $sqldump .= implode(', ', $cdata); | ||
165 | + $sqldump .= ")"; | ||
166 | + $sqldump .= ($c % 600 != 0 ? ($c_columns != $c ? ',' : ';') : ''); | ||
167 | + # CHECK | ||
168 | + if ($c % 600 == 0) { | ||
169 | + $sqldump .= ";\n\n"; | ||
170 | + } else { | ||
171 | + $sqldump .= "\n"; | ||
172 | + } | ||
173 | + # CHECK | ||
174 | + if ($c % 600 == 0) { | ||
175 | + $sqldump .= "INSERT INTO " . $table[0] . "("; | ||
176 | + # ARRAY | ||
177 | + $rows = Array(); | ||
178 | + # LOOP: Get the tables | ||
179 | + foreach ($this->db->query("DESCRIBE " . $table[0]) AS $row) { | ||
180 | + $rows[] = "`" . $row[0] . "`"; | ||
181 | + } | ||
182 | + $sqldump .= implode(', ', $rows); | ||
183 | + $sqldump .= ") VALUES\n"; | ||
184 | + } | ||
185 | + } | ||
186 | + } | ||
187 | + } | ||
188 | + | ||
189 | + $sqldump .= "\n\n\n"; | ||
190 | + // Backup views | ||
191 | + $tables = $this->db->query("SHOW FULL TABLES WHERE Table_Type = 'VIEW'"); | ||
192 | + # LOOP: Get the tables | ||
193 | + foreach ($tables AS $table) { | ||
194 | + // 忽略表 | ||
195 | + if (in_array($table[0], $this->ignoreTables)) { | ||
196 | + continue; | ||
197 | + } | ||
198 | + foreach ($this->db->query("SHOW CREATE VIEW " . $table[0]) AS $field) { | ||
199 | + $sqldump .= "--\n"; | ||
200 | + $sqldump .= "-- Remove the view if it exists\n"; | ||
201 | + $sqldump .= "--\n\n"; | ||
202 | + $sqldump .= "DROP VIEW IF EXISTS `{$field[0]}`;\n\n"; | ||
203 | + $sqldump .= "--\n"; | ||
204 | + $sqldump .= "-- Create the view if it not exists\n"; | ||
205 | + $sqldump .= "--\n\n"; | ||
206 | + $sqldump .= "{$field[1]};\n\n"; | ||
207 | + } | ||
208 | + } | ||
209 | + return $sqldump; | ||
210 | + | ||
211 | + } | ||
212 | + | ||
213 | +} |
1 | +define(['jquery', 'bootstrap', 'backend', 'template'], function ($, undefined, Backend, Template) { | ||
2 | + | ||
3 | + var Controller = { | ||
4 | + index: function () { | ||
5 | + | ||
6 | + //如果有备份权限 | ||
7 | + if ($("#backuplist").size() > 0) { | ||
8 | + Fast.api.ajax({ | ||
9 | + url: "general/database/backuplist", | ||
10 | + type: 'get' | ||
11 | + }, function (data) { | ||
12 | + $("#backuplist").html(Template("backuptpl", {backuplist: data.backuplist})); | ||
13 | + return false; | ||
14 | + }); | ||
15 | + return false; | ||
16 | + } | ||
17 | + | ||
18 | + //禁止在操作select元素时关闭dropdown的关闭事件 | ||
19 | + $("#database").on('click', '.dropdown-menu input, .dropdown-menu label, .dropdown-menu select', function (e) { | ||
20 | + e.stopPropagation(); | ||
21 | + }); | ||
22 | + | ||
23 | + //提交时检查是否有删除或清空操作 | ||
24 | + $("#database").on("submit", "#sqlexecute", function () { | ||
25 | + var v = $("#sqlquery").val().toLowerCase(); | ||
26 | + if ((v.indexOf("delete ") >= 0 || v.indexOf("truncate ") >= 0) && !confirm(__('Are you sure you want to delete or turncate?'))) { | ||
27 | + return false; | ||
28 | + } | ||
29 | + }); | ||
30 | + | ||
31 | + //事件按钮操作 | ||
32 | + $("#database").on("click", "ul#subaction li input", function () { | ||
33 | + $("#topaction").val($(this).attr("rel")); | ||
34 | + return true; | ||
35 | + }); | ||
36 | + | ||
37 | + //窗口变更的时候重设结果栏高度 | ||
38 | + $(window).on("resize", function () { | ||
39 | + $("#database .well").height($(window).height() - $("#database #sqlexecute").height() - $("#ribbon").outerHeight() - $(".panel-heading").outerHeight() - 130); | ||
40 | + }); | ||
41 | + | ||
42 | + //修复iOS下iframe无法滚动的BUG | ||
43 | + if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) { | ||
44 | + $("#resultparent").css({"-webkit-overflow-scrolling": "touch", "overflow": "auto"}); | ||
45 | + } | ||
46 | + | ||
47 | + $(document).on("click", ".btn-compress", function () { | ||
48 | + Fast.api.ajax({ | ||
49 | + url: "general/database/backuplist", | ||
50 | + type: 'get' | ||
51 | + }, function (data) { | ||
52 | + Layer.open({ | ||
53 | + area: ["680px", "500px"], | ||
54 | + btn: [], | ||
55 | + title: "备份与还原", | ||
56 | + content: Template("backuptpl", {backuplist: data.backuplist}) | ||
57 | + }); | ||
58 | + return false; | ||
59 | + }); | ||
60 | + return false; | ||
61 | + }); | ||
62 | + | ||
63 | + $(document).on("click", ".btn-backup", function () { | ||
64 | + Fast.api.ajax({ | ||
65 | + url: "general/database/backup", | ||
66 | + data: {action: 'backup'} | ||
67 | + }, function (data) { | ||
68 | + Layer.closeAll(); | ||
69 | + $(".btn-compress").trigger("click"); | ||
70 | + }); | ||
71 | + }); | ||
72 | + | ||
73 | + $(document).on("click", ".btn-restore", function () { | ||
74 | + var that = this; | ||
75 | + Layer.confirm("确定恢复备份?<br><font color='red'>建议先备份当前数据后再进行恢复操作!!!</font><br><font color='red'>当前数据库将被清空覆盖,请谨慎操作!!!</font>", { | ||
76 | + type: 5, | ||
77 | + skin: 'layui-layer-dialog layui-layer-fast' | ||
78 | + }, function (index) { | ||
79 | + Fast.api.ajax({ | ||
80 | + url: "general/database/restore", | ||
81 | + data: {action: 'restore', file: $(that).data('file')} | ||
82 | + }, function (data) { | ||
83 | + Layer.closeAll(); | ||
84 | + Fast.api.ajax({ | ||
85 | + url: 'ajax/wipecache', | ||
86 | + data: {type: 'all'}, | ||
87 | + }, function () { | ||
88 | + Layer.alert("备份恢复成功,点击确定将刷新页面", function () { | ||
89 | + top.location.reload(); | ||
90 | + }); | ||
91 | + return false; | ||
92 | + }); | ||
93 | + | ||
94 | + }); | ||
95 | + }); | ||
96 | + }); | ||
97 | + | ||
98 | + $(document).on("click", ".btn-delete", function () { | ||
99 | + var that = this; | ||
100 | + Layer.confirm("确定删除备份?", {type: 5, skin: 'layui-layer-dialog layui-layer-fast'}, function (index) { | ||
101 | + Fast.api.ajax({ | ||
102 | + url: "general/database/restore", | ||
103 | + data: {action: 'delete', file: $(that).data('file')} | ||
104 | + }, function (data) { | ||
105 | + Layer.closeAll(); | ||
106 | + $(".btn-compress").trigger("click"); | ||
107 | + }); | ||
108 | + }); | ||
109 | + }); | ||
110 | + | ||
111 | + $(window).resize(); | ||
112 | + } | ||
113 | + }; | ||
114 | + return Controller; | ||
115 | +}); |
addons/example/Example.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\example; | ||
4 | + | ||
5 | +use app\common\library\Menu; | ||
6 | +use think\Addons; | ||
7 | + | ||
8 | +/** | ||
9 | + * Example | ||
10 | + */ | ||
11 | +class Example extends Addons | ||
12 | +{ | ||
13 | + | ||
14 | + /** | ||
15 | + * 插件安装方法 | ||
16 | + * @return bool | ||
17 | + */ | ||
18 | + public function install() | ||
19 | + { | ||
20 | + $menu = [ | ||
21 | + [ | ||
22 | + 'name' => 'example', | ||
23 | + 'title' => '开发示例管理', | ||
24 | + 'icon' => 'fa fa-magic', | ||
25 | + 'sublist' => [ | ||
26 | + [ | ||
27 | + 'name' => 'example/bootstraptable', | ||
28 | + 'title' => '表格完整示例', | ||
29 | + 'icon' => 'fa fa-table', | ||
30 | + 'sublist' => [ | ||
31 | + ['name' => 'example/bootstraptable/index', 'title' => '查看'], | ||
32 | + ['name' => 'example/bootstraptable/detail', 'title' => '详情'], | ||
33 | + ['name' => 'example/bootstraptable/change', 'title' => '变更'], | ||
34 | + ['name' => 'example/bootstraptable/del', 'title' => '删除'], | ||
35 | + ['name' => 'example/bootstraptable/multi', 'title' => '批量更新'], | ||
36 | + ] | ||
37 | + ], | ||
38 | + [ | ||
39 | + 'name' => 'example/customsearch', | ||
40 | + 'title' => '自定义搜索', | ||
41 | + 'icon' => 'fa fa-table', | ||
42 | + 'sublist' => [ | ||
43 | + ['name' => 'example/customsearch/index', 'title' => '查看'], | ||
44 | + ['name' => 'example/customsearch/del', 'title' => '删除'], | ||
45 | + ['name' => 'example/customsearch/multi', 'title' => '批量更新'], | ||
46 | + ] | ||
47 | + ], | ||
48 | + [ | ||
49 | + 'name' => 'example/customform', | ||
50 | + 'title' => '自定义表单示例', | ||
51 | + 'icon' => 'fa fa-edit', | ||
52 | + 'sublist' => [ | ||
53 | + ['name' => 'example/customform/index', 'title' => '查看'], | ||
54 | + ] | ||
55 | + ], | ||
56 | + [ | ||
57 | + 'name' => 'example/tablelink', | ||
58 | + 'title' => '表格联动示例', | ||
59 | + 'icon' => 'fa fa-table', | ||
60 | + 'remark' => '点击左侧日志列表,右侧的表格数据会显示指定管理员的日志列表', | ||
61 | + 'sublist' => [ | ||
62 | + ['name' => 'example/tablelink/index', 'title' => '查看'], | ||
63 | + ] | ||
64 | + ], | ||
65 | + [ | ||
66 | + 'name' => 'example/colorbadge', | ||
67 | + 'title' => '彩色角标', | ||
68 | + 'icon' => 'fa fa-table', | ||
69 | + 'remark' => '左侧彩色的角标会根据当前数据量的大小进行更新', | ||
70 | + 'sublist' => [ | ||
71 | + ['name' => 'example/colorbadge/index', 'title' => '查看'], | ||
72 | + ['name' => 'example/colorbadge/del', 'title' => '删除'], | ||
73 | + ['name' => 'example/colorbadge/multi', 'title' => '批量更新'], | ||
74 | + ] | ||
75 | + ], | ||
76 | + [ | ||
77 | + 'name' => 'example/controllerjump', | ||
78 | + 'title' => '控制器间跳转', | ||
79 | + 'icon' => 'fa fa-table', | ||
80 | + 'remark' => '点击IP地址可以跳转到新的选项卡中查看指定IP的数据', | ||
81 | + 'sublist' => [ | ||
82 | + ['name' => 'example/controllerjump/index', 'title' => '查看'], | ||
83 | + ['name' => 'example/controllerjump/del', 'title' => '删除'], | ||
84 | + ['name' => 'example/controllerjump/multi', 'title' => '批量更新'], | ||
85 | + ] | ||
86 | + ], | ||
87 | + [ | ||
88 | + 'name' => 'example/cxselect', | ||
89 | + 'title' => '多级联动', | ||
90 | + 'icon' => 'fa fa-table', | ||
91 | + 'remark' => '基于jquery.cxselect实现的多级联动', | ||
92 | + 'sublist' => [ | ||
93 | + ['name' => 'example/cxselect/index', 'title' => '查看'], | ||
94 | + ['name' => 'example/cxselect/del', 'title' => '删除'], | ||
95 | + ['name' => 'example/cxselect/multi', 'title' => '批量更新'], | ||
96 | + ] | ||
97 | + ], | ||
98 | + [ | ||
99 | + 'name' => 'example/multitable', | ||
100 | + 'title' => '多表格示例', | ||
101 | + 'icon' => 'fa fa-table', | ||
102 | + 'remark' => '展示在一个页面显示多个Bootstrap-table表格', | ||
103 | + 'sublist' => [ | ||
104 | + ['name' => 'example/multitable/index', 'title' => '查看'], | ||
105 | + ['name' => 'example/multitable/del', 'title' => '删除'], | ||
106 | + ['name' => 'example/multitable/multi', 'title' => '批量更新'], | ||
107 | + ] | ||
108 | + ], | ||
109 | + [ | ||
110 | + 'name' => 'example/relationmodel', | ||
111 | + 'title' => '关联模型示例', | ||
112 | + 'icon' => 'fa fa-table', | ||
113 | + 'remark' => '列表中的头像、用户名和昵称字段均从关联表中取出', | ||
114 | + 'sublist' => [ | ||
115 | + ['name' => 'example/relationmodel/index', 'title' => '查看'], | ||
116 | + ['name' => 'example/relationmodel/del', 'title' => '删除'], | ||
117 | + ['name' => 'example/relationmodel/multi', 'title' => '批量更新'], | ||
118 | + ] | ||
119 | + ], | ||
120 | + [ | ||
121 | + 'name' => 'example/tabletemplate', | ||
122 | + 'title' => '表格模板示例', | ||
123 | + 'icon' => 'fa fa-table', | ||
124 | + 'remark' => '', | ||
125 | + 'sublist' => [ | ||
126 | + ['name' => 'example/tabletemplate/index', 'title' => '查看'], | ||
127 | + ['name' => 'example/tabletemplate/detail', 'title' => '详情'], | ||
128 | + ['name' => 'example/tabletemplate/del', 'title' => '删除'], | ||
129 | + ['name' => 'example/tabletemplate/multi', 'title' => '批量更新'], | ||
130 | + ] | ||
131 | + ], | ||
132 | + [ | ||
133 | + 'name' => 'example/baidumap', | ||
134 | + 'title' => '百度地图示例', | ||
135 | + 'icon' => 'fa fa-map-pin', | ||
136 | + 'sublist' => [ | ||
137 | + ['name' => 'example/baidumap/index', 'title' => '查看'], | ||
138 | + ['name' => 'example/baidumap/map', 'title' => '详情'], | ||
139 | + ['name' => 'example/baidumap/del', 'title' => '删除'], | ||
140 | + ] | ||
141 | + ], | ||
142 | + [ | ||
143 | + 'name' => 'example/echarts', | ||
144 | + 'title' => '统计图表示例', | ||
145 | + 'icon' => 'fa fa-bar-chart', | ||
146 | + 'sublist' => [ | ||
147 | + ['name' => 'example/echarts/index', 'title' => '查看'], | ||
148 | + ] | ||
149 | + ], | ||
150 | + ] | ||
151 | + ] | ||
152 | + ]; | ||
153 | + Menu::create($menu); | ||
154 | + return true; | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * 插件卸载方法 | ||
159 | + * @return bool | ||
160 | + */ | ||
161 | + public function uninstall() | ||
162 | + { | ||
163 | + Menu::delete('example'); | ||
164 | + return true; | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * 插件启用方法 | ||
169 | + */ | ||
170 | + public function enable() | ||
171 | + { | ||
172 | + Menu::enable('example'); | ||
173 | + } | ||
174 | + | ||
175 | + /** | ||
176 | + * 插件禁用方法 | ||
177 | + */ | ||
178 | + public function disable() | ||
179 | + { | ||
180 | + Menu::disable('example'); | ||
181 | + } | ||
182 | + | ||
183 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 百度地图 | ||
9 | + * | ||
10 | + * @icon fa fa-map | ||
11 | + * @remark 可以搜索百度位置,调用百度地图的相关API | ||
12 | + */ | ||
13 | +class Baidumap extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + } | ||
22 | + | ||
23 | + /** | ||
24 | + * 查找地图 | ||
25 | + */ | ||
26 | + public function map() | ||
27 | + { | ||
28 | + return $this->view->fetch(); | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * 搜索列表 | ||
33 | + */ | ||
34 | + public function selectpage() | ||
35 | + { | ||
36 | + $this->model = model('Area'); | ||
37 | + return parent::selectpage(); | ||
38 | + } | ||
39 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 表格完整示例 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + * @remark 在使用Bootstrap-table中的常用方式,更多使用方式可查看:http://bootstrap-table.wenzhixin.net.cn/zh-cn/ | ||
12 | + */ | ||
13 | +class Bootstraptable extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + /** | ||
17 | + * 无需鉴权的方法(需登录) | ||
18 | + * @var array | ||
19 | + */ | ||
20 | + protected $noNeedRight = ['start', 'pause', 'change', 'detail', 'cxselect', 'searchlist']; | ||
21 | + /** | ||
22 | + * 快捷搜索的字段 | ||
23 | + * @var string | ||
24 | + */ | ||
25 | + protected $searchFields = 'id,title,url'; | ||
26 | + | ||
27 | + public function _initialize() | ||
28 | + { | ||
29 | + parent::_initialize(); | ||
30 | + $this->model = model('AdminLog'); | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * 查看 | ||
35 | + */ | ||
36 | + public function index() | ||
37 | + { | ||
38 | + if ($this->request->isAjax()) { | ||
39 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(null); | ||
40 | + $total = $this->model | ||
41 | + ->where($where) | ||
42 | + ->order($sort, $order) | ||
43 | + ->count(); | ||
44 | + $list = $this->model | ||
45 | + ->where($where) | ||
46 | + ->order($sort, $order) | ||
47 | + ->limit($offset, $limit) | ||
48 | + ->select(); | ||
49 | + $result = array("total" => $total, "rows" => $list, "extend" => ['money' => mt_rand(100000, 999999), 'price' => 200]); | ||
50 | + | ||
51 | + return json($result); | ||
52 | + } | ||
53 | + return $this->view->fetch(); | ||
54 | + } | ||
55 | + | ||
56 | + /** | ||
57 | + * 详情 | ||
58 | + */ | ||
59 | + public function detail($ids) | ||
60 | + { | ||
61 | + $row = $this->model->get(['id' => $ids]); | ||
62 | + if (!$row) { | ||
63 | + $this->error(__('No Results were found')); | ||
64 | + } | ||
65 | + if ($this->request->isAjax()) { | ||
66 | + $this->success("Ajax请求成功", null, ['id' => $ids]); | ||
67 | + } | ||
68 | + $this->view->assign("row", $row->toArray()); | ||
69 | + return $this->view->fetch(); | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * 启用 | ||
74 | + */ | ||
75 | + public function start($ids = '') | ||
76 | + { | ||
77 | + $this->success("模拟启动成功"); | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * 暂停 | ||
82 | + */ | ||
83 | + public function pause($ids = '') | ||
84 | + { | ||
85 | + $this->success("模拟暂停成功"); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * 切换 | ||
90 | + */ | ||
91 | + public function change($ids = '') | ||
92 | + { | ||
93 | + //你需要在此做具体的操作逻辑 | ||
94 | + | ||
95 | + $this->success("模拟切换成功"); | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * 联动搜索 | ||
100 | + */ | ||
101 | + public function cxselect() | ||
102 | + { | ||
103 | + $type = $this->request->get('type'); | ||
104 | + $group_id = $this->request->get('group_id'); | ||
105 | + $list = null; | ||
106 | + if ($group_id !== '') { | ||
107 | + if ($type == 'group') { | ||
108 | + $groupIds = $this->auth->getChildrenGroupIds(true); | ||
109 | + $list = \app\admin\model\AuthGroup::where('id', 'in', $groupIds)->field('id as value, name')->select(); | ||
110 | + } else { | ||
111 | + $adminIds = \app\admin\model\AuthGroupAccess::where('group_id', 'in', $group_id)->column('uid'); | ||
112 | + $list = \app\admin\model\Admin::where('id', 'in', $adminIds)->field('id as value, username AS name')->select(); | ||
113 | + } | ||
114 | + } | ||
115 | + $this->success('', null, $list); | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * 搜索下拉列表 | ||
120 | + */ | ||
121 | + public function searchlist() | ||
122 | + { | ||
123 | + $result = $this->model->limit(10)->select(); | ||
124 | + $searchlist = []; | ||
125 | + foreach ($result as $key => $value) { | ||
126 | + $searchlist[] = ['id' => $value['url'], 'name' => $value['url']]; | ||
127 | + } | ||
128 | + $data = ['searchlist' => $searchlist]; | ||
129 | + $this->success('', null, $data); | ||
130 | + } | ||
131 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 彩色角标 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + * @remark 在JS端控制角标的显示与隐藏,请注意左侧菜单栏角标的数值变化 | ||
12 | + */ | ||
13 | +class Colorbadge extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + } | ||
22 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 控制器间跳转 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + * @remark FastAdmin支持在控制器间跳转,点击后将切换到另外一个TAB中,无需刷新当前页面 | ||
12 | + */ | ||
13 | +class Controllerjump extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + } | ||
22 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 自定义表单示例 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + * @remark FastAdmin支持在控制器间跳转,点击后将切换到另外一个TAB中,无需刷新当前页面 | ||
12 | + */ | ||
13 | +class Customform extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + } | ||
22 | + | ||
23 | + public function index() | ||
24 | + { | ||
25 | + if ($this->request->isPost()) { | ||
26 | + $this->success("提交成功", null, ['data' => json_encode($this->request->post("row/a"), JSON_UNESCAPED_UNICODE)]); | ||
27 | + } | ||
28 | + return $this->view->fetch(); | ||
29 | + } | ||
30 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 自定义搜索 | ||
9 | + * | ||
10 | + * @icon fa fa-search | ||
11 | + * @remark 自定义列表的搜索 | ||
12 | + */ | ||
13 | +class Customsearch extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + $ipList = $this->model->whereTime('createtime', '-37 days')->group("ip")->column("ip,ip as aa"); | ||
22 | + $this->view->assign("ipList", $ipList); | ||
23 | + } | ||
24 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 多级联动 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + * @remark FastAdmin使用了jQuery-cxselect实现多级联动,更多文档请参考https://github.com/karsonzhang/cxSelect | ||
12 | + */ | ||
13 | +class Cxselect extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + } | ||
21 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 统计图表示例 | ||
9 | + * | ||
10 | + * @icon fa fa-charts | ||
11 | + * @remark 展示在FastAdmin中使用Echarts展示丰富多彩的统计图表 | ||
12 | + */ | ||
13 | +class Echarts extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + } | ||
22 | + | ||
23 | + /** | ||
24 | + * 查看 | ||
25 | + */ | ||
26 | + public function index() | ||
27 | + { | ||
28 | + | ||
29 | + return $this->view->fetch(); | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * 详情 | ||
34 | + */ | ||
35 | + public function detail($ids) | ||
36 | + { | ||
37 | + $row = $this->model->get(['id' => $ids]); | ||
38 | + if (!$row) { | ||
39 | + $this->error(__('No Results were found')); | ||
40 | + } | ||
41 | + $this->view->assign("row", $row->toArray()); | ||
42 | + return $this->view->fetch(); | ||
43 | + } | ||
44 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 多表格示例 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + * @remark 当一个页面上存在多个Bootstrap-table时该如何控制按钮和表格 | ||
12 | + */ | ||
13 | +class Multitable extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + protected $noNeedRight = ['table1', 'table2']; | ||
17 | + | ||
18 | + public function _initialize() | ||
19 | + { | ||
20 | + parent::_initialize(); | ||
21 | + } | ||
22 | + | ||
23 | + /** | ||
24 | + * 查看 | ||
25 | + */ | ||
26 | + public function index() | ||
27 | + { | ||
28 | + $this->loadlang('general/attachment'); | ||
29 | + $this->loadlang('general/crontab'); | ||
30 | + return $this->view->fetch(); | ||
31 | + } | ||
32 | + | ||
33 | + public function table1() | ||
34 | + { | ||
35 | + $this->model = model('Attachment'); | ||
36 | + //设置过滤方法 | ||
37 | + $this->request->filter(['strip_tags']); | ||
38 | + if ($this->request->isAjax()) { | ||
39 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
40 | + if ($this->request->request('keyField')) { | ||
41 | + return $this->selectpage(); | ||
42 | + } | ||
43 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
44 | + $total = $this->model | ||
45 | + ->where($where) | ||
46 | + ->order($sort, $order) | ||
47 | + ->count(); | ||
48 | + | ||
49 | + $list = $this->model | ||
50 | + ->where($where) | ||
51 | + ->order($sort, $order) | ||
52 | + ->limit($offset, $limit) | ||
53 | + ->select(); | ||
54 | + | ||
55 | + $result = array("total" => $total, "rows" => $list); | ||
56 | + | ||
57 | + return json($result); | ||
58 | + } | ||
59 | + return $this->view->fetch('index'); | ||
60 | + } | ||
61 | + | ||
62 | + public function table2() | ||
63 | + { | ||
64 | + $this->model = model('AdminLog'); | ||
65 | + //设置过滤方法 | ||
66 | + $this->request->filter(['strip_tags']); | ||
67 | + if ($this->request->isAjax()) { | ||
68 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
69 | + if ($this->request->request('keyField')) { | ||
70 | + return $this->selectpage(); | ||
71 | + } | ||
72 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
73 | + $total = $this->model | ||
74 | + ->where($where) | ||
75 | + ->order($sort, $order) | ||
76 | + ->count(); | ||
77 | + | ||
78 | + $list = $this->model | ||
79 | + ->where($where) | ||
80 | + ->order($sort, $order) | ||
81 | + ->limit($offset, $limit) | ||
82 | + ->select(); | ||
83 | + | ||
84 | + $result = array("total" => $total, "rows" => $list); | ||
85 | + | ||
86 | + return json($result); | ||
87 | + } | ||
88 | + return $this->view->fetch('index'); | ||
89 | + } | ||
90 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 关联模型 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + * @remark 当使用到关联模型时需要重载index方法 | ||
12 | + */ | ||
13 | +class Relationmodel extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + } | ||
22 | + | ||
23 | + /** | ||
24 | + * 查看 | ||
25 | + */ | ||
26 | + public function index() | ||
27 | + { | ||
28 | + $this->relationSearch = true; | ||
29 | + $this->searchFields = "admin.username,id"; | ||
30 | + if ($this->request->isAjax()) { | ||
31 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
32 | + $total = $this->model | ||
33 | + ->with("admin") | ||
34 | + ->where($where) | ||
35 | + ->order($sort, $order) | ||
36 | + ->count(); | ||
37 | + $list = $this->model | ||
38 | + ->with("admin") | ||
39 | + ->where($where) | ||
40 | + ->order($sort, $order) | ||
41 | + ->limit($offset, $limit) | ||
42 | + ->select(); | ||
43 | + $result = array("total" => $total, "rows" => $list); | ||
44 | + | ||
45 | + return json($result); | ||
46 | + } | ||
47 | + return $this->view->fetch(); | ||
48 | + } | ||
49 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 表格联动 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + */ | ||
12 | +class Tablelink extends Backend | ||
13 | +{ | ||
14 | + protected $model = null; | ||
15 | + protected $noNeedRight = ['table1', 'table2']; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + } | ||
22 | + | ||
23 | + | ||
24 | + public function table1() | ||
25 | + { | ||
26 | + $this->model = model('Admin'); | ||
27 | + //设置过滤方法 | ||
28 | + $this->request->filter(['strip_tags']); | ||
29 | + if ($this->request->isAjax()) { | ||
30 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
31 | + if ($this->request->request('keyField')) { | ||
32 | + return $this->selectpage(); | ||
33 | + } | ||
34 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
35 | + $total = $this->model | ||
36 | + ->where($where) | ||
37 | + ->order($sort, $order) | ||
38 | + ->count(); | ||
39 | + | ||
40 | + $list = $this->model | ||
41 | + ->where($where) | ||
42 | + ->order($sort, $order) | ||
43 | + ->limit($offset, $limit) | ||
44 | + ->select(); | ||
45 | + | ||
46 | + $result = array("total" => $total, "rows" => $list); | ||
47 | + | ||
48 | + return json($result); | ||
49 | + } | ||
50 | + return $this->view->fetch('index'); | ||
51 | + } | ||
52 | + | ||
53 | + public function table2() | ||
54 | + { | ||
55 | + $this->model = model('AdminLog'); | ||
56 | + //设置过滤方法 | ||
57 | + $this->request->filter(['strip_tags']); | ||
58 | + if ($this->request->isAjax()) { | ||
59 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
60 | + if ($this->request->request('keyField')) { | ||
61 | + return $this->selectpage(); | ||
62 | + } | ||
63 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
64 | + $total = $this->model | ||
65 | + ->where($where) | ||
66 | + ->order($sort, $order) | ||
67 | + ->count(); | ||
68 | + | ||
69 | + $list = $this->model | ||
70 | + ->where($where) | ||
71 | + ->order($sort, $order) | ||
72 | + ->limit($offset, $limit) | ||
73 | + ->select(); | ||
74 | + | ||
75 | + $result = array("total" => $total, "rows" => $list); | ||
76 | + | ||
77 | + return json($result); | ||
78 | + } | ||
79 | + return $this->view->fetch('index'); | ||
80 | + } | ||
81 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\example; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | + | ||
7 | +/** | ||
8 | + * 表格模板示例 | ||
9 | + * | ||
10 | + * @icon fa fa-table | ||
11 | + * @remark 可以通过使用表格模板将表格中的行渲染成一样的展现方式,基于此功能可以任意定制自己想要的展示列表 | ||
12 | + */ | ||
13 | +class Tabletemplate extends Backend | ||
14 | +{ | ||
15 | + protected $model = null; | ||
16 | + | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + parent::_initialize(); | ||
20 | + $this->model = model('AdminLog'); | ||
21 | + } | ||
22 | + | ||
23 | + /** | ||
24 | + * 查看 | ||
25 | + */ | ||
26 | + public function index() | ||
27 | + { | ||
28 | + if ($this->request->isAjax()) { | ||
29 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(null); | ||
30 | + $total = $this->model | ||
31 | + ->where($where) | ||
32 | + ->order($sort, $order) | ||
33 | + ->count(); | ||
34 | + $list = $this->model | ||
35 | + ->where($where) | ||
36 | + ->order($sort, $order) | ||
37 | + ->limit($offset, $limit) | ||
38 | + ->select(); | ||
39 | + $result = array("total" => $total, "rows" => $list); | ||
40 | + | ||
41 | + return json($result); | ||
42 | + } | ||
43 | + return $this->view->fetch(); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * 详情 | ||
48 | + */ | ||
49 | + public function detail($ids) | ||
50 | + { | ||
51 | + $row = $this->model->get(['id' => $ids]); | ||
52 | + if (!$row) { | ||
53 | + $this->error(__('No Results were found')); | ||
54 | + } | ||
55 | + $this->view->assign("row", $row->toArray()); | ||
56 | + return $this->view->fetch(); | ||
57 | + } | ||
58 | +} |
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 | + {:build_toolbar('refresh,delete')} | ||
10 | + <a href="example/baidumap/map" class="btn btn-info btn-dialog" title="地图"><i class="fa fa-map-signs"></i> 地图</a> | ||
11 | + </div> | ||
12 | + <table id="table" class="table table-striped table-bordered table-hover" width="100%"> | ||
13 | + | ||
14 | + </table> | ||
15 | + | ||
16 | + </div> | ||
17 | + </div> | ||
18 | + | ||
19 | + </div> | ||
20 | + </div> | ||
21 | +</div> |
1 | +{__NOLAYOUT__} | ||
2 | +<!DOCTYPE html> | ||
3 | +<html lang="{$config.language}"> | ||
4 | + <head> | ||
5 | + {include file="common/meta" /} | ||
6 | + <style type="text/css"> | ||
7 | + body, html,#allmap{width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";} | ||
8 | + #search{position:absolute;top:20px;left:20px;} | ||
9 | + </style> | ||
10 | + </head> | ||
11 | + | ||
12 | + <body class="inside-header inside-aside {:defined('IS_DIALOG') && IS_DIALOG ? 'is-dialog' : ''}"> | ||
13 | + <div class="container-fluid" id="search"> | ||
14 | + <div class="row"> | ||
15 | + <div class="col-xs-12 col-sm-4"> | ||
16 | + <form role="form" action=""> | ||
17 | + <div class="input-group" style="width:300px;"> | ||
18 | + <input type="text" id="searchaddress" class="form-control selectpage" data-primary-key="name" data-source="example/baidumap/selectpage" /> | ||
19 | + <span class="input-group-btn"> | ||
20 | + <button class="btn btn-success btn-search" type="button">搜索</button> | ||
21 | + </span> | ||
22 | + </div> | ||
23 | + </form> | ||
24 | + </div> | ||
25 | + </div> | ||
26 | + </div> | ||
27 | + <div id='allmap'></div> | ||
28 | + {include file="common/script" /} | ||
29 | + </body> | ||
30 | +</html> |
1 | +<table class="table table-striped"> | ||
2 | + <thead> | ||
3 | + <tr> | ||
4 | + <th>{:__('Title')}</th> | ||
5 | + <th>{:__('Content')}</th> | ||
6 | + </tr> | ||
7 | + </thead> | ||
8 | + <tbody> | ||
9 | + {volist name="row" id="vo" } | ||
10 | + <tr> | ||
11 | + <td>{$key}</td> | ||
12 | + <td>{$vo}</td> | ||
13 | + </tr> | ||
14 | + {/volist} | ||
15 | + {if $Think.get.dialog} | ||
16 | + <tr> | ||
17 | + <td>回传数据</td> | ||
18 | + <td> | ||
19 | + <div class="input-group"> | ||
20 | + <input name="callback" class="form-control" value="test" /> | ||
21 | + <span class="input-group-btn"><a href="javascript:;" class="btn btn-success btn-callback" >回传数据</a></span> | ||
22 | + </div> | ||
23 | + </td> | ||
24 | + </tr> | ||
25 | + {/if} | ||
26 | + </tbody> | ||
27 | +</table> | ||
28 | +<div class="hide layer-footer"> | ||
29 | + <label class="control-label col-xs-12 col-sm-2"></label> | ||
30 | + <div class="col-xs-12 col-sm-8"> | ||
31 | + <button type="reset" class="btn btn-primary btn-embossed btn-close" onclick="Layer.closeAll();">{:__('Close')}</button> | ||
32 | + </div> | ||
33 | +</div> |
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 | + {:build_toolbar('refresh,delete')} | ||
10 | + <a class="btn btn-info btn-disabled disabled btn-selected" href="javascript:;"><i class="fa fa-leaf"></i> 获取选中项</a> | ||
11 | + <div class="dropdown btn-group"> | ||
12 | + <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> <?= __('More') ?></a> | ||
13 | + <ul class="dropdown-menu text-left" role="menu"> | ||
14 | + <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> | ||
15 | + <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> | ||
16 | + </ul> | ||
17 | + </div> | ||
18 | + <a class="btn btn-success btn-singlesearch" href="javascript:;"><i class="fa fa-user"></i> 自定义搜索</a> | ||
19 | + <a class="btn btn-success btn-change btn-start" data-params="action=start" data-url="example/bootstraptable/start" href="javascript:;"><i class="fa fa-play"></i> 启动</a> | ||
20 | + <a class="btn btn-danger btn-change btn-pause" data-params="action=pause" data-url="example/bootstraptable/pause" href="javascript:;"><i class="fa fa-pause"></i> 暂停</a> | ||
21 | + <a href="javascript:;" class="btn btn-default" style="font-size:14px;color:dodgerblue;"> | ||
22 | + <i class="fa fa-dollar"></i> | ||
23 | + <span class="extend"> | ||
24 | + 金额:<span id="money">0</span> | ||
25 | + 单价:<span id="price">0</span> | ||
26 | + </span> | ||
27 | + </a> | ||
28 | + </div> | ||
29 | + <table id="table" class="table table-striped table-bordered table-hover" width="100%"> | ||
30 | + | ||
31 | + </table> | ||
32 | + | ||
33 | + </div> | ||
34 | + </div> | ||
35 | + | ||
36 | + </div> | ||
37 | + </div> | ||
38 | +</div> | ||
39 | +<script id="categorytpl" type="text/html"> | ||
40 | + <div class="row"> | ||
41 | + <div class="col-xs-12"> | ||
42 | + <div class="form-inline" data-toggle="cxselect" data-selects="group,admin"> | ||
43 | + <select class="group form-control" name="group" data-url="example/bootstraptable/cxselect?type=group"></select> | ||
44 | + <select class="admin form-control" name="admin_id" data-url="example/bootstraptable/cxselect?type=admin" data-query-name="group_id"></select> | ||
45 | + <input type="hidden" class="operate" data-name="admin_id" value="=" /> | ||
46 | + </div> | ||
47 | + </div> | ||
48 | + </div> | ||
49 | +</script> |
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 | + {:build_toolbar('refresh,delete')} | ||
10 | + </div> | ||
11 | + <table id="table" class="table table-striped table-bordered table-hover" width="100%"> | ||
12 | + | ||
13 | + </table> | ||
14 | + | ||
15 | + | ||
16 | + </div> | ||
17 | + </div> | ||
18 | + | ||
19 | + </div> | ||
20 | + </div> | ||
21 | +</div> |
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 | + {:build_toolbar('refresh,delete')} | ||
10 | + </div> | ||
11 | + <table id="table" class="table table-striped table-bordered table-hover" width="100%"> | ||
12 | + | ||
13 | + </table> | ||
14 | + | ||
15 | + | ||
16 | + </div> | ||
17 | + </div> | ||
18 | + | ||
19 | + </div> | ||
20 | + </div> | ||
21 | +</div> |
1 | +<div class="row"> | ||
2 | + <div class="col-md-6"> | ||
3 | + <div class="box box-success"> | ||
4 | + <div class="panel-heading"> | ||
5 | + {:__('自定义图片描述')} | ||
6 | + </div> | ||
7 | + <div class="panel-body"> | ||
8 | + <div class="alert alert-success-light"> | ||
9 | + <b>温馨提示</b><br> | ||
10 | + 默认我们的多图是没有图片描述的,如果我们需要自定义描述,可以使用以下的自定义功能<br> | ||
11 | + 特别注意的是图片的url和描述是分开储存的,也就是说图片一个字段,描述一个字段,你在前台使用时需要自己匹配映射关系<br> | ||
12 | + <b>下面的演示textarea为了便于调试,设置为可见的,实际使用中应该添加个hidden的class进行隐藏</b> | ||
13 | + </div> | ||
14 | + <form id="first-form" role="form" data-toggle="validator" method="POST" action=""> | ||
15 | + <div class="form-group row"> | ||
16 | + <label class="control-label col-xs-12 col-sm-2">{:__('一维数组示例')}:</label> | ||
17 | + <div class="col-xs-12 col-sm-8"> | ||
18 | + <div class="input-group"> | ||
19 | + <input id="c-files" data-rule="required" class="form-control" size="50" name="row[files]" type="text" value="https://cdn.fastadmin.net/uploads/addons/blog.png,https://cdn.fastadmin.net/uploads/addons/cms.png,https://cdn.fastadmin.net/uploads/addons/vote.png"> | ||
20 | + <div class="input-group-addon no-border no-padding"> | ||
21 | + <span><button type="button" id="plupload-files" class="btn btn-danger plupload" data-input-id="c-files" data-mimetype="*" data-multiple="true" data-preview-id="p-files"><i class="fa fa-upload"></i> {:__('Upload')}</button></span> | ||
22 | + <span><button type="button" id="fachoose-files" class="btn btn-primary fachoose" data-input-id="c-files" data-mimetype="*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span> | ||
23 | + </div> | ||
24 | + <span class="msg-box n-right" for="c-files"></span> | ||
25 | + </div> | ||
26 | + | ||
27 | + <!--ul需要添加 data-template和data-name属性,并一一对应且唯一 --> | ||
28 | + <ul class="row list-inline plupload-preview" id="p-files" data-template="introtpl" data-name="row[intro]"></ul> | ||
29 | + | ||
30 | + <!--请注意 ul和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏--> | ||
31 | + <textarea name="row[intro]" class="form-control" style="margin-top:5px;">["简洁响应式博客","CMS内容管理系统","在线投票系统"]</textarea> | ||
32 | + | ||
33 | + <!--这里自定义图片预览的模板 开始--> | ||
34 | + <script type="text/html" id="introtpl"> | ||
35 | + <li class="col-xs-3"> | ||
36 | + <a href="<%=fullurl%>" data-url="<%=url%>" target="_blank" class="thumbnail"> | ||
37 | + <img src="<%=fullurl%>" class="img-responsive"> | ||
38 | + </a> | ||
39 | + <input type="text" name="row[intro][<%=index%>]" class="form-control" placeholder="请输入文件描述" value="<%=value?value:''%>"/> | ||
40 | + <a href="javascript:;" class="btn btn-danger btn-xs btn-trash"><i class="fa fa-trash"></i></a> | ||
41 | + </li> | ||
42 | + </script> | ||
43 | + <!--这里自定义图片预览的模板 结束--> | ||
44 | + </div> | ||
45 | + </div> | ||
46 | + <div class="form-group row"> | ||
47 | + <label class="control-label col-xs-12 col-sm-2">{:__('二维数组示例')}:</label> | ||
48 | + <div class="col-xs-12 col-sm-8"> | ||
49 | + <div class="input-group"> | ||
50 | + <input id="c-images" data-rule="required" class="form-control" size="50" name="row[images]" type="text" value="https://cdn.fastadmin.net/uploads/addons/example.png,https://cdn.fastadmin.net/uploads/addons/upyun.png,https://cdn.fastadmin.net/uploads/addons/alioss.png"> | ||
51 | + <div class="input-group-addon no-border no-padding"> | ||
52 | + <span><button type="button" id="plupload-images" class="btn btn-danger plupload" data-input-id="c-images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="true" data-preview-id="p-images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span> | ||
53 | + <span><button type="button" id="fachoose-images" class="btn btn-primary fachoose" data-input-id="c-images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span> | ||
54 | + </div> | ||
55 | + <span class="msg-box n-right" for="c-images"></span> | ||
56 | + </div> | ||
57 | + | ||
58 | + <!--ul需要添加 data-template和data-name属性,并一一对应且唯一 --> | ||
59 | + <ul class="row list-inline plupload-preview" id="p-images" data-template="desctpl" data-name="row[desc]"></ul> | ||
60 | + | ||
61 | + <!--请注意 ul和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏--> | ||
62 | + <textarea name="row[desc]" class="form-control" style="margin-top:5px;">[{"info":"开发者示例插件","size":"1M"},{"info":"又拍云储存整合","size":"2M"},{"info":"阿里OSS云储存","size":"1M"}]</textarea> | ||
63 | + | ||
64 | + <!--这里自定义图片预览的模板 开始--> | ||
65 | + <script type="text/html" id="desctpl"> | ||
66 | + <li class="col-xs-3"> | ||
67 | + <a href="<%=fullurl%>" data-url="<%=url%>" target="_blank" class="thumbnail"> | ||
68 | + <img src="<%=fullurl%>" class="img-responsive"> | ||
69 | + </a> | ||
70 | + <input type="text" name="row[desc][<%=index%>][info]" class="form-control" placeholder="请输入插件描述" value="<%=value?value['info']:''%>"/> | ||
71 | + <input type="text" name="row[desc][<%=index%>][size]" class="form-control" placeholder="请输入插件大小" value="<%=value?value['size']:''%>"/> | ||
72 | + <a href="javascript:;" class="btn btn-danger btn-xs btn-trash"><i class="fa fa-trash"></i></a> | ||
73 | + </li> | ||
74 | + </script> | ||
75 | + <!--这里自定义图片预览的模板 结束--> | ||
76 | + </div> | ||
77 | + </div> | ||
78 | + <div class="form-group row"> | ||
79 | + <label class="control-label col-xs-12 col-sm-2"></label> | ||
80 | + <div class="col-xs-12 col-sm-8"> | ||
81 | + <button type="submit" class="btn btn-success btn-embossed">{:__('OK')}</button> | ||
82 | + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button> | ||
83 | + </div> | ||
84 | + </div> | ||
85 | + | ||
86 | + </form> | ||
87 | + </div> | ||
88 | + </div> | ||
89 | + | ||
90 | + </div> | ||
91 | + <div class="col-md-6"> | ||
92 | + <div class="box box-info"> | ||
93 | + <div class="panel-heading"> | ||
94 | + {:__('自定义Fieldlist示例')} | ||
95 | + </div> | ||
96 | + <div class="panel-body"> | ||
97 | + <div class="alert alert-danger-light"> | ||
98 | + <b>温馨提示</b><br> | ||
99 | + 默认我们的fieldlist只有一维数组,为键值形式,如果需要二维数组,可使用下面的自定义模板来实现<br> | ||
100 | + 默认追加的元素是没有进行事件绑定的,我们需要监听btn-append这个按钮的fa.event.appendfieldlist事件<br> | ||
101 | + <b>下面的演示textarea为了便于调试,设置为可见的,实际使用中应该添加个hidden的class进行隐藏</b> | ||
102 | + </div> | ||
103 | + <form id="second-form" role="form" data-toggle="validator" method="POST" action=""> | ||
104 | + | ||
105 | + <div class="form-group row"> | ||
106 | + <label class="control-label col-xs-12 col-sm-2">{:__('Fieldlist示例')}:</label> | ||
107 | + <div class="col-xs-12 col-sm-8"> | ||
108 | + <dl class="fieldlist" data-template="basictpl" data-name="row[basic]"> | ||
109 | + <dd> | ||
110 | + <ins>{:__('标题')}</ins> | ||
111 | + <ins>{:__('介绍')}</ins> | ||
112 | + <ins>{:__('大小')}</ins> | ||
113 | + </dd> | ||
114 | + <dd><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></dd> | ||
115 | + <!--请注意 dd和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏--> | ||
116 | + <textarea name="row[basic]" class="form-control" cols="30" rows="5">[{"title":"开发者示例插件","intro":"开发者必备","size":"1M"},{"title":"又拍云储存整合","intro":"一款云储存","size":"2M"},{"title":"阿里OSS云储存","intro":"一款云储存","size":"1M"}]</textarea> | ||
117 | + </dl> | ||
118 | + <script id="basictpl" type="text/html"> | ||
119 | + <dd class="form-inline"> | ||
120 | + <ins><input type="text" name="<%=name%>[<%=index%>][title]" class="form-control" value="<%=row.title%>" placeholder="标题" size="10"/></ins> | ||
121 | + <ins><input type="text" name="<%=name%>[<%=index%>][intro]" class="form-control" value="<%=row.intro%>" placeholder="描述"/></ins> | ||
122 | + <ins><input type="text" name="<%=name%>[<%=index%>][size]" class="form-control" value="<%=row.size%>" placeholder="大小"/></ins> | ||
123 | + <!--下面的两个按钮务必保留--> | ||
124 | + <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span> | ||
125 | + <span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span> | ||
126 | + </dd> | ||
127 | + </script> | ||
128 | + </div> | ||
129 | + </div> | ||
130 | + <div class="form-group row"> | ||
131 | + <label class="control-label col-xs-12 col-sm-2">{:__('元素事件')}:</label> | ||
132 | + <div class="col-xs-12 col-sm-8"> | ||
133 | + <dl class="fieldlist" data-template="eventtpl" data-name="row[event]"> | ||
134 | + <dd> | ||
135 | + <ins>{:__('管理员')}</ins> | ||
136 | + <ins>{:__('名称')}</ins> | ||
137 | + <ins>{:__('登录时间')}</ins> | ||
138 | + </dd> | ||
139 | + <dd><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></dd> | ||
140 | + <!--请注意 dd和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏--> | ||
141 | + <textarea name="row[event]" class="form-control" cols="30" rows="5">[{"id":"1","name":"admin","time":"2019-06-28 12:05:03"}]</textarea> | ||
142 | + </dl> | ||
143 | + <script id="eventtpl" type="text/html"> | ||
144 | + <dd class="form-inline"> | ||
145 | + <ins><input type="text" name="<%=name%>[<%=index%>][id]" class="form-control selectpage" data-source="auth/admin/selectpage" data-field="username" value="<%=row.id%>" placeholder="管理员" size="10"/></ins> | ||
146 | + <ins><input type="text" name="<%=name%>[<%=index%>][name]" class="form-control" value="<%=row.name%>" placeholder="名称"/></ins> | ||
147 | + <ins><input type="text" name="<%=name%>[<%=index%>][time]" class="form-control datetimepicker" value="<%=row.time%>" placeholder="时间"/></ins> | ||
148 | + <!--下面的两个按钮务必保留--> | ||
149 | + <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span> | ||
150 | + <span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span> | ||
151 | + </dd> | ||
152 | + </script> | ||
153 | + </div> | ||
154 | + </div> | ||
155 | + <div class="form-group row"> | ||
156 | + <label class="control-label col-xs-12 col-sm-2"></label> | ||
157 | + <div class="col-xs-12 col-sm-8"> | ||
158 | + <button type="submit" class="btn btn-success btn-embossed">{:__('OK')}</button> | ||
159 | + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button> | ||
160 | + </div> | ||
161 | + </div> | ||
162 | + | ||
163 | + </form> | ||
164 | + </div> | ||
165 | + </div> | ||
166 | + | ||
167 | + </div> | ||
168 | +</div> |
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 | + {:build_toolbar('refresh')} | ||
10 | + </div> | ||
11 | + <table id="table" class="table table-striped table-bordered table-hover" width="100%"> | ||
12 | + | ||
13 | + </table> | ||
14 | + | ||
15 | + </div> | ||
16 | + </div> | ||
17 | + | ||
18 | + </div> | ||
19 | + </div> | ||
20 | +</div> | ||
21 | + | ||
22 | +<script id="customformtpl" type="text/html"> | ||
23 | + <!--form表单必须添加form-commsearch这个类--> | ||
24 | + <form action="" class="form-commonsearch"> | ||
25 | + <div style="border-radius:2px;margin-bottom:10px;background:#f5f5f5;padding:15px 20px;"> | ||
26 | + <h4>自定义搜索表单</h4> | ||
27 | + <hr> | ||
28 | + <div class="row"> | ||
29 | + <div class="col-xs-12 col-sm-6 col-md-3"> | ||
30 | + <div class="form-group"> | ||
31 | + <label class="control-label">ID</label> | ||
32 | + <!--显式的operate操作符--> | ||
33 | + <div class="input-group"> | ||
34 | + <div class="input-group-btn"> | ||
35 | + <select class="form-control operate" data-name="id" style="width:60px;"> | ||
36 | + <option value="=" selected>等于</option> | ||
37 | + <option value=">">大于</option> | ||
38 | + <option value="<">小于</option> | ||
39 | + </select> | ||
40 | + </div> | ||
41 | + <input class="form-control" type="text" name="id" placeholder="" value=""/> | ||
42 | + </div> | ||
43 | + </div> | ||
44 | + </div> | ||
45 | + <div class="col-xs-12 col-sm-6 col-md-3"> | ||
46 | + <div class="form-group"> | ||
47 | + <label class="control-label">标题</label> | ||
48 | + <!--隐式的operate操作符,必须携带一个class为operate隐藏的文本框,且它的data-name="字段",值为操作符--> | ||
49 | + <input class="operate" type="hidden" data-name="title" value="="/> | ||
50 | + <div> | ||
51 | + <input class="form-control" type="text" name="title" placeholder="请输入查找的标题" value=""/> | ||
52 | + </div> | ||
53 | + </div> | ||
54 | + </div> | ||
55 | + <div class="col-xs-12 col-sm-6 col-md-3"> | ||
56 | + <div class="form-group"> | ||
57 | + <label class="control-label">管理员ID</label> | ||
58 | + <div class="row" data-toggle="cxselect" data-selects="group,admin"> | ||
59 | + <div class="col-xs-6"> | ||
60 | + <select class="group form-control" name="group" | ||
61 | + data-url="example/bootstraptable/cxselect?type=group"></select> | ||
62 | + </div> | ||
63 | + <div class="col-xs-6"> | ||
64 | + <select class="admin form-control" name="admin_id" | ||
65 | + data-url="example/bootstraptable/cxselect?type=admin" | ||
66 | + data-query-name="group_id"></select> | ||
67 | + </div> | ||
68 | + <input type="hidden" class="operate" data-name="admin_id" value="="/> | ||
69 | + </div> | ||
70 | + </div> | ||
71 | + </div> | ||
72 | + <div class="col-xs-12 col-sm-6 col-md-3"> | ||
73 | + <div class="form-group"> | ||
74 | + <label class="control-label">用户名</label> | ||
75 | + <input type="hidden" class="operate" data-name="username" value="="/> | ||
76 | + <div> | ||
77 | + <input id="c-category_id" data-source="auth/admin/index" data-primary-key="username" | ||
78 | + data-field="username" class="form-control selectpage" name="username" type="text" | ||
79 | + value="" style="display:block;"> | ||
80 | + </div> | ||
81 | + </div> | ||
82 | + </div> | ||
83 | + | ||
84 | + <div class="col-xs-12 col-sm-6 col-md-3" style="min-height:68px;"> | ||
85 | + <!--这里添加68px是为了避免刷新时出现元素错位闪屏--> | ||
86 | + <div class="form-group"> | ||
87 | + <label class="control-label">IP</label> | ||
88 | + <input type="hidden" class="operate" data-name="ip" value="in"/> | ||
89 | + <div> | ||
90 | + <!--给select一个固定的高度--> | ||
91 | + <select id="c-flag" class="form-control selectpicker" multiple name="ip" style="height:31px;"> | ||
92 | + {foreach name="ipList" item="vo"} | ||
93 | + <option value="{$key}" {in name="key" value="" }selected{ | ||
94 | + /in}>{$vo}</option> | ||
95 | + {/foreach} | ||
96 | + </select> | ||
97 | + </div> | ||
98 | + </div> | ||
99 | + </div> | ||
100 | + <div class="col-xs-12 col-sm-6 col-md-3"> | ||
101 | + <div class="form-group"> | ||
102 | + <label class="control-label">IP</label> | ||
103 | + <input type="hidden" class="operate" data-name="createtime" value="RANGE"/> | ||
104 | + <div> | ||
105 | + <input type="text" class="form-control datetimerange" name="createtime" value=""/> | ||
106 | + </div> | ||
107 | + </div> | ||
108 | + </div> | ||
109 | + <div class="col-xs-12 col-sm-6 col-md-3"> | ||
110 | + <div class="form-group"> | ||
111 | + <label class="control-label"></label> | ||
112 | + <div class="row"> | ||
113 | + <div class="col-xs-6"> | ||
114 | + <input type="submit" class="btn btn-success btn-block" value="提交"/> | ||
115 | + </div> | ||
116 | + <div class="col-xs-6"> | ||
117 | + <input type="reset" class="btn btn-primary btn-block" value="重置"/> | ||
118 | + </div> | ||
119 | + </div> | ||
120 | + </div> | ||
121 | + </div> | ||
122 | + </div> | ||
123 | + </div> | ||
124 | + </form> | ||
125 | +</script> |
1 | +<style>#cxselect-example textarea{margin:10px 0;}</style> | ||
2 | +<div class="panel panel-default panel-intro"> | ||
3 | + {:build_heading()} | ||
4 | + | ||
5 | + <div class="panel-body"> | ||
6 | + <div id="myTabContent" class="tab-content"> | ||
7 | + <div class="tab-pane fade active in" id="one"> | ||
8 | + <div class="widget-body no-padding" id="cxselect-example"> | ||
9 | + <form id="cxselectform" action=""> | ||
10 | + <div class="row"> | ||
11 | + <div class="col-md-6"> | ||
12 | + | ||
13 | + <div class="panel panel-default"> | ||
14 | + <div class="panel-heading"><b>省市区联动</b>(通过AJAX读取数据)</div> | ||
15 | + <div class="panel-body"> | ||
16 | + <div class="row"> | ||
17 | + <div class="col-xs-9"> | ||
18 | + <div class="form-inline" data-toggle="cxselect" data-selects="province,city,area"> | ||
19 | + <select class="province form-control" name="province" data-url="ajax/area"></select> | ||
20 | + <select class="city form-control" name="city" data-url="ajax/area"></select> | ||
21 | + <select class="area form-control" name="area" data-url="ajax/area"></select> | ||
22 | + </div> | ||
23 | + </div> | ||
24 | + <div class="col-xs-3 text-right"> | ||
25 | + <h6><label class="label label-primary"><i class="fa fa-pencil"></i> 增加</label></h6> | ||
26 | + </div> | ||
27 | + <div class="col-xs-12"> | ||
28 | + <textarea class="form-control" rows="8"> | ||
29 | + </textarea> | ||
30 | + </div> | ||
31 | + </div> | ||
32 | + <div class="row"> | ||
33 | + <div class="col-xs-9"> | ||
34 | + <div class="form-inline" data-toggle="cxselect" data-selects="province,city,area"> | ||
35 | + <select class="province form-control" name="province" data-url="ajax/area"> | ||
36 | + <option value="1964" selected>广东省</option> | ||
37 | + </select> | ||
38 | + <select class="city form-control" name="city" data-url="ajax/area"> | ||
39 | + <option value="1988" selected>深圳市</option> | ||
40 | + </select> | ||
41 | + <select class="area form-control" name="area" data-url="ajax/area"> | ||
42 | + <option value="1991" selected>南山区</option> | ||
43 | + </select> | ||
44 | + </div> | ||
45 | + </div> | ||
46 | + <div class="col-xs-3 text-right"> | ||
47 | + <h6><label class="label label-success"><i class="fa fa-edit"></i> 修改</label></h6> | ||
48 | + </div> | ||
49 | + <div class="col-xs-12"> | ||
50 | + <textarea class="form-control" rows="8"> | ||
51 | + </textarea> | ||
52 | + </div> | ||
53 | + </div> | ||
54 | + </div> | ||
55 | + | ||
56 | + </div> | ||
57 | + </div> | ||
58 | + <div class="col-md-6"> | ||
59 | + <div class="panel panel-default"> | ||
60 | + <div class="panel-heading"><b>类别联动</b>(Ajax读取数据)</div> | ||
61 | + <div class="panel-body"> | ||
62 | + <div class="row"> | ||
63 | + <div class="col-xs-9"> | ||
64 | + <div class="form-inline" data-toggle="cxselect" data-selects="first,second"> | ||
65 | + <select class="first form-control" name="first" data-url="ajax/category?type=page&pid=5"></select> | ||
66 | + <select class="second form-control" name="second" data-url="ajax/category" data-query-name="pid"></select> | ||
67 | + </div> | ||
68 | + </div> | ||
69 | + <div class="col-xs-3 text-right"> | ||
70 | + <h6><label class="label label-primary"><i class="fa fa-pencil"></i> 增加</label></h6> | ||
71 | + </div> | ||
72 | + <div class="col-xs-12"> | ||
73 | + <textarea class="form-control" rows="8"> | ||
74 | + </textarea> | ||
75 | + </div> | ||
76 | + </div> | ||
77 | + <div class="row"> | ||
78 | + <div class="col-xs-9"> | ||
79 | + <div class="form-inline" data-toggle="cxselect" data-selects="first,second"> | ||
80 | + <select class="first form-control" name="first" data-url="ajax/category?type=page&pid=5"> | ||
81 | + <option value="6" selected>网站建站</option> | ||
82 | + </select> | ||
83 | + <select class="second form-control" name="second" data-url="ajax/category" data-query-name="pid"> | ||
84 | + <option value="9" selected>移动端</option> | ||
85 | + </select> | ||
86 | + </div> | ||
87 | + </div> | ||
88 | + <div class="col-xs-3 text-right"> | ||
89 | + <h6><label class="label label-success"><i class="fa fa-edit"></i> 修改</label></h6> | ||
90 | + </div> | ||
91 | + <div class="col-xs-12"> | ||
92 | + <textarea class="form-control" rows="8"> | ||
93 | + </textarea> | ||
94 | + </div> | ||
95 | + </div> | ||
96 | + | ||
97 | + </div> | ||
98 | + </div> | ||
99 | + </div> | ||
100 | + <div class="col-md-6"> | ||
101 | + <div class="panel panel-default"> | ||
102 | + <div class="panel-heading"><b>省市区联动</b>(通过JSON渲染数据)</div> | ||
103 | + <div class="panel-body"> | ||
104 | + <div class="row"> | ||
105 | + <div class="col-xs-9"> | ||
106 | + <!--由于在初始化中修改了默认值,所以这里需要修改-jsonSpace/jsonValue/jsonName的值--> | ||
107 | + <div class="form-inline" data-toggle="cxselect" data-url="__CDN__/assets/libs/fastadmin-cxselect/js/cityData.min.json" | ||
108 | + data-selects="province,city,area" data-json-space="" data-json-name="n" data-json-value=""> | ||
109 | + <select class="province form-control" name="province"></select> | ||
110 | + <select class="city form-control" name="city"></select> | ||
111 | + <select class="area form-control" name="area"></select> | ||
112 | + </div> | ||
113 | + </div> | ||
114 | + <div class="col-xs-3 text-right"> | ||
115 | + <h6><label class="label label-primary"><i class="fa fa-pencil"></i> 增加</label></h6> | ||
116 | + </div> | ||
117 | + <div class="col-xs-12"> | ||
118 | + <textarea class="form-control" rows="8"> | ||
119 | + </textarea> | ||
120 | + </div> | ||
121 | + </div> | ||
122 | + <div class="row"> | ||
123 | + <div class="col-xs-9"> | ||
124 | + <!--由于在初始化中修改了默认值,所以这里需要修改-jsonSpace/jsonValue/jsonName的值--> | ||
125 | + <div class="form-inline" data-toggle="cxselect" data-url="__CDN__/assets/libs/fastadmin-cxselect/js/cityData.min.json" | ||
126 | + data-selects="province,city,area" data-json-space="" data-json-name="n" data-json-value=""> | ||
127 | + <select class="province form-control" data-first-title="选择省"> | ||
128 | + <option value="">请选择</option> | ||
129 | + <option value="浙江省" selected>浙江省</option> | ||
130 | + </select> | ||
131 | + <select class="city form-control" data-first-title="选择市"> | ||
132 | + <option value="">请选择</option> | ||
133 | + <option value="杭州市" selected>杭州市</option> | ||
134 | + </select> | ||
135 | + <select class="area form-control" data-first-title="选择地区"> | ||
136 | + <option value="">请选择</option> | ||
137 | + <option value="西湖区" selected>西湖区</option> | ||
138 | + </select> | ||
139 | + </div> | ||
140 | + </div> | ||
141 | + <div class="col-xs-3 text-right"> | ||
142 | + <h6><label class="label label-success"><i class="fa fa-edit"></i> 修改</label></h6> | ||
143 | + </div> | ||
144 | + <div class="col-xs-12"> | ||
145 | + <textarea class="form-control" rows="8"> | ||
146 | + </textarea> | ||
147 | + </div> | ||
148 | + </div> | ||
149 | + </div> | ||
150 | + | ||
151 | + </div> | ||
152 | + </div> | ||
153 | + </div> | ||
154 | + </form> | ||
155 | + </div> | ||
156 | + </div> | ||
157 | + | ||
158 | + </div> | ||
159 | + </div> | ||
160 | +</div> |
1 | +<style> | ||
2 | + .tab-content > .chart { | ||
3 | + padding: 10px; | ||
4 | + } | ||
5 | +</style> | ||
6 | +<div class="row"> | ||
7 | + <div class="col-lg-3 col-xs-6"> | ||
8 | + <!-- small box --> | ||
9 | + <div class="small-box bg-aqua"> | ||
10 | + <div class="inner"> | ||
11 | + <h3>150</h3> | ||
12 | + | ||
13 | + <p>今日订单</p> | ||
14 | + </div> | ||
15 | + <div class="icon"> | ||
16 | + <i class="fa fa-shopping-cart"></i> | ||
17 | + </div> | ||
18 | + <a href="#" class="small-box-footer">更多 <i class="fa fa-arrow-circle-right"></i></a> | ||
19 | + </div> | ||
20 | + </div> | ||
21 | + <!-- ./col --> | ||
22 | + <div class="col-lg-3 col-xs-6"> | ||
23 | + <!-- small box --> | ||
24 | + <div class="small-box bg-green"> | ||
25 | + <div class="inner"> | ||
26 | + <h3>53<sup style="font-size: 20px">%</sup></h3> | ||
27 | + | ||
28 | + <p>同比增长率</p> | ||
29 | + </div> | ||
30 | + <div class="icon"> | ||
31 | + <i class="fa fa-area-chart"></i> | ||
32 | + </div> | ||
33 | + <a href="#" class="small-box-footer">更多 <i class="fa fa-arrow-circle-right"></i></a> | ||
34 | + </div> | ||
35 | + </div> | ||
36 | + <!-- ./col --> | ||
37 | + <div class="col-lg-3 col-xs-6"> | ||
38 | + <!-- small box --> | ||
39 | + <div class="small-box bg-yellow"> | ||
40 | + <div class="inner"> | ||
41 | + <h3>44</h3> | ||
42 | + | ||
43 | + <p>今日注册用户数</p> | ||
44 | + </div> | ||
45 | + <div class="icon"> | ||
46 | + <i class="fa fa-users"></i> | ||
47 | + </div> | ||
48 | + <a href="#" class="small-box-footer">更多 <i class="fa fa-arrow-circle-right"></i></a> | ||
49 | + </div> | ||
50 | + </div> | ||
51 | + <!-- ./col --> | ||
52 | + <div class="col-lg-3 col-xs-6"> | ||
53 | + <!-- small box --> | ||
54 | + <div class="small-box bg-red"> | ||
55 | + <div class="inner"> | ||
56 | + <h3>65</h3> | ||
57 | + | ||
58 | + <p>唯一访客用户</p> | ||
59 | + </div> | ||
60 | + <div class="icon"> | ||
61 | + <i class="fa fa-user"></i> | ||
62 | + </div> | ||
63 | + <a href="#" class="small-box-footer">更多 <i class="fa fa-arrow-circle-right"></i></a> | ||
64 | + </div> | ||
65 | + </div> | ||
66 | + <!-- ./col --> | ||
67 | +</div> | ||
68 | +<!-- /.row --> | ||
69 | +<!-- Main row --> | ||
70 | +<div class="row" style="margin-bottom:5px;"> | ||
71 | + <!-- Left col --> | ||
72 | + <section class="col-lg-7 connectedSortable"> | ||
73 | + <!-- Custom tabs (Charts with tabs)--> | ||
74 | + <div class="nav-tabs-custom charts-custom"> | ||
75 | + <!-- Tabs within a box --> | ||
76 | + <ul class="nav nav-tabs pull-right"> | ||
77 | + <li class="active"><a href="#line-chart" data-toggle="tab">折线图</a></li> | ||
78 | + <li><a href="#area-chart" data-toggle="tab">区域图</a></li> | ||
79 | + <li class="pull-left header"><i class="fa fa-inbox"></i> 销售趋势</li> | ||
80 | + </ul> | ||
81 | + <div class="tab-content no-padding"> | ||
82 | + <!-- Morris chart - Sales --> | ||
83 | + <div class="chart tab-pane active" id="line-chart" style="position: relative; height: 300px;"></div> | ||
84 | + <div class="chart tab-pane" id="area-chart" style="position: relative; height: 300px;"></div> | ||
85 | + </div> | ||
86 | + </div> | ||
87 | + <div class="nav-tabs-custom charts-custom"> | ||
88 | + <!-- Tabs within a box --> | ||
89 | + <ul class="nav nav-tabs pull-right"> | ||
90 | + <li class="active"><a href="#pie-chart" data-toggle="tab">饼图</a></li> | ||
91 | + <li><a href="#bar-chart" data-toggle="tab">柱状图</a></li> | ||
92 | + <li class="pull-left header"><i class="fa fa-inbox"></i> 访问记录</li> | ||
93 | + </ul> | ||
94 | + <div class="tab-content no-padding"> | ||
95 | + <!-- Morris chart - Sales --> | ||
96 | + <div class="chart tab-pane active" id="pie-chart" style="position: relative; height: 300px;"></div> | ||
97 | + <div class="chart tab-pane" id="bar-chart" style="position: relative; height: 300px;"></div> | ||
98 | + </div> | ||
99 | + </div> | ||
100 | + <!-- /.nav-tabs-custom --> | ||
101 | + | ||
102 | + </section> | ||
103 | + <!-- /.Left col --> | ||
104 | + <section class="col-lg-5 connectedSortable"> | ||
105 | + | ||
106 | + <!-- Map box --> | ||
107 | + <div class="box box-solid bg-light-blue-gradient"> | ||
108 | + <div class="box-header"> | ||
109 | + <!-- tools box --> | ||
110 | + <div class="pull-right box-tools"> | ||
111 | + </div> | ||
112 | + <!-- /. tools --> | ||
113 | + | ||
114 | + <i class="fa fa-map-marker"></i> | ||
115 | + | ||
116 | + <h3 class="box-title"> | ||
117 | + 访客分布 | ||
118 | + </h3> | ||
119 | + </div> | ||
120 | + <div class="box-body"> | ||
121 | + <div id="simplebar-chart" style="height: 250px; width: 100%;"></div> | ||
122 | + </div> | ||
123 | + <!-- /.box-body--> | ||
124 | + <div class="box-footer no-border"> | ||
125 | + <div class="row"> | ||
126 | + <div class="col-xs-12 text-center"> | ||
127 | + <div class="knob-label">统计最近一周访客的记录</div> | ||
128 | + </div> | ||
129 | + <!-- ./col --> | ||
130 | + </div> | ||
131 | + <!-- /.row --> | ||
132 | + </div> | ||
133 | + </div> | ||
134 | + <!-- /.box --> | ||
135 | + | ||
136 | + <!-- solid sales graph --> | ||
137 | + <div class="box box-solid bg-teal-gradient"> | ||
138 | + <div class="box-header"> | ||
139 | + <i class="fa fa-th"></i> | ||
140 | + | ||
141 | + <h3 class="box-title">订单趋势</h3> | ||
142 | + | ||
143 | + <div class="box-tools pull-right"> | ||
144 | + </div> | ||
145 | + </div> | ||
146 | + <div class="box-body border-radius-none"> | ||
147 | + <div class="chart" id="smoothline-chart" style="height: 250px;"></div> | ||
148 | + </div> | ||
149 | + <!-- /.box-body--> | ||
150 | + <div class="box-footer no-border"> | ||
151 | + <div class="row"> | ||
152 | + <div class="col-xs-12 text-center"> | ||
153 | + <div class="knob-label">统计最近一周订单的趋势</div> | ||
154 | + </div> | ||
155 | + <!-- ./col --> | ||
156 | + </div> | ||
157 | + <!-- /.row --> | ||
158 | + </div> | ||
159 | + </div> | ||
160 | + <!-- /.box --> | ||
161 | + | ||
162 | + </section> | ||
163 | + <!-- right col --> | ||
164 | +</div> | ||
165 | +<!-- /.row (main row) --> |
1 | +<div class="panel panel-default panel-intro"> | ||
2 | + <div class="panel-heading"> | ||
3 | + <div class="panel-lead"><em>多表格(Multitable)</em>用于展示在一个页面展示多个表格数据,并且每次切换时刷新</div> | ||
4 | + <ul class="nav nav-tabs"> | ||
5 | + <li class="active"><a href="#first" data-toggle="tab">表格1</a></li> | ||
6 | + <li><a href="#second" data-toggle="tab">表格2</a></li> | ||
7 | + </ul> | ||
8 | + </div> | ||
9 | + <div class="panel-body"> | ||
10 | + <div id="myTabContent" class="tab-content"> | ||
11 | + <div class="tab-pane fade active in" id="first"> | ||
12 | + <div id="toolbar1" class="toolbar"> | ||
13 | + {:build_toolbar('refresh')} | ||
14 | + </div> | ||
15 | + <table id="table1" class="table table-striped table-bordered table-hover" width="100%"> | ||
16 | + </table> | ||
17 | + </div> | ||
18 | + <div class="tab-pane fade" id="second"> | ||
19 | + <div id="toolbar2" class="toolbar"> | ||
20 | + {:build_toolbar('refresh')} | ||
21 | + </div> | ||
22 | + <table id="table2" class="table table-striped table-bordered table-hover" width="100%"> | ||
23 | + </table> | ||
24 | + </div> | ||
25 | + </div> | ||
26 | + </div> | ||
27 | +</div> |
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 | + {:build_toolbar('refresh,delete')} | ||
10 | + </div> | ||
11 | + <table id="table" class="table table-striped table-bordered table-hover" width="100%"> | ||
12 | + | ||
13 | + </table> | ||
14 | + | ||
15 | + | ||
16 | + </div> | ||
17 | + </div> | ||
18 | + | ||
19 | + </div> | ||
20 | + </div> | ||
21 | +</div> |
1 | +<div class="row"> | ||
2 | + <div class="col-xs-12 col-sm-6 col-md-5 col-lg-4"> | ||
3 | + <div class="panel panel-default panel-intro"> | ||
4 | + <div class="panel-body"> | ||
5 | + <div id="1" class="tab-content"> | ||
6 | + <div class="tab-pane fade active in" id="one"> | ||
7 | + <div class="widget-body no-padding"> | ||
8 | + <div id="toolbar1" class="toolbar"> | ||
9 | + {:build_toolbar('refresh')} | ||
10 | + </div> | ||
11 | + <table id="table1" class="table table-striped table-bordered table-hover" width="100%"> | ||
12 | + | ||
13 | + </table> | ||
14 | + | ||
15 | + | ||
16 | + </div> | ||
17 | + </div> | ||
18 | + | ||
19 | + </div> | ||
20 | + </div> | ||
21 | + </div> | ||
22 | + </div> | ||
23 | + <div class="col-xs-12 col-sm-6 col-md-7 col-lg-8"> | ||
24 | + <div class="panel panel-default panel-intro"> | ||
25 | + <div class="panel-body"> | ||
26 | + <div id="myTabContent2" class="tab-content"> | ||
27 | + <div class="tab-pane fade active in" id="two"> | ||
28 | + <div class="widget-body no-padding"> | ||
29 | + <div id="toolbar2" class="toolbar"> | ||
30 | + {:build_toolbar('refresh')} | ||
31 | + </div> | ||
32 | + <table id="table2" class="table table-striped table-bordered table-hover" width="100%"> | ||
33 | + | ||
34 | + </table> | ||
35 | + | ||
36 | + | ||
37 | + </div> | ||
38 | + </div> | ||
39 | + | ||
40 | + </div> | ||
41 | + </div> | ||
42 | + </div> | ||
43 | + </div> | ||
44 | +</div> |
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 | + {:build_toolbar('refresh,delete')} | ||
10 | + <a class="btn btn-info btn-disabled disabled btn-selected" href="javascript:;"><i class="fa fa-leaf"></i> 获取选中项</a> | ||
11 | + <a class="btn btn-success btn-toggle-view" href="javascript:;"><i class="fa fa-leaf"></i> 切换视图</a> | ||
12 | + </div> | ||
13 | + <table id="table" class="table table-striped table-hover" width="100%"> | ||
14 | + | ||
15 | + </table> | ||
16 | + | ||
17 | + </div> | ||
18 | + </div> | ||
19 | + | ||
20 | + </div> | ||
21 | + </div> | ||
22 | +</div> | ||
23 | +<style type="text/css"> | ||
24 | + .example { | ||
25 | + height:100%;position: relative; | ||
26 | + } | ||
27 | + .example > span { | ||
28 | + position:absolute;left:15px;top:15px; | ||
29 | + } | ||
30 | +</style> | ||
31 | + | ||
32 | +<script id="itemtpl" type="text/html"> | ||
33 | + <!-- | ||
34 | + 如果启用了templateView,默认调用的是itemtpl这个模板,可以通过设置templateFormatter来修改 | ||
35 | + 在当前模板中可以使用三个变量(item:行数据,i:当前第几行,data:所有的行数据) | ||
36 | + 此模板引擎使用的是art-template的native,可参考官方文档 | ||
37 | + --> | ||
38 | + | ||
39 | + <div class="col-sm-4 col-md-3"> | ||
40 | + <!--下面四行是为了展示随机图片和标签,可移除--> | ||
41 | + <% var imagearr = ['https://cdn.fastadmin.net/uploads/addons/blog.png', 'https://cdn.fastadmin.net/uploads/addons/cms.png', 'https://cdn.fastadmin.net/uploads/addons/vote.png', 'https://cdn.fastadmin.net/uploads/addons/blog.png', 'https://cdn.fastadmin.net/uploads/addons/alisms.png']; %> | ||
42 | + <% var image = imagearr[item.id % 5]; %> | ||
43 | + <% var labelarr = ['primary', 'success', 'info', 'danger', 'warning']; %> | ||
44 | + <% var label = labelarr[item.id % 5]; %> | ||
45 | + <div class="thumbnail example"> | ||
46 | + <span class="btn btn-<%=label%>">ID:<%=item.id%></span> | ||
47 | + <img src="<%=image%>" style="width:100%;" alt="<%=item.title%>"> | ||
48 | + <div class="caption"> | ||
49 | + <h4><%=item.title?item.title:'无'%></h4> | ||
50 | + <p class="text-muted">操作者IP:<%=item.ip%></p> | ||
51 | + <p class="text-muted">操作时间:<%=Moment(item.createtime*1000).format("YYYY-MM-DD HH:mm:ss")%></p> | ||
52 | + <p> | ||
53 | + <!--详情的事件需要在JS中手动绑定--> | ||
54 | + <a href="#" class="btn btn-primary btn-success btn-detail" data-id="<%=item.id%>"><i class="fa fa-camera"></i> 详情</a> | ||
55 | + | ||
56 | + <!--如果需要响应编辑或删除事件,可以给元素添加 btn-edit或btn-del的类和data-id这个属性值--> | ||
57 | + <a href="#" class="btn btn-primary btn-edit" data-id="<%=item.id%>"><i class="fa fa-pencil"></i> 编辑</a> | ||
58 | + <a href="#" class="btn btn-danger btn-del" data-id="<%=item.id%>"><i class="fa fa-times"></i> 删除</a> | ||
59 | + <span class="pull-right" style="margin-top:10px;"> | ||
60 | + <!--如果需要多选操作,请确保有下面的checkbox元素存在,可移除--> | ||
61 | + <input name="checkbox" data-id="<%=item.id%>" type="checkbox" /> | ||
62 | + </span> | ||
63 | + </p> | ||
64 | + </div> | ||
65 | + </div> | ||
66 | + </div> | ||
67 | +</script> |
addons/example/assets/css/common.css
0 → 100644
1 | +/*! | ||
2 | + * Start Bootstrap - Modern Business (http://startbootstrap.com/) | ||
3 | + * Copyright 2013-2016 Start Bootstrap | ||
4 | + * Licensed under MIT (https://github.com/BlackrockDigital/startbootstrap/blob/gh-pages/LICENSE) | ||
5 | + */ | ||
6 | + | ||
7 | +/* Global Styles */ | ||
8 | + | ||
9 | +html, | ||
10 | +body { | ||
11 | + height: 100%; | ||
12 | +} | ||
13 | + | ||
14 | +body { | ||
15 | + padding-top: 50px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */ | ||
16 | + -webkit-font-smoothing: antialiased; | ||
17 | + -moz-osx-font-smoothing: grayscale; | ||
18 | + font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif; | ||
19 | +} | ||
20 | + | ||
21 | +.img-addon { | ||
22 | + margin-bottom: 10px; | ||
23 | + width:100%; | ||
24 | +} | ||
25 | + | ||
26 | +.img-hover:hover { | ||
27 | + opacity: 0.8; | ||
28 | +} | ||
29 | + | ||
30 | +.display-1 { | ||
31 | + font-size:44px; | ||
32 | +} | ||
33 | +.display-4 { | ||
34 | + font-size:24px; | ||
35 | + line-height:32px; | ||
36 | +} | ||
37 | + | ||
38 | +/* Home Page Carousel */ | ||
39 | + | ||
40 | +header.carousel { | ||
41 | + height: 50%; | ||
42 | +} | ||
43 | + | ||
44 | +header.carousel .item, | ||
45 | +header.carousel .item.active, | ||
46 | +header.carousel .carousel-inner { | ||
47 | + height: 100%; | ||
48 | +} | ||
49 | + | ||
50 | +header.carousel .fill { | ||
51 | + width: 100%; | ||
52 | + height: 100%; | ||
53 | +} | ||
54 | + | ||
55 | +/* 404 Page Styles */ | ||
56 | + | ||
57 | +.error-404 { | ||
58 | + font-size: 100px; | ||
59 | +} | ||
60 | + | ||
61 | +/* Pricing Page Styles */ | ||
62 | + | ||
63 | +.price { | ||
64 | + display: block; | ||
65 | + font-size: 50px; | ||
66 | + line-height: 50px; | ||
67 | +} | ||
68 | + | ||
69 | +.price sup { | ||
70 | + top: -20px; | ||
71 | + left: 2px; | ||
72 | + font-size: 20px; | ||
73 | +} | ||
74 | + | ||
75 | +.period { | ||
76 | + display: block; | ||
77 | + font-style: italic; | ||
78 | +} | ||
79 | + | ||
80 | +/* Footer Styles */ | ||
81 | + | ||
82 | +footer { | ||
83 | + margin: 50px 0; | ||
84 | +} | ||
85 | + | ||
86 | +/* Responsive Styles */ | ||
87 | + | ||
88 | +@media(max-width:991px) { | ||
89 | + .customer-img, | ||
90 | + .img-related { | ||
91 | + margin-bottom: 30px; | ||
92 | + } | ||
93 | +} | ||
94 | + | ||
95 | +@media(max-width:767px) { | ||
96 | + .img-addon { | ||
97 | + margin-bottom: 15px; | ||
98 | + } | ||
99 | + | ||
100 | + header.carousel .carousel { | ||
101 | + height: 70%; | ||
102 | + } | ||
103 | +} | ||
104 | +.carousel-body { | ||
105 | + position:absolute; | ||
106 | + width: 100%; | ||
107 | + top:25%; | ||
108 | + text-align:center; | ||
109 | + color:#fff; | ||
110 | +} | ||
111 | + | ||
112 | +.addonlist a > p{ | ||
113 | + margin-bottom:15px; | ||
114 | +} |
addons/example/assets/js/async.js
0 → 100644
1 | +/** @license | ||
2 | + * RequireJS plugin for async dependency load like JSONP and Google Maps | ||
3 | + * Author: Miller Medeiros | ||
4 | + * Version: 0.1.2 (2014/02/24) | ||
5 | + * Released under the MIT license | ||
6 | + */ | ||
7 | +define(function(){ | ||
8 | + | ||
9 | + var DEFAULT_PARAM_NAME = 'callback', | ||
10 | + _uid = 0; | ||
11 | + | ||
12 | + function injectScript(src){ | ||
13 | + var s, t; | ||
14 | + s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = src; | ||
15 | + t = document.getElementsByTagName('script')[0]; t.parentNode.insertBefore(s,t); | ||
16 | + } | ||
17 | + | ||
18 | + function formatUrl(name, id){ | ||
19 | + var paramRegex = /!(.+)/, | ||
20 | + url = name.replace(paramRegex, ''), | ||
21 | + param = (paramRegex.test(name))? name.replace(/.+!/, '') : DEFAULT_PARAM_NAME; | ||
22 | + url += (url.indexOf('?') < 0)? '?' : '&'; | ||
23 | + return url + param +'='+ id; | ||
24 | + } | ||
25 | + | ||
26 | + function uid() { | ||
27 | + _uid += 1; | ||
28 | + return '__async_req_'+ _uid +'__'; | ||
29 | + } | ||
30 | + | ||
31 | + return{ | ||
32 | + load : function(name, req, onLoad, config){ | ||
33 | + if(config.isBuild){ | ||
34 | + onLoad(null); //avoid errors on the optimizer | ||
35 | + }else{ | ||
36 | + var id = uid(); | ||
37 | + //create a global variable that stores onLoad so callback | ||
38 | + //function can define new module after async load | ||
39 | + window[id] = onLoad; | ||
40 | + injectScript(formatUrl(req.toUrl(name), id)); | ||
41 | + } | ||
42 | + } | ||
43 | + }; | ||
44 | +}); |
addons/example/bootstrap.js
0 → 100644
addons/example/config.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +return [ | ||
4 | + [ | ||
5 | + 'name' => 'title', | ||
6 | + 'title' => '标题', | ||
7 | + 'type' => 'string', | ||
8 | + 'content' => [ | ||
9 | + ], | ||
10 | + 'value' => '示例标题', | ||
11 | + 'rule' => 'required', | ||
12 | + 'msg' => '', | ||
13 | + 'tip' => '', | ||
14 | + 'ok' => '', | ||
15 | + 'extend' => '' | ||
16 | + ], | ||
17 | + [ | ||
18 | + //配置唯一标识 | ||
19 | + 'name' => 'theme', | ||
20 | + //显示的标题 | ||
21 | + 'title' => '皮肤', | ||
22 | + //类型 | ||
23 | + 'type' => 'string', | ||
24 | + //数据字典 | ||
25 | + 'content' => [ | ||
26 | + ], | ||
27 | + //值 | ||
28 | + 'value' => 'default', | ||
29 | + //验证规则 | ||
30 | + 'rule' => 'required', | ||
31 | + //错误消息 | ||
32 | + 'msg' => '', | ||
33 | + //提示消息 | ||
34 | + 'tip' => '', | ||
35 | + //成功消息 | ||
36 | + 'ok' => '', | ||
37 | + //扩展信息 | ||
38 | + 'extend' => '' | ||
39 | + ], | ||
40 | + [ | ||
41 | + 'name' => 'domain', | ||
42 | + 'title' => '绑定二级域名前缀', | ||
43 | + 'type' => 'string', | ||
44 | + 'content' => [ | ||
45 | + ], | ||
46 | + 'value' => '', | ||
47 | + 'rule' => '', | ||
48 | + 'msg' => '', | ||
49 | + 'tip' => '', | ||
50 | + 'ok' => '', | ||
51 | + 'extend' => '' | ||
52 | + ], | ||
53 | + [ | ||
54 | + 'name' => 'rewrite', | ||
55 | + 'title' => '伪静态', | ||
56 | + 'type' => 'array', | ||
57 | + 'content' => [], | ||
58 | + 'value' => [ | ||
59 | + 'index/index' => '/example$', | ||
60 | + 'demo/index' => '/example/d/[:name]', | ||
61 | + 'demo/demo1' => '/example/d1/[:name]', | ||
62 | + 'demo/demo2' => '/example/d2/[:name]', | ||
63 | + ], | ||
64 | + 'rule' => 'required', | ||
65 | + 'msg' => '', | ||
66 | + 'tip' => '', | ||
67 | + 'ok' => '', | ||
68 | + 'extend' => '' | ||
69 | + ], | ||
70 | +]; |
addons/example/controller/Demo.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace addons\example\controller; | ||
4 | + | ||
5 | +use think\addons\Controller; | ||
6 | + | ||
7 | +/** | ||
8 | + * 测试控制器 | ||
9 | + */ | ||
10 | +class Demo extends Controller | ||
11 | +{ | ||
12 | + | ||
13 | + protected $layout = 'default'; | ||
14 | + protected $noNeedLogin = ['index', 'demo1']; | ||
15 | + protected $noNeedRight = ['*']; | ||
16 | + | ||
17 | + public function index() | ||
18 | + { | ||
19 | + return $this->view->fetch(); | ||
20 | + } | ||
21 | + | ||
22 | + public function demo1() | ||
23 | + { | ||
24 | + return $this->view->fetch(); | ||
25 | + } | ||
26 | + | ||
27 | + public function demo2() | ||
28 | + { | ||
29 | + return $this->view->fetch(); | ||
30 | + } | ||
31 | + | ||
32 | +} |
addons/example/controller/Index.php
0 → 100644
addons/example/info.ini
0 → 100644
addons/example/install.sql
0 → 100644
此 diff 太大无法显示。
1 | +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { | ||
2 | + var Controller = { | ||
3 | + index: function () { | ||
4 | + // | ||
5 | + // 初始化表格参数配置 | ||
6 | + Table.api.init({ | ||
7 | + extend: { | ||
8 | + index_url: 'example/baidumap/index', | ||
9 | + add_url: 'example/baidumap/add', | ||
10 | + edit_url: 'example/baidumap/edit', | ||
11 | + del_url: 'example/baidumap/del', | ||
12 | + multi_url: 'example/baidumap/multi', | ||
13 | + table: '', | ||
14 | + } | ||
15 | + }); | ||
16 | + | ||
17 | + var table = $("#table"); | ||
18 | + | ||
19 | + // 初始化表格 | ||
20 | + table.bootstrapTable({ | ||
21 | + url: $.fn.bootstrapTable.defaults.extend.index_url, | ||
22 | + pk: 'id', | ||
23 | + sortName: 'id', | ||
24 | + columns: [ | ||
25 | + [ | ||
26 | + {checkbox: true}, | ||
27 | + {field: 'id', title: 'ID', operate: false}, | ||
28 | + {field: 'admin_id', title: __('Admin_id'), visible: false, operate: false}, | ||
29 | + {field: 'username', title: __('Username'), formatter: Table.api.formatter.search}, | ||
30 | + {field: 'title', title: __('Title')}, | ||
31 | + {field: 'url', title: __('Url'), align: 'left'}, | ||
32 | + {field: 'ip', title: __('IP')}, | ||
33 | + {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true}, | ||
34 | + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} | ||
35 | + ] | ||
36 | + ] | ||
37 | + }); | ||
38 | + | ||
39 | + // 为表格绑定事件 | ||
40 | + Table.api.bindevent(table); | ||
41 | + }, | ||
42 | + add: function () { | ||
43 | + Controller.api.bindevent(); | ||
44 | + }, | ||
45 | + edit: function () { | ||
46 | + Controller.api.bindevent(); | ||
47 | + }, | ||
48 | + map: function () { | ||
49 | + Form.api.bindevent($("form[role=form]")); | ||
50 | + require(['async!BMap'], function () { | ||
51 | + // 更多文档可参考 http://lbsyun.baidu.com/jsdemo.htm | ||
52 | + // 百度地图API功能 | ||
53 | + var map = new BMap.Map("allmap"); | ||
54 | + var point = new BMap.Point(116.404, 39.915); | ||
55 | + | ||
56 | + map.centerAndZoom(point, 13); //设置中心坐标点和级别 | ||
57 | + var marker = new BMap.Marker(point); // 创建标注 | ||
58 | + map.addOverlay(marker); // 将标注添加到地图中 | ||
59 | + marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画 | ||
60 | + | ||
61 | + map.enableDragging(); //开启拖拽 | ||
62 | + //map.enableInertialDragging(); //开启惯性拖拽 | ||
63 | + map.enableScrollWheelZoom(true); //是否允许缩放 | ||
64 | + //map.centerAndZoom("上海",15); //根据城市名设定地图中心点 | ||
65 | + | ||
66 | + var geolocation = new BMap.Geolocation(); | ||
67 | + geolocation.getCurrentPosition(function (r) { | ||
68 | + if (this.getStatus() == BMAP_STATUS_SUCCESS) { | ||
69 | + var mk = new BMap.Marker(r.point); | ||
70 | + map.addOverlay(mk); | ||
71 | + map.panTo(r.point); | ||
72 | + //Layer.alert('您的位置:' + r.point.lng + ',' + r.point.lat); | ||
73 | + } else { | ||
74 | + Layer.alert('failed' + this.getStatus()); | ||
75 | + } | ||
76 | + }, {enableHighAccuracy: true}); | ||
77 | + | ||
78 | + // 点搜索按钮时解析地址坐标 | ||
79 | + $(document).on('click', '.btn-search', function () { | ||
80 | + // 创建地址解析器实例 | ||
81 | + var myGeo = new BMap.Geocoder(); | ||
82 | + // 将地址解析结果显示在地图上,并调整地图视野 | ||
83 | + myGeo.getPoint($("#searchaddress").val(), function (point) { | ||
84 | + if (point) { | ||
85 | + map.centerAndZoom(point, 16); | ||
86 | + map.addOverlay(new BMap.Marker(point)); | ||
87 | + } else { | ||
88 | + Layer.alert("您选择地址没有解析到结果!"); | ||
89 | + } | ||
90 | + }); | ||
91 | + }); | ||
92 | + | ||
93 | + }); | ||
94 | + }, | ||
95 | + api: { | ||
96 | + bindevent: function () { | ||
97 | + Form.api.bindevent($("form[role=form]")); | ||
98 | + } | ||
99 | + } | ||
100 | + }; | ||
101 | + return Controller; | ||
102 | +}); |
1 | +define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) { | ||
2 | + | ||
3 | + var Controller = { | ||
4 | + index: function () { | ||
5 | + // 初始化表格参数配置 | ||
6 | + Table.api.init({ | ||
7 | + extend: { | ||
8 | + index_url: 'example/bootstraptable/index', | ||
9 | + add_url: '', | ||
10 | + edit_url: '', | ||
11 | + del_url: 'example/bootstraptable/del', | ||
12 | + multi_url: '', | ||
13 | + } | ||
14 | + }); | ||
15 | + | ||
16 | + var table = $("#table"); | ||
17 | + | ||
18 | + //在普通搜索提交搜索前 | ||
19 | + table.on('common-search.bs.table', function (event, table, query) { | ||
20 | + //这里可以获取到普通搜索表单中字段的查询条件 | ||
21 | + console.log(query); | ||
22 | + }); | ||
23 | + | ||
24 | + //在普通搜索渲染后 | ||
25 | + table.on('post-common-search.bs.table', function (event, table) { | ||
26 | + var form = $("form", table.$commonsearch); | ||
27 | + $("input[name='title']", form).addClass("selectpage").data("source", "auth/adminlog/selectpage").data("primaryKey", "title").data("field", "title").data("orderBy", "id desc"); | ||
28 | + $("input[name='username']", form).addClass("selectpage").data("source", "auth/admin/index").data("primaryKey", "username").data("field", "username").data("orderBy", "id desc"); | ||
29 | + Form.events.cxselect(form); | ||
30 | + Form.events.selectpage(form); | ||
31 | + }); | ||
32 | + | ||
33 | + //在表格内容渲染完成后回调的事件 | ||
34 | + table.on('post-body.bs.table', function (e, settings, json, xhr) { | ||
35 | + console.log(e, settings, json, xhr); | ||
36 | + }); | ||
37 | + | ||
38 | + //当表格数据加载完成时 | ||
39 | + table.on('load-success.bs.table', function (e, data) { | ||
40 | + //这里可以获取从服务端获取的JSON数据 | ||
41 | + console.log(data); | ||
42 | + //这里我们手动设置底部的值 | ||
43 | + $("#money").text(data.extend.money); | ||
44 | + $("#price").text(data.extend.price); | ||
45 | + }); | ||
46 | + | ||
47 | + // 初始化表格 | ||
48 | + // 这里使用的是Bootstrap-table插件渲染表格 | ||
49 | + // 相关文档:https://doc.fastadmin.net/doc/table.html | ||
50 | + table.bootstrapTable({ | ||
51 | + //表格参数可以参考:https://doc.fastadmin.net/doc/190.html | ||
52 | + url: $.fn.bootstrapTable.defaults.extend.index_url, | ||
53 | + columns: [ | ||
54 | + [ | ||
55 | + //更多列参数可以参考:https://doc.fastadmin.net/doc/191.html | ||
56 | + //该列为复选框字段,如果后台的返回state值将会默认选中 | ||
57 | + {field: 'state', checkbox: true,}, | ||
58 | + //sortable为是否排序,operate为搜索时的操作符,visible表示是否可见 | ||
59 | + {field: 'id', title: 'ID', sortable: true, operate: false}, | ||
60 | + //默认隐藏该列 | ||
61 | + {field: 'admin_id', title: __('管理员'), operate: false}, | ||
62 | + //直接响应搜索 | ||
63 | + {field: 'username', title: __('管理员'), formatter: Table.api.formatter.search}, | ||
64 | + //模糊搜索 | ||
65 | + {field: 'title', title: __('Title'), operate: 'LIKE %...%', placeholder: '模糊搜索,*表示任意字符'}, | ||
66 | + //通过Ajax渲染searchList,也可以使用JSON数据 | ||
67 | + { | ||
68 | + field: 'url', | ||
69 | + title: __('Url'), | ||
70 | + align: 'left', | ||
71 | + searchList: $.getJSON('example/bootstraptable/searchlist?search=a&field=row[user_id]'), | ||
72 | + formatter: Controller.api.formatter.url | ||
73 | + }, | ||
74 | + //点击IP时同时执行搜索此IP | ||
75 | + { | ||
76 | + field: 'ip', | ||
77 | + title: __('IP'), | ||
78 | + events: Controller.api.events.ip, | ||
79 | + formatter: Controller.api.formatter.ip | ||
80 | + }, | ||
81 | + //自定义栏位,custom是不存在的字段 | ||
82 | + {field: 'custom', title: __('切换'), operate: false, formatter: Controller.api.formatter.custom}, | ||
83 | + //browser是一个不存在的字段 | ||
84 | + //通过formatter来渲染数据,同时为它添加上事件 | ||
85 | + { | ||
86 | + field: 'browser', | ||
87 | + title: __('Browser'), | ||
88 | + operate: false, | ||
89 | + events: Controller.api.events.browser, | ||
90 | + formatter: Controller.api.formatter.browser | ||
91 | + }, | ||
92 | + { | ||
93 | + field: 'admin_id', title: __('联动搜索'), searchList: function (column) { | ||
94 | + return Template('categorytpl', {}); | ||
95 | + }, formatter: function (value, row, index) { | ||
96 | + return '无'; | ||
97 | + }, visible: false | ||
98 | + }, | ||
99 | + //启用时间段搜索 | ||
100 | + { | ||
101 | + field: 'createtime', | ||
102 | + title: __('Update time'), | ||
103 | + sortable: true, | ||
104 | + formatter: Table.api.formatter.datetime, | ||
105 | + operate: 'RANGE', | ||
106 | + addclass: 'datetimerange' | ||
107 | + }, | ||
108 | + //操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮 | ||
109 | + { | ||
110 | + field: 'operate', | ||
111 | + width: "150px", | ||
112 | + title: __('Operate'), | ||
113 | + table: table, | ||
114 | + events: Table.api.events.operate, | ||
115 | + buttons: [ | ||
116 | + { | ||
117 | + name: 'click', | ||
118 | + title: __('点击执行事件'), | ||
119 | + classname: 'btn btn-xs btn-info btn-click', | ||
120 | + icon: 'fa fa-leaf', | ||
121 | + // dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示 | ||
122 | + click: function (data) { | ||
123 | + Layer.alert("点击按钮执行的事件"); | ||
124 | + } | ||
125 | + }, | ||
126 | + { | ||
127 | + name: 'detail', | ||
128 | + title: __('弹出窗口打开'), | ||
129 | + classname: 'btn btn-xs btn-primary btn-dialog', | ||
130 | + icon: 'fa fa-list', | ||
131 | + url: 'example/bootstraptable/detail', | ||
132 | + callback: function (data) { | ||
133 | + Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"}); | ||
134 | + } | ||
135 | + }, | ||
136 | + { | ||
137 | + name: 'ajax', | ||
138 | + title: __('发送Ajax'), | ||
139 | + classname: 'btn btn-xs btn-success btn-magic btn-ajax', | ||
140 | + icon: 'fa fa-magic', | ||
141 | + confirm: '确认发送Ajax请求?', | ||
142 | + url: 'example/bootstraptable/detail', | ||
143 | + success: function (data, ret) { | ||
144 | + Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data)); | ||
145 | + //如果需要阻止成功提示,则必须使用return false; | ||
146 | + //return false; | ||
147 | + }, | ||
148 | + error: function (data, ret) { | ||
149 | + console.log(data, ret); | ||
150 | + Layer.alert(ret.msg); | ||
151 | + return false; | ||
152 | + } | ||
153 | + }, | ||
154 | + { | ||
155 | + name: 'addtabs', | ||
156 | + title: __('新选项卡中打开'), | ||
157 | + classname: 'btn btn-xs btn-warning btn-addtabs', | ||
158 | + icon: 'fa fa-folder-o', | ||
159 | + url: 'example/bootstraptable/detail' | ||
160 | + } | ||
161 | + ], | ||
162 | + formatter: Table.api.formatter.operate | ||
163 | + }, | ||
164 | + ], | ||
165 | + ], | ||
166 | + //更多配置参数可参考:https://doc.fastadmin.net/doc/190.html | ||
167 | + //亦可以参考require-table.js中defaults的配置 | ||
168 | + //快捷搜索,这里可在控制器定义快捷搜索的字段 | ||
169 | + search: true, | ||
170 | + //启用普通表单搜索 | ||
171 | + commonSearch: true, | ||
172 | + //显示导出按钮 | ||
173 | + showExport: true, | ||
174 | + //导出类型 | ||
175 | + exportDataType: "all", //共有basic, all, selected三种值 basic当前页 all全部 selected仅选中 | ||
176 | + //导出下拉列表选项 | ||
177 | + exportTypes: ['json', 'xml', 'csv', 'txt', 'doc', 'excel'], | ||
178 | + //可以控制是否默认显示搜索单表,false则隐藏,默认为false | ||
179 | + searchFormVisible: true, | ||
180 | + queryParams: function (params) { | ||
181 | + //这里可以追加搜索条件 | ||
182 | + var filter = JSON.parse(params.filter); | ||
183 | + var op = JSON.parse(params.op); | ||
184 | + //这里可以动态赋值,比如从URL中获取admin_id的值,filter.admin_id=Fast.api.query('admin_id'); | ||
185 | + filter.admin_id = 1; | ||
186 | + op.admin_id = "="; | ||
187 | + params.filter = JSON.stringify(filter); | ||
188 | + params.op = JSON.stringify(op); | ||
189 | + return params; | ||
190 | + }, | ||
191 | + }); | ||
192 | + | ||
193 | + // 为表格绑定事件 | ||
194 | + Table.api.bindevent(table); | ||
195 | + | ||
196 | + // 监听下拉列表改变的事件 | ||
197 | + $(document).on('change', 'select[name=admin]', function () { | ||
198 | + $("input[name='admin_id']").val($(this).val()); | ||
199 | + }); | ||
200 | + | ||
201 | + // 指定搜索条件 | ||
202 | + $(document).on("click", ".btn-singlesearch", function () { | ||
203 | + var options = table.bootstrapTable('getOptions'); | ||
204 | + var queryParams = options.queryParams; | ||
205 | + options.pageNumber = 1; | ||
206 | + options.queryParams = function (params) { | ||
207 | + //这一行必须要存在,否则在点击下一页时会丢失搜索栏数据 | ||
208 | + params = queryParams(params); | ||
209 | + | ||
210 | + //如果希望追加搜索条件,可使用 | ||
211 | + var filter = params.filter ? JSON.parse(params.filter) : {}; | ||
212 | + var op = params.op ? JSON.parse(params.op) : {}; | ||
213 | + filter.url = 'login'; | ||
214 | + op.url = 'like'; | ||
215 | + params.filter = JSON.stringify(filter); | ||
216 | + params.op = JSON.stringify(op); | ||
217 | + | ||
218 | + //如果希望忽略搜索栏搜索条件,可使用 | ||
219 | + //params.filter = JSON.stringify({url: 'login'}); | ||
220 | + //params.op = JSON.stringify({url: 'like'}); | ||
221 | + return params; | ||
222 | + }; | ||
223 | + table.bootstrapTable('refresh', {}); | ||
224 | + Toastr.info("当前执行的是自定义搜索,搜索URL中包含login的数据"); | ||
225 | + return false; | ||
226 | + }); | ||
227 | + | ||
228 | + // 获取选中项 | ||
229 | + $(document).on("click", ".btn-selected", function () { | ||
230 | + Layer.alert(JSON.stringify(table.bootstrapTable('getSelections'))); | ||
231 | + }); | ||
232 | + | ||
233 | + // 启动和暂停按钮 | ||
234 | + $(document).on("click", ".btn-start,.btn-pause", function () { | ||
235 | + //在table外不可以使用添加.btn-change的方法 | ||
236 | + //只能自己调用Table.api.multi实现 | ||
237 | + //如果操作全部则ids可以置为空 | ||
238 | + var ids = Table.api.selectedids(table); | ||
239 | + Table.api.multi("changestatus", ids.join(","), table, this); | ||
240 | + }); | ||
241 | + | ||
242 | + }, | ||
243 | + add: function () { | ||
244 | + Controller.api.bindevent(); | ||
245 | + }, | ||
246 | + edit: function () { | ||
247 | + Controller.api.bindevent(); | ||
248 | + }, | ||
249 | + detail: function () { | ||
250 | + $(document).on('click', '.btn-callback', function () { | ||
251 | + Fast.api.close($("input[name=callback]").val()); | ||
252 | + }); | ||
253 | + }, | ||
254 | + api: { | ||
255 | + bindevent: function () { | ||
256 | + Form.api.bindevent($("form[role=form]")); | ||
257 | + }, | ||
258 | + formatter: {//渲染的方法 | ||
259 | + url: function (value, row, index) { | ||
260 | + return '<div class="input-group input-group-sm" style="width:250px;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>'; | ||
261 | + }, | ||
262 | + ip: function (value, row, index) { | ||
263 | + return '<a class="btn btn-xs btn-ip bg-success"><i class="fa fa-map-marker"></i> ' + value + '</a>'; | ||
264 | + }, | ||
265 | + browser: function (value, row, index) { | ||
266 | + //这里我们直接使用row的数据 | ||
267 | + return '<a class="btn btn-xs btn-browser">' + row.useragent.split(" ")[0] + '</a>'; | ||
268 | + }, | ||
269 | + custom: function (value, row, index) { | ||
270 | + //添加上btn-change可以自定义请求的URL进行数据处理 | ||
271 | + return '<a class="btn-change text-success" data-url="example/bootstraptable/change" data-id="' + row.id + '"><i class="fa ' + (row.title == '' ? 'fa-toggle-on fa-flip-horizontal text-gray' : 'fa-toggle-on') + ' fa-2x"></i></a>'; | ||
272 | + }, | ||
273 | + }, | ||
274 | + events: {//绑定事件的方法 | ||
275 | + ip: { | ||
276 | + //格式为:方法名+空格+DOM元素 | ||
277 | + 'click .btn-ip': function (e, value, row, index) { | ||
278 | + e.stopPropagation(); | ||
279 | + var container = $("#table").data("bootstrap.table").$container; | ||
280 | + var options = $("#table").bootstrapTable('getOptions'); | ||
281 | + //这里我们手动将数据填充到表单然后提交 | ||
282 | + $("form.form-commonsearch [name='ip']", container).val(value); | ||
283 | + $("form.form-commonsearch", container).trigger('submit'); | ||
284 | + Toastr.info("执行了自定义搜索操作"); | ||
285 | + } | ||
286 | + }, | ||
287 | + browser: { | ||
288 | + 'click .btn-browser': function (e, value, row, index) { | ||
289 | + e.stopPropagation(); | ||
290 | + Layer.alert("该行数据为: <code>" + JSON.stringify(row) + "</code>"); | ||
291 | + } | ||
292 | + }, | ||
293 | + } | ||
294 | + } | ||
295 | + }; | ||
296 | + return Controller; | ||
297 | +}); |
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: 'example/colorbadge/index', | ||
9 | + add_url: '', | ||
10 | + edit_url: '', | ||
11 | + del_url: 'example/colorbadge/del', | ||
12 | + multi_url: '', | ||
13 | + } | ||
14 | + }); | ||
15 | + | ||
16 | + var table = $("#table"); | ||
17 | + | ||
18 | + // 初始化表格 | ||
19 | + table.bootstrapTable({ | ||
20 | + url: $.fn.bootstrapTable.defaults.extend.index_url, | ||
21 | + columns: [ | ||
22 | + [ | ||
23 | + {field: 'state', checkbox: true, }, | ||
24 | + {field: 'id', title: 'ID'}, | ||
25 | + {field: 'title', title: __('Title')}, | ||
26 | + {field: 'ip', title: __('IP')}, | ||
27 | + {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true}, | ||
28 | + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} | ||
29 | + ] | ||
30 | + ], | ||
31 | + onLoadSuccess: function (data) { | ||
32 | + // 在表格第次加载成功后,刷新左侧菜单栏彩色小角标,支持一次渲染多个 | ||
33 | + // 如果需要在进入后台即显示左侧的彩色小角标,请使用服务端渲染方式,详情修改application/admin/controller/Index.php | ||
34 | + Backend.api.sidebar({ | ||
35 | + 'example/colorbadge': data.total | ||
36 | + }); | ||
37 | + Toastr.info("左侧角标已经刷新成功"); | ||
38 | + } | ||
39 | + }); | ||
40 | + | ||
41 | + // 为表格绑定事件 | ||
42 | + Table.api.bindevent(table); | ||
43 | + }, | ||
44 | + add: function () { | ||
45 | + Form.api.bindevent($("form[role=form]")); | ||
46 | + }, | ||
47 | + edit: function () { | ||
48 | + Form.api.bindevent($("form[role=form]")); | ||
49 | + } | ||
50 | + }; | ||
51 | + return Controller; | ||
52 | +}); |
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: 'example/controllerjump/index', | ||
9 | + add_url: '', | ||
10 | + edit_url: '', | ||
11 | + del_url: 'example/controllerjump/del', | ||
12 | + multi_url: '', | ||
13 | + } | ||
14 | + }); | ||
15 | + | ||
16 | + var table = $("#table"); | ||
17 | + | ||
18 | + // 初始化表格 | ||
19 | + table.bootstrapTable({ | ||
20 | + url: $.fn.bootstrapTable.defaults.extend.index_url, | ||
21 | + columns: [ | ||
22 | + [ | ||
23 | + {field: 'state', checkbox: true, }, | ||
24 | + {field: 'id', title: 'ID'}, | ||
25 | + {field: 'admin_id', title: __('Admin_id')}, | ||
26 | + {field: 'title', title: __('Title')}, | ||
27 | + {field: 'ip', title: __('IP'), formatter: Controller.api.formatter.ip}, | ||
28 | + {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true}, | ||
29 | + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} | ||
30 | + ] | ||
31 | + ] | ||
32 | + }); | ||
33 | + | ||
34 | + // 为表格绑定事件 | ||
35 | + Table.api.bindevent(table); | ||
36 | + }, | ||
37 | + add: function () { | ||
38 | + Form.api.bindevent($("form[role=form]")); | ||
39 | + }, | ||
40 | + edit: function () { | ||
41 | + Form.api.bindevent($("form[role=form]")); | ||
42 | + }, | ||
43 | + api: { | ||
44 | + formatter: { | ||
45 | + ip: function (value, row, index) { | ||
46 | + //这里手动构造URL | ||
47 | + url = "example/bootstraptable?" + this.field + "=" + value; | ||
48 | + | ||
49 | + //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容 | ||
50 | + return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("Search %s", value) + '">' + __('Search %s', value) + '</a>'; | ||
51 | + | ||
52 | + //方式二,直接调用Table.api.formatter.addtabs | ||
53 | + return Table.api.formatter.addtabs(value, row, index, url); | ||
54 | + } | ||
55 | + } | ||
56 | + } | ||
57 | + }; | ||
58 | + return Controller; | ||
59 | +}); |
1 | +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { | ||
2 | + | ||
3 | + var Controller = { | ||
4 | + index: function () { | ||
5 | + //因为日期选择框不会触发change事件,导致无法刷新textarea,所以加上判断 | ||
6 | + $(document).on("dp.change", "#second-form .datetimepicker", function () { | ||
7 | + $(this).parent().prev().find("input").trigger("change"); | ||
8 | + }); | ||
9 | + $(document).on("fa.event.appendfieldlist", "#second-form .btn-append", function (e, obj) { | ||
10 | + Form.events.selectpage(obj); | ||
11 | + Form.events.datetimepicker(obj); | ||
12 | + }); | ||
13 | + Form.api.bindevent($("form[role=form]"), function (data, ret) { | ||
14 | + Layer.alert(data.data); | ||
15 | + }); | ||
16 | + }, | ||
17 | + }; | ||
18 | + return Controller; | ||
19 | +}); |
1 | +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { | ||
2 | + var Controller = { | ||
3 | + index: function () { | ||
4 | + // | ||
5 | + // 初始化表格参数配置 | ||
6 | + Table.api.init({ | ||
7 | + extend: { | ||
8 | + index_url: 'example/customsearch/index', | ||
9 | + add_url: 'example/customsearch/add', | ||
10 | + edit_url: 'example/customsearch/edit', | ||
11 | + del_url: 'example/customsearch/del', | ||
12 | + multi_url: 'example/customsearch/multi', | ||
13 | + table: '', | ||
14 | + } | ||
15 | + }); | ||
16 | + | ||
17 | + var table = $("#table"); | ||
18 | + | ||
19 | + // 初始化表格 | ||
20 | + table.bootstrapTable({ | ||
21 | + url: $.fn.bootstrapTable.defaults.extend.index_url, | ||
22 | + pk: 'id', | ||
23 | + sortName: 'id', | ||
24 | + searchFormVisible: true, | ||
25 | + searchFormTemplate: 'customformtpl', | ||
26 | + columns: [ | ||
27 | + [ | ||
28 | + {checkbox: true}, | ||
29 | + {field: 'id', title: 'ID', operate: false}, | ||
30 | + {field: 'admin_id', title: __('Admin_id'), visible: false, operate: false}, | ||
31 | + {field: 'username', title: __('Username'), formatter: Table.api.formatter.search}, | ||
32 | + {field: 'title', title: __('Title')}, | ||
33 | + {field: 'url', title: __('Url'), align: 'left'}, | ||
34 | + {field: 'ip', title: __('IP')}, | ||
35 | + {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true}, | ||
36 | + { | ||
37 | + field: 'operate', | ||
38 | + title: __('Operate'), | ||
39 | + table: table, | ||
40 | + events: Table.api.events.operate, | ||
41 | + formatter: Table.api.formatter.operate | ||
42 | + } | ||
43 | + ] | ||
44 | + ] | ||
45 | + }); | ||
46 | + | ||
47 | + // 为表格绑定事件 | ||
48 | + Table.api.bindevent(table); | ||
49 | + }, | ||
50 | + add: function () { | ||
51 | + Controller.api.bindevent(); | ||
52 | + }, | ||
53 | + edit: function () { | ||
54 | + Controller.api.bindevent(); | ||
55 | + }, | ||
56 | + api: { | ||
57 | + bindevent: function () { | ||
58 | + Form.api.bindevent($("form[role=form]")); | ||
59 | + } | ||
60 | + } | ||
61 | + }; | ||
62 | + return Controller; | ||
63 | +}); |
1 | +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { | ||
2 | + | ||
3 | + var Controller = { | ||
4 | + index: function () { | ||
5 | + $("#cxselect-example .col-xs-12").each(function () { | ||
6 | + $("textarea", this).val($(this).prev().prev().html().replace(/[ ]{2}/g, '')); | ||
7 | + }); | ||
8 | + | ||
9 | + //这里需要手动为Form绑定上元素事件 | ||
10 | + Form.api.bindevent($("form#cxselectform")); | ||
11 | + } | ||
12 | + }; | ||
13 | + return Controller; | ||
14 | +}); |
-
请 注册 或 登录 后发表评论