NavBar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <el-row class="el-menu-demo">
  3. <el-col :md="2">
  4. <ul role="menubar" class="el-menu--horizontal el-menu">
  5. <li role="menuitem" class="el-menu-item">
  6. <a href="/" style="color: #007bff;text-decoration-line: none">
  7. <img src="@/assets/img/icon/logo.png" class="logo" alt="img">
  8. tnb
  9. </a>
  10. </li>
  11. </ul>
  12. </el-col>
  13. <el-col :md="8">
  14. <el-menu
  15. mode="horizontal"
  16. >
  17. <el-menu-item index="1">
  18. <a href="/video" style="text-decoration-line: none">
  19. <span style="color: #007bff">视频</span>
  20. </a>
  21. </el-menu-item>
  22. <el-menu-item index="2">
  23. <a href="/shortvideo" style="text-decoration-line: none">
  24. <span style="color: #007bff">短视频</span>
  25. </a>
  26. </el-menu-item>
  27. <el-menu-item index="3">
  28. <a href="/image" style="text-decoration-line: none">
  29. <span style="color: #007bff">相册</span>
  30. </a>
  31. </el-menu-item>
  32. <el-menu-item index="4">
  33. <a href="/article" style="text-decoration-line: none">
  34. <span style="color: #007bff">文章</span>
  35. </a>
  36. </el-menu-item>
  37. <el-menu-item index="5">
  38. <a href="/discover" style="text-decoration-line: none">
  39. <span style="color: #007bff">发现</span>
  40. </a>
  41. </el-menu-item>
  42. </el-menu>
  43. </el-col>
  44. <el-col :md="8">
  45. <ul class="el-menu--horizontal el-menu">
  46. <li class="el-menu-item">
  47. <el-autocomplete
  48. v-model="keyword"
  49. :fetch-suggestions="querySearchAsync"
  50. :placeholder="placeholder"
  51. clearable
  52. suffix-icon="el-icon-search"
  53. size="medium"
  54. :debounce="1000"
  55. @keyup.enter.native="onSearch"
  56. @select="onSearch"
  57. />
  58. </li>
  59. </ul>
  60. </el-col>
  61. <el-col :md="6">
  62. <ul class="el-menu--horizontal el-menu">
  63. <li class="el-menu-item">
  64. <el-dropdown v-if="user">
  65. <img
  66. :src="user.avatarUrl"
  67. class="el-avatar--circle el-avatar--medium"
  68. alt=""
  69. >
  70. <el-dropdown-menu v-if="user" slot="dropdown" class="iconsize">
  71. <el-dropdown-item
  72. icon="el-icon-files"
  73. class="size"
  74. @click.native="goToDisk"
  75. >我的网盘</el-dropdown-item>
  76. <el-dropdown-item
  77. icon="el-icon-user-solid"
  78. class="size"
  79. @click.native="goToProfile"
  80. >我的帐号</el-dropdown-item>
  81. <el-dropdown-item
  82. icon="el-icon-s-home"
  83. class="size"
  84. @click.native="goToHome"
  85. >我的主页</el-dropdown-item>
  86. <el-dropdown-item
  87. icon="el-icon-s-data"
  88. class="size"
  89. @click.native="goToPost"
  90. >我的稿件
  91. </el-dropdown-item>
  92. <el-dropdown-item
  93. icon="el-icon-star-on"
  94. class="size"
  95. @click.native="goToFavlist"
  96. >收藏夹
  97. </el-dropdown-item>
  98. <el-dropdown-item
  99. icon="el-icon-video-camera-solid"
  100. class="size"
  101. @click.native="goToHistory"
  102. >历史记录
  103. </el-dropdown-item>
  104. <el-dropdown-item
  105. icon="el-icon-error"
  106. class="size"
  107. @click.native="goToLogout"
  108. >退出</el-dropdown-item>
  109. </el-dropdown-menu>
  110. </el-dropdown>
  111. <span
  112. v-else
  113. style="color: #007bff"
  114. @click="login"
  115. >登录</span>
  116. </li>
  117. <li class="el-menu-item" @click="goToTimeline">
  118. <el-badge v-if="statusCount > 0" class="item" :value="statusCount" :max="99">
  119. <span class="el-icon-view" style="color: #007bff">状态</span>
  120. </el-badge>
  121. <span v-else class="el-icon-view" style="color: #007bff">状态</span>
  122. </li>
  123. <li class="el-menu-item" @click="goToMessage">
  124. <el-badge v-if="msgCount > 0" class="item" :value="msgCount" :max="99">
  125. <span class="el-icon-bell" style="color: #007bff">消息</span>
  126. </el-badge>
  127. <span v-else class="el-icon-bell" style="color: #007bff">消息</span>
  128. </li>
  129. <li class="el-menu-item">
  130. <el-button size="mini" type="upload" icon="el-icon-upload" @click="goToPublish">投稿</el-button>
  131. </li>
  132. </ul>
  133. </el-col>
  134. <!--登录弹窗-->
  135. <el-dialog
  136. title="用户登录"
  137. append-to-body
  138. :visible.sync="dialogVisible"
  139. width="30%"
  140. center
  141. >
  142. <el-form ref="form" :model="userLogin">
  143. <el-form-item label="帐号">
  144. <el-input
  145. v-model="userLogin.principal"
  146. placeholder="请输入手机号或邮箱"
  147. style="width: 70%; padding-right: 2px"
  148. clearable
  149. />
  150. </el-form-item>
  151. <el-form-item label="密码">
  152. <el-input
  153. v-model="userLogin.credential"
  154. placeholder="请输入验证码"
  155. style="width: 45%; padding-right: 2px"
  156. />
  157. <el-button :disabled="isBtn" @click="fetchVerifyCode">{{ code }}</el-button>
  158. </el-form-item>
  159. <el-form-item label="图形验证码" label-width="90px">
  160. <el-image :src="captchaCode" @click="getCaptcha" />
  161. <el-input
  162. v-model="userLogin.captchaCode"
  163. placeholder="请输入图形验证码"
  164. style="width: 45%; padding-right: 2px"
  165. />
  166. </el-form-item>
  167. <el-form-item>
  168. <el-button
  169. type="primary"
  170. :loading="isLoading"
  171. @click.native="loginBtn"
  172. >登 录</el-button>
  173. <el-button type="plain" @click="register">注册/忘记密码?</el-button>
  174. </el-form-item>
  175. </el-form>
  176. </el-dialog>
  177. </el-row>
  178. </template>
  179. <script>
  180. import { userMixin } from 'assets/js/mixin'
  181. import { keywordSuggest } from '@/api/search'
  182. import { getAuthedUser } from '@/utils/auth'
  183. export default {
  184. name: 'NavBar',
  185. mixins: [userMixin],
  186. data() {
  187. return {
  188. user: null,
  189. activeIndex: '1',
  190. restaurants: [],
  191. placeholder: '想要搜点神马呢',
  192. keyword: '',
  193. statusCount: 0,
  194. msgCount: 0
  195. }
  196. },
  197. created() {
  198. /* const userdata = Vue.$cookies.get('USERDATA')
  199. const userId = userdata.split(':')[0]*/
  200. const userInfo = getAuthedUser()
  201. if (userInfo !== null) {
  202. this.user = userInfo
  203. }
  204. },
  205. methods: {
  206. handleSelect(key, keyPath) {
  207. console.log(key, keyPath)
  208. },
  209. // ****************************************************************************************************************
  210. // 重点:当框中的改变时触发该方法,elementui自动设置了防抖,参见debounce属性
  211. // queryString 为输入框中的值。cb为返回显示列表的回调函数
  212. querySearchAsync(queryString, cb) {
  213. if (queryString === '') {
  214. return
  215. }
  216. setTimeout(() => {
  217. keywordSuggest(queryString).then(res => {
  218. if (res.code === 0) {
  219. this.restaurants = res.data.map((item) => {
  220. return {
  221. value: item.keyword,
  222. rank: 1
  223. }
  224. })
  225. // 如果 cb 返回一个空数组, 那么模糊搜索输入建议的下拉选项会因为 length 为 0 而消失
  226. // cb([])
  227. cb(this.restaurants)
  228. // eslint-disable-next-line no-empty
  229. } else {
  230. }
  231. })
  232. }, 500)
  233. },
  234. // select 事件或 enter 键事件
  235. onSearch() {
  236. console.log('回车事件')
  237. // 正则去空格
  238. if (this.keyword.replace(/\s*/g, '')) {
  239. this.toSearchPage()
  240. } else {
  241. this.$message({
  242. showClose: true,
  243. message: '不能为空!',
  244. type: 'warning'
  245. })
  246. }
  247. },
  248. // 跳转搜索页面,传递搜索框的参数
  249. toSearchPage() {
  250. const currentPath = this.$route.path
  251. if (currentPath === '/search') {
  252. this.$router.push({
  253. path: '/search',
  254. query: {
  255. keyword: this.keyword,
  256. pageNumber: 1
  257. }
  258. })
  259. this.$router.go(0)
  260. } else {
  261. const routeUrl = this.$router.resolve({
  262. path: '/search',
  263. query: {
  264. keyword: this.keyword,
  265. pageNumber: 1
  266. }
  267. })
  268. window.open(routeUrl.href, '_blank')
  269. }
  270. },
  271. // ****************************************************************************************************************
  272. login1() {
  273. this.fetchPubkey()
  274. this.dialogVisible = true
  275. },
  276. login() {
  277. const path = '/login'
  278. if (this.$route.path === path) {
  279. this.$router.go(0)
  280. return
  281. }
  282. this.$router.push(path)
  283. },
  284. register() {
  285. window.open('//account.reghao.cn/login', '_blank')
  286. },
  287. // ****************************************************************************************************************
  288. goToDisk() {
  289. const path = '/disk'
  290. if (this.$route.path === path) {
  291. this.$router.go(0)
  292. return
  293. }
  294. this.$router.push(path)
  295. },
  296. goToProfile() {
  297. const path = '/my'
  298. if (this.$route.path === path) {
  299. this.$router.go(0)
  300. return
  301. }
  302. this.$router.push(path)
  303. },
  304. goToTimeline() {
  305. const path = '/timeline'
  306. if (this.$route.path === path) {
  307. this.$router.go(0)
  308. return
  309. }
  310. this.$router.push(path)
  311. },
  312. goToHome() {
  313. const path = '/user/' + this.user.userId
  314. if (this.$route.path === path) {
  315. this.$router.go(0)
  316. return
  317. }
  318. this.$router.push(path)
  319. },
  320. goToPost() {
  321. if (this.$route.path === '/my/post/list/video') {
  322. this.$router.go(0)
  323. return
  324. }
  325. this.$router.push('/my/post/list/video')
  326. },
  327. goToFavlist() {
  328. if (this.$route.path === '/my/favlist/video') {
  329. this.$router.go(0)
  330. return
  331. }
  332. this.$router.push('/my/favlist/video')
  333. },
  334. goToHistory() {
  335. if (this.$route.path === '/my/visit') {
  336. this.$router.go(0)
  337. return
  338. }
  339. this.$router.push('/my/visit')
  340. },
  341. goToMessage() {
  342. if (this.$route.path === '/my/message/receive') {
  343. this.$router.go(0)
  344. return
  345. }
  346. this.$router.push('/my/message/receive')
  347. },
  348. goToPublish() {
  349. if (this.$route.path === '/my/post/publish/video') {
  350. this.$router.go(0)
  351. return
  352. }
  353. this.$router.push('/my/post/publish/video')
  354. }
  355. }
  356. }
  357. </script>
  358. <style scoped>
  359. @media screen and (max-width: 768px) {
  360. }
  361. .logo {
  362. width: 30px;
  363. position: relative;
  364. }
  365. .size {
  366. font-size: 16px;
  367. }
  368. .item {
  369. margin-top: 10px;
  370. margin-right: 10px;
  371. }
  372. </style>