功能迭代
This commit is contained in:
1 parent
d1844ce9a2
commit
617371be3e
13 files changed
+884
-138
No files matched your search
@@ -8,4 +8,5 @@ public record StoreProfileAdminReq(
|
|||||||
/** 站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode,
|
/** 站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode,
|
||||||
/** 店铺名称。 */ @NotBlank @Size(max = 100) String storeName,
|
/** 店铺名称。 */ @NotBlank @Size(max = 100) String storeName,
|
||||||
/** 店铺描述。 */ @Size(max = 1000) String description,
|
/** 店铺描述。 */ @Size(max = 1000) String description,
|
||||||
/** 店铺所属行业。 */ @NotBlank @Size(max = 100) String industry) {}
|
/** 店铺所属行业。 */ @NotBlank @Size(max = 100) String industry,
|
||||||
|
/** 店铺主域名,不含协议、端口和路径。 */ @Size(max = 255) String domain) {}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
package com.shoplix.admin.modules.store.res;
|
package com.shoplix.admin.modules.store.res;
|
||||||
|
|
||||||
/** 店铺基本信息响应。 */
|
/** 店铺基本信息响应。 */
|
||||||
public record StoreProfileAdminRes(String siteCode, String storeName, String description, String industry) {}
|
public record StoreProfileAdminRes(
|
||||||
|
/** 站点业务编号。 */ String siteCode,
|
||||||
|
/** 店铺名称。 */ String storeName,
|
||||||
|
/** 店铺描述。 */ String description,
|
||||||
|
/** 店铺所属行业。 */ String industry,
|
||||||
|
/** 店铺主域名。 */ String domain) {}
|
||||||
@@ -2,10 +2,20 @@ package com.shoplix.admin.service;
|
|||||||
|
|
||||||
import com.shoplix.admin.modules.store.req.StoreProfileAdminReq;
|
import com.shoplix.admin.modules.store.req.StoreProfileAdminReq;
|
||||||
import com.shoplix.admin.modules.store.res.StoreProfileAdminRes;
|
import com.shoplix.admin.modules.store.res.StoreProfileAdminRes;
|
||||||
|
import com.shoplix.admin.store.StoreMessageKeys;
|
||||||
import com.shoplix.common.exception.BusinessException;
|
import com.shoplix.common.exception.BusinessException;
|
||||||
import com.shoplix.modules.account.repository.entity.AdminUserEntity;
|
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||||
|
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||||
|
import com.shoplix.modules.site.enums.SiteDomainStatusEnum;
|
||||||
|
import com.shoplix.modules.site.repository.entity.SiteDomainEntity;
|
||||||
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
||||||
|
import com.shoplix.modules.site.repository.service.SiteDomainRepositoryService;
|
||||||
import com.shoplix.modules.site.repository.service.SiteRepositoryService;
|
import com.shoplix.modules.site.repository.service.SiteRepositoryService;
|
||||||
|
import java.net.IDN;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Locale;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -14,11 +24,19 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
public class AdminStoreService {
|
public class AdminStoreService {
|
||||||
private final SiteRepositoryService repository;
|
private final SiteRepositoryService repository;
|
||||||
private final AdminSiteAccessService accessService;
|
private final AdminSiteAccessService accessService;
|
||||||
|
private final SiteDomainRepositoryService domainRepository;
|
||||||
|
private final BusinessCodeUtils codes;
|
||||||
|
private final MessageSource messageSource;
|
||||||
|
|
||||||
/** 注入站点数据源。 */
|
/** 注入站点数据源。 */
|
||||||
public AdminStoreService(SiteRepositoryService repository, AdminSiteAccessService accessService) {
|
public AdminStoreService(SiteRepositoryService repository, AdminSiteAccessService accessService,
|
||||||
|
SiteDomainRepositoryService domainRepository, BusinessCodeUtils codes,
|
||||||
|
MessageSource messageSource) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.accessService = accessService;
|
this.accessService = accessService;
|
||||||
|
this.domainRepository = domainRepository;
|
||||||
|
this.codes = codes;
|
||||||
|
this.messageSource = messageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 查询店铺基本信息。 */
|
/** 查询店铺基本信息。 */
|
||||||
@@ -36,6 +54,7 @@ public class AdminStoreService {
|
|||||||
entity.setSiteDescription(request.description());
|
entity.setSiteDescription(request.description());
|
||||||
entity.setIndustry(request.industry().trim());
|
entity.setIndustry(request.industry().trim());
|
||||||
if (repository.updateProfile(entity) != 1) throw new BusinessException("STORE_PROFILE_UPDATE_FAILED", "店铺信息保存失败");
|
if (repository.updateProfile(entity) != 1) throw new BusinessException("STORE_PROFILE_UPDATE_FAILED", "店铺信息保存失败");
|
||||||
|
saveDomain(request.siteCode(), request.domain());
|
||||||
return toResponse(entity);
|
return toResponse(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +70,53 @@ public class AdminStoreService {
|
|||||||
|
|
||||||
/** 转换店铺信息响应。 */
|
/** 转换店铺信息响应。 */
|
||||||
private StoreProfileAdminRes toResponse(SiteEntity entity) {
|
private StoreProfileAdminRes toResponse(SiteEntity entity) {
|
||||||
return new StoreProfileAdminRes(entity.getSiteCode(), entity.getSiteName(), entity.getSiteDescription(), entity.getIndustry());
|
String domain = domainRepository.findPrimaryBySiteCode(entity.getSiteCode())
|
||||||
|
.map(SiteDomainEntity::getDomain).orElse("");
|
||||||
|
return new StoreProfileAdminRes(entity.getSiteCode(), entity.getSiteName(),
|
||||||
|
entity.getSiteDescription(), entity.getIndustry(), domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 保存规范化后的站点主域名。 */
|
||||||
|
private void saveDomain(String siteCode, String input) {
|
||||||
|
String domain = normalizeDomain(input);
|
||||||
|
if (domain.isBlank()) return;
|
||||||
|
if (domainRepository.existsByDomainExcludingSite(domain, siteCode)) {
|
||||||
|
throw exception("STORE_DOMAIN_EXISTS", StoreMessageKeys.DOMAIN_EXISTS);
|
||||||
|
}
|
||||||
|
SiteDomainEntity entity = domainRepository.findPrimaryBySiteCode(siteCode).orElseGet(() -> {
|
||||||
|
SiteDomainEntity created = new SiteDomainEntity();
|
||||||
|
created.setDomainCode(codes.generate(BusinessCodePrefixEnum.DOMAIN));
|
||||||
|
created.setSiteCode(siteCode);
|
||||||
|
created.setPrimaryFlag(1);
|
||||||
|
created.setForceHttps(1);
|
||||||
|
created.setStatus(SiteDomainStatusEnum.ENABLED.name());
|
||||||
|
created.setDeleted(0);
|
||||||
|
return created;
|
||||||
|
});
|
||||||
|
entity.setDomain(domain);
|
||||||
|
int rows = entity.getId() == null ? domainRepository.insert(entity) : domainRepository.updatePrimary(entity);
|
||||||
|
if (rows != 1) throw exception("STORE_DOMAIN_UPDATE_FAILED", StoreMessageKeys.DOMAIN_SAVE_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 将输入规范化为不含协议、端口和路径的 ASCII 小写域名。 */
|
||||||
|
private String normalizeDomain(String input) {
|
||||||
|
if (input == null || input.isBlank()) return "";
|
||||||
|
try {
|
||||||
|
String value = input.trim();
|
||||||
|
URI uri = URI.create(value.contains("://") ? value : "https://" + value);
|
||||||
|
String host = uri.getHost();
|
||||||
|
if (host == null || host.isBlank() || host.contains("_") || host.startsWith(".") || host.endsWith(".")) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
return IDN.toASCII(host).toLowerCase(Locale.ROOT);
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
throw exception("STORE_DOMAIN_INVALID", StoreMessageKeys.DOMAIN_INVALID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建已完成多语言解析的店铺业务异常。 */
|
||||||
|
private BusinessException exception(String code, String key) {
|
||||||
|
return new BusinessException(code,
|
||||||
|
messageSource.getMessage(key, null, LocaleContextHolder.getLocale()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.shoplix.admin.store;
|
||||||
|
|
||||||
|
/** 店铺信息多语言消息键。 */
|
||||||
|
public final class StoreMessageKeys {
|
||||||
|
/** 禁止实例化。 */ private StoreMessageKeys() { }
|
||||||
|
/** 域名已被其他店铺绑定。 */ public static final String DOMAIN_EXISTS = "store.domain.exists";
|
||||||
|
/** 域名保存失败。 */ public static final String DOMAIN_SAVE_FAILED = "store.domain.save-failed";
|
||||||
|
/** 域名格式错误。 */ public static final String DOMAIN_INVALID = "store.domain.invalid";
|
||||||
|
}
|
||||||
@@ -17,3 +17,6 @@ site.membership-create-failed=Failed to grant access to the new site.
|
|||||||
crm.customer.not-found=Customer not found
|
crm.customer.not-found=Customer not found
|
||||||
crm.customer.save-failed=Failed to save customer
|
crm.customer.save-failed=Failed to save customer
|
||||||
crm.tag.save-failed=Failed to save customer tag
|
crm.tag.save-failed=Failed to save customer tag
|
||||||
|
store.domain.exists=This domain is already bound to another store
|
||||||
|
store.domain.save-failed=Failed to save the store domain
|
||||||
|
store.domain.invalid=Enter a valid domain, for example www.example.com
|
||||||
@@ -17,3 +17,6 @@ site.membership-create-failed=新站点访问权限创建失败。
|
|||||||
crm.customer.not-found=客户不存在
|
crm.customer.not-found=客户不存在
|
||||||
crm.customer.save-failed=客户保存失败
|
crm.customer.save-failed=客户保存失败
|
||||||
crm.tag.save-failed=客户标签保存失败
|
crm.tag.save-failed=客户标签保存失败
|
||||||
|
store.domain.exists=该域名已绑定其他店铺
|
||||||
|
store.domain.save-failed=店铺域名保存失败
|
||||||
|
store.domain.invalid=请输入有效域名,例如 www.example.com
|
||||||
@@ -17,3 +17,6 @@ site.membership-create-failed=新站點存取權限建立失敗。
|
|||||||
crm.customer.not-found=客戶不存在
|
crm.customer.not-found=客戶不存在
|
||||||
crm.customer.save-failed=客戶儲存失敗
|
crm.customer.save-failed=客戶儲存失敗
|
||||||
crm.tag.save-failed=客戶標籤儲存失敗
|
crm.tag.save-failed=客戶標籤儲存失敗
|
||||||
|
store.domain.exists=該網域已綁定其他店鋪
|
||||||
|
store.domain.save-failed=店鋪網域儲存失敗
|
||||||
|
store.domain.invalid=請輸入有效網域,例如 www.example.com
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.shoplix.modules.site.enums;
|
||||||
|
|
||||||
|
/** 站点域名状态。 */
|
||||||
|
public enum SiteDomainStatusEnum {
|
||||||
|
/** 待验证。 */ PENDING,
|
||||||
|
/** 已启用。 */ ENABLED,
|
||||||
|
/** 已停用。 */ DISABLED
|
||||||
|
}
|
||||||
+16
@@ -16,11 +16,19 @@ public class SiteDomainEntity {
|
|||||||
private String siteCode;
|
private String siteCode;
|
||||||
/** 规范化后的域名。 */
|
/** 规范化后的域名。 */
|
||||||
private String domain;
|
private String domain;
|
||||||
|
/** 主域名标识:0否,1是。 */
|
||||||
|
private Integer primaryFlag;
|
||||||
|
/** 强制 HTTPS 标识:0否,1是。 */
|
||||||
|
private Integer forceHttps;
|
||||||
/** 域名启用状态。 */
|
/** 域名启用状态。 */
|
||||||
private String status;
|
private String status;
|
||||||
/** 逻辑删除状态:0未删除,1已删除。 */
|
/** 逻辑删除状态:0未删除,1已删除。 */
|
||||||
private Integer deleted;
|
private Integer deleted;
|
||||||
|
|
||||||
|
/** 获取数据库内部主键。 */
|
||||||
|
public Long getId() { return id; }
|
||||||
|
/** 设置数据库内部主键。 */
|
||||||
|
public void setId(Long id) { this.id = id; }
|
||||||
/** 获取域名业务编号。 */
|
/** 获取域名业务编号。 */
|
||||||
public String getDomainCode() { return domainCode; }
|
public String getDomainCode() { return domainCode; }
|
||||||
/** 设置域名业务编号。 */
|
/** 设置域名业务编号。 */
|
||||||
@@ -33,6 +41,14 @@ public class SiteDomainEntity {
|
|||||||
public String getDomain() { return domain; }
|
public String getDomain() { return domain; }
|
||||||
/** 设置域名。 */
|
/** 设置域名。 */
|
||||||
public void setDomain(String domain) { this.domain = domain; }
|
public void setDomain(String domain) { this.domain = domain; }
|
||||||
|
/** 获取主域名标识。 */
|
||||||
|
public Integer getPrimaryFlag() { return primaryFlag; }
|
||||||
|
/** 设置主域名标识。 */
|
||||||
|
public void setPrimaryFlag(Integer primaryFlag) { this.primaryFlag = primaryFlag; }
|
||||||
|
/** 获取强制 HTTPS 标识。 */
|
||||||
|
public Integer getForceHttps() { return forceHttps; }
|
||||||
|
/** 设置强制 HTTPS 标识。 */
|
||||||
|
public void setForceHttps(Integer forceHttps) { this.forceHttps = forceHttps; }
|
||||||
/** 获取域名状态。 */
|
/** 获取域名状态。 */
|
||||||
public String getStatus() { return status; }
|
public String getStatus() { return status; }
|
||||||
/** 设置域名状态。 */
|
/** 设置域名状态。 */
|
||||||
|
|||||||
+30
-2
@@ -7,11 +7,11 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import com.shoplix.modules.site.enums.SiteDomainStatusEnum;
|
||||||
|
|
||||||
/** 封装站点域名单表查询。 */
|
/** 封装站点域名单表查询。 */
|
||||||
@Service
|
@Service
|
||||||
public class SiteDomainRepositoryService {
|
public class SiteDomainRepositoryService {
|
||||||
private static final String ENABLED_STATUS = "ENABLED";
|
|
||||||
/** 站点域名 Mapper。 */
|
/** 站点域名 Mapper。 */
|
||||||
private final SiteDomainMapper mapper;
|
private final SiteDomainMapper mapper;
|
||||||
|
|
||||||
@@ -25,7 +25,35 @@ public class SiteDomainRepositoryService {
|
|||||||
String normalizedDomain = domain.toLowerCase(Locale.ROOT);
|
String normalizedDomain = domain.toLowerCase(Locale.ROOT);
|
||||||
return Optional.ofNullable(mapper.selectOne(Wrappers.<SiteDomainEntity>lambdaQuery()
|
return Optional.ofNullable(mapper.selectOne(Wrappers.<SiteDomainEntity>lambdaQuery()
|
||||||
.eq(SiteDomainEntity::getDomain, normalizedDomain)
|
.eq(SiteDomainEntity::getDomain, normalizedDomain)
|
||||||
.eq(SiteDomainEntity::getStatus, ENABLED_STATUS)
|
.eq(SiteDomainEntity::getStatus, SiteDomainStatusEnum.ENABLED.name())
|
||||||
.last("LIMIT 1")));
|
.last("LIMIT 1")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 查询站点主域名绑定。 */
|
||||||
|
public Optional<SiteDomainEntity> findPrimaryBySiteCode(String siteCode) {
|
||||||
|
return Optional.ofNullable(mapper.selectOne(Wrappers.<SiteDomainEntity>lambdaQuery()
|
||||||
|
.eq(SiteDomainEntity::getSiteCode, siteCode)
|
||||||
|
.eq(SiteDomainEntity::getPrimaryFlag, 1)
|
||||||
|
.eq(SiteDomainEntity::getDeleted, 0)
|
||||||
|
.last("LIMIT 1")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 判断域名是否已被其他站点绑定。 */
|
||||||
|
public boolean existsByDomainExcludingSite(String domain, String siteCode) {
|
||||||
|
return mapper.selectCount(Wrappers.<SiteDomainEntity>lambdaQuery()
|
||||||
|
.eq(SiteDomainEntity::getDomain, domain)
|
||||||
|
.ne(SiteDomainEntity::getSiteCode, siteCode)
|
||||||
|
.eq(SiteDomainEntity::getDeleted, 0)) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增站点域名绑定。 */
|
||||||
|
public int insert(SiteDomainEntity entity) { return mapper.insert(entity); }
|
||||||
|
|
||||||
|
/** 更新站点主域名绑定。 */
|
||||||
|
public int updatePrimary(SiteDomainEntity entity) {
|
||||||
|
return mapper.update(entity, Wrappers.<SiteDomainEntity>lambdaUpdate()
|
||||||
|
.eq(SiteDomainEntity::getDomainCode, entity.getDomainCode())
|
||||||
|
.eq(SiteDomainEntity::getSiteCode, entity.getSiteCode())
|
||||||
|
.eq(SiteDomainEntity::getDeleted, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+510
-50
@@ -1,71 +1,531 @@
|
|||||||
import { FormEvent, useEffect, useState } from "react";
|
import { FormEvent, useEffect, useState } from "react";
|
||||||
import { KeyRound, LogOut, Plus, Save, Share2, Store, Trash2, UserRound } from "lucide-react";
|
import {
|
||||||
|
KeyRound,
|
||||||
|
LogOut,
|
||||||
|
Plus,
|
||||||
|
Save,
|
||||||
|
Share2,
|
||||||
|
Store,
|
||||||
|
Trash2,
|
||||||
|
UserRound,
|
||||||
|
} from "lucide-react";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
import type { Account } from "./LoginPage";
|
import type { Account } from "./LoginPage";
|
||||||
import { getCurrentSiteCode } from "./siteContext";
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
type StoreProfile = { siteCode: string; storeName: string; description: string; industry: string };
|
type StoreProfile = {
|
||||||
type SocialChannel = { platform: string; displayName: string; profileUrl: string; shareEnabled: boolean; floatingEnabled: boolean; enabled: boolean; sortNo: number };
|
siteCode: string;
|
||||||
|
storeName: string;
|
||||||
|
description: string;
|
||||||
|
industry: string;
|
||||||
|
domain: string;
|
||||||
|
};
|
||||||
|
type SocialChannel = {
|
||||||
|
platform: string;
|
||||||
|
displayName: string;
|
||||||
|
profileUrl: string;
|
||||||
|
shareEnabled: boolean;
|
||||||
|
floatingEnabled: boolean;
|
||||||
|
enabled: boolean;
|
||||||
|
sortNo: number;
|
||||||
|
};
|
||||||
type SettingsTab = "store" | "account" | "social";
|
type SettingsTab = "store" | "account" | "social";
|
||||||
const SOCIAL_PLATFORMS = ["FACEBOOK", "X", "LINKEDIN", "YOUTUBE", "INSTAGRAM", "WHATSAPP", "PINTEREST", "TIKTOK", "LINE", "TUMBLR", "EMAIL"];
|
const SOCIAL_PLATFORMS = [
|
||||||
|
"FACEBOOK",
|
||||||
|
"X",
|
||||||
|
"LINKEDIN",
|
||||||
|
"YOUTUBE",
|
||||||
|
"INSTAGRAM",
|
||||||
|
"WHATSAPP",
|
||||||
|
"PINTEREST",
|
||||||
|
"TIKTOK",
|
||||||
|
"LINE",
|
||||||
|
"TUMBLR",
|
||||||
|
"EMAIL",
|
||||||
|
];
|
||||||
|
|
||||||
export default function SettingsPage({ account, onAccount, onLogout, tab }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void; tab: SettingsTab }) {
|
export default function SettingsPage({
|
||||||
|
account,
|
||||||
|
onAccount,
|
||||||
|
onLogout,
|
||||||
|
tab,
|
||||||
|
}: {
|
||||||
|
account: Account;
|
||||||
|
onAccount: (value: Account) => void;
|
||||||
|
onLogout: () => void;
|
||||||
|
tab: SettingsTab;
|
||||||
|
}) {
|
||||||
const siteCode = getCurrentSiteCode();
|
const siteCode = getCurrentSiteCode();
|
||||||
const [store, setStore] = useState<StoreProfile>({ siteCode, storeName: "", description: "", industry: "" });
|
const [store, setStore] = useState<StoreProfile>({
|
||||||
const [profile, setProfile] = useState({ username: account.username, displayName: account.displayName });
|
siteCode,
|
||||||
const [password, setPassword] = useState({ currentPassword: "", newPassword: "", confirmPassword: "" });
|
storeName: "",
|
||||||
|
description: "",
|
||||||
|
industry: "",
|
||||||
|
domain: "",
|
||||||
|
});
|
||||||
|
const [profile, setProfile] = useState({
|
||||||
|
username: account.username,
|
||||||
|
displayName: account.displayName,
|
||||||
|
});
|
||||||
|
const [password, setPassword] = useState({
|
||||||
|
currentPassword: "",
|
||||||
|
newPassword: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
});
|
||||||
const [socialChannels, setSocialChannels] = useState<SocialChannel[]>([]);
|
const [socialChannels, setSocialChannels] = useState<SocialChannel[]>([]);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
apiPost<StoreProfile>("/store/detail", { siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败"));
|
apiPost<StoreProfile>("/store/detail", { siteCode })
|
||||||
if (tab === "social") apiPost<{ items: SocialChannel[] }>("/social-channels/list", { siteCode }).then(data => setSocialChannels(data.items || [])).catch(cause => setError(cause instanceof Error ? cause.message : "社媒渠道加载失败"));
|
.then(setStore)
|
||||||
|
.catch((cause) =>
|
||||||
|
setError(cause instanceof Error ? cause.message : "加载失败"),
|
||||||
|
);
|
||||||
|
if (tab === "social")
|
||||||
|
apiPost<{ items: SocialChannel[] }>("/social-channels/list", { siteCode })
|
||||||
|
.then((data) => setSocialChannels(data.items || []))
|
||||||
|
.catch((cause) =>
|
||||||
|
setError(cause instanceof Error ? cause.message : "社媒渠道加载失败"),
|
||||||
|
);
|
||||||
}, [siteCode, tab]);
|
}, [siteCode, tab]);
|
||||||
const run = async (operation: () => Promise<void>, success: string) => { try { setError(""); setMessage(""); await operation(); setMessage(success); } catch (cause) { setError(cause instanceof Error ? cause.message : "操作失败"); } };
|
const run = async (operation: () => Promise<void>, success: string) => {
|
||||||
const saveStore = (event: FormEvent) => { event.preventDefault(); void run(async () => setStore(await apiPost("/store/save", store)), "店铺信息已保存"); };
|
try {
|
||||||
const saveProfile = (event: FormEvent) => { event.preventDefault(); void run(async () => onAccount(await apiPost("/auth/account", profile)), "账户资料已更新"); };
|
setError("");
|
||||||
const savePassword = (event: FormEvent) => { event.preventDefault(); void run(async () => { await apiPost("/auth/password", password); setPassword({ currentPassword: "", newPassword: "", confirmPassword: "" }); }, "密码已修改"); };
|
setMessage("");
|
||||||
const logout = () => void run(async () => { await apiPost("/auth/logout"); onLogout(); }, "");
|
await operation();
|
||||||
|
setMessage(success);
|
||||||
|
} catch (cause) {
|
||||||
|
setError(cause instanceof Error ? cause.message : "操作失败");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const saveStore = (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
void run(
|
||||||
|
async () => setStore(await apiPost("/store/save", store)),
|
||||||
|
"店铺信息已保存",
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const saveProfile = (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
void run(
|
||||||
|
async () => onAccount(await apiPost("/auth/account", profile)),
|
||||||
|
"账户资料已更新",
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const savePassword = (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
void run(async () => {
|
||||||
|
await apiPost("/auth/password", password);
|
||||||
|
setPassword({
|
||||||
|
currentPassword: "",
|
||||||
|
newPassword: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
});
|
||||||
|
}, "密码已修改");
|
||||||
|
};
|
||||||
|
const logout = () =>
|
||||||
|
void run(async () => {
|
||||||
|
await apiPost("/auth/logout");
|
||||||
|
onLogout();
|
||||||
|
}, "");
|
||||||
/** 新增一个尚未使用的平台渠道。 */
|
/** 新增一个尚未使用的平台渠道。 */
|
||||||
const addSocialChannel = () => {
|
const addSocialChannel = () => {
|
||||||
const platform = SOCIAL_PLATFORMS.find(item => !socialChannels.some(channel => channel.platform === item));
|
const platform = SOCIAL_PLATFORMS.find(
|
||||||
if (!platform) { setError("所有支持的社媒平台均已配置"); return; }
|
(item) => !socialChannels.some((channel) => channel.platform === item),
|
||||||
setSocialChannels([...socialChannels, { platform, displayName: platform === "X" ? "X" : platform.charAt(0) + platform.slice(1).toLowerCase(), profileUrl: "", shareEnabled: true, floatingEnabled: false, enabled: true, sortNo: (socialChannels.length + 1) * 10 }]);
|
);
|
||||||
|
if (!platform) {
|
||||||
|
setError("所有支持的社媒平台均已配置");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSocialChannels([
|
||||||
|
...socialChannels,
|
||||||
|
{
|
||||||
|
platform,
|
||||||
|
displayName:
|
||||||
|
platform === "X"
|
||||||
|
? "X"
|
||||||
|
: platform.charAt(0) + platform.slice(1).toLowerCase(),
|
||||||
|
profileUrl: "",
|
||||||
|
shareEnabled: true,
|
||||||
|
floatingEnabled: false,
|
||||||
|
enabled: true,
|
||||||
|
sortNo: (socialChannels.length + 1) * 10,
|
||||||
|
},
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
/** 更新指定社媒渠道。 */
|
/** 更新指定社媒渠道。 */
|
||||||
const updateSocialChannel = (index: number, patch: Partial<SocialChannel>) => setSocialChannels(current => current.map((item, itemIndex) => itemIndex === index ? { ...item, ...patch } : item));
|
const updateSocialChannel = (index: number, patch: Partial<SocialChannel>) =>
|
||||||
|
setSocialChannels((current) =>
|
||||||
|
current.map((item, itemIndex) =>
|
||||||
|
itemIndex === index ? { ...item, ...patch } : item,
|
||||||
|
),
|
||||||
|
);
|
||||||
/** 保存整组社媒渠道配置。 */
|
/** 保存整组社媒渠道配置。 */
|
||||||
const saveSocialChannels = (event: FormEvent) => { event.preventDefault(); void run(async () => { await apiPost("/social-channels/save", { siteCode, items: socialChannels }); }, "社媒渠道已保存"); };
|
const saveSocialChannels = (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
void run(async () => {
|
||||||
|
await apiPost("/social-channels/save", {
|
||||||
|
siteCode,
|
||||||
|
items: socialChannels,
|
||||||
|
});
|
||||||
|
}, "社媒渠道已保存");
|
||||||
|
};
|
||||||
|
|
||||||
const titles: Record<SettingsTab, [string, string]> = { store: ["店铺信息", "维护网站名称、行业和店铺介绍。"], account: ["账户与安全", "维护登录账户、显示名称和密码。"], social: ["社媒渠道", "配置产品分享入口和全站右侧悬浮联系渠道。"] };
|
const titles: Record<SettingsTab, [string, string]> = {
|
||||||
return <div className="account-settings">
|
store: ["店铺信息", "维护网站名称、行业和店铺介绍。"],
|
||||||
<header><div><h1>{titles[tab][0]}</h1><p>{titles[tab][1]}</p></div><button className="secondary" onClick={logout}><LogOut size={17}/>退出登录</button></header>
|
account: ["账户与安全", "维护登录账户、显示名称和密码。"],
|
||||||
{(message || error) && <div className={error ? "settings-message error" : "settings-message"}>{error || message}</div>}
|
social: ["社媒渠道", "配置产品分享入口和全站右侧悬浮联系渠道。"],
|
||||||
{tab === "store" && <div className="settings-layout">
|
};
|
||||||
<form className="profile-card" onSubmit={saveStore}><div className="profile-card-title"><Store/><div><h2>店铺信息</h2><p>用于运营后台识别当前网站和业务所属行业。</p></div></div><label><span>店铺名称</span><input required maxLength={100} value={store.storeName} onChange={event => setStore({ ...store, storeName: event.target.value })}/></label><label><span>所属行业</span><input required maxLength={100} value={store.industry} onChange={event => setStore({ ...store, industry: event.target.value })} placeholder="例如:工业设备"/></label><label className="wide"><span>店铺描述</span><textarea rows={5} maxLength={1000} value={store.description || ""} onChange={event => setStore({ ...store, description: event.target.value })}/></label><div className="profile-actions"><button className="primary"><Save size={17}/>保存店铺信息</button></div></form>
|
return (
|
||||||
</div>}
|
<div className="account-settings">
|
||||||
{tab === "account" && <div className="settings-layout settings-account-layout">
|
<header>
|
||||||
<div className="settings-side">
|
<div>
|
||||||
<form className="profile-card" onSubmit={saveProfile}><div className="profile-card-title"><UserRound/><div><h2>账户资料</h2><p>账户名用于登录,显示名称用于后台识别。</p></div></div><label><span>登录账户</span><input required minLength={4} maxLength={50} value={profile.username} onChange={event => setProfile({ ...profile, username: event.target.value })}/></label><label><span>显示名称</span><input required maxLength={50} value={profile.displayName} onChange={event => setProfile({ ...profile, displayName: event.target.value })}/></label><div className="profile-actions"><button className="primary"><Save size={17}/>保存账户资料</button></div></form>
|
<h1>{titles[tab][0]}</h1>
|
||||||
<form className="profile-card" onSubmit={savePassword}><div className="profile-card-title"><KeyRound/><div><h2>修改密码</h2><p>新密码需与当前密码不同。</p></div></div><label><span>当前密码</span><input required type="password" autoComplete="current-password" value={password.currentPassword} onChange={event => setPassword({ ...password, currentPassword: event.target.value })}/></label><label><span>新密码</span><input required type="password" minLength={8} maxLength={64} autoComplete="new-password" value={password.newPassword} onChange={event => setPassword({ ...password, newPassword: event.target.value })}/></label><label><span>确认新密码</span><input required type="password" minLength={8} maxLength={64} autoComplete="new-password" value={password.confirmPassword} onChange={event => setPassword({ ...password, confirmPassword: event.target.value })}/></label><div className="profile-actions"><button className="primary"><KeyRound size={17}/>修改密码</button></div></form>
|
<p>{titles[tab][1]}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>}
|
<button className="secondary" onClick={logout}>
|
||||||
{tab === "social" && <form className="profile-card social-settings-card" onSubmit={saveSocialChannels}>
|
<LogOut size={17} />
|
||||||
<div className="profile-card-title"><Share2/><div><h2>社媒渠道</h2><p>配置产品分享入口和全站右侧悬浮联系渠道。</p></div><button type="button" className="social-add" onClick={addSocialChannel}><Plus size={16}/>添加渠道</button></div>
|
退出登录
|
||||||
<div className="social-channel-head"><span>平台</span><span>展示名称</span><span>主页或联系地址</span><span>展示位置</span><span>排序</span><span>操作</span></div>
|
</button>
|
||||||
<div className="social-channel-list">
|
</header>
|
||||||
{socialChannels.length === 0 && <div className="social-channel-empty">尚未配置社媒渠道</div>}
|
{(message || error) && (
|
||||||
{socialChannels.map((channel, index) => <div className="social-channel-row" key={`${channel.platform}-${index}`}>
|
<div className={error ? "settings-message error" : "settings-message"}>
|
||||||
<select value={channel.platform} onChange={event => updateSocialChannel(index, { platform: event.target.value })}>{SOCIAL_PLATFORMS.map(platform => <option key={platform} value={platform} disabled={socialChannels.some((item, itemIndex) => itemIndex !== index && item.platform === platform)}>{platform}</option>)}</select>
|
{error || message}
|
||||||
<input required maxLength={100} value={channel.displayName} onChange={event => updateSocialChannel(index, { displayName: event.target.value })}/>
|
</div>
|
||||||
<input required maxLength={1000} type={channel.platform === "EMAIL" ? "email" : "url"} placeholder={channel.platform === "EMAIL" ? "sales@example.com" : "https://..."} value={channel.profileUrl} onChange={event => updateSocialChannel(index, { profileUrl: event.target.value })}/>
|
)}
|
||||||
<div className="social-channel-flags"><label><input type="checkbox" checked={channel.shareEnabled} onChange={event => updateSocialChannel(index, { shareEnabled: event.target.checked })}/>产品分享</label><label><input type="checkbox" checked={channel.floatingEnabled} onChange={event => updateSocialChannel(index, { floatingEnabled: event.target.checked })}/>右侧悬浮</label><label><input type="checkbox" checked={channel.enabled} onChange={event => updateSocialChannel(index, { enabled: event.target.checked })}/>启用</label></div>
|
{tab === "store" && (
|
||||||
<input className="social-sort" type="number" min={0} max={9999} value={channel.sortNo} onChange={event => updateSocialChannel(index, { sortNo: Number(event.target.value) })}/>
|
<div className="settings-layout">
|
||||||
<button type="button" className="social-delete" title="删除渠道" onClick={() => setSocialChannels(current => current.filter((_, itemIndex) => itemIndex !== index))}><Trash2 size={17}/></button>
|
<form className="profile-card" onSubmit={saveStore}>
|
||||||
</div>)}
|
<div className="profile-card-title">
|
||||||
</div>
|
<Store />
|
||||||
<div className="profile-actions"><button className="primary"><Save size={17}/>保存社媒渠道</button></div>
|
<div>
|
||||||
</form>}
|
<h2>店铺信息</h2>
|
||||||
</div>;
|
<p>用于运营后台识别当前网站和业务所属行业。</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label>
|
||||||
|
<span>店铺名称</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
maxLength={100}
|
||||||
|
value={store.storeName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setStore({ ...store, storeName: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>所属行业</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
maxLength={100}
|
||||||
|
value={store.industry}
|
||||||
|
onChange={(event) =>
|
||||||
|
setStore({ ...store, industry: event.target.value })
|
||||||
|
}
|
||||||
|
placeholder="例如:工业设备"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="wide">
|
||||||
|
<span>店铺域名</span>
|
||||||
|
<input
|
||||||
|
maxLength={255}
|
||||||
|
value={store.domain || ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setStore({ ...store, domain: event.target.value })
|
||||||
|
}
|
||||||
|
placeholder="www.example.com"
|
||||||
|
/>
|
||||||
|
{store.domain && (
|
||||||
|
<small className="store-domain-preview">
|
||||||
|
访问地址:https://{store.domain.replace(/^https?:\/\//, "")}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</label>
|
||||||
|
<label className="wide">
|
||||||
|
<span>店铺描述</span>
|
||||||
|
<textarea
|
||||||
|
rows={5}
|
||||||
|
maxLength={1000}
|
||||||
|
value={store.description || ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
setStore({ ...store, description: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<div className="profile-actions">
|
||||||
|
<button className="primary">
|
||||||
|
<Save size={17} />
|
||||||
|
保存店铺信息
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{tab === "account" && (
|
||||||
|
<div className="settings-layout settings-account-layout">
|
||||||
|
<div className="settings-side">
|
||||||
|
<form className="profile-card" onSubmit={saveProfile}>
|
||||||
|
<div className="profile-card-title">
|
||||||
|
<UserRound />
|
||||||
|
<div>
|
||||||
|
<h2>账户资料</h2>
|
||||||
|
<p>账户名用于登录,显示名称用于后台识别。</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label>
|
||||||
|
<span>登录账户</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
minLength={4}
|
||||||
|
maxLength={50}
|
||||||
|
value={profile.username}
|
||||||
|
onChange={(event) =>
|
||||||
|
setProfile({ ...profile, username: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>显示名称</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
maxLength={50}
|
||||||
|
value={profile.displayName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setProfile({ ...profile, displayName: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<div className="profile-actions">
|
||||||
|
<button className="primary">
|
||||||
|
<Save size={17} />
|
||||||
|
保存账户资料
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<form className="profile-card" onSubmit={savePassword}>
|
||||||
|
<div className="profile-card-title">
|
||||||
|
<KeyRound />
|
||||||
|
<div>
|
||||||
|
<h2>修改密码</h2>
|
||||||
|
<p>新密码需与当前密码不同。</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label>
|
||||||
|
<span>当前密码</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
type="password"
|
||||||
|
autoComplete="current-password"
|
||||||
|
value={password.currentPassword}
|
||||||
|
onChange={(event) =>
|
||||||
|
setPassword({
|
||||||
|
...password,
|
||||||
|
currentPassword: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>新密码</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
type="password"
|
||||||
|
minLength={8}
|
||||||
|
maxLength={64}
|
||||||
|
autoComplete="new-password"
|
||||||
|
value={password.newPassword}
|
||||||
|
onChange={(event) =>
|
||||||
|
setPassword({
|
||||||
|
...password,
|
||||||
|
newPassword: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>确认新密码</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
type="password"
|
||||||
|
minLength={8}
|
||||||
|
maxLength={64}
|
||||||
|
autoComplete="new-password"
|
||||||
|
value={password.confirmPassword}
|
||||||
|
onChange={(event) =>
|
||||||
|
setPassword({
|
||||||
|
...password,
|
||||||
|
confirmPassword: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<div className="profile-actions">
|
||||||
|
<button className="primary">
|
||||||
|
<KeyRound size={17} />
|
||||||
|
修改密码
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{tab === "social" && (
|
||||||
|
<form
|
||||||
|
className="profile-card social-settings-card"
|
||||||
|
onSubmit={saveSocialChannels}
|
||||||
|
>
|
||||||
|
<div className="profile-card-title">
|
||||||
|
<Share2 />
|
||||||
|
<div>
|
||||||
|
<h2>社媒渠道</h2>
|
||||||
|
<p>配置产品分享入口和全站右侧悬浮联系渠道。</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="social-add"
|
||||||
|
onClick={addSocialChannel}
|
||||||
|
>
|
||||||
|
<Plus size={16} />
|
||||||
|
添加渠道
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="social-channel-head">
|
||||||
|
<span>平台</span>
|
||||||
|
<span>展示名称</span>
|
||||||
|
<span>主页或联系地址</span>
|
||||||
|
<span>展示位置</span>
|
||||||
|
<span>排序</span>
|
||||||
|
<span>操作</span>
|
||||||
|
</div>
|
||||||
|
<div className="social-channel-list">
|
||||||
|
{socialChannels.length === 0 && (
|
||||||
|
<div className="social-channel-empty">尚未配置社媒渠道</div>
|
||||||
|
)}
|
||||||
|
{socialChannels.map((channel, index) => (
|
||||||
|
<div
|
||||||
|
className="social-channel-row"
|
||||||
|
key={`${channel.platform}-${index}`}
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
value={channel.platform}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateSocialChannel(index, { platform: event.target.value })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{SOCIAL_PLATFORMS.map((platform) => (
|
||||||
|
<option
|
||||||
|
key={platform}
|
||||||
|
value={platform}
|
||||||
|
disabled={socialChannels.some(
|
||||||
|
(item, itemIndex) =>
|
||||||
|
itemIndex !== index && item.platform === platform,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{platform}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
maxLength={100}
|
||||||
|
value={channel.displayName}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateSocialChannel(index, {
|
||||||
|
displayName: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
maxLength={1000}
|
||||||
|
type={channel.platform === "EMAIL" ? "email" : "url"}
|
||||||
|
placeholder={
|
||||||
|
channel.platform === "EMAIL"
|
||||||
|
? "sales@example.com"
|
||||||
|
: "https://..."
|
||||||
|
}
|
||||||
|
value={channel.profileUrl}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateSocialChannel(index, {
|
||||||
|
profileUrl: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<div className="social-channel-flags">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={channel.shareEnabled}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateSocialChannel(index, {
|
||||||
|
shareEnabled: event.target.checked,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
产品分享
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={channel.floatingEnabled}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateSocialChannel(index, {
|
||||||
|
floatingEnabled: event.target.checked,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
右侧悬浮
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={channel.enabled}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateSocialChannel(index, {
|
||||||
|
enabled: event.target.checked,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
启用
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
className="social-sort"
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
max={9999}
|
||||||
|
value={channel.sortNo}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateSocialChannel(index, {
|
||||||
|
sortNo: Number(event.target.value),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="social-delete"
|
||||||
|
title="删除渠道"
|
||||||
|
onClick={() =>
|
||||||
|
setSocialChannels((current) =>
|
||||||
|
current.filter((_, itemIndex) => itemIndex !== index),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Trash2 size={17} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="profile-actions">
|
||||||
|
<button className="primary">
|
||||||
|
<Save size={17} />
|
||||||
|
保存社媒渠道
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
+224
-81
@@ -46,7 +46,12 @@ import DashboardPage from "./DashboardPage";
|
|||||||
import CrmCustomerPage from "./CrmCustomerPage";
|
import CrmCustomerPage from "./CrmCustomerPage";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
import { statusLabel } from "./statusLabels";
|
import { statusLabel } from "./statusLabels";
|
||||||
import { ensureCurrentSiteCode, getCurrentSiteCode, setCurrentSiteCode, type SiteOption } from "./siteContext";
|
import {
|
||||||
|
ensureCurrentSiteCode,
|
||||||
|
getCurrentSiteCode,
|
||||||
|
setCurrentSiteCode,
|
||||||
|
type SiteOption,
|
||||||
|
} from "./siteContext";
|
||||||
|
|
||||||
const SITE_WEB =
|
const SITE_WEB =
|
||||||
window.location.hostname === "admin.steliro.com"
|
window.location.hostname === "admin.steliro.com"
|
||||||
@@ -233,8 +238,11 @@ function App({
|
|||||||
const previousCodes = new Set(account.sites.map((site) => site.siteCode));
|
const previousCodes = new Set(account.sites.map((site) => site.siteCode));
|
||||||
await apiPost("/sites/create", siteForm);
|
await apiPost("/sites/create", siteForm);
|
||||||
const result = await apiPost<{ items: SiteOption[] }>("/sites/list", {});
|
const result = await apiPost<{ items: SiteOption[] }>("/sites/list", {});
|
||||||
const site = result.items.find((item) => !previousCodes.has(item.siteCode));
|
const site = result.items.find(
|
||||||
if (!site) throw new Error("站点已创建,但未能读取新站点信息,请刷新后重试");
|
(item) => !previousCodes.has(item.siteCode),
|
||||||
|
);
|
||||||
|
if (!site)
|
||||||
|
throw new Error("站点已创建,但未能读取新站点信息,请刷新后重试");
|
||||||
setCurrentSiteCode(site.siteCode);
|
setCurrentSiteCode(site.siteCode);
|
||||||
window.location.assign("/");
|
window.location.assign("/");
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
@@ -261,11 +269,11 @@ function App({
|
|||||||
const [editingPage, setEditingPage] = useState<string | null>(
|
const [editingPage, setEditingPage] = useState<string | null>(
|
||||||
resolvePageRoute,
|
resolvePageRoute,
|
||||||
);
|
);
|
||||||
const [productMenuOpen, setProductMenuOpen] = useState(true);
|
const [productMenuOpen, setProductMenuOpen] = useState(false);
|
||||||
const [contentMenuOpen, setContentMenuOpen] = useState(true);
|
const [contentMenuOpen, setContentMenuOpen] = useState(false);
|
||||||
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(true);
|
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(false);
|
||||||
const [systemSettingsOpen, setSystemSettingsOpen] = useState(true);
|
const [systemSettingsOpen, setSystemSettingsOpen] = useState(false);
|
||||||
const [crmMenuOpen, setCrmMenuOpen] = useState(true);
|
const [crmMenuOpen, setCrmMenuOpen] = useState(false);
|
||||||
const navigateSection = (next: Section) => {
|
const navigateSection = (next: Section) => {
|
||||||
setEditingProduct(null);
|
setEditingProduct(null);
|
||||||
setEditingContent(null);
|
setEditingContent(null);
|
||||||
@@ -288,28 +296,28 @@ function App({
|
|||||||
? { items: [] }
|
? { items: [] }
|
||||||
: section === "dashboard"
|
: section === "dashboard"
|
||||||
? { items: [] }
|
? { items: [] }
|
||||||
: section.startsWith("settings-")
|
: section.startsWith("settings-")
|
||||||
? { items: [] }
|
|
||||||
: section === "navigation"
|
|
||||||
? { items: [] }
|
? { items: [] }
|
||||||
: section === "agreements"
|
: section === "navigation"
|
||||||
? { items: [] }
|
? { items: [] }
|
||||||
: section === "about-us"
|
: section === "agreements"
|
||||||
? { items: [] }
|
? { items: [] }
|
||||||
: section === "products"
|
: section === "about-us"
|
||||||
? await post("/products/list", { siteCode: SITE })
|
? { items: [] }
|
||||||
: section === "pages"
|
: section === "products"
|
||||||
? await post("/pages/list", { siteCode: SITE })
|
? await post("/products/list", { siteCode: SITE })
|
||||||
: section === "decoration"
|
: section === "pages"
|
||||||
? { items: [] }
|
? await post("/pages/list", { siteCode: SITE })
|
||||||
: section === "inquiries"
|
: section === "decoration"
|
||||||
? await post("/inquiries/list", { siteCode: SITE })
|
|
||||||
: section === "inquiry-settings"
|
|
||||||
? { items: [] }
|
? { items: [] }
|
||||||
: await post("/contents/list", {
|
: section === "inquiries"
|
||||||
siteCode: SITE,
|
? await post("/inquiries/list", { siteCode: SITE })
|
||||||
contentType: section,
|
: section === "inquiry-settings"
|
||||||
});
|
? { items: [] }
|
||||||
|
: await post("/contents/list", {
|
||||||
|
siteCode: SITE,
|
||||||
|
contentType: section,
|
||||||
|
});
|
||||||
setItems(data.items || []);
|
setItems(data.items || []);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(e instanceof Error ? e.message : "加载失败");
|
setError(e instanceof Error ? e.message : "加载失败");
|
||||||
@@ -512,11 +520,21 @@ function App({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<button className={section === "dashboard" ? "active" : ""} onClick={() => navigateSection("dashboard")}><LayoutDashboard size={18}/>数据概览</button>
|
<button
|
||||||
|
className={section === "dashboard" ? "active" : ""}
|
||||||
|
onClick={() => navigateSection("dashboard")}
|
||||||
|
>
|
||||||
|
<LayoutDashboard size={18} />
|
||||||
|
数据概览
|
||||||
|
</button>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
["products", "product-categories", "product-templates"].includes(section)
|
[
|
||||||
|
"products",
|
||||||
|
"product-categories",
|
||||||
|
"product-templates",
|
||||||
|
].includes(section)
|
||||||
? "group-active"
|
? "group-active"
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
@@ -553,14 +571,28 @@ function App({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
<button className={section === "crm-customers" ? "group-active" : ""} onClick={() => setCrmMenuOpen(!crmMenuOpen)}>
|
<button
|
||||||
|
className={section === "crm-customers" ? "group-active" : ""}
|
||||||
|
onClick={() => setCrmMenuOpen(!crmMenuOpen)}
|
||||||
|
>
|
||||||
<Users size={18} />
|
<Users size={18} />
|
||||||
CRM 管理
|
CRM 管理
|
||||||
<ChevronDown className={crmMenuOpen ? "expanded" : ""} size={16} />
|
<ChevronDown
|
||||||
|
className={crmMenuOpen ? "expanded" : ""}
|
||||||
|
size={16}
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
{crmMenuOpen && <div className="nav-children">
|
{crmMenuOpen && (
|
||||||
<button className={section === "crm-customers" ? "active" : ""} onClick={() => navigateSection("crm-customers")}><Users size={15}/>客户列表</button>
|
<div className="nav-children">
|
||||||
</div>}
|
<button
|
||||||
|
className={section === "crm-customers" ? "active" : ""}
|
||||||
|
onClick={() => navigateSection("crm-customers")}
|
||||||
|
>
|
||||||
|
<Users size={15} />
|
||||||
|
客户列表
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
<button
|
<button
|
||||||
@@ -655,14 +687,35 @@ function App({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
<button className={systemSettingsMenus.some((item) => item.key === section) ? "group-active" : ""} onClick={() => setSystemSettingsOpen(!systemSettingsOpen)}>
|
<button
|
||||||
|
className={
|
||||||
|
systemSettingsMenus.some((item) => item.key === section)
|
||||||
|
? "group-active"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
onClick={() => setSystemSettingsOpen(!systemSettingsOpen)}
|
||||||
|
>
|
||||||
<Settings size={18} />
|
<Settings size={18} />
|
||||||
系统设置
|
系统设置
|
||||||
<ChevronDown className={systemSettingsOpen ? "expanded" : ""} size={16} />
|
<ChevronDown
|
||||||
|
className={systemSettingsOpen ? "expanded" : ""}
|
||||||
|
size={16}
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
{systemSettingsOpen && <div className="nav-children">
|
{systemSettingsOpen && (
|
||||||
{systemSettingsMenus.map((item) => <button key={item.key} className={section === item.key ? "active" : ""} onClick={() => navigateSection(item.key)}><item.icon size={15} />{item.label}</button>)}
|
<div className="nav-children">
|
||||||
</div>}
|
{systemSettingsMenus.map((item) => (
|
||||||
|
<button
|
||||||
|
key={item.key}
|
||||||
|
className={section === item.key ? "active" : ""}
|
||||||
|
onClick={() => navigateSection(item.key)}
|
||||||
|
>
|
||||||
|
<item.icon size={15} />
|
||||||
|
{item.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{menus.map((m) => (
|
{menus.map((m) => (
|
||||||
<button
|
<button
|
||||||
@@ -678,15 +731,32 @@ function App({
|
|||||||
</aside>
|
</aside>
|
||||||
<main>
|
<main>
|
||||||
{section === "dashboard" ? (
|
{section === "dashboard" ? (
|
||||||
<DashboardPage onNavigate={(next) => navigateSection(next as Section)} />
|
<DashboardPage
|
||||||
|
onNavigate={(next) => navigateSection(next as Section)}
|
||||||
|
/>
|
||||||
) : section === "crm-customers" ? (
|
) : section === "crm-customers" ? (
|
||||||
<CrmCustomerPage />
|
<CrmCustomerPage />
|
||||||
) : section === "settings-store" ? (
|
) : section === "settings-store" ? (
|
||||||
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="store" />
|
<SettingsPage
|
||||||
|
account={account}
|
||||||
|
onAccount={onAccount}
|
||||||
|
onLogout={onLogout}
|
||||||
|
tab="store"
|
||||||
|
/>
|
||||||
) : section === "settings-account" ? (
|
) : section === "settings-account" ? (
|
||||||
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="account" />
|
<SettingsPage
|
||||||
|
account={account}
|
||||||
|
onAccount={onAccount}
|
||||||
|
onLogout={onLogout}
|
||||||
|
tab="account"
|
||||||
|
/>
|
||||||
) : section === "settings-social" ? (
|
) : section === "settings-social" ? (
|
||||||
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="social" />
|
<SettingsPage
|
||||||
|
account={account}
|
||||||
|
onAccount={onAccount}
|
||||||
|
onLogout={onLogout}
|
||||||
|
tab="social"
|
||||||
|
/>
|
||||||
) : section === "about-us" ? (
|
) : section === "about-us" ? (
|
||||||
<AboutUsSettingsPage />
|
<AboutUsSettingsPage />
|
||||||
) : section === "seo-settings" ? (
|
) : section === "seo-settings" ? (
|
||||||
@@ -737,39 +807,39 @@ function App({
|
|||||||
<>
|
<>
|
||||||
{section !== "inquiry-settings" && (
|
{section !== "inquiry-settings" && (
|
||||||
<header>
|
<header>
|
||||||
<div>
|
<div>
|
||||||
<h1>{title}管理</h1>
|
<h1>{title}管理</h1>
|
||||||
</div>
|
</div>
|
||||||
{!["inquiries", "inquiry-settings"].includes(section) && (
|
{!["inquiries", "inquiry-settings"].includes(section) && (
|
||||||
<div className="header-actions">
|
<div className="header-actions">
|
||||||
{["NEWS", "CASE", "HELP"].includes(section) && (
|
{["NEWS", "CASE", "HELP"].includes(section) && (
|
||||||
|
<button
|
||||||
|
className="secondary"
|
||||||
|
onClick={() =>
|
||||||
|
setSection(`${section}-categories` as Section)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FolderTree size={17} />
|
||||||
|
管理分类
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
className="secondary"
|
className="primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setSection(`${section}-categories` as Section)
|
section === "products"
|
||||||
|
? openProductEditor()
|
||||||
|
: ["NEWS", "CASE", "HELP"].includes(section)
|
||||||
|
? openContentEditor(section as EditorialSection)
|
||||||
|
: section === "pages"
|
||||||
|
? openPageEditor()
|
||||||
|
: setOpen(true)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FolderTree size={17} />
|
<Plus size={17} />
|
||||||
管理分类
|
新建{title}
|
||||||
</button>
|
</button>
|
||||||
)}
|
</div>
|
||||||
<button
|
)}
|
||||||
className="primary"
|
|
||||||
onClick={() =>
|
|
||||||
section === "products"
|
|
||||||
? openProductEditor()
|
|
||||||
: ["NEWS", "CASE", "HELP"].includes(section)
|
|
||||||
? openContentEditor(section as EditorialSection)
|
|
||||||
: section === "pages"
|
|
||||||
? openPageEditor()
|
|
||||||
: setOpen(true)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Plus size={17} />
|
|
||||||
新建{title}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</header>
|
</header>
|
||||||
)}
|
)}
|
||||||
{section === "inquiry-settings" ? (
|
{section === "inquiry-settings" ? (
|
||||||
@@ -861,7 +931,8 @@ function App({
|
|||||||
>
|
>
|
||||||
{item.readStatus === 0
|
{item.readStatus === 0
|
||||||
? "未读"
|
? "未读"
|
||||||
: item.statusLabel || statusLabel(item.status)}
|
: item.statusLabel ||
|
||||||
|
statusLabel(item.status)}
|
||||||
</span>
|
</span>
|
||||||
<div className="row-actions">
|
<div className="row-actions">
|
||||||
<button className="link">查看</button>
|
<button className="link">查看</button>
|
||||||
@@ -1067,24 +1138,93 @@ function App({
|
|||||||
)}
|
)}
|
||||||
{siteDialogOpen && (
|
{siteDialogOpen && (
|
||||||
<div className="mask" onMouseDown={() => setSiteDialogOpen(false)}>
|
<div className="mask" onMouseDown={() => setSiteDialogOpen(false)}>
|
||||||
<section className="dialog site-dialog" onMouseDown={(event) => event.stopPropagation()}>
|
<section
|
||||||
|
className="dialog site-dialog"
|
||||||
|
onMouseDown={(event) => event.stopPropagation()}
|
||||||
|
>
|
||||||
<div className="dialog-head">
|
<div className="dialog-head">
|
||||||
<div>
|
<div>
|
||||||
<h2>新增站点</h2>
|
<h2>新增站点</h2>
|
||||||
<p>创建后将自动切换到新站点。</p>
|
<p>创建后将自动切换到新站点。</p>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" aria-label="关闭" onClick={() => setSiteDialogOpen(false)}><X size={19} /></button>
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="关闭"
|
||||||
|
onClick={() => setSiteDialogOpen(false)}
|
||||||
|
>
|
||||||
|
<X size={19} />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-grid">
|
<div className="form-grid">
|
||||||
<label><span>站点名称</span><input autoFocus required maxLength={100} value={siteForm.siteName} onChange={(event) => setSiteForm({ ...siteForm, siteName: event.target.value })} placeholder="例如:Shoplix Global" /></label>
|
<label>
|
||||||
<label><span>所属行业</span><input required maxLength={100} value={siteForm.industry} onChange={(event) => setSiteForm({ ...siteForm, industry: event.target.value })} placeholder="例如:工业设备" /></label>
|
<span>站点名称</span>
|
||||||
<label><span>站点时区</span><input required maxLength={50} value={siteForm.timezone} onChange={(event) => setSiteForm({ ...siteForm, timezone: event.target.value })} /></label>
|
<input
|
||||||
<label className="wide"><span>站点描述</span><textarea rows={4} maxLength={1000} value={siteForm.description} onChange={(event) => setSiteForm({ ...siteForm, description: event.target.value })} /></label>
|
autoFocus
|
||||||
|
required
|
||||||
|
maxLength={100}
|
||||||
|
value={siteForm.siteName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setSiteForm({ ...siteForm, siteName: event.target.value })
|
||||||
|
}
|
||||||
|
placeholder="例如:Shoplix Global"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>所属行业</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
maxLength={100}
|
||||||
|
value={siteForm.industry}
|
||||||
|
onChange={(event) =>
|
||||||
|
setSiteForm({ ...siteForm, industry: event.target.value })
|
||||||
|
}
|
||||||
|
placeholder="例如:工业设备"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>站点时区</span>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
maxLength={50}
|
||||||
|
value={siteForm.timezone}
|
||||||
|
onChange={(event) =>
|
||||||
|
setSiteForm({ ...siteForm, timezone: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="wide">
|
||||||
|
<span>站点描述</span>
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
maxLength={1000}
|
||||||
|
value={siteForm.description}
|
||||||
|
onChange={(event) =>
|
||||||
|
setSiteForm({
|
||||||
|
...siteForm,
|
||||||
|
description: event.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
{siteError && <div className="site-dialog-error">{siteError}</div>}
|
{siteError && <div className="site-dialog-error">{siteError}</div>}
|
||||||
<div className="dialog-actions">
|
<div className="dialog-actions">
|
||||||
<button type="button" onClick={() => setSiteDialogOpen(false)}>取消</button>
|
<button type="button" onClick={() => setSiteDialogOpen(false)}>
|
||||||
<button type="button" className="primary" disabled={siteCreating || !siteForm.siteName.trim() || !siteForm.industry.trim() || !siteForm.timezone.trim()} onClick={createSite}>{siteCreating ? "创建中..." : "创建并切换"}</button>
|
取消
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="primary"
|
||||||
|
disabled={
|
||||||
|
siteCreating ||
|
||||||
|
!siteForm.siteName.trim() ||
|
||||||
|
!siteForm.industry.trim() ||
|
||||||
|
!siteForm.timezone.trim()
|
||||||
|
}
|
||||||
|
onClick={createSite}
|
||||||
|
>
|
||||||
|
{siteCreating ? "创建中..." : "创建并切换"}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
@@ -1099,7 +1239,10 @@ function RootApp() {
|
|||||||
/** 接收账户信息并保证模块级站点上下文与账户权限一致。 */
|
/** 接收账户信息并保证模块级站点上下文与账户权限一致。 */
|
||||||
const acceptAccount = (value: Account) => {
|
const acceptAccount = (value: Account) => {
|
||||||
const previousSiteCode = getCurrentSiteCode();
|
const previousSiteCode = getCurrentSiteCode();
|
||||||
const currentSiteCode = ensureCurrentSiteCode(value.sites || [], value.siteCode);
|
const currentSiteCode = ensureCurrentSiteCode(
|
||||||
|
value.sites || [],
|
||||||
|
value.siteCode,
|
||||||
|
);
|
||||||
if (previousSiteCode !== currentSiteCode) {
|
if (previousSiteCode !== currentSiteCode) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -377,6 +377,7 @@ header p {
|
|||||||
}
|
}
|
||||||
.site-dialog { width:min(620px,calc(100vw - 32px)); }
|
.site-dialog { width:min(620px,calc(100vw - 32px)); }
|
||||||
.site-dialog-error { margin:0 24px 14px; padding:10px 12px; border:1px solid #e5b7b7; border-radius:5px; background:#fff2f2; color:#a52f2f; font-size:13px; }
|
.site-dialog-error { margin:0 24px 14px; padding:10px 12px; border:1px solid #e5b7b7; border-radius:5px; background:#fff2f2; color:#a52f2f; font-size:13px; }
|
||||||
|
.store-domain-preview { color:#718087; font-size:12px; font-weight:400; }
|
||||||
.primary:disabled {
|
.primary:disabled {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
|
|||||||
Reference in new issue
Block a user