123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- $(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){
- $(".addkeyWord").show();
- $(".showKeyWord").hide();
- } else {
- $(".addkeyWord").hide();
- $(".showKeyWord").show();
- }
- }
- hasWords();
-
- //添加按钮
- $(".addKeyWord i").on('click',function(){
- sessionStorage.removeItem("keyWord");
- window.location.href="/front/wx_dataExport/keyWordInput";
- });
- // 添加keyWords检查输入框内是否有文字,如果有才能点击添加按钮
- $('.addkeyWord input.enterOne').on('input', function() {
- if ($(this).val().length >= 100) {
- var s = $(this).val().slice(0,100)
- $(this).val(s)
- weui.toast('关键词不能超过100字', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){ console.log('close') }
- });
- return
- }
- 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);
- }
- });
-
- // $('.exclusion input.enterOne').on('input', function() {
- // var buttonDOM = $(this).siblings().find('button')[0]
- // if ($(this).val().length >= 1) {
- // buttonDOM.style.opacity = 1
- // buttonDOM.removeAttribute("disabled")
- // } else {
- // buttonDOM.style.opacity = .5
- // buttonDOM.setAttribute("disabled", true)
- // }
- // })
-
- // 添加 按钮的点击事件
- $('.addkeyWord .btn .save').on('click', function(){
- var keyWord = $('.addkeyWord input.enterOne').val();
- var Obj = {"keyWord": keyWord};
- keyWordArr.push(Obj);
- localStorage.setItem("keyWord", JSON.stringify(keyWordArr));
- 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">
- <span contentEditable="true">${ keyWord }</span>
- <button class="addAdjunctWord">编辑 附加词</button>
- <button class="addExclusion">添加 排除词</button>
- <button class="deleteKey">删除</button>
- <button class="ascertainKey">确定</button>
- </div>
- </li>`
- $('.showKeyWord > ul').prepend(html);
-
- // 隐藏
- $(".addkeyWord").hide();
- $('.showKeyWord').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){
- $('.modify span').each(function(item){
- $('.modify span')[0].contentEditable = true
- });
- // console.log($(this).parent().siblings().find('span').text())
- $(this).parent().hide();
- $(this).parent().siblings().css('display','block')
- });
- // 编辑删除
- $('.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();
- hasWords()
- }
- }]
- });
- // console.log('删除关键词:',$(this).parent().find('span').text())
- })
- // 编辑确定
- $('.showKeyWord').on('click', '.ascertainKey', function(e) {
- var $this = $(this);
- var keyWord = $(this).siblings('span').text();
- var keyWords = $(this).parent().prev().find('.key').text();
- for(var i in keyWordArr){
- if(keyWordArr[i].keyWord === keyWords){
- keyWordArr[i].keyWord = keyWord;
- }
- }
- localStorage.keyWord = JSON.stringify(keyWordArr);
- // weui.confirm('保存关键词?', {
- // buttons: [{
- // label: '我再想想',
- // type: 'default',
- // onClick: function(){
- // $this.parent().hide().siblings().show()
- // console.log('我再想想')
- // }
- // }, {
- // label: '确定保存',
- // type: 'primary',
- // onClick: function(){
- // $this.parent().siblings().find('.key').text(keyWord)
- // $this.parent().hide().siblings().show()
- // console.log(keyWord)
- // }
- // }]
- // });
- $this.parent().siblings().find('.key').text(keyWord)
- $this.parent().hide().siblings().show()
- // console.log(keyWord)
- })
- //去空格方法
- String.prototype.trim = function(){
- return this.replace(/(^\s*)|(\s*$)/g, ' ');
- }
- //关键词个数
- $('.modify span').keydown(function(){
- var olength = $(this).text().replace(/\s+/g,'').length;
- // console.log(olength)
- if(olength >= 100){
- $('.fontLength').show();
- var s = $(this).text().slice(0,100)
- $(this).text(s)
- weui.toast('关键词不能超过100字', {
- duration: 2000,
- className: 'text-overflow100',
- callback: function(){
- }
- });
- }
- })
- // $(".addExclusion").on('click',function(){
- // $('.exclusion').show();
- // $('.showKeyWord').hide();
- // })
-
- })
|