PostBar.vue 9.4 KB

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