Browse Source

用户个人信息头像修改

zhaoxiaohai 3 years ago
parent
commit
e8128e7cb7

+ 94 - 32
components/My_UploadFiles/index.js

@@ -11,7 +11,11 @@ Component({
         fileList: {
             type: Array
         },
-        /* 上传类型 */
+        /* 父页面传递图片 */
+        attinfos: {
+            type: Object
+        },
+        /* 上传类型 Logo-品牌logo userImage-用户头像 */
         upType: {
             type: String
         },
@@ -28,6 +32,20 @@ Component({
         /* 提示文本 */
         Tips: {
             type: String
+        },
+        /* 显示隐藏 */
+        UploadShow: {
+            type: Boolean,
+            value: false
+        },
+        /* 文本行高 */
+        lineHeight: {
+            type: String,
+            value: "100rpx"
+        },
+        /* 返回图片数据函数 */
+        imageChange: {
+            type: Function
         }
     },
 
@@ -87,6 +105,7 @@ Component({
             let data = {};
             //不同类型图片数据
             if (this.data.upType == 'Logo') {
+                //logo上传
                 data = {
                     "accesstoken": wx.getStorageSync('userData').token,
                     "classname": "system.system.docManage",
@@ -99,6 +118,20 @@ Component({
                         "ftype": "brandlogo"
                     }
                 }
+            } else if (this.data.upType == 'userImage') {
+                //头像上传
+                data = {
+                    "accesstoken": wx.getStorageSync('userData').token,
+                    "classname": "system.system.docManage",
+                    "method": "getFileName",
+                    "content": {
+                        "filename": timestamp,
+                        "filetype": ext,
+                        "ownertable": "tenterprise_users",
+                        "ownerid": wx.getStorageSync('userData').userid,
+                        "ftype": "headportrait"
+                    }
+                }
             }
             //发送请求
             wx.getFileSystemManager().readFile({
@@ -108,8 +141,7 @@ Component({
                     const fileData = result.data
                     _Http.basic(data).then(res => {
                         that.uploadFile(res, fileData)
-                    }).catch(err => {
-                    })
+                    }).catch(err => {})
                 },
                 fail: console.error
             })
@@ -144,9 +176,18 @@ Component({
                             }
                             fileList.push(arr)
                         };
-                        that.setData({
-                            fileList
-                        })
+                        if (that.data.upType != "userImage") {
+                            //普通返回
+                            that.setData({
+                                fileList
+                            })
+                        } else {
+                            that.dleeteDealWith();
+                            // 需要返回到父组件中 userImage
+                            that.triggerEvent("imageChange", {
+                                fileList
+                            })
+                        }
                     }).catch(err => {
                         console.log(err)
                     })
@@ -164,35 +205,56 @@ Component({
                         const {
                             index
                         } = e.detail;
-                        let ownertable = '';
-                        if (that.data.upType == 'Logo') {
-                            //品牌logo
-                            ownertable = "tagents"
-                        };
-                        _Http.basic({
-                            "accesstoken": wx.getStorageSync('userData').token,
-                            "classname": "system.system.docManage",
-                            "method": "deleteDoc",
-                            "content": {
-                                "ownertable": ownertable,
-                                "ownerid": that.data.fileList[index].ownerid,
-                                "tattachmentid": that.data.fileList[index].tattachmentid
-                            }
-                        }).then(s => {
-                            if (s.msg != '成功') return;
-                            console.log(s)
-                            let fileList = that.data.fileList;
-                            fileList.splice(index - 1, 1);
-                            that.setData({
-                                fileList
-                            })
-                        })
-                    } else {
-                        return
+                        that.dleeteDealWith(index);
                     }
                 }
             })
-
+        },
+        /* 处理删除 */
+        dleeteDealWith(index) {
+            const that = this;
+            let ownertable = '';
+            if (that.data.upType == 'Logo') {
+                //品牌logo
+                ownertable = "tagents"
+            } else if (that.data.upType == 'userImage') {
+                //用户头像
+                ownertable = "tenterprise_users"
+            };
+            let content = {}
+            if (that.data.upType != "userImage") {
+                //图片在本页面
+                content = {
+                    "ownertable": ownertable,
+                    "ownerid": that.data.fileList[index].ownerid,
+                    "tattachmentid": that.data.fileList[index].tattachmentid
+                }
+            } else {
+                //图片在父组件
+                content = {
+                    "ownertable": ownertable,
+                    "ownerid": that.data.attinfos.ownerid,
+                    "tattachmentid": that.data.attinfos.tattachmentid
+                }
+            }
+            _Http.basic({
+                "accesstoken": wx.getStorageSync('userData').token,
+                "classname": "system.system.docManage",
+                "method": "deleteDoc",
+                "content": content
+            }).then(s => {
+                if (s.msg != '成功') return;
+                console.log(s)
+                if (that.data.upType != "userImage") {
+                    let fileList = that.data.fileList;
+                    fileList.splice(index - 1, 1);
+                    that.setData({
+                        fileList
+                    })
+                } else {
+                    console.log("删除成功")
+                }
+            })
         },
         /* 验证是否上传附件 */
         VerifyThere() {

+ 12 - 5
components/My_UploadFiles/index.wxml

@@ -1,8 +1,15 @@
 <van-uploader file-list="{{ fileList }}" max-count="{{maxCount}}" bind:after-read="afterRead" deletable="{{ true }}" use-before-read bind:before-read="beforeRead" bind:delete="imagesDelete">
-    <view class="upImage_ltem">
-        <van-icon class="upImage_add" name="plus" />
-    </view>
-    <view class="image-tips" wx:if="{{logoTips}}">
-        <van-icon name="clear" />{{Tips}}
+    <!-- 默认样式 -->
+    <block wx:if="{{UploadShow}}">
+        <view class="upImage_ltem">
+            <van-icon class="upImage_add" name="plus" />
+        </view>
+        <view class="image-tips" wx:if="{{logoTips}}">
+            <van-icon name="clear" />{{Tips}}
+        </view>
+    </block>
+    <!-- 文本样式 -->
+    <view wx:else style="display: flex;align-items: center; height: {{lineHeight}};">
+        <slot></slot>
     </view>
 </van-uploader>

+ 1 - 1
pages/login/index.js

@@ -12,7 +12,7 @@ Page({
      * 页面的初始数据
      */
     data: {
-        pageType: "login", //页面类型 login 手机登录页面 signin 注册页面 firm 商户认证 changeUser 切换用户
+        pageType: "firm", //页面类型 login 手机登录页面 signin 注册页面 firm 商户认证 changeUser 切换用户
         butText: "", //按钮文本
         /* 登录 */
         fphonenumber: 17757394388, //手机号码

+ 1 - 1
pages/login/index.wxml

@@ -61,7 +61,7 @@
             <!-- 品牌LOGO -->
             <view class="input_text_title">品牌LOGO<text>*</text></view>
             <view class="box_mar_bot">
-                <My_UploadFiles id="loadFiles" upType="Logo" maxCount='1' logoTips="{{errTips.logoTips}}" Tips="请上传logo图片"></My_UploadFiles>
+                <My_UploadFiles  id="loadFiles" UploadShow="{{true}}" upType="Logo" maxCount='1' logoTips="{{errTips.logoTips}}" Tips="请上传logo图片"></My_UploadFiles>
             </view>
             <!-- 经营类目 -->
             <view style="position: relative;">

+ 1 - 1
pages/tabbar-pages/user/index.js

@@ -58,7 +58,7 @@ Page({
                 wx.showToast({
                     title: '退出成功',
                 })
-                // wx.setStorageSync('userData', {}) //清空用户数据
+                wx.setStorageSync('userData', {}) //清空用户数据
                 setTimeout(() => {
                     wx.reLaunch({
                         url: '/pages/login/index',

+ 1 - 1
pages/tabbar-pages/user/index.wxml

@@ -22,7 +22,7 @@
                 <van-icon name="arrow" color="#333333" size="34rpx" />
             </view>
         </view>
-        <view style="height: 2rpx; width: 100%; background-color: #979797;"></view>
+        <view style="height: 2rpx; width: 100%; background-color: #979797; opacity: .3;"></view>
     </view>
     <!-- 宫格 -->
     <view class="grid_box">

+ 1 - 0
pages/tabbar-pages/user/index.wxss

@@ -26,6 +26,7 @@
     width: 100%;
     height: 100%;
     border-radius: 50%;
+    box-shadow: 0px 0px 20rpx 0px rgba(0, 0, 0, 0.1);
 }
 
 /* 文本信息 */

+ 11 - 1
pages/userCenter/index.js

@@ -18,7 +18,17 @@ Page({
             userMessage
         })
     },
-
+    /* 修改用户头像 */
+    userImageChange(data) {
+        const attinfos = [{
+            ownerid: data.detail.fileList[0].ownerid,
+            tattachmentid: data.detail.fileList[0].tattachmentid,
+            fobsurl: data.detail.fileList[0].url
+        }]
+        this.setData({
+            'userMessage.attinfos': attinfos
+        })
+    },
     /**
      * 生命周期函数--监听页面初次渲染完成
      */

+ 2 - 1
pages/userCenter/index.json

@@ -1,5 +1,6 @@
 {
   "usingComponents": {
-    "My_GeneralTemplate": "../../components/My_GeneralTemplate/index"
+    "My_GeneralTemplate": "../../components/My_GeneralTemplate/index",
+    "My_UploadFiles":"../../components/My_UploadFiles/index"
   }
 }

+ 14 - 2
pages/userCenter/index.wxml

@@ -1,5 +1,17 @@
 <My_GeneralTemplate>
-    <view>
-        
+    <view class="user_header">
+        <view class="user_header_msg">
+            <!-- 头像 -->
+            <view class="user_headPortrait">
+                <image wx:if="{{userMessage.attinfos[0].fobsurl}}" src="{{userMessage.attinfos[0].fobsurl}}" mode="aspectFill"></image>
+                <image wx:else src="/static/userImage.png" mode="aspectFit"></image>
+            </view>
+            <!-- 修改头像 -->
+            <My_UploadFiles upType="userImage" bind:imageChange="userImageChange" attinfos="{{userMessage.attinfos[0]}}" UploadShow='{{false}}' lineHeight="130rpx">
+                <view class="changeImage">修改头像</view>
+            </My_UploadFiles>
+        </view>
+        <view style="height: 2rpx; width: 100%; background-color: #979797; opacity: 0.3;"></view>
     </view>
+
 </My_GeneralTemplate>

+ 37 - 1
pages/userCenter/index.wxss

@@ -1 +1,37 @@
-/* pages/userCenter/index.wxss */
+/* 用户头部 */
+.user_header {
+    width: 100%;
+    padding: 0 16rpx;
+    box-sizing: border-box;
+}
+
+.user_header_msg {
+    display: flex;
+    justify-content: space-between;
+    width: 100%;
+    height: 130rpx;
+    padding: 0 24rpx;
+    margin-bottom: 40rpx;
+    box-sizing: border-box;
+}
+
+/* 头像 */
+.user_headPortrait {
+    width: 130rpx;
+    height: 100%;
+    border-radius: 50%;
+    margin-right: 30rpx;
+}
+
+.user_headPortrait>image {
+    width: 100%;
+    height: 100%;
+    border-radius: 50%;
+    box-shadow: 0px 0px 20rpx 0px rgba(0, 0, 0, 0.1);
+}
+
+/* 修改头像 */
+.changeImage {
+    font-size: 32rpx;
+    color: #333333;
+}