MyRealname.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <el-row class="movie-list">
  3. <el-col :md="8" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  4. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  5. <el-card class="box-card">
  6. <div slot="header" class="clearfix">
  7. <span>身份证背面照</span>
  8. </div>
  9. <div class="text item">
  10. <el-tooltip class="item" effect="dark" content="点击更新我的头像" placement="top-end">
  11. <el-upload
  12. class="avatar-uploader"
  13. :action="imgOssUrl"
  14. :headers="imgHeaders"
  15. :data="imgData"
  16. :with-credentials="true"
  17. :show-file-list="false"
  18. :before-upload="beforeAvatarUpload"
  19. :on-success="handleAvatarSuccess"
  20. >
  21. <img v-if="loginUser" :src="loginUser.avatarUrl" class="avatar">
  22. <i v-else class="el-icon-plus avatar-uploader-icon" />
  23. </el-upload>
  24. </el-tooltip>
  25. </div>
  26. </el-card>
  27. </el-row>
  28. </el-col>
  29. <el-col :md="8" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  30. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  31. <el-card class="box-card">
  32. <div slot="header" class="clearfix">
  33. <span>身份证反面照</span>
  34. </div>
  35. <div class="text item">
  36. <el-tooltip class="item" effect="dark" content="点击更新我的头像" placement="top-end">
  37. <el-upload
  38. class="avatar-uploader"
  39. :action="imgOssUrl"
  40. :headers="imgHeaders"
  41. :data="imgData"
  42. :with-credentials="true"
  43. :show-file-list="false"
  44. :before-upload="beforeAvatarUpload"
  45. :on-success="handleAvatarSuccess"
  46. >
  47. <img v-if="loginUser" :src="loginUser.avatarUrl" class="avatar">
  48. <i v-else class="el-icon-plus avatar-uploader-icon" />
  49. </el-upload>
  50. </el-tooltip>
  51. </div>
  52. </el-card>
  53. </el-row>
  54. </el-col>
  55. <el-col :md="8" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  56. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  57. <el-card class="box-card">
  58. <div slot="header" class="clearfix">
  59. <span>手持身份证反面照</span>
  60. </div>
  61. <div class="text item">
  62. <el-tooltip class="item" effect="dark" content="点击更新我的头像" placement="top-end">
  63. <el-upload
  64. class="avatar-uploader"
  65. :action="imgOssUrl"
  66. :headers="imgHeaders"
  67. :data="imgData"
  68. :with-credentials="true"
  69. :show-file-list="false"
  70. :before-upload="beforeAvatarUpload"
  71. :on-success="handleAvatarSuccess"
  72. >
  73. <img v-if="loginUser" :src="loginUser.avatarUrl" class="avatar">
  74. <i v-else class="el-icon-plus avatar-uploader-icon" />
  75. </el-upload>
  76. </el-tooltip>
  77. </div>
  78. </el-card>
  79. </el-row>
  80. </el-col>
  81. <el-col :md="8" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  82. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  83. <el-card class="box-card">
  84. <div slot="header" class="clearfix">
  85. <span>我的资料</span>
  86. </div>
  87. <div class="text item">
  88. <el-form ref="form" :model="loginUser" label-width="80px">
  89. <el-form-item label="ID">
  90. <el-input v-model="loginUser.userId" style="padding-right: 1px" readonly />
  91. </el-form-item>
  92. <el-form-item label="显示名">
  93. <el-input v-model="loginUser.screenName" style="padding-right: 1px" readonly />
  94. </el-form-item>
  95. <el-form-item label="签名">
  96. <el-input v-model="loginUser.signature" style="padding-right: 1px" readonly />
  97. </el-form-item>
  98. </el-form>
  99. </div>
  100. </el-card>
  101. </el-row>
  102. </el-col>
  103. </el-row>
  104. </template>
  105. <script>
  106. import { getServerInfo } from '@/api/content'
  107. import { updateAvatar } from '@/api/account'
  108. import { getAuthedUser, updateAuthedUser } from '@/utils/auth'
  109. export default {
  110. name: 'MyRealname',
  111. data() {
  112. return {
  113. imgOssUrl: '',
  114. imgHeaders: {
  115. Authorization: ''
  116. },
  117. imgData: {
  118. channelId: process.env.VUE_APP_UPLOAD_AVATAR_CHANNEL
  119. },
  120. coverUrl: null,
  121. // ****************************************************************************************************************
  122. loginUser: null
  123. }
  124. },
  125. created() {
  126. document.title = '我的实名认证'
  127. this.loginUser = getAuthedUser()
  128. getServerInfo(this.imgData.channelId).then(res => {
  129. if (res.code === 0) {
  130. const resData = res.data
  131. this.imgOssUrl = resData.ossUrl
  132. this.imgHeaders.Authorization = 'Bearer ' + resData.token
  133. } else {
  134. this.$notify({
  135. title: '提示',
  136. message: '获取 OSS 服务器地址失败, 暂时无法上传文件',
  137. type: 'error',
  138. duration: 3000
  139. })
  140. }
  141. }).catch(error => {
  142. this.$notify({
  143. title: '提示',
  144. message: error.message,
  145. type: 'warning',
  146. duration: 3000
  147. })
  148. })
  149. },
  150. mounted() {
  151. },
  152. methods: {
  153. // ****************************************************************************************************************
  154. beforeAvatarUpload(file) {
  155. const isJPG = file.type === 'image/jpeg'
  156. const isLt2M = file.size / 1024 / 1024 < 2
  157. if (!isJPG) {
  158. this.$message.error('头像文件只能是 JPG 格式!')
  159. }
  160. if (!isLt2M) {
  161. this.$message.error('头像文件大小不能超过 2MB!')
  162. }
  163. return isJPG && isLt2M
  164. },
  165. handleAvatarSuccess(res, file) {
  166. if (res.code === 0) {
  167. const resData = res.data
  168. this.coverUrl = URL.createObjectURL(file.raw)
  169. const avatar = {}
  170. avatar.channelId = this.imgData.channelId
  171. avatar.uploadId = resData.uploadId
  172. updateAvatar(avatar).then(resp => {
  173. if (resp.code === 0) {
  174. this.loginUser.avatarUrl = resp.data.url
  175. updateAuthedUser(this.loginUser)
  176. } else {
  177. this.$notify({
  178. title: '头像更新失败',
  179. message: resp.msg,
  180. type: 'warning',
  181. duration: 3000
  182. })
  183. }
  184. })
  185. } else {
  186. this.$notify({
  187. title: '提示',
  188. message: '头像上传失败,请重试!' + res.msg,
  189. type: 'warning',
  190. duration: 3000
  191. })
  192. }
  193. }
  194. // ****************************************************************************************************************
  195. }
  196. }
  197. </script>
  198. <style>
  199. .uploader-example .uploader-btn {
  200. margin-right: 4px;
  201. }
  202. .uploader-example .uploader-list {
  203. max-height: 440px;
  204. overflow: auto;
  205. overflow-x: hidden;
  206. overflow-y: auto;
  207. }
  208. .avatar-uploader .el-upload {
  209. border: 1px dashed #d9d9d9;
  210. border-radius: 6px;
  211. cursor: pointer;
  212. position: relative;
  213. overflow: hidden;
  214. }
  215. .avatar-uploader .el-upload:hover {
  216. border-color: #409EFF;
  217. }
  218. .avatar-uploader-icon {
  219. font-size: 28px;
  220. color: #8c939d;
  221. width: 256px;
  222. height: 256px;
  223. line-height: 178px;
  224. text-align: center;
  225. }
  226. .avatar {
  227. width: 256px;
  228. height: 256px;
  229. display: block;
  230. }
  231. </style>