refactor(top-nav-bar): add custom back prop
- add customBack prop to enable explicit custom back handling - rewrite back navigation logic to use the new prop instead of inferring from emit listeners - remove unused getCurrentInstance import - update three AIGC page components to use the custom-back prop
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, getCurrentInstance, onMounted, ref } from "vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
|
||||
// 定义props
|
||||
const props = defineProps({
|
||||
@@ -85,11 +85,14 @@ const props = defineProps({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
customBack: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
// 定义emits
|
||||
const emit = defineEmits(["back"]);
|
||||
const instance = getCurrentInstance();
|
||||
|
||||
// 系统信息
|
||||
const statusBarHeight = ref(0);
|
||||
@@ -145,25 +148,9 @@ const navContentStyle = computed(() => {
|
||||
};
|
||||
});
|
||||
|
||||
const hasBackListener = computed(() => {
|
||||
const vnodeProps = instance?.vnode?.props || {};
|
||||
return Boolean(vnodeProps.onBack);
|
||||
});
|
||||
|
||||
// 处理返回事件
|
||||
const handleBack = () => {
|
||||
const pages = getCurrentPages();
|
||||
|
||||
if (pages.length <= 1) {
|
||||
// #ifdef MP-WEIXIN
|
||||
if (typeof wx !== "undefined" && typeof wx.exitMiniProgram === "function") {
|
||||
wx.exitMiniProgram();
|
||||
return;
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
if (hasBackListener.value) {
|
||||
if (props.customBack) {
|
||||
emit("back");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user