Explorar el Código

解决uni.previewImage图片模糊问题

gcz hace 2 años
padre
commit
59247b395a
Se han modificado 3 ficheros con 66 adiciones y 1 borrados
  1. 5 0
      main.js
  2. 60 0
      mixin/previewImage.js
  3. 1 1
      pages/login/login.vue

+ 5 - 0
main.js

@@ -64,6 +64,11 @@ require('./common/request.js')(app)
 import httpApi from '@/common/http.api.js';
 Vue.use(httpApi, app);
 
+// 解决uni.previewImage图片模糊问题
+import previewImage from '@/mixin/previewImage.js'
+Vue.mixin(previewImage);
+
+
 app.$mount()
 
 

+ 60 - 0
mixin/previewImage.js

@@ -0,0 +1,60 @@
+// 解决uni.previewImage图片模糊问题
+// https://blog.csdn.net/iVRJay/article/details/125942024
+function v(a, b) {
+	return +((1000 * a - 1000 * b) / 1000).toFixed(1)
+}
+module.exports = {
+	created() {
+		if (this._setTransform) {
+			this._setTransform = (x, y, scale, source = '', r, o) => {
+				if (!(x !== null && x.toString() !== 'NaN' && typeof x === 'number')) {
+					x = this._translateX || 0
+				}
+				if (!(y !== null && y.toString() !== 'NaN' && typeof y === 'number')) {
+					y = this._translateY || 0
+				}
+				x = Number(x.toFixed(1))
+				y = Number(y.toFixed(1))
+				scale = Number(scale.toFixed(1))
+				if (!(this._translateX === x && this._translateY === y)) {
+					if (!r) {
+						this.$trigger('change', {}, {
+							x: v(x, this._scaleOffset.x),
+							y: v(y, this._scaleOffset.y),
+							source: source
+						})
+					}
+				}
+				if (!this.scale) {
+					scale = this._scale
+				}
+				scale = this._adjustScale(scale)
+				scale = +scale.toFixed(3)
+				if (o && scale !== this._scale) {
+					this.$trigger('scale', {}, {
+						x: x,
+						y: y,
+						scale: scale
+					})
+				}
+				var transform = 'translateX(' + x + 'px) translateY(' + y + 'px) scale(' + scale + ')'
+				this.$el.style.transform = transform
+				this.$el.style.webkitTransform = transform
+				this._translateX = x
+				this._translateY = y
+				this._scale = scale
+			}
+		}
+	},
+	destroyed() {
+        //解决预览模式关闭后,和重复开关预览模式this._setTransform函数无限次执行导致手机卡顿的问题
+		if (this._FA) {
+			this._FA.cancel()
+		}
+		if (this._SFA) {
+			this._SFA.cancel()
+		}
+	},
+	methods: {
+	}
+}

+ 1 - 1
pages/login/login.vue

@@ -76,7 +76,7 @@
 		onLoad() {
 			// 测试环境填充用户名密码
 			if(process.env.NODE_ENV=='development'){
-				this.form.mobile = '18085000374';
+				this.form.mobile = '15285955523';
 				this.form.password = '000000';
 			}
 			let that = this;