123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- <template>
- <view>
- <view class="product-window" :class="{'on':isShow}">
- <view class="iconfont icon-guanbi" @click="closeAttr"></view>
- <view class="trip-msg">
- <view class="title">
- 获取您的昵称、头像
- </view>
- <view class="trip">
- 提供具有辨识度的用户中心界面
- </view>
- </view>
- <form @submit="formSubmit">
- <view class="edit">
- <view class="avatar edit-box">
- <view class="left">
- <view class="head">头像</view>
- <!-- <image :src="userInfo.avatar || defaultAvatar" mode=""></image> -->
- <button class="avatar-box" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
- <image :src="userInfo.avatar || defHead"></image>
- </button>
- </view>
- <!-- <view class="iconfont icon-xiangyou"></view> -->
- </view>
- <view class="nickname edit-box">
- <view class="left">
- <view class="head">昵称</view>
- <view class='input'><input type='nickname' :always-embed="true" :adjust-position="true"
- cursor-spacing="30" placeholder-class="pl-sty" placeholder="请输入昵称" name='nickname'
- :maxlength="16" :value='userInfo.nickname'></input>
- </view>
- </view>
- <!-- <view class="iconfont icon-xiangyou"></view> -->
- </view>
- </view>
- <view class="bottom">
- <button class="save" formType="submit" :class="{'open': userInfo.avatar}">
- 保存
- </button>
- </view>
- </form>
- </view>
- <canvas canvas-id="canvas" v-if="canvasStatus"
- :style="{width: canvasWidth + 'px', height: canvasHeight + 'px',position: 'absolute',left:'-100000px',top:'-100000px'}"></canvas>
- <view class="mask" @touchmove.prevent v-if="isShow" @click="closeAttr"></view>
- </view>
- </uni-popup>
- </template>
- <script>
- import store from '@/store/index.js'
- import {
- upload
- } from '@/api/order.js';
- import {
- userEdit,
- } from '@/api/set.js';
- export default {
- props: {
- isShow: {
- type: Boolean,
- value: false
- }
- },
- data() {
- return {
- defHead: require('@/static/error/missing-face.png'),
- userInfo: {
- avatar: '',
- nickname: '',
- },
- canvasStatus: false,
- };
- },
- methods: {
- /**
- * 上传文件
- *
- */
- uploadpic: function() {
- let that = this;
- this.canvasStatus = true
- upload().then((res) => {
- let userInfo = that.userInfo;
- if (userInfo !== undefined) {
- that.userInfo.avatar = res.data.url;
- }
- this.canvasStatus = false
- }, (res) => {
- this.canvasStatus = false
- }, (res) => {
- this.canvasWidth = res.w
- this.canvasHeight = res.h
- });
- },
- // 微信头像获取
- onChooseAvatar(e) {
- const {
- avatarUrl
- } = e.detail;
- let that = this;
- console.log("upimg",avatarUrl);
- uni.uploadFile({
- url: store.state.baseURL + '/api/' + 'upload/image',
- filePath: avatarUrl,
- fileType: 'image',
- name: 'pics',
- formData: {
- 'filename': 'pics'
- },
- header: {
- // #ifdef MP
- "Content-Type": "multipart/form-data",
- // #endif
- "Authori-zation": 'Bearer ' + uni.getStorageSync('token')
- },
- success: (res) => {
- uni.hideLoading();
- console.log(res,'陈宫');
- if (res.statusCode == 403) {
- uni.showToast({
- title: res.data,
- icon: "error"
- })
- } else if (res.statusCode == 413) {
- uni.showToast({
- title: '上传图片失败,请重新上传小尺寸图片',
- icon: "error"
- })
- } else {
- console.log(res,'res');
- let data = res.data ? JSON.parse(res.data) : {};
- console.log(data.status == 200,data,'data');
- if (data.status == 200) {
-
- that.userInfo.avatar = data.data.url
- } else {
- uni.showToast({
- title: data.msg,
- icon: "error"
- })
- }
- }
- },
- fail: (err) => {
- console.log(err,'失败');
- uni.hideLoading();
- uni.showToast({
- title: '上传图片失败',
- icon: "error"
- })
- }
- })
- },
- closeAttr: function() {
- this.$emit('closeEdit');
- },
- /**
- * 提交修改
- */
- formSubmit(e) {
- let that = this
- if (!this.userInfo.avatar) {
- uni.showToast({
- title: '请上传头像',
- icon: "error"
- })
- return
- }
- if (!e.detail.value.nickname) {
- uni.showToast({
- title: '请输入昵称',
- icon: "error"
- })
- return
- }
- this.userInfo.nickname = e.detail.value.nickname
- userEdit(this.userInfo).then(res => {
- this.$emit('editSuccess')
- }).catch(msg => {
- uni.showToast({
- title: msg || '保存失败',
- icon: "error"
- })
- return
- });
- }
- }
- }
- </script>
- <style>
- .pl-sty {
- color: #999999;
- font-size: 30rpx;
- }
- </style>
- <style scoped lang="scss">
- uni-popup{
- height: 100vh;
- }
- .product-window.on {
- transform: translate3d(0, 0, 0);
- }
- .avatar-box{
- width: 48rpx;
- background-color: #fff;
- }
- .avatar-box:after{
- border: none;
- }
- .mask {
- z-index: 100;
- }
- .product-window {
- position: fixed;
- bottom: 0;
- width: 100%;
- left: 0;
- background-color: #fff;
- z-index: 1000;
- border-radius: 20rpx 20rpx 0 0;
- transform: translate3d(0, 100%, 0);
- transition: all .3s cubic-bezier(.25, .5, .5, .9);
- padding: 38rpx 40rpx;
- padding-bottom: 80rpx;
- padding-bottom: calc(80rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
- padding-bottom: calc(80rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
- .icon-guanbi {
- position: absolute;
- top: 30rpx;
- right: 30rpx;
- font-size: 24rpx;
- font-weight: bold;
- color: #999;
- padding: 10rpx;
- }
- .mp-data {
- display: flex;
- align-items: center;
- margin-bottom: 30rpx;
- .mp-name {
- font-size: 28rpx;
- font-weight: bold;
- color: #000000;
- }
- image {
- width: 48rpx;
- height: 48rpx;
- border-radius: 50%;
- margin-right: 16rpx;
- }
- }
- .trip-msg {
- padding-bottom: 32rpx;
- border-bottom: 1px solid #F5F5F5;
- .title {
- font-size: 30rpx;
- font-weight: bold;
- color: #000;
- margin-bottom: 6rpx;
- }
- .trip {
- font-size: 26rpx;
- color: #777777;
- }
- }
- .edit {
- border-bottom: 1px solid #F5F5F5;
- .avatar {
- border-bottom: 1px solid #F5F5F5;
- }
- .nickname {
- .input {
- width: 100%;
- }
- input {
- height: 80rpx;
- }
- }
- .edit-box {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 30rpx;
- padding: 22rpx 0;
- .left {
- display: flex;
- align-items: center;
- flex: 1;
- .head {
- color: rgba(0, 0, 0, 0.9);
- white-space: nowrap;
- margin-right: 60rpx;
- }
- button {
- flex: 1;
- display: flex;
- align-items: center;
- }
- }
- image {
- width: 80rpx;
- height: 80rpx;
- border-radius: 6rpx;
- }
- }
- .icon-xiangyou {
- color: #cfcfcf;
- }
- }
- .bottom {
- display: flex;
- align-items: center;
- justify-content: center;
- .save {
- border: 1px solid #F5F5F5;
- display: flex;
- align-items: center;
- justify-content: center;
- width: 368rpx;
- height: 80rpx;
- border-radius: 12rpx;
- margin-top: 52rpx;
- background-color: #F5F5F5;
- color: #ccc;
- font-size: 30rpx;
- font-weight: bold;
- }
- .save.open {
- border: 1px solid #fff;
- background-color:#007c92;
- color: #fff;
- }
- }
- }
- </style>
|