提交 68cffbad 编写于 作者: Q qiang

Merge branch 'dev' into alpha

......@@ -83,7 +83,7 @@
* commands
* lib
* packages:内置依赖包
* mp-vue:小程序平台使用的 Vue 依赖,由仓库 [fxy060608/vue](https://github.com/fxy060608/vue) 编译。
* mp-vue:小程序平台使用的 Vue 依赖,由仓库 [fxy060608/vue#dev](https://github.com/fxy060608/vue) 编译。
* vue-cli-plugin-uni-optimize:Vue CLI 插件,主要处理 H5 平台摇树优化
* webpack-uni-mp-loader:webpack loader,用于生成小程序平台的各种文件
* webpack-uni-pages-loader:webpack loader,用于解析 pages.json
......@@ -144,4 +144,4 @@
* quickapp-native:快应用平台运行时
* quickapp-webview:快应用平台运行时
* shared
* test:单元测试(运行时)
\ No newline at end of file
* test:单元测试(运行时)
<template>
<view @click="onclick">
<slot
:options="options"
:data="adData"
/>
<slot :options="options" :data="adData" :loading="loading" :error="errorMessage" />
</view>
</template>
<script>
const AD_URL = 'https://wxac1.dcloud.net.cn/tuiaApplet/acs'
const AD_REPORT_URL = 'https://wxac1.dcloud.net.cn/tuiaApplet/acs'
const WEBVIEW_PATH = '/uni_modules/uni-ad-interactive/pages/uni-ad-interactive/uni-ad-interactive'
const AD_URL = 'https://wxac1.dcloud.net.cn/openPage/acs'
const AD_REPORT_URL = 'https://wxac1.dcloud.net.cn/openPage/acs'
//const WEBVIEW_PATH = '/uni_modules/uni-ad-interactive/pages/uni-ad-interactive/uni-ad-interactive'
const events = {
load: 'load',
close: 'close',
error: 'error'
}
const events = {
load: 'load',
close: 'close',
error: 'error'
}
const OpenTypes = {
Interactive: 'interactive'
}
const OpenTypes = {
Interactive: 'interactive'
}
export default {
name: 'AdInteractive',
props: {
options: {
type: [Object, Array],
default () {
return {}
export default {
name: 'AdInteractive',
props: {
options: {
type: [Object, Array],
default () {
return {}
}
},
disabled: {
type: [Boolean, String],
default: false
},
adpid: {
type: [Number, String],
default: ''
},
openType: {
type: String,
default: 'interactive'
},
openPagePath: {
type: String,
default: ""
}
},
adpid: {
type: [Number, String],
default: ''
},
openUrl: {
type: String,
default: WEBVIEW_PATH
}
},
data () {
return {
adData: {}
}
},
created () {
this._uniAdPlugin = null
this._interactiveUrl = null
if (this.openType === OpenTypes.Interactive) {
this.getAdData()
}
},
methods: {
show () {
if (this._uniAdPlugin === null) {
this._uniAdPlugin = this.selectComponent('.uni-ad-plugin')
data() {
return {
adData: null,
loading: false,
errorMessage: ""
}
this._uniAdPlugin.show()
},
getAdData () {
if (!this.adpid) {
this.$emit(events.error, {
code: -5002,
message: 'invalid adpid'
})
return
created() {
this._uniAdPlugin = null
this._interactiveUrl = null
if (this.openPagePath) {
this.getAdData()
}
},
methods: {
show() {
if (this._uniAdPlugin === null) {
this._uniAdPlugin = this.selectComponent('.uni-ad-plugin')
}
this._uniAdPlugin.show()
},
getAdData() {
if (!this.adpid) {
this.$emit(events.error, {
code: -5002,
message: 'invalid adpid'
})
return
}
uni.request({
url: AD_URL,
method: 'POST',
data: {
adpid: this.adpid
},
timeout: 5000,
dataType: 'json',
success: (res) => {
console.log(res.data)
this.loading = true
if (res.statusCode !== 200) {
this.$emit(events.error, {
code: res.statusCode,
message: res.statusCode
})
return
}
uni.request({
url: AD_URL,
method: 'POST',
data: {
adpid: this.adpid
},
timeout: 5000,
dataType: 'json',
success: (res) => {
if (res.statusCode !== 200) {
this.$emit(events.error, {
errCode: res.statusCode,
errMsg: res.statusCode
})
return
}
const responseData = res.data
if (responseData.ret === 0) {
this._interactiveUrl = responseData.data.adp_url
this.adData.imgUrl = responseData.data.icon_url
this.adData.openUrl = this.openUrl + '?url=' + encodeURIComponent(this._interactiveUrl)
this.$emit(events.load, {})
} else {
const responseData = res.data
if (responseData.ret === 0) {
this._interactiveUrl = responseData.data.adp_url
this.adData = {
imgUrl: responseData.data.icon_url,
openPath: this.openPagePath + '?url=' + encodeURIComponent(this._interactiveUrl)
}
this.$emit(events.load, this.adData)
} else {
const errMsg = {
errCode: responseData.ret,
errMsg: responseData.msg
}
this.errorMessage = errMsg
this.$emit(events.error, errMsg)
}
},
fail: (err) => {
this.$emit(events.error, {
code: responseData.ret,
message: responseData.msg
errCode: '',
errMsg: err.errMsg
})
},
complete: () => {
this.loading = false
}
},
fail: (err) => {
this.$emit(events.error, {
code: '',
message: err.errMsg
})
})
},
onclick() {
if (this.disabled) {
return
}
if (!this._interactiveUrl) {
return
}
})
},
onclick () {
if (this.openType !== OpenTypes.Interactive || !this._interactiveUrl) {
return
}
uni.navigateTo({
url: this.adData.openUrl
})
uni.navigateTo({
url: this.adData.openPath
})
this._report()
},
_report () {
uni.request({
url: AD_REPORT_URL,
data: {
adpid: this.adpid,
t: '10019'
},
timeout: 5000,
dataType: 'json'
})
this._report()
},
_report() {
uni.request({
url: AD_REPORT_URL,
data: {
adpid: this.adpid,
t: '10019'
},
timeout: 5000,
dataType: 'json'
})
}
}
}
}
</script>
<style>
......
......@@ -26,6 +26,8 @@ function createUniMPPlugin () {
}
const createWxMpIndependentPlugins = require('@dcloudio/uni-mp-weixin/lib/createIndependentPlugin')
const UniTips = require('./tips')
function getProvides () {
const uniPath = require('@dcloudio/uni-cli-shared/lib/platform').getMPRuntimePath()
......@@ -190,7 +192,7 @@ module.exports = {
if ((process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN) && process.env.UNI_SUBPACKGE !== 'main') {
plugins.push(new PreprocessAssetsPlugin())
}
}
{
const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx';
......@@ -228,7 +230,12 @@ ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;`
}
if (process.env.NODE_ENV === 'production' || process.env.UNI_MINIMIZE === 'true') {
output.pathinfo = false
}
}
if (process.env.UNI_PLATFORM === 'mp-weixin' && process.env.NODE_ENV === 'production') {
plugins.push(new UniTips())
}
return {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
entry () {
......
const fs = require('fs')
const path = require('path')
const {
isInHBuilderX
} = require('@dcloudio/uni-cli-shared')
class UniTips {
apply (compiler) {
compiler.hooks.emit.tap('PreprocessAssetsPlugin', compilation => {
const assets = compilation.assets
let hasAd = false
try {
Object.keys(assets).forEach(name => {
if (hasAd) {
return
}
if (!name.startsWith('common') && !name.startsWith('pages')) {
return
}
const extname = path.extname(name)
if (extname !== '.js') {
return
}
if (!hasAd && !process.env.USE_UNI_AD) {
hasAd = assets[name]._value.match(/createRewardedVideoAd|createInterstitialAd/)
}
})
setTimeout(() => {
if (hasAd) {
console.log(
'推荐使用uni-ad微信小程序版广告,无开通门槛、提前结算、插件丰富,助力广告变现。详情: https://uniapp.dcloud.net.cn/component/ad-weixin.html'
)
}
let projectRoot = ''
if (isInHBuilderX) {
projectRoot = process.env.UNI_INPUT_DIR
} else {
projectRoot = process.env.UNI_CLI_CONTEXT
}
const paths = fs.readdirSync(projectRoot)
const useUniCloud = paths.find((name) => {
return name.includes('uniCloud-')
})
if (!useUniCloud && assets['project.config.json']) {
const pcjString = assets['project.config.json'].source()
const pcjJson = JSON.parse(pcjString)
if (typeof pcjJson.cloudfunctionRoot === 'string' && pcjJson.cloudfunctionRoot.length > 0) {
console.log(
'欢迎使用uniCloud,价格更便宜、开发更方便、生态更丰富的云开发。详情: https://uniapp.dcloud.net.cn/uniCloud/wx2unicloud.html'
)
}
}
}, 100)
} catch (e) {}
})
}
}
module.exports = UniTips
......@@ -133,22 +133,6 @@ function initPushNotification() {
},
});
});
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'click',
message: result,
});
});
uni.onPushMessage((res) => {
if (res.type === 'receive' &&
res.data &&
res.data.force_notification) {
// 创建通知栏
uni.createPushMessage(res.data);
res.stopped = true;
}
});
}
}
......@@ -207,4 +191,16 @@ else {
});
},
});
// 仅在 jssdk 中监听
// #ifdef APP
uni.onPushMessage((res) => {
if (res.type === 'receive' &&
res.data &&
res.data.force_notification) {
// 创建通知栏
uni.createPushMessage(res.data);
res.stopped = true;
}
});
// #endif
}
......@@ -31,22 +31,6 @@ function initPushNotification() {
},
});
});
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'click',
message: result,
});
});
uni.onPushMessage((res) => {
if (res.type === 'receive' &&
res.data &&
res.data.force_notification) {
// 创建通知栏
uni.createPushMessage(res.data);
res.stopped = true;
}
});
}
}
......@@ -58,11 +42,4 @@ uni.invokePushCallback({
Promise.resolve().then(() => {
initPushNotification();
plus.push.setAutoNotification && plus.push.setAutoNotification(false);
plus.push.addEventListener('receive', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'pushMsg',
message: result,
});
});
});
......@@ -87,12 +87,6 @@ function findHooks (vueOptions, hooks = []) {
function initHook (mpOptions, hook, excludes) {
if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
mpOptions[hook] = function (args) {
if (
(__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark') &&
hook === 'onError'
) {
return getApp().$vm.$callHook(hook, args)
}
return this.$vm && this.$vm.__call_hook(hook, args)
}
}
......
......@@ -23,7 +23,7 @@ export function invokePushCallback (
) {
if (args.type === 'enabled') {
enabled = true
if (__PLATFORM__ === 'app') {
if (__PLATFORM__ === 'app-plus') {
offline = args.offline
}
} else if (args.type === 'clientId') {
......@@ -76,7 +76,7 @@ export function getPushClientId (args) {
const hasComplete = isFn(complete)
// App 端且启用离线时,使用 getClientInfoAsync 来调用
if (__PLATFORM__ === 'app' && offline) {
if (__PLATFORM__ === 'app-plus' && offline) {
plus.push.getClientInfoAsync(
(info) => {
const res = {
......@@ -126,10 +126,27 @@ export function getPushClientId (args) {
}
const onPushMessageCallbacks = []
let listening = false
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
export const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn)
}
// 不能程序启动时就监听,因为离线事件,仅触发一次,框架监听后,无法转发给还没开始监听的开发者
if (__PLATFORM__ === 'app' && !listening) {
listening = true
plus.push.addEventListener('click', (result) => {
invokePushCallback({
type: 'click',
message: result
})
})
plus.push.addEventListener('receive', (result) => {
invokePushCallback({
type: 'pushMsg',
message: result
})
})
}
}
......
......@@ -269,33 +269,22 @@ export default {
const self = this
window.AMap.plugin('AMap.PlaceSearch', function () {
var autoOptions = {
const placeSearch = new window.AMap.PlaceSearch({
city: '全国',
pageSize: 10,
pageIndex: self.pageIndex
}
var placeSearch = new window.AMap.PlaceSearch(autoOptions)
if (self.searching) {
placeSearch.searchNearBy(self.keyword, [self.longitude, self.latitude], 50000, function (status, result) {
if (status === 'error') {
console.error(result)
} else if (status === 'no_data') {
self.hasNextPage = false
} else {
self.pushData(result.poiList.pois)
}
})
} else {
placeSearch.searchNearBy('', [self.longitude, self.latitude], 5000, function (status, result) {
if (status === 'error') {
console.error(result)
} else if (status === 'no_data') {
self.hasNextPage = false
} else {
self.pushData(result.poiList.pois)
}
})
}
})
const keyword = self.searching ? self.keyword : ''
const radius = self.searching ? 50000 : 5000
placeSearch.searchNearBy(keyword, [self.longitude, self.latitude], radius, function (status, result) {
if (status === 'error') {
console.error(result)
} else if (status === 'no_data') {
self.hasNextPage = false
} else {
self.pushData(result.poiList.pois)
}
})
self.loading = false
})
}
......
......@@ -5,6 +5,7 @@ import {
MapType,
getMapInfo
} from '../../../helpers/location'
import { loadMaps } from '../../../view/components/map/maps'
/**
* 获取定位信息
......@@ -67,44 +68,57 @@ export function getLocation ({
reject(new Error('network error'))
}
})
} else if (mapInfo.type === MapType.AMAP) {
window.AMap.plugin('AMap.Geolocation', function () {
var geolocation = new window.AMap.Geolocation({})
geolocation.getCurrentPosition(function (status, res) {
if (status === 'complete') {
resolve({
latitude: res.position.lat,
longitude: res.position.lng,
accuracy: res.accuracy
})
} else {
reject(new Error((res.message) || JSON.stringify(res)))
}
})
})
} else {
reject(new Error('network error'))
}
})
}).then((coords, skip) => {
if (type.toUpperCase() === 'WGS84' || mapInfo.type !== MapType.QQ || skip) {
const wgs84Map = [MapType.GOOGLE]
if (type.toUpperCase() === 'WGS84' || wgs84Map.includes(mapInfo.type) || skip) {
return coords
}
return new Promise((resolve, reject) => {
getJSONP(`https://apis.map.qq.com/jsapi?qt=translate&type=1&points=${coords.longitude},${coords.latitude}&key=${mapInfo.key}&output=jsonp&pf=jsapi&ref=jsapi`, {
callback: 'cb'
}, (res) => {
if ('detail' in res && 'points' in res.detail && res.detail.points.length) {
const location = res.detail.points[0]
resolve(Object.assign({}, coords, {
longitude: location.lng,
latitude: location.lat
}))
} else {
resolve(coords)
}
}, () => resolve(coords))
})
if (mapInfo.type === MapType.QQ) {
return new Promise((resolve) => {
getJSONP(`https://apis.map.qq.com/jsapi?qt=translate&type=1&points=${coords.longitude},${coords.latitude}&key=${mapInfo.key}&output=jsonp&pf=jsapi&ref=jsapi`, {
callback: 'cb'
}, (res) => {
if ('detail' in res && 'points' in res.detail && res.detail.points.length) {
const location = res.detail.points[0]
resolve(Object.assign({}, coords, {
longitude: location.lng,
latitude: location.lat
}))
} else {
resolve(coords)
}
}, () => resolve(coords))
})
}
if (mapInfo.type === MapType.AMAP) {
return new Promise((resolve) => {
loadMaps([], () => {
window.AMap.convertFrom(
[coords.longitude, coords.latitude],
'gps',
(_, res) => {
if (res.info === 'ok' && res.locations.length) {
const { lat, lng } = res.locations[0]
resolve(
Object.assign({}, coords, {
longitude: lng,
latitude: lat
})
)
} else {
resolve(coords)
}
}
)
})
})
}
}).then(coords => {
invoke(callbackId, Object.assign(coords, {
errMsg: 'getLocation:ok',
......
......@@ -234,7 +234,6 @@ export default {
return
}
const { pageX, pageY } = e.changedTouches[0]
this.$trigger('click', { x: pageX, y: pageY }, {})
this.$trigger('tap', { x: pageX, y: pageY }, {})
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册