|
|
@@ -63,13 +63,18 @@ function App() {
|
|
|
}
|
|
|
}, []);
|
|
|
|
|
|
- const handleConfigPermission = useCallback(async () => {
|
|
|
+ const handleConfigPermission = useCallback(async (token: string) => {
|
|
|
try {
|
|
|
console.log('开始配置权限...');
|
|
|
console.log('当前URL:', window.location.href);
|
|
|
|
|
|
const currentUrl = window.location.href.split('#')[0];
|
|
|
- const response = await fetch(`https://openapi.julefood.cn:8082/api/sys_user/jsapi/config?url=${encodeURIComponent(currentUrl)}`);
|
|
|
+ const response = await fetch(`https://openapi.julefood.cn:8082/api/sys_user/jsapi/config?url=${encodeURIComponent(currentUrl)}`, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${token}`,
|
|
|
+ 'token': token
|
|
|
+ }
|
|
|
+ });
|
|
|
const config = await response.json();
|
|
|
|
|
|
console.log('服务器返回配置:', config);
|
|
|
@@ -95,8 +100,6 @@ function App() {
|
|
|
|
|
|
const handleAutoLogin = useCallback(async () => {
|
|
|
try {
|
|
|
- await handleConfigPermission();
|
|
|
-
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
const corpId = urlParams.get('corpId') || '';
|
|
|
const authResult = await Dingdocs.base.host.getAuthCode(corpId);
|
|
|
@@ -105,6 +108,11 @@ function App() {
|
|
|
const user = await Dingdocs.script.run('login', authCode);
|
|
|
setUserInfo(user);
|
|
|
console.log('自动登录成功:', user);
|
|
|
+
|
|
|
+ const token = await Dingdocs.script.run('getToken');
|
|
|
+ console.log('获取到token:', token);
|
|
|
+
|
|
|
+ await handleConfigPermission(token);
|
|
|
} catch (error: any) {
|
|
|
console.error('自动登录失败:', error);
|
|
|
setError(error.message || '登录失败');
|