NavBar.vue 10 KB

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