办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { PropType } from 'vue';
 
import type { Menu } from '#/api/system/menu/model';
 
import { computed, defineComponent } from 'vue';
 
import { Tag } from 'ant-design-vue';
 
export default defineComponent({
  name: 'TreeItem',
  props: {
    data: {
      required: true,
      type: Object as PropType<Menu>,
    },
  },
  setup(props, { expose }) {
    expose();
 
    interface TagProp {
      color: string;
      text: string;
    }
 
    const menuTagProp = computed<TagProp>(() => {
      // 正则判断是否为链接
      if (/^https?:\/\/[^\s/$.?#].\S*$/i.test(props.data.path)) {
        return { color: 'pink', text: '外链' };
      }
      const type = props.data.menuType;
      if (type === 'M') return { color: 'green', text: '目录' };
      if (type === 'C') return { color: 'blue', text: '菜单' };
      if (type === 'F') return { color: '', text: '按钮' };
      return { color: 'error', text: '未知' };
    });
 
    return () => (
      <div class="flex gap-[6px]">
        <span>{props.data.menuName}</span>
        <Tag color={menuTagProp.value.color}>{menuTagProp.value.text}</Tag>
      </div>
    );
  },
});