优化 router,支持 isAuth,并添加示例

This commit is contained in:
icssoa
2025-09-23 15:59:19 +08:00
parent 30750cc164
commit 3f988f2c31
10 changed files with 202 additions and 71 deletions

View File

@@ -0,0 +1,41 @@
<template>
<cl-page>
<view class="p-3">
<demo-item :label="t('跳转')">
<cl-button @click="toPush">{{ t("跳转") }}</cl-button>
</demo-item>
<demo-item :label="t('带参数')">
<cl-button @click="toQuery">{{ t("跳转") }}</cl-button>
</demo-item>
<demo-item :label="t('需登录')">
<cl-button @click="toLogin">{{ t("跳转") }}</cl-button>
</demo-item>
</view>
</cl-page>
</template>
<script lang="ts" setup>
import { router, uuid } from "@/cool";
import DemoItem from "../../components/item.uvue";
import { t } from "@/locale";
function toPush() {
router.to("/pages/demo/other/router/query");
}
function toQuery() {
router.push({ path: "/pages/demo/other/router/query", query: { id: uuid() } });
}
function toLogin() {
router.push({
path: "/pages/demo/other/router/query",
query: { id: uuid() },
isAuth: true
});
}
</script>
<style lang="scss" scoped></style>

View File

@@ -0,0 +1,29 @@
<template>
<cl-page>
<view class="p-3">
<demo-item :label="t('ID')">
<cl-text>{{ id ?? "-" }}</cl-text>
</demo-item>
<demo-item :label="t('用户信息')" v-if="!user.isNull()">
<cl-text>{{ userInfo?.nickName ?? "-" }}</cl-text>
</demo-item>
</view>
</cl-page>
</template>
<script lang="ts" setup>
import { t } from "@/locale";
import DemoItem from "../../components/item.uvue";
import { userInfo, useStore } from "@/cool";
const { user } = useStore();
const props = defineProps({
id: {
type: String
}
});
</script>
<style lang="scss" scoped></style>

View File

@@ -46,9 +46,9 @@
<view class="p-3">
<view class="group" v-for="item in data" :key="item.label">
<cl-text :pt="{ className: '!text-sm !text-surface-400 mb-2 ml-2' }">{{
item.label
}}{{ item.children?.length ?? 0 }}</cl-text>
<cl-text :pt="{ className: '!text-sm !text-surface-400 mb-2 ml-2' }"
>{{ item.label }}{{ item.children?.length ?? 0 }}</cl-text
>
<view class="list">
<cl-row :gutter="10">
@@ -461,6 +461,11 @@ const data = computed<Item[]>(() => {
label: "Animation",
icon: "instance-line",
path: "/pages/demo/other/animation"
},
{
label: "Router",
icon: "compass-discover-line",
path: "/pages/demo/other/router/index"
}
]
}