123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <template>
- <view>
- <u-navbar title="编辑个人信息" >
- <view class="slot-wrap" @click="save">
- 保存
- </view>
- </u-navbar>
- <view class="photo" @click="uploadPhoto">
- <u-avatar class="avatar"
- :src="form.headImg != null ? form.headImg : '../../assets/img/head.png'" size="160">
- </u-avatar>
- <view class="edit-photo">
- <img src="../../../assets/img/md-camera_alt@1x(1).png" alt="">
- </view>
- </view>
- <view class="change">
- 点击更换头像
- </view>
-
- <view class="pet-name">
- <view class="title">
- 昵称
- </view>
- <view class="name">
- <input type="text" name="" id="" v-model="form.nickName" style="text-align: right;">
- </view>
-
- </view>
-
- </view>
- </template>
- <script>
- import * as loginApi from '@/apis/login.js'
- import * as mineApi from '@/apis/parents/mine.js'
-
- export default {
- data() {
- return {
- form: {
- headImg: '',
- nickName: '',
- type: '1'
- }
- }
- },
- onReady() {
- this.getParentsInfo();
- },
- methods: {
- getParentsInfo() {
- uni.showLoading({
- title: "加载中",
- mask: true,
- })
- loginApi.findByOpenId({
- openId: this.carhelp.getOpenId()
- }).then((response) => {
- uni.hideLoading();
- this.form.headImg = response.data.regUser.headImg;
- this.form.nickName = response.data.regUser.nickName;
- }).catch(error => {
- uni.showToast({
- title: error,
- icon: "none"
- })
- })
- },
- save() {
- uni.showLoading({
- title: "加载中",
- mask: true,
- })
- mineApi.updateRegUser(this.form).then((response) => {
- uni.hideLoading();
- uni.navigateBack({
-
- })
- }).catch(error => {
- uni.showToast({
- title: error,
- icon: "none"
- })
- })
- },
- uploadPhoto() {
- let _self = this;
- var token = _self.carhelp.getToken()
-
- const crop = {
- quality: 100,
- width: 600,
- height: 600,
- resize: true
- };
-
- // 上传图片
- uni.chooseImage({
- count: 1,
- crop,
- success: async (res) => {
- //(res);
- let tempFile = res.tempFiles[0],
- avatar_file = {
- // #ifdef H5
- extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
- // #endif
- // #ifndef H5
- extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
- // #endif
- },
- filePath = res.tempFilePaths[0]
-
- // #ifndef APP-PLUS
- //(`filePath=${filePath}`)
-
- //非app端用前端组件剪裁头像,app端用内置的原生裁剪
- let fileData = await new Promise((callback) => {
- uni.navigateTo({
- url: '/pages/components/cropImage?path=' + filePath +
- `&options=${JSON.stringify(crop)}`,
- animationType: "fade-in",
- events: {
- success: url => {
- callback(url)
- }
- }
- });
- })
- // #endif
-
- //返回 base64 图片
- //(fileData);
-
- // var token = _self.carhelp.getToken()
-
- uni.showLoading({
- title: '上传中'
- });
-
- uni.request({
- url: process.car.BASE_URL + "/mobile/student/uploadBase64",
- method: 'POST',
- data: {
- photoBase64Data: fileData
- },
- header: {
- 'Authorization': token,
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success: (res) => {
- let jsonData = res.data;
- _self.form.headImg = jsonData.data;
- // _self.save();
- uni.hideLoading();
- }
- });
- }
- });
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- page{
- background-color: #fff;
- }
- ::v-deep.u-slot-content{
- justify-content: end;
- margin-right: 32rpx;
- color: rgba(13, 186, 199, 1);
- }
- .photo{
- margin: 20px auto 8px;
- width: 160rpx;
- height: 160rpx;
- position: relative;
-
- img{
- width: 100%;
- height: 100%;
- border-radius: 999px;
- }
-
- }
- .edit-photo{
- width: 56rpx;
- height: 56rpx;
- background-color: rgba(78, 141, 246, 1);
- border: 4rpx solid rgba(255, 255, 255, 1);
- text-align: center;
- border-radius: 999px;
- z-index: 999;
- position: absolute;
- right: 0;
- bottom: 0;
-
- img{
-
- width: 32rpx;
- height: 32rpx;
- margin-top: 8rpx;
- }
- }
- .change{
- color: rgba(13, 186, 199, 1);
- text-align: center;
- }
- .pet-name{
- margin-top: 20px;
- padding: 15px;
- border-bottom: 1px solid rgba(244, 244, 244, 1);
- display: flex;
- justify-content: space-between;
- .title{
- color: rgba(16, 16, 16, 1);
- font-weight: bold;
- }
- .name{
- color: rgba(136, 136, 136, 1);
- }
- }
- </style>
|