feat: 添加@uni-ku/root依赖并配置vite插件

移除页面中的tabbar布局配置
在default.vue中暴露testUniLayoutExposedData
添加App.ku.vue作为根组件
更新pages.json移除tabbar布局配置
This commit is contained in:
feige996
2025-08-24 21:42:04 +08:00
parent 21cbb7970b
commit a108236784
9 changed files with 57 additions and 6 deletions

View File

@@ -144,6 +144,7 @@
"@uni-helper/vite-plugin-uni-pages": "0.3.0",
"@uni-helper/vite-plugin-uni-platform": "0.0.5",
"@uni-ku/bundle-optimizer": "^1.3.3",
"@uni-ku/root": "^1.3.2",
"@unocss/eslint-plugin": "^66.2.3",
"@vue/runtime-core": "3.4.21",
"@vue/tsconfig": "^0.1.3",

18
pnpm-lock.yaml generated
View File

@@ -167,6 +167,9 @@ importers:
'@uni-ku/bundle-optimizer':
specifier: ^1.3.3
version: 1.3.8(postcss@8.5.6)(rollup@4.46.2)(vite@5.2.8(@types/node@20.19.9)(sass@1.77.8)(terser@5.43.1))(vue@3.4.21(typescript@5.8.3))
'@uni-ku/root':
specifier: ^1.3.2
version: 1.3.2(vite@5.2.8(@types/node@20.19.9)(sass@1.77.8)(terser@5.43.1))
'@unocss/eslint-plugin':
specifier: ^66.2.3
version: 66.4.0(eslint@9.32.0(jiti@2.5.1))(typescript@5.8.3)
@@ -1155,11 +1158,13 @@ packages:
'@esbuild/darwin-arm64@0.20.2':
resolution: {integrity: sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==}
engines: {node: '>=12'}
cpu: [arm64]
os: [darwin]
'@esbuild/darwin-x64@0.20.2':
resolution: {integrity: sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==}
engines: {node: '>=12'}
cpu: [x64]
os: [darwin]
'@esbuild/freebsd-arm64@0.20.2':
@@ -1784,6 +1789,7 @@ packages:
'@rollup/rollup-darwin-x64@4.46.2':
resolution: {integrity: sha512-SSj8TlYV5nJixSsm/y3QXfhspSiLYP11zpfwp6G/YDXctf3Xkdnk4woJIF5VQe0of2OjzTt8EsxnJDCdHd2xMA==}
cpu: [x64]
os: [darwin]
'@rollup/rollup-freebsd-arm64@4.46.2':
@@ -2155,6 +2161,11 @@ packages:
peerDependencies:
vite: ^4.0.0 || ^5.0.0
'@uni-ku/root@1.3.2':
resolution: {integrity: sha512-0wgUVATOCaFapkwgjbZxp8X0B8eOw3flg/JDPRBYyIumBbVENbZEa57pOi8hl5ogmVDCm+sdNSFWRXOiQIy3tA==}
peerDependencies:
vite: ^5.0.0
'@unocss-applet/preset-applet@0.10.0':
resolution: {integrity: sha512-bN6jaZo0WMQRvKVDisUXAF4Ig2CVDMe8rk6rZDxzWNFZiReMYK97SxS/JTEFAknWSu4C+GYtut+57NPD2PqHrg==}
peerDependencies:
@@ -8968,6 +8979,13 @@ snapshots:
- ts-node
- vue
'@uni-ku/root@1.3.2(vite@5.2.8(@types/node@20.19.9)(sass@1.77.8)(terser@5.43.1))':
dependencies:
'@vue/compiler-sfc': 3.4.21
chokidar: 3.6.0
jsonc-parser: 3.3.1
vite: 5.2.8(@types/node@20.19.9)(sass@1.77.8)(terser@5.43.1)
'@unocss-applet/preset-applet@0.10.0(@unocss/core@66.4.0)(@unocss/preset-mini@66.0.0)(@unocss/preset-wind3@66.0.0)':
dependencies:
'@unocss/core': 66.4.0

24
src/App.ku.vue Normal file
View File

@@ -0,0 +1,24 @@
<script setup lang="ts">
import { ref } from 'vue'
import FgTabbar from '@/tabbar/index.vue'
import { isPageTabbar } from './tabbar/store'
import { currRoute } from './utils'
const isCurrentPageTabbar = ref(true)
onShow(() => {
console.log('App.ku.vue onShow', currRoute())
const { path } = currRoute()
isCurrentPageTabbar.value = isPageTabbar(path)
})
const helloKuRoot = ref('Hello AppKuVue')
</script>
<template>
<view class="text-center">
{{ helloKuRoot }}这里可以配置全局的东西
</view>
<!-- 顶级 KuRootView -->
<KuRootView />
<FgTabbar v-if="isCurrentPageTabbar" />
</template>

View File

@@ -2,6 +2,11 @@
import { useThemeStore } from '@/store'
const themeStore = useThemeStore()
const testUniLayoutExposedData = ref('testUniLayoutExposedData')
defineExpose({
testUniLayoutExposedData,
})
</script>
<template>

View File

@@ -43,7 +43,6 @@
{
"path": "pages/index/index",
"type": "home",
"layout": "tabbar",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "首页"
@@ -52,7 +51,6 @@
{
"path": "pages/about/about",
"type": "page",
"layout": "tabbar",
"style": {
"navigationBarTitleText": "关于"
}
@@ -92,7 +90,6 @@
{
"path": "pages/me/me",
"type": "page",
"layout": "tabbar",
"style": {
"navigationBarTitleText": "我的"
}

View File

@@ -1,6 +1,5 @@
<route lang="jsonc" type="page">
{
"layout": "tabbar",
"style": {
"navigationBarTitleText": "关于"
}
@@ -49,6 +48,11 @@ onReady(() => {
console.log('onReady:', uniLayout.value) // onReady: Proxy(Object)
console.log('onReady:', uniLayout.value.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
})
// 结论第一次通过onShow获取不到但是可以通过 onReady获取到后面就可以通过onShow获取到了
onShow(() => {
console.log('onShow:', uniLayout.value) // onReady: Proxy(Object)
console.log('onShow:', uniLayout.value?.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
})
function gotoTabbar() {
uni.switchTab({

View File

@@ -1,7 +1,6 @@
<!-- 使用 type="home" 属性设置首页其他页面不需要设置默认为page -->
<route lang="jsonc" type="home">
{
"layout": "tabbar",
"style": {
// 'custom' 表示开启自定义导航栏,默认 'default'
"navigationStyle": "custom",

View File

@@ -1,6 +1,5 @@
<route lang="jsonc" type="page">
{
"layout": "tabbar",
"style": {
// 'custom' 表示开启自定义导航栏,默认 'default'
// "navigationStyle": "custom",

View File

@@ -16,6 +16,8 @@ import UniPlatform from '@uni-helper/vite-plugin-uni-platform'
* @see https://github.com/uni-ku/bundle-optimizer
*/
import Optimization from '@uni-ku/bundle-optimizer'
// https://github.com/uni-ku/root
import UniKuRoot from '@uni-ku/root'
import dayjs from 'dayjs'
import { visualizer } from 'rollup-plugin-visualizer'
import UnoCSS from 'unocss/vite'
@@ -129,6 +131,8 @@ export default ({ command, mode }) => {
directoryAsNamespace: false, // 是否把目录名作为命名空间前缀true 时组件名为 目录名+组件名,
dts: 'src/types/components.d.ts', // 自动生成的组件类型声明文件路径(用于 TypeScript 支持)
}),
// 若存在改变 pages.json 的插件,请将 UniKuRoot 放置其后
UniKuRoot(),
Uni(),
],
define: {