news.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <script>
  2. import AdminLayout from "~/components/layout/adminLayout.vue";
  3. import {adminMenus} from "../../map/adminSideBar";
  4. import Vue from 'vue'
  5. import antd from 'ant-design-vue'
  6. import 'ant-design-vue/dist/antd.css'
  7. import {login_types} from "../../store/login";
  8. import {handle} from "../../until/handle";
  9. Vue.use(antd);
  10. export default {
  11. name: "mangerProduct",
  12. components: {AdminLayout},
  13. async asyncData(ctx) {
  14. // 判断 store 中的 isLogin 是否为 true $store.state.login.captcha
  15. console.log(ctx?.store?.state?.login)
  16. if (!ctx?.store?.state?.login?.isLogin) {
  17. // 如果未登录,重定向到登录页
  18. // ctx.redirect('/manger/login')
  19. ctx.redirect('/manger/login')
  20. }
  21. return {}
  22. },
  23. data(){
  24. return {
  25. headerMenus:[
  26. {
  27. text: '前往首页',
  28. href: '/',
  29. key: 'toIndex'
  30. }
  31. ],
  32. sidebarMenus: adminMenus
  33. }
  34. },
  35. computed: {
  36. userInfo(){
  37. return this.$store.state.login.userInfo
  38. }
  39. },
  40. methods: {
  41. dataLogOut(){
  42. this.$store.commit('login/'+login_types.mutations.userLogout);
  43. },
  44. async logout(){
  45. let [err,res] = await handle(this.$axios.get('/api/user/logout'));
  46. this.dataLogOut();
  47. if(err){
  48. return {};
  49. }
  50. this.$message.success('退出成功');
  51. // 切换url至 /login
  52. this.$router.push('/manger/login');
  53. }
  54. }
  55. }
  56. </script>
  57. <template>
  58. <div class="w-full">
  59. <admin-layout
  60. :logoTitle="'深圳合方圆站点管理'"
  61. :header-menus="headerMenus"
  62. :sidebar-menus="sidebarMenus"
  63. index-path="/manger"
  64. >
  65. <!-- 下拉菜单,对应slot user-->
  66. <a-dropdown slot="user">
  67. <a class="ant-dropdown-link" href="#">
  68. {{ userInfo.name }} <a-icon type="down" />
  69. </a>
  70. <a-menu slot="overlay">
  71. <!-- <a-menu-info key="1">-->
  72. <!-- <a href="#">1st menu info</a>-->
  73. <!-- </a-menu-info>-->
  74. <a-menu-item key="3">
  75. <span @click="logout">退出登录</span>
  76. </a-menu-item>
  77. </a-menu>
  78. </a-dropdown>
  79. <nuxt-child>
  80. </nuxt-child>
  81. </admin-layout>
  82. </div>
  83. </template>
  84. <style scoped>
  85. </style>