浏览代码

feat: 搜索页面同步 input 流程中发现问题处理

zhangyuhan 2 年之前
父节点
当前提交
38db418d6e

+ 5 - 2
src/web/staticres/js/common.js

@@ -865,7 +865,7 @@ function isElementVisible (el) {
  * 3. 监听顶部搜索 change 事件,更新页面 input 值
  * 4. 监听顶部搜索 submit 事件,执行传递的页面 submit 函数
  * 5. 监听 window.onbeforeunload 事件,销毁上述事件监听
- * 6. 返回 { off: fn } 提供手动 off 函数,用于手动销毁上述事件监听
+ * 6. 返回 { off: fn, syncInput: fn } 提供手动 off 函数,用于手动销毁上述事件监听, syncInput 用于手动触发同步 input
  * 7. 初始化时自动触发 change, scroll 事件更新状态
  *
  * // 对应支持的搜索类型
@@ -893,7 +893,7 @@ function isElementVisible (el) {
  * @param config.submit - 用于实现当前页面搜索事件函数
  * @param config.inputSelector - 用于实现当前页面搜索 input 输入框选择器特殊处理,默认 input
  * @param config.submitSelector - 用于实现当前页面搜索提交按钮选择器特殊处理,默认 button
- * @returns {{off: off}}
+ * @returns {{off: fn, syncInput: fn}}
  */
 function initSearchPageEvent (config) {
   // el 对应容器 submit 自定义提交函数
@@ -1021,6 +1021,9 @@ function initSearchPageEvent (config) {
   return {
     off: function () {
       offEvent()
+    },
+    syncInput: function () {
+      $(inputEl).trigger('input')
     }
   }
 }

+ 22 - 4
src/web/staticres/js/ent-search-index-pc.js

@@ -175,7 +175,7 @@ var vm = new Vue({
                 entClass: '', // 单位类型
                 entContact: '', // 联系方式
                 establish:[],//成立时间
-                
+
             },
             listState: {
                 loaded: false, // 是否已经搜索过
@@ -288,6 +288,17 @@ var vm = new Vue({
         // 全选按钮逻辑
         // this.searchTypeChange([], true)
         this.industryTab()
+        /**
+         * 初始化页面搜索框与工作台顶部搜索联动事件函数,详情见对应函数 common.js
+         * 需要在 dom 初始化后调用来监听事件,Vue中需要额外在 input 对应事件额外手动触发事件
+         */
+        if (goTemplateData.inIframe) {
+          this._$SearchEvent = initSearchPageEvent({
+            type: 'company',
+            el: '.search-header-top .input-container',
+            submitSelector: '.search-button'
+          })
+        }
     },
     methods: {
         industryTab: function() {
@@ -486,7 +497,7 @@ var vm = new Vue({
                             // thisList.push(_this.getTimeDate(10)+'-'+_this.getTimeDate(1))
                             thisList.push('10y-')
                             break;
-                    
+
                         default:
                             break;
                     }
@@ -543,7 +554,7 @@ var vm = new Vue({
                     this.endDate = this.getThisDate(e);
                 }
             }
-            
+
         },
         //成立时间自定义区间搜索按钮
         establishSearch:function () {
@@ -664,6 +675,13 @@ var vm = new Vue({
             Object.assign(this.listState, state)
         },
         getPreSearchList: utils.debounce(function () {
+            /**
+             * 初始化页面搜索框与工作台顶部搜索联动事件函数,详情见对应函数 common.js
+             * 需要在 dom 初始化后调用来监听事件,Vue中需要额外在 input 对应事件额外手动触发事件
+             */
+            if (this._$SearchEvent) {
+              this._$SearchEvent.syncInput()
+            }
             var data = {
                 name: this.searchContent.trim()
             }
@@ -980,4 +998,4 @@ function baiduEvent(name) {
   } catch (e) {
     console.log('未初始化百度统计')
   }
-}
+}

+ 18 - 0
src/web/staticres/js/pur-search-index-pc.js

@@ -184,6 +184,17 @@ var vm = new Vue({
         this.$on('updatescope', (data) => {
             this.setData.keyList = data
         })
+        /**
+         * 初始化页面搜索框与工作台顶部搜索联动事件函数,详情见对应函数 common.js
+         * 需要在 dom 初始化后调用来监听事件,Vue中需要额外在 input 对应事件额外手动触发事件
+         */
+        if (goTemplateData.inIframe) {
+          this._$SearchEvent = initSearchPageEvent({
+            type: 'buyer',
+            el: '.search-header-top .input-container',
+            submitSelector: '.search-button'
+          })
+        }
     },
     methods: {
         updatescope(data) {
@@ -197,6 +208,13 @@ var vm = new Vue({
         },
         // 采购单位模糊搜索
         getPreSearchList: utils.debounce(function () {
+            /**
+             * 初始化页面搜索框与工作台顶部搜索联动事件函数,详情见对应函数 common.js
+             * 需要在 dom 初始化后调用来监听事件,Vue中需要额外在 input 对应事件额外手动触发事件
+             */
+            if (this._$SearchEvent) {
+              this._$SearchEvent.syncInput()
+            }
             var data = {
                 name: this.searchContent.trim()
             }

+ 0 - 10
src/web/templates/micro/web-pc/index.html

@@ -102,16 +102,6 @@
 <script>
     $(function () {
         haslogin({{.T.logid}});
-      /**
-       * 初始化页面搜索框与工作台顶部搜索联动事件函数,详情见对应函数 common.js
-       */
-      if (goTemplateData.inIframe) {
-        initSearchPageEvent({
-          type: 'supplier',
-          el: '.search-header-top .input-container',
-          submitSelector: '.search-button'
-        })
-      }
     })
 </script>
 <!--S-百度统计-->

+ 0 - 10
src/web/templates/pc/entsearchindex.html

@@ -455,16 +455,6 @@
             searchContent: {{.T.searchvalue}},
         }
         haslogin({{.T.logid}})
-        /**
-         * 初始化页面搜索框与工作台顶部搜索联动事件函数,详情见对应函数 common.js
-         */
-        if (goTemplateData.inIframe) {
-          initSearchPageEvent({
-            type: 'company',
-            el: '.search-header-top .input-container',
-            submitSelector: '.search-button'
-          })
-        }
 	</script>
     <script src='{{Msg "seo" "cdn"}}/common-module/public/js/china-map-data.js?v={{Msg "seo" "version"}}'></script>
     <script src='{{Msg "seo" "cdn"}}/common-module/selector/js/provinceMap.js'></script>

+ 0 - 10
src/web/templates/pc/pursearchindex.html

@@ -303,16 +303,6 @@
             searchContent: {{.T.searchvalue}},
         }
         haslogin({{.T.logid}})
-        /**
-         * 初始化页面搜索框与工作台顶部搜索联动事件函数,详情见对应函数 common.js
-         */
-        if (goTemplateData.inIframe) {
-          initSearchPageEvent({
-            type: 'buyer',
-            el: '.search-header-top .input-container',
-            submitSelector: '.search-button'
-          })
-        }
 	</script>
   <script src='{{Msg "seo" "cdn"}}/common-module/public/js/china-map-data.js?v={{Msg "seo" "version"}}'></script>
   <script src='{{Msg "seo" "cdn"}}/common-module/selector/js/provinceMap.js?v={{Msg "seo" "version"}}'></script>

+ 9 - 6
src/web/templates/pc/supsearch.html

@@ -236,7 +236,8 @@
       });
     $("#t-clear").click(function(){
       $("#t-clear").hide();
-      $("#searchinput").val("").change().focus();
+      $("#searchinput").val("").focus();
+      $("#searchinput").trigger('input');
       //$("#zbSeatchT [name='searchvalue']").val("");
     })
 
@@ -585,11 +586,13 @@
    * 初始化页面搜索框与工作台顶部搜索联动事件函数,详情见对应函数 common.js
    */
   if (goTemplateData.inIframe) {
-    initSearchPageEvent({
-      type: 'bidding',
-      el: '.searchHeader-container .searchInput',
-      inputSelector: '#searchinput',
-      submitSelector: 'input[type="button"]'
+    $(function () {
+      initSearchPageEvent({
+        type: 'bidding',
+        el: '.searchHeader-container .searchInput',
+        inputSelector: '#searchinput',
+        submitSelector: 'input[type="button"]'
+      })
     })
   }
   </script>