|
@@ -858,11 +858,6 @@ function isElementVisible (el) {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * searchHeader-container searchInput
|
|
|
- * search-header-top input-container
|
|
|
- */
|
|
|
-
|
|
|
/**
|
|
|
* 适用于快速集成不同搜索页面与顶部导航搜索模块的通信
|
|
|
* 1. 监听容器 scroll 事件,更新顶部搜索可见状态
|
|
@@ -871,18 +866,62 @@ function isElementVisible (el) {
|
|
|
* 4. 监听顶部搜索 submit 事件,执行传递的页面 submit 函数
|
|
|
* 5. 监听 window.onbeforeunload 事件,销毁上述事件监听
|
|
|
* 6. 返回 { off: fn } 提供手动 off 函数,用于手动销毁上述事件监听
|
|
|
+ * 7. 初始化时自动触发 change, scroll 事件更新状态
|
|
|
+ *
|
|
|
+ * // 对应支持的搜索类型
|
|
|
+ * types: [
|
|
|
+ * {
|
|
|
+ * label: '招标采购搜索',
|
|
|
+ * key: 'bidding',
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * label: '企业搜索',
|
|
|
+ * key: 'company'
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * label: '采购单位搜索',
|
|
|
+ * key: 'buyer'
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * label: '供应搜索',
|
|
|
+ * key: 'supplier'
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
* @param config
|
|
|
- * @param config.el - 当前页面 input 搜索框容器
|
|
|
+ * @param config.el - 当前页面 input 搜索框的父容器
|
|
|
+ * @param config.type - 当前页面搜索类型, 对应 key 见上方类型
|
|
|
* @param config.submit - 用于实现当前页面搜索事件函数
|
|
|
+ * @param config.inputSelector - 用于实现当前页面搜索 input 输入框选择器特殊处理,默认 input
|
|
|
+ * @param config.submitSelector - 用于实现当前页面搜索提交按钮选择器特殊处理,默认 button
|
|
|
* @returns {{off: off}}
|
|
|
*/
|
|
|
function initSearchPageEvent (config) {
|
|
|
// el 对应容器 submit 自定义提交函数
|
|
|
var el = config.el
|
|
|
- var submit = config.submit
|
|
|
+ var inputSelector = config.inputSelector || 'input'
|
|
|
+ var submitSelector = config.submitSelector || 'button'
|
|
|
+ // 默认提交函数处理,仅处理相同 type
|
|
|
+ var searchType = config.type || ''
|
|
|
+ var submit = function (item, next) {
|
|
|
+ if (item.type === searchType) {
|
|
|
+ return triggerFormSubmit()
|
|
|
+ } else {
|
|
|
+ return next(item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (typeof config.submit === 'function') {
|
|
|
+ submit = config.submit
|
|
|
+ }
|
|
|
|
|
|
// 需要的工具函数集
|
|
|
|
|
|
+ /**
|
|
|
+ * 触发原表单提交按钮点击事件
|
|
|
+ */
|
|
|
+ function triggerFormSubmit () {
|
|
|
+ $(el).find(submitSelector).trigger('click')
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 返回当前容器可见状态
|
|
|
* @returns {boolean}
|
|
@@ -906,7 +945,7 @@ function initSearchPageEvent (config) {
|
|
|
$BRACE.$emit('nav-search', {
|
|
|
type: 'change',
|
|
|
params: {
|
|
|
- show: getElementVisible()
|
|
|
+ show: !getElementVisible()
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -943,10 +982,12 @@ function initSearchPageEvent (config) {
|
|
|
|
|
|
// 绑定滚动事件,切换顶部搜索模块展示
|
|
|
$(window).on('scroll', checkShowSearchModule)
|
|
|
+ checkShowSearchModule()
|
|
|
|
|
|
// 绑定输入事件,通过钩子更新同步搜索 input 值
|
|
|
- var inputEl = $(el).find('input')
|
|
|
+ var inputEl = $(el).find(inputSelector)
|
|
|
$(inputEl).on('input', onChangeInput)
|
|
|
+ $(inputEl).trigger('input')
|
|
|
|
|
|
// 绑定提交事件,接手 submit 提交事件
|
|
|
if (typeof submit === 'function') {
|