Authored by LiQZ

匹配词功能提交

/**
* Created by LiQZ
* 活动模板管理
*/
module.exports=function(app) {
/* 首页 */
app.get("/search/matchWords/index","search.matchWords.Index", "resourceManage_getUrlAction", function (response) {
this.$extend = {
actions:response.data,
moduleName: "搜索词管理",
pageName: "匹配词管理"
}
});
app.post("/search/matchWords/list", "matchWords_matchWordsList");
app.post("/search/matchWords/triggerStatus", "matchWords_matchWordsTriggerStatus");
app.post("/search/matchWords/save", "matchWords_matchWordsSaveOrUpdate");
}
... ...
/**
* Created by LiQZ
* 匹配词管理管理
*/
module.exports={
namespace:"matchWords",
apis:{
matchWordsList: {
title: "查询匹配词列表接口",
url: "/match_words_list",
params: [
{name: "matchWordName", type: "string"},
{name: "status", type: "number"},
{name: "timeStatus", type: "number"},
{name: "startTime", type: "number"},
{name: "endTime", type: "number"},
{name: 'page', type: 'Number'},
{name: 'size', type: 'Number'}
]
},
matchWordsSaveOrUpdate:{
title: "添加更新/匹配词接口",
url: "/match_words_save_update",
params: [
{name: "id", type: "number"},
{name: "matchWordName", type: "string"},
{name: "matchPcUrl", type: "string"},
{name: "matchAppAction", type: "string"},
{name: "matchAppUrl", type: "string"},
{name: "status", type: "number"},
{name: "startTime", type: "number"},
{name: "endTime", type: "number"}
]
},
matchWordsDelete:{
title: "删除匹配词接口",
url: "/match_words_delete",
params: [
{name: "id", type: "number"}
]
},
matchWordsTriggerStatus: {
title: "状态切换接口",
url:"/match_words_trigger_status",
params: [
{name: "id", type: "number"},
{name: "status", type: "number"}
]
}
}
}
... ...
<%include '../../../common/views/__ui/header'%>
<%include '../../../common/views/__partail/ListHeader'%>
<div class="contentpanel">
<div class="panel panel-default" style="margin-bottom:10px;">
<div class="panel-body" style="padding-bottom: 0">
<a href="javascript:void(0);" id="btn_add" class="btn btn-success "><i class="fa fa-plus"></i> 添加匹配词</a>
</div>
<div class="panel-body">
<div class="row">
<div class="panel-col">
<input id="matchWordName" class="form-control panel-input" type="text" placeholder="匹配词">
</div>
<div class="panel-col">
<select name="status" id="status" tabindex="-1" title="" class="select2-offscreen brandBtn-group">
<option value="" selected="">选择开启状态</option>
<option value="1">关闭</option>
<option value="0">开启</option>
</select>
</div>
<div class="panel-col">
<select name="time_status" id="time_status" tabindex="-1" title="" class="select2-offscreen brandBtn-group">
<option value="" selected="">选择时间状态</option>
<option value="1">未开始</option>
<option value="2">进行中</option>
<option value="3">已结束</option>
</select>
</div>
<div class="panel-col">
<input id="start_time" class="form-control panel-input hasDatepicker" readonly="readonly" type="text" placeholder="开始时间">
</div>
<div class="panel-col">
<input id="end_time" class="form-control panel-input hasDatepicker" readonly="readonly" type="text" placeholder="结束时间">
</div>
<div class="panel-col2">
<a id="filter-btn" href="javascript:;" class="btn btn-info">筛选</a>
<a id="all-btn" href="" class="btn btn-info">全部</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="dataTab_wrapper" id="basicTab" style="margin-bottom: 10px"></div>
<div id="table-box" class="table-responsive"></div>
</div>
</div>
</div>
<!--添加修改模板-->
<script type="text/template" id="template">
<div class="rows" id="baseform">
<div class="form-group">
<label class="col-sm-2 control-label" for="matchWordName">匹配词</label>
<input type="hidden" value="{{id}}" id="id"/>
<input type="hidden" value="{{status }}" id="status"/>
<div class="col-sm-10">
<input type="text" value="{{matchWordName}}" class="form-control" id="matchWordName" required="required" placeholder="多个匹配词之间以 , 隔开" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="matchPcUrl">PC 链接</label>
<div class="col-sm-10">
<input type="text" value="{{matchPcUrl}}" class="form-control" id="matchPcUrl" required="required"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">移动端链接</label>
<div class="col-sm-3">
<select id="matchAppAction" name="matchAppAction" class="form-control" required="required">
<option value="">选择跳转目的</option>
<%each actions as item index%>
<option value="<%item.enName%>" {{if matchAppAction == "<%item.enName%>"}}selected{{/if}}><%item.chName%></option>
<%/each%>
</select>
</div>
<div class="col-sm-7">
<input id="matchAppUrl" value="{{matchAppUrl}}" class="form-control" placeholder="URL地址" required="required"/>
<p style="color:#999;margin-top: 5px;">注:链接中不能有英文单引号</p>
</div>
</div>
<div class="form-group col-sm-100">
<label class="col-sm-2 control-label">发布时间</label>
<div class="panel-col1 col-sm-4">
<input type="text" id="startTime" jsaction="time:end:endTime" readonly
class="form-control panel-input hasDatepicker " name="startTime" placeholder="开始时间" required="required" value="{{startTime | dateFormat: 'yyyy-MM-dd hh:mm:ss'}}">
</div>
<div class="panel-col1 col-sm-4">
<input type="text" id="endTime" jsaction="time:start:startTime" readonly
class="form-control panel-input hasDatepicker" name="endTime" placeholder="结束时间" required="required" value="{{endTime | dateFormat: 'yyyy-MM-dd hh:mm:ss'}}">
</div>
</div>
</div>
</script>
\ No newline at end of file
... ...
var artTemplate = require('./util/template');
artTemplate.helper('dateFormat', function (date, format) {
if (!date) {
return '';
}
// 秒
if (typeof date == "number" && date < 10000000000) {
date = date * 1000;
}
date = new Date(date);
var map = {
"M": date.getMonth() + 1, //月份
"d": date.getDate(), //日
"h": date.getHours(), //小时
"m": date.getMinutes(), //分
"s": date.getSeconds(), //秒
"q": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
format = format.replace(/([yMdhmsqS])+/g, function(all, t){
var v = map[t];
if(v !== undefined){
if(all.length > 1){
v = '0' + v;
v = v.substr(v.length-2);
}
return v;
}
else if(t === 'y'){
return (date.getFullYear() + '').substr(4 - all.length);
}
return all;
});
return format;
});
module.exports = artTemplate;
\ No newline at end of file
... ...
... ... @@ -16,6 +16,7 @@ drag2=require('./drag2'),
config=require('./config'),
popImg=require('./popImg'),
sizeInfo = require('./sizeInfo');
artTemplate = require('./artTemplate');
require('./index');
... ... @@ -36,7 +37,8 @@ var common={
popImg:popImg,
components:components,
config:config,
sizeInfo:sizeInfo
sizeInfo:sizeInfo,
artTemplate:artTemplate
};
module.exports=common;
\ No newline at end of file
... ...
... ... @@ -302,6 +302,13 @@ var util = {
},
__secondsFormat: function(seconds) {
if (seconds) {
return util.__dateFormat(new Date(seconds * 1000), "yyyy-MM-dd hh:mm:ss");
}
return '';
},
/**
* 比较两个时间戳
*
... ...
/*!art-template - Template Engine | http://aui.github.com/artTemplate/*/
!function(){function a(a){return a.replace(t,"").replace(u,",").replace(v,"").replace(w,"").replace(x,"").split(y)}function b(a){return"'"+a.replace(/('|\\)/g,"\\$1").replace(/\r/g,"\\r").replace(/\n/g,"\\n")+"'"}function c(c,d){function e(a){return m+=a.split(/\n/).length-1,k&&(a=a.replace(/\s+/g," ").replace(/<!--[\w\W]*?-->/g,"")),a&&(a=s[1]+b(a)+s[2]+"\n"),a}function f(b){var c=m;if(j?b=j(b,d):g&&(b=b.replace(/\n/g,function(){return m++,"$line="+m+";"})),0===b.indexOf("=")){var e=l&&!/^=[=#]/.test(b);if(b=b.replace(/^=[=#]?|[\s;]*$/g,""),e){var f=b.replace(/\s*\([^\)]+\)/,"");n[f]||/^(include|print)$/.test(f)||(b="$escape("+b+")")}else b="$string("+b+")";b=s[1]+b+s[2]}return g&&(b="$line="+c+";"+b),r(a(b),function(a){if(a&&!p[a]){var b;b="print"===a?u:"include"===a?v:n[a]?"$utils."+a:o[a]?"$helpers."+a:"$data."+a,w+=a+"="+b+",",p[a]=!0}}),b+"\n"}var g=d.debug,h=d.openTag,i=d.closeTag,j=d.parser,k=d.compress,l=d.escape,m=1,p={$data:1,$filename:1,$utils:1,$helpers:1,$out:1,$line:1},q="".trim,s=q?["$out='';","$out+=",";","$out"]:["$out=[];","$out.push(",");","$out.join('')"],t=q?"$out+=text;return $out;":"$out.push(text);",u="function(){var text=''.concat.apply('',arguments);"+t+"}",v="function(filename,data){data=data||$data;var text=$utils.$include(filename,data,$filename);"+t+"}",w="'use strict';var $utils=this,$helpers=$utils.$helpers,"+(g?"$line=0,":""),x=s[0],y="return new String("+s[3]+");";r(c.split(h),function(a){a=a.split(i);var b=a[0],c=a[1];1===a.length?x+=e(b):(x+=f(b),c&&(x+=e(c)))});var z=w+x+y;g&&(z="try{"+z+"}catch(e){throw {filename:$filename,name:'Render Error',message:e.message,line:$line,source:"+b(c)+".split(/\\n/)[$line-1].replace(/^\\s+/,'')};}");try{var A=new Function("$data","$filename",z);return A.prototype=n,A}catch(B){throw B.temp="function anonymous($data,$filename) {"+z+"}",B}}var d=function(a,b){return"string"==typeof b?q(b,{filename:a}):g(a,b)};d.version="3.0.0",d.config=function(a,b){e[a]=b};var e=d.defaults={openTag:"<%",closeTag:"%>",escape:!0,cache:!0,compress:!1,parser:null},f=d.cache={};d.render=function(a,b){return q(a,b)};var g=d.renderFile=function(a,b){var c=d.get(a)||p({filename:a,name:"Render Error",message:"Template not found"});return b?c(b):c};d.get=function(a){var b;if(f[a])b=f[a];else if("object"==typeof document){var c=document.getElementById(a);if(c){var d=(c.value||c.innerHTML).replace(/^\s*|\s*$/g,"");b=q(d,{filename:a})}}return b};var h=function(a,b){return"string"!=typeof a&&(b=typeof a,"number"===b?a+="":a="function"===b?h(a.call(a)):""),a},i={"<":"&#60;",">":"&#62;",'"':"&#34;","'":"&#39;","&":"&#38;"},j=function(a){return i[a]},k=function(a){return h(a).replace(/&(?![\w#]+;)|[<>"']/g,j)},l=Array.isArray||function(a){return"[object Array]"==={}.toString.call(a)},m=function(a,b){var c,d;if(l(a))for(c=0,d=a.length;d>c;c++)b.call(a,a[c],c,a);else for(c in a)b.call(a,a[c],c)},n=d.utils={$helpers:{},$include:g,$string:h,$escape:k,$each:m};d.helper=function(a,b){o[a]=b};var o=d.helpers=n.$helpers;d.onerror=function(a){var b="Template Error\n\n";for(var c in a)b+="<"+c+">\n"+a[c]+"\n\n";"object"==typeof console&&console.error(b)};var p=function(a){return d.onerror(a),function(){return"{Template Error}"}},q=d.compile=function(a,b){function d(c){try{return new i(c,h)+""}catch(d){return b.debug?p(d)():(b.debug=!0,q(a,b)(c))}}b=b||{};for(var g in e)void 0===b[g]&&(b[g]=e[g]);var h=b.filename;try{var i=c(a,b)}catch(j){return j.filename=h||"anonymous",j.name="Syntax Error",p(j)}return d.prototype=i.prototype,d.toString=function(){return i.toString()},h&&b.cache&&(f[h]=d),d},r=n.$each,s="break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield,undefined",t=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|\s*\.\s*[$\w\.]+/g,u=/[^\w$]+/g,v=new RegExp(["\\b"+s.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),w=/^\d[^,]*|,\d[^,]*/g,x=/^,+|,+$/g,y=/^$|,+/;e.openTag="{{",e.closeTag="}}";var z=function(a,b){var c=b.split(":"),d=c.shift(),e=c.join(":")||"";return e&&(e=", "+e),"$helpers."+d+"("+a+e+")"};e.parser=function(a){a=a.replace(/^\s/,"");var b=a.split(" "),c=b.shift(),e=b.join(" ");switch(c){case"if":a="if("+e+"){";break;case"else":b="if"===b.shift()?" if("+b.join(" ")+")":"",a="}else"+b+"{";break;case"/if":a="}";break;case"each":var f=b[0]||"$data",g=b[1]||"as",h=b[2]||"$value",i=b[3]||"$index",j=h+","+i;"as"!==g&&(f="[]"),a="$each("+f+",function("+j+"){";break;case"/each":a="});";break;case"echo":a="print("+e+");";break;case"print":case"include":a=c+"("+b.join(",")+");";break;default:if(/^\s*\|\s*[\w\$]/.test(e)){var k=!0;0===a.indexOf("#")&&(a=a.substr(1),k=!1);for(var l=0,m=a.split("|"),n=m.length,o=m[l++];n>l;l++)o=z(o,m[l]);a=(k?"=":"=#")+o}else a=d.helpers[c]?"=#"+c+"("+b.join(",")+");":"="+a}return a},"function"==typeof define?define(function(){return d}):"undefined"!=typeof exports?module.exports=d:this.template=d}();
\ No newline at end of file
... ...
/*
*@time: 2016-11-09 11:09:56
*@author: LiQZ
* App.template
*/
var $ = require('jquery'), common = require('../../../common/common');
var artTemplate = common.artTemplate;
// 下拉框
new common.dropDown({
el: "#status"
});
new common.dropDown({
el: "#time_status"
});
$('.hasDatepicker').fdatepicker({
format: 'yyyy-mm-dd hh:ii:ss',
pickTime: true
});
var tableGird = new common.grid({
el: "#table-box",
parms: function() {
return {
matchWordName: $("#matchWordName").val(),
status: $("#status").val(),
timeStatus: $("#time_status").val(),
startTime: timeToSeconds($("#start_time").val()),
endTime: timeToSeconds($("#end_time").val()),
}
},
columns: [
{ display: "ID", name: "id" },
{ display: "匹配词", name: "matchWordName"},
{ display: "PC链接", name: "matchPcUrl"},
{ display: "移动端链接", name:"matchAppUrl"},
{ display: "开启状态", name:"status", render: function(item) {
if (item.status == 0) {return "开启"; } else { return "关闭"; }
}},
{ display: "时间状态", name:"status", render: function(item) {
var now = Date.parse(new Date())/1000;
// 未开始
if (item.startTime > now) {
return "未开始";
}
// 进行中
if (item.startTime <= now && item.endTime >= now) {
return "进行中";
}
// 已结束
if (item.endTime < now) {
return "已结束";
}
return "时间设置错误";
}},
{ display: "开始时间", name:"startTime", render: function(item) {
return common.util.__secondsFormat(item.startTime);
}},
{ display: "结束时间", name:"endTime", render: function(item) {
return common.util.__secondsFormat(item.endTime);
}},
{ display: "操作", render: function(items) {
var HtmArr = [];
HtmArr.push('<a href="javascript:void(0);" data-index="' + items.__index + '" class="btn btn-primary btn-xs btn_edit">编辑</a>');
if (items.status == 0) {
HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-danger btn-xs close-btn">关闭</a>');
} else {
HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-success btn-xs open-btn">开启</a>');
}
return HtmArr.join('');
}
}]
});
tableGird.init('/search/matchWords/list');
$(document).on("click", "#filter-btn", function () {
tableGird.reload();
});
//开启
$('#table-box').on('click', '.open-btn', function() {
var param = {
id: $(this).data('id'),
status: '0'
}
common.util.__ajax({
url: '/search/matchWords/triggerStatus',
data: param
}, function(res) {
tableGird.reload();
});
});
//关闭
$('#table-box').on('click', '.close-btn', function() {
var param = {
id: $(this).data('id'),
status: '1'
}
common.util.__ajax({
url: '/search/matchWords/triggerStatus',
data: param
}, function(res) {
tableGird.reload();
});
});
function timeToSeconds(time) {
if (time) {
time = time.replace(/-/g,'/'); // 通用性好一点
return new Date(time).getTime() / 1000;
}
}
/**************************************
* 添加编辑
**************************************/
var Bll = {
toast:function(url, item, hint) {
var e = new common.edit("#baseform");
console.log(e);
var dialog = common.dialog.confirm(hint, artTemplate("template", item), function() {
e.submit(url, function (option) {
option.data.startTime = new Date(option.data.startTime).getTime() / 1000;
option.data.endTime = new Date(option.data.endTime).getTime() / 1000;
option.success=function() {
dialog.close();
tableGird.reload();
};
option.error=function(){};
});
return false;
});
e.init();
}
};
$('#btn_add').on('click', function() {
var item = { "status": 0 }; // 默认开启
Bll.toast('/search/matchWords/save', item, "创建匹配词");
});
$(document).on('click', '.btn_edit', function() {
var item = tableGird.rows[$(this).data("index")];
Bll.toast('/search/matchWords/save', item, "编辑匹配词");
});
... ...