feature/ui:1.0 feature,like mcp price method support use token and set more config about home page
This commit is contained in:
1 parent
2262a7f49a
commit
8946be619d
69 files changed
+4189
-1021
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
import {
|
||||
EmbeddedHtmlConfig,
|
||||
FaqItem,
|
||||
TopNavigationItem,
|
||||
} from "@/shared/types/system";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export interface HomepageConfig {
|
||||
faq: FaqItem[];
|
||||
top_navigation: TopNavigationItem[];
|
||||
embeded_html: EmbeddedHtmlConfig;
|
||||
}
|
||||
|
||||
export class HomepageConfigService {
|
||||
// get homepage config
|
||||
async getHomepageConfig(): Promise<HomepageConfig> {
|
||||
const response = await fetchAdminAPI<HomepageConfig>(
|
||||
"/api/sysconfig/homepage",
|
||||
{
|
||||
method: "GET",
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(
|
||||
response.error_message || "Failed to fetch homepage config"
|
||||
);
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// update homepage config
|
||||
async updateHomepageConfig(config: {
|
||||
faq?: FaqItem[];
|
||||
top_navigation?: TopNavigationItem[];
|
||||
embeded_html?: EmbeddedHtmlConfig;
|
||||
}): Promise<boolean> {
|
||||
const response = await fetchAdminAPI("/api/sysconfig/homepage", {
|
||||
method: "PUT",
|
||||
body: config as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
toast.error(
|
||||
response.error_message || i18n.t("Failed to update homepage config")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("Homepage config updated successfully"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export const homepageConfigService = new HomepageConfigService();
|
||||
@@ -1,5 +1,7 @@
|
||||
import {
|
||||
StripeConfig,
|
||||
AlipayConfig,
|
||||
WechatConfig,
|
||||
PaymentChannelApiItem,
|
||||
PaymentChannelListResponse,
|
||||
PaymentChannelTestResult,
|
||||
@@ -52,50 +54,74 @@ export class PaymentChannelService {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// Save Stripe configuration
|
||||
async saveStripeConfig(config: StripeConfig): Promise<boolean> {
|
||||
const response = await fetchAdminAPI<StripeConfig>(
|
||||
"/api/payment_channel/info",
|
||||
{
|
||||
method: "PUT",
|
||||
body: {
|
||||
id: "stripe",
|
||||
config: config,
|
||||
} as unknown as BodyInit,
|
||||
}
|
||||
);
|
||||
// Generic method to save payment channel configuration
|
||||
async savePaymentChannelConfig<T>(
|
||||
channelId: string,
|
||||
config: T,
|
||||
channelName: string
|
||||
): Promise<boolean> {
|
||||
const response = await fetchAdminAPI<T>("/api/payment_channel/info", {
|
||||
method: "PUT",
|
||||
body: {
|
||||
id: channelId,
|
||||
config: {
|
||||
...config,
|
||||
is_enabled: undefined,
|
||||
},
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
toast.error(
|
||||
response.error_message || i18n.t("Failed to save Stripe config")
|
||||
response.error_message ||
|
||||
i18n.t("Failed to save {{channelName}} config", { channelName })
|
||||
);
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("Stripe config saved successfully"));
|
||||
toast.success(
|
||||
i18n.t("{{channelName}} config saved successfully", { channelName })
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Test Stripe connection
|
||||
async testStripeConnection(
|
||||
config: StripeConfig
|
||||
// Save Stripe configuration
|
||||
async saveStripeConfig(config: StripeConfig): Promise<boolean> {
|
||||
return this.savePaymentChannelConfig("stripe", config, "Stripe");
|
||||
}
|
||||
|
||||
// Generic method to test payment channel connection
|
||||
async testPaymentChannelConnection<T>(
|
||||
channelId: string,
|
||||
config: T,
|
||||
channelName: string
|
||||
): Promise<PaymentChannelTestResult> {
|
||||
try {
|
||||
const response = await fetchAdminAPI<any>("/api/payment_channel/info", {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(config),
|
||||
const response = await fetchAdminAPI<any>("/api/payment_channel/test", {
|
||||
method: "POST",
|
||||
body: {
|
||||
id: channelId,
|
||||
config: {
|
||||
...config,
|
||||
is_enabled: undefined,
|
||||
},
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
return {
|
||||
success: false,
|
||||
message: response.error_message || "Stripe connection test failed",
|
||||
message:
|
||||
response.error_message ||
|
||||
i18n.t("{{channelName}} connection test failed", { channelName }),
|
||||
details: response.data,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Stripe connection test successful",
|
||||
message: i18n.t("{{channelName}} connection test successful", {
|
||||
channelName,
|
||||
}),
|
||||
details: response.data,
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -106,36 +132,73 @@ export class PaymentChannelService {
|
||||
}
|
||||
}
|
||||
|
||||
// Test Stripe connection
|
||||
async testStripeConnection(
|
||||
config: StripeConfig
|
||||
): Promise<PaymentChannelTestResult> {
|
||||
return this.testPaymentChannelConnection("stripe", config, "Stripe");
|
||||
}
|
||||
|
||||
// enable payment channel
|
||||
async enablePaymentChannel(id: string): Promise<void> {
|
||||
async enablePaymentChannel(id: string): Promise<boolean> {
|
||||
const response = await fetchAdminAPI("/api/payment_channel/enable", {
|
||||
method: "POST",
|
||||
method: "PUT",
|
||||
body: {
|
||||
id,
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(
|
||||
response.error_message || "Failed to enable payment channel"
|
||||
toast.error(
|
||||
response.error_message || i18n.t("Failed to enable payment channel")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("Payment channel enabled successfully"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// disable payment channel
|
||||
async disablePaymentChannel(id: string): Promise<void> {
|
||||
async disablePaymentChannel(id: string): Promise<boolean> {
|
||||
const response = await fetchAdminAPI("/api/payment_channel/disable", {
|
||||
method: "POST",
|
||||
method: "PUT",
|
||||
body: {
|
||||
id,
|
||||
} as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(
|
||||
response.error_message || "Failed to disable payment channel"
|
||||
toast.error(
|
||||
response.error_message || i18n.t("Failed to disable payment channel")
|
||||
);
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("Payment channel disabled successfully"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Save Alipay configuration
|
||||
async saveAlipayConfig(config: AlipayConfig): Promise<boolean> {
|
||||
return this.savePaymentChannelConfig("alipay", config, "Alipay");
|
||||
}
|
||||
|
||||
// Save WeChat configuration
|
||||
async saveWechatConfig(config: WechatConfig): Promise<boolean> {
|
||||
return this.savePaymentChannelConfig("wechat", config, "WeChat");
|
||||
}
|
||||
|
||||
// Test Alipay connection
|
||||
async testAlipayConnection(
|
||||
config: AlipayConfig
|
||||
): Promise<PaymentChannelTestResult> {
|
||||
return this.testPaymentChannelConnection("alipay", config, "Alipay");
|
||||
}
|
||||
|
||||
// Test WeChat connection
|
||||
async testWechatConnection(
|
||||
config: WechatConfig
|
||||
): Promise<PaymentChannelTestResult> {
|
||||
return this.testPaymentChannelConnection("wechat", config, "WeChat");
|
||||
}
|
||||
|
||||
// validate stripe config
|
||||
|
||||
@@ -37,10 +37,26 @@ export class PlatformConfigService {
|
||||
console.error(response.error_message);
|
||||
return {
|
||||
platform: _DefaultPlatformConfig,
|
||||
login: undefined,
|
||||
faq: [],
|
||||
top_navigation: [],
|
||||
embeded_html: undefined,
|
||||
payment_channels: [],
|
||||
is_installed: false,
|
||||
};
|
||||
}
|
||||
|
||||
return response.data;
|
||||
// 确保返回的数据结构正确
|
||||
const data = response.data;
|
||||
return {
|
||||
platform: data.platform || _DefaultPlatformConfig,
|
||||
login: data.login,
|
||||
faq: data.faq || [],
|
||||
top_navigation: data.top_navigation || [],
|
||||
embeded_html: data.embeded_html,
|
||||
payment_channels: data.payment_channels || [],
|
||||
is_installed: data.is_installed || false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
import { PlatformConfig, LoginConfig } from "@/shared/types/system";
|
||||
import {
|
||||
PlatformConfig,
|
||||
LoginConfig,
|
||||
FaqItem,
|
||||
TopNavigationItem,
|
||||
EmbeddedHtmlConfig,
|
||||
PaymentChannel
|
||||
} from "@/shared/types/system";
|
||||
import { AdminConfig, EmailConfig, SystemConfigApiData } from "@/types/system";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
@@ -29,8 +36,13 @@ export class SystemConfigService {
|
||||
account?: AdminConfig;
|
||||
email?: EmailConfig;
|
||||
login?: LoginConfig;
|
||||
faq?: FaqItem[];
|
||||
top_navigation?: TopNavigationItem[];
|
||||
embeded_html?: EmbeddedHtmlConfig;
|
||||
payment_channels?: PaymentChannel[];
|
||||
is_installed?: boolean;
|
||||
},
|
||||
key?: "theme" | "about"
|
||||
key?: "theme" | "about" | "faq" | "navigation" | "embedded_html" | "payment"
|
||||
): Promise<boolean> {
|
||||
const response = await fetchAdminAPI("/api/sysconfig/info", {
|
||||
method: "PUT",
|
||||
@@ -50,6 +62,18 @@ export class SystemConfigService {
|
||||
case "about":
|
||||
toast.success(i18n.t("About page saved successfully"));
|
||||
break;
|
||||
case "faq":
|
||||
toast.success(i18n.t("FAQ updated successfully"));
|
||||
break;
|
||||
case "navigation":
|
||||
toast.success(i18n.t("Navigation updated successfully"));
|
||||
break;
|
||||
case "embedded_html":
|
||||
toast.success(i18n.t("Embedded HTML updated successfully"));
|
||||
break;
|
||||
case "payment":
|
||||
toast.success(i18n.t("Payment channels updated successfully"));
|
||||
break;
|
||||
default: {
|
||||
toast.success(i18n.t("System config updated successfully"));
|
||||
break;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { User } from "@/types/user";
|
||||
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||
import toast from "react-hot-toast";
|
||||
import i18n from "@/shared/lib/i18n";
|
||||
import { md5Encrypt, sha256Encrypt } from "@/shared/utils/crypto";
|
||||
|
||||
// user list API response interface (according to API document xpack-response-array format)
|
||||
export interface UserListApiResponse extends ApiArrayResponse<User> {}
|
||||
@@ -63,3 +64,42 @@ export const deleteUser = async (userId: string): Promise<boolean> => {
|
||||
toast.success(i18n.t("User deleted successfully"));
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* recharge user balance
|
||||
*/
|
||||
export const rechargeUser = async (
|
||||
userId: string,
|
||||
amount: number
|
||||
): Promise<boolean> => {
|
||||
// Create request body
|
||||
const body = {
|
||||
user_id: userId,
|
||||
balance: amount,
|
||||
type: "incr",
|
||||
};
|
||||
|
||||
// Generate timestamp
|
||||
const timestamp = Date.now().toString();
|
||||
|
||||
// Generate signature: sha256(md5((x-xpack-timestamp){body}))
|
||||
// For this implementation, we're using a simplified approach
|
||||
// In a real implementation, you would use actual crypto functions
|
||||
const bodyString = JSON.stringify(body);
|
||||
const signature = sha256Encrypt(md5Encrypt(`${timestamp}${bodyString}`));
|
||||
const response = await fetchAdminAPI(`/api/user_manager/balance/recharge`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"x-xpack-timestamp": timestamp,
|
||||
"x-xpack-sign": signature,
|
||||
},
|
||||
body: body as unknown as BodyInit,
|
||||
});
|
||||
|
||||
if (!response.success) {
|
||||
toast.error(response.error_message || i18n.t("Failed to recharge user"));
|
||||
return false;
|
||||
}
|
||||
toast.success(i18n.t("User recharged successfully"));
|
||||
return true;
|
||||
};
|
||||
Reference in new issue
Block a user