Skip to content

Commit 9bbf956

Browse files
author
hikki
committed
2.0
1 parent 6d98fdf commit 9bbf956

File tree

2 files changed

+61
-65
lines changed

2 files changed

+61
-65
lines changed

resources/assets/component.js

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const _componentSvg = {
1+
const _component = {
22
'trash': `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
33
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
44
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
@@ -25,55 +25,51 @@ type="rotate"from="0 20 20"to="360 20 20"dur="0.5s"repeatCount="indefinite"/></p
2525
'check_circle': `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-circle" viewBox="0 0 16 16">
2626
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
2727
<path d="M10.97 4.97a.235.235 0 0 0-.02.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05z"/>
28-
</svg>`
29-
};
30-
31-
function _componentRequest(url, method = "GET", data = {}, callback = function () {
32-
}) {
33-
let xhr = new XMLHttpRequest();
34-
xhr.open(method, url, true);
35-
xhr.timeout = 30000;
36-
let token = '';
37-
if (document.querySelector('meta[name="csrf-token"]')) {
38-
token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
39-
}
40-
xhr.setRequestHeader("X-CSRF-TOKEN", token);
41-
if (method === 'GET') {
42-
xhr.setRequestHeader("Content-type", "application/text;charset=UTF-8");
43-
xhr.responseType = "text";
44-
xhr.send(null);
45-
} else {
46-
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
47-
xhr.responseType = "json";
48-
xhr.send(data);
49-
}
50-
xhr.onreadystatechange = function () {
51-
if (xhr.readyState === xhr.DONE && xhr.status === 200) {
52-
let response = xhr.response;
53-
callback(response);
28+
</svg>`,
29+
request:function (url, method = "GET", data = {}, callback = null) {
30+
let xhr = new XMLHttpRequest();
31+
xhr.open(method, url, true);
32+
xhr.timeout = 30000;
33+
let token = '';
34+
if (document.querySelector('meta[name="csrf-token"]')) {
35+
token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
36+
}
37+
xhr.setRequestHeader("X-CSRF-TOKEN", token);
38+
if (method === 'GET') {
39+
xhr.setRequestHeader("Content-type", "application/text;charset=UTF-8");
40+
xhr.responseType = "text";
41+
xhr.send(null);
42+
} else {
43+
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
44+
xhr.responseType = "json";
45+
xhr.send(data);
5446
}
55-
};
56-
xhr.onerror = function (e) {
57-
console.error(e);
58-
};
59-
}
60-
61-
function _componentAlert(message, time = 1, callback = function () {
62-
}) {
63-
let div = document.createElement('div');
64-
div.innerHTML = message;
65-
let w = window.innerWidth / 2 - 140;
66-
let h = window.innerHeight / 2 - 145;
67-
div.style = "z-index: 1000000; position: fixed;background-color: rgba(0,0,0,.6);color: #fff;" +
68-
"width: 280px;height: 45px;line-height: 40px;border-radius: 3px;text-align: center;" +
69-
"top:" + h + "px;left:" + w + "px;";
70-
document.getElementsByTagName("BODY")[0].appendChild(div);
71-
var task = setTimeout(function () {
72-
clearTimeout(task);
73-
div.parentNode.removeChild(div);
74-
callback();
75-
}, time * 1000);
76-
}
47+
xhr.onreadystatechange = function () {
48+
if (xhr.readyState === xhr.DONE && xhr.status === 200) {
49+
let response = xhr.response;
50+
if(typeof callback === 'function') callback(response);
51+
}
52+
};
53+
xhr.onerror = function (e) {
54+
console.error(e);
55+
};
56+
},
57+
alert:function (message, time = 1, callback = null) {
58+
let div = document.createElement('div');
59+
div.innerHTML = message;
60+
let w = window.innerWidth / 2 - 140;
61+
let h = window.innerHeight / 2 - 145;
62+
div.style = "z-index: 1000000; position: fixed;background-color: rgba(0,0,0,.6);color: #fff;" +
63+
"width: 280px;height: 45px;line-height: 40px;border-radius: 3px;text-align: center;" +
64+
"top:" + h + "px;left:" + w + "px;";
65+
document.getElementsByTagName("BODY")[0].appendChild(div);
66+
var task = setTimeout(function () {
67+
clearTimeout(task);
68+
div.parentNode.removeChild(div);
69+
if(typeof callback === 'function') callback();
70+
}, time * 1000);
71+
}
72+
};
7773

7874
class ComponentDot {
7975
MODE = {
@@ -338,7 +334,7 @@ class ComponentCascadeDot {
338334
this.tagCal(id, this.MODE.insert);
339335
element.classList.remove('dlp-label-silence');
340336
element.querySelector('i') != null && element.removeChild(element.querySelector('i'));
341-
element.insertAdjacentHTML('beforeend', `<i>${_componentSvg.check}</i>`);
337+
element.insertAdjacentHTML('beforeend', `<i>${_component.check}</i>`);
342338
this.selectToChildren(stack + 1, data.nodes);
343339
this.selectToSelected(element, stack);
344340
this.SELECTED_DOM.scrollTop = this.SELECTED_DOM.scrollHeight;
@@ -404,7 +400,7 @@ class ComponentCascadeDot {
404400
}
405401
if (checked === true && node === data.key && data.mark !== true) {
406402
data.mark = true;
407-
D.insertAdjacentHTML('beforeend', `<i>${_componentSvg.check_circle}</i>`);
403+
D.insertAdjacentHTML('beforeend', `<i>${_component.check_circle}</i>`);
408404
}
409405
if (checked === false && node === data.key) {
410406
let nodes = this.dimensional_data[stack][index].nodes;
@@ -659,7 +655,7 @@ class ComponentLine {
659655
var object = this;
660656
var i = document.createElement('i');
661657
i.style = 'cursor: pointer';
662-
i.insertAdjacentHTML('afterbegin', _componentSvg.write);
658+
i.insertAdjacentHTML('afterbegin', _component.write);
663659
i.addEventListener('click', function () {
664660
let inputs = object.DOM.getElementsByTagName('tfoot')[0].getElementsByTagName('input');
665661
let insert = {};
@@ -727,14 +723,14 @@ class ComponentLine {
727723
let M = document.createElement('i');
728724
M.setAttribute('style', 'cursor: pointer;margin-right:5px;');
729725
M.setAttribute('sortable-handle', 'sortable-handle');
730-
M.insertAdjacentHTML('afterbegin', _componentSvg.move);
726+
M.insertAdjacentHTML('afterbegin', _component.move);
731727
td.appendChild(M);
732728
}
733729

734730
if (this.OPTIONS.delete) {
735731
let D = document.createElement('span');
736732
D.setAttribute('style', 'cursor: pointer;display: inline-block;');
737-
D.insertAdjacentHTML('afterbegin', _componentSvg.trash);
733+
D.insertAdjacentHTML('afterbegin', _component.trash);
738734
D.addEventListener('click', function () {
739735
let tr = this.parentNode.parentNode;
740736
let tbody = tr.parentNode;
@@ -788,7 +784,7 @@ class ComponentPlane {
788784
this.DOM = document.getElementById('dlp-plane');
789785
/*X*/
790786
let X = document.createElement('i');
791-
X.insertAdjacentHTML('afterbegin', _componentSvg.close);
787+
X.insertAdjacentHTML('afterbegin', _component.close);
792788
let object = this;
793789
X.addEventListener('click', function () {
794790
if (object.DOM instanceof HTMLElement) {
@@ -805,7 +801,7 @@ class ComponentPlane {
805801
makeContent() {
806802
this.loading();
807803
var object = this;
808-
_componentRequest(this.URL, 'GET', {}, function (response) {
804+
_component.request(this.URL, 'GET', {}, function (response) {
809805
object.loading(true);
810806
/*object.MODEL_BODY_DOM.innerHTML = response;*/
811807
$('#dlp-plane .plane-body').append(response);
@@ -822,7 +818,7 @@ class ComponentPlane {
822818
let form = this.MODEL_BODY_DOM.getElementsByTagName('form')[0];
823819
let formdata = new FormData(form);
824820
var object = this;
825-
_componentRequest(this.XHR_URL, this.METHOD, formdata, function (response) {
821+
_component.request(this.XHR_URL, this.METHOD, formdata, function (response) {
826822
if (typeof object.CALLBACK == 'function') {
827823
object.CALLBACK(response);
828824
return;
@@ -831,7 +827,7 @@ class ComponentPlane {
831827
window.location.reload();
832828
return;
833829
} else {
834-
_componentAlert(response.message, 3, function () {
830+
_component.alert(response.message, 3, function () {
835831
element.removeAttribute('disabled');
836832
element.innerText = '提交';
837833
});
@@ -850,7 +846,7 @@ class ComponentPlane {
850846
}
851847
this.LOADING_DOM = document.createElement('div');
852848
this.LOADING_DOM.style = 'width: 100%;height: 100px;';
853-
this.LOADING_DOM.insertAdjacentHTML('afterbegin', _componentSvg.loading);
849+
this.LOADING_DOM.insertAdjacentHTML('afterbegin', _component.loading);
854850
this.MODEL_BODY_DOM.append(this.LOADING_DOM);
855851
}
856852
}

src/DLPViewer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DLPViewer
2727
* settings.width string 容器宽度设置
2828
* settings.height string 容器高度设置
2929
*/
30-
public static function makeComponentDot(Form $form, string $column, string $title, array $selected = [], array $select = [], array $settings = [])
30+
public static function dot(Form $form, string $column, string $title, array $selected = [], array $select = [], array $settings = [])
3131
{
3232
$strict = isset($settings['strict']) && $settings['strict'] ? true : false;
3333
$width = isset($settings['width']) ? $settings['width'] : '100%';
@@ -61,7 +61,7 @@ public static function makeComponentDot(Form $form, string $column, string $titl
6161
* settings.width string 容器宽度设置
6262
* settings.height string 容器高度设置
6363
*/
64-
public static function makeComponentCascadeDot(Form $form, string $column, string $title, array $selected = [], array $select = [], array $settings = [])
64+
public static function cascadeDot(Form $form, string $column, string $title, array $selected = [], array $select = [], array $settings = [])
6565
{
6666
$strict = isset($settings['strict']) && $settings['strict'] ? true : false;
6767
$width = isset($settings['width']) ? $settings['width'] : '100%';
@@ -102,7 +102,7 @@ public static function makeComponentCascadeDot(Form $form, string $column, strin
102102
* 'delete'=>true 删除操作
103103
* ]
104104
*/
105-
public static function makeComponentLine(Form $form, string $column, string $title, array $data, array $settings = [])
105+
public static function line(Form $form, string $column, string $title, array $data, array $settings = [])
106106
{
107107
$strict = isset($settings['strict']) && $settings['strict'] ? true : false;
108108
$width = isset($settings['width']) ? $settings['width'] : '100%';
@@ -136,7 +136,7 @@ public static function makeComponentLine(Form $form, string $column, string $tit
136136
* settings.options 弹窗配置项 array(选填)
137137
* options = ['W'=>0.8,'H'=>0.8] W宽 H高
138138
*/
139-
public static function makeHeadPlaneAction(Grid $grid, array $settings = [])
139+
public static function headPlaneAction(Grid $grid, array $settings = [])
140140
{
141141
$script = '';
142142
foreach ($settings as $setting) {
@@ -189,7 +189,7 @@ public function render()
189189
* options = ['W'=>0.8,'H'=>0.8] W宽 H高
190190
* @param array $disable ['view','edit','delete'] 禁止操作按钮
191191
*/
192-
public static function makeRowPlaneAction(Grid $grid, array $settings = [], array $disable = [])
192+
public static function rowPlaneAction(Grid $grid, array $settings = [], array $disable = [])
193193
{
194194
$script = '';
195195
foreach ($settings as $setting) {
@@ -249,7 +249,7 @@ public function render()
249249
* options = ['W'=>0.8,'H'=>0.8] W宽 H高
250250
* @param array $disable ['view','edit','delete'] 禁止操作按钮
251251
*/
252-
public static function _makeRowPlaneAction(Grid $grid, array $settings = [], array $disable = [])
252+
public static function _rowPlaneAction(Grid $grid, array $settings = [], array $disable = [])
253253
{
254254
$script = '';
255255
foreach ($settings as $setting) {

0 commit comments

Comments
 (0)