加入block-ui及select2輔助函式
This commit is contained in:
parent
acbc178c41
commit
179e369f0b
1
resources/js/admin/lib.js
vendored
1
resources/js/admin/lib.js
vendored
@ -23,6 +23,7 @@ import 'chart.js';
|
|||||||
import '@coreui/coreui-plugin-chartjs-custom-tooltips';
|
import '@coreui/coreui-plugin-chartjs-custom-tooltips';
|
||||||
import 'datatables.net-bs4';
|
import 'datatables.net-bs4';
|
||||||
import 'datatables.net-responsive-bs4';
|
import 'datatables.net-responsive-bs4';
|
||||||
|
import 'block-ui';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|||||||
10
resources/js/app-common.js
vendored
10
resources/js/app-common.js
vendored
@ -1,5 +1,6 @@
|
|||||||
import {dataTable} from "./utils/datatable";
|
import {dataTable} from "./utils/datatable";
|
||||||
|
import {block, blockElement, unblock, unblockElement} from "./utils/blockui";
|
||||||
|
import {init as initSelect2} from './utils/select2';
|
||||||
|
|
||||||
$('.logout-btn').on('click', e => {
|
$('.logout-btn').on('click', e => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -11,4 +12,11 @@ $('.logout-btn').on('click', e => {
|
|||||||
*/
|
*/
|
||||||
app.utils = {
|
app.utils = {
|
||||||
dataTable: dataTable,
|
dataTable: dataTable,
|
||||||
|
blockui: {
|
||||||
|
blockElement: blockElement,
|
||||||
|
unblockElement: unblockElement,
|
||||||
|
block: block,
|
||||||
|
unblock: unblock
|
||||||
|
},
|
||||||
|
select2: initSelect2,
|
||||||
}
|
}
|
||||||
|
|||||||
20
resources/js/utils/blockui.js
vendored
Normal file
20
resources/js/utils/blockui.js
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
export const blockElement = function(ele, option = {}) {
|
||||||
|
$(ele).block(Object.assign({
|
||||||
|
message: null
|
||||||
|
}, option))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const unblockElement = function(ele) {
|
||||||
|
$(ele).unblock();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const block = function(ele, option = {}) {
|
||||||
|
$.blockUI(Object.assign({
|
||||||
|
message: ele,
|
||||||
|
onOverlayClick: $.unblockUI
|
||||||
|
}, option))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const unblock = function() {
|
||||||
|
$.unblockUI();
|
||||||
|
}
|
||||||
24
resources/js/utils/select2.js
vendored
Normal file
24
resources/js/utils/select2.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
export const init = (selector, options = {}) => {
|
||||||
|
return $(selector).select2(Object.assign({
|
||||||
|
templateResult: item => {
|
||||||
|
if (!item.id) {
|
||||||
|
return item.text;
|
||||||
|
}
|
||||||
|
let text = item.text,
|
||||||
|
search = $(selector).data('select2').dropdown.$search.val(),
|
||||||
|
_text = text.split(''),
|
||||||
|
startIndex = 0
|
||||||
|
$.each(search.split(''), (index, ch) => {
|
||||||
|
for (let i = startIndex; i < _text.length; i++) {
|
||||||
|
if(_text[i] == ch) {
|
||||||
|
_text[i] = '<span class="select2-rendered-highlight" style="color:red;">' + ch + '</span>'
|
||||||
|
startIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return $('<span>' + _text.join('') + '</span>');
|
||||||
|
}
|
||||||
|
}, options))
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user