88 lines
1.8 KiB
Vue
88 lines
1.8 KiB
Vue
<template>
|
|
<div class="demo">
|
|
<div class="bar">
|
|
<t-button size="small" theme="primary" @click="switchUser">切换用户</t-button>
|
|
<span class="status" v-text="`当前:${currentName}`" />
|
|
</div>
|
|
|
|
<p class="tip">
|
|
<span v-popup="popupUserStore.config" v-text="'把鼠标移到这段文字上查看用户资料'" />
|
|
</p>
|
|
|
|
<user-profile-popup />
|
|
<popup />
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { computed, onMounted, ref } from "vue";
|
|
import { Popup } from "timi-web";
|
|
import { UserProfilePopup, popupUserStore } from "timi-tdesign-pc";
|
|
import type { UserView } from "timi-tdesign-pc";
|
|
|
|
/**
|
|
* 演示用数据。
|
|
*
|
|
* popup 内容是真实 DOM 节点,通过 PopupType.EL 挂到 timi-web 的弹层容器里,
|
|
* 所以每次切换用户后直接悬停即可看到最新资料。
|
|
*/
|
|
const userList: UserView[] = [
|
|
{
|
|
id: "demo-001",
|
|
name: "Timi",
|
|
profile: {
|
|
exp: 96,
|
|
sex: 1,
|
|
description: "全栈开发,关注前端工程化。"
|
|
}
|
|
},
|
|
{
|
|
id: "demo-002",
|
|
name: "Mia",
|
|
profile: {
|
|
exp: 32,
|
|
sex: 2,
|
|
description: "产品设计,负责交互与视觉。"
|
|
}
|
|
}
|
|
];
|
|
|
|
const activeIndex = ref(0);
|
|
|
|
const currentName = computed(() => userList[activeIndex.value].name);
|
|
|
|
function switchUser() {
|
|
activeIndex.value = (activeIndex.value + 1) % userList.length;
|
|
popupUserStore.user.value = userList[activeIndex.value];
|
|
}
|
|
|
|
onMounted(() => {
|
|
popupUserStore.user.value = userList[activeIndex.value];
|
|
});
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.demo {
|
|
.bar {
|
|
display: flex;
|
|
gap: .75rem;
|
|
align-items: center;
|
|
}
|
|
|
|
.status {
|
|
font-size: .75rem;
|
|
color: var(--td-text-color-secondary);
|
|
}
|
|
|
|
.tip {
|
|
margin: 1rem 0 0;
|
|
}
|
|
|
|
.tip span {
|
|
cursor: help;
|
|
border-bottom: 1px dashed var(--td-brand-color);
|
|
color: var(--td-brand-color);
|
|
}
|
|
}
|
|
</style>
|