feat: 小程序跳转改用明文 URL Scheme
- UrlSchemeLauncher: 使用明文 Scheme 格式,无需后端 API 生成 - HomePage: 修复 path 格式,去掉开头斜杠以匹配小程序后台配置 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,9 +20,26 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { FiExternalLink, FiCopy, FiCheck } from 'react-icons/fi';
|
import { FiExternalLink, FiCopy, FiCheck } from 'react-icons/fi';
|
||||||
import { generateUrlScheme, openUrlScheme } from '@services/miniprogramService';
|
|
||||||
import { isIOSDevice } from './hooks/useWechatEnvironment';
|
import { isIOSDevice } from './hooks/useWechatEnvironment';
|
||||||
|
|
||||||
|
// 小程序 AppID
|
||||||
|
const MINIPROGRAM_APPID = 'wx0edeaab76d4fa414';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成明文 URL Scheme
|
||||||
|
* 格式:weixin://dl/business/?appid=APPID&path=PATH&query=QUERY
|
||||||
|
*/
|
||||||
|
const generatePlainUrlScheme = (path, query) => {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
appid: MINIPROGRAM_APPID,
|
||||||
|
path: path || '',
|
||||||
|
});
|
||||||
|
if (query) {
|
||||||
|
params.set('query', query);
|
||||||
|
}
|
||||||
|
return `weixin://dl/business/?${params.toString()}`;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL Scheme 跳转组件
|
* URL Scheme 跳转组件
|
||||||
* @param {Object} props
|
* @param {Object} props
|
||||||
@@ -54,17 +71,15 @@ const UrlSchemeLauncher = ({
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// 生成 URL Scheme
|
// 生成明文 URL Scheme(不需要后端 API)
|
||||||
const result = await generateUrlScheme({ path, query });
|
const scheme = generatePlainUrlScheme(path, query);
|
||||||
|
console.log('[UrlSchemeLauncher] 生成的 scheme:', scheme);
|
||||||
|
|
||||||
if (!result?.openlink) {
|
setOpenlink(scheme);
|
||||||
throw new Error('生成跳转链接失败');
|
|
||||||
}
|
|
||||||
|
|
||||||
setOpenlink(result.openlink);
|
|
||||||
|
|
||||||
// 尝试直接跳转
|
// 尝试直接跳转
|
||||||
const success = openUrlScheme(result.openlink);
|
window.location.href = scheme;
|
||||||
|
const success = true;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
onSuccess?.();
|
onSuccess?.();
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ const HomePage: React.FC = () => {
|
|||||||
zIndex={1000}
|
zIndex={1000}
|
||||||
>
|
>
|
||||||
<MiniProgramLauncher
|
<MiniProgramLauncher
|
||||||
path="/pages/index/index"
|
path="pages/index/index"
|
||||||
buttonStyle={{
|
buttonStyle={{
|
||||||
backgroundColor: '#07c160',
|
backgroundColor: '#07c160',
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
|
|||||||
Reference in New Issue
Block a user