import { createSSRApp } from 'vue'; import App from './App.vue'; import * as Pinia from 'pinia'; import 'uno.css'; import { selectDictLabel, selectDictLabels } from './utils/ruoyi'; import { useDict } from '@/utils/dict'; import uviewPlus, { setConfig } from 'uview-plus'; import { navigateBackOrHome, showToast } from '@/utils/common'; import routerGuard from '@/uni_modules/hh-router-guard/src/index'; const uviewProps: any = { config: { loadFontOnce: true, color: { primary: '#37A954', }, }, props: { form: { labelStyle: { color: '#666', fontSize: '30rpx', }, }, input: { color: '#333', fontSize: '30rpx', placeholderStyle: 'color: #ccc; font-weight: 400;', }, textarea: { color: '#333', fontSize: '30rpx', placeholderStyle: 'color: #ccc; font-weight: 400;', }, }, }; export function createApp() { const app = createSSRApp(App); app.use(Pinia.createPinia()); // setConfig(uviewProps) app.use(uviewPlus, () => { return { options: { // 这里可以配置uView的全局属性 ...uviewProps, }, }; }); app.use(routerGuard, { // 白名单:无需登录即可访问的页面路径 whiteList: [ '/pages/login/login', // 登录页 '/pages/plant/index', '/plant/species/config/index', ], // 自定义登录检查函数(返回 true 表示已登录) checkLogin: () => { const token = uni.getStorageSync('token'); return !!token; }, // 登录页面路径 === 需要替换为实际项目中登录页面的路径 loginPath: '/pages/login/login', // 未登录时的处理逻辑 loginHandler: (to: string) => { console.log(to); uni.navigateTo({ url: `/pages/login/login?redirect=${encodeURIComponent(to)}`, }); }, }); app.config.globalProperties.navigateBackOrHome = navigateBackOrHome; app.config.globalProperties.showToast = showToast; app.config.globalProperties.selectDictLabel = selectDictLabel; app.config.globalProperties.selectDictLabels = selectDictLabels; app.config.globalProperties.useDict = useDict; return { app, Pinia, }; }