main.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { createSSRApp } from 'vue';
  2. import App from './App.vue';
  3. import pinia from './store';
  4. import 'uno.css';
  5. import { previewImage, selectDictLabel, selectDictLabels } from './utils/ruoyi';
  6. import { useDict } from '@/utils/dict';
  7. import uviewPlus, { setConfig } from 'uview-plus';
  8. import { navigateBackOrHome, showToast } from '@/utils/common';
  9. import routerGuard from '@/uni_modules/hh-router-guard/src/index';
  10. import { useInfoStore } from '@/store';
  11. const uviewProps: any = {
  12. config: {
  13. loadFontOnce: true,
  14. color: {
  15. primary: '#37A954',
  16. },
  17. },
  18. props: {
  19. form: {
  20. labelStyle: {
  21. color: '#333',
  22. fontSize: '30rpx',
  23. },
  24. },
  25. input: {
  26. color: '#333',
  27. fontSize: '30rpx',
  28. placeholderStyle: 'color: #ccc; font-weight: 400;',
  29. },
  30. textarea: {
  31. color: '#333',
  32. fontSize: '30rpx',
  33. placeholderStyle: 'color: #ccc; font-weight: 400;',
  34. },
  35. radio: {
  36. activeColor: '#37A954',
  37. },
  38. checkbox: {
  39. activeColor: '#37A954',
  40. },
  41. },
  42. };
  43. export function createApp() {
  44. const app = createSSRApp(App);
  45. app.use(pinia);
  46. // setConfig(uviewProps)
  47. app.use(uviewPlus, () => {
  48. return {
  49. options: {
  50. // 这里可以配置uView的全局属性
  51. ...uviewProps,
  52. },
  53. };
  54. });
  55. app.use(routerGuard, {
  56. // 白名单:无需登录即可访问的页面路径
  57. whiteList: [
  58. '/pages/login/login', // 登录页
  59. '/pages/plant/index',
  60. '/pages/switch/index1',
  61. '/tools/map-draw-area/index',
  62. '/plant/species/config/index',
  63. '/plant/base/gap-base-info/index',
  64. '/plant/base/base-edit/index',
  65. ],
  66. // 自定义登录检查函数(返回 true 表示已登录)
  67. checkLogin: () => {
  68. //检查token是否过期 true代表过期了
  69. const token = useInfoStore().isTokenExpired();
  70. return !token;
  71. },
  72. // 登录页面路径 === 需要替换为实际项目中登录页面的路径
  73. loginPath: '/pages/login/login',
  74. // 未登录时的处理逻辑
  75. loginHandler: (to: string) => {
  76. uni.navigateTo({
  77. url: `/pages/login/login?redirect=${encodeURIComponent(to)}`,
  78. });
  79. },
  80. });
  81. app.config.globalProperties.navigateBackOrHome = navigateBackOrHome;
  82. app.config.globalProperties.showToast = showToast;
  83. app.config.globalProperties.selectDictLabel = selectDictLabel;
  84. app.config.globalProperties.selectDictLabels = selectDictLabels;
  85. app.config.globalProperties.useDict = useDict;
  86. app.config.globalProperties.previewImage = previewImage;
  87. return {
  88. app,
  89. Pinia: { pinia },
  90. };
  91. }