|
@@ -123,7 +123,10 @@ $(document).on('click','.delete-close>i',function () {
|
|
|
|
|
|
window[arr].splice(index,1)
|
|
window[arr].splice(index,1)
|
|
keyAllArr.splice(index,1)
|
|
keyAllArr.splice(index,1)
|
|
- dom.remove()
|
|
|
|
|
|
+ var vKey = $(dom).attr('data-key')
|
|
|
|
+ dom.remove()
|
|
|
|
+ $('#inputDel_0 div[data-key="'+vKey+'"]').remove()
|
|
|
|
+ renderColumn()
|
|
} else {
|
|
} else {
|
|
window[arr].splice(index,1)
|
|
window[arr].splice(index,1)
|
|
var i = selectProvince.indexOf(dom.text());
|
|
var i = selectProvince.indexOf(dom.text());
|
|
@@ -138,9 +141,10 @@ $(document).on('click','.delete-close>i',function () {
|
|
}
|
|
}
|
|
//20181227
|
|
//20181227
|
|
if (arr && arr.indexOf("inputDel")>-1){
|
|
if (arr && arr.indexOf("inputDel")>-1){
|
|
|
|
+ console.log(arr, 'arr', $("div[data-arr='"+arr+"']").length);
|
|
if($("div[data-arr='"+arr+"']").length==0){
|
|
if($("div[data-arr='"+arr+"']").length==0){
|
|
- $("div[id='"+arr+"']").siblings(".user-input").find("input").show();
|
|
|
|
- $("div[id='"+arr+"']").siblings(".add-input-w-").hide();
|
|
|
|
|
|
+ $("div[id='"+arr+"']").siblings(".new-box").children('.user-input').find("input").show();
|
|
|
|
+ $("div[id='"+arr+"']").siblings('.new-box').children(".add-input-w-").hide();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -245,7 +249,7 @@ function delAddBox(n) {
|
|
// })
|
|
// })
|
|
/* 生成子标签 */
|
|
/* 生成子标签 */
|
|
function createCKey(title,arr,clazz) {
|
|
function createCKey(title,arr,clazz) {
|
|
- if(arr.length === 0) {
|
|
|
|
|
|
+ if(!arr || arr.length === 0) {
|
|
return ''
|
|
return ''
|
|
}
|
|
}
|
|
var all = arr.map(function (value) {
|
|
var all = arr.map(function (value) {
|
|
@@ -254,14 +258,15 @@ function createCKey(title,arr,clazz) {
|
|
return '<div class="text-box float-box '+clazz+'"><div class="title">'+title+':</div><div class="title-other float-box">'+all+'</div></div>'
|
|
return '<div class="text-box float-box '+clazz+'"><div class="title">'+title+':</div><div class="title-other float-box">'+all+'</div></div>'
|
|
}
|
|
}
|
|
/* 添加关键词标签 */
|
|
/* 添加关键词标签 */
|
|
-function createKeyBox(t) {
|
|
|
|
- var appArr = appendArr
|
|
|
|
- var exArr = excludeArr
|
|
|
|
- var key = t
|
|
|
|
|
|
+function createKeyBox(key, append, exclude, i) {
|
|
|
|
+ var appArr = append
|
|
|
|
+ var exArr = exclude
|
|
var all = createCKey('关键词',[key],"key") + createCKey('附加词',appArr,"app") + createCKey('排除词',exArr,"ex")
|
|
var all = createCKey('关键词',[key],"key") + createCKey('附加词',appArr,"app") + createCKey('排除词',exArr,"ex")
|
|
- var template = '<div data-index="'+keyAllArr.length+'" data-arr="inputDel_0" class="delete-close">'+all+' <i class="iconfont icon-guanbi"></i> </div>'
|
|
|
|
|
|
+ // var index = type === 'edit' ? i : keyAllArr.length
|
|
|
|
+ var template = '<div data-index="'+i+'" data-key="' + key +'" data-arr="inputDel_0" class="delete-close">'+all+' <span class="icon-edit-img" data-key="' + key +'" data-exclude="' + exArr +'" data-append="'+ appArr + '"></span><i class="iconfont icon-guanbi"></i></div>'
|
|
return template
|
|
return template
|
|
}
|
|
}
|
|
|
|
+
|
|
function fixLeft(){
|
|
function fixLeft(){
|
|
var one = $("#inputDel_0 .column:eq(0)")
|
|
var one = $("#inputDel_0 .column:eq(0)")
|
|
var two = $("#inputDel_0 .column:eq(1)")
|
|
var two = $("#inputDel_0 .column:eq(1)")
|
|
@@ -308,6 +313,7 @@ function addDelInput(t,type) {
|
|
var template = null
|
|
var template = null
|
|
var arr = box
|
|
var arr = box
|
|
switch (type) {
|
|
switch (type) {
|
|
|
|
+ // 关键词类型时弃用(绑定到确定按钮事件委托)
|
|
case 0: {
|
|
case 0: {
|
|
// 计算当前输入的关键词、附加词、排除词总数
|
|
// 计算当前输入的关键词、附加词、排除词总数
|
|
var inputVal = []
|
|
var inputVal = []
|
|
@@ -339,6 +345,8 @@ function addDelInput(t,type) {
|
|
$(".add-input-w input.sm").remove()
|
|
$(".add-input-w input.sm").remove()
|
|
$(".add-input-w").css("display","none");
|
|
$(".add-input-w").css("display","none");
|
|
$("#addKeyword").css("display","block");
|
|
$("#addKeyword").css("display","block");
|
|
|
|
+ $('.new-action').hide()
|
|
|
|
+ $('.new-box').removeClass('bg-active')
|
|
setTimeout(function(){
|
|
setTimeout(function(){
|
|
fixLeft()
|
|
fixLeft()
|
|
},80)
|
|
},80)
|
|
@@ -411,7 +419,6 @@ function addOtherInput(t,f) {
|
|
inputVal.push($(this).val())
|
|
inputVal.push($(this).val())
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- console.log(inputVal, 'inputVal');
|
|
|
|
// inputVal为当前输入的排除词、附加词
|
|
// inputVal为当前输入的排除词、附加词
|
|
// 已存关键词、附加词、排除词数量和 + 1(当前输入的关键词)+ inputVal.length
|
|
// 已存关键词、附加词、排除词数量和 + 1(当前输入的关键词)+ inputVal.length
|
|
if (getTotal() + 1 + inputVal.length >= wordsLimit) {
|
|
if (getTotal() + 1 + inputVal.length >= wordsLimit) {
|
|
@@ -444,6 +451,7 @@ function addOtherInput(t,f) {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+ console.log('附加词:' + appendArr, '排除词:'+ excludeArr);
|
|
$(t).before(input)
|
|
$(t).before(input)
|
|
$(input).focus();
|
|
$(input).focus();
|
|
}
|
|
}
|
|
@@ -451,34 +459,33 @@ function addOtherInput(t,f) {
|
|
var nowSpan = null
|
|
var nowSpan = null
|
|
var dataIndex = 0;
|
|
var dataIndex = 0;
|
|
var textBoxClass = "";
|
|
var textBoxClass = "";
|
|
-$(document).on('click','#inputDel_0 .title-other>span',function (e) {
|
|
|
|
- var par = $(this).parent().parent();
|
|
|
|
- dataIndex = par.parent().attr("data-index");
|
|
|
|
- if(par.hasClass("key")){
|
|
|
|
- textBoxClass = "key";
|
|
|
|
- }else if(par.hasClass("app")){
|
|
|
|
- textBoxClass = "app";
|
|
|
|
- }else if(par.hasClass("ex")){
|
|
|
|
- textBoxClass = "ex";
|
|
|
|
- }
|
|
|
|
|
|
+// $(document).on('click','#inputDel_0 .title-other>span',function (e) {
|
|
|
|
+// var par = $(this).parent().parent();
|
|
|
|
+// dataIndex = par.parent().attr("data-index");
|
|
|
|
+// if(par.hasClass("key")){
|
|
|
|
+// textBoxClass = "key";
|
|
|
|
+// }else if(par.hasClass("app")){
|
|
|
|
+// textBoxClass = "app";
|
|
|
|
+// }else if(par.hasClass("ex")){
|
|
|
|
+// textBoxClass = "ex";
|
|
|
|
+// }
|
|
|
|
|
|
- var xy = $(this).offset()
|
|
|
|
- // console.log('--xy--', xy)
|
|
|
|
- var x = xy.top + 30
|
|
|
|
- var maxY = $(document).width() - 600
|
|
|
|
- var y = maxY < xy.left ? maxY : xy.left
|
|
|
|
- nowSpan = $(this)
|
|
|
|
- // console.log('--$(this).offset()--', xy)
|
|
|
|
- var text = $(this).text()
|
|
|
|
- $('.edit-user-input').children('.up-icon').css({
|
|
|
|
- left: xy.left - y + 'px'
|
|
|
|
- })
|
|
|
|
- $('.edit-user-input').css({
|
|
|
|
- top: x + 'px',
|
|
|
|
- left: y + 'px'
|
|
|
|
- }).show().children('input').val(text)
|
|
|
|
- // console.log('--text--', text)
|
|
|
|
-})
|
|
|
|
|
|
+// var xy = $(this).offset()
|
|
|
|
+// // console.log('--xy--', xy)
|
|
|
|
+// var x = xy.top + 30
|
|
|
|
+// var maxY = $(document).width() - 600
|
|
|
|
+// var y = maxY < xy.left ? maxY : xy.left
|
|
|
|
+// nowSpan = $(this)
|
|
|
|
+// // console.log('--$(this).offset()--', xy)
|
|
|
|
+// var text = $(this).text()
|
|
|
|
+// $('.edit-user-input').children('.up-icon').css({
|
|
|
|
+// left: xy.left - y + 'px'
|
|
|
|
+// })
|
|
|
|
+// $('.edit-user-input').css({
|
|
|
|
+// top: x + 'px',
|
|
|
|
+// left: y + 'px'
|
|
|
|
+// }).show().children('input').val(text)
|
|
|
|
+// })
|
|
/* 修改关键词标签文字 */
|
|
/* 修改关键词标签文字 */
|
|
$(".edit-user-input").click(function (e) {
|
|
$(".edit-user-input").click(function (e) {
|
|
e.stopPropagation()
|
|
e.stopPropagation()
|
|
@@ -524,3 +531,188 @@ function editKeywordBox() {
|
|
function resetAreaLT() {
|
|
function resetAreaLT() {
|
|
$("#area-del").parent().prev().css("padding-top","8px");
|
|
$("#area-del").parent().prev().css("padding-top","8px");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 关键词编辑修改
|
|
|
|
+$(document).on('click','#inputDel_0 .icon-edit-img',function (e) {
|
|
|
|
+ $('.new-box').addClass('bg-active')
|
|
|
|
+ var key = $(this).attr('data-key')
|
|
|
|
+ var append = $(this).attr('data-append')
|
|
|
|
+ var exclude = $(this).attr('data-exclude')
|
|
|
|
+ console.log(append, exclude, key, 'ddd');
|
|
|
|
+ var index = $(this).parent().attr("data-index")
|
|
|
|
+ var container = $('.new-box.bg-active')
|
|
|
|
+ container.attr('data-index', index)
|
|
|
|
+ container.attr('data-type', 'edit')
|
|
|
|
+ // console.log(key, append, exclude, index);
|
|
|
|
+ $("#keyInput").show().val(key).next().show()
|
|
|
|
+ $('.new-action').show()
|
|
|
|
+ $('#addKeyword').hide()
|
|
|
|
+ $('.new-box').find('input.sm').remove()
|
|
|
|
+ $('.new-confirm').attr('data-key', key).attr('data-append', append).attr('data-exclude', exclude).attr('data-type', 'edit')
|
|
|
|
+ $(this).parent().attr('data-key', key)
|
|
|
|
+
|
|
|
|
+ if(append){
|
|
|
|
+ $('.new-box .add-input-w').show()
|
|
|
|
+ append = append.split(",")
|
|
|
|
+ append.forEach(function (value, index) {
|
|
|
|
+ addOtherInput('.new-box .l .add-w', true)
|
|
|
|
+ $('.new-box .l .sm:eq(' + index + ')').val(value)
|
|
|
|
+ })
|
|
|
|
+ appendArr = append
|
|
|
|
+ }
|
|
|
|
+ if(exclude){
|
|
|
|
+ $('.new-box.r.add-w').show()
|
|
|
|
+ exclude = exclude.split(",")
|
|
|
|
+ exclude.forEach(function (value, index) {
|
|
|
|
+ addOtherInput('.new-box .r .add-w', false)
|
|
|
|
+ $('.new-box .r .sm:eq(' + index + ')').val(value)
|
|
|
|
+ })
|
|
|
|
+ excludeArr = exclude
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+// 倒叙重绘关键词3列dom(一维数组转二维数组横向倒叙排列)
|
|
|
|
+function renderColumn() {
|
|
|
|
+ var indexArr = []
|
|
|
|
+ $('.column:eq(0) > div').each(function(index,el) {
|
|
|
|
+ indexArr.push($(this).attr('data-index'))
|
|
|
|
+ })
|
|
|
|
+ $('.column > div').hide()
|
|
|
|
+ var newArr = divideArrayIntoThreeParts(indexArr.sort(function(a, b){
|
|
|
|
+ return b - a
|
|
|
|
+ }))
|
|
|
|
+ newArr.forEach(function(v, index){
|
|
|
|
+ $('.column').css({'display': 'flex', 'flex-direction': 'column-reverse'})
|
|
|
|
+ v.forEach(function(vv){
|
|
|
|
+ $('.column:eq('+ index +') > div[data-index='+ vv +']').show()
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 关键词添加/编辑 确定操作(新布局调用老方法-微调)
|
|
|
|
+$('.new-box .new-confirm').click(function () {
|
|
|
|
+ // var type = $(this).attr('data-type')
|
|
|
|
+ var d = document.createElement('div')
|
|
|
|
+ var text = $('#keyInput').val()
|
|
|
|
+ if(!text.trim()){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ $(d).html(text)
|
|
|
|
+ text = $(d).text()
|
|
|
|
+ text = text.replace(/(^\s*)|(\s*$)/g, "");
|
|
|
|
+ var box = 'inputDel_0'
|
|
|
|
+ var template = null
|
|
|
|
+ var arr = box
|
|
|
|
+ // 计算当前输入的关键词、附加词、排除词总数
|
|
|
|
+ var inputVal = []
|
|
|
|
+ var inputs = $('.add-input-w').find('.sm')
|
|
|
|
+ inputs.each(function(){
|
|
|
|
+ if ($(this).val()) {
|
|
|
|
+ inputVal.push($(this).val())
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ if (getTotal() + inputVal.length >= wordsLimit) {
|
|
|
|
+ $('.keywords-more-tips').show()
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // start
|
|
|
|
+ // 通过确定按钮的data-key获取到当前编辑的关键词 在关键词数组中的索引 进行删除
|
|
|
|
+ var btnKeyAttr = $(this).attr('data-key')
|
|
|
|
+ if (btnKeyAttr) {
|
|
|
|
+ var index = window[arr].indexOf(btnKeyAttr)
|
|
|
|
+ window[arr].splice(index, 1)
|
|
|
|
+ keyAllArr.splice(index, 1)
|
|
|
|
+ }
|
|
|
|
+ // end
|
|
|
|
+
|
|
|
|
+ var tempArr = keyAllArr.map(function(v){return v.name})
|
|
|
|
+ if(tempArr.indexOf(text) === -1) {
|
|
|
|
+ keyAllArr.push({
|
|
|
|
+ name: text,
|
|
|
|
+ append: appendArr,
|
|
|
|
+ exclude: excludeArr
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ appendArr = []
|
|
|
|
+ excludeArr = []
|
|
|
|
+ $(".new-box input.sm").remove()
|
|
|
|
+ $(".add-input-w").css("display","none");
|
|
|
|
+ $("#addKeyword").css("display","block");
|
|
|
|
+ $('.new-action').hide()
|
|
|
|
+ $('.new-box').removeClass('bg-active')
|
|
|
|
+ setTimeout(function(){
|
|
|
|
+ fixLeft()
|
|
|
|
+ },80)
|
|
|
|
+ $('#keyInput').val('').hide()
|
|
|
|
+
|
|
|
|
+ var keyTemArr = window[arr]
|
|
|
|
+ if(!Array.isArray(keyTemArr)) {
|
|
|
|
+ window[arr] = []
|
|
|
|
+ keyTemArr = window[arr]
|
|
|
|
+ }
|
|
|
|
+ keyTemArr.push(text)
|
|
|
|
+
|
|
|
|
+ var nnTemplate = ''
|
|
|
|
+ for (var i = 0; i<keyTemArr.length;i++) {
|
|
|
|
+ var append = keyAllArr[i].append ? keyAllArr[i].append : []
|
|
|
|
+ var exclude = keyAllArr[i].exclude ? keyAllArr[i].exclude: []
|
|
|
|
+ nnTemplate += createKeyBox(keyTemArr[i], append, exclude, i)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $('#inputDel_0 .column:eq(0)').html(nnTemplate)
|
|
|
|
+ $('#inputDel_0 .column:eq(1)').html(nnTemplate)
|
|
|
|
+ $('#inputDel_0 .column:eq(2)').html(nnTemplate)
|
|
|
|
+ // 重绘操作
|
|
|
|
+ renderColumn()
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+function divideArrayIntoThreeParts(arr) {
|
|
|
|
+ // 获取数组的长度
|
|
|
|
+ const length = arr.length;
|
|
|
|
+ // 计算每一份的长度
|
|
|
|
+ const partLength = Math.ceil(length / 3);
|
|
|
|
+ // 初始化一个二维数组用于存储结果
|
|
|
|
+ const result = [[], [], []];
|
|
|
|
+
|
|
|
|
+ // 遍历原始数组
|
|
|
|
+ for (let i = 0; i < length; i++) {
|
|
|
|
+ // 根据当前索引确定该元素应该放入二维数组的哪一部分
|
|
|
|
+ const partIndex = i % 3;
|
|
|
|
+ // 将元素放入对应的子数组中
|
|
|
|
+ result[partIndex].push(arr[i]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 返回结果
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 关键词添加/编辑 取消操作
|
|
|
|
+$('.new-box .new-cancel').click(function () {
|
|
|
|
+ var LArr = [$("#inputDel_0 .column:eq(0)>div").length,$("#inputDel_0 .column:eq(1)>div").length,$("#inputDel_0 .column:eq(2)>div").length]
|
|
|
|
+ var length = sum(LArr)
|
|
|
|
+ $(".new-box input.sm").remove()
|
|
|
|
+ $(".add-input-w-").hide()
|
|
|
|
+ $(".add-input-w").hide()
|
|
|
|
+ $('.new-action').hide()
|
|
|
|
+ $('.new-box').removeClass('bg-active')
|
|
|
|
+ $('#keyInput').val('')
|
|
|
|
+
|
|
|
|
+ if (length > 0) {
|
|
|
|
+ $('#keyInput').hide()
|
|
|
|
+ $("#addKeyword").show();
|
|
|
|
+ } else {
|
|
|
|
+ $('#keyInput').show()
|
|
|
|
+ $("#addKeyword").hide();
|
|
|
|
+ }
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+// 数组求和
|
|
|
|
+function sum(arr){
|
|
|
|
+ let number = 0;
|
|
|
|
+ for(var i = 0;i<arr.length;i++){
|
|
|
|
+ number += arr[i];
|
|
|
|
+ }
|
|
|
|
+ return number;
|
|
|
|
+}
|