This commit is contained in:
dntzhang 2018-11-07 17:24:34 +08:00
parent ef1686d2d8
commit 9e28ea6485
1 changed files with 26 additions and 6 deletions

View File

@ -1,12 +1,30 @@
import appCss from '../../app.wxss'
import indexCss from './index.wxss'
import { h, define, WeElement } from 'omi'
function css(){
function css() {
return appCss + indexCss
}
function render(){
return h('view',{'class': `container`},[h('view',{'class': `userinfo`},[!hasUserInfo&&canIUse?h('button',{'open-type': `getUserInfo`,'bindgetuserinfo': `getUserInfo`},[`获取头像昵称`]):h('block',{},[h('image',{'bindtap': `bindViewTap`,'class': `userinfo-avatar`,'src': userInfo.avatarUrl,'mode': `cover`},[]),h('text',{'class': `userinfo-nickname`},[`${userInfo.nickName}`])])]),h('view',{'class': `usermotto`},[h('text',{'class': `user-motto`},[`${motto}`])])])
function render() {
return (
h('view', { 'class': `container` },
[
h('view', { 'class': `userinfo` },
[!hasUserInfo && canIUse ? h('button', { 'open-type': `getUserInfo`, 'bindgetuserinfo': `getUserInfo` }, [`获取头像昵称`]) : h('block', {},
[
h('image', { 'bindtap': `bindViewTap`, 'class': `userinfo-avatar`, 'src': userInfo.avatarUrl, 'mode': `cover` }, []),
h('text', { 'class': `userinfo-nickname` },
[`${userInfo.nickName}`])
])
]),
h('view', { 'class': `usermotto` },
[
h('text', { 'class': `user-motto` },
[`${motto}`])
])
])
)
}
//index.js
@ -21,7 +39,7 @@ Page({
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
bindViewTap: function() {
bindViewTap: function () {
wx.navigateTo({
url: '../logs/logs'
})
@ -32,7 +50,7 @@ Page({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse){
} else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
@ -54,7 +72,7 @@ Page({
})
}
},
getUserInfo: function(e) {
getUserInfo: function (e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
@ -63,3 +81,5 @@ Page({
})
}
})
define('my-app', render)