Skip to content

Commit 4166ecf

Browse files
committed
V1.0
1 parent 7a05aab commit 4166ecf

File tree

9 files changed

+59
-34
lines changed

9 files changed

+59
-34
lines changed

Diff for: README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
- 视图模板都是采用比较流行的后台模板;
1010
- 自动生成搜索,分页,提示,排序等功能;
1111
- 生成一个表的完整的增删改;
12-
- 开发速度快速增加;
12+
- 开发速度快速增加,适合后台全栈开发,没有前端一样可以快速写出一套漂亮的后台
1313

14+
- 版本修改(2017/10/25) - V1.0:
15+
- 去除引入boostrap库,解决样式兼容性问题,样式全部改为layui样式;
16+
- 增加自动生成图片字段,数据库在字段中设置了关键字image,img,pic,logo会自动生成单张图片上传的代码,图片在列表中会自动展示;多张图片上传功能目前还需要手动完成;
17+
- 增加下拉列表,单选按钮样式;
18+
- 增加富文本编辑器样式,数据库字段中设置了类型为text,或者关键字中存在content等会自动在表单中生成富文本;
1419
- 缺点:
1520
- 目前只集成了layui模板,后续加入更多的模板;
16-
- boostrap库与layui库不兼容,只做了一部分的修改;
1721
- 不能自动生成导航,暂时需要手动配置好url
1822

1923
- 配置环境:
2024
- php;
2125
- mysql;
2226
- xampp;
2327
- Yii2;
28+
- 测试数据库 **./test.sql**
2429

2530
- 操作示例:
2631
>生成test表的增删改查示例,有id,姓名,电话,爱好等字段,在代码中生成模型,控制器,视图
@@ -44,7 +49,7 @@
4449
![微信图片_20171018174755.png](http://chuantu.biz/t6/103/1508376543x992584279.png)
4550

4651

47-
![微信图片_20171018174824.png](http://chuantu.biz/t6/103/1508376575x992584279.png)
52+
![微信图片_20171018174824.png](http://bmob-cdn-14725.b0.upaiyun.com/2017/10/25/d60eb7c0406ff13d80711fa63b23f1e0.jpg)
4853

4954

50-
![微信图片_20171018174829.png](http://chuantu.biz/t6/103/1508376594x992584279.png)
55+
![微信图片_20171018174829.png](http://bmob-cdn-14725.b0.upaiyun.com/2017/10/25/dfc30e1140ac918780dffc7256d8dee8.jpg)

Diff for: models/Test.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* @property integer $age
1414
* @property string $hobby
1515
* @property string $decr
16+
* @property integer $sex
17+
* @property string $area
18+
* @property string $logo
1619
*/
1720
class Test extends \yii\db\ActiveRecord
1821
{
@@ -32,7 +35,7 @@ public function rules()
3235
return [
3336
[['username' , 'age'], 'required'],
3437
[['age'], 'integer'],
35-
[['username', 'hobby', 'decr' , 'area'], 'string', 'max' => 255],
38+
[['username', 'hobby', 'decr', 'area', 'logo'], 'string', 'max' => 255],
3639
[['tel'], 'string', 'max' => 50],
3740
];
3841
}

Diff for: test.sql

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ CREATE TABLE `test` (
2626
`tel` varchar(50) NOT NULL DEFAULT '' COMMENT '电话号码',
2727
`age` tinyint(4) NOT NULL DEFAULT '0' COMMENT '年龄',
2828
`hobby` varchar(255) NOT NULL DEFAULT '' COMMENT '爱好',
29-
`decr` varchar(255) NOT NULL DEFAULT '' COMMENT '简介',
29+
`decr` text NOT NULL COMMENT '简介',
3030
`sex` tinyint(4) NOT NULL DEFAULT '0' COMMENT '性别',
31+
`area` varchar(255) NOT NULL DEFAULT '' COMMENT '地区',
32+
`logo` varchar(255) NOT NULL DEFAULT '' COMMENT '头像',
3133
PRIMARY KEY (`id`)
32-
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4;
34+
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4;
3335

3436
/*Data for the table `test` */
3537

36-
insert into `test`(`id`,`username`,`tel`,`age`,`hobby`,`decr`,`sex`) values (1,'嘉颖','1332222111',23,'篮球,足球','php开发程序员',0),(2,'小明','1325455544',24,'篮球,唱歌','c++',0),(3,'小红','1325455544',25,'篮球,唱歌','java',1),(4,'嘉颖','1332222111',23,'篮球,足球','php开发程序员',0),(5,'小明','1325455544',24,'篮球,唱歌','c++',0),(6,'小红','1325455544',25,'篮球,唱歌','java',1),(7,'嘉颖','1332222111',23,'篮球,足球','php开发程序员',0),(8,'小明','1325455544',24,'篮球,唱歌','c++',0),(9,'小红','1325455544',25,'篮球,唱歌','java',1),(10,'嘉颖','1332222111',23,'篮球,足球','php开发程序员',0);
38+
insert into `test`(`id`,`username`,`tel`,`age`,`hobby`,`decr`,`sex`,`area`,`logo`) values (1,'嘉颖','1332222111',23,'篮球,足球','php开发程序员<div>111</div>',0,'广东',''),(2,'小明','1325455544',24,'篮球,唱歌','c++',0,'广东',''),(3,'小红','1325455544',25,'篮球,唱歌','java',1,'广东',''),(4,'嘉颖','1332222111',23,'篮球,足球','php开发程序员',0,'广东',''),(5,'小明','1325455544',24,'篮球,唱歌','c++',0,'江苏',''),(6,'小红','1325455544',25,'篮球,唱歌','java',1,'江苏',''),(7,'嘉颖','1332222111',23,'篮球,足球','php开发程序员',0,'江苏',''),(8,'小明','1325455544',24,'篮球,唱歌','c++',0,'江苏',''),(9,'小红','1325455544',25,'篮球,唱歌','java',1,'北京',''),(10,'嘉颖','1332222111',23,'篮球,足球','php开发程序员',0,'北京',''),(14,'小黄','13251005451',18,'篮球','1024',0,'广东','uploads/59f03527245df.jpg'),(20,'Ewing','13250150526',15,'php','php开发',0,'广东','uploads/59f02f736d156.jpg');
3739

3840
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3941
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

Diff for: views/test/_form.php

+10-21
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
]
2121
); ?>
2222

23-
2423
<?= $form->field($model, 'username')->textInput(['style'=> 'width:30%','class' => "layui-input"]) ?>
2524

26-
<div class="upload_img_div <?php echo !$model->isNewRecord && $model->logo ? '' : 'hidden';?>">
27-
<img src="<?php echo !$model->isNewRecord && $model->logo ? $model->logo : ''?>" class="upload_img">
28-
</div>
2925
<?= $form->field($model, 'logo')->fileInput(['class' => "layui-upload-file"]) ?>
3026

3127
<?= $form->field($model, 'tel')->textInput(['style'=> 'width:30%','class' => "layui-input"]) ?>
@@ -64,6 +60,14 @@
6460

6561
<?php $this->beginBlock("servicea") ?>
6662

63+
layui.use('layedit', function(){
64+
var layedit = layui.layedit;
65+
layedit.build('test-decr', {
66+
height: 180, //设置编辑器高度
67+
width: 70, //设置编辑器宽度(百分比)
68+
});
69+
});
70+
6771
var options = {
6872
url: '<?=Yii::$app->urlManager->createUrl('test/uploadfile')?>',
6973
success: function(res){
@@ -72,6 +76,7 @@
7276
$('input[name="Test[logo]"][type="hidden"]').val(res.url);
7377
$('.upload_img').attr('src','/'+res.url);
7478
$('.upload_img_div').removeClass('hidden');
79+
layer.msg('上传成功');
7580
}else{
7681
layer.msg('上传失败'+res);
7782
}
@@ -80,12 +85,8 @@
8085

8186
layui.use('upload', function(){
8287
$("#test-logo").prepend('<input type="hidden" name="_csrf-backend" value="<?= Yii::$app->request->csrfToken ?>">');
83-
document.getElementById("create-form").removeEventListener("submit", function(e){
84-
alert('11');
85-
e.stopPropagation();
86-
});
88+
$("#test-logo").parent().before('<div class="upload_img_div <?php echo !$model->isNewRecord && $model->logo ? '' : 'hidden';?>"><img src="<?php echo !$model->isNewRecord && $model->logo ? $model->logo : ''?>" class="upload_img"></div>');
8789
layui.upload(options);
88-
8990
});
9091

9192
layui.use('form', function(){
@@ -95,18 +96,6 @@
9596
form.render("radio"); //更新全部
9697
});
9798

98-
layui.use('layedit', function(){
99-
var layedit = layui.layedit;
100-
layedit.build('test-decr', {
101-
height: 180, //设置编辑器高度
102-
width: 70, //设置编辑器宽度(百分比)
103-
});
104-
});
105-
106-
107-
108-
109-
11099

111100
<?php $this->endBlock() ?>
112101
<?php $this->registerJs($this->blocks["servicea"], \yii\web\View::POS_END); ?>

Diff for: views/test/index.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232

3333
'id',
3434
'username',
35+
[
36+
'attribute' => 'logo',
37+
'format' => ['image' , [ 'width'=>'80','height'=>'80']],
38+
'value' => function($data) {
39+
return $data['logo'];
40+
}
41+
],
3542
[
3643
'attribute' => 'sex',
3744
'value' => function($data) {
@@ -42,7 +49,13 @@
4249
'area',
4350
'age',
4451
'hobby',
45-
// 'decr',
52+
// [
53+
// 'attribute' => 'decr',
54+
// 'format' => 'raw',
55+
// 'value' => function($data) {
56+
// return $data['decr'];
57+
// }
58+
// ],
4659

4760
[
4861
'header' => '操作',

Diff for: web/css/layui/site.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ body .layui-layout-admin .layui-larry-foot .p-admin a{
12381238
}
12391239

12401240
.upload_img_div{
1241-
margin-left:110px;margin-bottom:5px
1241+
margin-left:130px;margin-bottom:5px
12421242
}
12431243
.upload_img{
12441244
width:100px;

Diff for: web/layui/lay_old/modules/upload.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ layui.define('layer', function(exports){
8686
};
8787

8888
//提交上传
89-
Upload.prototype.action = function(input, type){
89+
Upload.prototype.action = function(input, type ,e){
9090
var that = this, options = that.options, val = input.value;
9191
var item = $(input), ext = item.attr('lay-ext') || options.ext || ''; //获取支持上传的文件扩展名;
9292

@@ -123,8 +123,21 @@ layui.define('layer', function(exports){
123123
}
124124

125125
options.before && options.before(input);
126-
item.parent().submit();
127-
126+
// item.parent().submit(function(event){
127+
//     event.preventDefault();
128+
//   } );
129+
130+
$.ajax({
131+
processData: false,
132+
contentType: false,
133+
url : item.parent().attr('action'),
134+
type : 'post',
135+
data : new FormData(item.parent()[0]),
136+
dataType : 'json',
137+
success : function(res){
138+
options.success(res, input)
139+
}
140+
});
128141

129142
var iframe = $('#'+elemIframe), timer = setInterval(function() {
130143
var res;

Diff for: web/uploads/59f02f736d156.jpg

8.46 KB
Loading

Diff for: web/uploads/59f03527245df.jpg

4.14 KB
Loading

0 commit comments

Comments
 (0)