| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- async function request($url, $data, $method = 'POST') {
- return await new Promise((resolve, reject) => {
- $.ajax({
- type: $method,
- url: $url,
- data: $data,
- success: (res) => {
- // if(res.code === 1012) {
- // window.location = 'http://localhost:8001/admin/login'
- // }
- resolve(res)
- },
- error: (err) => {
- reject(err.message)
- }
- })
- })
- }
- // 搜索开关
- function select_card_switch() {
- const element = $('#select_card_caviar')
- if (element.css('display') === 'none') {
- element.css('display', 'block');
- $("#caviar_search_btn").val("关闭搜索")
- } else {
- element.css('display', 'none');
- $("#caviar_search_btn").val("展开搜索")
- }
- }
- function check_params(p = []) {
- const index = p.findIndex(v => v !== undefined && v.toString().length > 0);
- return index >= 0;
- }
- function checkbox() {
- const isSelect = $("#check-all").is(":checked")
- isSelect ? $("input[class='checkbox_caviar']").each(function (i, n) {
- n.checked = true;
- }) : $("input[class='checkbox_caviar']").each(function (i, n) {
- n.checked = false;
- })
- }
- async function caviar_checkbox_delete(url,
- hints = ['Check at least one box', 'Succeed'],
- title = 'Warn',
- content = 'Are you sure you want to delete the selected data?',
- btn = ['Confirm'],
- ids_data = undefined
- ) {
- const ids = $('.checkbox_caviar:checkbox:checked').map((index, el) => {
- return $(el).val();
- }).get();
- if (ids.length === 0 && ids_data === undefined) {
- layer.msg(hints[0], {icon: 5})
- return false;
- }
- layer.open({
- title,
- content,
- btn,
- yes: async (index, layero) => {
- const response = await request(url, {ids: ids_data ? ids_data.join(',') : ids.join(',')});
- response.code === 200 ? layer.msg(hints[1], {icon: 1, time: 500}, () => {
- location.reload();
- }) : layer.msg(res.message, {icon: 5})
- layer.close(index);
- }
- });
- }
- function deletingASingle(url,
- id,
- hints = ['Succeed'],
- title = 'Warn',
- content = 'Are you sure you want to delete the selected data?',
- btn = ['Confirm']) {
- layer.open({
- title: title,
- content: content,
- btn: btn,
- yes: async (index, layero) => {
- const response = await request(url, {ids: id.toString()});
- response.code === 200 ? layer.msg(hints[0], {icon: 1, time: 500}, () => {
- location.reload();
- }) : layer.msg(res.message, {icon: 5})
- layer.close(index);
- }
- });
- }
- function add(url = '', title = "Info", area = ['60%', '80%']) {
- layui.use('layer', function () {
- var layer = layui.layer;
- layer.open({
- title: title,
- type: 2,
- content: url,
- area: area,
- });
- });
- }
- function view(url = '', title = "Info", area = ['80%', '80%']) {
- layui.use('layer', function () {
- var layer = layui.layer;
- layer.open({
- title: title,
- type: 2,
- content: url,
- area: area,
- });
- });
- }
- function image_magnify() {
- let jishu = 0;
- $(document).on('click', '.small-img', function (data) {
- var ImgUrl = $(this).attr('src');
- if (jishu === 0) {
- jishu = 1;
- layer.open({
- type: 1
- , title: false
- , closeBtn: 0
- , skin: 'layui-layer-nobg'
- , shadeClose: true
- , content: '<img style="width:100%;height:100%;" class="layui-upload-img" src="' + ImgUrl + '"/>'
- , scrollbar: false
- })
- } else {
- jishu = 0;
- layer.closeAll();
- }
- })
- }
- function deepTraversal(tree = []) {
- let nodes = [];
- const queues = tree.map(v => v);
- while (queues.length > 0) {
- const queue = queues.pop();
- if (queue.children !== undefined && queue.children.length > 0) {
- queue.children.forEach(child => {
- queues.push(child)
- })
- }
- nodes.push({
- id: queue.id,
- title: queue.title,
- field: queue.field,
- checked: true,
- })
- }
- return nodes;
- }
- function urlencode (str) {
- str = (str + '').toString();
- return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
- replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
- }
|