App.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <script setup lang="ts">
  2. import { computed, watch } from 'vue'
  3. import { useAppStore } from './store/modules/app'
  4. import { ConfigGlobal } from './components/ConfigGlobal'
  5. import { useDesign } from './hooks/web/useDesign'
  6. import { getCodeList, getDeptTree, getDistrictTree } from './api'
  7. import { useUserStore } from './store/modules/user'
  8. const { getPrefixCls } = useDesign()
  9. const prefixCls = getPrefixCls('app')
  10. const appStore = useAppStore()
  11. const currentSize = computed(() => appStore.getCurrentSize)
  12. const greyMode = computed(() => appStore.getGreyMode)
  13. const userStore = useUserStore()
  14. appStore.initTheme()
  15. // 全局存一下字典数据
  16. const getGlobalCodeList = async () => {
  17. const {
  18. success,
  19. data: { list }
  20. } = await getCodeList({
  21. current: 1,
  22. size: 10000000
  23. })
  24. if (success) {
  25. const formatter = list.map((i) => {
  26. return {
  27. codeName: i.codeName,
  28. codeType: i.codeType,
  29. codeValue: i.codeValue
  30. }
  31. })
  32. sessionStorage.setItem('CODE_ENUM', JSON.stringify(formatter))
  33. }
  34. }
  35. // 存一下公共部门树
  36. const getDeptTreeFunc = async () => {
  37. const { data, success } = await getDeptTree()
  38. if (success) {
  39. sessionStorage.setItem('DEPT_TREE', JSON.stringify(data))
  40. }
  41. }
  42. // 存一下行政区划
  43. const getDistrictFunc = async () => {
  44. const { data, success } = await getDistrictTree()
  45. if (success) {
  46. sessionStorage.setItem('DISTRICT_TREE', JSON.stringify(data))
  47. }
  48. }
  49. // watch(
  50. // () => userStore.getToken,
  51. // (val) => {
  52. // if (val) {
  53. // getGlobalCodeList()
  54. // getDeptTreeFunc()
  55. // getDistrictFunc()
  56. // }
  57. // },
  58. // {
  59. // immediate: true
  60. // }
  61. // )
  62. </script>
  63. <template>
  64. <ConfigGlobal :size="currentSize">
  65. <RouterView :class="greyMode ? `${prefixCls}-grey-mode` : ''" />
  66. </ConfigGlobal>
  67. </template>
  68. <style lang="less">
  69. @prefix-cls: ~'@{adminNamespace}-app';
  70. .size {
  71. width: 100%;
  72. height: 100%;
  73. }
  74. html,
  75. body {
  76. padding: 0 !important;
  77. margin: 0 !important;
  78. overflow: hidden;
  79. .size;
  80. #app {
  81. .size;
  82. }
  83. }
  84. .@{prefix-cls}-grey-mode {
  85. filter: grayscale(100%);
  86. }
  87. </style>