历经半个月潜心研发,我的又一款原创新作vue3+arco
仿macOS桌面pc版os管理系统项目正式完结了。
vite-macos支持macos桌面和window桌面两种模式。
vite-macos采用vite5
搭建项目框架,搭配arco-design
组件库。
vue3-os支持自定义桌面栅格布局引擎、可拖拽桌面图标、多屏分页管理、自定义桌面壁纸主题、毛玻璃虚化背景等功能。
使用vite.js
构建工具搭建项目,依然采用vue3 setup
语法糖编码开发。
import { createApp } from 'vue'
import './style.scss'
import App from './App.vue'
// 引入arco.design组件库
import ArcoDesign from '@arco-design/web-vue'
import '@arco-design/web-vue/dist/arco.css'
// 额外引入图标库
import ArcoIcon from '@arco-design/web-vue/es/icon'
import VEPlus from 've-plus'
import 've-plus/dist/ve-plus.css'
// 引入路由及状态管理
import Router from './router'
import Pinia from './pinia'
const app = createApp(App)
app
.use(ArcoDesign)
.use(ArcoIcon)
.use(VEPlus)
.use(Router)
.use(Pinia)
.mount('#app')
vite采用import.meta.glob
批量导入路由配置。
/**
* 路由管理Router
* @author andy
*/
import { createRouter, createWebHashHistory } from 'vue-router'
import { authState } from '@/pinia/modules/auth'
import Layout from '@/layouts/index.vue'
// 批量导入路由
const modules = import.meta.glob('./modules/*.js', { eager: true })
console.log(modules)
const patchRouters = Object.keys(modules).map(key => modules[key].default).flat()
console.log(patchRouters)
/**
* meta配置
* @param meta.requireAuth 需登录验证页面
*/
const routes = [
{
path: '/',
redirect: '/desktop',
},
...patchRouters,
// 错误模块
{
path: '/:pathMatch(.*)*',
redirect: '/404',
component: Layout,
meta: {
title: '404error',
},
children: [
{
path: '404',
component: () => import('@/views/error/404.vue'),
}
]
},
]
const router = createRouter({
history: createWebHashHistory(),
routes,
})
// 全局路由钩子拦截
router.beforeEach((to, from) => {
const authstate = authState()
// 登录验证
if(to?.meta?.requireAuth && !authstate.authorization) {
console.log('你还未登录!')
return {
path: '/login'
}
}
})
router.afterEach(() => {
// ...
})
router.onError(error => {
console.warn('[Router Error]', error)
})
/**
* 状态管理Pinia
* @author andy
*/
import { createPinia } from 'pinia'
// pinia本地持久化存储
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
export default pinia
<script setup>
import { appState } from '@/pinia/modules/app'
// 引入布局模板
import MacosLayout from './template/macos.vue'
import WindowsLayout from './template/windows.vue'
const appstate = appState()
const DeskLayout = {
macos: MacosLayout,
windows: WindowsLayout
}
</script>
<template>
<div
class="vu__container desktop flexbox flex-alignc flex-justifyc"
:style="{'--themeSkin': appstate.config.skin}"
@contextmenu.prevent
>
<component :is="DeskLayout[appstate.config.layout]" />
</div>
</template>
<template>
<div class="vu__layout flexbox flex-col">
<div class="vu__layout-header">
<Toolbar />
</div>
<div class="vu__layout-body flex1 flexbox">
<Desk />
</div>
<div class="vu__layout-footer">
<Dock />
</div>
<!-- 悬浮球(辅助触控) -->
<Touch />
</div>
</template>
采用全新自研可拖拽排序栅格化布局引擎。
桌面图标支持自定义尺寸、圆角、间距、背景色、标签等功能。
// 自定义变量(桌面图标)
const deskVariable = ref({
'--icon-radius': '8px', // 圆角
'--icon-size': '60px', // 图标尺寸(设置rpx自定义手机设备)
'--icon-gap-col': '30px', // 水平间距
'--icon-gap-row': '30px', // 垂直间距
'--icon-labelSize': '12px', // 标签文字大小
'--icon-labelColor': '#fff', // 标签颜色
'--icon-fit': 'contain', // 图标自适应模式
})
菜单配置
/**
* label 图标标题
* imgico 图标(本地或网络图片) 支持Arco Design内置图标或自定义iconfont图标
* path 跳转路由页面
* link 跳转外部链接
* hideLabel 是否隐藏图标标题
* background 自定义图标背景色
* color 自定义图标颜色
* size 栅格磁贴布局(16种) 1x1 1x2 1x3 1x4、2x1 2x2 2x3 2x4、3x1 3x2 3x3 3x4、4x1 4x2 4x3 4x4
* onClick 点击图标回调函数
*/
const deskMenu = [
{
pid: 20240507001,
list: [
{imgico: markRaw(Today), size: '2x2'},
{imgico: markRaw(Weather), size: '2x2'},
{label: '便签', imgico: markRaw(NoteBook), size: '4x2'},
...
]
},
{
pid: 20240509002,
list: [
{label: 'Appstore', imgico: '/static/mac/appstore.png'},
{label: '地图', imgico: '/static/mac/maps.png'},
...
]
},
{
pid: 20240510001,
list: [
{label: 'Github', imgico: '/static/svg/github.svg', link: 'https://github.com/', background: '#607d8b',},
{label: '码云Gitee', imgico: '/static/svg/gitee.svg', link: 'https://gitee.com/', background: '#bb2124',},
...
]
},
{
uid: 'd141f210-207e-1e8e-9950-9deefac27e48',
list: [
{label: 'Vite^5.3.3', imgico: 'https://vitejs.dev/logo.svg', link: 'https://vitejs.dev/'},
{
label: '编程开发',
children: [
...
]
},
{label: '首页', imgico: markRaw(IconHome), path: '/home', color: '#fff'},
{label: '工作台', imgico: markRaw(IconComputer), path: '/home/dashboard', color: '#fff'},
{
label: '组件',
children: [
...
]
},
{label: 'ChatGPT', imgico: '/static/svg/chatgpt.svg', link: 'https://openai.com/chatgpt/', background: '#15A17F',},
{label: 'Bilibili', imgico: '/static/svg/bilibili.svg', link: 'https://www.bilibili.com/', background: '#ff6899',},
{
label: '个人中心',
children: [
...
]
},
{
label: '设置',
children: [
...
]
},
{
label: '公众号', imgico: markRaw(IconWechat), color: '#07c160',
onClick: () => {
...
}
},
]
}
]
以上就是vite5.x+vue3+arcoDesign开发网页版webos系统的一些分享,希望给大家能有些帮助~
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。