提交 e4d94a97 编写于 作者: Q qiang

Merge branch 'dev' into alpha

......@@ -258,18 +258,18 @@ export default {
} = res.result
this._isEnded = data.length < this.pageSize
callback && callback(data, this._isEnded)
this._dispatchEvent(events.load, data)
const data2 = this.getone ? (data.length ? data[0] : undefined) : data
if (this.getone) {
this.dataList = data.length ? data[0] : undefined
} else if (this.pageData === pageMode.add) {
this.dataList.push(...data)
callback && callback(data2, this._isEnded)
this._dispatchEvent(events.load, data2)
if (this.pageData === pageMode.add) {
this.dataList.push(...data2)
if (this.dataList.length) {
this.paginationInternal.current++
}
} else if (this.pageData === pageMode.replace) {
this.dataList = data
} else {
this.dataList = data2
}
if (this.getcount) {
......
......@@ -1386,7 +1386,7 @@ function resolveAsset(type, name, warnMissing = true) {
if (name === `_self`) {
return Component;
}
const selfName = Component.displayName || Component.name;
const selfName = getComponentName(Component);
if (selfName &&
(selfName === name ||
selfName === camelize(name) ||
......@@ -2354,6 +2354,7 @@ function applyOptions(instance, options, deferredData = [], deferredWatch = [],
deferredData.forEach(dataFn => resolveData(instance, dataFn, publicThis));
}
if (dataOptions) {
// @ts-ignore dataOptions is not fully type safe
resolveData(instance, dataOptions, publicThis);
}
if ((process.env.NODE_ENV !== 'production')) {
......@@ -3190,11 +3191,14 @@ function recordInstanceBoundEffect(effect, instance = currentInstance) {
}
const classifyRE = /(?:^|[-_])(\w)/g;
const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
/* istanbul ignore next */
function formatComponentName(instance, Component, isRoot = false) {
let name = isFunction(Component)
function getComponentName(Component) {
return isFunction(Component)
? Component.displayName || Component.name
: Component.name;
}
/* istanbul ignore next */
function formatComponentName(instance, Component, isRoot = false) {
let name = getComponentName(Component);
if (!name && Component.__file) {
const match = Component.__file.match(/([^/\\]+)\.\w+$/);
if (match) {
......@@ -3243,7 +3247,7 @@ function defineEmit() {
}
// Core API ------------------------------------------------------------------
const version = "3.0.3";
const version = "3.0.4";
// import deepCopy from './deepCopy'
/**
......
......@@ -63,23 +63,28 @@ function generateAutoComponentsCode (autoComponents, dynamic = false) {
// 统一转换为驼峰命名
name = name.replace(/-(\w)/g, (_, str) => str.toUpperCase())
if (dynamic) {
components.push(`'${name}': function(){return import(/* webpackChunkName: "${getWebpackChunkName(source)}" */'${source}')}`)
components.push(
`'${name}': function(){return import(/* webpackChunkName: "${getWebpackChunkName(source)}" */'${source}')}`
)
} else {
components.push(`'${name}': require('${source}').default`)
}
})
return `var components;
try{
components = {${components.join(',')}}
}catch(e){
if(e.message.indexOf('Cannot find module') !== -1 && e.message.indexOf('.vue') !== -1){
console.error(e.message)
console.error('1. 排查组件名称拼写是否正确')
console.error('2. 排查组件是否符合 easycom 规范,文档:https://uniapp.dcloud.net.cn/collocation/pages?id=easycom')
console.error('3. 若组件不符合 easycom 规范,需手动引入,并在 components 中注册该组件')
} else {
throw e
}
if (process.env.NODE_ENV === 'production') {
return `var components = {${components.join(',')}}`
}
return `var components;
try{
components = {${components.join(',')}}
}catch(e){
if(e.message.indexOf('Cannot find module') !== -1 && e.message.indexOf('.vue') !== -1){
console.error(e.message)
console.error('1. 排查组件名称拼写是否正确')
console.error('2. 排查组件是否符合 easycom 规范,文档:https://uniapp.dcloud.net.cn/collocation/pages?id=easycom')
console.error('3. 若组件不符合 easycom 规范,需手动引入,并在 components 中注册该组件')
} else {
throw e
}
}`
}
......@@ -99,9 +104,9 @@ function compileTemplate (source, options, compile) {
}
const compilerModule = {
preTransformNode (el, options) {
if (el.tag === 'match-media' && process.env.UNI_PLATFORM !== 'mp-weixin') {
el.tag = 'uni-match-media'
preTransformNode (el, options) {
if (el.tag === 'match-media' && process.env.UNI_PLATFORM !== 'mp-weixin') {
el.tag = 'uni-match-media'
}
if (process.env.UNI_PLATFORM === 'quickapp-native') {
// 排查所有标签
......@@ -115,4 +120,4 @@ const compilerModule = {
module.exports = {
compileTemplate,
module: compilerModule
}
}
......@@ -95,7 +95,7 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
const defines = {
'process.env.UNI_ENV': JSON.stringify(process.env.UNI_PLATFORM),
'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'process.env.HBX_USER_TOKEN': JSON.stringify(process.env.HBX_USER_TOKEN || ''),
'process.env.UNICLOUD_DEBUG': process.env.UNICLOUD_DEBUG,
'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT)
}
if (process.env.UNI_USING_VUE3) {
......
......@@ -2204,8 +2204,9 @@ var HTML5History = (function (History$$1) {
// fixed by xxxxxx
var id = e.state && e.state.id;
if (!id) {
// TODO
id = router.id;
// 当手动切换页面时,强制刷新
return window.location.reload()
// id = router.id
}
this$1.transitionTo({ // fixed by xxxxxx
......@@ -2353,8 +2354,9 @@ var HashHistory = (function (History$$1) {
// fixed by xxxxxx
var id = e.state && e.state.id;
if (!id) {
// TODO
id = router.id;
// 当手动切换页面时,强制刷新
return window.location.reload()
// id = router.id
}
this$1.transitionTo({
......
......@@ -2202,8 +2202,9 @@ var HTML5History = (function (History$$1) {
// fixed by xxxxxx
var id = e.state && e.state.id;
if (!id) {
// TODO
id = router.id;
// 当手动切换页面时,强制刷新
return window.location.reload()
// id = router.id
}
this$1.transitionTo({ // fixed by xxxxxx
......@@ -2351,8 +2352,9 @@ var HashHistory = (function (History$$1) {
// fixed by xxxxxx
var id = e.state && e.state.id;
if (!id) {
// TODO
id = router.id;
// 当手动切换页面时,强制刷新
return window.location.reload()
// id = router.id
}
this$1.transitionTo({
......
......@@ -2208,8 +2208,9 @@ var HTML5History = (function (History$$1) {
// fixed by xxxxxx
var id = e.state && e.state.id;
if (!id) {
// TODO
id = router.id;
// 当手动切换页面时,强制刷新
return window.location.reload()
// id = router.id
}
this$1.transitionTo({ // fixed by xxxxxx
......@@ -2357,8 +2358,9 @@ var HashHistory = (function (History$$1) {
// fixed by xxxxxx
var id = e.state && e.state.id;
if (!id) {
// TODO
id = router.id;
// 当手动切换页面时,强制刷新
return window.location.reload()
// id = router.id
}
this$1.transitionTo({
......
......@@ -81,7 +81,7 @@ function beforeEach (to, from, next, routes) {
if (toId === fromId && to.type !== 'reLaunch') { // 相同页面阻止
// 处理外部修改 history 导致卡在当前页面的问题
if (to.fullPath !== from.fullPath) {
removeKeepAliveInclude.call(this, toName)
addKeepAliveInclude.call(this, toName)
next()
} else {
next(false)
......
......@@ -95,6 +95,15 @@ export default {
})
initClick(this.$el)
initScrollBounce()
let $vm = this
while ($vm) {
const scopeId = $vm.$options._scopeId
if (scopeId) {
this.$refs.indicator.setAttribute(scopeId, '')
}
$vm = $vm.$parent
}
},
methods: {
_setItemHeight (height) {
......
......@@ -2,33 +2,33 @@
<uni-slider
ref="uni-slider"
v-on="$listeners"
@click="_onClick"
@click="_onClick"
>
<div class="uni-slider-wrapper">
<div class="uni-slider-tap-area">
<div
:style="setBgColor"
class="uni-slider-handle-wrapper"
class="uni-slider-handle-wrapper"
>
<div
ref="uni-slider-handle"
:style="setBlockBg"
class="uni-slider-handle"
class="uni-slider-handle"
/>
<div
:style="setBlockStyle"
class="uni-slider-thumb"
class="uni-slider-thumb"
/>
<div
:style="setActiveColor"
class="uni-slider-track"
class="uni-slider-track"
/>
</div>
</div>
<span
v-show="showValue"
v-show="showValue"
ref="uni-slider-value"
class="uni-slider-value"
class="uni-slider-value"
>{{ sliderValue }}</span>
</div>
<slot />
......@@ -40,6 +40,78 @@ import {
listeners
} from 'uni-mixins'
import touchtrack from 'uni-mixins/touchtrack'
// 处理js计算小数时的精度问题
var computeController = {
add: function (arg) {
var r1, r2, m
try {
// 获得小数位数
r1 = this.toString().split('.')[1].length
} catch (e) {
r1 = 0
}
try {
// 获得小数位数
r2 = arg.toString().split('.')[1].length
} catch (e) {
r2 = 0
}
m = Math.pow(10, Math.max(r1, r2))
return (this * m + arg * m) / m
},
sub: function (arg) {
return this.add(-arg)
},
mul: function (arg) {
var m = 0; var s1 = this.toString(); var s2 = arg.toString()
try {
// 获得小数位数
m += s1.split('.')[1].length
} catch (e) { }
try {
// 获得小数位数
m += s2.split('.')[1].length
} catch (e) { }
// 转为十进制计算后,要除以两个数的共同小数位数
return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m)
},
div: function (arg) {
var t1 = 0; var t2 = 0; var r1; var r2
try {
// 获得小数位数
t1 = this.toString().split('.')[1].length
} catch (e) { }
try {
// 获得小数位数
t2 = arg.toString().split('.')[1].length
} catch (e) { }
r1 = Number(this.toString().replace('.', ''))
r2 = Number(arg.toString().replace('.', ''))
// 转为十进制计算后,要乘以除数与被除数小数位数的差
return (r1 / r2) * Math.pow(10, t2 - t1)
},
mod: function (arg) {
var t1 = 0; var t2 = 0; var r1; var r2
try {
t1 = this.toString().split('.')[1].length
} catch (e) { }
try {
t2 = arg.toString().split('.')[1].length
} catch (e) { }
// 小数位数
var digit = Math.pow(10, Math.abs(t1 - t2))
// eslint-disable-next-line eqeqeq
if (digit == 1) { digit = Math.pow(10, t1) }
// 计算余数
r1 = (this * digit).toString().split('.')[0]
r2 = arg * digit
// 小数点后数字,直接拼接上即可
var decimals = (this * digit).toString().split('.')[1] ? (this * digit).toString().split('.')[1] : ''
return (r1 % r2 + decimals) / digit
}
}
export default {
name: 'Slider',
mixins: [emitter, listeners, touchtrack],
......@@ -151,22 +223,21 @@ export default {
})
},
methods: {
_onUserChangedValue (e) {
const sliderRightBox = this.$refs['uni-slider-value']
const sliderRightBoxLeft = getComputedStyle(sliderRightBox, null).marginLeft
let sliderRightBoxWidth = sliderRightBox.offsetWidth
sliderRightBoxWidth = sliderRightBoxWidth + parseInt(sliderRightBoxLeft)
_onUserChangedValue (e) {
const sliderRightBox = this.$refs['uni-slider-value']
const sliderRightBoxLeft = getComputedStyle(sliderRightBox, null).marginLeft
let sliderRightBoxWidth = sliderRightBox.offsetWidth
sliderRightBoxWidth = sliderRightBoxWidth + parseInt(sliderRightBoxLeft)
const slider = this.$refs['uni-slider']
const offsetWidth = slider.offsetWidth - (this.showValue ? sliderRightBoxWidth : 0)
const boxLeft = slider.getBoundingClientRect().left
const value = (e.x - boxLeft) * (this.max - this.min) / offsetWidth + Number(this.min)
this.sliderValue = this._filterValue(value)
},
_filterValue (e) {
const max = Number(this.max)
_filterValue (e) {
const max = Number(this.max)
const min = Number(this.min)
return e < min ? min : e > max ? max : Math.round((e - min) / this
.step) * this.step + min
return e < min ? min : e > max ? max : computeController.mul.call(Math.round((e - min) / this.step), this.step) + min
},
_getValueWidth () {
return 100 * (this.sliderValue - this.min) / (this.max - this.min) + '%'
......@@ -180,7 +251,7 @@ export default {
: '#e9e9e9')
},
_onTrack: function (e) {
if (!this.disabled) {
if (!this.disabled) {
return e.detail.state === 'move' ? (this._onUserChangedValue({
x: e.detail.x0
}), this.$trigger('changing', e, {
......@@ -288,11 +359,11 @@ export default {
z-index: 1;
}
uni-slider .uni-slider-value {
uni-slider .uni-slider-value {
width: 3ch;
color: #888;
font-size: 14px;
margin-left: 1em;
margin-left: 1em;
}
uni-slider .uni-slider-disabled .uni-slider-track {
......
const eventNames = [
'load',
'close',
'error'
'error',
'adClicked'
]
class FullScreenVideoAd {
......@@ -50,6 +51,9 @@ class FullScreenVideoAd {
this._loadPromiseReject = null
}
})
ad.onAdClicked((e) => {
this._dispatchEvent('adClicked', {})
})
}
load () {
......
......@@ -2,7 +2,8 @@ const eventNames = [
'load',
'close',
'verify',
'error'
'error',
'adClicked'
]
const ERROR_CODE_LIST = [-5001, -5002, -5003, -5004, -5005, -5006]
......@@ -62,6 +63,9 @@ class RewardedVideoAd {
this._loadPromiseReject = null
}
})
rewardAd.onAdClicked((e) => {
this._dispatchEvent('adClicked', {})
})
if (this._preload) {
this._loadAd()
......
export function getScreenBrightness () {
return {
errMsg: 'getScreenBrightness:ok',
value: plus.screen.getBrightness()
value: plus.screen.getBrightness(false)
}
}
export function setScreenBrightness ({
value
} = {}) {
plus.screen.setBrightness(value)
plus.screen.setBrightness(value, false)
return {
errMsg: 'setScreenBrightness:ok'
}
......@@ -21,4 +21,4 @@ export function setKeepScreenOn ({
return {
errMsg: 'setKeepScreenOn:ok'
}
}
}
......@@ -49,7 +49,7 @@ export function previewImagePlus ({
title: item,
color: itemColor
})),
cancel: '取消'
cancel: ''
}
if (title) {
options.title = title
......
......@@ -52,7 +52,7 @@ const createUploadTaskById = function (uploadTaskId, {
for (const name in header) {
if (hasOwn(header, name)) {
uploader.setRequestHeader(name, header[name])
uploader.setRequestHeader(name, String(header[name]))
}
}
for (const name in formData) {
......
......@@ -58,7 +58,7 @@ export function getProvider ({
providers[service]((err, provider) => {
if (err) {
invoke(callbackId, {
errMsg: 'getProvider:fail:' + err.message
errMsg: 'getProvider:fail ' + err.message
})
} else {
invoke(callbackId, {
......@@ -70,7 +70,7 @@ export function getProvider ({
})
} else {
invoke(callbackId, {
errMsg: 'getProvider:fail:服务[' + service + ']不支持'
errMsg: 'getProvider:fail 服务[' + service + ']不支持'
})
}
}
......@@ -20,6 +20,8 @@ function getService (provider) {
*/
export function login (params, callbackId) {
const provider = params.provider || 'weixin'
const errorCallback = warpPlusErrorCallback(callbackId, 'login')
getService(provider).then(service => {
function login () {
service.login(res => {
......@@ -29,12 +31,7 @@ export function login (params, callbackId) {
authResult: authResult,
errMsg: 'login:ok'
})
}, err => {
invoke(callbackId, {
code: err.code,
errMsg: 'login:fail:' + err.message
})
}, provider === 'apple' ? { scope: 'email' } : params.univerifyStyle || {})
}, errorCallback, provider === 'apple' ? { scope: 'email' } : params.univerifyStyle || {})
}
// 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname;一键登录无logout
......@@ -43,12 +40,7 @@ export function login (params, callbackId) {
} else {
service.logout(login, login)
}
}).catch(err => {
invoke(callbackId, {
code: err.code || '',
errMsg: 'login:fail:' + err.message
})
})
}).catch(errorCallback)
}
export function getUserInfo (params, callbackId) {
......
......@@ -2,29 +2,27 @@ import {
invoke
} from '../../bridge'
import {
warpPlusErrorCallback
} from '../util'
export function requestPayment (params, callbackId) {
const provider = params.provider
const errorCallback = warpPlusErrorCallback(callbackId, 'requestPayment')
plus.payment.getChannels(services => {
const service = services.find(({
id
}) => id === provider)
if (!service) {
invoke(callbackId, {
errMsg: 'requestPayment:fail:支付服务[' + provider + ']不存在'
errMsg: 'requestPayment:fail 支付服务[' + provider + ']不存在'
})
} else {
plus.payment.request(service, params.orderInfo, res => {
res.errMsg = 'requestPayment:ok'
invoke(callbackId, res)
}, err => {
invoke(callbackId, {
errMsg: 'requestPayment:fail:' + err.message
})
})
}, errorCallback)
}
}, err => {
invoke(callbackId, {
errMsg: 'requestPayment:fail:' + err.message
})
})
}, errorCallback)
}
......@@ -3,7 +3,8 @@ import {
} from '../constants'
import {
getRealPath
getRealPath,
warpPlusErrorCallback
} from '../util'
import {
......@@ -82,19 +83,13 @@ const parseParams = (args, callbackId, method) => {
}
const sendShareMsg = function (service, params, callbackId, method = 'share') {
service.send(
params,
() => {
invoke(callbackId, {
errMsg: method + ':ok'
})
},
err => {
invoke(callbackId, {
errMsg: method + ':fail:' + err.message
})
}
)
const errorCallback = warpPlusErrorCallback(callbackId, method)
service.send(params, () => {
invoke(callbackId, {
errMsg: method + ':ok'
})
}, errorCallback)
}
export function shareAppMessageDirectly ({
......@@ -117,37 +112,24 @@ export function shareAppMessageDirectly ({
'shareAppMessageDirectly'
)
}
const errorCallback = warpPlusErrorCallback(callbackId, 'shareAppMessageDirectly')
if (useDefaultSnapshot) {
const pages = getCurrentPages()
const webview = plus.webview.getWebviewById(pages[pages.length - 1].__wxWebviewId__ + '')
if (webview) {
const bitmap = new plus.nativeObj.Bitmap()
webview.draw(
bitmap,
() => {
const fileName = TEMP_PATH + '/share/snapshot.jpg'
bitmap.save(
fileName, {
overwrite: true,
format: 'jpg'
},
() => {
imageUrl = fileName
goShare()
},
err => {
invoke(callbackId, {
errMsg: 'shareAppMessageDirectly:fail:' + err.message
})
}
)
},
err => {
invoke(callbackId, {
errMsg: 'shareAppMessageDirectly:fail:' + err.message
})
}
)
webview.draw(bitmap, () => {
const fileName = TEMP_PATH + '/share/snapshot.jpg'
bitmap.save(
fileName, {
overwrite: true,
format: 'jpg'
}, () => {
imageUrl = fileName
goShare()
}, errorCallback)
}, errorCallback)
} else {
goShare()
}
......@@ -158,73 +140,62 @@ export function shareAppMessageDirectly ({
export function share (params, callbackId, method = 'share') {
params = parseParams(params, callbackId, method)
const errorCallback = warpPlusErrorCallback(callbackId, method)
if (typeof params === 'string') {
return invoke(callbackId, {
errMsg: method + ':fail:' + params
errMsg: method + ':fail ' + params
})
}
const provider = params.provider
plus.share.getServices(
services => {
const service = services.find(({
id
}) => id === provider)
if (!service) {
invoke(callbackId, {
errMsg: method + ':fail:分享服务[' + provider + ']不存在'
})
} else {
if (service.authenticated) {
sendShareMsg(service, params, callbackId)
} else {
service.authorize(
() => sendShareMsg(service, params, callbackId),
err => {
invoke(callbackId, {
errMsg: method + ':fail:' + err.message
})
}
)
}
}
},
err => {
plus.share.getServices(services => {
const service = services.find(({
id
}) => id === provider)
if (!service) {
invoke(callbackId, {
errMsg: method + ':fail:' + err.message
errMsg: method + ':fail 分享服务[' + provider + ']不存在'
})
} else {
if (service.authenticated) {
sendShareMsg(service, params, callbackId)
} else {
service.authorize(
() => sendShareMsg(service, params, callbackId),
errorCallback
)
}
}
)
}, errorCallback)
}
export function shareWithSystem (params, callbackId, method = 'shareWithSystem') {
let {
type,
imageUrl,
summary: content,
href
export function shareWithSystem (params, callbackId, method = 'shareWithSystem') {
let {
type,
imageUrl,
summary: content,
href
} = params
type = type || 'text'
const allowedTypes = ['text', 'image']
if (allowedTypes.indexOf(type) < 0) {
invoke(callbackId, {
errMsg: method + ':fail:分享参数 type 不正确'
})
}
if (typeof imageUrl === 'string' && imageUrl) {
imageUrl = getRealPath(imageUrl)
const allowedTypes = ['text', 'image']
const errorCallback = warpPlusErrorCallback(callbackId, method)
if (allowedTypes.indexOf(type) < 0) {
invoke(callbackId, {
errMsg: method + ':fail 分享参数 type 不正确'
})
}
if (typeof imageUrl === 'string' && imageUrl) {
imageUrl = getRealPath(imageUrl)
}
plus.share.sendWithSystem({
type,
pictures: imageUrl && [imageUrl],
content,
href
plus.share.sendWithSystem({
type,
pictures: imageUrl && [imageUrl],
content,
href
}, function (res) {
invoke(callbackId, {
errMsg: method + ':ok'
})
}, function (err) {
invoke(callbackId, {
errMsg: method + ':fail:' + err.message
})
})
}
}, errorCallback)
}
......@@ -37,7 +37,7 @@ function backWebview (webview, callback) {
// 如果页面有subNvues,切使用了webview组件,则返回时子webview会取错,因此需要做id匹配
const childWebview = children.find(webview => webview.id.indexOf(WEBVIEW_ID_PREFIX) === 0) || children[0]
console.log('backWebview -> childWebview', childWebview)
childWebview.canBack(({
canBack
}) => {
......
......@@ -190,9 +190,11 @@ export function warpPlusSuccessCallback (callbackId, neme) {
export function warpPlusErrorCallback (callbackId, neme, errMsg) {
return function errorCallback (error) {
error = error || {}
const code = error.code || 0
invoke(callbackId, {
errMsg: `${neme}:fail ${error.message || errMsg || ''}`,
errCode: error.code || 0
errCode: code,
code
})
}
}
......
......@@ -136,9 +136,8 @@ export default {
})
}
})
// 仅 Android 下载类广告
adView.setDownloadListener && adView.setDownloadListener((data) => {
this.$trigger('downloadchange', {}, data)
adView.setAdClickedListener((data) => {
this.$trigger('adclicked', {}, data)
})
this._request()
},
......
......@@ -220,7 +220,7 @@ import getRealPath from 'uni-platform/helpers/get-real-path'
import { isPlainObject } from 'uni-shared'
import { publish } from 'uni-platform/service/bridge'
function cssSupports (css) {
return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(undefined, css.split(':')))
return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(CSS, css.split(':')))
}
export default {
name: 'TabBar',
......
function cssSupports (css) {
return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(undefined, css.split(':')))
return window.CSS && CSS.supports && (CSS.supports(css) || CSS.supports.apply(CSS, css.split(':')))
}
export default {
......
......@@ -55,6 +55,16 @@ function getExtname (type) {
const extname = type.split('/')[1]
return extname ? `.${extname}` : ''
}
/**
* 简易获取文件名
* @param {*} url
*/
export function getFileName (url) {
url = url.split('#')[0].split('?')[0]
const array = url.split('/')
return array[array.length - 1]
}
/**
* blob转File
* @param {Blob} blob
......
import { fileToUrl } from 'uni-platform/helpers/file'
import {
fileToUrl,
getFileName
} from 'uni-platform/helpers/file'
/**
* 下载任务
*/
......@@ -63,6 +66,17 @@ export function downloadFile ({
clearTimeout(timer)
const statusCode = xhr.status
const blob = this.response
let filename
// 使用 getResponseHeader 跨域时会出现警告,但相比 getAllResponseHeaders 更方便
const contentDisposition = xhr.getResponseHeader('content-disposition')
if (contentDisposition) {
// 暂时仅解析 filename 不解析 filename*
const res = contentDisposition.match(/filename="?(\S+)"?\b/)
if (res) {
filename = res[1]
}
}
blob.name = filename || getFileName(url)
invoke(callbackId, {
errMsg: 'downloadFile:ok',
statusCode,
......
......@@ -17,6 +17,7 @@ import {
handleRef,
handleLink,
initBehavior,
triggerEvent,
initChildVues,
initSpecialMethods
} from './util'
......@@ -85,7 +86,8 @@ export default function parsePage (vuePageOptions) {
},
__r: handleRef,
__e: handleEvent,
__l: handleLink
__l: handleLink,
triggerEvent
}
initHooks(pageOptions, hooks, vuePageOptions)
......@@ -99,4 +101,4 @@ export default function parsePage (vuePageOptions) {
}
return pageOptions
}
}
......@@ -122,7 +122,7 @@ export function handleRef (ref) {
}
export function triggerEvent (type, detail, options) {
const handler = this.props[customize('on-' + type)]
const handler = this.props && this.props[customize('on-' + type)]
if (!handler) {
return
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册