|
@@ -118,14 +118,26 @@ $(document).on('click','.delete-close>i',function () {
|
|
|
var f = arr === "inputDel_0"
|
|
|
if(f) {
|
|
|
// beforeDelKeyIndex = dom.parent().index('#inputDel_0 .column')
|
|
|
- index = window[arr].indexOf(dom.find('.key span').text())
|
|
|
- // console.log(index)
|
|
|
+ // index = window[arr].indexOf(dom.find('.key span').text())
|
|
|
|
|
|
+ index = dom.attr('data-index')
|
|
|
window[arr].splice(index,1)
|
|
|
keyAllArr.splice(index,1)
|
|
|
var vKey = $(dom).attr('data-key')
|
|
|
dom.remove()
|
|
|
$('#inputDel_0 div[data-key="'+vKey+'"]').remove()
|
|
|
+ var nnTemplate = ''
|
|
|
+ var keyTemArr = window[arr]
|
|
|
+ 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)
|
|
|
+ initDom()
|
|
|
renderColumn()
|
|
|
} else {
|
|
|
window[arr].splice(index,1)
|
|
@@ -141,7 +153,6 @@ $(document).on('click','.delete-close>i',function () {
|
|
|
}
|
|
|
//20181227
|
|
|
if (arr && arr.indexOf("inputDel")>-1){
|
|
|
- console.log(arr, 'arr', $("div[data-arr='"+arr+"']").length);
|
|
|
if($("div[data-arr='"+arr+"']").length==0){
|
|
|
$("div[id='"+arr+"']").siblings(".new-box").children('.user-input').find("input").show();
|
|
|
$("div[id='"+arr+"']").siblings('.new-box').children(".add-input-w-").hide();
|
|
@@ -323,7 +334,6 @@ function addDelInput(t,type) {
|
|
|
inputVal.push($(this).val())
|
|
|
}
|
|
|
})
|
|
|
- // console.log(inputVal);
|
|
|
if (getTotal() + inputVal.length >= wordsLimit) {
|
|
|
$('.keywords-more-tips').show()
|
|
|
return
|
|
@@ -408,7 +418,7 @@ function addDelInputB(t,type) {
|
|
|
/* 添加排除/附加词 */
|
|
|
var excludeArr = []
|
|
|
var appendArr = []
|
|
|
-function addOtherInput(t,f) {
|
|
|
+function addOtherInput(t,f, type) {
|
|
|
if($("#keyInput").val()==""){
|
|
|
return false;
|
|
|
}
|
|
@@ -431,27 +441,35 @@ function addOtherInput(t,f) {
|
|
|
input.placeholder = temp
|
|
|
input.maxLength = 20;
|
|
|
if(f){
|
|
|
- var l = appendArr.length
|
|
|
- $(input).on('input',function () {
|
|
|
+ if(type !== 'edit') {
|
|
|
+ var l = appendArr.length
|
|
|
+ console.log($(input), 'input input');
|
|
|
+ console.log(appendArr, l, 'append--add');
|
|
|
+ $(input).on('input',function () {
|
|
|
var val = $.trim($(this).val()).replace(/\s/g,"");
|
|
|
+ console.log(val, 'val');
|
|
|
if(val){
|
|
|
appendArr[l] = val
|
|
|
}else {
|
|
|
appendArr.splice(l,1)
|
|
|
}
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
}else {
|
|
|
- var l = excludeArr.length
|
|
|
- $(input).on('input',function () {
|
|
|
- var val = $.trim($(this).val()).replace(/\s/g,"");
|
|
|
- if(val){
|
|
|
- excludeArr[l] = val
|
|
|
- }else{
|
|
|
- excludeArr.splice(l,1)
|
|
|
- }
|
|
|
- })
|
|
|
+ if (type !== 'edit') {
|
|
|
+ var l = excludeArr.length
|
|
|
+ $(input).on('input',function () {
|
|
|
+ var val = $.trim($(this).val()).replace(/\s/g,"");
|
|
|
+ if(val){
|
|
|
+ excludeArr[l] = val
|
|
|
+ }else{
|
|
|
+ excludeArr.splice(l,1)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- console.log('附加词:' + appendArr, '排除词:'+ excludeArr);
|
|
|
+ // console.log('附加词:' + appendArr, '排除词:'+ excludeArr);
|
|
|
$(t).before(input)
|
|
|
$(input).focus();
|
|
|
}
|
|
@@ -534,42 +552,58 @@ function resetAreaLT() {
|
|
|
|
|
|
// 关键词编辑修改
|
|
|
$(document).on('click','#inputDel_0 .icon-edit-img',function (e) {
|
|
|
+ appendArr = []
|
|
|
+ excludeArr = []
|
|
|
$('.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')
|
|
|
+ $('.new-confirm').attr('data-key', key).attr('data-append', append).attr('data-exclude', exclude).attr('data-type', 'edit').attr('data-index', index)
|
|
|
$(this).parent().attr('data-key', key)
|
|
|
|
|
|
if(append){
|
|
|
$('.new-box .add-input-w').show()
|
|
|
append = append.split(",")
|
|
|
+ // console.log(append, 'append-1');
|
|
|
append.forEach(function (value, index) {
|
|
|
- addOtherInput('.new-box .l .add-w', true)
|
|
|
+ addOtherInput('.new-box .l .add-w', true, 'edit')
|
|
|
+
|
|
|
$('.new-box .l .sm:eq(' + index + ')').val(value)
|
|
|
+ $('.new-box .l .sm:eq(' + index + ')').on('input', function() {
|
|
|
+ if ($(this).val()) {
|
|
|
+ append[index] = $(this).val()
|
|
|
+ }else{
|
|
|
+ append.splice(index,1)
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
appendArr = append
|
|
|
+ console.log(appendArr, 'append-edit');
|
|
|
}
|
|
|
if(exclude){
|
|
|
$('.new-box.r.add-w').show()
|
|
|
exclude = exclude.split(",")
|
|
|
exclude.forEach(function (value, index) {
|
|
|
- addOtherInput('.new-box .r .add-w', false)
|
|
|
+ addOtherInput('.new-box .r .add-w', false, 'edit')
|
|
|
$('.new-box .r .sm:eq(' + index + ')').val(value)
|
|
|
+ $('.new-box .r .sm:eq(' + index + ')').on('input', function() {
|
|
|
+ if ($(this).val()) {
|
|
|
+ exclude[index] = $(this).val()
|
|
|
+ }else{
|
|
|
+ exclude.splice(index,1)
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
excludeArr = exclude
|
|
|
}
|
|
|
-
|
|
|
})
|
|
|
|
|
|
// 倒叙重绘关键词3列dom(一维数组转二维数组横向倒叙排列)
|
|
@@ -592,7 +626,7 @@ function renderColumn() {
|
|
|
|
|
|
// 关键词添加/编辑 确定操作(新布局调用老方法-微调)
|
|
|
$('.new-box .new-confirm').click(function () {
|
|
|
- // var type = $(this).attr('data-type')
|
|
|
+ var type = $(this).attr('data-type')
|
|
|
var d = document.createElement('div')
|
|
|
var text = $('#keyInput').val()
|
|
|
if(!text.trim()){
|
|
@@ -619,24 +653,50 @@ $('.new-box .new-confirm').click(function () {
|
|
|
|
|
|
// 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)
|
|
|
- }
|
|
|
+ // 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 editIndex = $(this).attr('data-index')
|
|
|
+ console.log(editIndex,type, text, appendArr, excludeArr, 'editIndex');
|
|
|
|
|
|
- var tempArr = keyAllArr.map(function(v){return v.name})
|
|
|
- if(tempArr.indexOf(text) === -1) {
|
|
|
+ var keyTemArr = window[arr] || []
|
|
|
+ if(!Array.isArray(keyTemArr)) {
|
|
|
+ window[arr] = []
|
|
|
+ keyTemArr = window[arr]
|
|
|
+ }
|
|
|
+ if (type === 'edit') {
|
|
|
+ // 如果是修改操作
|
|
|
+ keyAllArr[editIndex].name = text
|
|
|
+ keyAllArr[editIndex].append = appendArr
|
|
|
+ keyAllArr[editIndex].exclude = excludeArr
|
|
|
+ keyTemArr[editIndex] = text
|
|
|
+ } else {
|
|
|
+ // 如果是添加操作
|
|
|
keyAllArr.push({
|
|
|
name: text,
|
|
|
append: appendArr,
|
|
|
exclude: excludeArr
|
|
|
})
|
|
|
+ keyTemArr.push(text)
|
|
|
}
|
|
|
+ console.log(keyAllArr, keyTemArr, 'keyAllArr');
|
|
|
+
|
|
|
+ // 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");
|
|
@@ -647,12 +707,16 @@ $('.new-box .new-confirm').click(function () {
|
|
|
},80)
|
|
|
$('#keyInput').val('').hide()
|
|
|
|
|
|
- var keyTemArr = window[arr]
|
|
|
- if(!Array.isArray(keyTemArr)) {
|
|
|
- window[arr] = []
|
|
|
- keyTemArr = window[arr]
|
|
|
- }
|
|
|
- keyTemArr.push(text)
|
|
|
+ // var keyTemArr = window[arr]
|
|
|
+ // if(!Array.isArray(keyTemArr)) {
|
|
|
+ // window[arr] = []
|
|
|
+ // keyTemArr = window[arr]
|
|
|
+ // }
|
|
|
+ // if(editIndex) {
|
|
|
+ // keyTemArr[editIndex] = text
|
|
|
+ // } else {
|
|
|
+ // keyTemArr.push(text)
|
|
|
+ // }
|
|
|
|
|
|
var nnTemplate = ''
|
|
|
for (var i = 0; i<keyTemArr.length;i++) {
|
|
@@ -670,11 +734,11 @@ $('.new-box .new-confirm').click(function () {
|
|
|
|
|
|
function divideArrayIntoThreeParts(arr) {
|
|
|
// 获取数组的长度
|
|
|
- const length = arr.length;
|
|
|
+ var length = arr.length;
|
|
|
// 计算每一份的长度
|
|
|
- const partLength = Math.ceil(length / 3);
|
|
|
+ // const partLength = Math.ceil(length / 3);
|
|
|
// 初始化一个二维数组用于存储结果
|
|
|
- const result = [[], [], []];
|
|
|
+ var result = [[], [], []];
|
|
|
|
|
|
// 遍历原始数组
|
|
|
for (let i = 0; i < length; i++) {
|
|
@@ -688,8 +752,8 @@ function divideArrayIntoThreeParts(arr) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-// 关键词添加/编辑 取消操作
|
|
|
-$('.new-box .new-cancel').click(function () {
|
|
|
+// 初始化dom
|
|
|
+function initDom() {
|
|
|
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()
|
|
@@ -706,6 +770,15 @@ $('.new-box .new-cancel').click(function () {
|
|
|
$('#keyInput').show()
|
|
|
$("#addKeyword").hide();
|
|
|
}
|
|
|
+ appendArr = []
|
|
|
+ excludeArr = []
|
|
|
+ $('.new-box').removeAttr('data-type')
|
|
|
+ $('.new-confirm').removeAttr('data-key').removeAttr('data-append').removeAttr('data-exclude').removeAttr('data-type').removeAttr('data-index')
|
|
|
+}
|
|
|
+
|
|
|
+// 关键词添加/编辑 取消操作
|
|
|
+$('.new-box .new-cancel').click(function () {
|
|
|
+ initDom()
|
|
|
})
|
|
|
|
|
|
// 数组求和
|