From 6544b2537f13c66f1f4f068ce587be09c08a8f68 Mon Sep 17 00:00:00 2001
From: "1054425342@qq.com" <1054425342@qq.com>
Date: Sat, 2 Aug 2025 14:45:03 +0800
Subject: [PATCH] delete
---
.../uni-transition/createAnimation.js | 50 ++-
.../uni-transition/uni-transition.vue | 97 +++--
.../uni-transition_BACKUP_472.vue | 373 ------------------
.../uni-transition_BASE_472.vue | 277 -------------
.../uni-transition_LOCAL_472.vue | 319 ---------------
.../uni-transition_REMOTE_472.vue | 310 ---------------
6 files changed, 104 insertions(+), 1322 deletions(-)
delete mode 100644 uni_modules/uni-transition/components/uni-transition/uni-transition_BACKUP_472.vue
delete mode 100644 uni_modules/uni-transition/components/uni-transition/uni-transition_BASE_472.vue
delete mode 100644 uni_modules/uni-transition/components/uni-transition/uni-transition_LOCAL_472.vue
delete mode 100644 uni_modules/uni-transition/components/uni-transition/uni-transition_REMOTE_472.vue
diff --git a/uni_modules/uni-transition/components/uni-transition/createAnimation.js b/uni_modules/uni-transition/components/uni-transition/createAnimation.js
index 6877a5d..eb5d785 100644
--- a/uni_modules/uni-transition/components/uni-transition/createAnimation.js
+++ b/uni_modules/uni-transition/components/uni-transition/createAnimation.js
@@ -10,7 +10,12 @@ const nvueAnimation = uni.requireNativePlugin('animation')
class MPAnimation {
constructor(options, _this) {
this.options = options
- this.animation = uni.createAnimation(options)
+ try {
+ this.animation = uni.createAnimation(options)
+ } catch (error) {
+ console.error('uni.createAnimation failed:', error)
+ this.animation = null
+ }
this.currentStepAnimates = {}
this.next = 0
this.$ = _this
@@ -75,27 +80,48 @@ class MPAnimation {
step(config = {}) {
// #ifndef APP-NVUE
- this.animation.step(config)
+ if (this.animation && typeof this.animation.step === 'function') {
+ try {
+ this.animation.step(config)
+ } catch (error) {
+ console.error('Animation step failed:', error)
+ }
+ }
// #endif
// #ifdef APP-NVUE
- this.currentStepAnimates[this.next].config = Object.assign({}, this.options, config)
- this.currentStepAnimates[this.next].styles.transformOrigin = this.currentStepAnimates[this.next].config.transformOrigin
- this.next++
+ if (this.currentStepAnimates[this.next]) {
+ this.currentStepAnimates[this.next].config = Object.assign({}, this.options, config)
+ this.currentStepAnimates[this.next].styles.transformOrigin = this.currentStepAnimates[this.next].config.transformOrigin
+ this.next++
+ }
// #endif
return this
}
run(fn) {
// #ifndef APP-NVUE
- this.$.animationData = this.animation.export()
- this.$.timer = setTimeout(() => {
+ if (this.animation && typeof this.animation.export === 'function') {
+ try {
+ this.$.animationData = this.animation.export()
+ this.$.timer = setTimeout(() => {
+ typeof fn === 'function' && fn()
+ }, this.$.durationTime)
+ } catch (error) {
+ console.error('Animation run failed:', error)
+ typeof fn === 'function' && fn()
+ }
+ } else {
+ // 如果动画对象不存在,直接执行回调
typeof fn === 'function' && fn()
- }, this.$.durationTime)
+ }
// #endif
// #ifdef APP-NVUE
this.isEnd = false
let ref = this.$.$refs['ani'] && this.$.$refs['ani'].ref
- if(!ref) return
+ if(!ref) {
+ typeof fn === 'function' && fn()
+ return
+ }
this._nvueNextAnimate(this.currentStepAnimates, 0, fn)
this.next = 0
// #endif
@@ -113,7 +139,11 @@ animateTypes1.concat(animateTypes2, animateTypes3).forEach(type => {
MPAnimation.prototype[type] = function(...args) {
// #ifndef APP-NVUE
if (this.animation && typeof this.animation[type] === 'function') {
- this.animation[type](...args)
+ try {
+ this.animation[type](...args)
+ } catch (error) {
+ console.error(`Animation method ${type} failed:`, error)
+ }
}
// #endif
// #ifdef APP-NVUE
diff --git a/uni_modules/uni-transition/components/uni-transition/uni-transition.vue b/uni_modules/uni-transition/components/uni-transition/uni-transition.vue
index b2bea45..7cee05c 100644
--- a/uni_modules/uni-transition/components/uni-transition/uni-transition.vue
+++ b/uni_modules/uni-transition/components/uni-transition/uni-transition.vue
@@ -125,6 +125,26 @@ export default {
};
this.durationTime = this.duration;
},
+ beforeUnmount() {
+ // 组件销毁前清理定时器和动画对象
+ if (this.timer) {
+ clearTimeout(this.timer);
+ this.timer = null;
+ }
+ if (this.animation) {
+ this.animation = null;
+ }
+ },
+ beforeDestroy() {
+ // Vue2 兼容
+ if (this.timer) {
+ clearTimeout(this.timer);
+ this.timer = null;
+ }
+ if (this.animation) {
+ this.animation = null;
+ }
+ },
methods: {
/**
* ref 触发 初始化动画
@@ -198,19 +218,23 @@ export default {
this.$nextTick(() => {
// TODO 定时器保证动画完全执行,目前有些问题,后面会取消定时器
this.timer = setTimeout(() => {
+ // 检查组件是否仍然存在且需要显示
+ if (!this.isShow || !this.$el) {
+ return;
+ }
try {
this.animation = createAnimation(this.config, this);
- if (this.animation) {
- let result = this.tranfromInit(false);
- if (result && typeof result.step === "function") {
- result.step();
- if (typeof result.run === "function") {
- result.run();
+ if (this.animation && typeof this.animation.step === "function" && typeof this.animation.run === "function") {
+ this.tranfromInit(false);
+ if (typeof this.animation.step === "function") {
+ this.animation.step();
+ if (typeof this.animation.run === "function") {
+ this.animation.run();
}
}
}
- } catch (e) {
- console.error("动画初始化错误:", e);
+ } catch (error) {
+ console.error('uni-transition animation error:', error);
}
this.$emit("change", {
detail: this.isShow,
@@ -220,27 +244,34 @@ export default {
},
// 关闭过度动画
close(type) {
- if (!this.animation) return;
+ if (!this.animation || typeof this.animation.step !== 'function' || typeof this.animation.run !== 'function') return;
try {
- let result = this.tranfromInit(true);
- if (result && typeof result.step === "function") {
- result.step();
- if (typeof result.run === "function") {
- result.run(() => {
+ this.tranfromInit(true);
+ if (typeof this.animation.step === 'function') {
+ this.animation.step();
+ if (typeof this.animation.run === 'function') {
+ this.animation.run(() => {
this.isShow = false;
this.animationData = null;
this.animation = null;
let { opacity, transform } = this.styleInit(false);
this.opacity = opacity || 1;
this.transform = transform;
- this.$emit("change", {
+ this.$emit('change', {
detail: this.isShow,
});
});
}
}
- } catch (e) {
- console.error("动画关闭错误:", e);
+ } catch (error) {
+ console.error('uni-transition close animation error:', error);
+ // 发生错误时直接关闭
+ this.isShow = false;
+ this.animationData = null;
+ this.animation = null;
+ this.$emit('change', {
+ detail: this.isShow
+ });
}
},
// 处理动画开始前的默认样式
@@ -266,35 +297,35 @@ export default {
},
// 处理内置组合动画
tranfromInit(type) {
- if (!this.animation) return this;
+ if (!this.animation) {
+ console.warn('uni-transition: animation object is not initialized');
+ return this.animation;
+ }
let buildTranfrom = (type, mode) => {
let aniNum = null;
- if (mode === "fade") {
+ if (mode === 'fade') {
aniNum = type ? 0 : 1;
} else {
- aniNum = type ? "-100%" : "0";
- if (mode === "zoom-in") {
+ aniNum = type ? '-100%' : '0';
+ if (mode === 'zoom-in') {
aniNum = type ? 0.8 : 1;
}
- if (mode === "zoom-out") {
+ if (mode === 'zoom-out') {
aniNum = type ? 1.2 : 1;
}
- if (mode === "slide-right") {
- aniNum = type ? "100%" : "0";
+ if (mode === 'slide-right') {
+ aniNum = type ? '100%' : '0';
}
- if (mode === "slide-bottom") {
- aniNum = type ? "100%" : "0";
+ if (mode === 'slide-bottom') {
+ aniNum = type ? '100%' : '0';
}
}
- let methodName = this.animationMode()[mode];
- if (
- this.animation &&
- typeof this.animation[methodName] === "function"
- ) {
- this.animation[methodName](aniNum);
+ const animationMethod = this.animationMode()[mode];
+ if (this.animation && typeof this.animation[animationMethod] === 'function') {
+ this.animation[animationMethod](aniNum);
}
};
- if (typeof this.modeClass === "string") {
+ if (typeof this.modeClass === 'string') {
buildTranfrom(type, this.modeClass);
} else {
this.modeClass.forEach((mode) => {
diff --git a/uni_modules/uni-transition/components/uni-transition/uni-transition_BACKUP_472.vue b/uni_modules/uni-transition/components/uni-transition/uni-transition_BACKUP_472.vue
deleted file mode 100644
index ccdd52a..0000000
--- a/uni_modules/uni-transition/components/uni-transition/uni-transition_BACKUP_472.vue
+++ /dev/null
@@ -1,373 +0,0 @@
-
-
-
-
-
-
-
diff --git a/uni_modules/uni-transition/components/uni-transition/uni-transition_BASE_472.vue b/uni_modules/uni-transition/components/uni-transition/uni-transition_BASE_472.vue
deleted file mode 100644
index 0d739bd..0000000
--- a/uni_modules/uni-transition/components/uni-transition/uni-transition_BASE_472.vue
+++ /dev/null
@@ -1,277 +0,0 @@
-
-
-
-
-
-
-
diff --git a/uni_modules/uni-transition/components/uni-transition/uni-transition_LOCAL_472.vue b/uni_modules/uni-transition/components/uni-transition/uni-transition_LOCAL_472.vue
deleted file mode 100644
index d5d0ace..0000000
--- a/uni_modules/uni-transition/components/uni-transition/uni-transition_LOCAL_472.vue
+++ /dev/null
@@ -1,319 +0,0 @@
-
-
-
-
-
-
-
diff --git a/uni_modules/uni-transition/components/uni-transition/uni-transition_REMOTE_472.vue b/uni_modules/uni-transition/components/uni-transition/uni-transition_REMOTE_472.vue
deleted file mode 100644
index 7c29a23..0000000
--- a/uni_modules/uni-transition/components/uni-transition/uni-transition_REMOTE_472.vue
+++ /dev/null
@@ -1,310 +0,0 @@
-
-
-
-
-
-
-