diff --git a/src/core/helpers/hidpi.js b/src/core/helpers/hidpi.js index ca8e0084be33a35f288a6fbe9e748deb583afd32..09fecb39c1c40d1e066e9e1fa5d5eb6eb531a462 100644 --- a/src/core/helpers/hidpi.js +++ b/src/core/helpers/hidpi.js @@ -105,6 +105,7 @@ if (pixelRatio !== 1) { args[1] *= pixelRatio args[2] *= pixelRatio + args[3] *= pixelRatio // Safari 重新设置部分属性会导致其他值恢复默认,需获取原始值 var font = this.__font__ || this.font @@ -130,6 +131,7 @@ if (pixelRatio !== 1) { args[1] *= pixelRatio // x args[2] *= pixelRatio // y + args[3] *= pixelRatio // y // Safari 重新设置部分属性会导致其他值恢复默认,需获取原始值 var font = this.__font__ || this.font @@ -157,11 +159,11 @@ if (pixelRatio !== 1) { })(proto.drawImage) } -export function wrapper (canvas) { - canvas.width = canvas.offsetWidth * pixelRatio - canvas.height = canvas.offsetHeight * pixelRatio - canvas.__hidpi__ = true +export function wrapper (canvas, hidpi = true) { + canvas.width = canvas.offsetWidth * (hidpi ? pixelRatio : 1) + canvas.height = canvas.offsetHeight * (hidpi ? pixelRatio : 1) + canvas.__hidpi__ = hidpi // 避免低版本安卓上 context 实例被回收 canvas.__context2d__ = canvas.getContext('2d') - canvas.__context2d__.__hidpi__ = true + canvas.__context2d__.__hidpi__ = hidpi } diff --git a/src/core/view/components/canvas/index.vue b/src/core/view/components/canvas/index.vue index 786a83cd969504f2f1b0cb8da5ecf91caba7e4c7..4ca7ae210aecc2a67e5cb87ea60197d22931af3a 100644 --- a/src/core/view/components/canvas/index.vue +++ b/src/core/view/components/canvas/index.vue @@ -78,6 +78,10 @@ export default { disableScroll: { type: [Boolean, String], default: false + }, + hidpi: { + type: Boolean, + default: true } }, data () { @@ -110,6 +114,9 @@ export default { $listeners[event] = eventHandler }) return $listeners + }, + pixelRatio () { + return this.hidpi ? pixelRatio : 1 } }, created () { @@ -135,15 +142,15 @@ export default { }, _resize (size) { var canvas = this.$refs.canvas - var hasChanged = !size || (canvas.width !== Math.floor(size.width * pixelRatio) || canvas.height !== Math.floor(size.height * pixelRatio)) + var hasChanged = !size || (canvas.width !== Math.floor(size.width * this.pixelRatio) || canvas.height !== Math.floor(size.height * this.pixelRatio)) if (!hasChanged) return if (canvas.width > 0 && canvas.height > 0) { var context = canvas.getContext('2d') var imageData = context.getImageData(0, 0, canvas.width, canvas.height) - wrapper(canvas) + wrapper(canvas, this.hidpi) context.putImageData(imageData, 0, 0) } else { - wrapper(canvas) + wrapper(canvas, this.hidpi) } }, _touchmove (event) { @@ -377,8 +384,8 @@ export default { height = height ? Math.min(height, maxHeight) : maxHeight if (!hidpi) { if (!destWidth && !destHeight) { - destWidth = Math.round(width * pixelRatio) - destHeight = Math.round(height * pixelRatio) + destWidth = Math.round(width * this.pixelRatio) + destHeight = Math.round(height * this.pixelRatio) } else if (!destWidth) { destWidth = Math.round(width / height * destHeight) } else if (!destHeight) { diff --git a/src/platforms/app-plus/service/api/device/add-phone-contact.js b/src/platforms/app-plus/service/api/device/add-phone-contact.js index 0f55b9eed588e5b8bfcc488bb83d071ee9c30105..3c06ef075fd608df72053f1bd5a3bfdea62f5264 100644 --- a/src/platforms/app-plus/service/api/device/add-phone-contact.js +++ b/src/platforms/app-plus/service/api/device/add-phone-contact.js @@ -6,7 +6,7 @@ const schema = { name: { givenName: 'firstName', middleName: 'middleName', - familyName: 'lastName', + familyName: 'lastName' }, nickname: 'nickName', photos: { @@ -84,7 +84,7 @@ const schema = { const keepFields = ['type', 'preferred'] -function buildContact(contact, data, schema) { +function buildContact (contact, data, schema) { let hasValue = 0 Object.keys(schema).forEach(contactKey => { const dataKey = schema[contactKey] @@ -127,7 +127,7 @@ function buildContact(contact, data, schema) { return hasValue } -export function addPhoneContact(data, callbackId) { +export function addPhoneContact (data, callbackId) { plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, (addressbook) => { !data.photoFilePath && (data.photoFilePath = '') const contact = addressbook.create()