提交 2c51f0b3 编写于 作者: Q qiang

Merge branch 'dev' into alpha

# Conflicts:
#	packages/uni-h5/dist/index.umd.min.js
...@@ -29,7 +29,9 @@ const cdns = { ...@@ -29,7 +29,9 @@ const cdns = {
'mp-360': 7, 'mp-360': 7,
'mp-dingtalk': 8, 'mp-dingtalk': 8,
'mp-kuaishou': 9, 'mp-kuaishou': 9,
'mp-lark': 10, 'mp-lark': 10,
'mp-jd': 11,
'mp-xhs': 12,
'quickapp-webview-huawei': 200, 'quickapp-webview-huawei': 200,
'quickapp-webview-union': 201 'quickapp-webview-union': 201
} }
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -80,12 +80,8 @@ function addMPPluginRequire (compilation) { ...@@ -80,12 +80,8 @@ function addMPPluginRequire (compilation) {
const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx' const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx'
const filePath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, name)) const filePath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, name))
const uniModuleId = modules.find(module => module.resource && normalizePath(module.resource) === filePath).id const uniModuleId = modules.find(module => module.resource && normalizePath(module.resource) === filePath).id
const newlineIndex = orignalSource.lastIndexOf('\n')
const source = const source = orignalSource + `\nmodule.exports = ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__('${uniModuleId}');\n`;
orignalSource.substring(0, newlineIndex) +
`\nmodule.exports = ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__('${uniModuleId}');\n` +
orignalSource.substring(newlineIndex + 1)
compilation.assets[name] = { compilation.assets[name] = {
size () { size () {
......
...@@ -100,7 +100,8 @@ export function showPage ({ ...@@ -100,7 +100,8 @@ export function showPage ({
animationType: 'pop-in', animationType: 'pop-in',
animationDuration: 200, animationDuration: 200,
uniNView: { uniNView: {
path: `${(typeof process === 'object' && process.env && process.env.VUE_APP_TEMPLATE_PATH) || ''}/${url}.js`, // eslint-disable-next-line
path: `${typeof VUE_APP_TEMPLATE_PATH === 'string' ? VUE_APP_TEMPLATE_PATH : ''}/${url}.js`,
defaultFontSize: 16, defaultFontSize: 16,
viewport: plus_.screen.resolutionWidth viewport: plus_.screen.resolutionWidth
} }
......
...@@ -4,7 +4,7 @@ import { ...@@ -4,7 +4,7 @@ import {
import { import {
showPage showPage
} from '../page.js' } from '../../../helpers/page.js'
import { import {
t t
......
...@@ -4,7 +4,7 @@ import { ...@@ -4,7 +4,7 @@ import {
import { import {
showPage showPage
} from '../page.js' } from '../../../helpers/page.js'
function getStatusBarStyle () { function getStatusBarStyle () {
let style = plus.navigator.getStatusBarStyle() let style = plus.navigator.getStatusBarStyle()
......
import { import {
invoke invoke
} from '../../bridge' } from '../../bridge'
import { import {
showPage showPage
} from '../page.js' } from '../../../helpers/page.js'
export function openLocation (data, callbackId) { export function openLocation (data, callbackId) {
showPage({ showPage({
...@@ -16,11 +16,11 @@ export function openLocation (data, callbackId) { ...@@ -16,11 +16,11 @@ export function openLocation (data, callbackId) {
}, },
popGesture: 'close', popGesture: 'close',
backButtonAutoControl: 'close' backButtonAutoControl: 'close'
}, },
onClose () { onClose () {
invoke(callbackId, { invoke(callbackId, {
errMsg: 'openLocation:fail cancel' errMsg: 'openLocation:fail cancel'
}) })
} }
}) })
return { return {
......
let plus_
let weex_
let BroadcastChannel_
function getRuntime () {
return typeof window === 'object' && typeof navigator === 'object' && typeof document === 'object' ? 'webview' : 'v8'
}
function getPageId () {
return plus_.webview.currentWebview().id
}
let channel
let globalEvent
const callbacks = {}
function onPlusMessage (res) {
const message = res.data && res.data.__message
if (!message || !message.__page) {
return
}
const pageId = message.__page
const callback = callbacks[pageId]
callback && callback(message)
if (!message.keep) {
delete callbacks[pageId]
}
}
function addEventListener (pageId, callback) {
if (getRuntime() === 'v8') {
if (BroadcastChannel_) {
channel && channel.close()
channel = new BroadcastChannel_(getPageId())
channel.onmessage = onPlusMessage
} else if (!globalEvent) {
globalEvent = weex_.requireModule('globalEvent')
globalEvent.addEventListener('plusMessage', onPlusMessage)
}
} else {
window.__plusMessage = onPlusMessage
}
callbacks[pageId] = callback
}
class Page {
constructor (webview) {
this.webview = webview
}
sendMessage (data) {
const message = {
__message: {
data
}
}
const id = this.webview.id
if (BroadcastChannel_) {
const channel = new BroadcastChannel_(id)
channel.postMessage(message)
} else {
plus_.webview.postMessageToUniNView(message, id)
}
}
close () {
this.webview.close()
}
}
export function showPage ({
context = {},
url,
data = {},
style = {},
onMessage,
onClose
}) {
// eslint-disable-next-line
plus_ = context.plus || plus
// eslint-disable-next-line
weex_ = context.weex || (typeof weex === 'object' ? weex : null)
// eslint-disable-next-line
BroadcastChannel_ = context.BroadcastChannel || (typeof BroadcastChannel === 'object' ? BroadcastChannel : null)
const titleNView = {
autoBackButton: true,
titleSize: '17px'
}
const pageId = `page${Date.now()}`
style = Object.assign({}, style)
if (style.titleNView !== false && style.titleNView !== 'none') {
style.titleNView = Object.assign(titleNView, style.titleNView)
}
const defaultStyle = {
top: 0,
bottom: 0,
usingComponents: {},
popGesture: 'close',
scrollIndicator: 'none',
animationType: 'pop-in',
animationDuration: 200,
uniNView: {
path: `${(typeof process === 'object' && process.env && process.env.VUE_APP_TEMPLATE_PATH) || ''}/${url}.js`,
defaultFontSize: 16,
viewport: plus_.screen.resolutionWidth
}
}
style = Object.assign(defaultStyle, style)
const page = plus_.webview.create('', pageId, style, {
extras: {
from: getPageId(),
runtime: getRuntime(),
data,
useGlobalEvent: !BroadcastChannel_
}
})
page.addEventListener('close', onClose)
addEventListener(pageId, message => {
if (typeof onMessage === 'function') {
onMessage(message.data)
}
if (!message.keep) {
page.close('auto')
}
})
page.show(style.animationType, style.animationDuration)
return new Page(page)
}
...@@ -24,7 +24,8 @@ function getService (provider) { ...@@ -24,7 +24,8 @@ function getService (provider) {
export function login (params, callbackId, plus = true) { export function login (params, callbackId, plus = true) {
const provider = params.provider || 'weixin' const provider = params.provider || 'weixin'
const errorCallback = warpErrorCallback(callbackId, 'login', plus) const errorCallback = warpErrorCallback(callbackId, 'login', plus)
const authOptions = provider === 'apple' const isAppleLogin = provider === 'apple'
const authOptions = isAppleLogin
? { scope: 'email' } ? { scope: 'email' }
: params.univerifyStyle : params.univerifyStyle
? { univerifyStyle: univerifyButtonsClickHandling(params.univerifyStyle, errorCallback) } ? { univerifyStyle: univerifyButtonsClickHandling(params.univerifyStyle, errorCallback) }
...@@ -45,16 +46,18 @@ export function login (params, callbackId, plus = true) { ...@@ -45,16 +46,18 @@ export function login (params, callbackId, plus = true) {
} }
service.login(res => { service.login(res => {
const authResult = res.target.authResult const authResult = res.target.authResult
const appleInfo = res.target.appleInfo
_invoke(callbackId, { _invoke(callbackId, {
code: authResult.code, code: authResult.code,
authResult: authResult, authResult: authResult,
appleInfo,
errMsg: 'login:ok' errMsg: 'login:ok'
}) })
}, errorCallback, authOptions) }, errorCallback, authOptions)
} }
// 先注销再登录 // 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname;一键登录无logout // apple登录logout之后无法重新触发获取email,fullname;一键登录无logout
if (provider === 'apple' || provider === 'univerify') { if (isAppleLogin || provider === 'univerify') {
login() login()
} else { } else {
service.logout(login, login) service.logout(login, login)
......
...@@ -51,7 +51,10 @@ const parseParams = (args, callbackId, method) => { ...@@ -51,7 +51,10 @@ const parseParams = (args, callbackId, method) => {
imageUrl, imageUrl,
mediaUrl: media, mediaUrl: media,
scene, scene,
miniProgram miniProgram,
openCustomerServiceChat,
corpid,
customerUrl: url
} = args } = args
if (typeof imageUrl === 'string' && imageUrl) { if (typeof imageUrl === 'string' && imageUrl) {
...@@ -72,7 +75,10 @@ const parseParams = (args, callbackId, method) => { ...@@ -72,7 +75,10 @@ const parseParams = (args, callbackId, method) => {
miniProgram, miniProgram,
extra: { extra: {
scene scene
} },
openCustomerServiceChat,
corpid,
url
} }
if (provider === 'weixin' && (type === 1 || type === 2)) { if (provider === 'weixin' && (type === 1 || type === 2)) {
delete sendMsg.thumbs delete sendMsg.thumbs
...@@ -84,12 +90,18 @@ const parseParams = (args, callbackId, method) => { ...@@ -84,12 +90,18 @@ const parseParams = (args, callbackId, method) => {
const sendShareMsg = function (service, params, callbackId, method = 'share') { const sendShareMsg = function (service, params, callbackId, method = 'share') {
const errorCallback = warpPlusErrorCallback(callbackId, method) const errorCallback = warpPlusErrorCallback(callbackId, method)
const serviceMethod = params.openCustomerServiceChat ? 'openCustomerServiceChat' : 'send'
service.send(params, () => { try {
invoke(callbackId, { service[serviceMethod](params, () => {
errMsg: method + ':ok' invoke(callbackId, {
errMsg: method + ':ok'
})
}, errorCallback)
} catch (error) {
errorCallback({
message: `${params.provider} ${serviceMethod} 方法调用失败`
}) })
}, errorCallback) }
} }
export function shareAppMessageDirectly ({ export function shareAppMessageDirectly ({
......
...@@ -46,6 +46,7 @@ const attrs = [ ...@@ -46,6 +46,7 @@ const attrs = [
'scale', 'scale',
'markers', 'markers',
'polyline', 'polyline',
'polygons',
'circles', 'circles',
'controls', 'controls',
'show-location' 'show-location'
...@@ -115,6 +116,12 @@ export default { ...@@ -115,6 +116,12 @@ export default {
return [] return []
} }
}, },
polygons: {
type: Array,
default () {
return []
}
},
controls: { controls: {
type: Array, type: Array,
default () { default () {
...@@ -186,6 +193,9 @@ export default { ...@@ -186,6 +193,9 @@ export default {
}, },
circles (val) { circles (val) {
this.map && this._addMapCircles(val) this.map && this._addMapCircles(val)
},
polygons (val) {
this.map && this._addMapPolygons(val)
} }
}, },
mounted () { mounted () {
...@@ -199,6 +209,7 @@ export default { ...@@ -199,6 +209,7 @@ export default {
map.__markers_map__ = {} map.__markers_map__ = {}
map.__lines__ = [] map.__lines__ = []
map.__circles__ = [] map.__circles__ = []
map.__polygons__ = []
map.setZoom(parseInt(this.scale)) map.setZoom(parseInt(this.scale))
plus.webview.currentWebview().append(map) plus.webview.currentWebview().append(map)
if (this.hidden) { if (this.hidden) {
...@@ -218,6 +229,7 @@ export default { ...@@ -218,6 +229,7 @@ export default {
this._addMarkers(this.markers) this._addMarkers(this.markers)
this._addMapLines(this.polyline) this._addMapLines(this.polyline)
this._addMapCircles(this.circles) this._addMapCircles(this.circles)
this._addMapPolygons(this.polygons)
}) })
}, },
beforeDestroy () { beforeDestroy () {
...@@ -423,6 +435,46 @@ export default { ...@@ -423,6 +435,46 @@ export default {
nativeMap.addOverlay(nativeCircle) nativeMap.addOverlay(nativeCircle)
nativeMap.__circles__.push(nativeCircle) nativeMap.__circles__.push(nativeCircle)
}) })
},
_addMapPolygons (polygons) {
const nativeMap = this.map
const nativeMapPolygons = nativeMap.__polygons__
nativeMapPolygons.forEach(polygon => {
nativeMap.removeOverlay(polygon)
})
nativeMapPolygons.length = 0
polygons.forEach(polygon => {
const {
points,
strokeWidth,
strokeColor,
fillColor
} = polygon
const plusPoints = []
if (points) {
points.forEach(({ latitude, longitude }) => {
plusPoints.push(new plus.maps.Point(longitude, latitude))
})
}
const nativePolygon = new plus.maps.Polygon(plusPoints)
if (strokeColor) {
const strokeStyle = parseHex(strokeColor)
nativePolygon.setStrokeColor(strokeStyle.color)
nativePolygon.setStrokeOpacity(strokeStyle.opacity)
}
if (fillColor) {
const fillStyle = parseHex(fillColor)
nativePolygon.setFillColor(fillStyle.color)
nativePolygon.setFillOpacity(fillStyle.opacity)
}
if (strokeWidth) {
nativePolygon.setLineWidth(strokeWidth)
}
nativeMap.addOverlay(nativePolygon)
nativeMapPolygons.push(nativePolygon)
})
} }
} }
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<script> <script>
import { emitter } from 'uni-mixins' import { emitter } from 'uni-mixins'
import { showPage } from './page' import { showPage } from '../../../helpers/page'
import * as webview from './webview' import * as webview from './webview'
import { getNavigationBarHeight } from '../../utils' import { getNavigationBarHeight } from '../../utils'
import { import {
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
:key="item.id" :key="item.id"
v-bind="item" v-bind="item"
/> />
<map-polygon
v-for="item in polygons"
:key="JSON.stringify(item.points)"
v-bind="item"
/>
<div <div
ref="map" ref="map"
style="width: 100%; height: 100%; position: relative; overflow: hidden" style="width: 100%; height: 100%; position: relative; overflow: hidden"
...@@ -37,6 +42,7 @@ import { ...@@ -37,6 +42,7 @@ import {
} from './maps' } from './maps'
import mapMarker from './map-marker' import mapMarker from './map-marker'
import mapPolygon from './map-polygon'
import { ICON_PATH_ORIGIN } from '../../../helpers/location' import { ICON_PATH_ORIGIN } from '../../../helpers/location'
...@@ -59,7 +65,8 @@ function getLng (latLng) { ...@@ -59,7 +65,8 @@ function getLng (latLng) {
export default { export default {
name: 'Map', name: 'Map',
components: { components: {
mapMarker mapMarker,
mapPolygon
}, },
mixins: [subscriber], mixins: [subscriber],
props: { props: {
...@@ -124,6 +131,10 @@ export default { ...@@ -124,6 +131,10 @@ export default {
default () { default () {
return [] return []
} }
},
polygons: {
type: Array,
default: () => []
} }
}, },
data () { data () {
......
import { hexToRgba } from 'uni-shared'
export default {
props: {
// 边框虚线,腾讯地图支持,google 地图不支持,默认值为[0, 0] 为实线,非 [0, 0] 为虚线,H5 端无法像微信小程序一样控制虚线的间隔像素大小
dashArray: {
type: Array,
default: () => [0, 0]
},
// 经纬度数组,[{latitude: 0, longitude: 0}]
points: {
type: Array,
required: true
},
// 描边的宽度
strokeWidth: {
type: Number,
default: 1
},
// 描边的颜色,十六进制
strokeColor: {
type: String,
default: '#000000'
},
// 填充颜色,十六进制
fillColor: {
type: String,
default: '#00000000'
},
// 设置多边形 Z 轴数值
zIndex: {
type: Number,
default: 0
}
},
mounted () {
const { $parent } = this
// 当地图准备好以后调用指定的回调函数
$parent.mapReady(() => {
this.drawPolygon()
// 遍历 props 对象,观察其中的每个属性,当属性发生变化时,更新地图上的 polygon
Object.keys(this.$props).forEach(key => {
this.$watch(key, () => {
this.drawPolygon()
}, { deep: true })
})
})
},
methods: {
// 绘制区域
drawPolygon () {
// polygon 组件的 props 配置
const {
points,
strokeWidth,
strokeColor,
dashArray,
fillColor,
zIndex
} = this
// 从父组件解析 _maps、_map 和 $trigger,下面要用
const { _maps, _map } = this.$parent
const path = points.map(item => {
const { latitude, longitude } = item
return new _maps.LatLng(latitude, longitude)
})
const { r: fcR, g: fcG, b: fcB, a: fcA } = hexToRgba(fillColor)
const { r: scR, g: scG, b: scB, a: scA } = hexToRgba(strokeColor)
const polygonOptions = {
// 多边形是否可点击。
clickable: true,
// 鼠标在多边形内的光标样式。
cursor: 'crosshair',
// 多边形是否可编辑。
editable: false,
// 地图实例,即要显示多边形的地图
// @ts-ignore
map: _map,
// 区域填充色
fillColor: '',
// 多边形的路径,以经纬度坐标数组构成。
path,
// 区域边框
strokeColor: '',
// 多边形的边框样式。实线是solid,虚线是dash。
strokeDashStyle: dashArray.some((item) => item > 0) ? 'dash' : 'solid',
// 多边形的边框线宽。
strokeWeight: strokeWidth,
// 多边形是否可见。
visible: true,
// 多边形的zIndex值。
zIndex: zIndex
}
// 多边形的填充色、边框以及相应的透明度
if (_maps.Color) {
// 说明是 腾讯地图,google map 实例没有 Color 属性
// 将类型转为两者共有的 string,避免 ts 报错
polygonOptions.fillColor = new _maps.Color(fcR, fcG, fcB, fcA)
polygonOptions.strokeColor = new _maps.Color(scR, scG, scB, scA)
} else {
// google map
polygonOptions.fillColor = `rgb(${fcR}, ${fcG}, ${fcB})`
polygonOptions.fillOpacity = fcA
polygonOptions.strokeColor = `rgb(${scR}, ${scG}, ${scB})`
polygonOptions.strokeOpacity = scA
}
if (this.polygonIns) {
// 更新区域属性
this.polygonIns.setOptions(polygonOptions)
return
}
// 说明是新增区域
this.polygonIns = new _maps.Polygon(polygonOptions)
}
},
// 卸载时清除地图上绘制的 polygon
beforeDestroy () {
this.polygonIns.setMap(null)
this.polygonIns = null
},
render () {
return null
}
}
...@@ -28,7 +28,7 @@ function initTriggerEvent (mpInstance) { ...@@ -28,7 +28,7 @@ function initTriggerEvent (mpInstance) {
function initHook (name, options, isComponent) { function initHook (name, options, isComponent) {
if (__PLATFORM__ === 'mp-toutiao') { if (__PLATFORM__ === 'mp-toutiao') {
// fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created // fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created
isComponent && (options = options.lifetimes) isComponent && options.lifetimes && options.lifetimes[name] && (options = options.lifetimes)
} }
const oldHook = options[name] const oldHook = options[name]
if (!oldHook) { if (!oldHook) {
......
/**
* 从 16 进制的色值解析成 rgba 格式的色值
* @param { string } hex, #000、#000A、#000000、#000000AA,参数只能是这四种格式
* @returns {
r: number;
g: number;
b: number;
a: number;
}
*/
export function hexToRgba (hex) { export function hexToRgba (hex) {
let r // 异常情况
let g if (!hex) {
let b return {
hex = hex.replace('#', '') r: 0,
if (hex.length === 6) { g: 0,
r = hex.substring(0, 2) b: 0,
g = hex.substring(2, 4) a: 0
b = hex.substring(4, 6) }
} else if (hex.length === 3) {
r = hex.substring(0, 1)
g = hex.substring(1, 2)
b = hex.substring(2, 3)
} else {
return false
} }
if (r.length === 1) { // 去掉 #
r += r let tmpHex = hex.slice(1)
const tmpHexLen = tmpHex.length
// 处理 16 进制色值位数异常的情况
if (![3, 4, 6, 8].includes(tmpHexLen)) {
return {
r: 0,
g: 0,
b: 0,
a: 0
}
} }
if (g.length === 1) { // 格式化 tmpHex,使其变成 rrggbb 或 rrggbbaa
g += g if (tmpHexLen === 3 || tmpHexLen === 4) {
// rgb => rrggbb || rgba => rrggbbaa
tmpHex = tmpHex.replace(/(\w{1})/g, '$1$1')
} }
if (b.length === 1) { // rgba
b += b const [sr, sg, sb, sa] = tmpHex.match(/(\w{2})/g)
// rgb
const r = parseInt(sr, 16); const g = parseInt(sg, 16); const b = parseInt(sb, 16)
if (!sa) {
return { r, g, b, a: 1 }
} }
r = parseInt(r, 16)
g = parseInt(g, 16)
b = parseInt(b, 16)
return { return {
r, r, g, b, a: (`0x100${sa}` - 0x10000) / 255
g,
b
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册