Authored by LiQZ

匹配词功能提交

  1 +/**
  2 + * Created by LiQZ
  3 + * 活动模板管理
  4 + */
  5 +module.exports=function(app) {
  6 +
  7 + /* 首页 */
  8 + app.get("/search/matchWords/index","search.matchWords.Index", "resourceManage_getUrlAction", function (response) {
  9 + this.$extend = {
  10 + actions:response.data,
  11 + moduleName: "搜索词管理",
  12 + pageName: "匹配词管理"
  13 + }
  14 + });
  15 +
  16 + app.post("/search/matchWords/list", "matchWords_matchWordsList");
  17 +
  18 + app.post("/search/matchWords/triggerStatus", "matchWords_matchWordsTriggerStatus");
  19 +
  20 + app.post("/search/matchWords/save", "matchWords_matchWordsSaveOrUpdate");
  21 +
  22 +}
  1 +/**
  2 + * Created by LiQZ
  3 + * 匹配词管理管理
  4 + */
  5 +module.exports={
  6 + namespace:"matchWords",
  7 + apis:{
  8 + matchWordsList: {
  9 + title: "查询匹配词列表接口",
  10 + url: "/match_words_list",
  11 + params: [
  12 + {name: "matchWordName", type: "string"},
  13 + {name: "status", type: "number"},
  14 + {name: "timeStatus", type: "number"},
  15 + {name: "startTime", type: "number"},
  16 + {name: "endTime", type: "number"},
  17 + {name: 'page', type: 'Number'},
  18 + {name: 'size', type: 'Number'}
  19 + ]
  20 + },
  21 + matchWordsSaveOrUpdate:{
  22 + title: "添加更新/匹配词接口",
  23 + url: "/match_words_save_update",
  24 + params: [
  25 + {name: "id", type: "number"},
  26 + {name: "matchWordName", type: "string"},
  27 + {name: "matchPcUrl", type: "string"},
  28 + {name: "matchAppAction", type: "string"},
  29 + {name: "matchAppUrl", type: "string"},
  30 + {name: "status", type: "number"},
  31 + {name: "startTime", type: "number"},
  32 + {name: "endTime", type: "number"}
  33 + ]
  34 + },
  35 + matchWordsDelete:{
  36 + title: "删除匹配词接口",
  37 + url: "/match_words_delete",
  38 + params: [
  39 + {name: "id", type: "number"}
  40 + ]
  41 + },
  42 + matchWordsTriggerStatus: {
  43 + title: "状态切换接口",
  44 + url:"/match_words_trigger_status",
  45 + params: [
  46 + {name: "id", type: "number"},
  47 + {name: "status", type: "number"}
  48 + ]
  49 + }
  50 + }
  51 +}
  1 +<%include '../../../common/views/__ui/header'%>
  2 +<%include '../../../common/views/__partail/ListHeader'%>
  3 +
  4 +<div class="contentpanel">
  5 + <div class="panel panel-default" style="margin-bottom:10px;">
  6 + <div class="panel-body" style="padding-bottom: 0">
  7 + <a href="javascript:void(0);" id="btn_add" class="btn btn-success "><i class="fa fa-plus"></i> 添加匹配词</a>
  8 + </div>
  9 + <div class="panel-body">
  10 + <div class="row">
  11 + <div class="panel-col">
  12 + <input id="matchWordName" class="form-control panel-input" type="text" placeholder="匹配词">
  13 + </div>
  14 + <div class="panel-col">
  15 + <select name="status" id="status" tabindex="-1" title="" class="select2-offscreen brandBtn-group">
  16 + <option value="" selected="">选择开启状态</option>
  17 + <option value="1">关闭</option>
  18 + <option value="0">开启</option>
  19 + </select>
  20 + </div>
  21 + <div class="panel-col">
  22 + <select name="time_status" id="time_status" tabindex="-1" title="" class="select2-offscreen brandBtn-group">
  23 + <option value="" selected="">选择时间状态</option>
  24 + <option value="1">未开始</option>
  25 + <option value="2">进行中</option>
  26 + <option value="3">已结束</option>
  27 + </select>
  28 + </div>
  29 + <div class="panel-col">
  30 + <input id="start_time" class="form-control panel-input hasDatepicker" readonly="readonly" type="text" placeholder="开始时间">
  31 + </div>
  32 + <div class="panel-col">
  33 + <input id="end_time" class="form-control panel-input hasDatepicker" readonly="readonly" type="text" placeholder="结束时间">
  34 + </div>
  35 + <div class="panel-col2">
  36 + <a id="filter-btn" href="javascript:;" class="btn btn-info">筛选</a>
  37 + <a id="all-btn" href="" class="btn btn-info">全部</a>
  38 + </div>
  39 + </div>
  40 + </div>
  41 + </div>
  42 +
  43 + <div class="row">
  44 + <div class="col-md-12">
  45 + <div class="dataTab_wrapper" id="basicTab" style="margin-bottom: 10px"></div>
  46 + <div id="table-box" class="table-responsive"></div>
  47 + </div>
  48 + </div>
  49 +</div>
  50 +
  51 +<!--添加修改模板-->
  52 +<script type="text/template" id="template">
  53 + <div class="rows" id="baseform">
  54 + <div class="form-group">
  55 + <label class="col-sm-2 control-label" for="matchWordName">匹配词</label>
  56 + <input type="hidden" value="{{id}}" id="id"/>
  57 + <input type="hidden" value="{{status }}" id="status"/>
  58 + <div class="col-sm-10">
  59 + <input type="text" value="{{matchWordName}}" class="form-control" id="matchWordName" required="required" placeholder="多个匹配词之间以 , 隔开" />
  60 + </div>
  61 + </div>
  62 + <div class="form-group">
  63 + <label class="col-sm-2 control-label" for="matchPcUrl">PC 链接</label>
  64 + <div class="col-sm-10">
  65 + <input type="text" value="{{matchPcUrl}}" class="form-control" id="matchPcUrl" required="required"/>
  66 + </div>
  67 + </div>
  68 + <div class="form-group">
  69 + <label class="col-sm-2 control-label">移动端链接</label>
  70 + <div class="col-sm-3">
  71 + <select id="matchAppAction" name="matchAppAction" class="form-control" required="required">
  72 + <option value="">选择跳转目的</option>
  73 + <%each actions as item index%>
  74 + <option value="<%item.enName%>" {{if matchAppAction == "<%item.enName%>"}}selected{{/if}}><%item.chName%></option>
  75 + <%/each%>
  76 + </select>
  77 + </div>
  78 + <div class="col-sm-7">
  79 + <input id="matchAppUrl" value="{{matchAppUrl}}" class="form-control" placeholder="URL地址" required="required"/>
  80 + <p style="color:#999;margin-top: 5px;">注:链接中不能有英文单引号</p>
  81 + </div>
  82 + </div>
  83 + <div class="form-group col-sm-100">
  84 + <label class="col-sm-2 control-label">发布时间</label>
  85 + <div class="panel-col1 col-sm-4">
  86 + <input type="text" id="startTime" jsaction="time:end:endTime" readonly
  87 + class="form-control panel-input hasDatepicker " name="startTime" placeholder="开始时间" required="required" value="{{startTime | dateFormat: 'yyyy-MM-dd hh:mm:ss'}}">
  88 + </div>
  89 + <div class="panel-col1 col-sm-4">
  90 + <input type="text" id="endTime" jsaction="time:start:startTime" readonly
  91 + class="form-control panel-input hasDatepicker" name="endTime" placeholder="结束时间" required="required" value="{{endTime | dateFormat: 'yyyy-MM-dd hh:mm:ss'}}">
  92 + </div>
  93 + </div>
  94 + </div>
  95 +</script>
  1 +var artTemplate = require('./util/template');
  2 +
  3 +artTemplate.helper('dateFormat', function (date, format) {
  4 +
  5 + if (!date) {
  6 + return '';
  7 + }
  8 +
  9 + // 秒
  10 + if (typeof date == "number" && date < 10000000000) {
  11 + date = date * 1000;
  12 + }
  13 +
  14 + date = new Date(date);
  15 +
  16 + var map = {
  17 + "M": date.getMonth() + 1, //月份
  18 + "d": date.getDate(), //日
  19 + "h": date.getHours(), //小时
  20 + "m": date.getMinutes(), //分
  21 + "s": date.getSeconds(), //秒
  22 + "q": Math.floor((date.getMonth() + 3) / 3), //季度
  23 + "S": date.getMilliseconds() //毫秒
  24 + };
  25 + format = format.replace(/([yMdhmsqS])+/g, function(all, t){
  26 + var v = map[t];
  27 + if(v !== undefined){
  28 + if(all.length > 1){
  29 + v = '0' + v;
  30 + v = v.substr(v.length-2);
  31 + }
  32 + return v;
  33 + }
  34 + else if(t === 'y'){
  35 + return (date.getFullYear() + '').substr(4 - all.length);
  36 + }
  37 + return all;
  38 + });
  39 + return format;
  40 +});
  41 +
  42 +
  43 +module.exports = artTemplate;
@@ -16,6 +16,7 @@ drag2=require('./drag2'), @@ -16,6 +16,7 @@ drag2=require('./drag2'),
16 config=require('./config'), 16 config=require('./config'),
17 popImg=require('./popImg'), 17 popImg=require('./popImg'),
18 sizeInfo = require('./sizeInfo'); 18 sizeInfo = require('./sizeInfo');
  19 +artTemplate = require('./artTemplate');
19 20
20 require('./index'); 21 require('./index');
21 22
@@ -36,7 +37,8 @@ var common={ @@ -36,7 +37,8 @@ var common={
36 popImg:popImg, 37 popImg:popImg,
37 components:components, 38 components:components,
38 config:config, 39 config:config,
39 - sizeInfo:sizeInfo 40 + sizeInfo:sizeInfo,
  41 + artTemplate:artTemplate
40 }; 42 };
41 43
42 module.exports=common; 44 module.exports=common;
@@ -302,6 +302,13 @@ var util = { @@ -302,6 +302,13 @@ var util = {
302 302
303 }, 303 },
304 304
  305 + __secondsFormat: function(seconds) {
  306 + if (seconds) {
  307 + return util.__dateFormat(new Date(seconds * 1000), "yyyy-MM-dd hh:mm:ss");
  308 + }
  309 + return '';
  310 + },
  311 +
305 /** 312 /**
306 * 比较两个时间戳 313 * 比较两个时间戳
307 * 314 *
  1 +/*!art-template - Template Engine | http://aui.github.com/artTemplate/*/
  2 +!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}();
  1 +/*
  2 + *@time: 2016-11-09 11:09:56
  3 + *@author: LiQZ
  4 + * App.template
  5 + */
  6 +var $ = require('jquery'), common = require('../../../common/common');
  7 +
  8 +var artTemplate = common.artTemplate;
  9 +
  10 +// 下拉框
  11 +new common.dropDown({
  12 + el: "#status"
  13 +});
  14 +new common.dropDown({
  15 + el: "#time_status"
  16 +});
  17 +
  18 +$('.hasDatepicker').fdatepicker({
  19 + format: 'yyyy-mm-dd hh:ii:ss',
  20 + pickTime: true
  21 +});
  22 +
  23 +var tableGird = new common.grid({
  24 +
  25 + el: "#table-box",
  26 + parms: function() {
  27 + return {
  28 + matchWordName: $("#matchWordName").val(),
  29 + status: $("#status").val(),
  30 + timeStatus: $("#time_status").val(),
  31 + startTime: timeToSeconds($("#start_time").val()),
  32 + endTime: timeToSeconds($("#end_time").val()),
  33 + }
  34 + },
  35 + columns: [
  36 + { display: "ID", name: "id" },
  37 + { display: "匹配词", name: "matchWordName"},
  38 + { display: "PC链接", name: "matchPcUrl"},
  39 + { display: "移动端链接", name:"matchAppUrl"},
  40 + { display: "开启状态", name:"status", render: function(item) {
  41 + if (item.status == 0) {return "开启"; } else { return "关闭"; }
  42 + }},
  43 + { display: "时间状态", name:"status", render: function(item) {
  44 + var now = Date.parse(new Date())/1000;
  45 + // 未开始
  46 + if (item.startTime > now) {
  47 + return "未开始";
  48 + }
  49 + // 进行中
  50 + if (item.startTime <= now && item.endTime >= now) {
  51 + return "进行中";
  52 + }
  53 + // 已结束
  54 + if (item.endTime < now) {
  55 + return "已结束";
  56 + }
  57 + return "时间设置错误";
  58 + }},
  59 + { display: "开始时间", name:"startTime", render: function(item) {
  60 + return common.util.__secondsFormat(item.startTime);
  61 + }},
  62 + { display: "结束时间", name:"endTime", render: function(item) {
  63 + return common.util.__secondsFormat(item.endTime);
  64 + }},
  65 + { display: "操作", render: function(items) {
  66 + var HtmArr = [];
  67 + HtmArr.push('<a href="javascript:void(0);" data-index="' + items.__index + '" class="btn btn-primary btn-xs btn_edit">编辑</a>');
  68 + if (items.status == 0) {
  69 + HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-danger btn-xs close-btn">关闭</a>');
  70 + } else {
  71 + HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-success btn-xs open-btn">开启</a>');
  72 + }
  73 + return HtmArr.join('');
  74 + }
  75 + }]
  76 +});
  77 +
  78 +tableGird.init('/search/matchWords/list');
  79 +
  80 +$(document).on("click", "#filter-btn", function () {
  81 + tableGird.reload();
  82 +});
  83 +
  84 +//开启
  85 +$('#table-box').on('click', '.open-btn', function() {
  86 + var param = {
  87 + id: $(this).data('id'),
  88 + status: '0'
  89 + }
  90 + common.util.__ajax({
  91 + url: '/search/matchWords/triggerStatus',
  92 + data: param
  93 +
  94 + }, function(res) {
  95 + tableGird.reload();
  96 + });
  97 +});
  98 +
  99 +//关闭
  100 +$('#table-box').on('click', '.close-btn', function() {
  101 + var param = {
  102 + id: $(this).data('id'),
  103 + status: '1'
  104 + }
  105 + common.util.__ajax({
  106 + url: '/search/matchWords/triggerStatus',
  107 + data: param
  108 +
  109 + }, function(res) {
  110 + tableGird.reload();
  111 + });
  112 +});
  113 +
  114 +function timeToSeconds(time) {
  115 + if (time) {
  116 + time = time.replace(/-/g,'/'); // 通用性好一点
  117 + return new Date(time).getTime() / 1000;
  118 + }
  119 +}
  120 +
  121 +/**************************************
  122 + * 添加编辑
  123 + **************************************/
  124 +
  125 + var Bll = {
  126 +
  127 + toast:function(url, item, hint) {
  128 +
  129 + var e = new common.edit("#baseform");
  130 +
  131 + console.log(e);
  132 +
  133 + var dialog = common.dialog.confirm(hint, artTemplate("template", item), function() {
  134 +
  135 + e.submit(url, function (option) {
  136 +
  137 + option.data.startTime = new Date(option.data.startTime).getTime() / 1000;
  138 + option.data.endTime = new Date(option.data.endTime).getTime() / 1000;
  139 +
  140 + option.success=function() {
  141 + dialog.close();
  142 + tableGird.reload();
  143 + };
  144 + option.error=function(){};
  145 + });
  146 +
  147 + return false;
  148 + });
  149 +
  150 + e.init();
  151 +
  152 +
  153 + }
  154 + };
  155 +
  156 + $('#btn_add').on('click', function() {
  157 + var item = { "status": 0 }; // 默认开启
  158 + Bll.toast('/search/matchWords/save', item, "创建匹配词");
  159 + });
  160 +
  161 + $(document).on('click', '.btn_edit', function() {
  162 + var item = tableGird.rows[$(this).data("index")];
  163 + Bll.toast('/search/matchWords/save', item, "编辑匹配词");
  164 + });
  165 +