header.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <template>
  2. <view>
  3. <view class="status-bar" :style="{ height: statusbarheight }" ></view>
  4. <view class="headerline" :style="{ top: statusbarheight }">
  5. <block v-if="!showsearch && !showsearch1">
  6. <view class="back" v-if="isback" @tap="clickback()">
  7. <uni-icons type='arrowleft' class="icons"></uni-icons>
  8. </view>
  9. <view class="logo" v-if="islogo" > <image src="/static/logo.png" ></image> </view>
  10. <view class="title" v-if="!shownav">{{title}}</view>
  11. <view class="nav" v-if="shownav" :style="navstyle">
  12. <block v-for="(m,index) in navitem" :key="index" >
  13. <view :class="{'navitem':true,'active':index==navselect}" @tap="tapnav(index)" :style="'width:'+(100/navitem.length)+'%'">{{m}}
  14. <view class="red" v-if="reditem1[index]>0"></view>
  15. </view>
  16. </block>
  17. </view>
  18. <view class="right" v-if="issearch || rightmenu || isright">
  19. <uni-icons @tap="clickshowsearch()" v-if="issearch" type="search" color="#ffffff" size="28" style="vertical-align: middle;margin-right: 1px;"/>
  20. <uni-icons @tap="clickmenu()" v-if="rightmenu" type="plusempty" color="#ffffff" size="28" style="vertical-align: middle;"/>
  21. <uni-icons @tap="click_right()" v-if="isright" :type="righticon" color="#ffffff" size="28" style="vertical-align: middle;"/>
  22. </view>
  23. </block>
  24. <block v-else>
  25. <view class="seacrchtop" :style="{'display': 'table','margin-top':statusbarheight}">
  26. <li class="back" @tap="closesearch()">
  27. <uni-icons type='arrowleft' class="icons" ></uni-icons>
  28. </li>
  29. <li><input class="input1" id="keyword" :placeholder="searchtips" v-model="keyword" @input="listen_input($event.detail.value)" /> </li>
  30. <li @tap="click_type('all');">
  31. <div class="btn"><uni-icons style="font-size: 16px;color:#fff;margin-right:2px;font-weight: 600;" type="search"></uni-icons>搜索</div>
  32. </li>
  33. </view>
  34. </block>
  35. </view>
  36. <view :class="{'menunav':true,'active':showmenu}" :style="'top:calc('+statusbarheight+' + 50px);'">
  37. <block v-for="(m,index) in menuitem" :key="index" >
  38. <view @tap="tapmenu(index)"><uni-icons :type='m.icon' class="iconshow" />{{m.title}}</view>
  39. </block>
  40. </view>
  41. <view :style="{ height: statusbarheight }" ></view>
  42. <view style="height: 45px;display: inline-block;width: 100%;"></view>
  43. <view class="search_tips" v-if="keyword && showsearch1 && issearchresult==false">
  44. <view @tap="click_type('user')"><view> <image src="/static/img/user_add.png"></image>找人:</view><view>{{keyword}}</view></view>
  45. <view @tap="click_type('group')"><view><image src="../static/img/group_add.png"></image>找群:</view><view>{{keyword}}</view></view>
  46. </view>
  47. <searchitem v-if="issearchresult==true" :data="serachdata" :type='searchtype' :keyword="keyword" :loading="loading" @showmore="click_type" @getnext="getnext"></searchitem>
  48. </view>
  49. </template>
  50. <script>
  51. import uniIcons from './uni-icons/uni-icons.vue'
  52. import http from "../library/http.js"
  53. import searchitem from './searchitem.vue'
  54. export default {
  55. components: {
  56. uniIcons,
  57. searchitem,
  58. },
  59. props: {
  60. shownav: {
  61. default: false
  62. },
  63. rightmenu:{
  64. default:false
  65. },
  66. islogo: {
  67. default: false
  68. },
  69. isback: {
  70. default: false
  71. },
  72. gameshow:{
  73. },
  74. title:{
  75. },
  76. statusbarheight:{
  77. },
  78. navitem:{
  79. },
  80. reditem:{
  81. default:false,
  82. },
  83. navselect:{
  84. default:0
  85. },
  86. menuitem:{
  87. },
  88. navstyle:{
  89. },
  90. issearch:{
  91. default:false
  92. },
  93. showsearch:{
  94. default:false
  95. },
  96. searchtips:{
  97. default:'请输入要搜索的内容'
  98. },
  99. isright:{
  100. default:false
  101. },
  102. righticon:{
  103. default:false
  104. }
  105. },
  106. data() {
  107. return {
  108. showtrend:false,
  109. trendactive:false,
  110. showmenu:false,
  111. menutop:55,
  112. keyword:'',
  113. reditem1:[0,0,0,0],
  114. showsearch1:false,
  115. searchtype:'all',
  116. page:1,
  117. serachdata:[],
  118. issearchresult:false,
  119. loading:false,
  120. }
  121. },
  122. methods: {
  123. clickback(){
  124. var urls= uni.getStorageSync('thisurl');
  125. if(urls && !uni.getStorageSync('access_token')){
  126. uni.reLaunch({
  127. url:urls
  128. })
  129. }
  130. else{
  131. uni.navigateBack({
  132. delta:1
  133. });
  134. }
  135. },
  136. click_right(){
  137. this.$emit('click_right');
  138. },
  139. clickmenu(){
  140. this.showmenu=!this.showmenu;
  141. },
  142. tapnav(num){
  143. this.$emit('tapnav',num);
  144. },
  145. tapmenu(num){
  146. this.showmenu=false;
  147. this.$emit('tapmenu',num);
  148. },
  149. clickshowsearch(){
  150. this.showsearch1=true
  151. this.showmenu=false;
  152. this.$emit('clicksearch',true)
  153. },
  154. clicksearch(){
  155. this.$emit('clicksearch',true)
  156. },
  157. closesearch(){
  158. this.showsearch1=false;
  159. this.issearchresult=false;
  160. this.keyword='';
  161. this.searchtype='all';
  162. this.page=1;
  163. this.$emit('clicksearch',false)
  164. },
  165. listen_input(value){
  166. this.issearchresult=false;
  167. this.searchtype='all';
  168. this.page=1;
  169. },
  170. click_type(type){
  171. this.page=1;
  172. this.issearchresult=false;
  173. this.searchtype=type;
  174. this.go_search();
  175. },
  176. getnext(e){
  177. this.loading=true;
  178. this.page++;
  179. this.searchtype=e;
  180. this.go_search();
  181. },
  182. go_search(){
  183. if(this.keyword.length<1){
  184. uni.showToast({
  185. title:'搜索内容不能为空',
  186. icon:'none'
  187. })
  188. return false;
  189. }
  190. http.setWait(false).get('index.php?act=search',{keyword:this.keyword,type:this.searchtype,page:this.page,userid:uni.getStorageSync('access_token')}).then(res=>{
  191. var reg =/^\d{5}$/;
  192. var reg1 =/^\d{6}$/;
  193. if(reg.test(this.keyword) && res.data.user.length==1){
  194. this.$jump('friend.detail',{id:res.data.user[0].id});
  195. }else if(reg1.test(this.keyword) && res.data.group.length==1){
  196. this.$jump('group.detail',{id:res.data.group[0].id});
  197. }else{
  198. if(res.data.user.length==0 && res.data.group.length==0 && this.page==1){
  199. uni.showToast({
  200. title:'没有搜索到相关内容',
  201. icon:'none'
  202. })
  203. }else{
  204. if(this.page>1 && this.searchtype!='all'){
  205. this.serachdata[this.searchtype].push(...res.data[this.searchtype])
  206. }else{
  207. this.serachdata=res.data;
  208. }
  209. this.issearchresult=true;
  210. }
  211. }
  212. this.loading=false;
  213. })
  214. // this.$emit('go_search',this.keyword)
  215. },
  216. showdata(){
  217. },
  218. },
  219. created() {
  220. this.showdata();
  221. if(this.reditem!=false) {
  222. this.reditem1=this.reditem;
  223. }
  224. },
  225. watch:{
  226. reditem(val){
  227. if(val!=false)this.reditem1=val;
  228. }
  229. },
  230. onLoad() {
  231. }
  232. }
  233. </script>
  234. <style>
  235. .status-bar{
  236. position: fixed;
  237. z-index: 10;
  238. left: 0px;
  239. top: 0px;
  240. width: 100%;
  241. background-color: #fff;
  242. /* background: -webkit-linear-gradient(left top, #01d9ff , #01a9fe);
  243. background: -o-linear-gradient(bottom right, #01d9ff, #01a9fe);
  244. background: -moz-linear-gradient(bottom right, #01d9ff, #01a9fe);
  245. background: linear-gradient(to right, #01d9ff , #01a9fe); */
  246. background: $uni-color-primary;
  247. }
  248. .headerline{
  249. position: fixed;
  250. z-index: 10;
  251. left: 0px;
  252. top:0px;
  253. width: 100%;
  254. height: 40px;
  255. line-height:40px;
  256. padding: 2px 0px;
  257. text-align: center;
  258. /* background: -webkit-linear-gradient(left top, #01d9ff , #01a9fe);
  259. background: -o-linear-gradient(bottom right, #01d9ff, #01a9fe);
  260. background: -moz-linear-gradient(bottom right, #01d9ff, #01a9fe);
  261. background: linear-gradient(to right, #01d9ff , #01a9fe); */
  262. background-color:#01a9fe ;
  263. display: table;
  264. table-layout: fixed;
  265. text-align: center;
  266. color:#fff;
  267. font-size: 28upx;
  268. border-bottom: 0px ;
  269. }
  270. .headerline view{
  271. display: table-cell;
  272. vertical-align: middle;
  273. }
  274. .headerline .back {
  275. text-align: left;
  276. padding-left: 5px;
  277. height: 40px;;
  278. line-height: 40px;
  279. color: black;
  280. }
  281. .headerline .back .icons{
  282. color:#000 !important;
  283. font-size: 30px !important;
  284. height: 30px !important;
  285. vertical-align: middle;
  286. }
  287. .headerline .logo {
  288. text-align: left;
  289. padding-left: 7px;
  290. }
  291. .headerline .logo image{
  292. height: 35px;
  293. vertical-align: middle;
  294. width: 90px;
  295. }
  296. .headerline .right{
  297. text-align: right;
  298. padding-right: 7px;
  299. }
  300. .headerline .title{
  301. position: absolute;
  302. left: 25%;
  303. width: 50%;
  304. top:5px;
  305. line-height: 35px;
  306. font-size: 16px;
  307. font-weight: 600;
  308. }
  309. .headerline .nav{
  310. position: absolute;
  311. left: 30%;
  312. top:9px;
  313. width: 40%;
  314. display: table;
  315. margin: 0px auto;
  316. height: 28px;
  317. line-height: 28px;
  318. color: #fff;
  319. border:1px solid #2319dc;
  320. border-radius: 5px;
  321. }
  322. .headerline .nav .navitem {
  323. display: table-cell;
  324. border-right:1px solid #2319dc;
  325. }
  326. .headerline .nav .navitem:first-child{
  327. border-left: 0px;
  328. }
  329. .headerline .nav .navitem.active{
  330. background-color: #2319dc;
  331. }
  332. .headerline .nav .navitem .red{
  333. display: inline-block;
  334. height: 7px;
  335. width: 7px;
  336. border-radius: 50%;
  337. margin-left: 1px;
  338. margin-top: 5px;
  339. background-color: #FF0000;
  340. vertical-align: top;
  341. }
  342. .menunav{
  343. position: fixed;
  344. top:70px;
  345. right: 1px;
  346. width: 120px;
  347. box-shadow: 0 0 20rpx 10rpx rgba(0, 0, 0, .1);
  348. z-index: 99;
  349. /* background-color: rgba(0,0,0,0.8); */
  350. background-color: #fff;
  351. line-height: 35px;
  352. padding: 5px 5px;
  353. transform: translate(0,-100vh);
  354. transition: .5s;
  355. font-size: 14px;
  356. border-radius: 5px;
  357. }
  358. .menunav.active{
  359. transform: translate(0,0);
  360. }
  361. .menunav:before{
  362. display: block;
  363. content: "";
  364. position: absolute;
  365. top: -6px;
  366. right:26upx;
  367. width: 0;
  368. height: 0;
  369. border-style: solid;
  370. border-width: 0px 7px 7px 7px;
  371. border-color: #fff transparent;
  372. }
  373. .menunav >view{
  374. height: 35px;
  375. line-height: 35px;
  376. color: #000;
  377. cursor: pointer;
  378. width: 100%;
  379. border-bottom:1px dashed #fff;
  380. font-size: 14px;
  381. text-align: center;
  382. display: flex;
  383. flex-direction: row;
  384. justify-content: center;
  385. }
  386. .menunav >view > .iconshow{
  387. color: #000 !important;
  388. /* color: #000; */
  389. font-size: 16px !important;
  390. margin-right: 5px;
  391. display:inline-block ;
  392. }
  393. .seacrchtop{
  394. /* background: -webkit-linear-gradient(left top, #01d9ff , #01a9fe);
  395. background: -o-linear-gradient(bottom right, #01d9ff, #01a9fe);
  396. background: -moz-linear-gradient(bottom right, #01d9ff, #01a9fe);
  397. background: linear-gradient(to right, #01d9ff , #01a9fe); */
  398. background-color: #fff;
  399. position: fixed;
  400. top:0px;
  401. left: 0px;
  402. width: 100%;
  403. height: 30px;
  404. line-height: 30px;
  405. text-align: center;
  406. color:#fff;
  407. padding-top: 10px;
  408. z-index: 19;
  409. display: none;
  410. table-layout: fixed;
  411. }
  412. .seacrchtop li{
  413. display: inline-block;
  414. text-align: center;
  415. vertical-align: top;
  416. }
  417. .seacrchtop li:first-child{
  418. width: 35px;
  419. line-height: 30px;
  420. text-align: center;
  421. }
  422. .seacrchtop li:first-child .icon{
  423. font-size: 20px;
  424. cursor: pointer;
  425. color: #fff;
  426. }
  427. .seacrchtop li:nth-child(2){
  428. width: calc(100% - 120px);
  429. overflow: hidden;
  430. }
  431. .seacrchtop li:last-child{
  432. width: 68px;
  433. padding-right: 10px;
  434. text-align: left;
  435. }
  436. .seacrchtop li .input1{
  437. width:100%;
  438. height: 28px;
  439. line-height: 28px;
  440. padding-left: 5px;
  441. font-size: 14px;
  442. background-color: #fff;
  443. color: #222;
  444. border:1px solid #2da2fd;
  445. border-right: 0px;
  446. text-align: left;
  447. vertical-align: top;
  448. border-top-left-radius:5px;
  449. border-bottom-left-radius:5px;
  450. }
  451. .seacrchtop li .input1::placeholder{
  452. color:#999;
  453. font-size: 12px;
  454. }
  455. .seacrchtop li .btn{
  456. /* background: -webkit-linear-gradient(left top, #3388ff , #2319dc);
  457. background: -o-linear-gradient(bottom right, #3388ff, #2319dc);
  458. background: -moz-linear-gradient(bottom right, #3388ff, #2319dc);
  459. background: linear-gradient(to bottom right, #3388ff , #2319dc); */
  460. background: #2da2fd;
  461. height: 30px;line-height: 30px;
  462. border:1px solid $uni-color-primary;
  463. width: 100%;
  464. text-align: center;
  465. padding: 0px 0px;
  466. display: inline-block;
  467. color: #fff;
  468. border: 0px;
  469. cursor: pointer;
  470. border-top-left-radius: 0px;
  471. border-bottom-left-radius: 0px;
  472. vertical-align: top;
  473. }
  474. .search_tips {
  475. font-size: 14px;
  476. line-height: 40px;
  477. display: flex;
  478. flex-direction: column;
  479. width: 100%;
  480. }
  481. .search_tips > view{
  482. height: 50px;
  483. line-height: 50px;
  484. background-color: #fff;
  485. border-bottom: 1px solid #eee;
  486. color: #000;
  487. display: flex;
  488. flex-direction: row;
  489. }
  490. .search_tips > view >view:nth-child(1){
  491. width: 78px;
  492. justify-content: right;
  493. text-align: right;
  494. align-items: right;
  495. color: #888;
  496. display: inline-flex;
  497. flex-direction: row;
  498. padding-left: 10px;
  499. }
  500. .search_tips > view image{
  501. height: 30px;
  502. width: 30px;
  503. vertical-align: middle;
  504. border-radius: 5px;
  505. margin-right: 5px;
  506. margin-top: 10px;
  507. justify-content: right;
  508. justify-items: ;
  509. text-align: right;
  510. align-items: right
  511. }
  512. </style>