|
@@ -5,6 +5,22 @@ import { initView } from 'dingtalk-docs-cool-app';
|
|
|
import { Typography, Button, Card, Select, Input, Spin } from 'dingtalk-design-desktop';
|
|
import { Typography, Button, Card, Select, Input, Spin } from 'dingtalk-design-desktop';
|
|
|
import './style.css';
|
|
import './style.css';
|
|
|
|
|
|
|
|
|
|
+const STORAGE_PREFIX = 'aiTablePlugin_';
|
|
|
|
|
+
|
|
|
|
|
+function saveData<T>(key: string, value: T) {
|
|
|
|
|
+ localStorage.setItem(STORAGE_PREFIX + key, JSON.stringify(value));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function loadData<T>(key: string, defaultValue: T): T {
|
|
|
|
|
+ const raw = localStorage.getItem(STORAGE_PREFIX + key);
|
|
|
|
|
+ if (raw === null) return defaultValue;
|
|
|
|
|
+ try {
|
|
|
|
|
+ return JSON.parse(raw) as T;
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return defaultValue;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
interface ApiParam {
|
|
interface ApiParam {
|
|
|
paramName: string;
|
|
paramName: string;
|
|
|
paramDesc: string;
|
|
paramDesc: string;
|
|
@@ -47,7 +63,7 @@ function App() {
|
|
|
const [apiParams, setApiParams] = useState<Record<string, string>>({});
|
|
const [apiParams, setApiParams] = useState<Record<string, string>>({});
|
|
|
const [result, setResult] = useState<string>('');
|
|
const [result, setResult] = useState<string>('');
|
|
|
const [callLoading, setCallLoading] = useState<boolean>(false);
|
|
const [callLoading, setCallLoading] = useState<boolean>(false);
|
|
|
- const [userInfo, setUserInfo] = useState<UserInfo | null>(null);
|
|
|
|
|
|
|
+ const [userInfo, setUserInfo] = useState<UserInfo | null>(loadData('userInfo', null));
|
|
|
const [error, setError] = useState<string>('');
|
|
const [error, setError] = useState<string>('');
|
|
|
const [customTableId, setCustomTableId] = useState<string>('');
|
|
const [customTableId, setCustomTableId] = useState<string>('');
|
|
|
const [customTableName, setCustomTableName] = useState<string>('');
|
|
const [customTableName, setCustomTableName] = useState<string>('');
|
|
@@ -106,6 +122,10 @@ function App() {
|
|
|
setUserInfo(user);
|
|
setUserInfo(user);
|
|
|
|
|
|
|
|
const token = await Dingdocs.script.run('getToken');
|
|
const token = await Dingdocs.script.run('getToken');
|
|
|
|
|
+
|
|
|
|
|
+ saveData('token', token);
|
|
|
|
|
+ saveData('userInfo', user);
|
|
|
|
|
+
|
|
|
await handleConfigPermission(token);
|
|
await handleConfigPermission(token);
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
|
console.error('自动登录失败:', error);
|
|
console.error('自动登录失败:', error);
|