Commit d752ac6a authored by 俞嘉婷's avatar 俞嘉婷

feat: 获取头像昵称

parent 68ecf35c
...@@ -65,6 +65,10 @@ ...@@ -65,6 +65,10 @@
font-size: 30rpx; font-size: 30rpx;
color: #824e00; color: #824e00;
text-shadow: 0px 1rpx 0px rgba(255, 222, 149, 0.96); text-shadow: 0px 1rpx 0px rgba(255, 222, 149, 0.96);
.nickname_input {
margin-top: -8rpx;
}
} }
.tel { .tel {
......
...@@ -4,17 +4,15 @@ import { ComponentWithStore } from "mobx-miniprogram-bindings"; ...@@ -4,17 +4,15 @@ import { ComponentWithStore } from "mobx-miniprogram-bindings";
import { store } from "../../store/store"; import { store } from "../../store/store";
import { dbLogin, request } from "../../utils/request"; import { dbLogin, request } from "../../utils/request";
import { API_PATH } from "../../utils/config"; import { API_PATH } from "../../utils/config";
import { _asyncThrottle } from "../../utils/util"; import { _asyncThrottle, defaultInfo } from "../../utils/util";
const app = getApp<IAppOption>() const app = getApp<IAppOption>()
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
ComponentWithStore({ ComponentWithStore({
storeBindings: { storeBindings: {
store, store,
fields: { fields: {
homeInfo: () => store.homeInfo, homeInfo: () => store.homeInfo,
avatar: () => store.homeInfo.avatar || defaultAvatarUrl,
mobile: () => store.homeInfo.mobile || "-", mobile: () => store.homeInfo.mobile || "-",
}, },
actions: {}, actions: {},
...@@ -24,7 +22,7 @@ ComponentWithStore({ ...@@ -24,7 +22,7 @@ ComponentWithStore({
showAlGetPanel: false, showAlGetPanel: false,
showPhoneBtn: false, showPhoneBtn: false,
userInfo: { userInfo: {
avatarUrl: defaultAvatarUrl, avatarUrl: defaultInfo.avatar,
nickName: '', nickName: '',
}, },
hasUserInfo: false, hasUserInfo: false,
...@@ -70,6 +68,11 @@ ComponentWithStore({ ...@@ -70,6 +68,11 @@ ComponentWithStore({
showGetPanel: channel && first, showGetPanel: channel && first,
showAlGetPanel: channel && !first, showAlGetPanel: channel && !first,
showPhoneBtn: false, showPhoneBtn: false,
userInfo: {
avatarUrl: store.homeInfo.avatar || defaultInfo.avatar,
nickName: store.homeInfo.nickname,
},
hasUserInfo: store.homeInfo.nickname && store.homeInfo.avatar,
}); });
} }
...@@ -83,37 +86,64 @@ ComponentWithStore({ ...@@ -83,37 +86,64 @@ ComponentWithStore({
await this.updateHomeInfo(); await this.updateHomeInfo();
}), }),
// 跳转活动页
jumpActPage: _asyncThrottle(async function () {
wx.switchTab({ url: "/pages/activity/activity" })
}),
closeGetPanel() { closeGetPanel() {
this.setData({ this.setData({
showGetPanel: false, showGetPanel: false,
}); });
// 定位权限未通过 先不做
// this.getPos()
}, },
closeAlGetPanel() { closeAlGetPanel() {
this.setData({ this.setData({
showAlGetPanel: false, showAlGetPanel: false,
}); });
// 定位权限未通过 先不做
// this.getPos()
}, },
// 事件处理函数 getPos() {
bindViewTap() { wx.getLocation({
wx.navigateTo({ type: 'wgs84',
url: '../logs/logs', success (res) {
}) const latitude = res.latitude
const longitude = res.longitude
const speed = res.speed
const accuracy = res.accuracy
}
})
}, },
onChooseAvatar(e: any) { async onChooseAvatar(e: any) {
const {avatarUrl} = e.detail const {avatarUrl} = e.detail
const {nickName} = this.data.userInfo console.log('avatarUrl', avatarUrl);
this.setData({
"userInfo.avatarUrl": avatarUrl, wx.getFileSystemManager().readFile({
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, filePath: e.detail.avatarUrl, //地址
encoding: 'base64', //编码格式
success: async(res) => {
let base64 = 'data:image/png;base64,' + res.data
const data = await store.doImgUpload(base64)
console.info('头像上传后data', data);
if (data) {
await dbLogin({
avatar: data,
});
await this.updateHomeInfo();
}
}
}) })
}, },
onInputChange(e: any) { async onInputChange(e: any) {
const nickName = e.detail.value const nickName = e.detail.value
const {avatarUrl} = this.data.userInfo if (nickName) {
this.setData({ await dbLogin({
"userInfo.nickName": nickName, nickname: nickName,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, });
}) await this.updateHomeInfo();
}
}, },
getUserProfile() { getUserProfile() {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
......
...@@ -6,10 +6,24 @@ ...@@ -6,10 +6,24 @@
</swiper-item> </swiper-item>
</swiper> </swiper>
<view class="user_info"> <view class="user_info">
<view class="avatar_box"> <block wx:if="{{canIUseNicknameComp && !hasUserInfo}}">
<image class="avatar" src="{{avatar}}"></image> <button class="avatar_box" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
</view> <image class="avatar" src="{{userInfo.avatarUrl}}"></image>
<text class="nickname">我的用户名称</text> </button>
<view class="nickname">
<input type="nickname" class="nickname_input" placeholder="请输入昵称" bind:change="onInputChange" />
</view>
</block>
<!-- <block wx:elif="{{!hasUserInfo}}">
<button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile">获取头像昵称</button>
<view wx:else>请使用2.10.4及以上版本基础库</view>
</block> -->
<block wx:else>
<view class="avatar_box">
<image class="avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
</view>
<text class="nickname">{{userInfo.nickName}}</text>
</block>
<text class="tel">手机号:{{homeInfo.mobile || "-"}}</text> <text class="tel">手机号:{{homeInfo.mobile || "-"}}</text>
</view> </view>
<view class="content_info"> <view class="content_info">
...@@ -17,44 +31,14 @@ ...@@ -17,44 +31,14 @@
<view class="content_sub" wx:if="{{!homeInfo.subscribe}}" bindtap="clickSubscribe">订阅消息</view> <view class="content_sub" wx:if="{{!homeInfo.subscribe}}" bindtap="clickSubscribe">订阅消息</view>
<view class="content_act_list"> <view class="content_act_list">
<view class="content_act_list_title">热门活动</view> <view class="content_act_list_title">热门活动</view>
<view class="content_act_list_more">查看更多 ></view> <view class="content_act_list_more" bindtap="jumpActPage">查看更多 ></view>
<view class="act_list"> <view class="act_list">
<image class="act_item" wx:for="{{homeInfo.activities}}" wx:key="{{index}}" src="{{item}}"></image> <image class="act_item" wx:for="{{homeInfo.activities}}" wx:key="{{index}}" src="{{item}}"></image>
</view> </view>
</view> </view>
</view> </view>
<!-- <view class="userinfo">
<block wx:if="{{canIUseNicknameComp && !hasUserInfo}}">
<button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
<image class="avatar" src="{{userInfo.avatarUrl}}"></image>
</button>
<view class="nickname-wrapper">
<text class="nickname-label">昵称</text>
<input type="nickname" class="nickname-input" placeholder="请输入昵称" bind:change="onInputChange" />
</view>
</block>
<block wx:elif="{{!hasUserInfo}}">
<button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
<view wx:else> 请使用2.10.4及以上版本基础库 </view>
</block>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view> -->
<!-- <button bindtap="changeStore">变更数据</button>
<view class="usermotto">
<text class="user-motto">{{homeInfo.name}}</text>
</view> -->
<get-panel wx:if="{{showGetPanel}}" bind:close="closeGetPanel" /> <get-panel wx:if="{{showGetPanel}}" bind:close="closeGetPanel" />
<al-get-panel wx:if="{{showAlGetPanel}}" bind:close="closeAlGetPanel" /> <al-get-panel wx:if="{{showAlGetPanel}}" bind:close="closeAlGetPanel" />
</view> </view>
<!-- 获取手机号按钮 -->
<!--获取手机号按钮--> <button type="primary" wx:if="{{showPhoneBtn}}" class="getPhoneBtn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>
<button \ No newline at end of file
type="primary"
wx:if="{{showPhoneBtn}}"
class="getPhoneBtn"
open-type="getPhoneNumber"
bindgetphonenumber="getPhoneNumber"
></button>
...@@ -25,7 +25,7 @@ class Store { ...@@ -25,7 +25,7 @@ class Store {
// title: '加载中', // title: '加载中',
// mask: true, // mask: true,
// }); // });
const {success, data} = await request({ const { success, data } = await request({
url: API_PATH.index, url: API_PATH.index,
data: params, data: params,
}); });
...@@ -46,7 +46,7 @@ class Store { ...@@ -46,7 +46,7 @@ class Store {
// title: '加载中', // title: '加载中',
// mask: true, // mask: true,
// }); // });
const {success, data} = await request({ const { success, data } = await request({
url: API_PATH.activity, url: API_PATH.activity,
}); });
...@@ -54,6 +54,25 @@ class Store { ...@@ -54,6 +54,25 @@ class Store {
this.activityInfo = data; this.activityInfo = data;
} }
async doImgUpload(img64: string) {
// wx.showLoading({
// title: '加载中',
// mask: true,
// });
const { success, data } = await request({
url: API_PATH.imgUpload,
method: 'POST',
headers: {
"Content-Type": 'application/json'
},
data: { img64 }
});
if (!success) return '';
return data;
}
} }
// 数据仓库 // 数据仓库
......
...@@ -33,4 +33,5 @@ export enum API_PATH { ...@@ -33,4 +33,5 @@ export enum API_PATH {
activity = "home/coop_activity.do", activity = "home/coop_activity.do",
subscribe = "home/coop_subscribe.do", subscribe = "home/coop_subscribe.do",
login = "/wechat/jlb/login", login = "/wechat/jlb/login",
imgUpload = "/customActivity/duiba/imgUploadUrl",
} }
\ No newline at end of file
...@@ -52,3 +52,8 @@ export const _asyncThrottle = (fun, delay = 2000) => { ...@@ -52,3 +52,8 @@ export const _asyncThrottle = (fun, delay = 2000) => {
}; };
}; };
/** 默认信息 */
export const defaultInfo = {
avatar: 'https://yun.duiba.com.cn/polaris/default_avator.8fa52026c1f64f47730d58eb31668c7e5e60bb59.png',
nickname: "用户昵称"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment