main.ts 2.8 KB

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