MyProfile.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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-form ref="form" :model="loginUser" label-width="80px">
  11. <el-form-item label="用户 ID">
  12. <el-input v-model="loginUser.userId" style="width: 70%; padding-right: 10px" readonly />
  13. </el-form-item>
  14. <el-form-item label="用户名">
  15. <el-input v-model="loginUser.username" style="width: 70%; padding-right: 10px" readonly />
  16. </el-form-item>
  17. <el-form-item label="显示名">
  18. <el-input v-model="loginUser.screenName" style="width: 70%; padding-right: 10px" readonly />
  19. </el-form-item>
  20. <el-form-item label="手机">
  21. <el-input v-model="loginUser.mobile" style="width: 70%; padding-right: 10px" readonly />
  22. <el-button size="mini" type="info" @click="showUpdateDialog(1)">更新</el-button>
  23. </el-form-item>
  24. <el-form-item label="密码">
  25. <el-input v-model="loginUser.mobile" style="width: 70%; padding-right: 10px" readonly />
  26. <el-button size="mini" type="info" @click="showUpdateDialog(2)">更新</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. </el-card>
  31. </el-row>
  32. </el-col>
  33. <el-col :md="8" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  34. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  35. <el-card class="box-card">
  36. <div slot="header" class="clearfix">
  37. <span>更新我的头像</span>
  38. </div>
  39. <div class="text item">
  40. <el-tooltip class="item" effect="dark" content="点击更新我的头像" placement="top-end">
  41. <el-upload
  42. class="avatar-uploader"
  43. :action="imgOssUrl"
  44. :headers="imgHeaders"
  45. :data="imgData"
  46. :with-credentials="true"
  47. :show-file-list="false"
  48. :before-upload="beforeAvatarUpload"
  49. :on-success="handleAvatarSuccess"
  50. >
  51. <img v-if="loginUser" :src="loginUser.avatarUrl" class="avatar">
  52. <i v-else class="el-icon-plus avatar-uploader-icon" />
  53. </el-upload>
  54. </el-tooltip>
  55. </div>
  56. </el-card>
  57. </el-row>
  58. </el-col>
  59. <el-col :md="8" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  60. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  61. <el-card class="box-card">
  62. <div slot="header" class="clearfix">
  63. <span>我的资料</span>
  64. </div>
  65. <div class="text item">
  66. <el-form ref="form" :model="loginUser" label-width="80px">
  67. <el-form-item label="性别">
  68. <el-input v-model="loginUser.mobile" style="width: 70%; padding-right: 10px" readonly />
  69. </el-form-item>
  70. <el-form-item label="签名">
  71. <el-input
  72. v-model="loginUser.signature"
  73. type="textarea"
  74. rows="3"
  75. style="width: 70%;
  76. padding-right: 10px"
  77. readonly />
  78. </el-form-item>
  79. </el-form>
  80. </div>
  81. </el-card>
  82. </el-row>
  83. </el-col>
  84. <el-dialog
  85. :title="updateTitle"
  86. append-to-body
  87. :visible.sync="updateMobileDialog"
  88. width="30%"
  89. center
  90. >
  91. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; text-align: center">
  92. <el-form ref="form" :model="updateMobileForm" label-width="100px">
  93. <el-form-item label="邮箱/手机号" label-width="100px">
  94. <el-input
  95. v-model="updateMobileForm.principal"
  96. placeholder="请输入邮箱或手机号"
  97. style="width: 45%; padding-right: 10px"
  98. clearable
  99. />
  100. <el-button :disabled="isBtn" @click="sendVerifyCode">{{ code }}</el-button>
  101. </el-form-item>
  102. <el-form-item label="验证码" label-width="90px">
  103. <el-input
  104. v-model="updateMobileForm.verifyCode"
  105. placeholder="请输入短信验证码"
  106. style="padding-right: 1px"
  107. clearable
  108. />
  109. </el-form-item>
  110. <el-form-item label="密码">
  111. <el-input
  112. v-model="updateMobileForm.credential"
  113. type="password"
  114. placeholder="请输入密码"
  115. style="padding-right: 1px"
  116. clearable
  117. />
  118. </el-form-item>
  119. <el-form-item>
  120. <el-button
  121. type="primary"
  122. @click.native="updateUserEmail"
  123. >更新</el-button>
  124. </el-form-item>
  125. </el-form>
  126. </el-row>
  127. </el-dialog>
  128. <el-dialog
  129. :title="updateTitle"
  130. append-to-body
  131. :visible.sync="updatePasswordDialog"
  132. width="30%"
  133. center
  134. >
  135. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; text-align: center">
  136. <el-card class="box-card">
  137. <div class="text item">
  138. <el-form ref="form" :model="updatePasswordForm" label-width="100px">
  139. <el-form-item label="当前密码">
  140. <el-input
  141. v-model="updatePasswordForm.credential"
  142. type="password"
  143. placeholder="请输入当前密码"
  144. style="padding-right: 1px"
  145. clearable
  146. />
  147. </el-form-item>
  148. <el-form-item label="新密码">
  149. <el-input
  150. v-model="updatePasswordForm.credential"
  151. type="password"
  152. placeholder="请输入新密码"
  153. style="padding-right: 1px"
  154. clearable
  155. />
  156. </el-form-item>
  157. <el-form-item label="确认新密码">
  158. <el-input
  159. v-model="updatePasswordForm.credential"
  160. type="password"
  161. placeholder="请确认新密码"
  162. style="padding-right: 1px"
  163. clearable
  164. />
  165. </el-form-item>
  166. <el-form-item>
  167. <el-button
  168. type="primary"
  169. @click.native="updateUserPassword"
  170. >更新</el-button>
  171. </el-form-item>
  172. </el-form>
  173. </div>
  174. </el-card>
  175. </el-row>
  176. </el-dialog>
  177. </el-row>
  178. </template>
  179. <script>
  180. import { userMixin } from 'assets/js/mixin'
  181. import { updateAvatar } from '@/api/account'
  182. import { getAuthedUser, updateAuthedUser } from '@/utils/auth'
  183. import { getAvatarChannelInfo } from '@/api/file'
  184. export default {
  185. name: 'MyProfile',
  186. mixins: [userMixin],
  187. data() {
  188. return {
  189. imgOssUrl: null,
  190. imgHeaders: {
  191. Authorization: ''
  192. },
  193. imgData: {
  194. channelCode: 0
  195. },
  196. coverUrl: null,
  197. // ****************************************************************************************************************
  198. loginUser: null,
  199. updateType: 1,
  200. updateTitle: '',
  201. updateMobileDialog: false,
  202. updateMobileForm: {
  203. principal: null,
  204. verifyCode: null,
  205. credential: null,
  206. captchaCode: null,
  207. channel: 1,
  208. plat: 2
  209. },
  210. updatePasswordDialog: false,
  211. updatePasswordForm: {
  212. principal: null,
  213. verifyCode: null,
  214. credential: null,
  215. captchaCode: null,
  216. channel: 1,
  217. plat: 2
  218. }
  219. }
  220. },
  221. created() {
  222. this.loginUser = getAuthedUser()
  223. getAvatarChannelInfo().then(res => {
  224. if (res.code === 0) {
  225. const resData = res.data
  226. this.imgData.channelCode = resData.channelCode
  227. this.imgOssUrl = resData.ossUrl
  228. this.imgHeaders.Authorization = 'Bearer ' + resData.token
  229. } else {
  230. this.$message.error(res.msg)
  231. }
  232. }).catch(error => {
  233. this.$message.error(error.message)
  234. })
  235. },
  236. mounted() {
  237. },
  238. methods: {
  239. // ****************************************************************************************************************
  240. beforeAvatarUpload(file) {
  241. if (this.imgOssUrl === null) {
  242. this.$message.error('没有可上传的 OSS 地址!')
  243. return
  244. }
  245. const isJPG = file.type === 'image/jpeg'
  246. const isLt2M = file.size / 1024 / 1024 < 2
  247. if (!isJPG) {
  248. this.$message.error('头像文件只能是 JPG 格式!')
  249. }
  250. if (!isLt2M) {
  251. this.$message.error('头像文件大小不能超过 2MB!')
  252. }
  253. return isJPG && isLt2M
  254. },
  255. handleAvatarSuccess(res, file) {
  256. if (res.code === 0) {
  257. const resData = res.data
  258. this.coverUrl = URL.createObjectURL(file.raw)
  259. const avatar = {}
  260. avatar.channelCode = this.imgData.channelCode
  261. avatar.uploadId = resData.uploadId
  262. updateAvatar(avatar).then(resp => {
  263. if (resp.code === 0) {
  264. this.loginUser.avatarUrl = resp.data.url
  265. updateAuthedUser(this.loginUser)
  266. } else {
  267. this.$notify({
  268. title: '头像更新失败',
  269. message: resp.msg,
  270. type: 'warning',
  271. duration: 3000
  272. })
  273. }
  274. })
  275. } else {
  276. this.$notify({
  277. title: '提示',
  278. message: '头像上传失败,请重试!' + res.msg,
  279. type: 'warning',
  280. duration: 3000
  281. })
  282. }
  283. },
  284. // ****************************************************************************************************************
  285. showUpdateDialog(type) {
  286. if (type === 1) {
  287. this.updateType = 1
  288. this.updateTitle = '更新用户手机号'
  289. this.updateMobileDialog = true
  290. } else if (type === 2) {
  291. this.updateType = 2
  292. this.updateTitle = '更新用户密码'
  293. this.updatePasswordDialog = true
  294. }
  295. },
  296. onUpdate() {
  297. if (this.updateType === 1) {
  298. this.updateMobileDialog = false
  299. } else {
  300. this.updatePasswordDialog = false
  301. }
  302. },
  303. sendVerifyCode() {
  304. this.$message.info('发送验证码')
  305. },
  306. updateUserEmail() {
  307. this.$message.info(this.updateMobileForm)
  308. this.updateMobileDialog = false
  309. },
  310. updateUserPassword() {
  311. this.$message.info(this.updatePasswordForm)
  312. this.updatePasswordDialog = false
  313. }
  314. }
  315. }
  316. </script>
  317. <style>
  318. .uploader-example .uploader-btn {
  319. margin-right: 4px;
  320. }
  321. .uploader-example .uploader-list {
  322. max-height: 440px;
  323. overflow: auto;
  324. overflow-x: hidden;
  325. overflow-y: auto;
  326. }
  327. .avatar-uploader .el-upload {
  328. border: 1px dashed #d9d9d9;
  329. border-radius: 6px;
  330. cursor: pointer;
  331. position: relative;
  332. overflow: hidden;
  333. }
  334. .avatar-uploader .el-upload:hover {
  335. border-color: #409EFF;
  336. }
  337. .avatar-uploader-icon {
  338. font-size: 28px;
  339. color: #8c939d;
  340. width: 256px;
  341. height: 256px;
  342. line-height: 178px;
  343. text-align: center;
  344. }
  345. .avatar {
  346. width: 256px;
  347. height: 256px;
  348. display: block;
  349. }
  350. </style>