App.vue 1.35 KB
Newer Older
leiqingsong's avatar
leiqingsong committed
1 2
<template>
  <div id="app">
leiqingsong's avatar
leiqingsong committed
3
    <base-nav-bar v-if="!$route.meta.noNav" :navBarTitle="currentTitle" />
leiqingsong's avatar
leiqingsong committed
4 5 6 7
    <router-view />
  </div>
</template>

8 9
<script>
import BaseNavBar from "./components/BaseNavBar.vue";
leiqingsong's avatar
leiqingsong committed
10
import { getUserInfo } from "@/api/user";
11 12 13 14 15 16 17 18 19 20 21 22 23
export default {
  components: {
    BaseNavBar
  },
  data() {
    return {
      currentTitle: ""
    };
  },
  watch: {
    $route(val) {
      this.currentTitle = val.meta.title;
    }
leiqingsong's avatar
leiqingsong committed
24
  },
25
  created() {
leiqingsong's avatar
leiqingsong committed
26
    console.log("和App开始交互");
27
    this.$bridgeToAppFun
leiqingsong's avatar
leiqingsong committed
28
      .getAuthToken()
leiqingsong's avatar
leiqingsong committed
29
      .then(res => {
leiqingsong's avatar
leiqingsong committed
30
        console.log("获取到token成功", res);
31
        localStorage.setItem("token", res);
leiqingsong's avatar
leiqingsong committed
32
        this.saveUser(res);
leiqingsong's avatar
leiqingsong committed
33 34
      })
      .catch(err => {
leiqingsong's avatar
leiqingsong committed
35
        console.log("获取token失败123", err);
leiqingsong's avatar
leiqingsong committed
36
      });
leiqingsong's avatar
leiqingsong committed
37 38
  },
  methods: {
39
    async saveUser(data) {
leiqingsong's avatar
leiqingsong committed
40
      if (data) {
41
        console.log("预存用户信息");
42
        await getUserInfo().then(res => {
43
          console.log("获取到,存用户信息");
leiqingsong's avatar
leiqingsong committed
44 45 46 47 48 49 50 51
          if (res.code == 0) {
            localStorage.setItem("user", JSON.stringify(res.data));
          }
        });
      } else {
        console.log("调用失败");
      }
    }
xulili's avatar
xulili committed
52
  }
53 54 55
};
</script>

leiqingsong's avatar
leiqingsong committed
56 57 58
<style lang="scss">
body {
  font-size: 16px;
leiqingsong's avatar
leiqingsong committed
59
  font-family: PingFang-SC-Medium;
leiqingsong's avatar
leiqingsong committed
60 61 62 63 64
  background: #f8f8f8;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>