search.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <template>
  2. <view class="search-container container">
  3. <view class="sticky-content">
  4. <view class="searchTarget-header">
  5. <input type="text" placeholder="请输入关键字" placeholder-class="sea_ipt_placeholder" class="sea_ipt" v-model="searchTxt" focus="true" confirm-type="search" @confirm="searchHandle" />
  6. <icon type="search" size="15" class="sea_ico" />
  7. <view class="ipt-right">
  8. <icon type="clear" size="16" color="#E0E0E0" v-show="searchTxt" @click="clearIpt" />
  9. <text class="line">|</text>
  10. <text @click="searchHandle" style="color: #3385ff">搜索</text>
  11. </view>
  12. </view>
  13. <view class="radio-content">
  14. <van-radio-group :value="radioSelect" @change="onChangeRadio" direction="horizontal">
  15. <van-radio icon-size="16" name="1">搜全部</van-radio>
  16. <van-radio icon-size="16" name="2">搜纪要</van-radio>
  17. <van-radio icon-size="16" name="3">搜图表</van-radio>
  18. </van-radio-group>
  19. </view>
  20. <view class="tab-cont" v-if="radioSelect == 2 && isResult">
  21. <view :class="['item', item.mode == orderColumn && 'tabs-active text_twoLine']" v-for="item in tabBars" :key="item.mode" @click.stop="toggleTab(item)">
  22. {{ item.PermissionName }}
  23. <view class="active" v-if="orderColumn === item.mode"></view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="search-cont" v-if="!isResult">
  28. <view class="search-cont-top">
  29. <view class="cont-tit">
  30. <text>热搜关键词:</text>
  31. </view>
  32. <view class="targetList">
  33. <view class="target-item" v-for="(item, index) in hotKeyWord" :key="index" @click="chooseTarget(item.KeyWord)"># {{ item.KeyWord }}</view>
  34. </view>
  35. </view>
  36. <view class="search-cont-top">
  37. <view class="cont-tit">
  38. <text>推荐关键词:</text>
  39. </view>
  40. <view class="targetList">
  41. <view class="target-item" v-for="(item, index) in keywordList" :key="index" @click="chooseTarget(item)"># {{ item }}</view>
  42. <view class="chart-item" v-for="(item, index) in chartWordList" :key="index" @click="chooseTarget(item.KeyWord)"># {{ item.KeyWord }}</view>
  43. </view>
  44. </view>
  45. <view class="search-cont-top" v-if="historySearchList.length">
  46. <view class="cont-tit">
  47. <text>搜索历史:</text>
  48. <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/empty_ico.png" class="empty_ico" @click="clearHistory"></image>
  49. </view>
  50. <view class="targetList">
  51. <block v-for="(item, index) in historySearchList" :key="index">
  52. <view v-if="index < 8" class="target-item" @click="chooseTarget(item)"># {{ item }}</view>
  53. </block>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 内容地方 -->
  58. <view class="search-cont" v-else>
  59. <block v-if="haveResult">
  60. <view class="result-data">
  61. <view class="report-ul">
  62. <view class="report-item" v-for="(report, index) in resultList" :key="index" v-if="index % 2 === 0" @click="goDetail(report)">
  63. <view class="item-content-img" v-if="report.BodyHtml">
  64. <image :src="report.BodyHtml" mode=""></image>
  65. </view>
  66. <view class="item-content" v-else><u-parse :html="report.Body[0] + '...'"></u-parse></view>
  67. <view class="line"></view>
  68. <view :class="['item-title', report.Source != 1 && 'chart-title text_twoLine']"><u-parse :html="report.Title"></u-parse></view>
  69. <text class="item-createtime" v-if="report.Source == 1">{{ report.PublishDate }}</text>
  70. <view class="item-createtime chart-tag" v-else>
  71. <text class="tag-item" v-if="report.PtagName">{{ report.PtagName }}</text>
  72. <text class="tag-item" v-if="report.CtagName">{{ report.CtagName }}</text>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="report-ul">
  77. <view class="report-item" v-for="(report, index) in resultList" :key="index" v-if="index % 2 !== 0" @click="goDetail(report)">
  78. <view class="item-content-img" v-if="report.BodyHtml">
  79. <image :src="report.BodyHtml" mode=""></image>
  80. </view>
  81. <view class="item-content" v-else><u-parse :html="report.Body[0] + '...'"></u-parse></view>
  82. <view class="line"></view>
  83. <view :class="['item-title', report.Source != 1 && 'chart-title text_twoLine']"><u-parse :html="report.Title"></u-parse></view>
  84. <text class="item-createtime" v-if="report.Source == 1">{{ report.PublishDate }}</text>
  85. <view class="item-createtime chart-tag" v-else>
  86. <text class="tag-item" v-if="report.PtagName">{{ report.PtagName }}</text>
  87. <text class="tag-item" v-if="report.CtagName">{{ report.CtagName }}</text>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. <u-loadmore :status="status" icon-type="flower" :load-text="loadText" margin-top="20" v-if="pageNum > 1" />
  93. </block>
  94. <view class="nodata" v-else>
  95. <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" mode="" class="nodata_ico"></image>
  96. <text>未找到您想搜索的内容</text>
  97. </view>
  98. </view>
  99. </view>
  100. </template>
  101. <script>
  102. import { Search } from "@/config/api.js";
  103. import { Debounce, Throttle } from "@/config/util.js";
  104. let app = getApp({ allowDefault: true });
  105. export default {
  106. data() {
  107. return {
  108. searchTxt: "", //搜索关键字
  109. isResult: false, //显示搜索结果
  110. haveResult: true, //是否有搜索数据
  111. // 历史搜索列表
  112. historySearchList: [],
  113. // 关键字列表
  114. keywordList: [],
  115. chartWordList: [],
  116. // 搜索结果列表
  117. resultList: [],
  118. resultDataList: [],
  119. indList: [],
  120. pageNum: 1,
  121. pageSize: 10,
  122. totalPage: 0,
  123. hotKeyWord: [],
  124. radioSelect: "1",
  125. tabBars: [
  126. {
  127. PermissionName: "匹配度排序",
  128. mode: "Matching",
  129. },
  130. {
  131. PermissionName: "综合排序",
  132. mode: "Comprehensive",
  133. },
  134. {
  135. PermissionName: "发布时间排序",
  136. mode: "PublishDate",
  137. },
  138. ],
  139. orderColumn: "Matching",
  140. status: "loadmore",
  141. loadText: {
  142. loadmore: "上拉加载更多",
  143. loading: "加载中",
  144. nomore: "已经到底了",
  145. },
  146. };
  147. },
  148. watch: {
  149. searchTxt(newVal) {
  150. if (newVal.length <= 0) {
  151. this.isResult = false;
  152. this.orderColumn = "Matching";
  153. }
  154. },
  155. },
  156. methods: {
  157. //获取热搜关键词的请求
  158. async researchHotKeyWord() {
  159. const res = await Search.getKeys();
  160. if (res.Ret === 200) {
  161. this.hotKeyWord = res.Data.ListHot || [];
  162. this.chartWordList = res.Data.List || [];
  163. this.keywordList = res.Data.Item ? res.Data.Item.ConfigValue.split(",") : [];
  164. }
  165. },
  166. //点击了搜索的变化
  167. onChangeRadio(value) {
  168. this.radioSelect = value.detail;
  169. this.orderColumn = "Matching";
  170. let srt = this.searchTxt.replace(/^\s+|\s+$/g, "");
  171. if (!srt) return this.$util.toast("请输入关键字");
  172. this.dataInit();
  173. this.getDataList();
  174. },
  175. /* 获取关键词 */
  176. getKeyWord() {
  177. Search.getKeys().then((res) => {
  178. if (res.Ret === 200) {
  179. this.keywordList = res.Data.Item.ConfigValue ? res.Data.Item.ConfigValue.split(",") : [];
  180. }
  181. });
  182. },
  183. // 选择历史搜索
  184. chooseTarget(item) {
  185. this.searchTxt = item;
  186. this.SecName = item;
  187. this.dataInit();
  188. this.indList = [];
  189. if (!this.historySearchList.includes(this.searchTxt)) {
  190. this.historySearchList.unshift(this.searchTxt);
  191. this.$db.set("historySearchList", JSON.stringify(this.historySearchList));
  192. }
  193. this.getDataList();
  194. },
  195. // 拼接
  196. join(str, key) {
  197. return str.replace(new RegExp(`${key}`, "g"), `%%${key}%%`).split("%%");
  198. },
  199. // 搜索数据
  200. searchHandle: Debounce(function () {
  201. if (this.searchTxt) {
  202. //添加搜索记录
  203. if (!this.historySearchList.includes(this.searchTxt)) {
  204. this.historySearchList.unshift(this.searchTxt);
  205. this.$db.set("historySearchList", JSON.stringify(this.historySearchList));
  206. }
  207. this.indList = [];
  208. this.dataInit();
  209. this.getDataList();
  210. } else {
  211. this.$util.toast("请输入关键字");
  212. }
  213. }),
  214. // 查找数据
  215. async getDataList() {
  216. this.isResult = true;
  217. const res = await Search.getArtAndChartList({
  218. KeyWord: this.searchTxt.replace(/^\s+|\s+$/g, ""),
  219. OrderColumn: this.radioSelect == 2 ? this.orderColumn : "",
  220. ListType: this.radioSelect,
  221. });
  222. if (res.Ret === 200) {
  223. this.totalPage = res.Data.Paging.Totals;
  224. if (this.radioSelect == 1) {
  225. if (!res.Data.List.length) {
  226. this.resultDataList = res.Data.ChartList || [];
  227. } else if (!res.Data.ChartList.length) {
  228. this.resultDataList = res.Data.List || [];
  229. } else {
  230. this.resultDataList.push(res.Data.List.shift());
  231. let newArr = [];
  232. let newArrTwo = [];
  233. for (let i = 0; i < res.Data.List.length; i += 2) {
  234. newArr.push(res.Data.List.slice(i, i + 2));
  235. }
  236. for (let i = 0; i < res.Data.ChartList.length; i += 2) {
  237. newArrTwo.push(res.Data.ChartList.slice(i, i + 2));
  238. }
  239. let arr = [];
  240. newArr.forEach((item, index) => {
  241. if (newArrTwo[index]) {
  242. arr.push(newArrTwo[index], item);
  243. } else {
  244. arr.push(item);
  245. }
  246. });
  247. this.resultDataList = this.resultDataList.concat(arr.flat(Infinity));
  248. }
  249. this.haveResult = this.resultDataList.length ? true : false;
  250. } else if (this.radioSelect == 2) {
  251. this.resultDataList = res.Data.List || [];
  252. this.haveResult = this.resultDataList.length ? true : false;
  253. } else {
  254. this.resultDataList = res.Data.ChartList || [];
  255. this.haveResult = this.resultDataList.length ? true : false;
  256. }
  257. this.resultList = this.haveResult ? this.resultDataList.slice((this.pageNum - 1) * this.pageSize, this.pageNum * this.pageSize) : [];
  258. }
  259. },
  260. /* 表单清空 */
  261. clearIpt() {
  262. this.searchTxt = "";
  263. this.dataInit();
  264. this.isTabAct = false;
  265. },
  266. /* 进入详情 校验是否有该品种权限 */
  267. goDetail(item) {
  268. if (item.Source == 2) {
  269. /* 无需授权且已绑定 检验是或否有权限 */
  270. this.$store.dispatch("checkHandle", "/pageMy/chartPage/chartPage?id=" + item.ChartId);
  271. } else {
  272. /* 无需授权且已绑定 检验是或否有权限 */
  273. this.$store.dispatch("checkHandle", "/pageMy/reportDetail/reportDetail?id=" + item.ArticleId);
  274. }
  275. },
  276. /* 历史搜索清空 */
  277. clearHistory() {
  278. this.historySearchList = [];
  279. this.$db.del("historySearchList");
  280. },
  281. //获取数据的初始值
  282. dataInit() {
  283. this.pageNum = 1;
  284. this.resultList = [];
  285. this.resultDataList = [];
  286. this.status = "loadmore";
  287. uni.pageScrollTo({
  288. scrollTop: 0,
  289. duration: 0,
  290. });
  291. },
  292. //tabs切换事件
  293. toggleTab(item) {
  294. this.orderColumn = item.mode;
  295. this.pageNum = 1;
  296. uni.pageScrollTo({
  297. scrollTop: 0,
  298. duration: 0,
  299. });
  300. this.resultList = [];
  301. this.getDataList();
  302. uni.pageScrollTo({
  303. scrollTop: 0,
  304. duration: 0,
  305. });
  306. },
  307. },
  308. onLoad(options) {
  309. if (options.text) {
  310. this.searchTxt = options.text;
  311. this.getDataList();
  312. }
  313. // 获取历史搜索记录
  314. if (this.$db.get("historySearchList")) {
  315. let historyList = JSON.parse(this.$db.get("historySearchList"));
  316. this.historySearchList = historyList;
  317. }
  318. },
  319. onShow() {
  320. this.$store.dispatch("statistics", { PageType: "SummarySearch" });
  321. this.getKeyWord();
  322. this.researchHotKeyWord();
  323. },
  324. // 上拉加载this.resultList
  325. onReachBottom: Throttle(function () {
  326. if (!this.resultList.length) return;
  327. if (this.status === "nomore") return;
  328. this.status = "loading";
  329. this.pageNum++;
  330. this.resultList = this.resultList.concat(this.resultDataList.slice((this.pageNum - 1) * this.pageSize, this.pageNum * this.pageSize));
  331. this.status = this.pageNum * 10 < this.totalPage ? "loadmore" : "nomore";
  332. }),
  333. };
  334. </script>
  335. <style lang="scss">
  336. .search-container {
  337. background-color: #fff;
  338. padding-bottom: 30rpx;
  339. .sticky-content {
  340. position: sticky;
  341. top: 0;
  342. left: 0;
  343. width: 100%;
  344. z-index: 99;
  345. padding-bottom: 10rpx;
  346. background-color: #fff;
  347. }
  348. .searchTarget-header {
  349. padding: 0 34rpx;
  350. width: 100%;
  351. position: relative;
  352. padding: 30rpx 0;
  353. display: flex;
  354. justify-content: center;
  355. align-items: center;
  356. .sea_ipt_placeholder {
  357. color: #8d8d8d;
  358. }
  359. .sea_ipt {
  360. width: 682rpx;
  361. height: 70rpx;
  362. line-height: 70rpx;
  363. box-sizing: border-box;
  364. border: 1rpx solid #e5e5e5;
  365. background-color: rgba(245, 245, 245, 0.2);
  366. font-size: 26rpx;
  367. color: #4a4a4a;
  368. padding: 0 180rpx 0 78rpx;
  369. border-radius: 70rpx;
  370. }
  371. .sea_ico {
  372. width: 31rpx;
  373. height: 31rpx;
  374. position: absolute;
  375. left: 68rpx;
  376. top: 50%;
  377. transform: translateY(-50%);
  378. }
  379. .ipt-right {
  380. display: flex;
  381. align-items: center;
  382. position: absolute;
  383. right: 59rpx;
  384. top: 50%;
  385. transform: translateY(-50%);
  386. color: #3385ff;
  387. .line {
  388. margin: 0 21rpx;
  389. color: #e0e0e0;
  390. }
  391. }
  392. }
  393. .radio-content {
  394. width: 100%;
  395. padding-left: 58rpx;
  396. background-color: #fff;
  397. display: flex;
  398. }
  399. .search-cont {
  400. .search-cont-top {
  401. padding: 0 34rpx 0;
  402. margin-bottom: 10rpx;
  403. padding-top: 20rpx;
  404. &:last-child {
  405. margin-bottom: 0;
  406. }
  407. .cont-tit {
  408. font-size: 32rpx;
  409. margin-bottom: 20rpx;
  410. font-weight: 500;
  411. display: flex;
  412. justify-content: space-between;
  413. .empty_ico {
  414. width: 32rpx;
  415. height: 33rpx;
  416. }
  417. }
  418. .targetList {
  419. display: flex;
  420. flex-wrap: wrap;
  421. font-size: 28rpx;
  422. .target-item {
  423. width: 50%;
  424. margin-bottom: 20rpx;
  425. }
  426. .chart-item {
  427. width: 100%;
  428. margin-bottom: 20rpx;
  429. }
  430. }
  431. }
  432. .result-cont {
  433. padding: 0 34rpx 0;
  434. padding-left: 21rpx;
  435. .result-list {
  436. display: flex;
  437. align-items: center;
  438. color: #333;
  439. padding-bottom: 30rpx;
  440. border-bottom: 1rpx solid #ebedf0;
  441. margin-bottom: 30rpx;
  442. .result_ico {
  443. width: 28rpx;
  444. height: 28rpx;
  445. margin-right: 20rpx;
  446. }
  447. text {
  448. display: inline;
  449. }
  450. .highlight {
  451. color: #3385ff;
  452. }
  453. }
  454. }
  455. .result-data {
  456. min-height: calc(100vh - 130rpx);
  457. padding: 20rpx 34rpx 40rpx;
  458. display: flex;
  459. background-color: #f7f7f7;
  460. .report-ul {
  461. width: 50%;
  462. &:first-child {
  463. margin-right: 10rpx;
  464. }
  465. .report-item {
  466. padding: 20rpx 20rpx 24rpx 20rpx;
  467. margin-bottom: 20rpx;
  468. border-radius: 8rpx;
  469. box-shadow: 0 3rpx 6rpx rgba($color: #000000, $alpha: 0.16);
  470. background: #fff;
  471. .item-content {
  472. font-size: 24rpx;
  473. line-height: 40rpx;
  474. color: #7f7f7f;
  475. display: -webkit-box;
  476. word-break: break-all;
  477. text {
  478. display: inline;
  479. }
  480. }
  481. .line {
  482. margin: 18rpx 0;
  483. content: "";
  484. width: 100%;
  485. height: 1px;
  486. padding: 0 32rpx;
  487. box-sizing: border-box;
  488. background-color: #e5e5e5;
  489. -webkit-transform: scale(1, 0.5);
  490. transform: scale(1, 0.5);
  491. -webkit-transform-origin: center bottom;
  492. transform-origin: center bottom;
  493. }
  494. .item-title {
  495. font-size: 28rpx;
  496. color: #4a4a4a;
  497. margin-bottom: 10rpx;
  498. position: relative;
  499. text-indent: 0.5em;
  500. &::before {
  501. content: "";
  502. position: absolute;
  503. top: 5rpx;
  504. left: 0;
  505. width: 6rpx;
  506. height: 31rpx;
  507. background-color: #3385ff;
  508. }
  509. text {
  510. display: inline;
  511. }
  512. }
  513. .chart-title {
  514. height: 72rpx;
  515. padding-bottom: 10rpx;
  516. text-indent: 0em;
  517. &::before {
  518. display: none;
  519. }
  520. }
  521. .item-abstract {
  522. font-size: 26rpx;
  523. color: #6a6a6a;
  524. margin-bottom: 10rpx;
  525. .report_ico {
  526. width: 32rpx;
  527. height: 26rpx;
  528. margin-right: 20rpx;
  529. display: inline-block;
  530. }
  531. }
  532. .item-createtime {
  533. color: #acacac;
  534. font-size: 24rpx;
  535. }
  536. }
  537. }
  538. .chart-tag {
  539. display: flex;
  540. align-items: center;
  541. justify-content: space-between;
  542. padding-top: 1rpx;
  543. height: 36rpx;
  544. .tag-item {
  545. width: 148rpx;
  546. border-radius: 28rpx;
  547. border: 2rpx solid rgba(49, 137, 255, 1);
  548. overflow: hidden;
  549. color: #3385ff;
  550. text-align: center;
  551. line-height: 32rpx;
  552. }
  553. }
  554. .item-content-img {
  555. display: flex;
  556. align-items: center;
  557. width: 330rpx;
  558. margin-left: -15rpx;
  559. margin-bottom: -20rpx;
  560. image {
  561. width: 100%;
  562. height: 262rpx;
  563. vertical-align: middle;
  564. }
  565. }
  566. }
  567. }
  568. .tab-cont {
  569. width: 100%;
  570. display: flex;
  571. align-items: center;
  572. padding: 20rpx 30rpx 0;
  573. font-size: 32rpx;
  574. &::-webkit-scrollbar {
  575. width: 0;
  576. height: 0;
  577. display: none;
  578. }
  579. .item {
  580. position: relative;
  581. padding-bottom: 16rpx;
  582. margin-right: 50rpx;
  583. flex-shrink: 0;
  584. .active {
  585. position: absolute;
  586. left: 0;
  587. bottom: 0;
  588. height: 4rpx;
  589. width: 100%;
  590. border-radius: 2rpx;
  591. font-weight: 500;
  592. background: linear-gradient(90deg, #2e85ff 0%, #7eeaf6 100%);
  593. }
  594. }
  595. .tabs-active {
  596. color: #3385ff;
  597. }
  598. }
  599. }
  600. </style>