feat: 添加点击消息打开微应用功能

This commit is contained in:
kuaifan 2025-12-02 06:29:45 +00:00
parent 4621222fa3
commit 4ef78d2c81
3 changed files with 53 additions and 10 deletions

View File

@ -3639,17 +3639,24 @@ export default {
return return
} }
// // /
let approveElement = target; let clickElement = target;
while (approveElement) { while (clickElement) {
if (approveElement.classList.contains('dialog-scroller')) { if (!clickElement.classList) {
break; break;
} }
if (approveElement.classList.contains('open-approve-details')) { if (clickElement.classList.contains('dialog-head')) {
emitter.emit('approveDetails', approveElement.getAttribute("data-id")); break;
}
if (clickElement.classList.contains('open-micro-app')) {
this.handleOpenMicroApp(clickElement);
return; return;
} }
approveElement = approveElement.parentElement; if (clickElement.classList.contains('open-approve-details')) {
emitter.emit('approveDetails', clickElement.getAttribute("data-id"));
return;
}
clickElement = clickElement.parentElement;
} }
switch (target.nodeName) { switch (target.nodeName) {
@ -4420,7 +4427,35 @@ export default {
this.sendMsg(msgText, sendType); this.sendMsg(msgText, sendType);
} }
}); });
},
handleOpenMicroApp(element) {
const dataset = element && element.dataset ? element.dataset : {};
const normalizeKey = key => {
const name = key.replace(/^app/, '');
return name.replace(/^[A-Z]/, m => m.toLowerCase()).replace(/([A-Z])/g, '_$1').toLowerCase();
};
let config = $A.jsonParse(dataset.appConfig);
Object.entries(dataset).forEach(([key, value]) => {
if (!key.startsWith('app') || key === 'appConfig') {
return;
} }
if (value === '' || typeof value === 'undefined') {
return;
}
const normalizedKey = normalizeKey(key);
if (normalizedKey === 'props') {
config.props = Object.assign(config.props || {}, $A.jsonParse(value));
return;
}
if (value === 'true' || value === 'false') {
config[normalizedKey] = /true/i.test(value);
} else {
config[normalizedKey] = value;
}
});
this.$store.dispatch("openMicroApp", config);
},
} }
} }
</script> </script>

View File

@ -5109,9 +5109,13 @@ export default {
props: $A.isJson(data.props) ? data.props : {}, props: $A.isJson(data.props) ? data.props : {},
} }
if (!state.microAppsIds.includes(config.id)) { if (!state.microAppsIds.includes(config.id)) {
const matchedId = state.microAppsIds.find(item => typeof item === 'string' && item.endsWith(config.id))
if (!matchedId) {
$A.modalWarning(`应用「${config.id}」未安装`); $A.modalWarning(`应用「${config.id}」未安装`);
return; return;
} }
config.id = matchedId;
}
config.url = config.url config.url = config.url
.replace(/\{user_id}/g, state.userId) .replace(/\{user_id}/g, state.userId)
.replace(/\{user_nickname}/g, encodeURIComponent(state.userInfo.nickname)) .replace(/\{user_nickname}/g, encodeURIComponent(state.userInfo.nickname))

View File

@ -1405,6 +1405,10 @@
} }
} }
.open-micro-app {
cursor: pointer;
}
.open-approve-details { .open-approve-details {
width: 280px; width: 280px;
display: inline-block; display: inline-block;