提交 46d679a8 编写于 作者: fxy060608's avatar fxy060608

npm run lint

上级 1c475042
......@@ -108,7 +108,7 @@ function createApiCallback (apiName, params = {}, extras = {}) {
params = Object.assign({}, params)
const apiCallbacks = {}
for (let name in params) {
for (const name in params) {
const param = params[name]
if (isFn(param)) {
apiCallbacks[name] = tryCatch(param)
......@@ -135,7 +135,7 @@ function createApiCallback (apiName, params = {}, extras = {}) {
}
const wrapperCallbacks = {}
for (let name in extras) {
for (const name in extras) {
const extra = extras[name]
if (isFn(extra)) {
wrapperCallbacks[name] = tryCatchFramework(extra)
......@@ -165,7 +165,7 @@ function createApiCallback (apiName, params = {}, extras = {}) {
res.errMsg = apiName + ':cancel'
} else if (res.errMsg.indexOf(':fail') !== -1) {
let errDetail = ''
let spaceIndex = res.errMsg.indexOf(' ')
const spaceIndex = res.errMsg.indexOf(' ')
if (spaceIndex > -1) {
errDetail = res.errMsg.substr(spaceIndex)
}
......
export const pixelRatio = (function () {
const canvas = document.createElement('canvas')
canvas.height = canvas.width = 0
const context = canvas.getContext('2d')
const backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1
return (window.devicePixelRatio || 1) / backingStore
})()
const forEach = function (obj, func) {
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
func(obj[key], key)
}
}
}
const ratioArgs = {
'fillRect': 'all',
'clearRect': 'all',
'strokeRect': 'all',
'moveTo': 'all',
'lineTo': 'all',
'arc': [0, 1, 2],
'arcTo': 'all',
'bezierCurveTo': 'all',
'isPointinPath': 'all',
'isPointinStroke': 'all',
'quadraticCurveTo': 'all',
'rect': 'all',
'translate': 'all',
'createRadialGradient': 'all',
'createLinearGradient': 'all',
'setTransform': [4, 5]
}
const proto = CanvasRenderingContext2D.prototype
proto.drawImageByCanvas = (function (_super) {
return function (canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh, isScale) {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
srcx *= pixelRatio
srcy *= pixelRatio
srcw *= pixelRatio
srch *= pixelRatio
desx *= pixelRatio
desy *= pixelRatio
desw = isScale ? desw * pixelRatio : desw
desh = isScale ? desh * pixelRatio : desh
_super.call(this, canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh)
}
})(proto.drawImage)
if (pixelRatio !== 1) {
forEach(ratioArgs, function (value, key) {
proto[key] = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
let args = Array.prototype.slice.call(arguments)
if (value === 'all') {
args = args.map(function (a) {
return a * pixelRatio
})
} else if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
args[value[i]] *= pixelRatio
}
}
return _super.apply(this, args)
}
})(proto[key])
})
proto.stroke = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
this.lineWidth *= pixelRatio
_super.apply(this, arguments)
this.lineWidth /= pixelRatio
}
})(proto.stroke)
proto.fillText = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
const args = Array.prototype.slice.call(arguments)
args[1] *= pixelRatio
args[2] *= pixelRatio
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function (w, m, u) {
return (m * pixelRatio) + u
}
)
_super.apply(this, args)
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function (w, m, u) {
return (m / pixelRatio) + u
}
)
}
})(proto.fillText)
proto.strokeText = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
var args = Array.prototype.slice.call(arguments)
args[1] *= pixelRatio // x
args[2] *= pixelRatio // y
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function (w, m, u) {
return (m * pixelRatio) + u
}
)
_super.apply(this, args)
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function (w, m, u) {
return (m / pixelRatio) + u
}
)
}
})(proto.strokeText)
proto.drawImage = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
this.scale(pixelRatio, pixelRatio)
_super.apply(this, arguments)
this.scale(1 / pixelRatio, 1 / pixelRatio)
}
})(proto.drawImage)
}
export function wrapper (canvas) {
canvas.width = canvas.offsetWidth * pixelRatio
canvas.height = canvas.offsetHeight * pixelRatio
canvas.getContext('2d').__hidpi__ = true
import {
hasOwn
}
from 'uni-shared'
export const pixelRatio = (function () {
const canvas = document.createElement('canvas')
canvas.height = canvas.width = 0
const context = canvas.getContext('2d')
const backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1
return (window.devicePixelRatio || 1) / backingStore
})()
const forEach = function (obj, func) {
for (const key in obj) {
if (hasOwn(obj, key)) {
func(obj[key], key)
}
}
}
const ratioArgs = {
fillRect: 'all',
clearRect: 'all',
strokeRect: 'all',
moveTo: 'all',
lineTo: 'all',
arc: [0, 1, 2],
arcTo: 'all',
bezierCurveTo: 'all',
isPointinPath: 'all',
isPointinStroke: 'all',
quadraticCurveTo: 'all',
rect: 'all',
translate: 'all',
createRadialGradient: 'all',
createLinearGradient: 'all',
setTransform: [4, 5]
}
const proto = CanvasRenderingContext2D.prototype
proto.drawImageByCanvas = (function (_super) {
return function (canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh, isScale) {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
srcx *= pixelRatio
srcy *= pixelRatio
srcw *= pixelRatio
srch *= pixelRatio
desx *= pixelRatio
desy *= pixelRatio
desw = isScale ? desw * pixelRatio : desw
desh = isScale ? desh * pixelRatio : desh
_super.call(this, canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh)
}
})(proto.drawImage)
if (pixelRatio !== 1) {
forEach(ratioArgs, function (value, key) {
proto[key] = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
let args = Array.prototype.slice.call(arguments)
if (value === 'all') {
args = args.map(function (a) {
return a * pixelRatio
})
} else if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
args[value[i]] *= pixelRatio
}
}
return _super.apply(this, args)
}
})(proto[key])
})
proto.stroke = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
this.lineWidth *= pixelRatio
_super.apply(this, arguments)
this.lineWidth /= pixelRatio
}
})(proto.stroke)
proto.fillText = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
const args = Array.prototype.slice.call(arguments)
args[1] *= pixelRatio
args[2] *= pixelRatio
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function (w, m, u) {
return (m * pixelRatio) + u
}
)
_super.apply(this, args)
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function (w, m, u) {
return (m / pixelRatio) + u
}
)
}
})(proto.fillText)
proto.strokeText = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
var args = Array.prototype.slice.call(arguments)
args[1] *= pixelRatio // x
args[2] *= pixelRatio // y
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function (w, m, u) {
return (m * pixelRatio) + u
}
)
_super.apply(this, args)
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function (w, m, u) {
return (m / pixelRatio) + u
}
)
}
})(proto.strokeText)
proto.drawImage = (function (_super) {
return function () {
if (!this.__hidpi__) {
return _super.apply(this, arguments)
}
this.scale(pixelRatio, pixelRatio)
_super.apply(this, arguments)
this.scale(1 / pixelRatio, 1 / pixelRatio)
}
})(proto.drawImage)
}
export function wrapper (canvas) {
canvas.width = canvas.offsetWidth * pixelRatio
canvas.height = canvas.offsetHeight * pixelRatio
canvas.getContext('2d').__hidpi__ = true
}
......@@ -18,7 +18,7 @@ export default function validateParam (key, paramTypes, paramsData) {
}
if (value === undefined) {
if (hasOwn(paramOptions, 'default')) {
const paramDefault = paramOptions['default']
const paramDefault = paramOptions.default
value = isFn(paramDefault) ? paramDefault() : paramDefault
paramsData[key] = value // 默认值
}
......
export const makePhoneCall = {
'phoneNumber': {
phoneNumber: {
type: String,
required: true,
validator (phoneNumber) {
if (!phoneNumber) {
return `makePhoneCall:fail parameter error: parameter.phoneNumber should not be empty String;`
return 'makePhoneCall:fail parameter error: parameter.phoneNumber should not be empty String;'
}
}
}
......
......@@ -2,7 +2,7 @@ const SIZE_TYPES = ['original', 'compressed']
const SOURCE_TYPES = ['album', 'camera']
export const chooseImage = {
'count': {
count: {
type: Number,
required: false,
default: 9,
......@@ -12,7 +12,7 @@ export const chooseImage = {
}
}
},
'sizeType': {
sizeType: {
type: [Array, String],
required: false,
default: SIZE_TYPES,
......@@ -35,7 +35,7 @@ export const chooseImage = {
}
}
},
'sourceType': {
sourceType: {
type: Array,
required: false,
default: SOURCE_TYPES,
......
const SOURCE_TYPES = ['album', 'camera']
export const chooseVideo = {
'sourceType': {
sourceType: {
type: Array,
required: false,
default: SOURCE_TYPES,
......
import getRealPath from 'uni-platform/helpers/get-real-path'
export const getImageInfo = {
'src': {
src: {
type: String,
required: true,
validator (src, params) {
......
......@@ -35,7 +35,7 @@ function stringifyQuery (url, data) {
item = item.split('=')
query[item[0]] = item[1]
})
for (let key in data) {
for (const key in data) {
if (hasOwn(data, key)) {
let v = data[key]
if (typeof v === 'undefined' || v === null) {
......
export const getStorage = {
'key': {
key: {
type: String,
required: true
}
......@@ -12,11 +12,11 @@ export const getStorageSync = [{
}]
export const setStorage = {
'key': {
key: {
type: String,
required: true
},
'data': {
data: {
required: true
}
}
......
const FRONT_COLORS = ['#ffffff', '#000000']
export const setNavigationBarColor = {
'frontColor': {
frontColor: {
type: String,
required: true,
validator (frontColor, params) {
......@@ -9,11 +9,11 @@ export const setNavigationBarColor = {
}
}
},
'backgroundColor': {
backgroundColor: {
type: String,
required: true
},
'animation': {
animation: {
type: Object,
default () {
return {
......@@ -30,7 +30,7 @@ export const setNavigationBarColor = {
}
}
export const setNavigationBarTitle = {
'title': {
title: {
type: String,
required: true
}
......
export const SOURCE_KEY = '__data__'
export const COMPONENT_LIFECYCLE = {
'created': 'onServiceCreated',
'attached': 'onServiceAttached',
'ready': 'mounted',
'moved': 'moved',
'detached': 'destroyed'
created: 'onServiceCreated',
attached: 'onServiceAttached',
ready: 'mounted',
moved: 'moved',
detached: 'destroyed'
}
export const COMPONENT_LIFECYCLE_KEYS = Object.keys(COMPONENT_LIFECYCLE)
......
......@@ -14,23 +14,23 @@ import {
import polyfill from './polyfill/index'
global['__wxRoute'] = ''
global['__wxComponents'] = Object.create(null)
global['__wxVueOptions'] = Object.create(null)
global.__wxRoute = ''
global.__wxComponents = Object.create(null)
global.__wxVueOptions = Object.create(null)
export function Page (options) {
const pageOptions = parsePage(options)
pageOptions.mixins.unshift(polyfill)
pageOptions.mpOptions.path = global['__wxRoute']
global['__wxComponents'][global['__wxRoute']] = pageOptions
pageOptions.mpOptions.path = global.__wxRoute
global.__wxComponents[global.__wxRoute] = pageOptions
}
function initRelationsHandler (vueComponentOptions) {
// linked 需要在当前组件 attached 之后再执行
if (!vueComponentOptions['onServiceAttached']) {
vueComponentOptions['onServiceAttached'] = []
if (!vueComponentOptions.onServiceAttached) {
vueComponentOptions.onServiceAttached = []
}
vueComponentOptions['onServiceAttached'].push(function onServiceAttached () {
vueComponentOptions.onServiceAttached.push(function onServiceAttached () {
handleRelations(this, 'linked')
})
}
......@@ -38,9 +38,9 @@ function initRelationsHandler (vueComponentOptions) {
export function Component (options) {
const componentOptions = parseComponent(options)
componentOptions.mixins.unshift(polyfill)
componentOptions.mpOptions.path = global['__wxRoute']
componentOptions.mpOptions.path = global.__wxRoute
initRelationsHandler(componentOptions)
global['__wxComponents'][global['__wxRoute']] = componentOptions
global.__wxComponents[global.__wxRoute] = componentOptions
}
export function Behavior (options) {
......
export function parseComponents (vueComponentOptions) {
vueComponentOptions.components = global['__wxVueOptions'].components
vueComponentOptions.components = global.__wxVueOptions.components
}
......@@ -3,7 +3,7 @@ export function parseMethods (methods, vueComponentOptions) {
return
}
if (methods.$emit) {
console.warn(`Method "$emit" conflicts with an existing Vue instance method`)
console.warn('Method "$emit" conflicts with an existing Vue instance method')
delete methods.$emit
}
vueComponentOptions.methods = methods
......
......@@ -25,7 +25,7 @@ export function parseRelations (relations, vueComponentOptions) {
Object.keys(relations).forEach(name => {
const relation = relations[name]
relation.name = name
relation.target = relation.target ? String(relation.target) : relative(global['__wxRoute'], name)
relation.target = relation.target ? String(relation.target) : relative(global.__wxRoute, name)
})
vueComponentOptions.mpOptions.relations = relations
}
import {
hasOwn
} from 'uni-shared'
import {
initWebviewApi as initAppplusWebviewApi
} from 'uni-platforms/app-plus/runtime/web-view'
......@@ -58,11 +62,11 @@ const api = typeof uni !== 'undefined' ? uni : {}
if (!api.navigateTo) {
for (const key in webViewApi) {
if (webViewApi.hasOwnProperty(key)) {
if (hasOwn(webViewApi, key)) {
api[key] = webViewApi[key]
}
}
}
api.webView = webViewApi
export default api
export default api
......@@ -26,7 +26,7 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, k
if (isFn(argsOption)) {
argsOption = argsOption(fromArgs, toArgs) || {}
}
for (let key in fromArgs) {
for (const key in fromArgs) {
if (hasOwn(argsOption, key)) {
let keyOption = argsOption[key]
if (isFn(keyOption)) {
......
......@@ -144,14 +144,14 @@ function createObserver (name) {
}
export function initBehaviors (vueOptions, initBehavior) {
const vueBehaviors = vueOptions['behaviors']
const vueExtends = vueOptions['extends']
const vueMixins = vueOptions['mixins']
const vueBehaviors = vueOptions.behaviors
const vueExtends = vueOptions.extends
const vueMixins = vueOptions.mixins
let vueProps = vueOptions['props']
let vueProps = vueOptions.props
if (!vueProps) {
vueOptions['props'] = vueProps = []
vueOptions.props = vueProps = []
}
const behaviors = []
......@@ -163,11 +163,11 @@ export function initBehaviors (vueOptions, initBehavior) {
vueProps.push('name')
vueProps.push('value')
} else {
vueProps['name'] = {
vueProps.name = {
type: String,
default: ''
}
vueProps['value'] = {
vueProps.value = {
type: [String, Number, Boolean, Array, Object, Date],
default: ''
}
......@@ -252,7 +252,7 @@ export function initProperties (props, isBehavior = false, file = '') {
Object.keys(props).forEach(key => {
const opts = props[key]
if (isPlainObject(opts)) { // title:{type:String,default:''}
let value = opts['default']
let value = opts.default
if (isFn(value)) {
value = value()
}
......@@ -453,11 +453,11 @@ export function handleEvent (event) {
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset
if (!dataset) {
return console.warn(`事件信息不存在`)
return console.warn('事件信息不存在')
}
const eventOpts = dataset.eventOpts || dataset['event-opts'] // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn(`事件信息不存在`)
return console.warn('事件信息不存在')
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
......
......@@ -92,28 +92,34 @@ class InnerAudioContext {
}
Object.defineProperty(this, name, data)
})
}
}
play () {
this._operate('play')
}
}
pause () {
this._operate('pause')
}
}
stop () {
this._operate('stop')
}
}
seek (position) {
this._operate('seek', {
currentTime: position * 1e3
})
}
}
destroy () {
clearInterval(this.__timing)
invokeMethod('destroyAudioInstance', {
audioId: this.id
})
delete innerAudioContexts[this.id]
}
}
_operate (type, options) {
invokeMethod('operateAudio', Object.assign({}, options, {
audioId: this.id,
......
......@@ -108,21 +108,26 @@ class BackgroundAudioManager {
}
Object.defineProperty(this, name, data)
})
}
}
play () {
this._operate('play')
}
}
pause () {
this._operate('pause')
}
}
stop () {
this._operate('stop')
}
}
seek (position) {
this._operate('seek', {
currentTime: position
})
}
}
_operate (type, options) {
invokeMethod('operateBackgroundAudio', Object.assign({}, options, {
operationType: type
......
......@@ -17,21 +17,26 @@ export class VideoContext {
play () {
operateVideoPlayer(this.id, this.pageVm, 'play')
}
}
pause () {
operateVideoPlayer(this.id, this.pageVm, 'pause')
}
}
stop () {
operateVideoPlayer(this.id, this.pageVm, 'stop')
}
}
seek (position) {
operateVideoPlayer(this.id, this.pageVm, 'seek', {
position
})
}
}
sendDanmu (args) {
operateVideoPlayer(this.id, this.pageVm, 'sendDanmu', args)
}
}
playbackRate (rate) {
if (!~RATES.indexOf(rate)) {
rate = 1.0
......@@ -39,16 +44,20 @@ export class VideoContext {
operateVideoPlayer(this.id, this.pageVm, 'playbackRate', {
rate
})
}
}
requestFullScreen (args = {}) {
operateVideoPlayer(this.id, this.pageVm, 'requestFullScreen', args)
}
}
exitFullScreen () {
operateVideoPlayer(this.id, this.pageVm, 'exitFullScreen')
}
}
showStatusBar () {
operateVideoPlayer(this.id, this.pageVm, 'showStatusBar')
}
}
hideStatusBar () {
operateVideoPlayer(this.id, this.pageVm, 'hideStatusBar')
}
......
......@@ -24,6 +24,7 @@ export class EditorContext {
this.id = id
this.pageId = pageId
}
format (name, value) {
operateEditor(this.id, this.pageId, 'format', {
options: {
......
......@@ -22,45 +22,57 @@ class RecorderManager {
}
})
}
onError (callback) {
callbacks.error = callback
}
onFrameRecorded (callback) {
}
onInterruptionBegin (callback) {
}
onInterruptionEnd (callback) {
}
onPause (callback) {
callbacks.pause = callback
}
onResume (callback) {
callbacks.resume = callback
}
onStart (callback) {
callbacks.start = callback
}
onStop (callback) {
callbacks.stop = callback
}
pause () {
invokeMethod('operateRecorder', {
operationType: 'pause'
})
}
resume () {
invokeMethod('operateRecorder', {
operationType: 'resume'
})
}
start (options) {
invokeMethod('operateRecorder', Object.assign({}, options, {
operationType: 'start'
}))
}
stop () {
invokeMethod('operateRecorder', {
operationType: 'stop'
......
......@@ -12,28 +12,33 @@ class DownloadTask {
this.id = downloadTaskId
this._callbackId = callbackId
this._callbacks = []
}
}
abort () {
invokeMethod('operateRequestTask', {
downloadTaskId: this.id,
operationType: 'abort'
})
}
}
onProgressUpdate (callback) {
if (typeof callback !== 'function') {
return
}
this._callbacks.push(callback)
}
}
onHeadersReceived () {
}
}
offProgressUpdate (callback) {
const index = this._callbacks.indexOf(callback)
if (index >= 0) {
this._callbacks.splice(index, 1)
}
}
}
offHeadersReceived () {
}
......
......@@ -21,7 +21,8 @@ class SocketTask {
this.CONNECTING = 0
this.OPEN = 1
this.readyState = this.CLOSED
}
}
send (args) {
if (this.readyState !== this.OPEN) {
this._callback(args, 'sendSocketMessage:fail WebSocket is not connected')
......@@ -33,7 +34,8 @@ class SocketTask {
socketTaskId: this.id
}))
this._callback(args, errMsg.replace('operateSocketTask', 'sendSocketMessage'))
}
}
close (args) {
this.readyState = this.CLOSING
const {
......@@ -43,19 +45,24 @@ class SocketTask {
socketTaskId: this.id
}))
this._callback(args, errMsg.replace('operateSocketTask', 'closeSocket'))
}
}
onOpen (callback) {
this._callbacks.open.push(callback)
}
}
onClose (callback) {
this._callbacks.close.push(callback)
}
}
onError (callback) {
this._callbacks.error.push(callback)
}
}
onMessage (callback) {
this._callbacks.message.push(callback)
}
}
_callback ({
success,
fail,
......
......@@ -12,28 +12,33 @@ class UploadTask {
this.id = uploadTaskId
this._callbackId = callbackId
this._callbacks = []
}
}
abort () {
invokeMethod('operateRequestTask', {
uploadTaskId: this.id,
operationType: 'abort'
})
}
}
onProgressUpdate (callback) {
if (typeof callback !== 'function') {
return
}
this._callbacks.push(callback)
}
}
onHeadersReceived () {
}
}
offProgressUpdate (callback) {
const index = this._callbacks.indexOf(callback)
if (index >= 0) {
this._callbacks.splice(index, 1)
}
}
}
offHeadersReceived () {
}
......
......@@ -12,28 +12,33 @@ class MPAnimation {
this.currentStepAnimates = []
this.option = Object.assign({}, defaultOption, option)
}
_getOption (option) {
let _option = {
const _option = {
transition: Object.assign({}, this.option, option)
}
_option.transformOrigin = _option.transition.transformOrigin
delete _option.transition.transformOrigin
return _option
}
_pushAnimates (type, args) {
this.currentStepAnimates.push({
type: type,
args: args
})
}
_converType (type) {
return type.replace(/[A-Z]/g, text => {
return `-${text.toLowerCase()}`
})
}
_getValue (value) {
return typeof value === 'number' ? `${value}px` : value
}
export () {
const actions = this.actions
this.actions = []
......@@ -41,6 +46,7 @@ class MPAnimation {
actions
}
}
step (option) {
this.currentStepAnimates.forEach(animate => {
if (animate.type !== 'style') {
......
......@@ -17,21 +17,25 @@ class ServiceIntersectionObserver {
this.pageId = component.$page.id
this.component = component._$id || component // app-plus 平台传输_$id
this.options = Object.assign({}, defaultOptions, options)
}
}
_makeRootMargin (margins = {}) {
this.options.rootMargin = ['top', 'right', 'bottom', 'left'].map(name => `${Number(margins[name]) || 0}px`).join(
' ')
}
}
relativeTo (selector, margins) {
this.options.relativeToSelector = selector
this._makeRootMargin(margins)
return this
}
}
relativeToViewport (margins) {
this.options.relativeToSelector = null
this._makeRootMargin(margins)
return this
}
}
observe (selector, callback) {
if (typeof callback !== 'function') {
return
......@@ -45,7 +49,8 @@ class ServiceIntersectionObserver {
component: this.component,
options: this.options
}, this.pageId)
}
}
disconnect () {
UniServiceJSBridge.publishHandler('destroyComponentObserver', {
reqId: this.reqId
......
......@@ -40,7 +40,7 @@ export function requestComponentObserver ({
const root = options.relativeToSelector ? $el.querySelector(options.relativeToSelector) : null
let intersectionObserver = intersectionObservers[reqId] = new IntersectionObserver((entries, observer) => {
const intersectionObserver = intersectionObservers[reqId] = new IntersectionObserver((entries, observer) => {
entries.forEach(entrie => {
UniViewJSBridge.publishHandler('onRequestComponentObserver', {
reqId,
......
......@@ -14,7 +14,7 @@ function findVmById (id, vm) {
export function findElm (component, pageVm) {
if (!pageVm) {
return console.error(`page is not ready`)
return console.error('page is not ready')
}
if (!component) {
return pageVm.$el
......
......@@ -13,7 +13,7 @@ export function loadFontFace ({
UniViewJSBridge.publishHandler('onLoadFontFaceCallback', {
callbackId,
data: {
errMsg: `loadFontFace:ok`
errMsg: 'loadFontFace:ok'
}
})
})
......@@ -32,7 +32,7 @@ export function loadFontFace ({
UniViewJSBridge.publishHandler('onLoadFontFaceCallback', {
callbackId,
data: {
errMsg: `loadFontFace:ok`
errMsg: 'loadFontFace:ok'
}
})
}
......
......@@ -80,7 +80,7 @@ export function createScrollListener (pageId, {
// 部分浏览器窗口高度变化后document.documentelement.clientheight不会变化,采用window.innerHeight
const windowHeight = window.innerHeight
const scrollY = window.scrollY
let isBottom = scrollY > 0 && scrollHeight > windowHeight && (scrollY + windowHeight + onReachBottomDistance) >= scrollHeight
const isBottom = scrollY > 0 && scrollHeight > windowHeight && (scrollY + windowHeight + onReachBottomDistance) >= scrollHeight
// 兼容部分浏览器滚动时scroll事件不触发
const heightChanged = Math.abs(scrollHeight - lastScrollHeight) > onReachBottomDistance
if (isBottom && (!hasReachBottom || heightChanged)) {
......
......@@ -63,9 +63,9 @@ export default {
},
_bindObjectListeners (data, value) {
if (value) {
for (let key in value) {
let existing = data.on[key]
let ours = value[key]
for (const key in value) {
const existing = data.on[key]
const ours = value[key]
data.on[key] = existing ? [].concat(existing, ours) : ours
}
}
......@@ -73,7 +73,7 @@ export default {
}
},
render (createElement) {
let $listeners = Object.create(null)
const $listeners = Object.create(null)
if (this.$listeners) {
Object.keys(this.$listeners).forEach(e => {
if (this.disabled && (e === 'click' || e === 'tap')) {
......@@ -86,7 +86,7 @@ export default {
return createElement('uni-button', this._bindObjectListeners({
class: [this.hovering ? this.hoverClass : ''],
attrs: {
'disabled': this.disabled
disabled: this.disabled
},
on: {
touchstart: this._hoverTouchStart,
......@@ -99,7 +99,7 @@ export default {
return createElement('uni-button', this._bindObjectListeners({
class: [this.hovering ? this.hoverClass : ''],
attrs: {
'disabled': this.disabled
disabled: this.disabled
},
on: {
click: this._onClick
......
......@@ -2,17 +2,20 @@
<uni-canvas
:canvas-id="canvasId"
:disable-scroll="disableScroll"
v-on="_listeners">
v-on="_listeners"
>
<canvas
ref="canvas"
width="300"
height="150" />
height="150"
/>
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden;">
<slot />
</div>
<v-uni-resize-sensor
ref="sensor"
@resize="_resize" />
@resize="_resize"
/>
</uni-canvas>
</template>
<script>
......@@ -162,36 +165,36 @@ export default {
}
this.preloadImage(actions)
for (let index = 0; index < actions.length; index++) {
let action = actions[index]
const action = actions[index]
let method = action.method
let data = action.data
const data = action.data
if (/^set/.test(method) && method !== 'setTransform') {
let method1 = method[3].toLowerCase() + method.slice(4)
const method1 = method[3].toLowerCase() + method.slice(4)
let color
if (method1 === 'fillStyle' || method1 === 'strokeStyle') {
if (data[0] === 'normal') {
color = resolveColor(data[1])
} else if (data[0] === 'linear') {
let LinearGradient = c2d.createLinearGradient(...data[1])
const LinearGradient = c2d.createLinearGradient(...data[1])
data[2].forEach(function (data2) {
let offset = data2[0]
let color = resolveColor(data2[1])
const offset = data2[0]
const color = resolveColor(data2[1])
LinearGradient.addColorStop(offset, color)
})
color = LinearGradient
} else if (data[0] === 'radial') {
let x = data[1][0]
let y = data[1][1]
let r = data[1][2]
let LinearGradient = c2d.createRadialGradient(x, y, 0, x, y, r)
const x = data[1][0]
const y = data[1][1]
const r = data[1][2]
const LinearGradient = c2d.createRadialGradient(x, y, 0, x, y, r)
data[2].forEach(function (data2) {
let offset = data2[0]
let color = resolveColor(data2[1])
const offset = data2[0]
const color = resolveColor(data2[1])
LinearGradient.addColorStop(offset, color)
})
color = LinearGradient
} else if (data[0] === 'pattern') {
let loaded = this.checkImageLoaded(data[1], actions.slice(index + 1), callbackId,
const loaded = this.checkImageLoaded(data[1], actions.slice(index + 1), callbackId,
function (image) {
if (image) {
c2d[method1] = c2d.createPattern(image, data[2])
......@@ -510,7 +513,7 @@ export default {
qualit,
callbackId
}) {
let res = this.getImageData({
const res = this.getImageData({
x,
y,
width,
......
......@@ -41,7 +41,7 @@ export default {
},
methods: {
_changeHandler ($event) {
let value = []
const value = []
this.checkboxList.forEach(vm => {
if (vm.checkboxChecked) {
value.push(vm.value)
......@@ -55,21 +55,21 @@ export default {
if ($event.type === 'add') {
this.checkboxList.push($event.vm)
} else {
let index = this.checkboxList.indexOf($event.vm)
const index = this.checkboxList.indexOf($event.vm)
this.checkboxList.splice(index, 1)
}
},
_getFormData () {
let data = {}
const data = {}
if (this.name !== '') {
let value = []
const value = []
this.checkboxList.forEach(vm => {
if (vm.checkboxChecked) {
value.push(vm.value)
}
})
data['value'] = value
data['key'] = this.name
data.value = value
data.key = this.name
}
return data
}
......
......@@ -2,12 +2,14 @@
<uni-checkbox
:disabled="disabled"
v-on="$listeners"
@click="_onClick">
@click="_onClick"
>
<div class="uni-checkbox-wrapper">
<div
:class="[checkboxChecked ? 'uni-checkbox-input-checked' : '']"
:style="{color:color}"
class="uni-checkbox-input" />
class="uni-checkbox-input"
/>
<slot />
</div>
</uni-checkbox>
......
......@@ -5,8 +5,8 @@ export default function (Quill) {
class List extends Container {
static create (value) {
let tagName = value === 'ordered' ? 'OL' : 'UL'
let node = super.create(tagName)
const tagName = value === 'ordered' ? 'OL' : 'UL'
const node = super.create(tagName)
if (value === 'checked' || value === 'unchecked') {
node.setAttribute('data-checked', value === 'checked')
}
......@@ -29,8 +29,8 @@ export default function (Quill) {
super(domNode)
const listEventHandler = (e) => {
if (e.target.parentNode !== domNode) return
let format = this.statics.formats(domNode)
let blot = Parchment.find(e.target)
const format = this.statics.formats(domNode)
const blot = Parchment.find(e.target)
if (format === 'checked') {
blot.format('list', 'unchecked')
} else if (format === 'unchecked') {
......@@ -56,15 +56,15 @@ export default function (Quill) {
if (blot instanceof ListItem) {
super.insertBefore(blot, ref)
} else {
let index = ref == null ? this.length() : ref.offset(this)
let after = this.split(index)
const index = ref == null ? this.length() : ref.offset(this)
const after = this.split(index)
after.parent.insertBefore(blot, after)
}
}
optimize (context) {
super.optimize(context)
let next = this.next
const next = this.next
if (next != null && next.prev === this &&
next.statics.blotName === this.statics.blotName &&
next.domNode.tagName === this.domNode.tagName &&
......@@ -76,7 +76,7 @@ export default function (Quill) {
replace (target) {
if (target.statics.blotName !== this.statics.blotName) {
let item = Parchment.create(this.statics.defaultChild)
const item = Parchment.create(this.statics.defaultChild)
target.moveChildren(item)
this.appendChild(item)
}
......
......@@ -2,7 +2,8 @@
<uni-editor
:id="id"
class="ql-container"
v-on="$listeners" />
v-on="$listeners"
/>
</template>
<script>
......@@ -101,34 +102,36 @@ export default {
if (this.quillReady) {
switch (type) {
case 'format':
let { name = '', value = false } = options
range = quill.getSelection(true)
let format = quill.getFormat(range)[name] || false
if (['bold', 'italic', 'underline', 'strike', 'ins'].includes(name)) {
value = !format
} else if (name === 'direction') {
value = value === 'rtl' && format ? false : value
const align = quill.getFormat(range).align
if (value === 'rtl' && !align) {
quill.format('align', 'right', Quill.sources.USER)
} else if (!value && align === 'right') {
quill.format('align', false, Quill.sources.USER)
}
} else if (name === 'indent') {
const rtl = quill.getFormat(range).direction === 'rtl'
value = value === '+1'
if (rtl) {
value = !value
}
value = value ? '+1' : '-1'
} else {
if (name === 'list') {
value = value === 'check' ? 'unchecked' : value
format = format === 'checked' ? 'unchecked' : format
{
let { name = '', value = false } = options
range = quill.getSelection(true)
let format = quill.getFormat(range)[name] || false
if (['bold', 'italic', 'underline', 'strike', 'ins'].includes(name)) {
value = !format
} else if (name === 'direction') {
value = value === 'rtl' && format ? false : value
const align = quill.getFormat(range).align
if (value === 'rtl' && !align) {
quill.format('align', 'right', Quill.sources.USER)
} else if (!value && align === 'right') {
quill.format('align', false, Quill.sources.USER)
}
} else if (name === 'indent') {
const rtl = quill.getFormat(range).direction === 'rtl'
value = value === '+1'
if (rtl) {
value = !value
}
value = value ? '+1' : '-1'
} else {
if (name === 'list') {
value = value === 'check' ? 'unchecked' : value
format = format === 'checked' ? 'unchecked' : format
}
value = ((format && format !== (value || false)) || (!format && value)) ? value : !format
}
value = ((format && format !== (value || false)) || (!format && value)) ? value : !format
quill.format(name, value, Quill.sources.USER)
}
quill.format(name, value, Quill.sources.USER)
break
case 'insertDivider':
range = quill.getSelection(true)
......@@ -137,27 +140,33 @@ export default {
quill.setSelection(range.index + 2, Quill.sources.SILENT)
break
case 'insertImage':
range = quill.getSelection(true)
const { src = '', alt = '', data = {} } = options
quill.insertEmbed(range.index, 'image', this.$getRealPath(src), Quill.sources.USER)
quill.formatText(range.index, 1, 'alt', alt)
quill.formatText(range.index, 1, 'data-custom', Object.keys(data).map(key => `${key}=${data[key]}`).join('&'))
quill.setSelection(range.index + 1, Quill.sources.SILENT)
{
range = quill.getSelection(true)
const { src = '', alt = '', data = {} } = options
quill.insertEmbed(range.index, 'image', this.$getRealPath(src), Quill.sources.USER)
quill.formatText(range.index, 1, 'alt', alt)
quill.formatText(range.index, 1, 'data-custom', Object.keys(data).map(key => `${key}=${data[key]}`).join('&'))
quill.setSelection(range.index + 1, Quill.sources.SILENT)
}
break
case 'insertText':
range = quill.getSelection(true)
const { text = '' } = options
quill.insertText(range.index, text, Quill.sources.USER)
quill.setSelection(range.index + text.length, 0, Quill.sources.SILENT)
{
range = quill.getSelection(true)
const { text = '' } = options
quill.insertText(range.index, text, Quill.sources.USER)
quill.setSelection(range.index + text.length, 0, Quill.sources.SILENT)
}
break
case 'setContents':
const { delta, html } = options
if (typeof delta === 'object') {
quill.setContents(delta, Quill.sources.SILENT)
} else if (typeof html === 'string') {
quill.setContents(this.html2delta(html), Quill.sources.SILENT)
} else {
errMsg = 'contents is missing'
{
const { delta, html } = options
if (typeof delta === 'object') {
quill.setContents(delta, Quill.sources.SILENT)
} else if (typeof html === 'string') {
quill.setContents(this.html2delta(html), Quill.sources.SILENT)
} else {
errMsg = 'contents is missing'
}
}
break
case 'getContents':
......@@ -167,16 +176,18 @@ export default {
quill.setContents([])
break
case 'removeFormat':
range = quill.getSelection(true)
var parchment = Quill.import('parchment')
if (range.length) {
quill.removeFormat(range, Quill.sources.USER)
} else {
Object.keys(quill.getFormat(range)).forEach(key => {
if (parchment.query(key, parchment.Scope.INLINE)) {
quill.format(key, false)
}
})
{
range = quill.getSelection(true)
const parchment = Quill.import('parchment')
if (range.length) {
quill.removeFormat(range, Quill.sources.USER)
} else {
Object.keys(quill.getFormat(range)).forEach(key => {
if (parchment.query(key, parchment.Scope.INLINE)) {
quill.format(key, false)
}
})
}
}
break
case 'undo':
......@@ -208,7 +219,7 @@ export default {
}
return
}
let script = document.createElement('script')
const script = document.createElement('script')
script.src = window.plus ? './__uniappquill.js' : 'https://unpkg.com/quill@1.3.7/dist/quill.min.js'
document.body.appendChild(script)
script.onload = callback
......@@ -220,7 +231,7 @@ export default {
}
return
}
let script = document.createElement('script')
const script = document.createElement('script')
script.src = window.plus ? './__uniappquillimageresize.js' : 'https://unpkg.com/quill-image-resize-mp@3.0.1/image-resize.min.js'
document.body.appendChild(script)
script.onload = callback
......
......@@ -24,7 +24,7 @@ export default {
},
methods: {
_onSubmit ($event) {
let data = {}
const data = {}
this.childrenList.forEach(vm => {
if (vm._getFormData && vm._getFormData().key) {
data[vm._getFormData().key] = vm._getFormData().value
......
......@@ -2,12 +2,14 @@
<uni-image v-on="$listeners">
<div
ref="content"
:style="modeStyle" />
:style="modeStyle"
/>
<img :src="realImagePath">
<v-uni-resize-sensor
v-if="mode === 'widthFix'"
ref="sensor"
@resize="_resize" />
@resize="_resize"
/>
</uni-image>
</template>
<script>
......@@ -46,7 +48,7 @@ export default {
modeStyle () {
let size = 'auto'
let position = ''
let repeat = 'no-repeat'
const repeat = 'no-repeat'
switch (this.mode) {
case 'aspectFit':
......
<template>
<uni-input
@change.stop
v-on="$listeners">
v-on="$listeners"
>
<div
ref="wrapper"
class="uni-input-wrapper">
class="uni-input-wrapper"
>
<div
v-show="!(composing || inputValue.length)"
ref="placeholder"
:style="placeholderStyle"
:class="placeholderClass"
class="uni-input-placeholder"
>{{ placeholder }}</div>
>
{{ placeholder }}
</div>
<input
ref="input"
v-model="inputValue"
......
......@@ -2,7 +2,8 @@
<uni-label
:class="{'uni-label-pointer':pointer}"
v-on="$listeners"
@click="_onClick">
@click="_onClick"
>
<slot />
</uni-label>
</template>
......
......@@ -382,12 +382,12 @@ export default {
this.$el.style.willChange = 'auto'
this._isTouching = false
if (!this._checkCanMove && !this._revise('out-of-bounds') && this.inertia) {
let xv = 1000 * (this.__touchInfo.historyX[1] - this.__touchInfo.historyX[0]) / (this.__touchInfo.historyT[1] - this.__touchInfo.historyT[0])
let yv = 1000 * (this.__touchInfo.historyY[1] - this.__touchInfo.historyY[0]) / (this.__touchInfo.historyT[1] - this.__touchInfo.historyT[0])
const xv = 1000 * (this.__touchInfo.historyX[1] - this.__touchInfo.historyX[0]) / (this.__touchInfo.historyT[1] - this.__touchInfo.historyT[0])
const yv = 1000 * (this.__touchInfo.historyY[1] - this.__touchInfo.historyY[0]) / (this.__touchInfo.historyT[1] - this.__touchInfo.historyT[0])
this._friction.setV(xv, yv)
this._friction.setS(this._translateX, this._translateY)
let x0 = this._friction.delta().x
let y0 = this._friction.delta().y
const x0 = this._friction.delta().x
const y0 = this._friction.delta().y
let x = x0 + this._translateX
let y = y0 + this._translateY
if (x < this.minX) {
......@@ -526,9 +526,9 @@ export default {
scale = this._adjustScale(scale)
this._updateWH(scale)
this._updateBoundary()
let limitXY = this._getLimitXY(this._translateX, this._translateY)
let x = limitXY.x
let y = limitXY.y
const limitXY = this._getLimitXY(this._translateX, this._translateY)
const x = limitXY.x
const y = limitXY.y
if (animat) {
this._animationTo(x, y, scale, '', true, true)
} else {
......
......@@ -101,9 +101,9 @@ Spring.prototype._solve = function (e, t) {
var r = this._k
var o = n * n - 4 * i * r
if (o === 0) {
let a = -n / (2 * i)
let s = e
let l = t / (a * e)
const a = -n / (2 * i)
const s = e
const l = t / (a * e)
return {
x: function (e) {
return (s + l * e) * Math.pow(Math.E, a * e)
......@@ -115,10 +115,10 @@ Spring.prototype._solve = function (e, t) {
}
}
if (o > 0) {
let c = (-n - Math.sqrt(o)) / (2 * i)
let u = (-n + Math.sqrt(o)) / (2 * i)
let d = (t - c * e) / (u - c)
let h = e - d
const c = (-n - Math.sqrt(o)) / (2 * i)
const u = (-n + Math.sqrt(o)) / (2 * i)
const d = (t - c * e) / (u - c)
const h = e - d
return {
x: function (e) {
var t
......
......@@ -6,13 +6,15 @@
@touchend="_hoverTouchEnd"
@touchcancel="_hoverTouchCancel"
@click="_onClick"
v-on="$listeners">
v-on="$listeners"
>
<slot />
</uni-navigator>
<uni-navigator
v-else
@click="_onClick"
v-on="$listeners">
v-on="$listeners"
>
<slot />
</uni-navigator>
</template>
......@@ -59,7 +61,7 @@ export default {
methods: {
_onClick ($event) {
if (this.openType !== 'navigateBack' && !this.url) {
console.error(`<navigator/> should have url attribute when using navigateTo, redirectTo, reLaunch or switchTab`)
console.error('<navigator/> should have url attribute when using navigateTo, redirectTo, reLaunch or switchTab')
return
}
......
......@@ -23,7 +23,7 @@ function initClick (dom) {
dom.addEventListener('touchend', (event) => {
const info = event.changedTouches[0]
if (Math.abs(info.clientX - x) < MAX_MOVE && Math.abs(info.clientY - y) < MAX_MOVE) {
let customEvent = new CustomEvent('click', {
const customEvent = new CustomEvent('click', {
bubbles: true,
cancelable: true,
target: event.target,
......
......@@ -55,7 +55,7 @@ export default {
} else {
this.changeSource = ''
// 避免外部直接对此值进行修改
let value = val.map(val => val)
const value = val.map(val => val)
this.$emit('update:value', value)
this.$trigger('change', {}, {
value
......@@ -114,7 +114,7 @@ export default {
}),
createElement('div', {
ref: 'wrapper',
'class': 'uni-picker-view-wrapper'
class: 'uni-picker-view-wrapper'
}, items)
])
}
......
<template>
<uni-progress
class="uni-progress"
v-on="$listeners">
v-on="$listeners"
>
<div
:style="outerBarStyle"
class="uni-progress-bar">
class="uni-progress-bar"
>
<div
:style="innerBarStyle"
class="uni-progress-inner-bar" />
class="uni-progress-inner-bar"
/>
</div>
<template v-if="showInfo">
<p class="uni-progress-info">{{ currentPercent }}%</p>
<p class="uni-progress-info">
{{ currentPercent }}%
</p>
</template>
</uni-progress>
</template>
......
......@@ -44,7 +44,7 @@ export default {
},
methods: {
_changeHandler ($event, vm) {
let index = this.radioList.indexOf(vm)
const index = this.radioList.indexOf(vm)
this._resetRadioGroupValue(index, true)
this.$trigger('change', $event, {
value: vm.radioValue
......@@ -78,7 +78,7 @@ export default {
})
},
_getFormData () {
let data = {}
const data = {}
if (this.name !== '') {
let value = ''
this.radioList.forEach(vm => {
......@@ -86,8 +86,8 @@ export default {
value = vm.value
}
})
data['value'] = value
data['key'] = this.name
data.value = value
data.key = this.name
}
return data
}
......
......@@ -2,12 +2,14 @@
<uni-radio
:disabled="disabled"
v-on="$listeners"
@click="_onClick">
@click="_onClick"
>
<div class="uni-radio-wrapper">
<div
:class="radioChecked ? 'uni-radio-input-checked' : ''"
:style="radioChecked ? checkedStyle : ''"
class="uni-radio-input" />
class="uni-radio-input"
/>
<slot />
</div>
</uni-radio>
......
......@@ -4,57 +4,57 @@ import {
} from 'uni-shared'
const TAGS = {
'a': '',
'abbr': '',
'b': '',
'blockquote': '',
'br': '',
'code': '',
'col': ['span', 'width'],
'colgroup': ['span', 'width'],
'dd': '',
'del': '',
'div': '',
'dl': '',
'dt': '',
'em': '',
'fieldset': '',
'h1': '',
'h2': '',
'h3': '',
'h4': '',
'h5': '',
'h6': '',
'hr': '',
'i': '',
'img': ['alt', 'src', 'height', 'width'],
'ins': '',
'label': '',
'legend': '',
'li': '',
'ol': ['start', 'type'],
'p': '',
'q': '',
'span': '',
'strong': '',
'sub': '',
'sup': '',
'table': ['width'],
'tbody': '',
'td': ['colspan', 'rowspan', 'height', 'width'],
'tfoot': '',
'th': ['colspan', 'rowspan', 'height', 'width'],
'thead': '',
'tr': '',
'ul': ''
a: '',
abbr: '',
b: '',
blockquote: '',
br: '',
code: '',
col: ['span', 'width'],
colgroup: ['span', 'width'],
dd: '',
del: '',
div: '',
dl: '',
dt: '',
em: '',
fieldset: '',
h1: '',
h2: '',
h3: '',
h4: '',
h5: '',
h6: '',
hr: '',
i: '',
img: ['alt', 'src', 'height', 'width'],
ins: '',
label: '',
legend: '',
li: '',
ol: ['start', 'type'],
p: '',
q: '',
span: '',
strong: '',
sub: '',
sup: '',
table: ['width'],
tbody: '',
td: ['colspan', 'rowspan', 'height', 'width'],
tfoot: '',
th: ['colspan', 'rowspan', 'height', 'width'],
thead: '',
tr: '',
ul: ''
}
const CHARS = {
'amp': '&',
'gt': '>',
'lt': '<',
'nbsp': ' ',
'quot': '"',
'apos': "'"
amp: '&',
gt: '>',
lt: '<',
nbsp: ' ',
quot: '"',
apos: "'"
}
function decodeEntities (htmlString) {
......@@ -68,7 +68,7 @@ function decodeEntities (htmlString) {
if (/^#x[0-9a-f]{1,4}$/i.test(stage)) {
return String.fromCharCode('0' + stage.slice(1))
}
let wrap = document.createElement('div')
const wrap = document.createElement('div')
wrap.innerHTML = match
return wrap.innerText || wrap.textContent
})
......
......@@ -2,20 +2,24 @@
<uni-scroll-view v-on="$listeners">
<div
ref="wrap"
class="uni-scroll-view">
class="uni-scroll-view"
>
<div
ref="main"
:style="{'overflow-x': scrollX?'auto':'hidden','overflow-y': scrollY?'auto':'hidden'}"
class="uni-scroll-view">
class="uni-scroll-view"
>
<div ref="content">
<div
v-if="refresherEnabled"
ref="refresherinner"
:style="{'background-color': refresherBackground, 'height': refresherHeight + 'px'}"
class="uni-scroll-view-refresher">
class="uni-scroll-view-refresher"
>
<div
v-if="refresherDefaultStyle !== 'none'"
class="uni-scroll-view-refresh">
class="uni-scroll-view-refresh"
>
<div class="uni-scroll-view-refresh-inner">
<svg
v-if="refreshState=='pulling'"
......@@ -24,33 +28,38 @@
class="uni-scroll-view-refresh__icon"
width="24"
height="24"
viewBox="0 0 24 24">
viewBox="0 0 24 24"
>
<path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" />
<path
d="M0 0h24v24H0z"
fill="none" />
fill="none"
/>
</svg>
<svg
v-if="refreshState=='refreshing'"
class="uni-scroll-view-refresh__spinner"
width="24"
height="24"
viewBox="25 25 50 50">
viewBox="25 25 50 50"
>
<circle
cx="50"
cy="50"
r="20"
fill="none"
style="color: #2BD009;"
stroke-width="3"/>
stroke-width="3"
/>
</svg>
</div>
</div>
<slot
v-if="refresherDefaultStyle=='none'"
name="refresher"/>
name="refresher"
/>
</div>
<slot/>
<slot />
</div>
</div>
</div>
......@@ -230,7 +239,7 @@ export default {
}
if (self.refresherEnabled && self.refreshState === 'pulling') {
let dy = y - touchStart.y
const dy = y - touchStart.y
self.refresherHeight = dy
let rotate = dy / self.refresherThreshold
......@@ -360,7 +369,7 @@ export default {
_handleScroll: function ($event) {
if (!($event.timeStamp - this._lastScrollTime < 20)) {
this._lastScrollTime = $event.timeStamp
let target = $event.target
const target = $event.target
this.$trigger('scroll', $event, {
scrollLeft: target.scrollLeft,
scrollTop: target.scrollTop,
......
......@@ -2,27 +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"
class="uni-slider-value">{{ sliderValue }}</span>
class="uni-slider-value"
>{{ sliderValue }}</span>
</div>
<slot />
</uni-slider>
......@@ -145,10 +151,10 @@ export default {
},
methods: {
_onUserChangedValue (e) {
let slider = this.$refs['uni-slider']
let offsetWidth = slider.offsetWidth
let boxLeft = slider.getBoundingClientRect().left
let value = (e.x - boxLeft) * (this.max - this.min) / offsetWidth + Number(this.min)
const slider = this.$refs['uni-slider']
const offsetWidth = slider.offsetWidth
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) {
......@@ -167,12 +173,12 @@ 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, {
value: this.sliderValue
}), !1) : void (e.detail.state === 'end' && this.$trigger('change', e, {
}), !1) : (e.detail.state === 'end' && this.$trigger('change', e, {
value: this.sliderValue
}))
}
......@@ -190,10 +196,10 @@ export default {
this.sliderValue = this.min
},
_getFormData () {
let data = {}
const data = {}
if (this.name !== '') {
data['value'] = this.sliderValue
data['key'] = this.name
data.value = this.sliderValue
data.key = this.name
}
return data
}
......
<template>
<uni-swiper-item v-on="$listeners">
<slot/>
<slot />
</uni-swiper-item>
</template>
<script>
......
......@@ -205,7 +205,7 @@ export default {
var current = -1
if (this.currentItemId) {
for (let i = 0, items = this.items; i < items.length; i++) {
let componentInstance = items[i].componentInstance
const componentInstance = items[i].componentInstance
if (componentInstance && componentInstance.itemId === this.currentItemId) {
current = i
break
......@@ -612,7 +612,7 @@ export default {
})
}
for (let index = 0, length = swiperItems.length; index < length; index++) {
let currentSync = this.currentSync
const currentSync = this.currentSync
slidesDots.push(createElement('div', {
on: {
click: () => {
......@@ -624,7 +624,7 @@ export default {
'uni-swiper-dot-active': (index < currentSync + this.displayMultipleItemsNumber && index >= currentSync) || (index < currentSync + this.displayMultipleItemsNumber - length)
},
style: {
'background': index === currentSync ? this.indicatorActiveColor : this.indicatorColor
background: index === currentSync ? this.indicatorActiveColor : this.indicatorColor
}
}))
}
......@@ -632,7 +632,7 @@ export default {
var slidesWrapperChild = [createElement('div', {
ref: 'slides',
style: this.slidesStyle,
'class': 'uni-swiper-slides'
class: 'uni-swiper-slides'
}, [
createElement('div', {
ref: 'slideFrame',
......@@ -643,7 +643,7 @@ export default {
if (this.indicatorDots) {
slidesWrapperChild.push(createElement('div', {
ref: 'slidesDots',
'class': ['uni-swiper-dots', this.vertical ? 'uni-swiper-dots-vertical' : 'uni-swiper-dots-horizontal']
class: ['uni-swiper-dots', this.vertical ? 'uni-swiper-dots-vertical' : 'uni-swiper-dots-horizontal']
}, slidesDots))
}
......@@ -652,7 +652,7 @@ export default {
on: this.$listeners
}, [createElement('div', {
ref: 'slidesWrapper',
'class': 'uni-swiper-wrapper'
class: 'uni-swiper-wrapper'
}, slidesWrapperChild)]
)
}
......
......@@ -2,18 +2,21 @@
<uni-switch
:disabled="disabled"
v-on="$listeners"
@click="_onClick">
@click="_onClick"
>
<div class="uni-switch-wrapper">
<div
v-show="type === 'switch'"
:class="[switchChecked ? 'uni-switch-input-checked' : '']"
:style="{backgroundColor: switchChecked ? color : '#DFDFDF',borderColor:switchChecked ? color : '#DFDFDF'}"
class="uni-switch-input" />
class="uni-switch-input"
/>
<div
v-show="type === 'checkbox'"
:class="[switchChecked ? 'uni-checkbox-input-checked' : '']"
:style="{color: color}"
class="uni-checkbox-input" />
class="uni-checkbox-input"
/>
</div>
</uni-switch>
</template>
......@@ -92,10 +95,10 @@ export default {
this.switchChecked = false
},
_getFormData () {
let data = {}
const data = {}
if (this.name !== '') {
data['value'] = this.switchChecked
data['key'] = this.name
data.value = this.switchChecked
data.key = this.name
}
return data
}
......
<script>
const SPACE_UNICODE = {
'ensp': '\u2002',
'emsp': '\u2003',
'nbsp': '\u00a0'
ensp: '\u2002',
emsp: '\u2003',
nbsp: '\u00a0'
}
export default {
......
<template>
<uni-textarea
@change.stop
v-on="$listeners">
v-on="$listeners"
>
<div class="uni-textarea-wrapper">
<div
v-show="!(composition||valueSync.length)"
......@@ -9,17 +10,26 @@
:style="placeholderStyle"
:class="placeholderClass"
class="uni-textarea-placeholder"
>{{ placeholder }}</div>
>
{{ placeholder }}
</div>
<div
ref="line"
class="uni-textarea-line">&nbsp;</div>
class="uni-textarea-line"
>
&nbsp;
</div>
<div class="uni-textarea-compute">
<div
v-for="(item,index) in valueCompute"
:key="index">{{ item.trim() ? item : '.' }}</div>
:key="index"
>
{{ item.trim() ? item : '.' }}
</div>
<v-uni-resize-sensor
ref="sensor"
@resize="_resize" />
@resize="_resize"
/>
</div>
<textarea
ref="textarea"
......
......@@ -7,12 +7,13 @@
@touchcancel="_hoverTouchCancel"
v-on="$listeners"
>
<slot/>
<slot />
</uni-view>
<uni-view
v-else
v-on="$listeners">
<slot/>
v-on="$listeners"
>
<slot />
</uni-view>
</template>
......
......@@ -25,7 +25,7 @@ function getStyle (action) {
const option = action.option
const transition = option.transition
const style = {}
let transform = []
const transform = []
animates.forEach(animate => {
let type = animate.type
let args = [...animate.args]
......
......@@ -21,9 +21,9 @@ Spring.prototype._solve = function (e, t) {
var r = this._k
var o = n * n - 4 * i * r
if (o === 0) {
let a = -n / (2 * i)
let s = e
let l = t / (a * e)
const a = -n / (2 * i)
const s = e
const l = t / (a * e)
return {
x: function (e) {
return (s + l * e) * Math.pow(Math.E, a * e)
......@@ -35,10 +35,10 @@ Spring.prototype._solve = function (e, t) {
}
}
if (o > 0) {
let c = (-n - Math.sqrt(o)) / (2 * i)
let u = (-n + Math.sqrt(o)) / (2 * i)
let l = (t - c * e) / (u - c)
let s = e - l
const c = (-n - Math.sqrt(o)) / (2 * i)
const u = (-n + Math.sqrt(o)) / (2 * i)
const l = (t - c * e) / (u - c)
const s = e - l
return {
x: function (e) {
let t
......
......@@ -91,14 +91,14 @@ export default {
Object.assign(vm.constructor.options.methods, emitter.methods)
Object.assign(options.methods, emitter.methods)
const createdHooks = options['created']
vm.constructor.options['created'] = options['created'] =
const createdHooks = options.created
vm.constructor.options.created = options.created =
createdHooks ? [].concat(created, createdHooks) : [
created
]
const beforeDestroyHooks = options['beforeDestroy']
vm.constructor.options['beforeDestroy'] = options['beforeDestroy'] =
const beforeDestroyHooks = options.beforeDestroy
vm.constructor.options.beforeDestroy = options.beforeDestroy =
beforeDestroyHooks ? [].concat(beforeDestroy, beforeDestroyHooks) : [
beforeDestroy
]
......
......@@ -135,7 +135,7 @@ function touchstart (evt) {
startPageY = pageY
longPressTimer = setTimeout(function () {
let customEvent = new CustomEvent('longpress', {
const customEvent = new CustomEvent('longpress', {
bubbles: true,
cancelable: true,
target: evt.target,
......
......@@ -13,14 +13,14 @@ function parseDataset (attr) {
}
function findAttrs (ids, elm, result) {
let nodes = elm.children
const nodes = elm.children
if (!Array.isArray(nodes)) {
return false
}
for (let i = 0; i < nodes.length; i++) {
let node = nodes[i]
const node = nodes[i]
if (node.attr) {
let index = ids.indexOf(node.attr.id)
const index = ids.indexOf(node.attr.id)
if (index >= 0) {
result[index] = {
id: ids[index],
......@@ -39,7 +39,7 @@ function findAttrs (ids, elm, result) {
}
function getSelectors (queue) {
let ids = []
const ids = []
for (let i = 0; i < queue.length; i++) {
const selector = queue[i].selector
if (selector.indexOf('#') === 0) {
......@@ -68,7 +68,7 @@ export function requestComponentInfo (pageVm, queue, callback) {
// TODO 重构,逻辑不对,queue 里的每一项可能有单独的作用域查找(即 component)
const dom = pageVm._$weex.requireModule('dom')
const selectors = getSelectors(queue)
let outAttrs = new Array(selectors.length)
const outAttrs = new Array(selectors.length)
findAttrs(selectors, pageVm.$el, outAttrs)
getComponentRectAll(dom, outAttrs, 0, [], (result) => {
callback(result)
......
......@@ -108,7 +108,7 @@ function normalizeCallback (method, callbacks) {
isFn(callback) && callback(ret)
if (type === SUCCESS || type === FAIL) {
const complete = callbacks['complete']
const complete = callbacks.complete
isFn(complete) && complete(ret)
}
}
......
......@@ -71,7 +71,7 @@ export function initSubNVue (nvue, plus, BroadcastChannel) {
const maskColor = webview.__uniapp_mask
let maskWebview = webview.__uniapp_mask_id === '0' ? {
const maskWebview = webview.__uniapp_mask_id === '0' ? {
setStyle ({ mask }) {
nvue.requireModule('uni-tabview').setMask({
color: mask
......
......@@ -16,7 +16,7 @@ export function createPage (pagePath, pageId, pageQuery, pageInstance) {
if (!pageFactory[pagePath]) {
console.error(`${pagePath} not found`)
}
let startTime = Date.now()
const startTime = Date.now()
const pageVm = new (getPageVueComponent(pagePath))({
mpType: 'page',
pageId,
......
......@@ -23,7 +23,7 @@ function wrapper (webview) {
return
}
const maskColor = webview.__uniapp_mask
let maskWebview = webview.__uniapp_mask_id === '0' ? {
const maskWebview = webview.__uniapp_mask_id === '0' ? {
setStyle ({
mask
}) {
......
......@@ -51,6 +51,7 @@ class RewardedVideoAd {
})
this._loadAd()
}
load () {
return new Promise((resolve, reject) => {
if (this._isLoad) {
......@@ -62,6 +63,7 @@ class RewardedVideoAd {
this._loadAd()
})
}
show () {
return new Promise((resolve, reject) => {
if (this._isLoad) {
......@@ -72,16 +74,20 @@ class RewardedVideoAd {
}
})
}
getProvider () {
return this._rewardAd.getProvider()
}
destroy () {
this._rewardAd.destroy()
}
_loadAd () {
this._isLoad = false
this._rewardAd.load()
}
_dispatchEvent (name, data) {
this._callbacks[name].forEach(callback => {
if (typeof callback === 'function') {
......
......@@ -6,7 +6,7 @@ import {
publish
} from '../../bridge'
let audios = {}
const audios = {}
const evts = ['play', 'canplay', 'ended', 'stop', 'waiting', 'seeking', 'seeked', 'pause']
......@@ -82,7 +82,7 @@ export function setAudioState ({
}) {
const audio = audios[audioId]
if (audio) {
let style = {
const style = {
loop,
autoplay
}
......@@ -112,7 +112,7 @@ export function getAudioState ({
errMsg: 'getAudioState:fail'
}
}
let {
const {
src,
startTime,
volume
......
......@@ -115,12 +115,12 @@ export function getMusicPlayerState () {
currentPosition: audio.getPosition(),
status: audio.isPaused() ? 0 : 1,
downloadPercent: Math.round(100 * audio.getBuffered() / audio.getDuration()),
errMsg: `getMusicPlayerState:ok`
errMsg: 'getMusicPlayerState:ok'
}
}
return {
status: 2,
errMsg: `getMusicPlayerState:ok`
errMsg: 'getMusicPlayerState:ok'
}
}
export function operateMusicPlayer ({
......@@ -153,7 +153,7 @@ export function operateMusicPlayer ({
export function setBackgroundAudioState (args) {
setMusicState(args)
return {
errMsg: `setBackgroundAudioState:ok`
errMsg: 'setBackgroundAudioState:ok'
}
}
export function operateBackgroundAudio ({
......@@ -182,11 +182,11 @@ export function getBackgroundAudioState () {
coverImgUrl: '',
webUrl: '',
startTime: 0,
errMsg: `getBackgroundAudioState:ok`
errMsg: 'getBackgroundAudioState:ok'
}
const audio = getAudio()
if (audio) {
let newData = {
const newData = {
duration: audio.getDuration() || 0,
currentTime: audio.isStopped ? 0 : audio.getPosition(),
paused: audio.isPaused(),
......
......@@ -27,12 +27,12 @@ export function scanCode ({
}, callbackId) {
const barcode = plus.barcode
const SCAN_TYPES = {
'qrCode': [
qrCode: [
barcode.QR,
barcode.AZTEC,
barcode.MAXICODE
],
'barCode': [
barCode: [
barcode.EAN13,
barcode.EAN8,
barcode.UPCA,
......@@ -45,8 +45,8 @@ export function scanCode ({
barcode.RSS14,
barcode.RSSEXPANDED
],
'datamatrix': [barcode.DATAMATRIX],
'pdf417': [barcode.PDF417]
datamatrix: [barcode.DATAMATRIX],
pdf417: [barcode.PDF417]
}
const SCAN_MAPS = {
......@@ -82,8 +82,8 @@ export function scanCode ({
})
}
if (!filters.length) {
filters = filters.concat(SCAN_TYPES['qrCode']).concat(SCAN_TYPES['barCode']).concat(SCAN_TYPES['datamatrix']).concat(
SCAN_TYPES['pdf417'])
filters = filters.concat(SCAN_TYPES.qrCode).concat(SCAN_TYPES.barCode).concat(SCAN_TYPES.datamatrix).concat(
SCAN_TYPES.pdf417)
}
const buttons = []
......
......@@ -17,7 +17,7 @@ function checkIsSupportFingerPrint () {
}
export function checkIsSupportSoterAuthentication () {
let supportMode = []
const supportMode = []
if (checkIsSupportFingerPrint()) {
supportMode.push('fingerPrint')
}
......@@ -96,7 +96,7 @@ export function startSoterAuthentication ({
errMsg: 'startSoterAuthentication:fail'
}
}
let supportRequestAuthMode = []
const supportRequestAuthMode = []
requestAuthModes.map((item, index) => {
if (supportMode.indexOf(item) > -1) {
supportRequestAuthMode.push(item)
......@@ -109,7 +109,7 @@ export function startSoterAuthentication ({
errMsg: 'startSoterAuthentication:fail no corresponding mode'
}
}
let enrolledRequestAuthMode = []
const enrolledRequestAuthMode = []
supportRequestAuthMode.map((item, index) => {
const checked = checkIsSoterEnrolledInDevice({
checkAuthMode: item
......
......@@ -62,7 +62,7 @@ export function chooseLocation (params, callbackId) {
})
}
let index = 0
let onShow = function () {
const onShow = function () {
index++
if (index === 2) {
webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`)
......
......@@ -7,7 +7,7 @@ import {
} from '../../bridge'
const invokeChooseVideo = function (callbackId, type, tempFilePath = '') {
let callbackResult = {
const callbackResult = {
errMsg: `chooseVideo:${type}`,
tempFilePath: tempFilePath,
duration: 0,
......@@ -62,7 +62,7 @@ export function chooseVideo ({
camera = 'back'
} = {}, callbackId) {
let fallback = true
let cameraIndex = (camera === 'front') ? 2 : 1
const cameraIndex = (camera === 'front') ? 2 : 1
if (sourceType.length === 1) {
if (sourceType[0] === 'album') {
fallback = false
......
......@@ -17,12 +17,12 @@ export function compressImage ({
quality
}, () => {
invoke(callbackId, {
errMsg: `compressImage:ok`,
errMsg: 'compressImage:ok',
tempFilePath: dst
})
}, () => {
invoke(callbackId, {
errMsg: `compressImage:fail`
errMsg: 'compressImage:fail'
})
})
}
......@@ -33,7 +33,7 @@ export function previewImagePlus ({
let itemList = []
let itemColor = ''
let title = ''
let hasLongPressActions = longPressActions && longPressActions.callbackId
const hasLongPressActions = longPressActions && longPressActions.callbackId
if (!hasLongPressActions) {
itemList = ['保存相册']
itemColor = '#000000'
......
import {
hasOwn
} from 'uni-shared'
import {
TEMP_PATH
} from '../constants'
......@@ -40,7 +44,7 @@ const createDownloadTaskById = function (downloadTaskId, {
}
})
for (const name in header) {
if (header.hasOwnProperty(name)) {
if (hasOwn(header, name)) {
downloader.setRequestHeader(name, header[name])
}
}
......@@ -87,4 +91,4 @@ export function operateDownloadTask ({
export function createDownloadTask (args) {
return createDownloadTaskById(++downloadTaskId, args)
}
}
import {
publish,
requireNativePlugin,
base64ToArrayBuffer
} from '../../bridge'
let requestTaskId = 0
const requestTasks = {}
const publishStateChange = res => {
publish('onRequestTaskStateChange', res)
delete requestTasks[requestTaskId]
}
export function createRequestTaskById (requestTaskId, {
url,
data,
header,
method = 'GET',
responseType,
sslVerify = true
} = {}) {
const stream = requireNativePlugin('stream')
const headers = {}
let abortTimeout
let aborted
let hasContentType = false
for (const name in header) {
if (!hasContentType && name.toLowerCase() === 'content-type') {
hasContentType = true
headers['Content-Type'] = header[name]
// TODO 需要重构
if (method !== 'GET' && header[name].indexOf('application/x-www-form-urlencoded') === 0 && typeof data !== 'string' && !(data instanceof ArrayBuffer)) {
let bodyArray = []
for (let key in data) {
if (data.hasOwnProperty(key)) {
bodyArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
}
}
data = bodyArray.join('&')
}
} else {
headers[name] = header[name]
}
}
if (!hasContentType && method === 'POST') {
headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
}
const timeout = __uniConfig.networkTimeout.request
if (timeout) {
abortTimeout = setTimeout(() => {
aborted = true
publishStateChange({
requestTaskId,
state: 'fail',
statusCode: 0,
errMsg: 'timeout'
})
}, (timeout + 200))// TODO +200 发消息到原生层有时间开销,以后考虑由原生层回调超时
}
const options = {
method,
url: url.trim(),
// weex 官方文档有误,headers 类型实际 object,用 string 类型会无响应
headers,
type: responseType === 'arraybuffer' ? 'base64' : 'text',
// weex 官方文档未说明实际支持 timeout,单位:ms
timeout: timeout || 6e5,
// 配置和weex模块内相反
sslVerify: !sslVerify
}
if (method !== 'GET') {
options.body = data
}
try {
stream.fetch(options, ({
ok,
status,
data,
headers
}) => {
if (aborted) {
return
}
if (abortTimeout) {
clearTimeout(abortTimeout)
}
const statusCode = status
if (statusCode > 0) {
publishStateChange({
requestTaskId,
state: 'success',
data: ok && responseType === 'arraybuffer' ? base64ToArrayBuffer(data) : data,
statusCode,
header: headers
})
} else {
publishStateChange({
requestTaskId,
state: 'fail',
statusCode,
errMsg: 'abort statusCode:' + statusCode
})
}
})
requestTasks[requestTaskId] = {
abort () {
aborted = true
if (abortTimeout) {
clearTimeout(abortTimeout)
}
publishStateChange({
requestTaskId,
state: 'fail',
statusCode: 0,
errMsg: 'abort'
})
}
}
} catch (e) {
return {
requestTaskId,
errMsg: 'createRequestTask:fail'
}
}
return {
requestTaskId,
errMsg: 'createRequestTask:ok'
}
}
export function createRequestTask (args) {
return createRequestTaskById(++requestTaskId, args)
}
export function operateRequestTask ({
requestTaskId,
operationType
} = {}) {
const requestTask = requestTasks[requestTaskId]
if (requestTask && operationType === 'abort') {
requestTask.abort()
return {
errMsg: 'operateRequestTask:ok'
}
}
return {
errMsg: 'operateRequestTask:fail'
}
import {
hasOwn
} from 'uni-shared'
import {
publish,
requireNativePlugin,
base64ToArrayBuffer
} from '../../bridge'
let requestTaskId = 0
const requestTasks = {}
const publishStateChange = res => {
publish('onRequestTaskStateChange', res)
delete requestTasks[requestTaskId]
}
export function createRequestTaskById (requestTaskId, {
url,
data,
header,
method = 'GET',
responseType,
sslVerify = true
} = {}) {
const stream = requireNativePlugin('stream')
const headers = {}
let abortTimeout
let aborted
let hasContentType = false
for (const name in header) {
if (!hasContentType && name.toLowerCase() === 'content-type') {
hasContentType = true
headers['Content-Type'] = header[name]
// TODO 需要重构
if (method !== 'GET' && header[name].indexOf('application/x-www-form-urlencoded') === 0 && typeof data !==
'string' && !(data instanceof ArrayBuffer)) {
const bodyArray = []
for (const key in data) {
if (hasOwn(data, key)) {
bodyArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
}
}
data = bodyArray.join('&')
}
} else {
headers[name] = header[name]
}
}
if (!hasContentType && method === 'POST') {
headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
}
const timeout = __uniConfig.networkTimeout.request
if (timeout) {
abortTimeout = setTimeout(() => {
aborted = true
publishStateChange({
requestTaskId,
state: 'fail',
statusCode: 0,
errMsg: 'timeout'
})
}, (timeout + 200)) // TODO +200 发消息到原生层有时间开销,以后考虑由原生层回调超时
}
const options = {
method,
url: url.trim(),
// weex 官方文档有误,headers 类型实际 object,用 string 类型会无响应
headers,
type: responseType === 'arraybuffer' ? 'base64' : 'text',
// weex 官方文档未说明实际支持 timeout,单位:ms
timeout: timeout || 6e5,
// 配置和weex模块内相反
sslVerify: !sslVerify
}
if (method !== 'GET') {
options.body = data
}
try {
stream.fetch(options, ({
ok,
status,
data,
headers
}) => {
if (aborted) {
return
}
if (abortTimeout) {
clearTimeout(abortTimeout)
}
const statusCode = status
if (statusCode > 0) {
publishStateChange({
requestTaskId,
state: 'success',
data: ok && responseType === 'arraybuffer' ? base64ToArrayBuffer(data) : data,
statusCode,
header: headers
})
} else {
publishStateChange({
requestTaskId,
state: 'fail',
statusCode,
errMsg: 'abort statusCode:' + statusCode
})
}
})
requestTasks[requestTaskId] = {
abort () {
aborted = true
if (abortTimeout) {
clearTimeout(abortTimeout)
}
publishStateChange({
requestTaskId,
state: 'fail',
statusCode: 0,
errMsg: 'abort'
})
}
}
} catch (e) {
return {
requestTaskId,
errMsg: 'createRequestTask:fail'
}
}
return {
requestTaskId,
errMsg: 'createRequestTask:ok'
}
}
export function createRequestTask (args) {
return createRequestTaskById(++requestTaskId, args)
}
export function operateRequestTask ({
requestTaskId,
operationType
} = {}) {
const requestTask = requestTasks[requestTaskId]
if (requestTask && operationType === 'abort') {
requestTask.abort()
return {
errMsg: 'operateRequestTask:ok'
}
}
return {
errMsg: 'operateRequestTask:fail'
}
}
import {
hasOwn
} from 'uni-shared'
import {
getRealPath
} from '../util'
......@@ -46,12 +50,12 @@ const createUploadTaskById = function (uploadTaskId, {
})
for (const name in header) {
if (header.hasOwnProperty(name)) {
if (hasOwn(header, name)) {
uploader.setRequestHeader(name, header[name])
}
}
for (const name in formData) {
if (formData.hasOwnProperty(name)) {
if (hasOwn(formData, name)) {
uploader.addData(name, String(formData[name]))
}
}
......@@ -109,4 +113,4 @@ export function operateUploadTask ({
export function createUploadTask (args) {
return createUploadTaskById(++uploadTaskId, args)
}
}
......@@ -46,7 +46,8 @@ function addEventListener (pageId, callback) {
class Page {
constructor (webview) {
this.webview = webview
}
}
sendMessage (data) {
const message = {
__message: {
......@@ -60,7 +61,8 @@ class Page {
} else {
plus_.webview.postMessageToUniNView(message, id)
}
}
}
close () {
this.webview.close()
}
......
......@@ -12,27 +12,27 @@ import {
// 0:图文,1:纯文字,2:纯图片,3:音乐,4:视频,5:小程序
const TYPES = {
'0': {
0: {
name: 'web',
title: '图文'
},
'1': {
1: {
name: 'text',
title: '纯文字'
},
'2': {
2: {
name: 'image',
title: '纯图片'
},
'3': {
3: {
name: 'music',
title: '音乐'
},
'4': {
4: {
name: 'video',
title: '视频'
},
'5': {
5: {
name: 'miniProgram',
title: '小程序'
}
......@@ -59,7 +59,7 @@ const parseParams = (args, callbackId, method) => {
const shareType = TYPES[type + '']
if (shareType) {
let sendMsg = {
const sendMsg = {
provider,
type: shareType.name,
title,
......@@ -215,7 +215,7 @@ export function shareWithSystem (params, callbackId, method = 'shareWithSystem')
}
plus.share.sendWithSystem({
type,
pictures: imageUrl ? [imageUrl] : void 0,
pictures: imageUrl && [imageUrl],
content,
href
}, function (res) {
......
......@@ -23,7 +23,7 @@ function wrapper (webview) {
return
}
const maskColor = webview.__uniapp_mask
let maskWebview = webview.__uniapp_mask_id === '0' ? {
const maskWebview = webview.__uniapp_mask_id === '0' ? {
setStyle ({
mask
}) {
......@@ -66,7 +66,7 @@ export function getSubNVueById (id) {
if (webview && !webview.$processed) {
wrapper(webview)
}
let oldSetStyle = webview.setStyle
const oldSetStyle = webview.setStyle
var parentWebview = plus.webview.getWebviewById(webview.__uniapp_mask_id)
webview.setStyle = function (style) {
if (style && style.mask) {
......
......@@ -37,7 +37,7 @@ export function showToast ({
waiting.close()
}
if (~['top', 'center', 'bottom'].indexOf(position)) {
let richText = `<span>${title}</span>`
const richText = `<span>${title}</span>`
plus.nativeUI.toast(richText, {
verticalAlign: position,
type: 'richtext'
......
......@@ -27,18 +27,18 @@ const getRealRoute = (e, t) => {
if (t.indexOf('./') === 0) return getRealRoute(e, t.substr(2), !1)
let n
let i
let o = t.split('/')
const o = t.split('/')
for (n = 0, i = o.length; n < i && o[n] === '..'; n++);
o.splice(0, n)
t = o.join('/')
let r = e.length > 0 ? e.split('/') : []
const r = e.length > 0 ? e.split('/') : []
r.splice(r.length - n - 1, n + 1)
return r.concat(o).join('/')
}
// 处理 Android 平台解压与非解压模式下获取的路径不一致的情况
const _handleLocalPath = filePath => {
let localUrl = plus.io.convertLocalFileSystemURL(filePath)
const localUrl = plus.io.convertLocalFileSystemURL(filePath)
return localUrl.replace(/^\/?apps\//, '/android_asset/apps/').replace(/\/$/, '')
}
......
......@@ -47,7 +47,7 @@ export function setStatusBarStyle (statusBarStyle) {
return
}
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] setStatusBarStyle`, statusBarStyle)
console.log('[uni-app] setStatusBarStyle', statusBarStyle)
}
lastStatusBarStyle = statusBarStyle
......
......@@ -200,7 +200,7 @@ function initEntryPage () {
export function registerApp (appVm) {
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] registerApp`)
console.log('[uni-app] registerApp')
}
appCtx = appVm
......
......@@ -33,6 +33,6 @@ export function registerConfig (config, Vue) {
parseRoutes(__uniConfig)
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] registerConfig`, __uniConfig)
console.log('[uni-app] registerConfig', __uniConfig)
}
}
......@@ -93,7 +93,7 @@ export function registerPage ({
this.$vm.$destroy()
}
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] removePage`, path, webview.id)
console.log('[uni-app] removePage', path, webview.id)
}
}
},
......
......@@ -92,7 +92,7 @@ function showTabBar (animation) {
})
}
let maskClickCallback = []
const maskClickCallback = []
export default {
id: '0',
......@@ -179,7 +179,7 @@ export default {
maskClickCallback.push(callback)
},
removeEventListener (name, callback) {
let callbackIndex = maskClickCallback.indexOf(callback)
const callbackIndex = maskClickCallback.indexOf(callback)
maskClickCallback.splice(callbackIndex, 1)
}
}
......@@ -35,10 +35,10 @@ export let preloadWebview
let id = 2
const WEBVIEW_LISTENERS = {
'pullToRefresh': 'onPullDownRefresh',
'titleNViewSearchInputChanged': 'onNavigationBarSearchInputChanged',
'titleNViewSearchInputConfirmed': 'onNavigationBarSearchInputConfirmed',
'titleNViewSearchInputClicked': 'onNavigationBarSearchInputClicked'
pullToRefresh: 'onPullDownRefresh',
titleNViewSearchInputChanged: 'onNavigationBarSearchInputChanged',
titleNViewSearchInputConfirmed: 'onNavigationBarSearchInputConfirmed',
titleNViewSearchInputClicked: 'onNavigationBarSearchInputClicked'
}
export function setPreloadWebview (webview) {
......@@ -78,7 +78,7 @@ export function createWebview (path, routeOptions, query) {
)
webviewStyle.uniPageUrl = getUniPageUrl(path, query)
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] createWebview`, webviewId, path, webviewStyle)
console.log('[uni-app] createWebview', webviewId, path, webviewStyle)
}
return plus.webview.create('', String(webviewId), webviewStyle, {
nvue: true
......@@ -106,7 +106,7 @@ export function initWebview (webview, routeOptions, path, query) {
webviewStyle.debugRefresh = getDebugRefresh(path, query, routeOptions)
}
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] updateWebview`, webviewStyle)
console.log('[uni-app] updateWebview', webviewStyle)
}
webview.setStyle(webviewStyle)
......
......@@ -49,9 +49,9 @@ export function parseTitleNView (routeOptions) {
const titleImage = windowOptions.titleImage || ''
const transparentTitle = windowOptions.transparentTitle || 'none'
const titleNViewTypeList = {
'none': 'default',
'auto': 'transparent',
'always': 'float'
none: 'default',
auto: 'transparent',
always: 'float'
}
const ret = {
......@@ -61,13 +61,13 @@ export function parseTitleNView (routeOptions) {
type: titleNViewTypeList[transparentTitle],
backgroundColor: windowOptions.navigationBarBackgroundColor || '#f8f8f8',
tags: titleImage === '' ? [] : [{
'tag': 'img',
'src': titleImage,
'position': {
'left': 'auto',
'top': 'auto',
'width': 'auto',
'height': '26px'
tag: 'img',
src: titleImage,
position: {
left: 'auto',
top: 'auto',
width: 'auto',
height: '26px'
}
}]
}
......
......@@ -5,7 +5,7 @@ function onMessage (pageId, arg) {
return
}
if (!page.$page.meta.isNVue) {
const target = page.$vm._$vd.elements.find(target => target.type === 'web-view' && target.events['message'])
const target = page.$vm._$vd.elements.find(target => target.type === 'web-view' && target.events.message)
if (!target) {
return
}
......
<template>
<uni-ad
v-bind="attrs"
v-on="$listeners">
v-on="$listeners"
>
<div
ref="container"
class="uni-ad-container" />
class="uni-ad-container"
/>
</uni-ad>
</template>
<script>
......@@ -96,10 +98,10 @@ export default {
}
},
mounted () {
let adStyle = Object.assign({
const adStyle = Object.assign({
id: 'AdView' + Date.now()
}, this.position)
let adView = this.adView = plus.ad.createAdView(adStyle)
const adView = this.adView = plus.ad.createAdView(adStyle)
adView.interceptTouchEvent(false)
plus.webview.currentWebview().append(adView)
if (this.hidden) {
......
......@@ -2,10 +2,12 @@
<uni-cover-image
:src="src"
:style="imageInfo"
v-on="$listeners">
v-on="$listeners"
>
<div
ref="container"
class="uni-cover-image" />
class="uni-cover-image"
/>
</uni-cover-image>
</template>
<script>
......
......@@ -2,14 +2,16 @@
<uni-map v-on="$listeners">
<div
ref="container"
class="uni-map-container" />
class="uni-map-container"
/>
<v-uni-cover-image
v-for="(control, index) in mapControls"
:key="index"
:src="control.iconPath"
:style="control.position"
auto-size
@click="controlclick(control)"/>
@click="controlclick(control)"
/>
<div class="uni-map-slot">
<slot />
</div>
......@@ -144,7 +146,7 @@ export default {
},
mapControls () {
const list = this.controls.map((control) => {
let position = { position: 'absolute' };
const position = { position: 'absolute' };
['top', 'left', 'width', 'height'].forEach(key => {
if (control.position[key]) {
position[key] = control.position[key] + 'px'
......@@ -187,7 +189,7 @@ export default {
}
},
mounted () {
let mapStyle = Object.assign({}, this.attrs, this.position)
const mapStyle = Object.assign({}, this.attrs, this.position)
if (this.latitude && this.longitude) {
mapStyle.center = new plus.maps.Point(this.longitude, this.latitude)
}
......
<template>
<uni-picker
@click.stop="_show"
v-on="$listeners">
v-on="$listeners"
>
<slot />
</uni-picker>
</template>
......@@ -48,7 +49,7 @@ function getDefaultStartValue () {
return '00:00'
}
if (this.mode === mode.DATE) {
let year = new Date().getFullYear() - 100
const year = new Date().getFullYear() - 100
switch (this.fields) {
case fields.YEAR:
return year
......@@ -66,7 +67,7 @@ function getDefaultEndValue () {
return '23:59'
}
if (this.mode === mode.DATE) {
let year = new Date().getFullYear() + 100
const year = new Date().getFullYear() + 100
switch (this.fields) {
case fields.YEAR:
return year
......@@ -162,17 +163,19 @@ export default {
let val = this.value
switch (this.mode) {
case mode.MULTISELECTOR:
if (!Array.isArray(val)) {
val = []
}
if (!Array.isArray(this.valueSync)) {
this.valueSync = []
}
const length = this.valueSync.length = Math.max(val.length, this.range.length)
for (let index = 0; index < length; index++) {
const val0 = Number(val[index])
const val1 = Number(this.valueSync[index])
this.valueSync.splice(index, 1, isNaN(val0) ? (isNaN(val1) ? 0 : val1) : val0)
{
if (!Array.isArray(val)) {
val = []
}
if (!Array.isArray(this.valueSync)) {
this.valueSync = []
}
const length = this.valueSync.length = Math.max(val.length, this.range.length)
for (let index = 0; index < length; index++) {
const val0 = Number(val[index])
const val1 = Number(this.valueSync[index])
this.valueSync.splice(index, 1, isNaN(val0) ? (isNaN(val1) ? 0 : val1) : val0)
}
}
break
case mode.TIME:
......
......@@ -46,7 +46,8 @@ function addEventListener (pageId, callback) {
class Page {
constructor (webview) {
this.webview = webview
}
}
sendMessage (data) {
const message = {
__message: {
......@@ -60,7 +61,8 @@ class Page {
} else {
plus_.webview.postMessageToUniNView(message, id)
}
}
}
close () {
this.webview.close()
}
......
......@@ -2,7 +2,8 @@
<uni-video v-on="$listeners">
<div
ref="container"
class="uni-video-container" />
class="uni-video-container"
/>
<div class="uni-video-slot">
<slot />
</div>
......
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册