search.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="container">
  3. <view class="tui-searchbox">
  4. <view class="tui-search-input">
  5. <icon type="search" :size='13' color='#333'></icon>
  6. <input confirm-type="search" placeholder="大家都在搜:代祭扫" :focus="true" auto-focus placeholder-class="tui-input-plholder"
  7. class="tui-input" v-model.trim="key" @input="inputKey"/>
  8. <icon type="clear" :size='13' color='#bcbcbc' @tap="cleanKey" v-show="key"></icon>
  9. </view>
  10. <view class="tui-cancle" @tap="back">取消</view>
  11. </view>
  12. <view class="tui-search-history" v-show="history.length>0 && !key">
  13. <view class="tui-history-header">
  14. <view class="tui-search-title">搜索历史</view>
  15. <tui-icon name="delete" :size='14' color='#333' @tap="openActionSheet" class="tui-icon-delete"></tui-icon>
  16. </view>
  17. <view class="tui-history-content">
  18. <block v-for="(item,index) in history" :key="index">
  19. <tui-tag margin="0 24rpx 24rpx 0" type="gray" shape="circle">{{item}}</tui-tag>
  20. </block>
  21. </view>
  22. </view>
  23. <view v-show="key">
  24. <view class="tui-header">
  25. <view class="tui-header-left tui-noboredr">搜索 “{{key}}”</view>
  26. </view>
  27. <view class="tui-result-box">
  28. <block v-for="(item,index) in searchList" :key="index">
  29. <view class="tui-result-item" hover-class="tui-opcity" :hover-stay-time="150">
  30. <rich-text :nodes="item.showKey"></rich-text>
  31. </view>
  32. </block>
  33. </view>
  34. </view>
  35. <!-- <view class="tui-search-hot">
  36. <view class="tui-hot-header">
  37. <view class="tui-search-title">大家正在搜</view>
  38. </view>
  39. <view class="tui-hot-content">
  40. <block v-for="(item,index) in hot" :key="index">
  41. <tui-tag type="gray" shape="circle">{{item}}</tui-tag>
  42. </block>
  43. </view>
  44. </view> -->
  45. <tui-actionsheet :show="showActionSheet" :tips="tips" @click="itemClick" @cancel="closeActionSheet"></tui-actionsheet>
  46. </view>
  47. </template>
  48. <script>
  49. import tuiButton from "@/components/thorui/tui-button/tui-button"
  50. import tuiIcon from "@/components/thorui/tui-icon/tui-icon"
  51. import tuiBadge from "@/components/thorui/tui-badge/tui-badge"
  52. import tuiTag from "@/components/thorui/tui-tag/tui-tag"
  53. import tuiNomore from "@/components/thorui/tui-nomore/tui-nomore"
  54. import tuiTopDropdown from "@/components/thorui/tui-top-dropdown/tui-top-dropdown"
  55. import tuiBottomPopup from "@/components/thorui/tui-bottom-popup/tui-bottom-popup"
  56. import tuiNumberbox from "@/components/thorui/tui-numberbox/tui-numberbox"
  57. import tuiDrawer from "@/components/thorui/tui-drawer/tui-drawer"
  58. import tuiActionsheet from "@/components/thorui/tui-actionsheet/tui-actionsheet"
  59. const util = require("@/utils/util.js")
  60. export default {
  61. components:{
  62. tuiButton,
  63. tuiIcon,
  64. tuiBadge,
  65. tuiTag,
  66. tuiNomore,
  67. tuiTopDropdown,
  68. tuiBottomPopup,
  69. tuiNumberbox,
  70. tuiDrawer,
  71. tuiActionsheet
  72. },
  73. data() {
  74. return {
  75. history: [
  76. "代祭扫",
  77. "蜡烛",
  78. "香火",
  79. "龙飞凤舞"
  80. ],
  81. hot: [
  82. "代祭扫",
  83. "蜡烛",
  84. "香火",
  85. "龙飞凤舞"
  86. ],
  87. key: "",
  88. showActionSheet: false,
  89. tips: "确认清空搜索历史吗?",
  90. searchResult:["按照展示的列表输入关键词看效果","thorui","2019退役球星","搜索关键词高亮显示","模拟搜索结果集","开源不易,需要鼓励","人人为我,我为人人"],
  91. searchList:[]
  92. }
  93. },
  94. methods: {
  95. back: function() {
  96. uni.navigateBack();
  97. },
  98. cleanKey: function() {
  99. this.key = ''
  100. },
  101. closeActionSheet: function() {
  102. this.showActionSheet = false
  103. },
  104. openActionSheet: function() {
  105. this.showActionSheet = true
  106. },
  107. itemClick: function(e) {
  108. let index = e.index;
  109. if (index == 0) {
  110. this.showActionSheet = false;
  111. this.history = []
  112. }
  113. },
  114. inputKey: function(e) {
  115. this.key = util.trim(e.detail.value);
  116. if (!this.key) {
  117. this.searchList = [];
  118. return;
  119. }
  120. //根据关键词查找
  121. let arr = []
  122. //实际开发中,根据搜索返回结果集,此处只是做展示提示搜索哪些文字
  123. this.searchResult.forEach((item) => {
  124. arr.push({
  125. key: item,
  126. showKey: util.replaceAll(item, this.key, `<label style="color:#E41F19">${this.key}</label>`)
  127. })
  128. })
  129. this.searchList = arr
  130. }
  131. }
  132. }
  133. </script>
  134. <style>
  135. page {
  136. color: #333;
  137. background: #fff;
  138. }
  139. .container {
  140. padding: 0 30rpx 30rpx 30rpx;
  141. box-sizing: border-box;
  142. width: 100%;
  143. }
  144. .tui-searchbox {
  145. padding: 30rpx 0;
  146. box-sizing: border-box;
  147. display: flex;
  148. align-items: center;
  149. }
  150. .tui-search-input {
  151. width: 100%;
  152. height: 66rpx;
  153. border-radius: 35rpx;
  154. padding: 0 30rpx;
  155. box-sizing: border-box;
  156. background: #f2f2f2;
  157. display: flex;
  158. align-items: center;
  159. flex-wrap: nowrap;
  160. }
  161. .tui-input {
  162. flex: 1;
  163. color: #333;
  164. padding: 0 16rpx;
  165. font-size: 28rpx;
  166. }
  167. .tui-input-plholder {
  168. font-size: 28rpx;
  169. color: #b2b2b2;
  170. }
  171. .tui-cancle {
  172. color: #888;
  173. font-size: 28rpx;
  174. padding-left: 30rpx;
  175. flex-shrink: 0;
  176. }
  177. .tui-history-header {
  178. display: flex;
  179. align-items: center;
  180. justify-content: space-between;
  181. padding: 30rpx 0;
  182. }
  183. .tui-history-content{
  184. display: flex;
  185. align-items: center;
  186. flex-wrap: wrap;
  187. }
  188. .tui-icon-delete {
  189. padding: 10rpx;
  190. }
  191. .tui-search-title {
  192. font-size: 28rpx;
  193. font-weight: bold;
  194. }
  195. .tui-hot-header {
  196. padding: 30rpx 0;
  197. }
  198. .tui-header {
  199. padding: 26rpx 0;
  200. box-sizing: border-box;
  201. display: flex;
  202. align-items: center;
  203. justify-content: space-between;
  204. }
  205. .tui-header-left {
  206. font-size: 30rpx;
  207. color: #222;
  208. border-left: 4rpx solid #EB0909;
  209. padding-left: 10rpx;
  210. word-break: break-all;
  211. }
  212. .tui-noboredr {
  213. border-left: 0 !important;
  214. }
  215. .tui-result-box {
  216. font-size: 28rpx;
  217. }
  218. .tui-result-item {
  219. line-height: 28rpx;
  220. padding: 28rpx 0;
  221. }
  222. </style>