Authored by 王钱钧

添加【搜索词管理】功能代码

... ... @@ -58,6 +58,9 @@ var util={
result = result.replace(reg, args[1][key]);
}
}
//clear {xxx}
var reg = new RegExp("({.*})", "g");
result = result.replace(reg, '');
} else {
for (var i = 1; i < args.length; i++) {
if (args[i] != undefined) {
... ...
/**
* Created by wangqianjun on 16/2/23.
*/
var $ = require('jquery'),
common = require('../common/common');
require('../util/datepicker');
// 热搜词状态xxz
var StatusEnum = {
ON: 2,// 开启
OFF: 1 // 关闭
};
var PagEnum = {
DEF_HOT_SEARCH_WORDS: 1, //默认热搜词管理页面
PULL_DOWN_WORDS: 2,//下拉词管理页面
HOT_SEARCH_WORDS: 3,//热搜词管理页面
SYNONYMS_: 4,//同义词管理页面
DISABLE_WORDS: 5//停用词管理页面
};
// 下拉框
new common.dropDown({el: "#status-filter"});
new common.dropDown({el: "#channel-ops"});
// 初始化日期插件
new common.edit("#filter").init();
var type = GetQueryString("type");
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
var g = new common.grid({
el: '#search-words-list',
parms:function(){
switch (parseInt(type)) {
//默认热搜词管理页面
case PagEnum.DEF_HOT_SEARCH_WORDS :
return {
type:type,
channelIds: $.trim($('#channel-ops').val()),
status: $.trim(common.util.__input("status-filter")),
startTime: $.trim($('#starttime-filter').val()),
endTime: $.trim($('#endtime-filter').val()),
content: $.trim($('#content-filter').val())
};
//下拉词管理页面
case PagEnum.PULL_DOWN_WORDS :
//热搜词管理页面
case PagEnum.HOT_SEARCH_WORDS :
//同义词管理页面
case PagEnum.SYNONYMS_ :
//停用词管理页面
case PagEnum.DISABLE_WORDS :
return {
type:type,
channelIds: $.trim($('#channel-ops').val()),
status: $.trim(common.util.__input("status-filter")),
content: $.trim($('#content-filter').val())
};
}
},
columns:
(function () {
console.log('type = ' + type);
switch (parseInt(type)) {
//默认热搜词管理页面
case PagEnum.DEF_HOT_SEARCH_WORDS :
return [
{display: "序号", name: "id"},
{display: "内容", name: "content"},
{display: "状态", name: "status", render: function (item) {
if (item.status === StatusEnum.ON) {
return "<span>开启</span>";
} else {
return "<span>关闭</span>";
}
}},
{display: "开始时间", name: "startTime"},
{display: "结束时间", name: "endTime"},
{display: "添加人", name: "creatorUsrname"},
{display: "添加时间", name: "createdTime"},
{display: "修改人", name: "modifyUsrname"},
{display: "修改时间", name: "modifyTime"},
{
display: "修改", name: "", render: function (item) {
return '<a class="btn btn-info modify" data-index="' + item.__index + '">修改</a>';
}
}
];
//下拉词管理页面
case PagEnum.PULL_DOWN_WORDS :
return [
{display: "序号", name: "id"},
{display: "内容", name: "content"},
{display: "状态", name: "status", render: function (item) {
if (item.status === StatusEnum.ON) {
return "<span>开启</span>";
} else {
return "<span>关闭</span>";
}
}},
{display: "排序", name: "sort"},
{display: "商品数", name: "goodsNum"},
{display: "添加人", name: "creatorUsrname"},
{display: "添加时间", name: "createdTime"},
{display: "修改人", name: "modifyUsrname"},
{display: "修改时间", name: "modifyTime"},
{
display: "修改", name: "", render: function (item) {
return '<a class="btn btn-info modify" data-index="' + item.__index + '">修改</a>';
}
}
];
//热搜词管理页面
case PagEnum.HOT_SEARCH_WORDS :
return [
{display: "序号", name: "id"},
{display: "内容", name: "content"},
{display: "状态", name: "status", render: function (item) {
if (item.status === StatusEnum.ON) {
return "<span>开启</span>";
} else {
return "<span>关闭</span>";
}
}},
{display: "排序", name: "sort"},
{display: "添加人", name: "creatorUsrname"},
{display: "添加时间", name: "createdTime"},
{display: "修改人", name: "modifyUsrname"},
{display: "修改时间", name: "modifyTime"},
{
display: "修改", name: "", render: function (item) {
return '<a class="btn btn-info modify" data-index="' + item.__index + '">修改</a>';
}
}
];
//同义词管理页面
case PagEnum.SYNONYMS_ :
return [
{display: "序号", name: "id"},
{display: "内容", name: "content"},
{display: "状态", name: "status", render: function (item) {
if (item.status === StatusEnum.ON) {
return "<span>开启</span>";
} else {
return "<span>关闭</span>";
}
}},
{display: "添加人", name: "creatorUsrname"},
{display: "添加时间", name: "createdTime"},
{display: "修改人", name: "modifyUsrname"},
{display: "修改时间", name: "modifyTime"},
{
display: "修改", name: "", render: function (item) {
return '<a class="btn btn-info modify" data-index="' + item.__index + '">修改</a>';
}
}
];
//停用词管理页面
case PagEnum.DISABLE_WORDS :
return [
{display: "序号", name: "id"},
{display: "内容", name: "content"},
{display: "状态", name: "status", render: function (item) {
if (item.status === StatusEnum.ON) {
return "<span>开启</span>";
} else {
return "<span>关闭</span>";
}
}},
{display: "添加人", name: "creatorUsrname"},
{display: "添加时间", name: "createdTime"},
{display: "修改人", name: "modifyUsrname"},
{display: "修改时间", name: "modifyTime"},
{
display: "修改", name: "", render: function (item) {
return '<a class="btn btn-info modify" data-index="' + item.__index + '">修改</a>';
}
}
];
}
})()
});
g.init($('#route').val());
$("#filter-btn").click(function(){
g.reload(1);
});
$("#filter-add").click(function() {
//初始化弹框的底部红色说明
searchWordOp("添加", '/operations/terms/add', {});
});
$(document).on("click",".modify",function () {
var item = g.rows[$(this).data('index')];
searchWordOp("修改", '/operations/terms/modify', item);
});
function searchWordOp (prefix, url, item) {
var templates = {
1: {
templAdd:['template-channel', 'template-content', 'template-url', 'template-sarttime', 'template-endtime','template-tips'],
title: '默认热搜词',
templModify:['template-channel', 'template-content', 'template-url', 'template-sarttime', 'template-endtime','template-modify','template-tips'],
tips: '注:默认热搜索词是默认显示在前台搜索框里的词或者短语'
},
2: {
templAdd:['template-content', 'template-goodsnum', 'template-sort', 'template-tips'],
templModify:['template-content', 'template-goodsnum', 'template-sort', 'template-modify','template-tips'],
title: '下拉词',
tips: '注:下拉词是前台输入框获取焦点之后下拉显示的词'
},
3: {
templAdd:['template-channel', 'template-content', 'template-url', 'template-sort','template-tips'],
templModify:['template-channel', 'template-content', 'template-url', 'template-sort', 'template-modify','template-tips'],
title: '热搜词',
tips: '注:热搜词是前台搜索框下面的词'
},
4: {
templAdd:['template-content', 'template-tips'],
templModify:['template-content', 'template-modify', 'template-tips'],
title: '同义词',
tips: '注:同义词,比如阿迪达斯和三叶草就是一对同义词'
},
5: {
templAdd:['template-content', 'template-tips'],
templModify:['template-content', 'template-modify', 'template-tips'],
title: '停用词',
tips: '注:停用词是指搜索引擎不进行拆分检索的词'
},
};
var t=[];
var templ = templates[parseInt(type)];
var tmp = (prefix=="添加")? templ.templAdd:templ.templModify;
console.log(tmp);
for(var templID in tmp) {
t.push($('#'+tmp[templID]).html());
}
var a =new common.edit(".confirm");
item.tips = templ.tips;
item.type = type;
common.dialog.confirm(prefix+templ.title, common.util.__template( t.join(""), item), function () {
//
a.submit(url,function(option){
option.success=function(res){
res=res.data;
if(res.code=="200"){
a.$tip("提交成功", function() {
g.reload();
}, 'growl-success');
}else{
a.$tip(res.message);
}
return false;
},
option.error=function(res){
a.$tip(res.message);
}
});
});
//$('#i-tips').html(templ.tips);
a.init();
}
// 根据type判断显不显示【开始时间】和【结束时间】
(function () {
var titles={
1:{name1:"默认热搜词列表",name2:"默认热搜词列表"},
2:{name1:"下拉词列表",name2:"下拉词列表"},
3:{name1:"热搜词列表",name2:"热搜词列表"},
4:{name1:"同义词列表",name2:"同义词列表"},
5:{name1:"停用词列表",name2:"停用词列表"}
}
//只有默认热搜词才显示时间选择
if (parseInt(type) == PagEnum.DEF_HOT_SEARCH_WORDS) {
$('#starttime-filter').show();
$('#endtime-filter').show();
} else {
$('#starttime-filter').hide();
$('#endtime-filter').hide();
}
var tem=common.util.__template($("#template").html(),titles[parseInt(type)]);
$(".media-body").html(tem);
})()
... ...
/**
* Created by wangqianjun on 16/2/3.
*/
//接口主域
exports.domain = require('../config/common.js').domain;
//路由配置
exports.res = [
{
//搜索词页面渲染
route: '/operations/terms/index',
method: 'GET',
view: 'pages/searchWords/index',
src: '/searchWords/index',
isJsonRaw: true,
data: {
filter: true
}
},
//搜索词列表
{
route: '/operation/terms/searchWordsList',
method: 'POST',
url: '/searchWords/querySearchWords',
isJsonRaw: true,
params: [
{name: 'page', type: 'Number', def: '1'},
{name: 'size', type: 'Number', def: '10'},
{name: 'type', type: 'Number'},
{name: 'channelIds', type: 'String'},
{name: 'startTime', type: 'String'},
{name: 'endTime', type: 'String'},
{name: 'content', type: 'String'},
{name: 'status', type: 'Number'},
]
},
{
//添加搜索词
route: '/operations/terms/add',
method: 'POST',
url: '/searchWords/addSearchWords',
isJsonRaw: true,
params: [
{name: 'type', type: 'Number'},
{name: 'content', type: 'String'},
{name: 'channelIds', type: 'String'},
{name: 'url', type: 'String'},
{name: 'startTime', type: 'String'},
{name: 'endTime', type: 'String'},
{name: 'content', type: 'String'},
{name: 'goodsNum', type: 'Number'},
{name: 'sort', type: 'Number'}
]
},
{
//搜索词修改
route: '/operations/terms/modify',
method: 'POST',
url: '/searchWords/updateSearchWords',
isJsonRaw: true,
params: [
{name: 'id', type: 'Number'},
{name: 'type', type: 'Number'},
{name: 'content', type: 'String'},
{name: 'channelIds', type: 'String'},
{name: 'url', type: 'String'},
{name: 'startTime', type: 'String'},
{name: 'endTime', type: 'String'},
{name: 'content', type: 'String'},
{name: 'goodsNum', type: 'Number'},
{name: 'sort', type: 'Number'},
{name: 'status', type: 'Number'},
]
}
];
... ...
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
</div>
</div>
</div>
<div class="contentpanel">
<div class="panel panel-default" style="...">
<div class="panel-heading">
筛选
</div>
<div class="panel-body" id="filter">
<div class="row">
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<input type="text" value="" name="content" id="content-filter" placeholder="内容" class="form-control">
</div>
<div class="panel-col">
<select name="status" id="status-filter" tabindex="-1" title="" class="select2-offscreen brandBtn-group">
<option value="" selected="">选择状态</option>
<option value="1">关闭</option>
<option value="2">开启</option>
</select>
</div>
<div class="panel-col">
<select name="channel-ops" id="channel-ops" tabindex="-1" title="" class="select2-offscreen brandBtn-group">
<option value="" selected="">选择频道</option>
<option value="1">男生</option>
<option value="2">女生</option>
<option value="3">潮童</option>
<option value="4">创意生活</option>
</select>
</div>
<div class="panel-col2">
<input type="text" id="starttime-filter" class="form-control panel-input hasDatepicker" jsaction="time:end:endtime-filter" name="start_time" placeholder="开始时间" value="">
</div>
<div class="panel-col2">
<input type="text" id="endtime-filter" class="form-control panel-input hasDatepicker" jsaction="time:start:starttime-filter" name="end_time" placeholder="结束时间" value="">
</div>
<input id="route" type="hidden" value="/operation/terms/searchWordsList">
<!--</div>-->
<a id="filter-btn" href="javascript:;" class="btn btn-info">查询</a>
<a id="filter-add" value="" class="btn btn-info">添加</a>
</div>
</div>
</div>
<div id="search-words-list" class="search-words">
</div>
</div>
<script type="text/template" id="template">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="">搜索词管理</a></li>
<li id="header-item">{name1}</li>
</ul>
<div>
<div style="width: 30%;float: left;">
<h4 id="header-title">{name2}</h4>
</div>
</div>
</script>
<!--添加修改模板-->
<script type="text/template" id="template-content">
<div class="form-group">
<label for="content" class="col-sm-2 control-label"><i class="red">*</i> 内容</label>
<div class="col-sm-10">
<input type="text" name="" value="{content}" id="content" class="form-control" value="" required="required" pattern="" title="">
</div>
</div>
</script>
<script type="text/template" id="template-channel">
<div class="form-group">
<label for="channelIds" class="col-sm-2 control-label"><i class="red">*</i> 频道</label>
<div class="col-sm-8">
<label style="cursor: pointer;"><input type="checkbox" name="channelIds" value="1"> 男生</label>
<label style="cursor: pointer;"><input type="checkbox" name="channelIds" value="2"> 女生</label>
<label style="cursor: pointer;"><input type="checkbox" name="channelIds" value="3"> 潮童</label>
<label style="cursor: pointer;"><input type="checkbox" name="channelIds" value="4"> 创意生活</label>
</div>
<input type="hidden" id="channelIds" value="{channelIds}" for="checkbox">
</div>
</script>
<script type="text/template" id="template-url">
<div class="form-group">
<label for="url" class="col-sm-2 control-label"> 链接</label>
<div class="col-sm-10">
<input type="text" name="" value="{url}" id="url" class="form-control" value="" required="required" pattern="" title="">
</div>
</div>
</script>
<script type="text/template" id="template-sarttime">
<div class="form-group">
<label for="startTime" class="col-sm-2 control-label"><i class="red">*</i> 开始时间</label>
<div class="col-sm-10">
<input type="text" id="startTime" class="form-control panel-input hasDatepicker" jsaction="time:end:endTime" name="start_time" placeholder="开始时间" value="{startTime}">
<!--<input type="text" name="" value="{input}" id="input" class="form-control" value="" required="required" pattern="" title="">-->
</div>
</div>
</script>
<script type="text/template" id="template-endtime">
<div class="form-group">
<label for="endtime" class="col-sm-2 control-label"><i class="red">*</i> 结束时间</label>
<div class="col-sm-10">
<input type="text" id="endTime" class="form-control panel-input hasDatepicker" jsaction="time:start:startTime" name="start_time" placeholder="结束时间" value="{endTime}">
</div>
</div>
</script>
<script type="text/template" id="template-goodsnum">
<div class="form-group">
<label for="goodsNum" class="col-sm-2 control-label"><i class="red">*</i> 商品数</label>
<div class="col-sm-10">
<input type="text" name="" value="{goodsNum}" id="goodsNum" class="form-control" value="" required="required" pattern="" title="">
</div>
</div>
</script>
<script type="text/template" id="template-sort">
<div class="form-group">
<label for="sort" class="col-sm-2 control-label"><i class="red">*</i> 排序</label>
<div class="col-sm-10">
<input type="text" name="" value="{sort}" id="sort" class="form-control" value="" required="required" pattern="" title="">
</div>
</div>
</script>
<!--修改页面共用部分-->
<script type="text/template" id="template-modify">
<div class="form-group">
<label class="col-sm-2 control-label"><span class="red">*</span> 状态</label>
<div class="col-sm-8">
<label class="radio-inline">
<input type="radio" name="status" value="2">启用
</label>
<label class="radio-inline">
<input type="radio" name="status" value="1">禁用 </label>
</label>
</div>
<input type="hidden" id="status" value="{status}" for="radio" required="">
</div>
<div class="form-group">
<label for="creatorUsrname" class="col-sm-2 control-label">添加人</label>
<div class="col-sm-10">
<label id="creatorUsrname">{creatorUsrname}</label>
</div>
</div>
<div class="form-group">
<label for="createdTime" class="col-sm-2 control-label">添加时间</label>
<div class="col-sm-10">
<label id="createdTime">{createdTime}</label>
</div>
</div>
<div class="form-group">
<label for="modifyUser" class="col-sm-2 control-label">修改人</label>
<div class="col-sm-10">
<label id="modifyUser">{modifyUser}</label>
</div>
</div>
<div class="form-group">
<label for="modifyTime" class="col-sm-2 control-label">修改时间</label>
<div class="col-sm-10">
<label id="modifyTime">{modifyTime}</label>
</div>
</div>
<input type="hidden" id="id" value="{id}"/>
</script>
<!--红颜色说明-->
<script type="text/template" id="template-tips">
<div class="form-group">
<input type="hidden" id="type" value="{type}"/>
<i class="red" id="i-tips">{tips}</i>
</div>
</script>
... ...
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="">搜索词管理</a></li>
<li>默认热搜词列表</li>
</ul>
<div>
<div style="width: 30%;float: left;">
<h4>默认热搜词列表</h4>
</div>
</div>
</div>
</div>
</div>
<div class="contentpanel">
<div class="panel panel-default" style="margin-bottom:10px;">
<div class="panel-heading">
筛选
</div>
<div class="panel-body">
<div class="row">
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<input type="text" value="" name="content" placeholder="内容" class="form-control">
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<select class="select2-container" style="padding: 10px;" name="status">
<option value="">状态</option>
<option value="2">开启</option>
<option value="1">禁用</option>
</select>
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<button type="submit" class="btn btn-info">查询</button>
</div>
</div>
</div>
</div>
</div>