|
1 | 1 | <script lang="ts" setup>
|
2 |
| -import { Fallback } from '@vben/common-ui'; |
| 2 | +import { reactive } from 'vue'; |
| 3 | +import { useRoute } from 'vue-router'; |
| 4 | +
|
| 5 | +import { Page } from '@vben/common-ui'; |
| 6 | +import { useAccessStore } from '@vben/stores'; |
| 7 | +import { MenuBadge } from '@vben-core/menu-ui'; |
| 8 | +
|
| 9 | +import { Button, Card, Radio, RadioGroup } from 'ant-design-vue'; |
| 10 | +
|
| 11 | +import { useVbenForm } from '#/adapter/form'; |
| 12 | +
|
| 13 | +const colors = [ |
| 14 | + { label: '预设:默认', value: 'default' }, |
| 15 | + { label: '预设:关键', value: 'destructive' }, |
| 16 | + { label: '预设:主要', value: 'primary' }, |
| 17 | + { label: '预设:成功', value: 'success' }, |
| 18 | + { label: '自定义', value: 'bg-gray-200 text-black' }, |
| 19 | +]; |
| 20 | +
|
| 21 | +const route = useRoute(); |
| 22 | +const accessStore = useAccessStore(); |
| 23 | +const menu = accessStore.getMenuByPath(route.path); |
| 24 | +const badgeProps = reactive({ |
| 25 | + badge: menu?.badge as string, |
| 26 | + badgeType: menu?.badge ? 'normal' : (menu?.badgeType as 'dot' | 'normal'), |
| 27 | + badgeVariants: menu?.badgeVariants as string, |
| 28 | +}); |
| 29 | +
|
| 30 | +const [Form] = useVbenForm({ |
| 31 | + handleValuesChange(values) { |
| 32 | + badgeProps.badge = values.badge; |
| 33 | + badgeProps.badgeType = values.badgeType; |
| 34 | + badgeProps.badgeVariants = values.badgeVariants; |
| 35 | + }, |
| 36 | + schema: [ |
| 37 | + { |
| 38 | + component: 'RadioGroup', |
| 39 | + componentProps: { |
| 40 | + buttonStyle: 'solid', |
| 41 | + options: [ |
| 42 | + { label: '点徽标', value: 'dot' }, |
| 43 | + { label: '文字徽标', value: 'normal' }, |
| 44 | + ], |
| 45 | + optionType: 'button', |
| 46 | + }, |
| 47 | + defaultValue: badgeProps.badgeType, |
| 48 | + fieldName: 'badgeType', |
| 49 | + label: '类型', |
| 50 | + }, |
| 51 | + { |
| 52 | + component: 'Input', |
| 53 | + componentProps: { |
| 54 | + maxLength: 4, |
| 55 | + placeholder: '请输入徽标内容', |
| 56 | + style: { width: '200px' }, |
| 57 | + }, |
| 58 | + defaultValue: badgeProps.badge, |
| 59 | + fieldName: 'badge', |
| 60 | + label: '徽标内容', |
| 61 | + }, |
| 62 | + { |
| 63 | + component: 'RadioGroup', |
| 64 | + defaultValue: badgeProps.badgeVariants, |
| 65 | + fieldName: 'badgeVariants', |
| 66 | + label: '颜色', |
| 67 | + }, |
| 68 | + { |
| 69 | + component: 'Input', |
| 70 | + fieldName: 'action', |
| 71 | + }, |
| 72 | + ], |
| 73 | + showDefaultActions: false, |
| 74 | +}); |
| 75 | +
|
| 76 | +function updateMenuBadge() { |
| 77 | + if (menu) { |
| 78 | + menu.badge = badgeProps.badge; |
| 79 | + menu.badgeType = badgeProps.badgeType; |
| 80 | + menu.badgeVariants = badgeProps.badgeVariants; |
| 81 | + } |
| 82 | +} |
3 | 83 | </script>
|
4 | 84 |
|
5 | 85 | <template>
|
6 |
| - <Fallback description="用于徽标示例" status="coming-soon" title="徽标示例" /> |
| 86 | + <Page |
| 87 | + description="菜单项上可以显示徽标,这些徽标可以主动更新" |
| 88 | + title="菜单徽标" |
| 89 | + > |
| 90 | + <Card title="徽标更新"> |
| 91 | + <Form> |
| 92 | + <template #badgeVariants="slotProps"> |
| 93 | + <RadioGroup v-bind="slotProps"> |
| 94 | + <Radio |
| 95 | + v-for="color in colors" |
| 96 | + :key="color.value" |
| 97 | + :value="color.value" |
| 98 | + > |
| 99 | + <div |
| 100 | + :title="color.label" |
| 101 | + class="flex h-[14px] w-[50px] items-center justify-start" |
| 102 | + > |
| 103 | + <MenuBadge |
| 104 | + v-bind="{ ...badgeProps, badgeVariants: color.value }" |
| 105 | + /> |
| 106 | + </div> |
| 107 | + </Radio> |
| 108 | + </RadioGroup> |
| 109 | + </template> |
| 110 | + <template #action> |
| 111 | + <Button type="primary" @click="updateMenuBadge">更新徽标</Button> |
| 112 | + </template> |
| 113 | + </Form> |
| 114 | + </Card> |
| 115 | + </Page> |
7 | 116 | </template>
|
0 commit comments