add mp tag html tap mapping
This commit is contained in:
parent
0bab072861
commit
db5da69e77
|
@ -3,9 +3,9 @@ import './pages/logs/logs'
|
|||
|
||||
//app.js
|
||||
App({
|
||||
onLaunch: function () {
|
||||
onLaunch() {
|
||||
// 展示本地存储能力
|
||||
var logs = wx.getStorageSync('logs') || []
|
||||
let logs = wx.getStorageSync('logs') || []
|
||||
logs.unshift(Date.now())
|
||||
wx.setStorageSync('logs', logs)
|
||||
|
||||
|
|
|
@ -1,16 +1,41 @@
|
|||
import appCss from '../../app.wxss'
|
||||
import indexCss from './index.wxss'
|
||||
import { h, define, WeElement } from 'omi'
|
||||
import { h, WeElement } from 'omi'
|
||||
|
||||
function css() {
|
||||
return appCss + indexCss
|
||||
}
|
||||
|
||||
function render() {
|
||||
const { hasUserInfo,canIUse,userInfo,motto } = Object.assign({}, this.data, this.props)
|
||||
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}`])])])
|
||||
const { hasUserInfo, canIUse, userInfo, motto } = Object.assign(
|
||||
{},
|
||||
this.data,
|
||||
this.props
|
||||
)
|
||||
return h('div', { class: 'container' }, [
|
||||
h('div', { class: 'userinfo' }, [
|
||||
!hasUserInfo && canIUse
|
||||
? h(
|
||||
'button',
|
||||
{ 'open-type': 'getUserInfo', bindgetuserinfo: 'getUserInfo' },
|
||||
['获取头像昵称']
|
||||
)
|
||||
: h(
|
||||
'img',
|
||||
{
|
||||
bindtap: 'bindViewTap',
|
||||
class: 'userinfo-avatar',
|
||||
src: userInfo.avatarUrl,
|
||||
mode: 'cover'
|
||||
},
|
||||
[]
|
||||
),
|
||||
h('span', { class: 'userinfo-nickname' }, [`${userInfo.nickName}`])
|
||||
]),
|
||||
h('div', { class: 'usermotto' }, [
|
||||
h('span', { class: 'user-motto' }, [`${motto}`])
|
||||
])
|
||||
])
|
||||
}
|
||||
|
||||
//index.js
|
||||
|
@ -25,12 +50,12 @@ Page({
|
|||
canIUse: wx.canIUse('button.open-type.getUserInfo')
|
||||
},
|
||||
//事件处理函数
|
||||
bindViewTap: function () {
|
||||
bindViewTap() {
|
||||
wx.navigateTo({
|
||||
url: '../logs/logs'
|
||||
})
|
||||
},
|
||||
onLoad: function () {
|
||||
onLoad() {
|
||||
if (app.globalData.userInfo) {
|
||||
this.setData({
|
||||
userInfo: app.globalData.userInfo,
|
||||
|
@ -58,7 +83,7 @@ Page({
|
|||
})
|
||||
}
|
||||
},
|
||||
getUserInfo: function (e) {
|
||||
getUserInfo(e) {
|
||||
console.log(e)
|
||||
app.globalData.userInfo = e.detail.userInfo
|
||||
this.setData({
|
||||
|
@ -68,4 +93,30 @@ Page({
|
|||
}
|
||||
})
|
||||
|
||||
define('my-app', render)
|
||||
class Element extends WeElement {
|
||||
install() {
|
||||
this.data = {
|
||||
motto: 'Hello World',
|
||||
userInfo: {},
|
||||
hasUserInfo: false,
|
||||
canIUse: wx.canIUse('button.open-type.getUserInfo')
|
||||
}
|
||||
console.log(111)
|
||||
}
|
||||
|
||||
render = render
|
||||
|
||||
beforeRender() {
|
||||
this._useId = 0
|
||||
}
|
||||
|
||||
beforeUpdate() {}
|
||||
|
||||
afterUpdate() {}
|
||||
|
||||
uninstall() {}
|
||||
|
||||
installed() {}
|
||||
}
|
||||
|
||||
customElements.define('my-app', Element)
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
import appCss from '../../app.wxss'
|
||||
import logsCss from './logs.wxss'
|
||||
|
||||
function css(){
|
||||
function css() {
|
||||
return appCss + logsCss
|
||||
}
|
||||
|
||||
function render() {
|
||||
const { logs } = Object.assign({}, this.data, this.props)
|
||||
return (
|
||||
h('view',{'class': `containerlog-list`},[h('block',{},logs.map((log,index)=>{
|
||||
h('text',{'class': `log-item`},[`${index + 1}. ${log}`])
|
||||
}))])
|
||||
)
|
||||
return h('view', { class: 'containerlog-list' }, [
|
||||
h(
|
||||
'block',
|
||||
{},
|
||||
logs.map((log, index) => {
|
||||
h('text', { class: 'log-item' }, [`${index + 1}. ${log}`])
|
||||
})
|
||||
)
|
||||
])
|
||||
}
|
||||
|
||||
//logs.js
|
||||
|
@ -21,7 +25,7 @@ Page({
|
|||
data: {
|
||||
logs: []
|
||||
},
|
||||
onLoad: function () {
|
||||
onLoad() {
|
||||
this.setData({
|
||||
logs: (wx.getStorageSync('logs') || []).map(log => {
|
||||
return util.formatTime(new Date(log))
|
||||
|
@ -29,6 +33,3 @@ Page({
|
|||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,11 @@ const formatTime = date => {
|
|||
const minute = date.getMinutes()
|
||||
const second = date.getSeconds()
|
||||
|
||||
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
|
||||
return (
|
||||
[year, month, day].map(formatNumber).join('/') +
|
||||
' ' +
|
||||
[hour, minute, second].map(formatNumber).join(':')
|
||||
)
|
||||
}
|
||||
|
||||
const formatNumber = n => {
|
||||
|
@ -15,5 +19,5 @@ const formatNumber = n => {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
formatTime: formatTime
|
||||
formatTime
|
||||
}
|
||||
|
|
|
@ -1,18 +1,10 @@
|
|||
function App(){
|
||||
function App() {}
|
||||
|
||||
}
|
||||
function getApp() {}
|
||||
|
||||
function getApp(){
|
||||
function Page() {}
|
||||
|
||||
}
|
||||
|
||||
function Page(){
|
||||
|
||||
}
|
||||
|
||||
function Component(){
|
||||
|
||||
}
|
||||
function Component() {}
|
||||
|
||||
function noop() {}
|
||||
const wx = {}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var htmlToJson = require('html2json').html2json
|
||||
var map = require('./tag-mapping')
|
||||
|
||||
function parse(wxml, fnName) {
|
||||
return walk(htmlToJson(minifier(wxml)), fnName)
|
||||
|
@ -10,9 +11,9 @@ function minifier(wxml) {
|
|||
}).replace(/<!--[\s\S]*?-->/g, '')
|
||||
}
|
||||
|
||||
function walk(node,fnName) {
|
||||
function walk(node, fnName) {
|
||||
return (
|
||||
`function ${fnName}() {
|
||||
`function ${fnName}() {
|
||||
0.0
|
||||
return (
|
||||
${_walk(node)}
|
||||
|
@ -83,17 +84,24 @@ function _walk(node, currentIndex, children) {
|
|||
delete node.attr['wx:for']
|
||||
delete node.attr['wx:for-index']
|
||||
delete node.attr['wx:for-item']
|
||||
|
||||
result = `${ifCond}h('${node.tag}',${stringify(node.attr)},${current})`
|
||||
if (node.tag == 'block') {
|
||||
result = `${ifCond} ${current}`
|
||||
} else {
|
||||
result = `${ifCond}h('${map(node.tag)}',${stringify(node.attr)},${current})`
|
||||
}
|
||||
} else {
|
||||
result = `${ifCond}h('${node.tag}',${stringify(node.attr)},[${c}])`
|
||||
if (node.tag == 'block') {
|
||||
result = `${ifCond} ${c}`
|
||||
} else {
|
||||
result = `${ifCond}h('${map(node.tag)}',${stringify(node.attr)},[${c}])`
|
||||
}
|
||||
}
|
||||
|
||||
if (isThree) {
|
||||
result += ':'
|
||||
}
|
||||
} else {
|
||||
result = `h('${node.tag}',${stringify(node.attr)},[${c}])`
|
||||
result = `h('${map(node.tag)}',${stringify(node.attr)},[${c}])`
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
var tagMapping = {
|
||||
'view': 'div',
|
||||
'text': 'span',
|
||||
'image': 'img',
|
||||
'button':'button',
|
||||
|
||||
}
|
||||
|
||||
function map(key){
|
||||
return tagMapping[key]
|
||||
}
|
||||
|
||||
module.exports = map
|
Loading…
Reference in New Issue