| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <template>
- <image v-if="url" :src="url" class="cu-avatar radius" :class="[size,{'grid-image':isGroup}]" ></image>
- <view v-if="!url" class="cu-avatar radius avatar-name bg-olive" :class="[size,{'grid-image':isGroup}]">{{start}}</view>
- </template>
- <script setup lang="ts">
- import {computed, ref} from "vue";
- import FetchRequest from "@/api/FetchRequest";
- const host = ref(FetchRequest.getHost())
- interface IProps {
- size?: string
- img?: string
- name?: string
- isGroup?: boolean
- }
- const props = withDefaults(defineProps<IProps>(), {
- size: 'lg' ,
- img: '',
- name: '',
- isGroup: false,
- })
- const url = computed(() => {
- if (props.img?.indexOf('http') > -1) {
- return props.img
- } else if (props.img?.trim() === '') {
- return null
- } else {
- return host.value + props.img
- }
- })
- const start = computed(() => {
- return props.name ? props.name.slice(0,2) : ''
- })
- </script>
- <style scoped>
- .avatar-name{
- font-size: 1rem;
- font-weight: bold;
- }
- .grid-image {
- position: relative;
- overflow: hidden; /* 防止裁剪部分之外的内容显示出来 */
- }
- .grid-image img {
- width: 100%;
- height: 100%;
- display: block;
- position: relative;
- z-index: 1;
- }
- .grid-image::before,
- .grid-image::after {
- content: '';
- position: absolute;
- z-index: 2;
- background: rgba(255, 255, 255, 0.5); /* 根据需要调整蒙板颜色 */
- }
- .grid-image::before {
- top: 0;
- left: 0;
- right: calc(51% - 1px);
- bottom: calc(51% - 1px);
- border-right: 1px solid /* 边框颜色 */;
- border-bottom: 1px solid /* 边框颜色 */;
- }
- .grid-image::after {
- top: 50%;
- left: 50%;
- right: 0;
- bottom: 0;
- border-left: 1px solid /* 边框颜色 */;
- border-top: 1px solid /* 边框颜色 */;
- }
- </style>
|