|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="profile" |
| 4 | + :class="{ background: backgroundImage }" |
| 5 | + :style="{ backgroundImage: 'url(' + 'https://cdn.jsdelivr.net/gh/nk-akun/cdn/pictures/71aa072e23f9cfff80fa69f76b2cc441.jpg' + ')' }" |
| 6 | + > |
| 7 | + <div class="profile-info"> |
| 8 | + <avatar |
| 9 | + v-if="backgroundImage" |
| 10 | + :user="user" |
| 11 | + :round="true" |
| 12 | + :has-border="true" |
| 13 | + size="100" |
| 14 | + :extra-style="{ position: 'absolute', top: '50px' }" |
| 15 | + /> |
| 16 | + <avatar v-else :user="user" :round="true" size="100" /> |
| 17 | + <div class="meta"> |
| 18 | + <h1> |
| 19 | + <a :href="'/user/' + user.id">{{ user.nickname }}</a> |
| 20 | + </h1> |
| 21 | + <div v-if="user.description" class="description"> |
| 22 | + <p>{{ user.description }}</p> |
| 23 | + </div> |
| 24 | + <div v-if="user.homePage" class="homepage"> |
| 25 | + <i class="iconfont icon-home"></i> |
| 26 | + <a :href="user.homePage" target="_blank" rel="external nofollow"> |
| 27 | + {{ |
| 28 | + user.homePage |
| 29 | + }} |
| 30 | + </a> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + </div> |
| 35 | +</template> |
| 36 | + |
| 37 | +<script> |
| 38 | +import Avatar from '~/components/Avatar' |
| 39 | +export default { |
| 40 | + components: { Avatar }, |
| 41 | + props: { |
| 42 | + user: { |
| 43 | + type: Object, |
| 44 | + required: true, |
| 45 | + }, |
| 46 | + }, |
| 47 | + computed: { |
| 48 | + backgroundImage() { |
| 49 | + return 'https://cdn.jsdelivr.net/gh/nk-akun/cdn/pictures/dLbeBmTdKa4.jpg' |
| 50 | + }, |
| 51 | + currentUser() { |
| 52 | + return this.$store.state.user.current |
| 53 | + }, |
| 54 | + // 是否是主人态 |
| 55 | + isOwner() { |
| 56 | + const current = this.$store.state.user.current |
| 57 | + return this.user && current && this.user.id === current.id |
| 58 | + }, |
| 59 | + }, |
| 60 | + methods: { |
| 61 | + // async uploadBackground(e) { |
| 62 | + // const files = e.target.files |
| 63 | + // if (files.length <= 0) { |
| 64 | + // return |
| 65 | + // } |
| 66 | + // try { |
| 67 | + // // 上传头像 |
| 68 | + // const file = files[0] |
| 69 | + // const formData = new FormData() |
| 70 | + // formData.append('image', file, file.name) |
| 71 | + // const ret = await this.$axios.post('/api/upload', formData, { |
| 72 | + // headers: { 'Content-Type': 'multipart/form-data' }, |
| 73 | + // }) |
| 74 | + // // 设置头像 |
| 75 | + // await this.$axios.post('/api/user/set/background/image', { |
| 76 | + // backgroundImage: ret.url, |
| 77 | + // }) |
| 78 | + // // 重新加载数据 |
| 79 | + // this.user = await this.$store.dispatch('user/getCurrentUser') |
| 80 | + // this.$message.success('背景设置成功') |
| 81 | + // } catch (e) { |
| 82 | + // this.$message.error(e.message || e) |
| 83 | + // console.error(e) |
| 84 | + // } |
| 85 | + // }, |
| 86 | + }, |
| 87 | +} |
| 88 | +</script> |
| 89 | + |
| 90 | +<style lang="scss" scoped> |
| 91 | +.profile { |
| 92 | + display: flex; |
| 93 | + margin-bottom: 10px; |
| 94 | + position: relative; |
| 95 | +
|
| 96 | + .change-bg { |
| 97 | + position: absolute; |
| 98 | + top: 10px; |
| 99 | + right: 10px; |
| 100 | + opacity: 0.7; |
| 101 | + &:hover { |
| 102 | + opacity: 1; |
| 103 | + } |
| 104 | + } |
| 105 | +
|
| 106 | + .profile-info { |
| 107 | + display: flex; |
| 108 | + width: 100%; |
| 109 | + padding: 10px; |
| 110 | + background: #fff; |
| 111 | +
|
| 112 | + .avatar { |
| 113 | + max-width: 66px; |
| 114 | + max-height: 66px; |
| 115 | + min-width: 66px; |
| 116 | + min-height: 66px; |
| 117 | + } |
| 118 | +
|
| 119 | + .meta { |
| 120 | + margin-left: 18px; |
| 121 | +
|
| 122 | + i { |
| 123 | + margin-right: 6px; |
| 124 | + } |
| 125 | +
|
| 126 | + h1 { |
| 127 | + font-size: 28px; |
| 128 | + font-weight: 700; |
| 129 | + margin-bottom: 6px; |
| 130 | + a { |
| 131 | + color: #000; |
| 132 | + &:hover { |
| 133 | + color: #000; |
| 134 | + text-decoration: underline; |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | +
|
| 139 | + .description { |
| 140 | + font-size: 14px; |
| 141 | + color: #555; |
| 142 | + margin-bottom: 6px; |
| 143 | + } |
| 144 | +
|
| 145 | + .homepage { |
| 146 | + font-size: 14px; |
| 147 | + a { |
| 148 | + color: #555; |
| 149 | + &:hover { |
| 150 | + color: #3273dc; |
| 151 | + text-decoration: underline; |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | +
|
| 158 | + &.background { |
| 159 | + //background-image: url('http://file.mlog.club/bg1.jpg!768_auto'); |
| 160 | + background-size: cover; |
| 161 | + background-position: 50%; |
| 162 | +
|
| 163 | + .profile-info { |
| 164 | + margin-top: 100px; |
| 165 | + background-color: unset; |
| 166 | + background-image: linear-gradient( |
| 167 | + 90deg, |
| 168 | + #dce9f25c, |
| 169 | + rgba(255, 255, 255, 0.76), |
| 170 | + #dce9f25c |
| 171 | + ); |
| 172 | +
|
| 173 | + .meta { |
| 174 | + margin-left: 138px; |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | +} |
| 179 | +</style> |
0 commit comments