@ -1,79 +0,0 @@
|
|||||||
const html5Entities = require('../vendors/html5-entities')
|
|
||||||
const { windowWidth } = wx.getSystemInfoSync()
|
|
||||||
|
|
||||||
module.exports = item => {
|
|
||||||
// decode html entities
|
|
||||||
if (item.type === 'Text') {
|
|
||||||
item.content = html5Entities.decode(item.content)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// <video> and <audio>
|
|
||||||
if (item.tagName === 'video' || item.tagName === 'audio') {
|
|
||||||
item.wxTag = item.tagName
|
|
||||||
|
|
||||||
if (!item.attributes.src) {
|
|
||||||
item.children.some(child => {
|
|
||||||
if (child.tagName === 'source') {
|
|
||||||
item.attributes.src = child.attributes.src
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// <br>
|
|
||||||
if (item.tagName === 'br') {
|
|
||||||
item.wxTag = 'text'
|
|
||||||
item.children = [{ type: 'Text', content: '\n' }]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// other tags
|
|
||||||
if (['b', 'big', 'i', 'small', 'tt', 'abbr', 'acronym', 'cite', 'code', 'dfn', 'em', 'kbd', 'strong', 'samp', 'time', 'var', 'a', 'bdo', 'map', 'object', 'q', 'script', 'span', 'sub', 'sup', 'button', 'input', 'label', 'select', 'textarea'].indexOf(item.tagName) !== -1) {
|
|
||||||
item.wxTag = 'text'
|
|
||||||
} else {
|
|
||||||
item.wxTag = 'view'
|
|
||||||
}
|
|
||||||
|
|
||||||
// <img>
|
|
||||||
if (item.tagName === 'img') {
|
|
||||||
item.wxTag = 'image'
|
|
||||||
|
|
||||||
let width, height
|
|
||||||
|
|
||||||
if (!item.attributes.style) item.attributes.style = {}
|
|
||||||
|
|
||||||
if (item.attributes.style.width && item.attributes.style.width.indexOf('px')) {
|
|
||||||
width = item.attributes.style.width.slice(0, -2)
|
|
||||||
} else if (item.attributes.width) {
|
|
||||||
width = item.attributes.width
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.attributes.style.height && item.attributes.style.height.indexOf('px')) {
|
|
||||||
height = item.attributes.style.height.slice(0, -2)
|
|
||||||
} else if (item.attributes.height) {
|
|
||||||
height = item.attributes.height
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.attributes.style) {
|
|
||||||
delete item.attributes.style.width
|
|
||||||
delete item.attributes.style.height
|
|
||||||
}
|
|
||||||
|
|
||||||
delete item.attributes.width
|
|
||||||
delete item.attributes.height
|
|
||||||
|
|
||||||
if (width && width < windowWidth) {
|
|
||||||
item.attributes.style.width = width + 'px'
|
|
||||||
if (height) item.attributes.style.height = height + 'px'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// generate inline style string
|
|
||||||
if (item.attributes && item.attributes.style) {
|
|
||||||
item.attributes.styleString = Object.keys(item.attributes.style).map(key => key + ': ' + item.attributes.style[key]).join(';')
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
// 七牛图片裁剪
|
|
||||||
|
|
||||||
const { pixelRatio, windowWidth } = wx.getSystemInfoSync()
|
|
||||||
const width = pixelRatio * windowWidth
|
|
||||||
|
|
||||||
module.exports = (domain, quality) =>
|
|
||||||
item => {
|
|
||||||
if (item.tagName === 'img' && item.attributes.src.indexOf(domain) !== -1 && item.attributes.src.indexOf('?') === -1) {
|
|
||||||
item.attributes.src += '?imageView2/2/w/' + width
|
|
||||||
if (quality) item.attributes.src += '/q/' + quality
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
// <a> to <navigator>
|
|
||||||
|
|
||||||
const url = require('../vendors/url')
|
|
||||||
const Router = require('../vendors/Router')
|
|
||||||
|
|
||||||
module.exports = (domain, routes) =>
|
|
||||||
item => {
|
|
||||||
if (item.tagName === 'a') {
|
|
||||||
const u = url.parse(item.attributes.href)
|
|
||||||
if (u.hostname === domain) {
|
|
||||||
const router = new Router(routes)
|
|
||||||
const route = router.match(u.pathname)
|
|
||||||
if (route) {
|
|
||||||
item.wxTag = 'navigator'
|
|
||||||
item.url = url.format({ pathname: route.path, query: Object.assign(u.query, route.params, route.options) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
const { resolve } = require('../vendors/url')
|
|
||||||
|
|
||||||
module.exports = baseUrl =>
|
|
||||||
item => {
|
|
||||||
if (['img', 'video', 'audio', 'source'].indexOf(item.tagName) !== -1) {
|
|
||||||
if (item.attributes.src) item.attributes.src = resolve(baseUrl, item.attributes.src)
|
|
||||||
} else if (item.tagName === 'a') {
|
|
||||||
item.attributes.href = resolve(baseUrl, item.attributes.href)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
const himalaya = require('./vendors/himalaya')
|
|
||||||
const defaultEachFn = require('./each/default')
|
|
||||||
const resolveUrl = require('./each/resolveUrl')
|
|
||||||
|
|
||||||
class HtmlParser {
|
|
||||||
constructor(html, { baseUrl } = {}) {
|
|
||||||
this.nodes = himalaya.parse(html)
|
|
||||||
if (baseUrl) this.each(resolveUrl(baseUrl))
|
|
||||||
this.each(defaultEachFn)
|
|
||||||
}
|
|
||||||
|
|
||||||
each(fn) {
|
|
||||||
this._each(fn, this.nodes)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
_each(fn, nodes) {
|
|
||||||
nodes.forEach((item, ...args) => {
|
|
||||||
fn(item, ...args)
|
|
||||||
|
|
||||||
if (item.children) this._each(fn, item.children)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
filter(fn) {
|
|
||||||
this.nodes = this._filter(fn, this.nodes)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
_filter(fn, nodes) {
|
|
||||||
return nodes.filter((item, ...args) => {
|
|
||||||
const result = fn(item, ...args)
|
|
||||||
if (result && item.children) item.children = this._filter(fn, item.children)
|
|
||||||
return result
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
map(fn) {
|
|
||||||
this.nodes = this._map(fn, this.nodes)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
_map(fn, nodes) {
|
|
||||||
return nodes.map((item, ...args) => {
|
|
||||||
item = fn(item, ...args)
|
|
||||||
if (item.children) item.children = this._map(fn, item.children)
|
|
||||||
return item
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = HtmlParser
|
|
@ -1,7 +0,0 @@
|
|||||||
<import src="nodes.wxml" />
|
|
||||||
|
|
||||||
<template name="html-view">
|
|
||||||
<view class="html-view">
|
|
||||||
<template is="html-view-nodes" data="{{nodes: data}}" />
|
|
||||||
</view>
|
|
||||||
</template>
|
|
@ -1,21 +0,0 @@
|
|||||||
@import "reset.wxss";
|
|
||||||
|
|
||||||
.html-view {
|
|
||||||
font-size: 36rpx;
|
|
||||||
color: #333;
|
|
||||||
line-height: 1.6;
|
|
||||||
overflow-wrap: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
.img, .video {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
|
|
||||||
.th, .td {
|
|
||||||
border: 1rpx solid #333;
|
|
||||||
padding: 10rpx;
|
|
||||||
}
|
|
@ -1,241 +0,0 @@
|
|||||||
<template name="html-view-nodes">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-1" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-1" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-1" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-1">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-2" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-2" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-2" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-2">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-3" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-3" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-3" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-3">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-4" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-4" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-4" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-4">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-5" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-5" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-5" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-5">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-6" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-6" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-6" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-6">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-7" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-7" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-7" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-7">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-8" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-8" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-8" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-8">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-9" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-9" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-9" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-9">
|
|
||||||
<block wx:for="{{nodes}}" wx:key="">
|
|
||||||
<block wx:if="{{item.type === 'Text'}}">{{item.content}}</block>
|
|
||||||
<block wx:elif="{{item.type === 'Element'}}">
|
|
||||||
<view wx:if="{{item.wxTag === 'view'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-10" data="{{nodes: item.children}}" />
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<text wx:elif="{{item.wxTag === 'text'}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-10" data="{{nodes: item.children}}" />
|
|
||||||
</text>
|
|
||||||
|
|
||||||
<navigator wx:elif="{{item.wxTag === 'navigator'}}" url="{{item.url}}" class="{{item.tagName}} {{item.attributes.className}}" style="{{item.attributes.styleString}}">
|
|
||||||
<template is="html-view-nodes-10" data="{{nodes: item.children}}" />
|
|
||||||
</navigator>
|
|
||||||
|
|
||||||
<image wx:if="{{item.wxTag === 'image'}}" src="{{item.attributes.src}}" class="img" mode="widthFix" style="{{item.attributes.styleString}}" />
|
|
||||||
|
|
||||||
<video wx:elif="{{item.wxTag === 'video'}}" src="{{item.attributes.src}}" class="video"></video>
|
|
||||||
|
|
||||||
<audio wx:elif="{{item.wxTag === 'audio'}}" src="{{item.attributes.src}}" class="audio" controls></audio>
|
|
||||||
</block>
|
|
||||||
</block>
|
|
||||||
</template>
|
|
||||||
<template name="html-view-nodes-10"></template>
|
|
@ -1,306 +0,0 @@
|
|||||||
/*
|
|
||||||
css reset
|
|
||||||
based on https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css
|
|
||||||
*/
|
|
||||||
|
|
||||||
.html {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* children of the <head> element all have display:none */
|
|
||||||
.head {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.meta {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.style {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.script {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* generic block-level elements */
|
|
||||||
|
|
||||||
.body {
|
|
||||||
display: block;
|
|
||||||
margin: 8rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.p {
|
|
||||||
display: block;
|
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.div {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.layer {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.article, .aside, .footer, .header, .hgroup, .main, .nav, .section {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.marquee {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.address {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.blockquote {
|
|
||||||
display: block;
|
|
||||||
margin: 1em 40rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.figcaption {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.figure {
|
|
||||||
display: block;
|
|
||||||
margin: 1em 40rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.q {
|
|
||||||
display: inline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.q:before {
|
|
||||||
content: open-quote;
|
|
||||||
}
|
|
||||||
|
|
||||||
.q:after {
|
|
||||||
content: close-quote;
|
|
||||||
}
|
|
||||||
|
|
||||||
.center {
|
|
||||||
display: block;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hr {
|
|
||||||
display: block;
|
|
||||||
margin: 0.5em 0;
|
|
||||||
border: 1rpx inset;
|
|
||||||
}
|
|
||||||
|
|
||||||
.map {
|
|
||||||
display: inline;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* heading elements */
|
|
||||||
|
|
||||||
.h1 {
|
|
||||||
display: block;
|
|
||||||
font-size: 2em;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 0.67em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.h2 {
|
|
||||||
display: block;
|
|
||||||
font-size: 1.5em;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 0.83em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.h3 {
|
|
||||||
display: block;
|
|
||||||
font-size: 1.17em;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.h4 {
|
|
||||||
display: block;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 1.33em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.h5 {
|
|
||||||
display: block;
|
|
||||||
font-size: 0.83em;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 1.67em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.h6 {
|
|
||||||
display: block;
|
|
||||||
font-size: 0.67em;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 2.33em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* tables */
|
|
||||||
|
|
||||||
.table {
|
|
||||||
display: table;
|
|
||||||
border-collapse: separate;
|
|
||||||
border-spacing: 2px;
|
|
||||||
border-color: gray;
|
|
||||||
}
|
|
||||||
|
|
||||||
.thead {
|
|
||||||
display: table-header-group;
|
|
||||||
vertical-align: middle;
|
|
||||||
border-color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tbody {
|
|
||||||
display: table-row-group;
|
|
||||||
vertical-align: middle;
|
|
||||||
border-color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tfoot {
|
|
||||||
display: table-footer-group;
|
|
||||||
vertical-align: middle;
|
|
||||||
border-color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
.col {
|
|
||||||
display: table-column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.colgroup {
|
|
||||||
display: table-column-group;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tr {
|
|
||||||
display: table-row;
|
|
||||||
vertical-align: inherit;
|
|
||||||
border-color: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
.td, .th {
|
|
||||||
display: table-cell;
|
|
||||||
vertical-align: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
.th {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.caption {
|
|
||||||
display: table-caption;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lists */
|
|
||||||
|
|
||||||
.ul, .menu, .dir {
|
|
||||||
list-style-type: disc;
|
|
||||||
margin: 1em 0;
|
|
||||||
padding-left: 40rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ol {
|
|
||||||
display: block;
|
|
||||||
list-style-type: decimal;
|
|
||||||
margin: 1em 0;
|
|
||||||
padding-left: 40rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.li {
|
|
||||||
display: list-item;
|
|
||||||
text-align: match-parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ul .ul, .ol .ul {
|
|
||||||
list-style-type: circle
|
|
||||||
}
|
|
||||||
|
|
||||||
.ol .ol .ul, .ol .ul .ul, .ul .ol .ul, .ul .ul .ul {
|
|
||||||
list-style-type: square;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dd {
|
|
||||||
display: block;
|
|
||||||
margin-left: 40rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dl {
|
|
||||||
display: block;
|
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dt {
|
|
||||||
display: block
|
|
||||||
}
|
|
||||||
|
|
||||||
.ol .ul, .ul .ol, .ul .ul, .ol .ol {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* inline elements */
|
|
||||||
|
|
||||||
.u, .ins {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.strong, .b {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.i, .cite, .em, .var, .address, .dfn {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tt, .code, .kbd, .samp {
|
|
||||||
font-family: monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pre, .xmp, .plaintext, .listing {
|
|
||||||
display: block;
|
|
||||||
font-family: monospace;
|
|
||||||
white-space: pre;
|
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mark {
|
|
||||||
background-color: yellow;
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.big {
|
|
||||||
font-size: larger;
|
|
||||||
}
|
|
||||||
|
|
||||||
.small {
|
|
||||||
font-size: smaller;
|
|
||||||
}
|
|
||||||
|
|
||||||
.s, .strike, .del {
|
|
||||||
text-decoration: line-through;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sub {
|
|
||||||
vertical-align: sub;
|
|
||||||
font-size: smaller;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sup {
|
|
||||||
vertical-align: super;
|
|
||||||
font-size: smaller;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nobr {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
@ -1,198 +0,0 @@
|
|||||||
(function (global, factory) {
|
|
||||||
if (typeof define === "function" && define.amd) {
|
|
||||||
define(['module', 'exports'], factory);
|
|
||||||
} else if (typeof exports !== "undefined") {
|
|
||||||
factory(module, exports);
|
|
||||||
} else {
|
|
||||||
var mod = {
|
|
||||||
exports: {}
|
|
||||||
};
|
|
||||||
factory(mod, mod.exports);
|
|
||||||
global.Router = mod.exports;
|
|
||||||
}
|
|
||||||
})(this, function (module, exports) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
exports.__esModule = true;
|
|
||||||
|
|
||||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
||||||
return typeof obj;
|
|
||||||
} : function (obj) {
|
|
||||||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) {
|
|
||||||
if (!(instance instanceof Constructor)) {
|
|
||||||
throw new TypeError("Cannot call a class as a function");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var Router = function () {
|
|
||||||
function Router(conf) {
|
|
||||||
_classCallCheck(this, Router);
|
|
||||||
|
|
||||||
this.routes = {};
|
|
||||||
|
|
||||||
if (conf.constructor === Array) conf = { ALL: conf };
|
|
||||||
|
|
||||||
for (var method in conf) {
|
|
||||||
var routes = conf[method];
|
|
||||||
var rts = this.routes[method] = {
|
|
||||||
string: {},
|
|
||||||
regex: []
|
|
||||||
};
|
|
||||||
|
|
||||||
var _loop = function _loop() {
|
|
||||||
if (_isArray) {
|
|
||||||
if (_i >= _iterator.length) return 'break';
|
|
||||||
_ref = _iterator[_i++];
|
|
||||||
} else {
|
|
||||||
_i = _iterator.next();
|
|
||||||
if (_i.done) return 'break';
|
|
||||||
_ref = _i.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
var _rt = _ref;
|
|
||||||
|
|
||||||
var pattern = void 0,
|
|
||||||
replacement = void 0,
|
|
||||||
params = void 0,
|
|
||||||
options = void 0;
|
|
||||||
|
|
||||||
if (_rt.constructor === String) {
|
|
||||||
pattern = _rt;
|
|
||||||
replacement = '$&';
|
|
||||||
params = [];
|
|
||||||
options = {};
|
|
||||||
} else {
|
|
||||||
var rt = _rt.concat();
|
|
||||||
pattern = rt.shift();
|
|
||||||
replacement = rt.shift() || '$&';
|
|
||||||
options = _typeof(rt[rt.length - 1]) == 'object' ? rt.pop() : {};
|
|
||||||
params = rt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pattern.constructor === RegExp) {
|
|
||||||
rts.regex.push({
|
|
||||||
pattern: pattern,
|
|
||||||
replacement: replacement,
|
|
||||||
params: params,
|
|
||||||
options: options,
|
|
||||||
origin: _rt
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (!/:|\*|\$/.test(pattern)) {
|
|
||||||
rts.string[pattern] = {
|
|
||||||
replacement: replacement === '$&' ? pattern : replacement,
|
|
||||||
options: options,
|
|
||||||
origin: _rt
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
params = [];
|
|
||||||
|
|
||||||
pattern = pattern.replace(/[\\&()+.[?^{|]/g, '\\$&').replace(/:(\w+)/g, function (str, key) {
|
|
||||||
params.push(key);
|
|
||||||
return '([^/]+)';
|
|
||||||
}).replace(/\*/g, '.*');
|
|
||||||
|
|
||||||
rts.regex.push({
|
|
||||||
pattern: new RegExp('^' + pattern + '$'),
|
|
||||||
replacement: replacement,
|
|
||||||
params: params,
|
|
||||||
options: options,
|
|
||||||
origin: _rt
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (var _iterator = routes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
|
||||||
var _ref;
|
|
||||||
|
|
||||||
var _ret = _loop();
|
|
||||||
|
|
||||||
if (_ret === 'break') break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Router.prototype.match = function match(path) {
|
|
||||||
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ALL';
|
|
||||||
|
|
||||||
var rts = this.routes[method];
|
|
||||||
|
|
||||||
if (rts) {
|
|
||||||
if (rts.string[path]) {
|
|
||||||
var match = {
|
|
||||||
path: rts.string[path].replacement,
|
|
||||||
params: {},
|
|
||||||
options: rts.string[path].options,
|
|
||||||
origin: rts.string[path].origin
|
|
||||||
};
|
|
||||||
|
|
||||||
if (Router.log) {
|
|
||||||
console.log('path:', path, '\n', 'method:', method, '\n', 'match:', match); // eslint-disable-line
|
|
||||||
}
|
|
||||||
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
|
|
||||||
var _replacement = void 0;
|
|
||||||
var _params = {};
|
|
||||||
for (var _iterator2 = rts.regex, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
|
||||||
var _ref2;
|
|
||||||
|
|
||||||
if (_isArray2) {
|
|
||||||
if (_i2 >= _iterator2.length) break;
|
|
||||||
_ref2 = _iterator2[_i2++];
|
|
||||||
} else {
|
|
||||||
_i2 = _iterator2.next();
|
|
||||||
if (_i2.done) break;
|
|
||||||
_ref2 = _i2.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rt = _ref2;
|
|
||||||
|
|
||||||
var matches = path.match(rt.pattern);
|
|
||||||
if (matches) {
|
|
||||||
_replacement = rt.replacement;
|
|
||||||
if (_replacement.indexOf('$') !== -1) {
|
|
||||||
_replacement = _replacement === '$&' ? path : path.replace(rt.pattern, _replacement);
|
|
||||||
}
|
|
||||||
|
|
||||||
matches.shift();
|
|
||||||
for (var j = 0; j < rt.params.length; j++) {
|
|
||||||
if (rt.params[j]) {
|
|
||||||
_params[rt.params[j]] = matches[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var _match = {
|
|
||||||
path: _replacement,
|
|
||||||
params: _params,
|
|
||||||
options: rt.options,
|
|
||||||
origin: rt.origin
|
|
||||||
};
|
|
||||||
|
|
||||||
if (Router.log) {
|
|
||||||
console.log('path:', path, '\n', 'method:', method, '\n', 'match:', _match); // eslint-disable-line
|
|
||||||
}
|
|
||||||
|
|
||||||
return _match;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Router.log) {
|
|
||||||
console.log('path:', path, '\n', 'method:', method, '\n', 'match:', null); // eslint-disable-line
|
|
||||||
}
|
|
||||||
|
|
||||||
return method === 'ALL' ? null : this.match(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
return Router;
|
|
||||||
}();
|
|
||||||
|
|
||||||
exports.default = Router;
|
|
||||||
module.exports = exports['default'];
|
|
||||||
});
|
|
@ -1,317 +0,0 @@
|
|||||||
(function() {
|
|
||||||
var root = this;
|
|
||||||
|
|
||||||
var tagStart = '<';
|
|
||||||
var tagEnd = '>';
|
|
||||||
var commentStart = '<!--';
|
|
||||||
var commentEnd = '-->';
|
|
||||||
|
|
||||||
var voidTags = [
|
|
||||||
"!doctype", "area", "base", "br", "col", "command",
|
|
||||||
"embed", "hr", "img", "input", "keygen", "link",
|
|
||||||
"meta", "param", "source", "track", "wbr"
|
|
||||||
];
|
|
||||||
var closingTags = [
|
|
||||||
"colgroup", "dd", "dt", "li", "options", "p",
|
|
||||||
"td", "tfoot", "th", "thead", "tr"
|
|
||||||
];
|
|
||||||
var childlessTags = ['style', 'script', 'template'];
|
|
||||||
|
|
||||||
function parse(str) {
|
|
||||||
return parseUntil(str + '</root>', ['root']).nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseUntil(str, stack) {
|
|
||||||
var nodes = [];
|
|
||||||
|
|
||||||
while (str.length) {
|
|
||||||
var nextTag = str.indexOf(tagStart);
|
|
||||||
if (nextTag === -1) {
|
|
||||||
// only text left
|
|
||||||
nodes.push({
|
|
||||||
type: 'Text',
|
|
||||||
content: str
|
|
||||||
});
|
|
||||||
str = '';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextTag) {
|
|
||||||
// text before tag
|
|
||||||
nodes.push({
|
|
||||||
type: 'Text',
|
|
||||||
content: str.slice(0, nextTag)
|
|
||||||
});
|
|
||||||
str = str.slice(nextTag);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startsWithCommentStart(str)) {
|
|
||||||
// comment
|
|
||||||
var end = str.indexOf(commentEnd);
|
|
||||||
nodes.push({
|
|
||||||
type: 'Comment',
|
|
||||||
content: str.slice(commentStart.length, end)
|
|
||||||
});
|
|
||||||
str = str.slice(end + commentEnd.length);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isClosingTag = str.charAt(nextTag + 1) === '/';
|
|
||||||
if (isClosingTag) {
|
|
||||||
var endTagEnd = str.indexOf(tagEnd);
|
|
||||||
var innerTag = str.slice(2, endTagEnd);
|
|
||||||
var tagName = innerTag.trim().split(' ')[0];
|
|
||||||
str = str.slice(endTagEnd + 1);
|
|
||||||
var loc = stack.lastIndexOf(tagName);
|
|
||||||
if (~loc) {
|
|
||||||
stack = stack.slice(0, loc);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// open tag
|
|
||||||
var results = parseTag(str, stack);
|
|
||||||
if (results.tag) {
|
|
||||||
results.tag.type = 'Element';
|
|
||||||
nodes.push(results.tag);
|
|
||||||
str = results.str;
|
|
||||||
}
|
|
||||||
if (results.stack.length !== stack.length) {
|
|
||||||
stack = results.stack;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
nodes: nodes,
|
|
||||||
stack: stack,
|
|
||||||
str: str
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseTag(str, stack) {
|
|
||||||
var idxTagEnd = str.indexOf(tagEnd);
|
|
||||||
var idxSpace = str.indexOf(' ');
|
|
||||||
var tagNameEnd = ~idxSpace ?
|
|
||||||
Math.min(idxTagEnd, idxSpace) :
|
|
||||||
idxTagEnd;
|
|
||||||
var tagName = str.slice(1, tagNameEnd);
|
|
||||||
var lowTagName = tagName.toLowerCase();
|
|
||||||
|
|
||||||
if (stack[stack.length - 1] === tagName && ~closingTags.indexOf(lowTagName)) {
|
|
||||||
return {
|
|
||||||
stack: stack.slice(0, -1)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var attrs = parseAttrs(str.slice(tagNameEnd));
|
|
||||||
var tag = {
|
|
||||||
tagName: tagName,
|
|
||||||
attributes: attrs.attributes
|
|
||||||
};
|
|
||||||
str = attrs.str;
|
|
||||||
|
|
||||||
if (startsWithSelfClose(str)) {
|
|
||||||
str = str.slice(2);
|
|
||||||
} else {
|
|
||||||
str = str.slice(1);
|
|
||||||
|
|
||||||
if (~childlessTags.indexOf(lowTagName)) {
|
|
||||||
var end = '</' + tagName + '>';
|
|
||||||
var idx = str.indexOf(end);
|
|
||||||
if (!~idx) idx = Infinity;
|
|
||||||
tag.content = str.slice(0, idx);
|
|
||||||
str = str.slice(idx);
|
|
||||||
} else if (!~voidTags.indexOf(lowTagName)) {
|
|
||||||
var results = parseUntil(str, stack.concat(tagName));
|
|
||||||
tag.children = results.nodes;
|
|
||||||
str = results.str;
|
|
||||||
stack = results.stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
tag: tag,
|
|
||||||
str: str,
|
|
||||||
stack: stack
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseAttrs(str) {
|
|
||||||
str = str.trim();
|
|
||||||
var results = tagPairs(str, 0);
|
|
||||||
str = str.slice(results.cursor);
|
|
||||||
var attributes = results.kvs.map(function(pair) {
|
|
||||||
var kv = splitHead(pair.trim(), '=');
|
|
||||||
kv[1] = kv[1] ? unquote(kv[1]) : kv[0];
|
|
||||||
return kv;
|
|
||||||
}).reduce(function(attrs, kv) {
|
|
||||||
var property = kv[0];
|
|
||||||
var value = kv[1];
|
|
||||||
if (property === 'class') {
|
|
||||||
attrs.className = value.split(' ');
|
|
||||||
} else if (property === 'style') {
|
|
||||||
attrs.style = parseStyle(value);
|
|
||||||
} else if (startsWithDataDash(property)) {
|
|
||||||
attrs.dataset = attrs.dataset || {};
|
|
||||||
var key = camelCase(property.slice(5));
|
|
||||||
attrs.dataset[key] = castValue(value);
|
|
||||||
} else {
|
|
||||||
attrs[camelCase(property)] = castValue(value);
|
|
||||||
}
|
|
||||||
return attrs;
|
|
||||||
}, {});
|
|
||||||
return {
|
|
||||||
str: str,
|
|
||||||
attributes: attributes
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function splitHead(str, sep) {
|
|
||||||
var idx = str.indexOf(sep);
|
|
||||||
if (idx === -1) return [str];
|
|
||||||
return [str.slice(0, idx), str.slice(idx + sep.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
function tagPairs(str, index) {
|
|
||||||
var words = []; // "key", "key=value", "key='value'", etc
|
|
||||||
var quote = null; // null, single-, or double-quote
|
|
||||||
var cursor = index; // index of parse into str
|
|
||||||
var wordBegin = cursor; // index of word start
|
|
||||||
var len = str.length;
|
|
||||||
while(cursor < len) {
|
|
||||||
var char = str.charAt(cursor);
|
|
||||||
var isTagEnd = !quote && (char === '/' || char === tagEnd);
|
|
||||||
if (isTagEnd) {
|
|
||||||
if (cursor !== wordBegin) {
|
|
||||||
words.push(str.slice(wordBegin, cursor));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isWordEnd = !quote && char === ' ';
|
|
||||||
if (isWordEnd) {
|
|
||||||
if (cursor !== wordBegin) {
|
|
||||||
words.push(str.slice(wordBegin, cursor));
|
|
||||||
}
|
|
||||||
wordBegin = cursor + 1;
|
|
||||||
cursor++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isQuoteEnd = char === quote;
|
|
||||||
if (isQuoteEnd) {
|
|
||||||
quote = null;
|
|
||||||
cursor++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isQuoteStart = !quote && (char === '\'' || char === '"');
|
|
||||||
if (isQuoteStart) {
|
|
||||||
quote = char;
|
|
||||||
cursor++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor++;
|
|
||||||
}
|
|
||||||
|
|
||||||
var attrs = [];
|
|
||||||
var wLen = words.length;
|
|
||||||
for (var i = 0; i < wLen; i++) {
|
|
||||||
var word = words[i];
|
|
||||||
if (!(word && word.length)) continue;
|
|
||||||
var isNotPair = word.indexOf('=') === -1;
|
|
||||||
if (isNotPair) {
|
|
||||||
var secondWord = words[i + 1];
|
|
||||||
var thirdWord = words[i + 2];
|
|
||||||
var isSpacedPair = secondWord === '=' && thirdWord;
|
|
||||||
if (isSpacedPair) {
|
|
||||||
var newWord = word + '=' + thirdWord;
|
|
||||||
attrs.push(newWord);
|
|
||||||
i += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attrs.push(word);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
cursor: cursor,
|
|
||||||
kvs: attrs
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function unquote(str) {
|
|
||||||
var car = str.charAt(0);
|
|
||||||
var end = str.length - 1;
|
|
||||||
if (car === '"' || car === "'" && car === str.charAt(end)) {
|
|
||||||
return str.slice(1, end);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStyle(str) {
|
|
||||||
return str.trim().split(';').map(function(statement) {
|
|
||||||
return statement.trim().split(':');
|
|
||||||
}).reduce(function(styles, kv) {
|
|
||||||
if (kv[1]) styles[camelCase(kv[0].trim())] = castValue(kv[1].trim());
|
|
||||||
return styles;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
function camelCase(str) {
|
|
||||||
return str.split('-').reduce(function(str, word) {
|
|
||||||
return str + word.charAt(0).toUpperCase() + word.slice(1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function castValue(str) {
|
|
||||||
if (typeof str !== 'string') return str;
|
|
||||||
var num = +str;
|
|
||||||
if (!isNaN(num)) return num;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function startsWithCommentStart(s) {
|
|
||||||
return (
|
|
||||||
s.charAt(0) === '<' &&
|
|
||||||
s.charAt(1) === '!' &&
|
|
||||||
s.charAt(2) === '-' &&
|
|
||||||
s.charAt(3) === '-');
|
|
||||||
}
|
|
||||||
|
|
||||||
function startsWithSelfClose(s) {
|
|
||||||
return (
|
|
||||||
s.charAt(0) === '/' &&
|
|
||||||
s.charAt(1) === '>');
|
|
||||||
}
|
|
||||||
|
|
||||||
function startsWithDataDash(s) {
|
|
||||||
return (
|
|
||||||
s.charAt(0) === 'd' &&
|
|
||||||
s.charAt(1) === 'a' &&
|
|
||||||
s.charAt(2) === 't' &&
|
|
||||||
s.charAt(3) === 'a' &&
|
|
||||||
s.charAt(4) === '-');
|
|
||||||
}
|
|
||||||
|
|
||||||
var himalaya = {
|
|
||||||
parse: parse,
|
|
||||||
parseTag: parseTag,
|
|
||||||
parseUntil: parseUntil,
|
|
||||||
parseAttrs: parseAttrs,
|
|
||||||
parseStyle: parseStyle
|
|
||||||
};
|
|
||||||
|
|
||||||
if (typeof exports !== 'undefined') {
|
|
||||||
if (typeof module !== 'undefined' && module.exports) {
|
|
||||||
exports = module.exports = himalaya;
|
|
||||||
}
|
|
||||||
exports.himalaya = himalaya;
|
|
||||||
} else {
|
|
||||||
root.himalaya = himalaya;
|
|
||||||
}
|
|
||||||
}).call(this);
|
|
@ -1,186 +0,0 @@
|
|||||||
(function (global, factory) {
|
|
||||||
if (typeof define === "function" && define.amd) {
|
|
||||||
define(['module', 'exports'], factory);
|
|
||||||
} else if (typeof exports !== "undefined") {
|
|
||||||
factory(module, exports);
|
|
||||||
} else {
|
|
||||||
var mod = {
|
|
||||||
exports: {}
|
|
||||||
};
|
|
||||||
factory(mod, mod.exports);
|
|
||||||
global.url = mod.exports;
|
|
||||||
}
|
|
||||||
})(this, function (module, exports) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
exports.__esModule = true;
|
|
||||||
function parseQuery(str) {
|
|
||||||
var query = {};
|
|
||||||
if (str.length) {
|
|
||||||
str.replace(/\+/g, ' ').split('&').forEach(function (s) {
|
|
||||||
var pair = s.split('=');
|
|
||||||
var key = decodeURIComponent(pair[0]);
|
|
||||||
var val = pair.length === 1 ? '' : decodeURIComponent(pair[1]);
|
|
||||||
if (query[key] == null) {
|
|
||||||
query[key] = val;
|
|
||||||
} else {
|
|
||||||
if (query[key].constructor !== Array) query[key] = [query[key]];
|
|
||||||
query[key].push(val);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatQuery(obj) {
|
|
||||||
var str = '';
|
|
||||||
|
|
||||||
var _loop = function _loop(p) {
|
|
||||||
var key = encodeURIComponent(p);
|
|
||||||
[].concat(obj[p]).forEach(function (val) {
|
|
||||||
if (val == null) return;
|
|
||||||
str += '&' + key;
|
|
||||||
if (val !== '') str += '=' + encodeURIComponent(val);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
for (var p in obj) {
|
|
||||||
_loop(p);
|
|
||||||
}
|
|
||||||
return str.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parse(str) {
|
|
||||||
var m = /^(?:([^:/?#]+:))?(?:\/\/(?:(([^:@]*)(?::([^:@]*))?)?@)?(([^:/?#]*)(?::(\d*))?))?(((?:[^?#/]*\/)*[^?#]*)(?:(\?[^#]*))?)(?:(#.*))?/.exec(str);
|
|
||||||
var url = {};['href', 'protocol', 'auth', 'username', 'password', 'host', 'hostname', 'port', 'path', 'pathname', 'search', 'hash'].forEach(function (key, i) {
|
|
||||||
return url[key] = m[i] || '';
|
|
||||||
});
|
|
||||||
if (!url.path && !url.pathname) url.path = url.pathname = '/';
|
|
||||||
url.query = parseQuery(url.search.slice(1));
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
function format() {
|
|
||||||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
||||||
_ref$protocol = _ref.protocol,
|
|
||||||
protocol = _ref$protocol === undefined ? '' : _ref$protocol,
|
|
||||||
_ref$auth = _ref.auth,
|
|
||||||
auth = _ref$auth === undefined ? '' : _ref$auth,
|
|
||||||
_ref$username = _ref.username,
|
|
||||||
username = _ref$username === undefined ? '' : _ref$username,
|
|
||||||
_ref$password = _ref.password,
|
|
||||||
password = _ref$password === undefined ? '' : _ref$password,
|
|
||||||
_ref$host = _ref.host,
|
|
||||||
host = _ref$host === undefined ? '' : _ref$host,
|
|
||||||
_ref$hostname = _ref.hostname,
|
|
||||||
hostname = _ref$hostname === undefined ? '' : _ref$hostname,
|
|
||||||
_ref$port = _ref.port,
|
|
||||||
port = _ref$port === undefined ? '' : _ref$port,
|
|
||||||
_ref$path = _ref.path,
|
|
||||||
path = _ref$path === undefined ? '' : _ref$path,
|
|
||||||
_ref$pathname = _ref.pathname,
|
|
||||||
pathname = _ref$pathname === undefined ? '' : _ref$pathname,
|
|
||||||
_ref$search = _ref.search,
|
|
||||||
search = _ref$search === undefined ? '' : _ref$search,
|
|
||||||
_ref$query = _ref.query,
|
|
||||||
query = _ref$query === undefined ? null : _ref$query,
|
|
||||||
_ref$hash = _ref.hash,
|
|
||||||
hash = _ref$hash === undefined ? '' : _ref$hash;
|
|
||||||
|
|
||||||
var str = '';
|
|
||||||
|
|
||||||
if (protocol) {
|
|
||||||
str += protocol;
|
|
||||||
if (protocol.slice(-1) !== ':') str += ':';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (protocol || host || hostname) str += '//';
|
|
||||||
|
|
||||||
if (host || hostname) {
|
|
||||||
if (auth) {
|
|
||||||
str += auth + '@';
|
|
||||||
} else if (username) {
|
|
||||||
str += username;
|
|
||||||
if (password) str += ':' + password;
|
|
||||||
str += '@';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (host) {
|
|
||||||
str += host;
|
|
||||||
} else {
|
|
||||||
str += hostname;
|
|
||||||
if (port) str += ':' + port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path) {
|
|
||||||
str += path;
|
|
||||||
} else {
|
|
||||||
str += pathname || '/';
|
|
||||||
|
|
||||||
if (search) {
|
|
||||||
str += search;
|
|
||||||
} else if (query) {
|
|
||||||
var q = formatQuery(query);
|
|
||||||
if (q) str += '?' + q;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
str += hash;
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolve(from, to) {
|
|
||||||
from = parse(from);
|
|
||||||
to = parse(to);
|
|
||||||
|
|
||||||
// 'to' is an absolute URL
|
|
||||||
if (to.protocol) return to.href;
|
|
||||||
|
|
||||||
// 'to' only need to complete the protocol
|
|
||||||
if (to.host) {
|
|
||||||
to.protocol = from.protocol;
|
|
||||||
return format(to);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'to' has aboslute path
|
|
||||||
if (to.path[0] === '/') {
|
|
||||||
from.path = to.path;
|
|
||||||
from.pathname = from.search = '';
|
|
||||||
from.query = null;
|
|
||||||
from.hash = to.hash;
|
|
||||||
return format(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (to.pathname) {
|
|
||||||
(function () {
|
|
||||||
var dirFrom = from.pathname.split('/');
|
|
||||||
// pop the filename
|
|
||||||
dirFrom.pop();
|
|
||||||
|
|
||||||
to.pathname.split('/').forEach(function (d) {
|
|
||||||
switch (d) {
|
|
||||||
case '.':
|
|
||||||
return;
|
|
||||||
case '..':
|
|
||||||
return dirFrom.length > 1 ? dirFrom.pop() : null;
|
|
||||||
default:
|
|
||||||
dirFrom.push(d);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
from.pathname = dirFrom.join('/');
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
|
|
||||||
from.path = '';
|
|
||||||
from.search = to.search;
|
|
||||||
from.query = null;
|
|
||||||
from.hash = to.hash;
|
|
||||||
return format(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.default = { parse: parse, format: format, resolve: resolve, parseQuery: parseQuery, formatQuery: formatQuery };
|
|
||||||
module.exports = exports['default'];
|
|
||||||
});
|
|
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 51 KiB |
After Width: | Height: | Size: 193 KiB |
After Width: | Height: | Size: 81 KiB |
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 29 KiB |
@ -1,7 +1,3 @@
|
|||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
|
||||||
"usingComponents": {}
|
"usingComponents": {}
|
||||||
=======
|
|
||||||
"navigationBarTitleText": "首页"
|
|
||||||
>>>>>>> 2265d9448044d64588fccdf8270e4f514a1b1f58
|
|
||||||
}
|
}
|
@ -1,30 +1 @@
|
|||||||
<<<<<<< HEAD
|
|
||||||
/* pages/shouye/shouye.wxss */
|
/* pages/shouye/shouye.wxss */
|
||||||
=======
|
|
||||||
/**index.wxss**/
|
|
||||||
.userinfo {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.userinfo-avatar {
|
|
||||||
width: 128rpx;
|
|
||||||
height: 128rpx;
|
|
||||||
margin: 20rpx;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
.swiper-ai image{
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
.swiper-ai swiper{
|
|
||||||
height:240px;
|
|
||||||
}
|
|
||||||
.userinfo-nickname {
|
|
||||||
color: #aaa;
|
|
||||||
}
|
|
||||||
|
|
||||||
.usermotto {
|
|
||||||
margin-top: 200px;
|
|
||||||
}
|
|
||||||
>>>>>>> 2265d9448044d64588fccdf8270e4f514a1b1f58
|
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
const apiURL = 'http://47.104.244.32:8100';
|
|
||||||
let headerData= {
|
|
||||||
|
|
||||||
}
|
|
||||||
headerData['Content-Type']= 'application/json';
|
|
||||||
let userData ={};
|
|
||||||
wx.getStorage({
|
|
||||||
key: 'bbsProfile',
|
|
||||||
success: function(res) {
|
|
||||||
userData = res.data;
|
|
||||||
if(userData.token){
|
|
||||||
headerData['Authorization']=userData.token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const wxRequest = (params, url) => {
|
|
||||||
wx.request({
|
|
||||||
url,
|
|
||||||
method: params.method || 'POST',
|
|
||||||
data: params.data || {},
|
|
||||||
header:headerData, /*{
|
|
||||||
Accept: 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},*/
|
|
||||||
success(res) {
|
|
||||||
if (params.success) {
|
|
||||||
params.success(res);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fail(res) {
|
|
||||||
if (params.fail) {
|
|
||||||
params.fail(res);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
complete(res) {
|
|
||||||
if (params.complete) {
|
|
||||||
params.complete(res);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const getForum = (params) => {
|
|
||||||
wxRequest(params, `${apiURL}/forumManagement/getForum`);
|
|
||||||
};
|
|
||||||
const getQuestion = (params) => {
|
|
||||||
wxRequest(params, `${apiURL}/question/getQuestion`);
|
|
||||||
};
|
|
||||||
const login = (params) => {
|
|
||||||
wxRequest(params, `${apiURL}/session`);
|
|
||||||
};
|
|
||||||
const newAdmin = (params) => {
|
|
||||||
wxRequest(params, `${apiURL}/user/newAdmin`);
|
|
||||||
};
|
|
||||||
module.exports = {
|
|
||||||
getForum,
|
|
||||||
getQuestion,
|
|
||||||
login,
|
|
||||||
newAdmin
|
|
||||||
};
|
|