Skip to content

Commit 87cd3f6

Browse files
author
hikki
committed
beta
1 parent 0897b1f commit 87cd3f6

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

ComponentViewer.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88
use Encore\Admin\Layout\Content;
99
use Illuminate\Http\Request;
1010

11+
/**
12+
* Class ComponentViewer
13+
* @package App\Admin\Controllers
14+
*/
1115
class ComponentViewer
1216
{
17+
/**
18+
* 创建弹窗新增表单-按钮
19+
* @param Grid\Tools $tools
20+
*/
1321
public static function makeAddFormAction(Grid\Tools $tools){
1422
$url = Request::capture()->getPathInfo();
1523
Admin::script(<<<EOF
@@ -35,6 +43,7 @@ public function render()
3543
}
3644

3745
/**
46+
* 创建弹窗修改表单-按钮
3847
* @param Grid $grid
3948
*/
4049
public static function makeEditFormAction(Grid &$grid)
@@ -63,6 +72,7 @@ public function render()
6372
}
6473

6574
/**
75+
* 创建弹窗修改表单-按钮
6676
* 旧版图标模式
6777
* @param Grid $grid
6878
*/
@@ -83,11 +93,28 @@ public static function _makeEditFormAction(Grid &$grid)
8393
});
8494
}
8595

96+
/**
97+
* 弹窗表单内容生成
98+
* @param Content $content
99+
* @return array|string
100+
* @throws \Throwable
101+
*/
86102
public static function makeForm(Content $content)
87103
{
88104
$items = [
89105
'_content_' => str_replace('pjax-container', '', $content->build())
90106
];
91107
return view('admin.content', $items)->render();
92108
}
109+
110+
public static function result($success=true,$message='OK',$data=[])
111+
{
112+
return response()->json([
113+
'code'=>$success?1:0,
114+
'data'=>$data,
115+
'message'=>$message
116+
],200)
117+
->header('Content-Type','application/json;charset=utf-8')
118+
->header('Access-Control-Allow-Origin', '*');
119+
}
93120
}

component.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ let _componentCommonBlock = {
4848
}
4949
};
5050

51+
function componentAlert(message,time=1,callback=function () {}) {
52+
var div = document.createElement('div');
53+
div.innerHTML = message;
54+
let w = window.innerWidth/2 - 140;
55+
let h = window.innerHeight/2 - 145;
56+
div.style = "z-index: 1000000; position: fixed;background-color: rgba(0,0,0,.6);color: #fff;" +
57+
"width: 280px;height: 45px;line-height: 40px;border-radius: 3px;text-align: center;" +
58+
"top:"+h+"px;left:"+w+"px;";
59+
document.getElementsByTagName("BODY")[0].appendChild(div);
60+
var task = setTimeout(function () {
61+
clearTimeout(task);
62+
div.parentNode.removeChild(div);
63+
callback();
64+
},time*1000);
65+
}
66+
5167
function componentSelect(name,selected,options) {
5268
function tagSelect() {
5369
var cdom = this.cloneNode(true);
@@ -321,7 +337,14 @@ function componentForm(url,method='POST'){
321337
});
322338

323339
_componentCommonBlock._request(url,method,data,function (response) {
324-
window.location.reload();
340+
if(response.code == 1) {
341+
window.location.reload();
342+
}else{
343+
componentAlert(response.message,3,function () {
344+
obj.removeAttribute('disabled');
345+
obj.innerText = '提交';
346+
});
347+
}
325348
});
326349
},
327350
_createBox: function (url) {

0 commit comments

Comments
 (0)