| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <template>
- <view class="container">
- <!-- #ifdef MP-WEIXIN -->
- <view class="row b-b flex jg">
- <text class="tit">头像</text>
- <image :src="userInfo.avatar" @click.stop="imgsub"></image>
- </view>
- <!-- <view class="row b-b flex jg">
- <text class="tit">头像</text>
- <button type="primary" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" plain="true" style="border: none;position: relative;">
- <image :src="userInfo.avatar" @click="imgsub"></image>
- </button>
- </view> -->
- <view class="row b-b flex">
- <text class="tit">昵称</text>
- <input class="input" v-model="userInfo.nickname" type="nickname" @blur="test" placeholder-class="placeholder" />
- </view>
- <!-- #endif -->
- <!-- #ifndef MP-WEIXIN -->
- <view class="row b-b flex jg">
- <text class="tit">头像</text>
- <image :src="userInfo.avatar" @click.stop="imgsub"></image>
- </view>
- <view class="row b-b flex">
- <text class="tit">昵称</text>
- <input class="input" v-model="userInfo.nickname" type="text" placeholder-class="placeholder" />
- </view>
- <!-- #endif -->
- <view class="row b-b flex">
- <text class="tit">ID</text>
- <input class="input" v-model="userInfo.uid" type="text" disabled="true" placeholder-class="placeholder" />
- </view>
- <view class="submit-box ">
- <view class="submit" @click="edit">确认修改</view>
- <view class="submit submit1" @click="toLogout">退出登录</view>
- </view>
- </view>
- </template>
- <script>
- import uniList from '@/components/uni-list/uni-list.vue';
- import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
- import { mapState, mapMutations } from 'vuex';
- import { logout } from '@/api/set.js';
- import { uploads, edit, upload } from '@/api/user.js';
- export default {
- components: {
- uniList,
- uniListItem
- },
- data() {
- return {
- userInfo: {},
- pics: []
- };
- },
- // onUnload() {
- // if (this.userInfo.nickname == '微信用户') {
- // logout({})
- // .then(e => {
- // obj.logout();
- // })
- // .catch(e => {
- // console.log(e);
- // });
- // }
- // console.log('222');
- // },
- onLoad() {
- this.userInfo = uni.getStorageSync('userInfo') || '';
- console.log(this.userInfo);
- },
- methods: {
- ...mapMutations('user', ['logout']),
- //退出登录
- toLogout() {
- let obj = this;
- uni.showModal({
- content: '确定要退出登录么',
- success: e => {
- if (e.confirm) {
- logout({})
- .then(e => {
- obj.logout();
- uni.switchTab({
- url: '/pages/index/index'
- });
- })
- .catch(e => {
- console.log(e);
- });
- }
- }
- });
- },
- imgsub() {
- let obj = this;
- upload({
- filename: ''
- }).then(res => {
- console.log(res, '上传图片');
- console.log(res[0].url);
- obj.userInfo.avatar = res[0].url;
- });
- },
- test(e) {
- console.log(e.detail, '123456');
- },
- onChooseAvatar(e) {
- this.userInfo.avatar = e.detail.avatarUrl;
- },
- edit() {
- const that = this;
- uni.showLoading({
- title: '提交中...',
- mask: true
- });
- edit({
- avatar: this.userInfo.avatar,
- nickname: this.userInfo.nickname
- })
- .then(e => {
- uni.hideLoading();
- that.$api.msg('修改成功');
- setTimeout(() => {
- uni.switchTab({
- url: '/pages/user/user'
- });
- }, 1000);
- })
- .catch(e => {
- console.log(e);
- that.$api.msg('修改失败');
- });
- }
- }
- };
- </script>
- <style lang="scss">
- page {
- background-color: #f3f3f3;
- min-height: 100%;
- .container {
- height: 100%;
- }
- }
- .row {
- background-color: #fff;
- padding: 42rpx 25rpx;
- font-size: 30rpx;
- color: #333333;
- button {
- width: 80rpx;
- height: 80rpx;
- margin: 0;
- padding: 0;
- border-radius: 50%;
- }
- image {
- width: 80rpx;
- height: 80rpx;
- border-radius: 50%;
- }
- .input {
- text-align: right;
- color: #333333;
- }
- }
- .submit-box {
- padding-top: 157rpx;
- .submit {
- margin: 40rpx auto;
- width: 560rpx;
- background-color: #ee2f72;
- color: #ffffff;
- text-align: center;
- padding: 26rpx 0rpx;
- border-radius: 50rpx;
- }
- .submit1 {
- background-color: #ffffff;
- color: #ee2f72;
- border: 1px solid #ee2f72;
- }
- }
- .jg {
- margin-bottom: 20rpx;
- }
- .out {
- display: flex;
- align-items: center;
- justify-content: center;
- margin: 0 auto 30rpx;
- width: 560rpx;
- height: 80rpx;
- border: 1px solid #58bab0;
- background: #ffffff;
- border-radius: 40px;
- color: #58bab0;
- }
- </style>
|