|
120 | 120 | luckyous_domain: "", |
121 | 121 | luckyous_variant_mode: "", |
122 | 122 | luckyous_specified_email: "", |
| 123 | + graph_accounts_mode: "file", |
123 | 124 | graph_accounts_file: "", |
| 125 | + graph_api_base_url: "", |
| 126 | + graph_api_token: "", |
124 | 127 | graph_tenant: "common", |
125 | 128 | graph_fetch_mode: "graph_api", |
126 | 129 | graph_pre_refresh_before_run: true, |
|
364 | 367 | mailRows: [], |
365 | 368 | mailTotal: 0 |
366 | 369 | }, |
| 370 | + luckyous: { |
| 371 | + domains: [], |
| 372 | + mailboxRows: [], |
| 373 | + selectedMailbox: "", |
| 374 | + mailRows: [], |
| 375 | + mailTotal: 0 |
| 376 | + }, |
367 | 377 | graph: { |
368 | 378 | domains: [], |
369 | 379 | mailboxRows: [], |
|
1009 | 1019 | { label: "IMAP XOAUTH2 取件", value: "imap_xoauth2" } |
1010 | 1020 | ]; |
1011 | 1021 |
|
| 1022 | + const graphAccountSourceOptions = [ |
| 1023 | + { label: "文件模式", value: "file" }, |
| 1024 | + { label: "接口模式", value: "api" } |
| 1025 | + ]; |
| 1026 | + |
| 1027 | + function normalizeGraphAccountsMode(raw) { |
| 1028 | + const val = String(raw || "file").trim().toLowerCase(); |
| 1029 | + if (["api", "http", "interface", "openapi", "open_api", "remote"].includes(val)) { |
| 1030 | + return "api"; |
| 1031 | + } |
| 1032 | + return "file"; |
| 1033 | + } |
| 1034 | + |
1012 | 1035 | const remoteAccountProviderOptions = [ |
1013 | 1036 | { label: "Sub2API", value: "sub2api" }, |
1014 | 1037 | { label: "CLIProxyAPI", value: "cliproxyapi" } |
|
1536 | 1559 | settingsForm.luckyous_domain = String(cfg.luckyous_domain || ""); |
1537 | 1560 | settingsForm.luckyous_variant_mode = String(cfg.luckyous_variant_mode || ""); |
1538 | 1561 | settingsForm.luckyous_specified_email = String(cfg.luckyous_specified_email || ""); |
| 1562 | + settingsForm.graph_accounts_mode = normalizeGraphAccountsMode(cfg.graph_accounts_mode || "file"); |
1539 | 1563 | settingsForm.graph_accounts_file = String(cfg.graph_accounts_file || ""); |
| 1564 | + settingsForm.graph_api_base_url = String(cfg.graph_api_base_url || ""); |
| 1565 | + settingsForm.graph_api_token = String(cfg.graph_api_token || ""); |
1540 | 1566 | settingsForm.graph_tenant = String(cfg.graph_tenant || "common"); |
1541 | 1567 | settingsForm.graph_fetch_mode = String(cfg.graph_fetch_mode || "graph_api"); |
1542 | 1568 | settingsForm.graph_pre_refresh_before_run = cfg.graph_pre_refresh_before_run !== false; |
|
1634 | 1660 | luckyous_domain: String(settingsForm.luckyous_domain || "").trim(), |
1635 | 1661 | luckyous_variant_mode: String(settingsForm.luckyous_variant_mode || "").trim(), |
1636 | 1662 | luckyous_specified_email: String(settingsForm.luckyous_specified_email || "").trim(), |
| 1663 | + graph_accounts_mode: normalizeGraphAccountsMode(settingsForm.graph_accounts_mode || "file"), |
1637 | 1664 | graph_accounts_file: String(settingsForm.graph_accounts_file || "").trim(), |
| 1665 | + graph_api_base_url: String(settingsForm.graph_api_base_url || "").trim(), |
| 1666 | + graph_api_token: String(settingsForm.graph_api_token || "").trim(), |
1638 | 1667 | graph_tenant: String(settingsForm.graph_tenant || "common").trim(), |
1639 | 1668 | graph_fetch_mode: String(settingsForm.graph_fetch_mode || "graph_api").trim(), |
1640 | 1669 | graph_pre_refresh_before_run: !!settingsForm.graph_pre_refresh_before_run, |
|
2766 | 2795 |
|
2767 | 2796 | function snapshotMailViewToCache() { |
2768 | 2797 | const key = currentMailProviderKey(); |
2769 | | - const target = mailViewCache[key]; |
| 2798 | + const target = mailViewCache[key] || { |
| 2799 | + domains: [], |
| 2800 | + mailboxRows: [], |
| 2801 | + selectedMailbox: "", |
| 2802 | + mailRows: [], |
| 2803 | + mailTotal: 0 |
| 2804 | + }; |
| 2805 | + if (!mailViewCache[key]) { |
| 2806 | + mailViewCache[key] = target; |
| 2807 | + } |
2770 | 2808 | target.domains = Array.isArray(mailDomains.value) ? [...mailDomains.value] : []; |
2771 | 2809 | target.mailboxRows = Array.isArray(mailboxRows.value) |
2772 | 2810 | ? mailboxRows.value.map((x) => Object.assign({}, x)) |
|
2780 | 2818 |
|
2781 | 2819 | function restoreMailViewFromCache(provider) { |
2782 | 2820 | const key = normalizeMailProvider(provider || "mailfree"); |
2783 | | - const source = mailViewCache[key]; |
| 2821 | + const source = mailViewCache[key] || { |
| 2822 | + domains: [], |
| 2823 | + mailboxRows: [], |
| 2824 | + selectedMailbox: "", |
| 2825 | + mailRows: [], |
| 2826 | + mailTotal: 0 |
| 2827 | + }; |
| 2828 | + if (!mailViewCache[key]) { |
| 2829 | + mailViewCache[key] = source; |
| 2830 | + } |
2784 | 2831 | mailDomains.value = Array.isArray(source.domains) ? [...source.domains] : []; |
2785 | 2832 | mailboxRows.value = Array.isArray(source.mailboxRows) |
2786 | 2833 | ? source.mailboxRows.map((x) => Object.assign({}, x)) |
|
2897 | 2944 | } |
2898 | 2945 |
|
2899 | 2946 | async function refreshGraphAccountFiles(showError = false) { |
| 2947 | + if (normalizeGraphAccountsMode(settingsForm.graph_accounts_mode) !== "file") { |
| 2948 | + graphAccountFileOptions.value = []; |
| 2949 | + return; |
| 2950 | + } |
2900 | 2951 | loading.graph_files = true; |
2901 | 2952 | try { |
2902 | 2953 | const data = await apiRequest("/api/mail/graph-account-files"); |
|
2915 | 2966 | } |
2916 | 2967 |
|
2917 | 2968 | function pickGraphAccountFile() { |
| 2969 | + if (normalizeGraphAccountsMode(settingsForm.graph_accounts_mode) !== "file") { |
| 2970 | + message.warning("接口模式无需选择账号文件"); |
| 2971 | + return; |
| 2972 | + } |
2918 | 2973 | const el = graphFileInputRef.value; |
2919 | 2974 | if (!el) { |
2920 | 2975 | message.error("文件选择器不可用"); |
|
2925 | 2980 | } |
2926 | 2981 |
|
2927 | 2982 | async function onGraphAccountFilePicked(e) { |
| 2983 | + if (normalizeGraphAccountsMode(settingsForm.graph_accounts_mode) !== "file") { |
| 2984 | + return; |
| 2985 | + } |
2928 | 2986 | const files = (e && e.target && e.target.files) ? e.target.files : null; |
2929 | 2987 | if (!files || !files.length) return; |
2930 | 2988 | const file = files[0]; |
|
2954 | 3012 | } |
2955 | 3013 |
|
2956 | 3014 | async function deleteSelectedGraphAccountFile() { |
| 3015 | + if (normalizeGraphAccountsMode(settingsForm.graph_accounts_mode) !== "file") { |
| 3016 | + message.warning("接口模式没有本地账号文件可删除"); |
| 3017 | + return; |
| 3018 | + } |
2957 | 3019 | const target = String(settingsForm.graph_accounts_file || "").trim(); |
2958 | 3020 | if (!target) { |
2959 | 3021 | message.warning("请先选择要删除的 Graph 账号文件"); |
|
2987 | 3049 | mailfreePanelTab.value = "basic"; |
2988 | 3050 | } |
2989 | 3051 | restoreMailViewFromCache(mailProviderTab.value); |
2990 | | - if (mailProviderTab.value === "graph") { |
| 3052 | + if (mailProviderTab.value === "graph" && normalizeGraphAccountsMode(settingsForm.graph_accounts_mode) === "file") { |
2991 | 3053 | refreshGraphAccountFiles(false); |
2992 | 3054 | } |
2993 | 3055 | if (mailProviderTab.value === "mailfree" && mailfreePanelTab.value === "domain") { |
|
3823 | 3885 | return; |
3824 | 3886 | } |
3825 | 3887 | if (tab === "mail") { |
3826 | | - if (normalizeMailProvider(mailProviderTab.value) === "graph") { |
| 3888 | + if ( |
| 3889 | + normalizeMailProvider(mailProviderTab.value) === "graph" |
| 3890 | + && normalizeGraphAccountsMode(settingsForm.graph_accounts_mode) === "file" |
| 3891 | + ) { |
3827 | 3892 | await refreshGraphAccountFiles(false); |
3828 | 3893 | } |
3829 | 3894 | await loadMailDomainStats(); |
|
3845 | 3910 | } |
3846 | 3911 | }); |
3847 | 3912 |
|
| 3913 | + Vue.watch( |
| 3914 | + () => normalizeGraphAccountsMode(settingsForm.graph_accounts_mode || "file"), |
| 3915 | + async (mode, oldMode) => { |
| 3916 | + if (mode === oldMode) return; |
| 3917 | + if (mode === "api") { |
| 3918 | + settingsForm.graph_fetch_mode = "graph_api"; |
| 3919 | + settingsForm.graph_pre_refresh_before_run = false; |
| 3920 | + graphAccountFileOptions.value = []; |
| 3921 | + return; |
| 3922 | + } |
| 3923 | + if (mailProviderTab.value === "graph") { |
| 3924 | + await refreshGraphAccountFiles(false); |
| 3925 | + } |
| 3926 | + } |
| 3927 | + ); |
| 3928 | + |
3848 | 3929 | Vue.watch( |
3849 | 3930 | () => String(settingsForm.hero_sms_service || "").trim(), |
3850 | 3931 | async (_val, _oldVal) => { |
|
3981 | 4062 | flclashProbeSummary, |
3982 | 4063 | flclashPolicyOptions, |
3983 | 4064 | graphFetchModeOptions, |
| 4065 | + graphAccountSourceOptions, |
3984 | 4066 | remoteAccountProviderOptions, |
3985 | 4067 | flclashProbeColumns, |
3986 | 4068 | jsonColumns, |
|
0 commit comments