123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <template>
- <div class="edit-me">
- <back-bar title="编辑资料"></back-bar>
- <div class="edit-list">
- <div class="item avatar-item">
- <span class="title">头像</span>
- <div class="cont">
- <img class="user-avatar" @click="$editUserAvatar(userInfo.cover_photo)" v-if="userInfo.cover_photo" :src="userInfo.cover_photo" alt="">
- <div v-else class="user-avatar"
- @click="$editUserAvatar"
- :class="'avatar_bg' + userInfo.user_id % 9"
- :data-name="userInfo.nick_name.slice(0,2).toUpperCase()"
- ></div>
- <i class="el-icon-arrow-right"></i>
- </div>
- </div>
- <div class="item" @click="editName">
- <span class="title">昵称</span>
- <span class="cont">
- {{userInfo.nick_name}} <i class="el-icon-arrow-right"></i>
- </span>
- </div>
- <div class="item" @click="editUserId">
- <span class="title">ID</span>
- <span class="cont">
- {{userInfo.user_name}}<i class="el-icon-arrow-right"></i>
- </span>
- </div>
- </div>
- </div>
- </template>
- <script>
- import { mapState } from 'vuex'
- import backBar from '@/components/backBar'
- import API from '@/api'
- import { Upload, MessageBox } from 'element-ui'
- import Vue from 'vue'
- Vue.component(Upload.name, Upload)
- export default {
- name: 'editMe',
- components: {
- backBar
- },
- data () {
- return {
- }
- },
- computed: {
- ...mapState({
- userInfo: state => {
- return state.userInfo
- }
- })
- },
- methods: {
- editName () {
- MessageBox.prompt('', '修改昵称', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- inputValue: this.userInfo.nick_name
- }).then(({ value }) => {
- if (value.length) {
- API.user.changeNickName({
- nick_name: value
- }).then(({ data }) => {
- this.$store.commit('setUserNickName', value)
- this.$store.commit('updateMemberNickName', {
- userId: this.$store.state.userId,
- nickName: value
- })
- this.$showTips('修改成功')
- })
- }
- }).catch(() => {
- })
- },
- editUserId () {
- MessageBox.prompt('', '修改ID', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- inputValue: this.userInfo.user_name,
- inputPattern: /^[a-zA-Z_0-9-]{5,36}$/i,
- inputErrorMessage: '只能是5-36位数字字母下划线'
- }).then(({ value }) => {
- if (value.length) {
- API.user.changeUserName({
- user_name: value
- }).then(({ data }) => {
- this.$store.commit('setUserUserName', value)
- this.$store.commit('updateMemberNickName', {
- userId: this.$store.state.userId,
- userName: value
- })
- this.$showTips('修改成功')
- })
- }
- }).catch(() => {
- })
- }
- },
- created () {
- }
- }
- </script>
- <style lang="scss" scoped>
- .edit-list{
- background-color: #ffffff;
- .item{
- &.avatar-item{
- height: px2rem(166);
- line-height: px2rem(166);
- }
- padding: 0 px2rem(20);
- height: px2rem(106);
- line-height: px2rem(106);
- position: relative;
- &::after{
- content: '';
- position: absolute;
- height: 1px;
- background-color: #d8d8d8;
- right: 0;
- bottom: 0;
- left: px2rem(20);
- }
- &:last-child{
- &::after{
- display: none;
- }
- }
- }
- .title{
- font-size: px2rem(28);
- color: #000;
- }
- .cont{
- float: right;
- color: #999999;
- font-size: px2rem(28);
- i{
- display: inline-block;
- margin-left: px2rem(10);
- }
- .user-avatar{
- width: px2rem(120);
- height: px2rem(120);
- }
- }
- }
- </style>
|