123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- $(function(){
- $(".enterOne").focus(function(){
- $(".btnChoose").show();
- });
- $('.knowBtn').on('click',function(){
- $(".problemPop").hide()
- });
- $(".problem").on('click',function(){
- $(".problemPop").css("display",'flex');
- });
- function hasWords () {
- var showKeyWordLength = $(".showKeyWord ul").find('li').length;
- if(showKeyWordLength === 0){
- $(".enter.addkeyWord").show();
- $(".addKeyWord").hide();
- $(".showKeyWord").hide();
- } else {
- $(".enter.addkeyWord").hide();
- $(".showKeyWord").show();
- $(".addKeyWord").show();
- }
- }
- hasWords();
- //添加按钮
- $(".addKeyWord i").on('click',function(){
- sessionStorage.removeItem("keyWord");
- window.location.href="/front/wx_dataExport/keyWordInput";
- });
- // 添加keyWords检查输入框内是否有文字,如果有才能点击添加按钮
- $('.addkeyWord input.enterOne').on('input', function() {
- var buttonDOM = $(this).siblings()[1].children[0];
- if ($(this).val().length >= 1) {
- buttonDOM.style.opacity = 1;
- buttonDOM.removeAttribute("disabled");
- //
- $(this).next().find(".appended").prop("disabled", false);
- $(this).next().find(".exclude").prop("disabled", false);
- } else {
- buttonDOM.style.opacity = .5;
- buttonDOM.setAttribute("disabled", true);
- //
- $(this).next().find(".appended").prop("disabled", true);
- $(this).next().find(".exclude").prop("disabled", true);
- }
- });
- $('textarea').each(function(i,dom){
- // console.log(i,dom)
- dom.style.height = dom.scrollHeight +'px';
- });
- $("textarea").on("input", function() {
- this.style.height = 'auto';
- this.style.height = this.scrollHeight + "px";
- });
- // 添加 按钮的点击事件
- $('.addkeyWord .btn .save').on('click', function(){
- var keyWord = $('.addkeyWord input.enterOne').val();
- keyWord = keyWord.replace(/\s/g,"");
- if (keyWord.length > 20) {
- // var s = keyWord.slice(0,19);
- // $('.addkeyWord input.enterOne').val(s)
- weui.toast('关键词不能超过20字', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){}
- });
- return
- }
- var keyWordHtml = "";
- var html = `
- <li>
- <div class="one">
- <div>
- <span>
- <strong> 关键词:</strong>
- <p class="key">${ keyWord }</p>
- </span>
- </div>
- <button class="editKeyWord"><i class="iconfont icon-xiugai"></i> 修改</button>
- </div>
- <div class="modify">
- <textarea name="" rows="1" placeholder="" maxlength="">${ keyWord}</textarea>
- <button class="addAdjunctWord">编辑 附加词</button>
- <button class="addExclusion">添加 排除词</button>
- <button class="deleteKey">删除</button>
- <button class="ascertainKey">确定</button>
- </div>
- </li>`;
- if(sessionStorage.keyWord!==""&&sessionStorage.keyWord!==undefined){
- var keys = JSON.parse(sessionStorage.keyWord);
- for(var i in keys){
- var append = keys[i].appended;
- var exclude = keys[i].exclude;
- // keys[i].keyWord = keyWord;
- if(keys[i].keyWord === turn){
- if(keyWord !== turn){
- keys[i].keyWord = keyWord
- }
- keyWordArr.push(keys[i]);
- localStorage.setItem("keyWord", JSON.stringify(keyWordArr));
- //
- if(append !== undefined && exclude === undefined){
- keyWordHtml += `
- <li>
- <div class="one">
- <div>
- <span>
- <strong> 关键词:</strong>
- <p class="key">${ keys[i].keyWord }</p>
- </span>
- <span>
- <strong> 附加词:</strong>
- <p class="addition">${ append }</p>
- </span>
- </div>
- <button class="editKeyWord"><i class="iconfont icon-xiugai"></i> 修改</button>
- </div>
- <div class="modify">
- <textarea name="" rows="1" placeholder="" maxlength="">${ keys[i].keyWord}</textarea>
- <button class="addAdjunctWord">编辑 附加词</button>
- <button class="addExclusion">添加 排除词</button>
- <button class="deleteKey">删除</button>
- <button class="ascertainKey">确定</button>
- </div>
- </li>`;
- }else if(append === undefined && exclude !== undefined){
- keyWordHtml += `
- <li>
- <div class="one">
- <div>
- <span>
- <strong> 关键词:</strong>
- <p class="key">${ keys[i].keyWord }</p>
- </span>
- <span>
- <strong> 排除词:</strong>
- <p class="exclusion">${ exclude }</p>
- </span>
- </div>
- <button class="editKeyWord"><i class="iconfont icon-xiugai"></i> 修改</button>
- </div>
- <div class="modify">
- <textarea name="" rows="1" placeholder="" maxlength="">${ keys[i].keyWord}</textarea>
- <button class="addAdjunctWord">编辑 附加词</button>
- <button class="addExclusion">添加 排除词</button>
- <button class="deleteKey">删除</button>
- <button class="ascertainKey">确定</button>
- </div>
- </li>`;
- }else if(append !== undefined && exclude !== undefined){
- keyWordHtml += `
- <li>
- <div class="one">
- <div>
- <span>
- <strong> 关键词:</strong>
- <p class="key">${ keys[i].keyWord }</p>
- </span>
- <span>
- <strong> 附加词:</strong>
- <p class="addition">${ append }</p>
- </span>
- <span>
- <strong> 排除词:</strong>
- <p class="exclusion">${ exclude }</p>
- </span>
- </div>
- <button class="editKeyWord"><i class="iconfont icon-xiugai"></i> 修改</button>
- </div>
- <div class="modify">
- <textarea name="" rows="1" placeholder="" maxlength="">${ keys[i].keyWord}</textarea>
- <button class="addAdjunctWord">编辑 附加词</button>
- <button class="addExclusion">添加 排除词</button>
- <button class="deleteKey">删除</button>
- <button class="ascertainKey">确定</button>
- </div>
- </li>`;
- }else if(append === undefined && exclude === undefined){
- keyWordHtml += `
- <li>
- <div class="one">
- <div>
- <span>
- <strong> 关键词:</strong>
- <p class="key">${ keys[i].keyWord }</p>
- </span>
- </div>
- <button class="editKeyWord"><i class="iconfont icon-xiugai"></i> 修改</button>
- </div>
- <div class="modify">
- <textarea name="" rows="1" placeholder="" maxlength="">${ keys[i].keyWord}</textarea>
- <button class="addAdjunctWord">编辑 附加词</button>
- <button class="addExclusion">添加 排除词</button>
- <button class="deleteKey">删除</button>
- <button class="ascertainKey">确定</button>
- </div>
- </li>`;
- }
- keyWordHtml = keyWordHtml.replace(/,/g, " ");
- //
- $('.showKeyWord > ul').prepend(keyWordHtml);
- // 隐藏
- $(".enter.addkeyWord").hide();
- $(".showKeyWord").show();
- $(".addKeyWord").show();
- $('.enter.addkeyWord > input').val('');
- var buttonDOM = $('.enter.addkeyWord .btn button')[0];
- buttonDOM.style.opacity = .5;
- buttonDOM.setAttribute("disabled", true);
- return
- }
- }
- }
- var Obj = {"keyWord": keyWord};
- keyWordArr.push(Obj);
- localStorage.setItem("keyWord", JSON.stringify(keyWordArr));
- $('.showKeyWord > ul').prepend(html);
- // 隐藏
- $(".enter.addkeyWord").hide();
- $(".showKeyWord").show();
- $(".addKeyWord").show();
- $('.enter.addkeyWord > input').val('');
- var buttonDOM = $('.enter.addkeyWord .btn button')[0];
- buttonDOM.style.opacity = .5;
- buttonDOM.setAttribute("disabled", true);
- });
- // 编辑
- $(".showKeyWord").on('click', '.editKeyWord',function(e){
- let oSpan = $(this).parent().siblings().children('textarea');
- let val = $(oSpan).val();
- var keyWord = $(this).prev().children().find(".key").text();
- for(var i in keyWordArr){
- if(keyWordArr[i].keyWord === keyWord){
- var str = "";
- var strs = "";
- if(keyWordArr[i].appended !== undefined){
- var appended = keyWordArr[i].appended.length;
- if(appended < 1){
- str = "添加 附加词";
- }else{
- str = "编辑 附加词 ("+appended+")";
- }
- }else{
- str = "添加 附加词";
- }
- $(this).parent().next().find(".addAdjunctWord").text(str);
- if(keyWordArr[i].exclude !== undefined){
- var exclude = keyWordArr[i].exclude.length;
- if(exclude < 1){
- strs = "添加 排除词";
- }else{
- strs = "编辑 排除词 ("+exclude+")";
- }
- }else{
- strs = "添加 排除词";
- }
- $(this).parent().next().find(".addExclusion").text(strs);
- }
- }
- $(this).parent().hide();
- $(this).parent().siblings().show().parent().siblings().children('.modify').hide().siblings('.one').show()
- $(oSpan).val('').focus().val(val);
- $(".addKeyWord").hide();
- });
- //
- //防止键盘把当前输入框给挡住
- $('input[type="text"],textarea').focus(function () {
- var target = this;
- setTimeout(function(){
- target.scrollIntoViewIfNeeded();
- },400);
- });
- // 编辑删除
- $('.showKeyWord').on('click', '.deleteKey', function(e) {
- var jQueryDOM = $(this).parents('li');
- var keyWord = $(this).parent().prev().find('.key').text();
- weui.confirm('确定要删除关键词?', {
- buttons: [{
- label: '取消',
- type: 'default',
- onClick: function(){
- }
- }, {
- label: '确定',
- type: 'primary',
- onClick: function(){
- keyWordArr = keyWordArr.filter((e=>{return e.keyWord!==keyWord}));
- localStorage.keyWord = JSON.stringify(keyWordArr);
- jQueryDOM.remove();
- sessionStorage.removeItem("keyWord");
- $(".addKeyWord").show();
- $(".btnChoose").hide();
- $(".appended").text("添加 附加词");
- $(".exclude").text("添加 排除词");
- //
- $(".appended").prop("disabled", true);
- $(".exclude").prop("disabled", true);
- //
- hasWords()
- }
- }]
- });
- // console.log('删除关键词:',$(this).parent().find('span').text())
- })
- // 编辑确定
- $('.showKeyWord').on('click', '.ascertainKey', function(e) {
- var $this = $(this);
- // var keyWord = $(this).siblings('span').text();
- var keyWord = $(this).siblings('textarea').val();
- var keyWords = $(this).parent().prev().find('.key').text();
- keyWord = keyWord.replace(/\s/g,"");
- if ($(this).parent().find("textarea").val().length < 1) {
- weui.toast('关键词不能为空', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){
- }
- });
- return
- }else if($(this).parent().find("textarea").val().length > 20){
- // var s = $(this).parent().find("span").text().slice(0,19);
- // $(this).parent().find("span").text(s);
- weui.toast('关键词不能超过20字', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){}
- });
- return
- }else{
- for(var i in keyWordArr){
- if(keyWord !== keyWords){
- if(keyWordArr[i].keyWord === keyWord){
- weui.toast('关键词重复了', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){}
- });
- return
- }
- }
- if(keyWordArr[i].keyWord === keyWords){
- keyWordArr[i].keyWord = keyWord;
- }
- }
- localStorage.keyWord = JSON.stringify(keyWordArr);
- $this.parent().siblings().find('.key').text(keyWord)
- $this.parent().hide().siblings().show()
- }
- $(".addKeyWord").show();
- })
- //去空格方法
- String.prototype.trim = function(){
- return this.replace(/(^\s*)|(\s*$)/g, ' ');
- }
- })
|