接入资料修改接口

This commit is contained in:
Abin committed 2026-01-15 19:33:56 +08:00
1 parent fa76d2624d
commit ac773fc1d3
6 files changed
+122 -40

No files matched your search

+58 -27
View File
@@ -1,4 +1,6 @@
// pages/ChangeUserInfo/ChangeUserInfo.js
const MyApi = require('../../Api/api.js')
Page({
/**
@@ -13,11 +15,19 @@ Page({
},
onChange(event) {
let inputVal = event.detail;
// 第一步:只保留中英文和数字(移除所有其他字符)
inputVal = inputVal.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '');
// 第二步:如果以数字开头,则去掉开头的数字(直到遇到非数字)
inputVal = inputVal.replace(/^[0-9]+/, '');
// 第三步:截取前8个字符
inputVal = inputVal.substring(0, 8);
this.setData({
username: event.detail,
username: inputVal
});
console.log("用户名将被修改为:"+this.data.username);
},
selectHeadicon(event) {
this.setData({
HeadiconID: event.currentTarget.dataset.index,
@@ -41,10 +51,52 @@ Page({
confirmColor: '#ff0000', // 确认按钮的文字颜色,默认是"#3CC51F"
success:(res)=> {
if (res.confirm) {
// 用户点击了确认按钮
// 调用函数datachange
//this.datachange()
// 用户点击了确认按钮,发起修改接口
MyApi.ApiChangeInfo(wx.getStorageSync('UserInfoCache').user_openid, this.data.username, this.data.HeadiconID)
.then(result1 => {
//打印服务器返回数据
//console.log(result1);
if (result1.result==="success") {
//这里修改缓存
var tempuesrinfo=wx.getStorageSync('UserInfoCache')
tempuesrinfo.UserName= this.data.username
tempuesrinfo.HeadiconID= this.data.HeadiconID
wx.setStorageSync('UserInfoCache', tempuesrinfo)
wx.showToast({
title: '成功!',
icon: 'success',
mask:true,
duration: 2000
});
setTimeout(function() {
wx.hideToast();
wx.switchTab({
url: '/pages/wode/wode',
})
},2000);
} else {
wx.showToast({
title: '失败!',
icon: 'error',
mask:true,
duration: 2000
});
}
})
.catch(err => {
});
} else if (res.cancel) {
// 用户点击了取消按钮
}
@@ -86,25 +138,4 @@ Page({
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})