| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <template>
- <n-config-provider :theme-overrides="themeOverrides">
- <n-dialog-provider>
- <router-view></router-view>
- <HomeModal
- :show="showModal"
- :content="modalContent"
- ></HomeModal>
- </n-dialog-provider>
- </n-config-provider>
- </template>
- <script lang="ts">
- export default {
- name: 'MainApp',
- };
- </script>
- <script lang="ts" setup>
- import { isMobile } from 'billd-utils';
- import { GlobalThemeOverrides, NConfigProvider } from 'naive-ui';
- import { onMounted, ref, watch } from 'vue';
- import { useRoute } from 'vue-router';
- import { THEME_COLOR, appBuildInfo } from '@/constant';
- import { useCheckUpdate } from '@/hooks/use-common';
- import { useGoogleAd } from '@/hooks/use-google-ad';
- import { loginMessage } from '@/hooks/use-login';
- import { useCacheStore } from '@/store/cache';
- import { useUserStore } from '@/store/user';
- import { getHostnameUrl } from '@/utils';
- import { getLastBuildDate, setLastBuildDate } from '@/utils/localStorage/app';
- import { getToken } from '@/utils/localStorage/user';
- import { fetchAreaList } from './api/area';
- import { fetchGlobalMsgMyList } from './api/globalMsg';
- import { useTip } from './hooks/use-tip';
- import { useAppStore } from './store/app';
- const { checkUpdate } = useCheckUpdate();
- const appStore = useAppStore();
- const cacheStore = useCacheStore();
- const userStore = useUserStore();
- const route = useRoute();
- const showModal = ref(false);
- const modalContent = ref('2');
- const themeOverrides: GlobalThemeOverrides = {
- common: {
- primaryColor: THEME_COLOR,
- primaryColorHover: THEME_COLOR,
- },
- };
- watch(
- () => userStore.userInfo,
- (newval) => {
- if (newval) {
- handleGlobalMsgMyList();
- }
- },
- {
- immediate: true,
- }
- );
- onMounted(() => {
- useGoogleAd();
- initGlobalData();
- checkUpdate({
- htmlUrl: getHostnameUrl(),
- });
- handleUpdate();
- loginMessage();
- cacheStore.muted = true;
- cacheStore.volume = 0;
- const token = getToken();
- if (token) {
- userStore.getUserInfo();
- }
- // 启用vconsole
- // import('vconsole')
- // .then((VConsole) => {
- // // eslint-disable-next-line
- // new VConsole.default();
- // })
- // .catch(() => {});
- if (isMobile()) {
- const metaEl = document.querySelector('meta[name="viewport"]');
- metaEl?.setAttribute(
- 'content',
- 'width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no'
- );
- }
- });
- async function handleGlobalMsgMyList() {
- const res = await fetchGlobalMsgMyList({});
- if (res.code === 200) {
- const data = res.data.rows[0];
- if (data) {
- useTip({
- content: data.content!,
- hiddenCancel: true,
- hiddenClose: true,
- });
- }
- }
- }
- async function getAreaList() {
- const res = await fetchAreaList({ orderName: 'priority', orderBy: 'desc' });
- if (res.code === 200) {
- appStore.areaList = res.data.rows;
- }
- }
- function initGlobalData() {
- getAreaList();
- }
- function handleUpdate() {
- const old = getLastBuildDate();
- if (appBuildInfo.lastBuildDate !== old) {
- localStorage.clear();
- }
- setLastBuildDate(appBuildInfo.lastBuildDate);
- }
- </script>
- <style lang="scss">
- body {
- font-size: 16px;
- // naive的message会影响全局line-height
- line-height: initial;
- }
- </style>
- <style lang="scss" scoped></style>
|