Showing
3 changed files
with
138 additions
and
49 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2024-09-26 13:36:06 | 2 | * @Date: 2024-09-26 13:36:06 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-10-25 14:01:25 | 4 | + * @LastEditTime: 2024-10-25 16:49:54 |
| 5 | * @FilePath: /hager/src/api/hager.js | 5 | * @FilePath: /hager/src/api/hager.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -23,6 +23,7 @@ const Api = { | ... | @@ -23,6 +23,7 @@ const Api = { |
| 23 | EDIT_USER: '/srv/?a=user&type=edit_user', | 23 | EDIT_USER: '/srv/?a=user&type=edit_user', |
| 24 | GET_CODE: '/srv/?a=user&type=get_code', | 24 | GET_CODE: '/srv/?a=user&type=get_code', |
| 25 | EDIT_PASSWORD: '/srv/?a=user&type=edit_password', | 25 | EDIT_PASSWORD: '/srv/?a=user&type=edit_password', |
| 26 | + SEARCH: '/srv/?a=search', | ||
| 26 | }; | 27 | }; |
| 27 | 28 | ||
| 28 | export const honorAPI = (params) => fn(fetch.get(Api.HONOR, params)); | 29 | export const honorAPI = (params) => fn(fetch.get(Api.HONOR, params)); |
| ... | @@ -49,3 +50,4 @@ export const getUserInfoAPI = (params) => fn(fetch.get(Api.GET_USER, params)); | ... | @@ -49,3 +50,4 @@ export const getUserInfoAPI = (params) => fn(fetch.get(Api.GET_USER, params)); |
| 49 | export const editUserInfoAPI = (params) => fn(fetch.post(Api.EDIT_USER, params)); | 50 | export const editUserInfoAPI = (params) => fn(fetch.post(Api.EDIT_USER, params)); |
| 50 | export const getCodeAPI = (params) => fn(fetch.post(Api.GET_CODE, params)); | 51 | export const getCodeAPI = (params) => fn(fetch.post(Api.GET_CODE, params)); |
| 51 | export const editPasswordAPI = (params) => fn(fetch.post(Api.EDIT_PASSWORD, params)); | 52 | export const editPasswordAPI = (params) => fn(fetch.post(Api.EDIT_PASSWORD, params)); |
| 53 | +export const searchAPI = (params) => fn(fetch.get(Api.SEARCH, params)); | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2024-09-26 13:42:11 | 2 | * @Date: 2024-09-26 13:42:11 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-10-25 14:21:41 | 4 | + * @LastEditTime: 2024-10-25 16:57:33 |
| 5 | * @FilePath: /hager/src/components/common/hagerHeader.vue | 5 | * @FilePath: /hager/src/components/common/hagerHeader.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -367,7 +367,9 @@ export default { | ... | @@ -367,7 +367,9 @@ export default { |
| 367 | $('body').css('overflow', 'auto'); | 367 | $('body').css('overflow', 'auto'); |
| 368 | }, | 368 | }, |
| 369 | goToSearch () { | 369 | goToSearch () { |
| 370 | - this.updateURL() | 370 | + if (this.keyword) { |
| 371 | + this.updateURL() | ||
| 372 | + } | ||
| 371 | }, | 373 | }, |
| 372 | updateURL() { | 374 | updateURL() { |
| 373 | const currentKeyword = this.$route.query.keyword; | 375 | const currentKeyword = this.$route.query.keyword; | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2024-10-20 16:57:48 | 2 | * @Date: 2024-10-20 16:57:48 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-10-25 15:39:59 | 4 | + * @LastEditTime: 2024-10-25 17:39:23 |
| 5 | * @FilePath: /hager/src/views/search.vue | 5 | * @FilePath: /hager/src/views/search.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -11,30 +11,34 @@ | ... | @@ -11,30 +11,34 @@ |
| 11 | <div class="search-title">与“{{ keyword }}”相关的搜索结果</div> | 11 | <div class="search-title">与“{{ keyword }}”相关的搜索结果</div> |
| 12 | <el-tabs v-model="activeName" @tab-click="handleClick"> | 12 | <el-tabs v-model="activeName" @tab-click="handleClick"> |
| 13 | <el-tab-pane name="product"> | 13 | <el-tab-pane name="product"> |
| 14 | - <div slot="label" class="customer-label">产品 <span>2</span></div> | 14 | + <div slot="label" class="customer-label">产品 <span>{{ count_product }}</span></div> |
| 15 | <div class="search-product-list"> | 15 | <div class="search-product-list"> |
| 16 | <div :class="['search-product-item', is_xs ? 'xs' : '']" v-for="(item, index) in product_list" :key="index"> | 16 | <div :class="['search-product-item', is_xs ? 'xs' : '']" v-for="(item, index) in product_list" :key="index"> |
| 17 | - <div :class="['search-product-item-img', is_xs ? 'xs' : '']" :style="{ 'background-image': 'url('+ item.img +')' }"></div> | 17 | + <div :class="['search-product-item-img', is_xs ? 'xs' : '']" :style="{ 'background-image': 'url('+ item.cover +')' }"></div> |
| 18 | - <p @click="goToDetail(item)" class="search-product-item-title">{{ item.title }}</p> | 18 | + <p @click="goToDetail(item)" class="search-product-item-title">{{ item.product_name }}</p> |
| 19 | </div> | 19 | </div> |
| 20 | </div> | 20 | </div> |
| 21 | <div style="height: 5rem;"></div> | 21 | <div style="height: 5rem;"></div> |
| 22 | </el-tab-pane> | 22 | </el-tab-pane> |
| 23 | <el-tab-pane name="solution"> | 23 | <el-tab-pane name="solution"> |
| 24 | - <div slot="label" class="customer-label">解决方案 <span>3</span></div> | 24 | + <div slot="label" class="customer-label">解决方案 <span>{{ count_solution }}</span></div> |
| 25 | - <div style="margin-top: 1rem;" v-for="(item, index) in news_list" :key="index"> | 25 | + <div style="margin-top: 1rem;" v-for="(item, index) in solution_list" :key="index"> |
| 26 | + <el-breadcrumb separator="/"> | ||
| 27 | + <el-breadcrumb-item>首页</el-breadcrumb-item> | ||
| 28 | + <el-breadcrumb-item>解决方案</el-breadcrumb-item> | ||
| 29 | + </el-breadcrumb> | ||
| 26 | <div :class="['search-news-wrapper', is_xs ? 'xs' : '']"> | 30 | <div :class="['search-news-wrapper', is_xs ? 'xs' : '']"> |
| 27 | - <div class="search-news-title" v-html="highlightKeyword(keyword, item.title)"></div> | 31 | + <div class="search-news-title" v-html="highlightKeyword(keyword, item.solution_name)"></div> |
| 28 | - <div class="search-news-content" v-html="highlightKeyword(keyword, item.content)"></div> | 32 | + <div class="search-news-content" v-html="highlightKeyword(keyword, item.solution_description)"></div> |
| 29 | <div class="search-news-more"> | 33 | <div class="search-news-more"> |
| 30 | - <div class="search-news-more-btn" @click="goTo(item.id)">MORE</div> | 34 | + <div class="search-news-more-btn" @click="goToCase(item.id)">MORE</div> |
| 31 | </div> | 35 | </div> |
| 32 | </div> | 36 | </div> |
| 33 | </div> | 37 | </div> |
| 34 | </el-tab-pane> | 38 | </el-tab-pane> |
| 35 | - <el-tab-pane name="success"> | 39 | + <el-tab-pane name="case"> |
| 36 | - <div slot="label" class="customer-label">成功案例 <span>3</span></div> | 40 | + <div slot="label" class="customer-label">成功案例 <span>{{ count_case }}</span></div> |
| 37 | - <div style="margin-top: 1rem;" v-for="(item, index) in news_list" :key="index"> | 41 | + <div style="margin-top: 1rem;" v-for="(item, index) in case_list" :key="index"> |
| 38 | <div :class="['search-news-wrapper', is_xs ? 'xs' : '']"> | 42 | <div :class="['search-news-wrapper', is_xs ? 'xs' : '']"> |
| 39 | <div class="search-news-title" v-html="highlightKeyword(keyword, item.title)"></div> | 43 | <div class="search-news-title" v-html="highlightKeyword(keyword, item.title)"></div> |
| 40 | <div class="search-news-content" v-html="highlightKeyword(keyword, item.content)"></div> | 44 | <div class="search-news-content" v-html="highlightKeyword(keyword, item.content)"></div> |
| ... | @@ -45,23 +49,29 @@ | ... | @@ -45,23 +49,29 @@ |
| 45 | </div> | 49 | </div> |
| 46 | </el-tab-pane> | 50 | </el-tab-pane> |
| 47 | <el-tab-pane name="news"> | 51 | <el-tab-pane name="news"> |
| 48 | - <div slot="label" class="customer-label">新闻 <span>3</span></div> | 52 | + <div slot="label" class="customer-label">新闻 <span>{{ count_news }}</span></div> |
| 49 | <div style="margin-top: 1rem;" v-for="(item, index) in news_list" :key="index"> | 53 | <div style="margin-top: 1rem;" v-for="(item, index) in news_list" :key="index"> |
| 50 | - <!-- <el-breadcrumb separator="/"> | 54 | + <el-breadcrumb separator="/"> |
| 51 | <el-breadcrumb-item>首页</el-breadcrumb-item> | 55 | <el-breadcrumb-item>首页</el-breadcrumb-item> |
| 52 | <el-breadcrumb-item>新闻中心</el-breadcrumb-item> | 56 | <el-breadcrumb-item>新闻中心</el-breadcrumb-item> |
| 53 | - </el-breadcrumb> --> | 57 | + </el-breadcrumb> |
| 54 | <div :class="['search-news-wrapper', is_xs ? 'xs' : '']"> | 58 | <div :class="['search-news-wrapper', is_xs ? 'xs' : '']"> |
| 55 | - <div class="search-news-title" v-html="highlightKeyword(keyword, item.title)"></div> | 59 | + <div class="search-news-title" v-html="highlightKeyword(keyword, item.post_title)"></div> |
| 56 | - <div class="search-news-content" v-html="highlightKeyword(keyword, item.content)"></div> | 60 | + <div class="search-news-content" v-html="highlightKeyword(keyword, item.post_excerpt)"></div> |
| 57 | <div class="search-news-more"> | 61 | <div class="search-news-more"> |
| 58 | - <div class="search-news-more-btn" @click="goTo(item.id)">MORE</div> | 62 | + <div class="search-news-more-btn" @click="goToNews(item.id)">MORE</div> |
| 59 | </div> | 63 | </div> |
| 60 | </div> | 64 | </div> |
| 61 | </div> | 65 | </div> |
| 62 | </el-tab-pane> | 66 | </el-tab-pane> |
| 63 | </el-tabs> | 67 | </el-tabs> |
| 64 | </hager-box> | 68 | </hager-box> |
| 69 | + <hager-box v-if="activeName === 'news'"> | ||
| 70 | + <hager-load-more v-if="news_page <= news_max_page" @click.native="getMore"></hager-load-more> | ||
| 71 | + </hager-box> | ||
| 72 | + <hager-box v-if="activeName === 'case'"> | ||
| 73 | + <hager-load-more v-if="case_page <= case_max_page" @click.native="getMore"></hager-load-more> | ||
| 74 | + </hager-box> | ||
| 65 | </div> | 75 | </div> |
| 66 | </template> | 76 | </template> |
| 67 | 77 | ||
| ... | @@ -70,6 +80,8 @@ import mixin from 'common/mixin'; | ... | @@ -70,6 +80,8 @@ import mixin from 'common/mixin'; |
| 70 | import hagerBox from '@/components/common/hagerBox'; | 80 | import hagerBox from '@/components/common/hagerBox'; |
| 71 | import $ from 'jquery'; | 81 | import $ from 'jquery'; |
| 72 | import objectFitImages from 'object-fit-images'; | 82 | import objectFitImages from 'object-fit-images'; |
| 83 | +import { searchAPI } from '@/api/hager'; | ||
| 84 | +import hagerLoadMore from '@/components/hagerLoadMore.vue'; | ||
| 73 | 85 | ||
| 74 | export default { | 86 | export default { |
| 75 | components: { hagerBox }, | 87 | components: { hagerBox }, |
| ... | @@ -78,37 +90,29 @@ export default { | ... | @@ -78,37 +90,29 @@ export default { |
| 78 | return { | 90 | return { |
| 79 | activeName: 'product', | 91 | activeName: 'product', |
| 80 | keyword: this.$route.query.keyword, | 92 | keyword: this.$route.query.keyword, |
| 81 | - news_list: [{ | 93 | + news_list: [], |
| 82 | - id: '123', | 94 | + case_list: [], |
| 83 | - title: '海格电气全新智能型hw+空气断路器重磅上市', | 95 | + count_news: 0, |
| 84 | - content: '11 月 24 日,海格电气在惠州举办了 2023 海格匠心之旅暨 hw+ 全系列新品发布会,面向中国市场正式推出了全新一代智能型 hw+ 空气断路器。海格电气管理层及员工代表,行业客户及合作伙伴等齐聚惠州工厂,共同见证海格电气新一代', | 96 | + count_case: 0, |
| 85 | - }, { | 97 | + count_product: 0, |
| 86 | - id: '456', | 98 | + count_solution: 0, |
| 87 | - title: '里程碑时刻!海格电气首台全新一代HW+空气断路器', | 99 | + product_list: [], |
| 88 | - content: '全新一代HW+空气断路器的整机下线,标志着海格电气在低压配电领域的进一步技术升级。作为海格电气在中国市场重磅推出的里程碑式产品,全新一代HW+空气断路器为大型建筑复杂、高负荷的用电需求提供高质量解决方案。', | 100 | + solution_list: [], |
| 89 | - }], | 101 | + news_page: 1, |
| 90 | - product_list: [{ | 102 | + case_page: 1, |
| 91 | - id: '', | 103 | + limit: 10, |
| 92 | - img: 'https://cdn.ipadbiz.cn/hager/img/product/t01.jpg', | 104 | + news_max_page: 0, |
| 93 | - title: 'acb hw 空气断路器' | 105 | + case_max_page: 0, |
| 94 | - }, { | ||
| 95 | - id: '', | ||
| 96 | - img: 'https://cdn.ipadbiz.cn/hager/img/product/t01.jpg', | ||
| 97 | - title: 'acb hw 空气断路器' | ||
| 98 | - }, { | ||
| 99 | - id: '', | ||
| 100 | - img: 'https://cdn.ipadbiz.cn/hager/img/product/t01.jpg', | ||
| 101 | - title: 'acb hw 空气断路器' | ||
| 102 | - }], | ||
| 103 | - is_end: false | ||
| 104 | } | 106 | } |
| 105 | }, | 107 | }, |
| 106 | watch: { | 108 | watch: { |
| 107 | '$route.query.keyword': function(newKeyword) { | 109 | '$route.query.keyword': function(newKeyword) { |
| 108 | this.keyword = newKeyword || ''; | 110 | this.keyword = newKeyword || ''; |
| 111 | + this.getList(); | ||
| 109 | }, | 112 | }, |
| 110 | }, | 113 | }, |
| 111 | - mounted () { | 114 | + async mounted () { |
| 115 | + this.getList(); | ||
| 112 | objectFitImages(this.$el); // 对当前组件的 DOM 元素应用 | 116 | objectFitImages(this.$el); // 对当前组件的 DOM 元素应用 |
| 113 | if (this.is_xs) { // 自适应模式下,左右箭头的颜色修改 | 117 | if (this.is_xs) { // 自适应模式下,左右箭头的颜色修改 |
| 114 | this.modifyTabColor(); | 118 | this.modifyTabColor(); |
| ... | @@ -137,19 +141,84 @@ export default { | ... | @@ -137,19 +141,84 @@ export default { |
| 137 | }, 100); | 141 | }, 100); |
| 138 | }) | 142 | }) |
| 139 | }, | 143 | }, |
| 144 | + async getList () { | ||
| 145 | + const { code, data } = await searchAPI({ keyword: this.keyword }); | ||
| 146 | + if (code) { | ||
| 147 | + this.count_news = data.count_news; | ||
| 148 | + this.count_case = data.count_case; | ||
| 149 | + this.count_product = data.count_product; | ||
| 150 | + this.count_solution = data.count_solution; | ||
| 151 | + this.product_list = data.product; | ||
| 152 | + this.solution_list = data.solution; | ||
| 153 | + } | ||
| 154 | + }, | ||
| 155 | + async getNewsList (type = '', page) { | ||
| 156 | + const { code, data } = await searchAPI({ keyword: this.keyword, type, page, limit: this.limit }); | ||
| 157 | + if (code) { | ||
| 158 | + this.news_list = data.list; | ||
| 159 | + this.news_max_page = data.max_page; | ||
| 160 | + } | ||
| 161 | + }, | ||
| 162 | + async getCaseList (type = '', page) { | ||
| 163 | + const { code, data } = await searchAPI({ keyword: this.keyword, type, page, limit: this.limit }); | ||
| 164 | + if (code) { | ||
| 165 | + this.case_list = data.list; | ||
| 166 | + this.case_max_page = data.max_page; | ||
| 167 | + } | ||
| 168 | + }, | ||
| 169 | + async getMoreNewsList (type = '', page) { | ||
| 170 | + const { code, data } = await searchAPI({ keyword: this.keyword, type, page, limit: this.limit }); | ||
| 171 | + if (code) { | ||
| 172 | + this.news_list = this.news_list.concat(data.list); | ||
| 173 | + } | ||
| 174 | + }, | ||
| 175 | + async getMoreCaseList (type = '', page) { | ||
| 176 | + const { code, data } = await searchAPI({ keyword: this.keyword, type, page, limit: this.limit }); | ||
| 177 | + if (code) { | ||
| 178 | + this.case_list = this.case_list.concat(data.list); | ||
| 179 | + } | ||
| 180 | + }, | ||
| 140 | handleClick(tab, event) { | 181 | handleClick(tab, event) { |
| 141 | - console.log(tab, event); | 182 | + switch (tab.name) { |
| 183 | + case 'product': | ||
| 184 | + this.getList(); | ||
| 185 | + break; | ||
| 186 | + case 'case': | ||
| 187 | + this.getList(); | ||
| 188 | + break; | ||
| 189 | + case 'case': | ||
| 190 | + this.case_page = 1; | ||
| 191 | + this.case_max_page = 0; | ||
| 192 | + this.getCaseList(tab.name, this.case_page); | ||
| 193 | + break; | ||
| 194 | + case 'news': | ||
| 195 | + this.news_page = 1; | ||
| 196 | + this.news_max_page = 0; | ||
| 197 | + this.getNewsList(tab.name, this.news_page); | ||
| 198 | + break; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + }, | ||
| 202 | + getMore () { | ||
| 203 | + if (this.activeName === 'case') { | ||
| 204 | + this.case_page += 1; | ||
| 205 | + this.getMoreCaseList(this.activeName, this.case_page); | ||
| 206 | + } | ||
| 207 | + if (this.activeName === 'news') { | ||
| 208 | + this.news_page += 1; | ||
| 209 | + this.getMoreNewsList(this.activeName, this.news_page); | ||
| 210 | + } | ||
| 142 | }, | 211 | }, |
| 143 | highlightKeyword (keyword, text) { | 212 | highlightKeyword (keyword, text) { |
| 144 | // 创建一个正则表达式来查找关键词 | 213 | // 创建一个正则表达式来查找关键词 |
| 145 | var regex = new RegExp(`(${keyword})`, 'gi'); | 214 | var regex = new RegExp(`(${keyword})`, 'gi'); |
| 146 | 215 | ||
| 147 | // 用 <span> 标签替换匹配到的关键词并加上高亮类 | 216 | // 用 <span> 标签替换匹配到的关键词并加上高亮类 |
| 148 | - var highlightedText = text.replace(regex, '<span style="color: #00ABE5;">$1</span>'); | 217 | + var highlightedText = text?.replace(regex, '<span style="color: #00ABE5;">$1</span>'); |
| 149 | 218 | ||
| 150 | return highlightedText; | 219 | return highlightedText; |
| 151 | }, | 220 | }, |
| 152 | - goTo (id) { | 221 | + goToNews (id) { |
| 153 | this.$router.push({ | 222 | this.$router.push({ |
| 154 | path: '/news/detail', | 223 | path: '/news/detail', |
| 155 | query: { | 224 | query: { |
| ... | @@ -164,6 +233,22 @@ export default { | ... | @@ -164,6 +233,22 @@ export default { |
| 164 | id: v.id | 233 | id: v.id |
| 165 | } | 234 | } |
| 166 | }); | 235 | }); |
| 236 | + }, | ||
| 237 | + goToCase (id) { | ||
| 238 | + this.$router.push({ | ||
| 239 | + path: '/solution/detail', | ||
| 240 | + query: { | ||
| 241 | + id: id | ||
| 242 | + } | ||
| 243 | + }); | ||
| 244 | + }, | ||
| 245 | + goToSolution (v) { // 跳转产品详情 | ||
| 246 | + this.$router.push({ | ||
| 247 | + path: '/product/detail', | ||
| 248 | + query: { | ||
| 249 | + id: v.id | ||
| 250 | + } | ||
| 251 | + }); | ||
| 167 | } | 252 | } |
| 168 | } | 253 | } |
| 169 | } | 254 | } |
| ... | @@ -225,8 +310,8 @@ export default { | ... | @@ -225,8 +310,8 @@ export default { |
| 225 | 310 | ||
| 226 | .search-news-wrapper { | 311 | .search-news-wrapper { |
| 227 | margin: 1.5rem 0; | 312 | margin: 1.5rem 0; |
| 313 | + border-bottom: 1px solid #ECECEC; | ||
| 228 | &.xs { | 314 | &.xs { |
| 229 | - border-bottom: 1px solid #ECECEC; | ||
| 230 | } | 315 | } |
| 231 | .search-news-title { | 316 | .search-news-title { |
| 232 | font-size: 1.15rem; | 317 | font-size: 1.15rem; | ... | ... |
-
Please register or login to post a comment