123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <template>
- <view class="containar">
- <view class="avatarUrl">
- <button type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseavatar">
- <image :src="avatarUrl?avatarUrl:'../../static/ucenter/big-avatar.png'" class="refreshIcon"></image>
- </button>
- </view>
- <view class="nickname">
- <text>昵称:</text>
- <input type="nickname" class="weui-input" maxlength="10" :value="nickName" @blur="bindblur" placeholder="请输入昵称"
- @input="bindinput" />
- </view>
- <view class="btn">
- <view class="btn-sub" @click="onSubmit">保存</view>
- </view>
- </view>
- </template>
- <script>
- import {pathToBase64} from 'image-tools'
- export default {
- data() {
- return {
- avatarUrl: '',
- nickName: '小狸',
- imgBase:'',
- };
- },
- onLoad(option) {},
- methods: {
- bindblur(e) {
- this.nickName = e.detail.value; // 获取微信昵称
- },
- bindinput(e) {
- this.nickName = e.detail.value; //这里要注意如果只用blur方法的话用户在输入玩昵称后直接点击保存按钮,会出现修改不成功的情况。
- },
- onChooseavatar(e) {
- this.avatarUrl=e.detail.avatarUrl
- pathToBase64(e.detail.avatarUrl).then(res=>{
- this.imgBase=res
- })
- },
- onSubmit() {
- if (this.nickName === '小狸' && this.avatarUrl === '') {
- uni.showToast({
- icon: 'none',
- title: '没有更改,勿提交'
- })
- return false;
- } else {
- let params = {
- nickName: this.nickName,
- avatar: this.imgBase
- }
- this.$store.state.users.avatar = this.avatarUrl
- this.$store.state.users.nickName = this.nickName
- this.$store.commit("UPDATEUSERS", this.$store.state.users)
- this.$http.wxLogin(params).then(res=>{
- if(res.code === 0){
- uni.navigateBack({delta:1})
- }else{
- this.$utils.msg(res.msg);
- }
- }).catch(error=>{
- this.$utils.msg(error);
- });
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .containar {
- height: 100vh;
- background: #fff;
- .avatarUrl {
- display: flex;
- justify-content: center;
- justify-items: center;
- padding-top: 10vh;
- button {
- background: #fff;
- line-height: 80rpx;
- height: 150rpx;
- width: 160rpx;
- margin: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- .refreshIcon {
- height: 110rpx;
- width: 110rpx;
- border-radius: 50%;
- }
- }
- }
- .nickname {
- background: #fff;
- padding: 30rpx;
- margin: 0rpx 20rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- margin-top: 50rpx;
- border: #cccccc solid 1px;
- border-radius: 10rpx;
- .weui-input {
- padding-left: 60rpx;
- }
- }
- .btn {
- width: 100%;
- padding: 0 20rpx;
- box-sizing: border-box;
- .btn-sub {
- margin: 80rpx auto 0;
- height: 90rpx;
- background: #58be6b;
- border-radius: 45rpx;
- line-height: 90rpx;
- text-align: center;
- font-size: 36rpx;
- color: #fff;
- }
- }
- }
- </style>
|