mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 03:22:51 +08:00
新增表格初始化搜索功能;新增getQueryVariable助手函数.
This commit is contained in:
@@ -29,20 +29,21 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
}],
|
}],
|
||||||
'delete', 'export'],
|
'delete', 'export'],
|
||||||
cols: [[
|
cols: [[
|
||||||
{type: "checkbox"},
|
{ type: "checkbox" },
|
||||||
{field: 'id', width: 80, title: 'ID'},
|
{ field: 'id', width: 80, title: 'ID' },
|
||||||
{field: 'sort', width: 80, title: '排序', edit: 'text'},
|
{ field: 'sort', width: 80, title: '排序', edit: 'text' },
|
||||||
{field: 'cate.title', minWidth: 80, title: '商品分类'},
|
{ field: 'cate.title', minWidth: 80, title: '商品分类', },
|
||||||
{field: 'title', minWidth: 80, title: '商品名称'},
|
{ field: 'cate.id', minWidth: 80, title: '商品分类', hide: true, defaultSearchValue: ea.getQueryVariable('cate_id', '') },
|
||||||
{field: 'logo', minWidth: 80, title: '分类图片', search: false, templet: ea.table.image},
|
{ field: 'title', minWidth: 80, title: '商品名称', },
|
||||||
{field: 'market_price', width: 100, title: '市场价', templet: ea.table.price},
|
{ field: 'logo', minWidth: 80, title: '分类图片', search: false, templet: ea.table.image },
|
||||||
{field: 'discount_price', width: 100, title: '折扣价', templet: ea.table.price},
|
{ field: 'market_price', width: 100, title: '市场价', templet: ea.table.price },
|
||||||
{field: 'total_stock', width: 100, title: '库存统计'},
|
{ field: 'discount_price', width: 100, title: '折扣价', templet: ea.table.price },
|
||||||
{field: 'stock', width: 100, title: '剩余库存'},
|
{ field: 'total_stock', width: 100, title: '库存统计' },
|
||||||
{field: 'virtual_sales', width: 100, title: '虚拟销量'},
|
{ field: 'stock', width: 100, title: '剩余库存' },
|
||||||
{field: 'sales', width: 80, title: '销量'},
|
{ field: 'virtual_sales', width: 100, title: '虚拟销量' },
|
||||||
{field: 'status', title: '状态', width: 85, selectList: {0: '禁用', 1: '启用'}, templet: ea.table.switch},
|
{ field: 'sales', width: 80, title: '销量' },
|
||||||
{field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'},
|
{ field: 'status', title: '状态', width: 85, selectList: { 0: '禁用', 1: '启用' }, templet: ea.table.switch },
|
||||||
|
{ field: 'create_time', minWidth: 80, title: '创建时间', search: 'range' },
|
||||||
{
|
{
|
||||||
width: 250,
|
width: 250,
|
||||||
title: '操作',
|
title: '操作',
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
|||||||
|
|
||||||
// 初始化表格搜索
|
// 初始化表格搜索
|
||||||
if (options.search === true) {
|
if (options.search === true) {
|
||||||
admin.table.renderSearch(options.cols, options.elem, options.id);
|
options = admin.table.renderSearch(options.cols, options.elem, options.id, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化表格左上方工具栏
|
// 初始化表格左上方工具栏
|
||||||
@@ -320,11 +320,13 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
|||||||
});
|
});
|
||||||
return '<div>' + toolbarHtml + '</div>';
|
return '<div>' + toolbarHtml + '</div>';
|
||||||
},
|
},
|
||||||
renderSearch: function (cols, elem, tableId) {
|
renderSearch: function (cols, elem, tableId, options) {
|
||||||
// TODO 只初始化第一个table搜索字段,如果存在多个(绝少数需求),得自己去扩展
|
// TODO 只初始化第一个table搜索字段,如果存在多个(绝少数需求),得自己去扩展
|
||||||
cols = cols[0] || {};
|
cols = cols[0] || {};
|
||||||
var newCols = [];
|
var newCols = [];
|
||||||
var formHtml = '';
|
var formHtml = '';
|
||||||
|
var formatFilter = {},
|
||||||
|
formatOp = {};
|
||||||
$.each(cols, function (i, d) {
|
$.each(cols, function (i, d) {
|
||||||
d.field = d.field || false;
|
d.field = d.field || false;
|
||||||
d.fieldAlias = admin.parame(d.fieldAlias, d.field);
|
d.fieldAlias = admin.parame(d.fieldAlias, d.field);
|
||||||
@@ -333,8 +335,19 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
|||||||
d.search = admin.parame(d.search, true);
|
d.search = admin.parame(d.search, true);
|
||||||
d.searchTip = d.searchTip || '请输入' + d.title || '';
|
d.searchTip = d.searchTip || '请输入' + d.title || '';
|
||||||
d.searchValue = d.searchValue || '';
|
d.searchValue = d.searchValue || '';
|
||||||
|
d.defaultSearchValue = d.defaultSearchValue || '';
|
||||||
d.searchOp = d.searchOp || '%*%';
|
d.searchOp = d.searchOp || '%*%';
|
||||||
d.timeType = d.timeType || 'datetime';
|
d.timeType = d.timeType || 'datetime';
|
||||||
|
|
||||||
|
if (d.defaultSearchValue.length > 0) {
|
||||||
|
if (d.searchValue.length == 0) {
|
||||||
|
d.searchValue = d.defaultSearchValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
formatFilter[d.field] = d.defaultSearchValue;
|
||||||
|
formatOp[d.field] = d.searchOp;
|
||||||
|
}
|
||||||
|
|
||||||
if (d.field !== false && d.search !== false) {
|
if (d.field !== false && d.search !== false) {
|
||||||
switch (d.search) {
|
switch (d.search) {
|
||||||
case true:
|
case true:
|
||||||
@@ -348,6 +361,7 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
|||||||
case 'select':
|
case 'select':
|
||||||
d.searchOp = '=';
|
d.searchOp = '=';
|
||||||
var selectHtml = '';
|
var selectHtml = '';
|
||||||
|
|
||||||
$.each(d.selectList, function (sI, sV) {
|
$.each(d.selectList, function (sI, sV) {
|
||||||
var selected = '';
|
var selected = '';
|
||||||
if (sI === d.searchValue) {
|
if (sI === d.searchValue) {
|
||||||
@@ -413,6 +427,13 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.where = {
|
||||||
|
filter: JSON.stringify(formatFilter),
|
||||||
|
op: JSON.stringify(formatOp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
},
|
},
|
||||||
renderSwitch: function (cols, tableInit, tableId, modifyReload) {
|
renderSwitch: function (cols, tableInit, tableId, modifyReload) {
|
||||||
tableInit.modify_url = tableInit.modify_url || false;
|
tableInit.modify_url = tableInit.modify_url || false;
|
||||||
@@ -1559,6 +1580,20 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
getQueryVariable(variable, defaultValue) {
|
||||||
|
if (typeof defaultValue == 'undefined') {
|
||||||
|
defaultValue = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
var query = window.location.search.substring(1);
|
||||||
|
var vars = query.split("&");
|
||||||
|
for (var i = 0; i < vars.length; i++) {
|
||||||
|
var pair = vars[i].split("=");
|
||||||
|
if (pair[0] == variable) { return decodeURIComponent(pair[1]); }
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
return admin;
|
return admin;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user