四端上传
This commit is contained in:
1 parent
25bbb5f9c8
commit
c6e2cb4d5b
276 files changed
+17812
-3
No files matched your search
@@ -0,0 +1,84 @@
|
||||
// pages/ChangeUserInfo/ChangeUserInfo.js
|
||||
const api = require('../../utils/api');
|
||||
const store = require('../../utils/store');
|
||||
const config = require('../../config/index');
|
||||
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
data: {
|
||||
// wxml 里直接用它拼头像路径,保持不变
|
||||
BaseURL: config.STATIC_BASE_URL,
|
||||
activeNames: [],
|
||||
username: '',
|
||||
HeadiconID: 0,
|
||||
list: 50,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
app.ready().then(() => this.applyUser());
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.applyUser();
|
||||
},
|
||||
|
||||
applyUser() {
|
||||
const user = store.getUser() || {};
|
||||
this.setData({
|
||||
username: user.nickname || '',
|
||||
HeadiconID: user.headiconId || 0,
|
||||
list: parseInt(store.cfg('profile.headicon_count', '50'), 10) || 50,
|
||||
});
|
||||
},
|
||||
|
||||
onChange(event) {
|
||||
let inputVal = event.detail;
|
||||
// 只保留中英文与数字
|
||||
inputVal = inputVal.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '');
|
||||
// 去掉开头的数字
|
||||
inputVal = inputVal.replace(/^[0-9]+/, '');
|
||||
inputVal = inputVal.substring(0, 8);
|
||||
this.setData({ username: inputVal });
|
||||
},
|
||||
|
||||
selectHeadicon(event) {
|
||||
this.setData({ HeadiconID: event.currentTarget.dataset.index });
|
||||
},
|
||||
|
||||
onChange2(event) {
|
||||
this.setData({ activeNames: event.detail });
|
||||
},
|
||||
|
||||
onConfirm() {
|
||||
const nickname = (this.data.username || '').trim();
|
||||
if (!nickname) {
|
||||
wx.showToast({ title: '请输入用户名', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '确定修改个人资料吗?',
|
||||
confirmColor: '#ff0000',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return;
|
||||
wx.showLoading({ title: '提交中', mask: true });
|
||||
|
||||
api
|
||||
.updateMe({ nickname: nickname, headiconId: this.data.HeadiconID })
|
||||
.then((user) => {
|
||||
store.setUser(user);
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: '成功', icon: 'success', mask: true, duration: 1500 });
|
||||
setTimeout(() => wx.switchTab({ url: '/pages/wode/wode' }), 1500);
|
||||
})
|
||||
.catch((err) => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: err.message || '修改失败', icon: 'none', mask: true });
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-field": "@vant/weapp/field/index",
|
||||
"van-collapse": "@vant/weapp/collapse/index",
|
||||
"van-collapse-item": "@vant/weapp/collapse-item/index",
|
||||
"van-grid": "@vant/weapp/grid/index",
|
||||
"van-grid-item": "@vant/weapp/grid-item/index",
|
||||
"van-image": "@vant/weapp/image/index",
|
||||
"van-button": "@vant/weapp/button/index"
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<van-cell-group>
|
||||
<van-field
|
||||
label="用户名"
|
||||
value="{{username}}"
|
||||
placeholder="请输入用户名"
|
||||
border="true"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
</van-cell-group>
|
||||
|
||||
<van-collapse value="{{ activeNames }}" bind:change="onChange2">
|
||||
<van-collapse-item title="头像" name="1">
|
||||
<view style="display: flex; justify-content: center; padding: 20rpx 0;">
|
||||
<van-image width="120rpx" height="120rpx" src="{{BaseURL}}/Images/Headicons/Headicon{{HeadiconID}}.png" />
|
||||
</view>
|
||||
<van-grid icon-size="80rpx">
|
||||
<scroll-view scroll-y style="min-height: 200rpx;max-height: 620rpx;" class="scroll-area">
|
||||
<van-grid-item wx:for="{{ list }}" wx:key="index" icon="{{BaseURL}}/Images/Headicons/Headicon{{index + 1}}.png" text="{{index + 1}}" bind:click="selectHeadicon" data-index="{{index + 1}}"/>
|
||||
</scroll-view>
|
||||
</van-grid>
|
||||
</van-collapse-item>
|
||||
</van-collapse>
|
||||
|
||||
<view class="button-container" style="text-align: center;padding: 20rpx;">
|
||||
<van-button type="primary" bind:click="onConfirm">确认修改</van-button>
|
||||
</view>
|
||||
@@ -0,0 +1 @@
|
||||
/* pages/ChangeUserInfo/ChangeUserInfo.wxss */
|
||||
Reference in new issue
Block a user