Add linked mini program functionality and enhance link tag handling

- Introduced `navigateToMiniProgramAppIdList` in app.json for mini program navigation.
- Updated link tag handling in the read page to support mini program keys and app IDs.
- Enhanced content parsing to include app ID and mini program key in link tags.
- Added linked mini programs management in the admin panel with API endpoints for CRUD operations.
- Improved UI for selecting linked mini programs in the content creation page.
This commit is contained in:
Alex-larget
2026-03-12 16:51:12 +08:00
parent 41ebc70a50
commit db4b4b8b87
13 changed files with 696 additions and 34 deletions

View File

@@ -78,11 +78,12 @@ Page({
async onLoad(options) {
wx.showShareMenu({ withShareTimeline: true })
// 预加载 linkTags 配置(供 onLinkTagTap 旧格式降级匹配 type 用
if (!app.globalData.linkTagsConfig) {
// 预加载 linkTags、linkedMiniprograms(供 onLinkTagTap 用密钥查 appId
if (!app.globalData.linkTagsConfig || !app.globalData.linkedMiniprograms) {
app.request({ url: '/api/miniprogram/config', silent: true }).then(cfg => {
if (cfg && Array.isArray(cfg.linkTags)) {
app.globalData.linkTagsConfig = cfg.linkTags
if (cfg) {
if (Array.isArray(cfg.linkTags)) app.globalData.linkTagsConfig = cfg.linkTags
if (Array.isArray(cfg.linkedMiniprograms)) app.globalData.linkedMiniprograms = cfg.linkedMiniprograms
}
}).catch(() => {})
}
@@ -469,12 +470,13 @@ Page({
getApp().goBackOrToHome()
},
// 点击正文中的 #链接标签:小程序内页/预览页跳转
// 点击正文中的 #链接标签:小程序内页/预览页/唤醒其他小程序
onLinkTagTap(e) {
let url = (e.currentTarget.dataset.url || '').trim()
const label = (e.currentTarget.dataset.label || '').trim()
let tagType = (e.currentTarget.dataset.tagType || '').trim()
let pagePath = (e.currentTarget.dataset.pagePath || '').trim()
let mpKey = (e.currentTarget.dataset.mpKey || '').trim() || (e.currentTarget.dataset.appId || '').trim()
// 旧格式(<a href>tagType 为空 → 按 label 从缓存 linkTags 补充类型信息
if (!tagType && label) {
@@ -483,6 +485,7 @@ Page({
tagType = cached.type || 'url'
pagePath = cached.pagePath || ''
if (!url) url = cached.url || ''
if (cached.mpKey) mpKey = cached.mpKey
}
}
@@ -493,6 +496,28 @@ Page({
return
}
// 小程序类型:用密钥查 linkedMiniprograms 得 appId再唤醒需在 app.json 的 navigateToMiniProgramAppIdList 中配置)
if (tagType === 'miniprogram') {
if (!mpKey && label) {
const cached = (app.globalData.linkTagsConfig || []).find(t => t.label === label)
if (cached) mpKey = cached.mpKey || cached.appId || ''
}
const linked = (app.globalData.linkedMiniprograms || []).find(m => (m.key || m.id) === mpKey)
if (linked && linked.appId) {
wx.navigateToMiniProgram({
appId: linked.appId,
path: pagePath || linked.path || '',
envVersion: 'release',
success: () => {},
fail: (err) => {
wx.showToast({ title: err.errMsg || '跳转失败', icon: 'none' })
},
})
return
}
if (mpKey) wx.showToast({ title: '未找到关联小程序配置', icon: 'none' })
}
// 小程序内部路径pagePath 或 url 以 /pages/ 开头)
const internalPath = pagePath || (url.startsWith('/pages/') ? url : '')
if (internalPath) {