From 1c06538e9db960dc3b4123b2e5338f81cb4b928d Mon Sep 17 00:00:00 2001 From: SelfRidicule Date: Wed, 13 Mar 2024 15:14:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=8F=E8=BF=B0:=E4=BF=AE=E6=94=B9=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/api/user/user.js | 13 + miniprogram/app.js | 2 +- miniprogram/pages/my/my.js | 114 +++-- miniprogram/pages/my/my.json | 5 +- miniprogram/pages/my/my.wxml | 37 +- miniprogram/pages/my/my.wxss | 70 ++- .../pages/my/personalData/personalData.js | 411 +++++++++--------- .../pages/my/personalData/personalData.wxml | 121 +++--- 8 files changed, 375 insertions(+), 398 deletions(-) create mode 100644 miniprogram/api/user/user.js diff --git a/miniprogram/api/user/user.js b/miniprogram/api/user/user.js new file mode 100644 index 0000000..3e6ecc6 --- /dev/null +++ b/miniprogram/api/user/user.js @@ -0,0 +1,13 @@ +import { + request +} from '../selfRequest'; + + +// 用户信息 +export function userProfile(id) { + return request({ + url: '/user/profile?id=' + id, + method: "get", + }); +} + diff --git a/miniprogram/app.js b/miniprogram/app.js index 5375e41..6aec9cf 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -127,7 +127,7 @@ App({ }); var that = this wx.uploadFile({ - url: that.DOMAIN_NAME + '/dfs/upload', + url: that.DOMAIN_NAME + '/api/dfs/upload', header: { 'Authorization': 'Bearer ' + that.Getopenid() }, diff --git a/miniprogram/pages/my/my.js b/miniprogram/pages/my/my.js index 19c64fa..8c7e05d 100644 --- a/miniprogram/pages/my/my.js +++ b/miniprogram/pages/my/my.js @@ -1,10 +1,17 @@ let app = getApp() + +import { + userProfile +} from "../../api/user/user.js" + Page({ /** * 页面的初始数据 */ data: { + DOMAIN_NAME: app.IMG_NAME, + userDetail: {}, // tabBar param tabBarParam: { selected: 2, @@ -33,58 +40,43 @@ Page({ "text": "我的" }, ], - DOMAIN_NAME: app.IMG_NAME, - customerPages: [ - [{ - listIcon: "icontubiao-1", - zh: "我的活动", - url: "/pages/myActivities/myActivities", - borderRadius: '20rpx 20rpx 0 0' - }, - { - listIcon: "iconqiyexinxi", - zh: "业务申请", - url: "../my/serviceApply/serviceApply" - }, - { - listIcon: "iconqiyexinxi", - zh: "园区建议", - url: "/pages/complaint/complaint", - borderRadius: '0 0 20rpx 20rpx', - marginbottom: true - }, - { - listIcon: "iconzhanghaoshezhi", - zh: "账号设置", - url: "/pages/my/accountSetting/accountSetting", - borderRadius: '20rpx 20rpx 0 0' - }, - { - listIcon: "iconfuwu", - zh: "我的服务", - url: "/pages/enterpriseServices/myServiceList/myServiceList" - }, - { - listIcon: "iconguzhangbaoxiu", - zh: "我的报修", - url: "/pages/parkRepair/parkRepair", - borderRadius: '0 0 20rpx 20rpx' - } - ] + customerPages: [{ + name: "我的活动", + url: "/pages/myActivities/myActivities", + }, + { + name: "业务申请", + url: "/pages/my/serviceApply/serviceApply" + }, + { + name: "园区建议", + url: "/pages/complaint/complaint", + }, + { + name: "账号设置", + url: "/pages/my/accountSetting/accountSetting", + }, + { + name: "我的服务", + url: "/pages/enterpriseServices/myServiceList/myServiceList" + }, + { + name: "我的报修", + url: "/pages/parkRepair/parkRepair", + } ], - memberInfo: {} }, - // 切换tabbar - switchTab(e) { + // 切换tabbar + switchTab(e) { const data = e.currentTarget.dataset console.log('switchTab', data) const url = data.path - if(url == 'pages/meeting/accessControl/accessControl'){ + if (url == 'pages/meeting/accessControl/accessControl') { wx.navigateTo({ url: '/' + url }) - }else{ + } else { wx.switchTab({ url: '/' + url }) @@ -94,29 +86,27 @@ Page({ /** * 生命周期函数--监听页面加载 */ - onLoad(options) {}, + onLoad(options) { + + }, + onShow() { - let that = this - if (wx.getStorageSync('token')) { - app.AjaxRequest('get', { - 'content-type': 'application/json', - 'Authorization': 'Bearer ' + app.Getopenid() - }, '/user/profile', {}, function (res) { - that.setData({ - memberInfo: res.data + let _this = this + let userId = wx.getStorageSync('userId'); + if (userId) { + userProfile(userId).then(res => { + console.log('userProfile', res); + _this.setData({ + userDetail: res.data }) }) } else { app.getlogin() } }, - navDetail(e) { - wx.navigateTo({ - url: e.currentTarget.dataset.url, - }) - }, + navigateTo(e) { - if (wx.getStorageSync('token')) { + if (wx.getStorageSync('userId')) { if (e.currentTarget.dataset.url == '/pages/parkRepair/parkRepair') { wx.switchTab({ url: e.currentTarget.dataset.url, @@ -130,15 +120,17 @@ Page({ app.getlogin() } }, + navpersonalData() { - if (wx.getStorageSync('token')) { + if (wx.getStorageSync('userId')) { wx.navigateTo({ - url: '../my/personalData/personalData', + url: '/pages/my/personalData/personalData', }) } else { wx.navigateTo({ url: '/pages/login/login', }) } - } + }, + }) \ No newline at end of file diff --git a/miniprogram/pages/my/my.json b/miniprogram/pages/my/my.json index 1da73fa..546980f 100644 --- a/miniprogram/pages/my/my.json +++ b/miniprogram/pages/my/my.json @@ -1,3 +1,6 @@ { - "navigationBarTitleText": "我的" + "navigationBarTitleText": "我的", + "usingComponents": { + "van-icon": "@vant/weapp/icon/index" + } } \ No newline at end of file diff --git a/miniprogram/pages/my/my.wxml b/miniprogram/pages/my/my.wxml index 9b9edb1..195af41 100644 --- a/miniprogram/pages/my/my.wxml +++ b/miniprogram/pages/my/my.wxml @@ -1,31 +1,24 @@ - - - - - - {{memberInfo.nickname? memberInfo.nickname:'登录'}} - - + + + + + + + {{userDetail.username? userDetail.username:'登录'}} + + - - - - - - + + + + {{item.name}} + + - diff --git a/miniprogram/pages/my/my.wxss b/miniprogram/pages/my/my.wxss index 60b9841..d431183 100644 --- a/miniprogram/pages/my/my.wxss +++ b/miniprogram/pages/my/my.wxss @@ -1,60 +1,40 @@ @import "../../tabBar.wxss"; -.page { - overflow: auto; - height: 100%; - padding: 0 24rpx; +.containerView.public { + background: #f1f1f1; + padding: 0 20rpx; } -.iconsize{ - font-size: 20pt; +.itemView { + margin-top: 20rpx; + border-radius: 20rpx; + background: white; } -.topBox { - display: flex; +.itemView .itemData { + display: flex; + justify-content: flex-start; + align-items: center; + padding: 28rpx 24rpx; + border-bottom: 1px solid rgb(126, 126, 126, 0.2); } -.topBox>view { - flex: 1; - text-align: center; - color: black; - border-right: 1rpx solid #cccccc; +.itemView .itemData:last-of-type { + border-bottom: none; } -.topBox>view:last-child { - border: none; + +.itemView .avatarImg { + width: 120rpx; + height: 120rpx; + border-radius: 120rpx; + margin-right: 30rpx; } -.btext { - font-size: 20pt; - font-weight: 550; +.itemView .label { + font-size: 30rpx; } -.btext1 { - font-size: 10pt; - margin-top: 10rpx; - color: #4C4C4C; -} - -.my-mainfun-moudel1 { - width: 100%; - margin-top: 20rpx; -} - -.main-item2 { - font-size: 10pt; - padding: 4% 0; - padding-left: 24rpx; - border-bottom: 1rpx solid #F1F1F1; - display: flex; - background: white; -} - -.iconBox { - text-align: center; - width: 10%; -} - -.main-item-text1 { - width: 90%; +.itemView .propOpen { + flex: 1; } \ No newline at end of file diff --git a/miniprogram/pages/my/personalData/personalData.js b/miniprogram/pages/my/personalData/personalData.js index 1de70f6..3f8c484 100644 --- a/miniprogram/pages/my/personalData/personalData.js +++ b/miniprogram/pages/my/personalData/personalData.js @@ -1,222 +1,221 @@ let app = getApp() + +import { + userProfile +} from "../../../api/user/user.js" + Page({ - /** - * 页面的初始数据 - */ - data: { - sex: ['男', '女'], - sexindex: 0, - showDialog: false, - ifName: true, - DOMAIN_NAME: '', - park: [], - parkindex: 0 - }, + data: { + sex: ['男', '女'], + sexindex: 0, + showDialog: false, + ifName: true, + DOMAIN_NAME: app.IMG_NAME, + park: [], + parkindex: 0 + }, - /** - * 生命周期函数--监听页面加载 - */ - onShow(e) { - var that = this - that.setData({ - DOMAIN_NAME: app.img_Name - }) - app.AjaxRequest('get', { - 'content-type': 'application/json' - }, '/park/list', {}, function (res) { - if (res.code == 0) { - res.data.forEach(item => { - let park = that.data.park - park.push(item.parkName) - that.setData({ - park - }) - }) + /** + * 生命周期函数--监听页面加载 + */ + onShow(e) { + var that = this that.setData({ - parkList: res.data + DOMAIN_NAME: app.img_Name }) - that.parkIdtype(res.data, wx.getStorageSync('parkId')) - } - }) - that.getList() - }, + app.AjaxRequest('get', { + 'content-type': 'application/json' + }, '/park/list', {}, function (res) { + if (res.code == 0) { + res.data.forEach(item => { + let park = that.data.park + park.push(item.parkName) + that.setData({ + park + }) + }) + that.setData({ + parkList: res.data + }) + that.parkIdtype(res.data, wx.getStorageSync('parkId')) + } + }) + that.getList() + }, - parkIdtype(list, id) { - list.forEach((item, index) => { - if (item.id == id) { + parkIdtype(list, id) { + list.forEach((item, index) => { + if (item.id == id) { + this.setData({ + parkindex: index + }) + } + }) + }, + + parkChange(e) { + var that = this + that.data.parkList.forEach(item => { + if (that.data.park[e.detail.value] == item.parkName) { + wx.request({ + url: app.DOMAIN_NAME + '/user/profile/update', + data: { + parkId: item.id + }, + method: 'POST', + header: { + 'content-type': 'application/json', + 'Authorization': 'Bearer ' + app.Getopenid() + }, + success(ret) { + if (ret.data.code == 402 || ret.data.code == 401) { + wx.hideLoading() + wx.showModal({ + confirmText: '确认', + content: '身份已过期,需重登录', + success(res) { + wx.removeStorageSync('MemberInfo') + wx.removeStorageSync('token') + if (res.confirm) { + wx.reLaunch({ + url: '/pages/login/login' + }) + } + } + }) + } else if (ret.data.code != 0) { + wx.hideLoading() + wx.showModal({ + confirmText: '好的', + content: ret.data.msg || '服务器开小差去了,请重试', + showCancel: false + }) + } else if (ret.data.code == 0) { + that.setData({ + parkindex: e.detail.value + }) + wx.setStorageSync('parkId', item.id) + wx.setStorageSync('parkName', item.parkName) + wx.navigateBack() + wx.hideLoading() + } + } + }) + } + }) + }, + + cancel() { this.setData({ - parkindex: index + ifName: true }) - } - }) - }, + }, - parkChange(e) { - var that = this - that.data.parkList.forEach(item => { - if (that.data.park[e.detail.value] == item.parkName) { - wx.request({ - url: app.DOMAIN_NAME + '/user/profile/update', - data: { - parkId: item.id - }, - method: 'POST', - header: { + change(e) { + this.setData({ + name: e.currentTarget.dataset.name, + ifName: false + }) + }, + + setValue(e) { + if (this.data.name == '姓名') { + this.setData({ + nickname: e.detail.value + }) + } else { + this.setData({ + post: e.detail.value + }) + } + }, + + confirm() { + let that = this + if (this.data.name == '姓名') { + app.AjaxRequest('POST', { + 'content-type': 'application/json', + 'Authorization': 'Bearer ' + app.Getopenid() + }, '/user/profile/update', { + username: that.data.nickname + }, function (ret) { + that.setData({ + ifName: true + }) + that.getList() + }) + } else { + app.AjaxRequest('POST', { + 'content-type': 'application/json', + 'Authorization': 'Bearer ' + app.Getopenid() + }, '/user/profile/update', { + post: that.data.post + }, function (ret) { + that.setData({ + ifName: true + }) + that.getList() + }) + } + }, + + // 性别选择 + sexChange: function (e) { + let that = this + that.setData({ + sexindex: e.detail.value + }) + app.AjaxRequest('POST', { 'content-type': 'application/json', 'Authorization': 'Bearer ' + app.Getopenid() - }, - success(ret) { - if (ret.data.code == 402 || ret.data.code == 401) { - wx.hideLoading() - wx.showModal({ - confirmText: '确认', - content: '身份已过期,需重登录', - success(res) { - wx.removeStorageSync('MemberInfo') - wx.removeStorageSync('token') - if (res.confirm) { - wx.reLaunch({ - url: '/pages/login/login' - }) - } - } - }) - } else if (ret.data.code != 0) { - wx.hideLoading() - wx.showModal({ - confirmText: '好的', - content: ret.data.msg || '服务器开小差去了,请重试', - showCancel: false - }) - } else if (ret.data.code == 0) { - that.setData({ - parkindex: e.detail.value - }) - wx.setStorageSync('parkId', item.id) - wx.setStorageSync('parkName', item.parkName) - wx.navigateBack() - wx.hideLoading() + }, '/user/profile/update', { + gender: JSON.parse(e.detail.value) + }, function (ret) { + that.getList() + }) + }, + getList() { + let that = this + userProfile(wx.getStorageSync('userId')).then(res => { + that.setData({ + memberInfo: res.data, + sexindex: res.data.sex + }) + }) + }, + chooseimage: function () { + var that = this + let imgUrl = that.data.imgUrl + wx.chooseImage({ + count: 1, // 默认9 + sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 + sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 + success: function (res) { + console.log(res.tempFilePaths[0]) + wx.navigateTo({ + url: '../cropper/cropper?img=' + res.tempFilePaths[0], + }) + } + }) + }, + navCropper() { + this.chooseimage() + }, + exitaccount() { + wx.showModal({ + title: '提示', + content: '确定退出账号吗', + success(res) { + if (res.confirm) { + wx.clearStorageSync() + wx.reLaunch({ + url: '/pages/login/login', + }) + } else if (res.cancel) { + console.log('用户点击取消') + } } - } }) - } - }) - }, - - cancel() { - this.setData({ - ifName: true - }) - }, - - change(e) { - this.setData({ - name: e.currentTarget.dataset.name, - ifName: false - }) - }, - - setValue(e) { - if (this.data.name == '姓名') { - this.setData({ - nickname: e.detail.value - }) - } else { - this.setData({ - post: e.detail.value - }) } - }, - - confirm() { - let that = this - if (this.data.name == '姓名') { - app.AjaxRequest('POST', { - 'content-type': 'application/json', - 'Authorization': 'Bearer ' + app.Getopenid() - }, '/user/profile/update', { - nickname: that.data.nickname - }, function (ret) { - that.setData({ - ifName: true - }) - that.getList() - }) - } else { - app.AjaxRequest('POST', { - 'content-type': 'application/json', - 'Authorization': 'Bearer ' + app.Getopenid() - }, '/user/profile/update', { - post: that.data.post - }, function (ret) { - that.setData({ - ifName: true - }) - that.getList() - }) - } - }, - - // 性别选择 - sexChange: function (e) { - let that = this - that.setData({ - sexindex: e.detail.value - }) - app.AjaxRequest('POST', { - 'content-type': 'application/json', - 'Authorization': 'Bearer ' + app.Getopenid() - }, '/user/profile/update', { - gender: JSON.parse(e.detail.value) - }, function (ret) { - that.getList() - }) - }, - getList() { - let that = this - app.AjaxRequest('get', { - 'content-type': 'application/json', - 'Authorization': 'Bearer ' + app.Getopenid() - }, '/user/profile', {}, function (res) { - that.setData({ - memberInfo: res.data, - sexindex: res.data.sex - }) - }) - }, - chooseimage: function () { - var that = this - let imgUrl = that.data.imgUrl - wx.chooseImage({ - count: 1, // 默认9 - sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 - sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 - success: function (res) { - console.log(res.tempFilePaths[0]) - wx.navigateTo({ - url: '../cropper/cropper?img=' + res.tempFilePaths[0], - }) - } - }) - }, - navCropper() { - this.chooseimage() - }, - exitaccount() { - wx.showModal({ - title: '提示', - content: '确定退出账号吗', - success(res) { - if (res.confirm) { - wx.clearStorageSync() - wx.reLaunch({ - url: '/pages/login/login', - }) - } else if (res.cancel) { - console.log('用户点击取消') - } - } - }) - } }) \ No newline at end of file diff --git a/miniprogram/pages/my/personalData/personalData.wxml b/miniprogram/pages/my/personalData/personalData.wxml index e181975..9c6113e 100644 --- a/miniprogram/pages/my/personalData/personalData.wxml +++ b/miniprogram/pages/my/personalData/personalData.wxml @@ -1,74 +1,71 @@ -