适配微信小程序
This commit is contained in:
@@ -13,16 +13,12 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// 微信小程序:pages.json 的 componentPlaceholder 注册分包组件(requiredComponents / 分包异步化)
|
||||
// #ifndef MP-WEIXIN
|
||||
// 全端显式注册:微信小程序下仅用 componentPlaceholder 时,子组件实例不会出现在 this.$refs 上,导致无法 refresh。
|
||||
import FurnitureReceptionImpl from '@/pages-subpackage/furniture_reception/furniture_reception-impl.vue';
|
||||
// #endif
|
||||
|
||||
export default {
|
||||
components: {
|
||||
// #ifndef MP-WEIXIN
|
||||
FurnitureReceptionImpl
|
||||
// #endif
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@@ -31,7 +27,14 @@ export default {
|
||||
error: ''
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
onLoad(options) {
|
||||
// 与 storage 双通道:避免分包异步晚于 onShow 时漏掉目标 tab
|
||||
const tab = options && options.tab;
|
||||
if (tab && ['status', 'reception', 'tag'].includes(String(tab))) {
|
||||
try {
|
||||
uni.setStorageSync('workbench-reception-tab', String(tab));
|
||||
} catch (e) {}
|
||||
}
|
||||
this.loadImpl();
|
||||
},
|
||||
onShow() {
|
||||
@@ -40,16 +43,20 @@ export default {
|
||||
const allowed = ['status', 'reception', 'tag'];
|
||||
const tab = (uni.getStorageSync('workbench-reception-tab') || '').toString();
|
||||
if (allowed.includes(tab)) {
|
||||
// 先清空再赋值,确保同一个 tabKey 也能触发子组件 watcher
|
||||
this.incomingTab = '';
|
||||
this.$nextTick(() => {
|
||||
this.incomingTab = tab;
|
||||
});
|
||||
uni.removeStorageSync('workbench-reception-tab');
|
||||
// 首次进入:loadImpl 往往在 onShow 的 $nextTick 之前就 implReady,若先 incomingTab='' 再 nextTick 赋回,
|
||||
// 子组件首次挂载会拿到空 tab,且与宿主 refresh 竞态。
|
||||
if (!this.implReady) {
|
||||
this.incomingTab = tab;
|
||||
} else {
|
||||
// 页面已缓存再次显示:脉冲触发子组件 watcher
|
||||
this.incomingTab = '';
|
||||
this.$nextTick(() => {
|
||||
this.incomingTab = tab;
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
} catch (e) {}
|
||||
// 底部 tab 等场景下页面会被缓存,子组件 mounted 不会再次执行,需每次显示时拉取最新数据
|
||||
this.refreshImplDataIfReady();
|
||||
},
|
||||
@@ -79,6 +86,7 @@ export default {
|
||||
await this.loadSubPackagePagesSubpackage();
|
||||
this.implReady = true;
|
||||
await this.$nextTick();
|
||||
await this.$nextTick();
|
||||
this.refreshImplDataIfReady();
|
||||
} catch (e) {
|
||||
console.error('[FurnitureReceptionHost] loadImpl failed:', e);
|
||||
@@ -89,12 +97,19 @@ export default {
|
||||
if (!this.implReady) {
|
||||
return;
|
||||
}
|
||||
this.$nextTick(() => {
|
||||
const impl = this.$refs.furnitureReceptionImpl;
|
||||
if (impl && typeof impl.refreshPageData === 'function') {
|
||||
impl.refreshPageData();
|
||||
}
|
||||
});
|
||||
const tryRefresh = (attempt) => {
|
||||
this.$nextTick(() => {
|
||||
const impl = this.$refs.furnitureReceptionImpl;
|
||||
if (impl && typeof impl.refreshPageData === 'function') {
|
||||
impl.refreshPageData();
|
||||
return;
|
||||
}
|
||||
if (attempt < 3) {
|
||||
setTimeout(() => tryRefresh(attempt + 1), 50);
|
||||
}
|
||||
});
|
||||
};
|
||||
tryRefresh(0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user