header.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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: -webkit-linear-gradient(left top, #01d9ff , #01a9fe);
  242. background: -o-linear-gradient(bottom right, #01d9ff, #01a9fe);
  243. background: -moz-linear-gradient(bottom right, #01d9ff, #01a9fe);
  244. background: linear-gradient(to right, #01d9ff , #01a9fe); */
  245. background: $uni-color-primary;
  246. }
  247. .headerline{
  248. position: fixed;
  249. z-index: 10;
  250. left: 0px;
  251. top:0px;
  252. width: 100%;
  253. height: 40px;
  254. line-height:40px;
  255. padding: 2px 0px;
  256. text-align: center;
  257. /* background: -webkit-linear-gradient(left top, #01d9ff , #01a9fe);
  258. background: -o-linear-gradient(bottom right, #01d9ff, #01a9fe);
  259. background: -moz-linear-gradient(bottom right, #01d9ff, #01a9fe);
  260. background: linear-gradient(to right, #01d9ff , #01a9fe); */
  261. background-color:#01a9fe ;
  262. display: table;
  263. table-layout: fixed;
  264. text-align: center;
  265. color:#fff;
  266. font-size: 28upx;
  267. border-bottom: 0px ;
  268. }
  269. .headerline view{
  270. display: table-cell;
  271. vertical-align: middle;
  272. }
  273. .headerline .back {
  274. text-align: left;
  275. padding-left: 5px;
  276. height: 40px;;
  277. line-height: 40px;
  278. color: black;
  279. }
  280. .headerline .back .icons{
  281. color:#000 !important;
  282. font-size: 30px !important;
  283. height: 30px !important;
  284. vertical-align: middle;
  285. }
  286. .headerline .logo {
  287. text-align: left;
  288. padding-left: 7px;
  289. }
  290. .headerline .logo image{
  291. height: 35px;
  292. vertical-align: middle;
  293. width: 90px;
  294. }
  295. .headerline .right{
  296. text-align: right;
  297. padding-right: 7px;
  298. }
  299. .headerline .title{
  300. position: absolute;
  301. left: 25%;
  302. width: 50%;
  303. top:5px;
  304. line-height: 35px;
  305. font-size: 16px;
  306. font-weight: 600;
  307. }
  308. .headerline .nav{
  309. position: absolute;
  310. left: 30%;
  311. top:9px;
  312. width: 40%;
  313. display: table;
  314. margin: 0px auto;
  315. height: 28px;
  316. line-height: 28px;
  317. color: #fff;
  318. border:1px solid #2319dc;
  319. border-radius: 5px;
  320. }
  321. .headerline .nav .navitem {
  322. display: table-cell;
  323. border-right:1px solid #2319dc;
  324. }
  325. .headerline .nav .navitem:first-child{
  326. border-left: 0px;
  327. }
  328. .headerline .nav .navitem.active{
  329. background-color: #2319dc;
  330. }
  331. .headerline .nav .navitem .red{
  332. display: inline-block;
  333. height: 7px;
  334. width: 7px;
  335. border-radius: 50%;
  336. margin-left: 1px;
  337. margin-top: 5px;
  338. background-color: #FF0000;
  339. vertical-align: top;
  340. }
  341. .menunav{
  342. position: fixed;
  343. top:70px;
  344. right: 1px;
  345. width: 120px;
  346. box-shadow: 0 0 20rpx 10rpx rgba(0, 0, 0, .1);
  347. z-index: 99;
  348. /* background-color: rgba(0,0,0,0.8); */
  349. background-color: #fff;
  350. line-height: 35px;
  351. padding: 5px 5px;
  352. transform: translate(0,-100vh);
  353. transition: .5s;
  354. font-size: 14px;
  355. border-radius: 5px;
  356. }
  357. .menunav.active{
  358. transform: translate(0,0);
  359. }
  360. .menunav:before{
  361. display: block;
  362. content: "";
  363. position: absolute;
  364. top: -6px;
  365. right:26upx;
  366. width: 0;
  367. height: 0;
  368. border-style: solid;
  369. border-width: 0px 7px 7px 7px;
  370. border-color: #fff transparent;
  371. }
  372. .menunav >view{
  373. height: 35px;
  374. line-height: 35px;
  375. color: #000;
  376. cursor: pointer;
  377. width: 100%;
  378. border-bottom:1px dashed #fff;
  379. font-size: 14px;
  380. text-align: center;
  381. display: flex;
  382. flex-direction: row;
  383. justify-content: center;
  384. }
  385. .menunav >view > .iconshow{
  386. color: #000 !important;
  387. /* color: #000; */
  388. font-size: 16px !important;
  389. margin-right: 5px;
  390. display:inline-block ;
  391. }
  392. .seacrchtop{
  393. /* background: -webkit-linear-gradient(left top, #01d9ff , #01a9fe);
  394. background: -o-linear-gradient(bottom right, #01d9ff, #01a9fe);
  395. background: -moz-linear-gradient(bottom right, #01d9ff, #01a9fe);
  396. background: linear-gradient(to right, #01d9ff , #01a9fe); */
  397. background-color: #fff;
  398. position: fixed;
  399. top:0px;
  400. left: 0px;
  401. width: 100%;
  402. height: 30px;
  403. line-height: 30px;
  404. text-align: center;
  405. color:#fff;
  406. padding-top: 10px;
  407. z-index: 19;
  408. display: none;
  409. table-layout: fixed;
  410. }
  411. .seacrchtop li{
  412. display: inline-block;
  413. text-align: center;
  414. vertical-align: top;
  415. }
  416. .seacrchtop li:first-child{
  417. width: 35px;
  418. line-height: 30px;
  419. text-align: center;
  420. }
  421. .seacrchtop li:first-child .icon{
  422. font-size: 20px;
  423. cursor: pointer;
  424. color: #fff;
  425. }
  426. .seacrchtop li:nth-child(2){
  427. width: calc(100% - 120px);
  428. overflow: hidden;
  429. }
  430. .seacrchtop li:last-child{
  431. width: 68px;
  432. padding-right: 10px;
  433. text-align: left;
  434. }
  435. .seacrchtop li .input1{
  436. width:100%;
  437. height: 28px;
  438. line-height: 28px;
  439. padding-left: 5px;
  440. font-size: 14px;
  441. background-color: #fff;
  442. color: #222;
  443. border:1px solid #2da2fd;
  444. border-right: 0px;
  445. text-align: left;
  446. vertical-align: top;
  447. border-top-left-radius:5px;
  448. border-bottom-left-radius:5px;
  449. }
  450. .seacrchtop li .input1::placeholder{
  451. color:#999;
  452. font-size: 12px;
  453. }
  454. .seacrchtop li .btn{
  455. /* background: -webkit-linear-gradient(left top, #3388ff , #2319dc);
  456. background: -o-linear-gradient(bottom right, #3388ff, #2319dc);
  457. background: -moz-linear-gradient(bottom right, #3388ff, #2319dc);
  458. background: linear-gradient(to bottom right, #3388ff , #2319dc); */
  459. background: #2da2fd;
  460. height: 30px;line-height: 30px;
  461. border:1px solid $uni-color-primary;
  462. width: 100%;
  463. text-align: center;
  464. padding: 0px 0px;
  465. display: inline-block;
  466. color: #fff;
  467. border: 0px;
  468. cursor: pointer;
  469. border-top-left-radius: 0px;
  470. border-bottom-left-radius: 0px;
  471. vertical-align: top;
  472. }
  473. .search_tips {
  474. font-size: 14px;
  475. line-height: 40px;
  476. display: flex;
  477. flex-direction: column;
  478. width: 100%;
  479. }
  480. .search_tips > view{
  481. height: 50px;
  482. line-height: 50px;
  483. background-color: #fff;
  484. border-bottom: 1px solid #eee;
  485. color: #000;
  486. display: flex;
  487. flex-direction: row;
  488. }
  489. .search_tips > view >view:nth-child(1){
  490. width: 78px;
  491. justify-content: right;
  492. text-align: right;
  493. align-items: right;
  494. color: #888;
  495. display: inline-flex;
  496. flex-direction: row;
  497. padding-left: 10px;
  498. }
  499. .search_tips > view image{
  500. height: 30px;
  501. width: 30px;
  502. vertical-align: middle;
  503. border-radius: 5px;
  504. margin-right: 5px;
  505. margin-top: 10px;
  506. justify-content: right;
  507. justify-items: ;
  508. text-align: right;
  509. align-items: right
  510. }
  511. </style>