main.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { createSSRApp } from 'vue';
  2. import App from './App.vue';
  3. import * as Pinia from 'pinia';
  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. },
  35. };
  36. export function createApp() {
  37. const app = createSSRApp(App);
  38. app.use(Pinia.createPinia());
  39. // setConfig(uviewProps)
  40. app.use(uviewPlus, () => {
  41. return {
  42. options: {
  43. // 这里可以配置uView的全局属性
  44. ...uviewProps,
  45. },
  46. };
  47. });
  48. app.use(routerGuard, {
  49. // 白名单:无需登录即可访问的页面路径
  50. whiteList: [
  51. '/pages/login/login', // 登录页
  52. '/pages/plant/index',
  53. ],
  54. // 自定义登录检查函数(返回 true 表示已登录)
  55. checkLogin: () => {
  56. const token = uni.getStorageSync('token');
  57. return !!token;
  58. },
  59. // 登录页面路径 === 需要替换为实际项目中登录页面的路径
  60. loginPath: '/pages/login/login',
  61. // 未登录时的处理逻辑
  62. loginHandler: (to: string) => {
  63. console.log(to);
  64. uni.navigateTo({
  65. url: `/pages/login/login?redirect=${encodeURIComponent(to)}`,
  66. });
  67. },
  68. });
  69. app.config.globalProperties.navigateBackOrHome = navigateBackOrHome;
  70. app.config.globalProperties.showToast = showToast;
  71. app.config.globalProperties.selectDictLabel = selectDictLabel;
  72. app.config.globalProperties.selectDictLabels = selectDictLabels;
  73. app.config.globalProperties.useDict = useDict;
  74. return {
  75. app,
  76. Pinia,
  77. };
  78. }