|
|
@@ -1,25 +1,183 @@
|
|
|
<template>
|
|
|
- <el-row>
|
|
|
- <span>我的资料</span>
|
|
|
+ <el-row class="movie-list">
|
|
|
+ <el-col :md="12" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
|
|
|
+ <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <div slot="header" class="clearfix">
|
|
|
+ <span>更新我的头像</span>
|
|
|
+ </div>
|
|
|
+ <div class="text item">
|
|
|
+ <el-tooltip class="item" effect="dark" content="点击更新我的头像" placement="top-end">
|
|
|
+ <el-upload
|
|
|
+ class="avatar-uploader"
|
|
|
+ action="//oss.reghao.cn/"
|
|
|
+ :headers="imgHeaders"
|
|
|
+ :data="imgData"
|
|
|
+ :with-credentials="true"
|
|
|
+ :show-file-list="false"
|
|
|
+ :before-upload="beforeAvatarUpload"
|
|
|
+ :on-success="handleAvatarSuccess"
|
|
|
+ >
|
|
|
+ <img v-if="loginUser" :src="loginUser.avatarUrl" class="avatar">
|
|
|
+ <i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
|
+ </el-upload>
|
|
|
+ </el-tooltip>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-row>
|
|
|
+ </el-col>
|
|
|
+ <el-col :md="12" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
|
|
|
+ <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <div slot="header" class="clearfix">
|
|
|
+ <span>我的资料</span>
|
|
|
+ </div>
|
|
|
+ <div class="text item">
|
|
|
+ <el-form ref="form" :model="loginUser" label-width="80px">
|
|
|
+ <el-form-item label="ID">
|
|
|
+ <el-input v-model="loginUser.userId" style="padding-right: 1px" readonly />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="显示名">
|
|
|
+ <el-input v-model="loginUser.screenName" style="padding-right: 1px" readonly />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="签名">
|
|
|
+ <el-input v-model="loginUser.signature" style="padding-right: 1px" readonly />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-row>
|
|
|
+ </el-col>
|
|
|
</el-row>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { getServerInfo } from '@/api/content'
|
|
|
+import { updateAvatar } from '@/api/account'
|
|
|
+import { getAuthedUser, updateAuthedUser } from '@/utils/auth'
|
|
|
+
|
|
|
export default {
|
|
|
name: 'MyProfile',
|
|
|
data() {
|
|
|
return {
|
|
|
+ imgOssUrl: null,
|
|
|
+ imgHeaders: {
|
|
|
+ Authorization: ''
|
|
|
+ },
|
|
|
+ imgData: {
|
|
|
+ channelId: 4
|
|
|
+ },
|
|
|
+ coverUrl: null,
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ loginUser: null
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
- document.title = '我的资料'
|
|
|
+ this.loginUser = getAuthedUser()
|
|
|
+
|
|
|
+ getServerInfo(this.imgData.channelId).then(res => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ const resData = res.data
|
|
|
+ this.imgOssUrl = resData.ossUrl
|
|
|
+ this.imgHeaders.Authorization = 'Bearer ' + resData.token
|
|
|
+ } else {
|
|
|
+ this.$notify({
|
|
|
+ title: '提示',
|
|
|
+ message: '获取 OSS 服务器地址失败, 暂时无法上传文件',
|
|
|
+ type: 'error',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch(error => {
|
|
|
+ this.$notify({
|
|
|
+ title: '提示',
|
|
|
+ message: error.message,
|
|
|
+ type: 'warning',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ })
|
|
|
},
|
|
|
mounted() {
|
|
|
},
|
|
|
methods: {
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ beforeAvatarUpload(file) {
|
|
|
+ const isJPG = file.type === 'image/jpeg'
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2
|
|
|
+ if (!isJPG) {
|
|
|
+ this.$message.error('头像文件只能是 JPG 格式!')
|
|
|
+ }
|
|
|
+ if (!isLt2M) {
|
|
|
+ this.$message.error('头像文件大小不能超过 2MB!')
|
|
|
+ }
|
|
|
+ return isJPG && isLt2M
|
|
|
+ },
|
|
|
+ handleAvatarSuccess(res, file) {
|
|
|
+ if (res.code === 0) {
|
|
|
+ const resData = res.data
|
|
|
+ this.coverUrl = URL.createObjectURL(file.raw)
|
|
|
+
|
|
|
+ const avatar = {}
|
|
|
+ avatar.avatarUrl = resData.url
|
|
|
+ updateAvatar(avatar).then(resp => {
|
|
|
+ if (resp.code === 0) {
|
|
|
+ this.loginUser.avatarUrl = resData.url
|
|
|
+ updateAuthedUser(this.loginUser)
|
|
|
+ } else {
|
|
|
+ this.$notify({
|
|
|
+ title: '头像更新失败',
|
|
|
+ message: resp.msg,
|
|
|
+ type: 'warning',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.$notify({
|
|
|
+ title: '提示',
|
|
|
+ message: '视频封面上传失败,请重试!' + res.msg,
|
|
|
+ type: 'warning',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // ****************************************************************************************************************
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
-<style scoped>
|
|
|
+<style>
|
|
|
+.uploader-example .uploader-btn {
|
|
|
+ margin-right: 4px;
|
|
|
+}
|
|
|
+.uploader-example .uploader-list {
|
|
|
+ max-height: 440px;
|
|
|
+ overflow: auto;
|
|
|
+ overflow-x: hidden;
|
|
|
+ overflow-y: auto;
|
|
|
+}
|
|
|
+
|
|
|
+.avatar-uploader .el-upload {
|
|
|
+ border: 1px dashed #d9d9d9;
|
|
|
+ border-radius: 6px;
|
|
|
+ cursor: pointer;
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+}
|
|
|
+.avatar-uploader .el-upload:hover {
|
|
|
+ border-color: #409EFF;
|
|
|
+}
|
|
|
+.avatar-uploader-icon {
|
|
|
+ font-size: 28px;
|
|
|
+ color: #8c939d;
|
|
|
+ width: 256px;
|
|
|
+ height: 256px;
|
|
|
+ line-height: 178px;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+.avatar {
|
|
|
+ width: 256px;
|
|
|
+ height: 256px;
|
|
|
+ display: block;
|
|
|
+}
|
|
|
</style>
|