站点页优化

This commit is contained in:
Mr Chen 2024-01-21 01:27:09 +08:00
parent 45b0e94132
commit 5c301296df
5 changed files with 54 additions and 22 deletions

View File

@ -394,6 +394,9 @@ def getPageObject(args, result='1,2,3,4,5,8'):
if 'tojs' in args:
info['return_js'] = args['tojs']
if 'args_tpl' in args:
info['args_tpl'] = args['args_tpl']
return (page.GetPage(info, result), page)

View File

@ -39,6 +39,7 @@ class Page():
__RTURN_JS = False # 是否返回JS回调
__START_NUM = None # 起始行
__END_NUM = None # 结束行
__ARGS_TPL = ''
def __init__(self):
if False:
@ -51,12 +52,19 @@ class Page():
self.__FO = tmp['FO']
self.__LINE = tmp['LINE']
def getPageNum(self, num):
return str(num) + self.__ARGS_TPL
def GetPage(self, pageInfo, limit='1,2,3,4,5,6,7,8'):
# 取分页信息
# @param pageInfo 传入分页参数字典
# @param limit 返回系列
self.__RTURN_JS = pageInfo['return_js']
self.__COUNT_ROW = pageInfo['count']
if 'args_tpl' in pageInfo:
self.__ARGS_TPL = pageInfo['args_tpl']
self.ROW = pageInfo['row']
self.__C_PAGE = self.__GetCpage(pageInfo['p'])
self.__START_NUM = self.__StartRow()
@ -111,7 +119,7 @@ class Page():
str(self.__COUNT_PAGE) + "'>" + str(self.__END) + "</a>"
else:
endStr = "<a class='Pend' onclick='" + self.__RTURN_JS + \
"(" + str(self.__COUNT_PAGE) + ")'>" + \
"(" + self.getPageNum(self.__COUNT_PAGE) + ")'>" + \
str(self.__END) + "</a>"
return endStr
@ -126,7 +134,7 @@ class Page():
str(self.__C_PAGE + 1) + "'>" + str(self.__NEXT) + "</a>"
else:
nextStr = "<a class='Pnext' onclick='" + self.__RTURN_JS + \
"(" + str(self.__C_PAGE + 1) + ")'>" + \
"(" + self.getPageNum(self.__C_PAGE + 1) + ")'>" + \
str(self.__NEXT) + "</a>"
return nextStr
@ -151,7 +159,7 @@ class Page():
"p=" + str(page) + "'>" + str(page) + "</a>"
else:
pages += "<a class='Pnum' onclick='" + self.__RTURN_JS + \
"(" + str(page) + ")'>" + str(page) + "</a>"
"(" + self.getPageNum(page) + ")'>" + str(page) + "</a>"
# 当前页
if self.__C_PAGE > 0:
@ -174,7 +182,7 @@ class Page():
"p=" + str(page) + "'>" + str(page) + "</a>"
else:
pages += "<a class='Pnum' onclick='" + self.__RTURN_JS + \
"(" + str(page) + ")'>" + str(page) + "</a>"
"(" + self.getPageNum(page) + ")'>" + str(page) + "</a>"
return pages
@ -189,7 +197,7 @@ class Page():
str(self.__C_PAGE - 1) + "'>" + str(self.__PREV) + "</a>"
else:
startStr = "<a class='Ppren' onclick='" + self.__RTURN_JS + \
"(" + str(self.__C_PAGE - 1) + ")'>" + \
"(" + self.getPageNum(self.__C_PAGE - 1) + ")'>" + \
str(self.__PREV) + "</a>"
return startStr
@ -204,7 +212,7 @@ class Page():
self.__URI + "p=1'>" + str(self.__START) + "</a>"
else:
startStr = "<a class='Pstart' onclick='" + \
self.__RTURN_JS + "(1)'>" + str(self.__START) + "</a>"
self.__RTURN_JS + "("+self.getPageNum(1)+")'>" + str(self.__START) + "</a>"
return startStr
def __GetCpage(self, p):

View File

@ -105,7 +105,7 @@ class site_api:
start = (int(p) - 1) * (int(limit))
siteM = mw.M('sites').field('id,name,path,status,ps,addtime,edate')
siteM = siteC = mw.M('sites').field('id,name,path,status,ps,addtime,edate,type_id')
sql_where = ''
if search != '':
@ -113,30 +113,37 @@ class site_api:
if type_id != '' and int(type_id) >= 0 and search != '':
sql_where = sql_where + " and type_id=" + type_id + ""
elif type_id != '' and int(type_id) >= 0:
if type_id != '' and int(type_id) >= 0:
sql_where = " type_id=" + type_id
if sql_where != '':
siteM.where(sql_where)
_list = siteM.limit((str(start)) + ',' +
limit).order('id desc').select()
_list = siteM.limit((str(start)) + ',' +limit).order('id desc').select()
if _list != None:
for i in range(len(_list)):
_list[i]['backup_count'] = mw.M('backup').where(
"pid=? AND type=?", (_list[i]['id'], 0)).count()
_list[i]['backup_count'] = mw.M('backup').where("pid=? AND type=?", (_list[i]['id'], 0)).count()
_ret = {}
_ret['data'] = _list
count = siteM.count()
if sql_where != '':
count = siteC.where(sql_where).count()
else:
count = siteC.count()
_page = {}
_page['count'] = count
_page['tojs'] = 'getWeb'
_page['p'] = p
_page['row'] = limit
page_args_tpl = ''
page_args_tpl += ','+type_id+''
if search != '':
page_args_tpl += ',"'+search+'"'
_page['args_tpl'] = page_args_tpl
_ret['page'] = mw.getPage(_page)
return mw.getJson(_ret)

View File

@ -1,10 +1,25 @@
$("#site_search_input").keyup(function(event){
if(event.keyCode == 13) {
getWeb(1, -1, $(this).val());
}
});
$('#site_search').click(function(){
getWeb(1, -1, $('#site_search_input').val());
});
/**
* 取回网站数据列表
* @param {Number} page 当前页
* @param {String} search 搜索条件
*/
function getWeb(page, search, type_id) {
var search = $("#SearchValue").prop("value");
function getWeb(page, type_id, search) {
if ( typeof(search) == 'undefined' ){
search = $('#site_search_input').val();
}
var page = page == undefined ? '1':page;
var order = getCookie('order');
if(order){
@ -117,6 +132,7 @@
},function(){
$(this).removeClass("open");
});
//输出分页
$("#webPage").html(data.page);
// $("#webPage").html('<div class="site_type"><span>站点分类:</span><select class="bt-input-text mr5" style="width:100px"><option value="-1">全部分类</option><option value="0">默认分类</option></select></div>');
@ -2704,8 +2720,7 @@ function getClassType(){
$(select).bind('change',function(){
var select_id = $(this).val();
// console.log(select_id);
getWeb(1,'',select_id);
getWeb(1,select_id, '');
})
},'json');
}

View File

@ -8,11 +8,10 @@
<a class="plr10 c4" href="/">首页</a>/<span class="plr10 c4">网站</span>
</div>
<div class="search pull-right">
<form target="hid" onsubmit='getWeb(1,$("#SearchValue").prop("value"))'>
<input type="text" id="SearchValue" class="ser-text pull-left" placeholder="网站搜索"/>
<button type="button" class="ser-sub pull-left" onclick='getWeb(1,$("#SearchValue").prop("value"))'></button>
<form onsubmit="return false;">
<input type="text" id="site_search_input" class="ser-text pull-left" autocomplete="off" placeholder="网站搜索"/>
<button type="button" class="ser-sub pull-left" id="site_search"></button>
</form>
<iframe name='hid' id="hid" style="display:none"></iframe>
</div>
</div>
<div class="safe bgw mtb15 pd15">