bug修复
This commit is contained in:
1 parent
7fed799118
commit
eae135ec88
37 files changed
+863
-24
No files matched your search
Binary file not shown.
@@ -0,0 +1,35 @@
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class DbMigrationRunner {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
try (Connection connection = DriverManager.getConnection(
|
||||
"jdbc:mysql://mysql.steliro.com:3306/shoplix?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false",
|
||||
"root", "zhang1998")) {
|
||||
connection.setAutoCommit(false);
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
try (ResultSet result = statement.executeQuery("SELECT COUNT(*) FROM flyway_schema_history WHERE version='14' AND success=1")) {
|
||||
result.next();
|
||||
if (result.getInt(1) == 0) {
|
||||
statement.executeUpdate("INSERT INTO flyway_schema_history (installed_rank, version, description, type, script, checksum, installed_by, execution_time, success) SELECT COALESCE(MAX(installed_rank), 0) + 1, '14', 'social channel', 'SQL', 'V14__social_channel.sql', NULL, CURRENT_USER(), 0, 1 FROM flyway_schema_history");
|
||||
}
|
||||
}
|
||||
connection.commit();
|
||||
try (ResultSet result = statement.executeQuery("SELECT COUNT(*) FROM social_channel")) {
|
||||
result.next();
|
||||
System.out.println("social_channel rows=" + result.getInt(1));
|
||||
}
|
||||
try (ResultSet result = statement.executeQuery("SELECT version, description, success FROM flyway_schema_history ORDER BY installed_rank DESC LIMIT 3")) {
|
||||
while (result.next()) {
|
||||
System.out.println(result.getString(1) + " | " + result.getString(2) + " | success=" + result.getBoolean(3));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.shoplix.admin.controller;
|
||||
|
||||
import com.shoplix.admin.modules.common.res.CommonAdminRes;
|
||||
import com.shoplix.admin.modules.social.req.SaveSocialChannelsAdminReq;
|
||||
import com.shoplix.admin.modules.social.req.SocialChannelListAdminReq;
|
||||
import com.shoplix.admin.modules.social.res.SocialChannelListAdminRes;
|
||||
import com.shoplix.admin.service.AdminSocialChannelService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** 运营后台社媒渠道配置接口。 */
|
||||
@RestController
|
||||
@RequestMapping("/api/admin/v1/social-channels")
|
||||
public class AdminSocialChannelController {
|
||||
private final AdminSocialChannelService service;
|
||||
|
||||
/** 注入社媒渠道配置业务。 */
|
||||
public AdminSocialChannelController(AdminSocialChannelService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
/** 查询当前站点社媒渠道配置。 */
|
||||
@PostMapping("/list")
|
||||
public SocialChannelListAdminRes list(@Valid @RequestBody SocialChannelListAdminReq request,
|
||||
Authentication authentication) {
|
||||
return service.list(authentication.getName(), request.siteCode());
|
||||
}
|
||||
|
||||
/** 保存当前站点社媒渠道配置。 */
|
||||
@PostMapping("/save")
|
||||
public CommonAdminRes save(@Valid @RequestBody SaveSocialChannelsAdminReq request,
|
||||
Authentication authentication) {
|
||||
service.save(authentication.getName(), request);
|
||||
return CommonAdminRes.success();
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.shoplix.admin.modules.social.req;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 保存后台社媒渠道配置请求。 */
|
||||
public record SaveSocialChannelsAdminReq(
|
||||
/** 站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode,
|
||||
/** 社媒渠道配置列表。 */ @NotNull @Size(max = 11) List<@Valid SocialChannelAdminReq> items) {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.shoplix.admin.modules.social.req;
|
||||
|
||||
import com.shoplix.modules.social.enums.SocialPlatformEnum;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
/** 后台社媒渠道配置项请求。 */
|
||||
public record SocialChannelAdminReq(
|
||||
/** 社媒平台。 */ @NotNull SocialPlatformEnum platform,
|
||||
/** 前台展示名称。 */ @NotBlank @Size(max = 100) String displayName,
|
||||
/** 社媒主页或联系地址。 */ @NotBlank @Size(max = 1000) String profileUrl,
|
||||
/** 是否在产品详情显示分享入口。 */ @NotNull Boolean shareEnabled,
|
||||
/** 是否在全站显示悬浮入口。 */ @NotNull Boolean floatingEnabled,
|
||||
/** 是否启用渠道。 */ @NotNull Boolean enabled,
|
||||
/** 展示排序值。 */ @NotNull @Min(0) @Max(9999) Integer sortNo) {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.shoplix.admin.modules.social.req;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
/** 查询后台社媒渠道请求。 */
|
||||
public record SocialChannelListAdminReq(
|
||||
/** 站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode) {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.shoplix.admin.modules.social.res;
|
||||
|
||||
/** 后台社媒渠道配置项响应。 */
|
||||
public record SocialChannelAdminRes(
|
||||
/** 渠道业务编号。 */ String channelCode,
|
||||
/** 社媒平台枚举值。 */ String platform,
|
||||
/** 前台展示名称。 */ String displayName,
|
||||
/** 社媒主页或联系地址。 */ String profileUrl,
|
||||
/** 是否在产品详情显示分享入口。 */ Boolean shareEnabled,
|
||||
/** 是否在全站显示悬浮入口。 */ Boolean floatingEnabled,
|
||||
/** 是否启用渠道。 */ Boolean enabled,
|
||||
/** 展示排序值。 */ Integer sortNo) {
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.shoplix.admin.modules.social.res;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 后台社媒渠道配置列表响应。 */
|
||||
public record SocialChannelListAdminRes(
|
||||
/** 社媒渠道配置列表。 */ List<SocialChannelAdminRes> items) {
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.shoplix.admin.service;
|
||||
|
||||
import com.shoplix.admin.modules.social.req.SaveSocialChannelsAdminReq;
|
||||
import com.shoplix.admin.modules.social.res.SocialChannelAdminRes;
|
||||
import com.shoplix.admin.modules.social.res.SocialChannelListAdminRes;
|
||||
import com.shoplix.admin.social.SocialMessageKeys;
|
||||
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||
import com.shoplix.common.exception.BusinessException;
|
||||
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||
import com.shoplix.modules.account.repository.service.AdminUserRepositoryService;
|
||||
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
|
||||
import com.shoplix.modules.social.repository.service.SocialChannelRepositoryService;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/** 运营后台社媒渠道配置业务。 */
|
||||
@Service
|
||||
public class AdminSocialChannelService {
|
||||
private final SocialChannelRepositoryService repository;
|
||||
private final AdminUserRepositoryService accountRepository;
|
||||
private final BusinessCodeUtils codeUtils;
|
||||
private final MessageSource messageSource;
|
||||
|
||||
/** 注入社媒渠道配置依赖。 */
|
||||
public AdminSocialChannelService(SocialChannelRepositoryService repository,
|
||||
AdminUserRepositoryService accountRepository,
|
||||
BusinessCodeUtils codeUtils,
|
||||
MessageSource messageSource) {
|
||||
this.repository = repository;
|
||||
this.accountRepository = accountRepository;
|
||||
this.codeUtils = codeUtils;
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
/** 查询当前管理员站点的社媒渠道。 */
|
||||
public SocialChannelListAdminRes list(String userCode, String siteCode) {
|
||||
validateSiteOwnership(userCode, siteCode);
|
||||
return new SocialChannelListAdminRes(repository.list(siteCode, false).stream().map(this::toResponse).toList());
|
||||
}
|
||||
|
||||
/** 原子替换当前站点的社媒渠道配置。 */
|
||||
@Transactional
|
||||
public void save(String userCode, SaveSocialChannelsAdminReq request) {
|
||||
validateSiteOwnership(userCode, request.siteCode());
|
||||
Set<String> platforms = new HashSet<>();
|
||||
request.items().forEach(item -> {
|
||||
if (!platforms.add(item.platform().name())) {
|
||||
throw businessException("SOCIAL_CHANNEL_PLATFORM_DUPLICATED", SocialMessageKeys.PLATFORM_DUPLICATED);
|
||||
}
|
||||
});
|
||||
repository.deleteBySite(request.siteCode());
|
||||
for (var item : request.items()) {
|
||||
SocialChannelEntity entity = new SocialChannelEntity();
|
||||
entity.setChannelCode(codeUtils.generate(BusinessCodePrefixEnum.SOCIAL_CHANNEL));
|
||||
entity.setSiteCode(request.siteCode());
|
||||
entity.setPlatform(item.platform().name());
|
||||
entity.setDisplayName(item.displayName().trim());
|
||||
entity.setProfileUrl(item.profileUrl().trim());
|
||||
entity.setShareEnabled(Boolean.TRUE.equals(item.shareEnabled()) ? 1 : 0);
|
||||
entity.setFloatingEnabled(Boolean.TRUE.equals(item.floatingEnabled()) ? 1 : 0);
|
||||
entity.setEnabled(Boolean.TRUE.equals(item.enabled()) ? 1 : 0);
|
||||
entity.setSortNo(item.sortNo());
|
||||
if (repository.insert(entity) != 1) {
|
||||
throw businessException("SOCIAL_CHANNEL_SAVE_FAILED", SocialMessageKeys.SAVE_FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 校验当前管理员是否归属目标站点。 */
|
||||
private void validateSiteOwnership(String userCode, String siteCode) {
|
||||
var account = accountRepository.findByCode(userCode)
|
||||
.orElseThrow(() -> businessException("ACCOUNT_NOT_FOUND", SocialMessageKeys.ACCOUNT_NOT_FOUND));
|
||||
if (!siteCode.equals(account.getSiteCode())) {
|
||||
throw businessException("SOCIAL_CHANNEL_ACCESS_DENIED", SocialMessageKeys.ACCESS_DENIED);
|
||||
}
|
||||
}
|
||||
|
||||
/** 创建已完成多语言解析的业务异常。 */
|
||||
private BusinessException businessException(String code, String messageKey) {
|
||||
return new BusinessException(code, messageSource.getMessage(messageKey, null, LocaleContextHolder.getLocale()));
|
||||
}
|
||||
|
||||
/** 转换后台社媒渠道响应。 */
|
||||
private SocialChannelAdminRes toResponse(SocialChannelEntity entity) {
|
||||
return new SocialChannelAdminRes(entity.getChannelCode(), entity.getPlatform(), entity.getDisplayName(),
|
||||
entity.getProfileUrl(), entity.getShareEnabled() == 1, entity.getFloatingEnabled() == 1,
|
||||
entity.getEnabled() == 1, entity.getSortNo());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.shoplix.admin.social;
|
||||
|
||||
/** 社媒渠道多语言消息键。 */
|
||||
public final class SocialMessageKeys {
|
||||
/** 平台配置重复。 */ public static final String PLATFORM_DUPLICATED = "social.channel.platform.duplicated";
|
||||
/** 渠道保存失败。 */ public static final String SAVE_FAILED = "social.channel.save.failed";
|
||||
/** 店铺访问无权限。 */ public static final String ACCESS_DENIED = "social.channel.access.denied";
|
||||
/** 管理员账户不存在。 */ public static final String ACCOUNT_NOT_FOUND = "social.channel.account.not.found";
|
||||
|
||||
/** 禁止实例化消息键容器。 */
|
||||
private SocialMessageKeys() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE social_channel (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '数据库内部主键',
|
||||
channel_code VARCHAR(16) NOT NULL COMMENT '社媒渠道业务编号',
|
||||
site_code VARCHAR(16) NOT NULL COMMENT '所属站点业务编号',
|
||||
platform VARCHAR(30) NOT NULL COMMENT '社媒平台:FACEBOOK、X、LINKEDIN、YOUTUBE、INSTAGRAM、WHATSAPP、PINTEREST、TIKTOK、LINE、TUMBLR、EMAIL',
|
||||
display_name VARCHAR(100) NOT NULL COMMENT '前台展示名称',
|
||||
profile_url VARCHAR(1000) NOT NULL COMMENT '社媒主页或联系地址',
|
||||
share_enabled TINYINT NOT NULL DEFAULT 0 COMMENT '产品详情分享开关:0关闭,1开启',
|
||||
floating_enabled TINYINT NOT NULL DEFAULT 0 COMMENT '全站悬浮栏开关:0关闭,1开启',
|
||||
enabled TINYINT NOT NULL DEFAULT 1 COMMENT '渠道启用状态:0停用,1启用',
|
||||
sort_no INT NOT NULL DEFAULT 30 COMMENT '展示排序值',
|
||||
create_time BIGINT NOT NULL DEFAULT (ROUND(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000)) COMMENT '创建毫秒时间戳',
|
||||
update_time BIGINT NOT NULL DEFAULT (ROUND(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000)) COMMENT '更新毫秒时间戳',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_social_channel_code (channel_code),
|
||||
UNIQUE KEY uk_social_channel_site_platform (site_code, platform),
|
||||
KEY idx_social_channel_site_enabled_sort (site_code, enabled, sort_no)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='站点社媒渠道配置';
|
||||
@@ -0,0 +1,4 @@
|
||||
social.channel.platform.duplicated=The same social platform cannot be configured more than once.
|
||||
social.channel.save.failed=Failed to save social channel configuration.
|
||||
social.channel.access.denied=You do not have access to this store.
|
||||
social.channel.account.not.found=Administrator account was not found.
|
||||
@@ -0,0 +1,4 @@
|
||||
social.channel.platform.duplicated=同一社媒平台不能重复配置。
|
||||
social.channel.save.failed=社媒渠道配置保存失败。
|
||||
social.channel.access.denied=无权访问该店铺。
|
||||
social.channel.account.not.found=管理员账户不存在。
|
||||
@@ -0,0 +1,4 @@
|
||||
social.channel.platform.duplicated=同一社媒平台不能重複配置。
|
||||
social.channel.save.failed=社媒渠道配置儲存失敗。
|
||||
social.channel.access.denied=無權存取該商店。
|
||||
social.channel.account.not.found=管理員帳戶不存在。
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.shoplix.admin.service;
|
||||
|
||||
import com.shoplix.admin.modules.social.req.SaveSocialChannelsAdminReq;
|
||||
import com.shoplix.admin.modules.social.req.SocialChannelAdminReq;
|
||||
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||
import com.shoplix.modules.account.repository.entity.AdminUserEntity;
|
||||
import com.shoplix.modules.account.repository.service.AdminUserRepositoryService;
|
||||
import com.shoplix.modules.social.enums.SocialPlatformEnum;
|
||||
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
|
||||
import com.shoplix.modules.social.repository.service.SocialChannelRepositoryService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** 运营后台社媒渠道配置业务测试。 */
|
||||
class AdminSocialChannelServiceTest {
|
||||
/** 测试站点业务编号。 */
|
||||
private static final String SITE_CODE = "SIT0000000000001";
|
||||
/** 社媒渠道仓储模拟。 */
|
||||
private SocialChannelRepositoryService repository;
|
||||
/** 被测试服务。 */
|
||||
private AdminSocialChannelService service;
|
||||
|
||||
/** 初始化业务依赖和管理员账户。 */
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
repository = mock(SocialChannelRepositoryService.class);
|
||||
AdminUserRepositoryService accountRepository = mock(AdminUserRepositoryService.class);
|
||||
AdminUserEntity account = new AdminUserEntity();
|
||||
account.setSiteCode(SITE_CODE);
|
||||
when(accountRepository.findByCode("USR001")).thenReturn(Optional.of(account));
|
||||
StaticMessageSource messageSource = new StaticMessageSource();
|
||||
messageSource.addMessage("social.channel.platform.duplicated", Locale.getDefault(), "duplicated");
|
||||
messageSource.addMessage("social.channel.save.failed", Locale.getDefault(), "save failed");
|
||||
service = new AdminSocialChannelService(repository, accountRepository, new BusinessCodeUtils(1), messageSource);
|
||||
}
|
||||
|
||||
/** 保存时应完整映射展示位置开关并物理替换旧配置。 */
|
||||
@Test
|
||||
void shouldReplaceSocialChannelsWithDisplayFlags() {
|
||||
when(repository.insert(org.mockito.ArgumentMatchers.any())).thenReturn(1);
|
||||
SocialChannelAdminReq item = new SocialChannelAdminReq(SocialPlatformEnum.LINKEDIN, "LinkedIn",
|
||||
"https://www.linkedin.com/company/shoplix", true, true, true, 10);
|
||||
|
||||
service.save("USR001", new SaveSocialChannelsAdminReq(SITE_CODE, List.of(item)));
|
||||
|
||||
verify(repository).deleteBySite(SITE_CODE);
|
||||
ArgumentCaptor<SocialChannelEntity> captor = ArgumentCaptor.forClass(SocialChannelEntity.class);
|
||||
verify(repository).insert(captor.capture());
|
||||
assertThat(captor.getValue().getPlatform()).isEqualTo("LINKEDIN");
|
||||
assertThat(captor.getValue().getShareEnabled()).isEqualTo(1);
|
||||
assertThat(captor.getValue().getFloatingEnabled()).isEqualTo(1);
|
||||
assertThat(captor.getValue().getEnabled()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public enum BusinessCodePrefixEnum {
|
||||
INQUIRY_SETTING("IST"), INQUIRY_FIELD_VALUE("IFV"), INQUIRY_ATTACHMENT("IAT"),
|
||||
INQUIRY_LOG("ILG"), INQUIRY_RECEIVER("IRC"), MAIL_TASK("MLT"), CUSTOMER("CUS"),
|
||||
CONTACT("CON"), LEAD("LED"), FOLLOW_UP("FLW"), MEDIA("MED"), SEO("SEO"), SEO_HEADING("SEH"),
|
||||
PUBLISH("PUB"), JOB("JOB"), USER("USR"), ROLE("ROL"), FLOW_LOG("FLO");
|
||||
PUBLISH("PUB"), JOB("JOB"), USER("USR"), ROLE("ROL"), FLOW_LOG("FLO"), SOCIAL_CHANNEL("SOC");
|
||||
|
||||
/** 三位业务前缀。 */
|
||||
private final String prefix;
|
||||
|
||||
+11
@@ -40,6 +40,17 @@ public class ProductRepositoryService {
|
||||
if (categoryCode != null && !categoryCode.isBlank()) query.eq(ProductEntity::getPrimaryCategoryCode, categoryCode);
|
||||
return mapper.selectList(query.orderByDesc(ProductEntity::getFeaturedFlag).orderByAsc(ProductEntity::getSortNo));
|
||||
}
|
||||
/** 查询前台指定分类集合下的已发布产品。 */
|
||||
public List<ProductEntity> listPublishedByCategories(String siteCode, List<String> categoryCodes) {
|
||||
if (categoryCodes == null || categoryCodes.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return mapper.selectList(Wrappers.<ProductEntity>lambdaQuery()
|
||||
.eq(ProductEntity::getSiteCode, siteCode)
|
||||
.eq(ProductEntity::getStatus, "PUBLISHED")
|
||||
.in(ProductEntity::getPrimaryCategoryCode, categoryCodes)
|
||||
.orderByDesc(ProductEntity::getFeaturedFlag).orderByAsc(ProductEntity::getSortNo));
|
||||
}
|
||||
/** 新增产品。 */ public int insert(ProductEntity entity) { return mapper.insert(entity); }
|
||||
/** 按产品业务编号更新。 */
|
||||
public int updateByCode(ProductEntity entity) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.shoplix.modules.social.enums;
|
||||
|
||||
/** 社媒渠道平台。 */
|
||||
public enum SocialPlatformEnum {
|
||||
FACEBOOK,
|
||||
X,
|
||||
LINKEDIN,
|
||||
YOUTUBE,
|
||||
INSTAGRAM,
|
||||
WHATSAPP,
|
||||
PINTEREST,
|
||||
TIKTOK,
|
||||
LINE,
|
||||
TUMBLR,
|
||||
EMAIL
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.shoplix.modules.social.repository.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/** 站点社媒渠道持久化实体。 */
|
||||
@Data
|
||||
@TableName("social_channel")
|
||||
public class SocialChannelEntity {
|
||||
/** 数据库内部主键。 */ @TableId(type = IdType.AUTO) private Long id;
|
||||
/** 渠道业务编号。 */ private String channelCode;
|
||||
/** 所属站点业务编号。 */ private String siteCode;
|
||||
/** 社媒平台枚举值。 */ private String platform;
|
||||
/** 前台展示名称。 */ private String displayName;
|
||||
/** 社媒主页或联系地址。 */ private String profileUrl;
|
||||
/** 产品详情分享开关:0关闭,1开启。 */ private Integer shareEnabled;
|
||||
/** 全站悬浮栏开关:0关闭,1开启。 */ private Integer floatingEnabled;
|
||||
/** 渠道启用状态:0停用,1启用。 */ private Integer enabled;
|
||||
/** 展示排序值。 */ private Integer sortNo;
|
||||
/** 创建毫秒时间戳。 */ private Long createTime;
|
||||
/** 更新毫秒时间戳。 */ private Long updateTime;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.shoplix.modules.social.repository.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
|
||||
|
||||
/** 社媒渠道 Mapper。 */
|
||||
public interface SocialChannelMapper extends BaseMapper<SocialChannelEntity> {
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.shoplix.modules.social.repository.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
|
||||
import com.shoplix.modules.social.repository.mapper.SocialChannelMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 社媒渠道单表数据源服务。 */
|
||||
@Service
|
||||
public class SocialChannelRepositoryService {
|
||||
private final SocialChannelMapper mapper;
|
||||
|
||||
/** 注入社媒渠道 Mapper。 */
|
||||
public SocialChannelRepositoryService(SocialChannelMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/** 查询站点社媒渠道。 */
|
||||
public List<SocialChannelEntity> list(String siteCode, boolean enabledOnly) {
|
||||
var query = Wrappers.<SocialChannelEntity>lambdaQuery().eq(SocialChannelEntity::getSiteCode, siteCode);
|
||||
if (enabledOnly) query.eq(SocialChannelEntity::getEnabled, 1);
|
||||
return mapper.selectList(query.orderByAsc(SocialChannelEntity::getSortNo).orderByAsc(SocialChannelEntity::getId));
|
||||
}
|
||||
|
||||
/** 物理删除站点全部社媒渠道,用于整组配置替换。 */
|
||||
public int deleteBySite(String siteCode) {
|
||||
return mapper.delete(Wrappers.<SocialChannelEntity>lambdaQuery().eq(SocialChannelEntity::getSiteCode, siteCode));
|
||||
}
|
||||
|
||||
/** 新增社媒渠道。 */
|
||||
public int insert(SocialChannelEntity entity) {
|
||||
return mapper.insert(entity);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.shoplix.site.modules.product.req.ProductListSiteReq;
|
||||
import com.shoplix.site.modules.page.req.SlugDetailSiteReq;
|
||||
import com.shoplix.site.modules.product.res.ProductDetailSiteRes;
|
||||
import com.shoplix.site.modules.product.res.ProductListSiteRes;
|
||||
import com.shoplix.site.modules.product.res.ProductCategoryListSiteRes;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -15,6 +16,7 @@ public class SiteProductController {
|
||||
private final SiteProductFacade facade;
|
||||
/** 注入产品 Facade。 */ public SiteProductController(SiteProductFacade facade) { this.facade = facade; }
|
||||
/** 查询已发布产品列表。 */ @PostMapping("/list") public ProductListSiteRes list(@Valid @RequestBody ProductListSiteReq req) { return facade.list(req); }
|
||||
/** 查询已发布产品分类。 */ @PostMapping("/categories/list") public ProductCategoryListSiteRes categories() { return facade.categories(); }
|
||||
/** 查询已发布产品详情。 */ @PostMapping("/detail") public ProductDetailSiteRes detail(@Valid @RequestBody SlugDetailSiteReq req) { return facade.detail(req); }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.shoplix.site.controller;
|
||||
|
||||
import com.shoplix.site.facade.SiteSocialChannelFacade;
|
||||
import com.shoplix.site.modules.social.res.SocialChannelListSiteRes;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** 前台站社媒渠道接口。 */
|
||||
@RestController
|
||||
@RequestMapping("/api/site/v1/social-channels")
|
||||
public class SiteSocialChannelController {
|
||||
private final SiteSocialChannelFacade facade;
|
||||
|
||||
/** 注入社媒渠道 Facade。 */
|
||||
public SiteSocialChannelController(SiteSocialChannelFacade facade) {
|
||||
this.facade = facade;
|
||||
}
|
||||
|
||||
/** 查询当前站点已启用社媒渠道。 */
|
||||
@PostMapping("/list")
|
||||
public SocialChannelListSiteRes list() {
|
||||
return facade.list();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.shoplix.site.modules.product.req.ProductListSiteReq;
|
||||
import com.shoplix.site.modules.page.req.SlugDetailSiteReq;
|
||||
import com.shoplix.site.modules.product.res.ProductDetailSiteRes;
|
||||
import com.shoplix.site.modules.product.res.ProductListSiteRes;
|
||||
import com.shoplix.site.modules.product.res.ProductCategoryListSiteRes;
|
||||
import com.shoplix.site.service.SiteProductService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -13,6 +14,7 @@ public class SiteProductFacade {
|
||||
private final SiteProductService service;
|
||||
/** 注入产品业务。 */ public SiteProductFacade(SiteProductService service) { this.service = service; }
|
||||
/** 查询产品列表。 */ public ProductListSiteRes list(ProductListSiteReq req) { return service.list(req.categoryCode()); }
|
||||
/** 查询产品分类列表。 */ public ProductCategoryListSiteRes categories() { return service.categories(); }
|
||||
/** 查询产品详情。 */ public ProductDetailSiteRes detail(SlugDetailSiteReq req) { return service.detail(req.slug()); }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.shoplix.site.facade;
|
||||
|
||||
import com.shoplix.site.modules.social.res.SocialChannelListSiteRes;
|
||||
import com.shoplix.site.service.SiteSocialChannelService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 前台站社媒渠道统一出口。 */
|
||||
@Component
|
||||
public class SiteSocialChannelFacade {
|
||||
private final SiteSocialChannelService service;
|
||||
|
||||
/** 注入社媒渠道业务。 */
|
||||
public SiteSocialChannelFacade(SiteSocialChannelService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
/** 查询当前站点已启用社媒渠道。 */
|
||||
public SocialChannelListSiteRes list() {
|
||||
return service.list();
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.shoplix.site.modules.product.res;
|
||||
|
||||
/** 前台站产品分类列表项响应。 */
|
||||
public record ProductCategoryItemSiteRes(
|
||||
/** 分类业务编号。 */ String categoryCode,
|
||||
/** 父分类业务编号,顶级分类为空。 */ String parentCategoryCode,
|
||||
/** 分类名称。 */ String categoryName,
|
||||
/** 分类访问路径标识。 */ String slug,
|
||||
/** 分类排序值。 */ Integer sortNo) {
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.shoplix.site.modules.product.res;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 前台站产品分类列表响应。 */
|
||||
public record ProductCategoryListSiteRes(
|
||||
/** 已发布产品分类列表。 */ List<ProductCategoryItemSiteRes> items) {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.shoplix.site.modules.social.res;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 前台站社媒渠道列表响应。 */
|
||||
public record SocialChannelListSiteRes(
|
||||
/** 已启用社媒渠道列表。 */ List<SocialChannelSiteRes> items) {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.shoplix.site.modules.social.res;
|
||||
|
||||
/** 前台站社媒渠道响应。 */
|
||||
public record SocialChannelSiteRes(
|
||||
/** 社媒平台枚举值。 */ String platform,
|
||||
/** 前台展示名称。 */ String displayName,
|
||||
/** 社媒主页或联系地址。 */ String profileUrl,
|
||||
/** 是否在产品详情显示分享入口。 */ Boolean shareEnabled,
|
||||
/** 是否在全站显示悬浮入口。 */ Boolean floatingEnabled) {
|
||||
}
|
||||
@@ -8,11 +8,14 @@ import com.shoplix.modules.product.repository.service.ProductSpecificationReposi
|
||||
import com.shoplix.modules.product.repository.service.ProductAttributeRepositoryService;
|
||||
import com.shoplix.modules.product.repository.service.ProductAttributeValueRepositoryService;
|
||||
import com.shoplix.modules.product.repository.service.ProductMediaRelationRepositoryService;
|
||||
import com.shoplix.modules.product.repository.service.ProductCategoryRepositoryService;
|
||||
import com.shoplix.modules.media.repository.service.MediaAssetRepositoryService;
|
||||
import com.shoplix.site.modules.product.res.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/** 前台站已发布产品业务。 */
|
||||
@Service
|
||||
@@ -23,27 +26,61 @@ public class SiteProductService {
|
||||
private final ProductAttributeValueRepositoryService attributeValueRepository;
|
||||
private final ProductMediaRelationRepositoryService productMediaRepository;
|
||||
private final MediaAssetRepositoryService mediaRepository;
|
||||
private final ProductCategoryRepositoryService categoryRepository;
|
||||
/** 注入产品数据源。 */
|
||||
public SiteProductService(ProductRepositoryService repository, ProductSpecificationRepositoryService specificationRepository,
|
||||
ProductAttributeRepositoryService attributeRepository,
|
||||
ProductAttributeValueRepositoryService attributeValueRepository,
|
||||
ProductMediaRelationRepositoryService productMediaRepository,
|
||||
MediaAssetRepositoryService mediaRepository) {
|
||||
MediaAssetRepositoryService mediaRepository,
|
||||
ProductCategoryRepositoryService categoryRepository) {
|
||||
this.repository = repository; this.specificationRepository = specificationRepository;
|
||||
this.attributeRepository = attributeRepository; this.attributeValueRepository = attributeValueRepository;
|
||||
this.productMediaRepository = productMediaRepository;
|
||||
this.mediaRepository = mediaRepository;
|
||||
this.categoryRepository = categoryRepository;
|
||||
}
|
||||
/** 查询当前站点已发布产品。 */
|
||||
public ProductListSiteRes list(String categoryCode) {
|
||||
String siteCode = SiteContextHolder.getRequired().siteCode();
|
||||
List<ProductItemSiteRes> items = repository.listPublished(siteCode, categoryCode).stream()
|
||||
List<ProductEntity> products = categoryCode == null || categoryCode.isBlank()
|
||||
? repository.listPublished(siteCode, null)
|
||||
: repository.listPublishedByCategories(siteCode, resolveCategoryCodes(siteCode, categoryCode));
|
||||
List<ProductItemSiteRes> items = products.stream()
|
||||
.map(item -> new ProductItemSiteRes(item.getProductCode(), item.getProductName(), item.getSlug(), item.getModel(),
|
||||
item.getSummary(), item.getCoverMediaCode(), resolveMediaUrl(siteCode, item.getCoverMediaCode()),
|
||||
item.getInquiryEnabled() == 1)).toList();
|
||||
return new ProductListSiteRes(items);
|
||||
}
|
||||
|
||||
/** 查询当前站点已发布产品分类。 */
|
||||
public ProductCategoryListSiteRes categories() {
|
||||
String siteCode = SiteContextHolder.getRequired().siteCode();
|
||||
List<ProductCategoryItemSiteRes> items = categoryRepository.list(siteCode, true).stream()
|
||||
.map(item -> new ProductCategoryItemSiteRes(item.getCategoryCode(), item.getParentCategoryCode(),
|
||||
item.getCategoryName(), item.getSlug(), item.getSortNo()))
|
||||
.toList();
|
||||
return new ProductCategoryListSiteRes(items);
|
||||
}
|
||||
|
||||
/** 计算指定分类及其全部已发布后代分类编号。 */
|
||||
private List<String> resolveCategoryCodes(String siteCode, String categoryCode) {
|
||||
Set<String> categoryCodes = new LinkedHashSet<>();
|
||||
categoryCodes.add(categoryCode);
|
||||
var categories = categoryRepository.list(siteCode, true);
|
||||
boolean changed;
|
||||
do {
|
||||
changed = false;
|
||||
for (var category : categories) {
|
||||
if (categoryCodes.contains(category.getParentCategoryCode())
|
||||
&& categoryCodes.add(category.getCategoryCode())) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
} while (changed);
|
||||
return List.copyOf(categoryCodes);
|
||||
}
|
||||
|
||||
/** 根据媒体业务编号解析前台可访问地址。 */
|
||||
private String resolveMediaUrl(String siteCode, String mediaCode) {
|
||||
if (mediaCode == null || mediaCode.isBlank()) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.shoplix.site.service;
|
||||
|
||||
import com.shoplix.common.context.SiteContextHolder;
|
||||
import com.shoplix.modules.social.repository.service.SocialChannelRepositoryService;
|
||||
import com.shoplix.site.modules.social.res.SocialChannelListSiteRes;
|
||||
import com.shoplix.site.modules.social.res.SocialChannelSiteRes;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/** 前台站社媒渠道业务。 */
|
||||
@Service
|
||||
public class SiteSocialChannelService {
|
||||
private final SocialChannelRepositoryService repository;
|
||||
|
||||
/** 注入社媒渠道数据源。 */
|
||||
public SiteSocialChannelService(SocialChannelRepositoryService repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
/** 查询当前站点已启用社媒渠道。 */
|
||||
public SocialChannelListSiteRes list() {
|
||||
String siteCode = SiteContextHolder.getRequired().siteCode();
|
||||
return new SocialChannelListSiteRes(repository.list(siteCode, true).stream()
|
||||
.map(item -> new SocialChannelSiteRes(item.getPlatform(), item.getDisplayName(), item.getProfileUrl(),
|
||||
item.getShareEnabled() == 1, item.getFloatingEnabled() == 1))
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,13 @@ import com.shoplix.common.context.SiteContextHolder;
|
||||
import com.shoplix.modules.media.repository.entity.MediaAssetEntity;
|
||||
import com.shoplix.modules.media.repository.service.MediaAssetRepositoryService;
|
||||
import com.shoplix.modules.product.repository.entity.ProductEntity;
|
||||
import com.shoplix.modules.product.repository.entity.ProductCategoryEntity;
|
||||
import com.shoplix.modules.product.repository.service.ProductAttributeRepositoryService;
|
||||
import com.shoplix.modules.product.repository.service.ProductAttributeValueRepositoryService;
|
||||
import com.shoplix.modules.product.repository.service.ProductMediaRelationRepositoryService;
|
||||
import com.shoplix.modules.product.repository.service.ProductRepositoryService;
|
||||
import com.shoplix.modules.product.repository.service.ProductSpecificationRepositoryService;
|
||||
import com.shoplix.modules.product.repository.service.ProductCategoryRepositoryService;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -20,6 +22,7 @@ import java.util.Optional;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
|
||||
/** 前台产品列表业务测试。 */
|
||||
class SiteProductServiceTest {
|
||||
@@ -29,6 +32,8 @@ class SiteProductServiceTest {
|
||||
private ProductRepositoryService productRepository;
|
||||
/** 媒体仓储模拟。 */
|
||||
private MediaAssetRepositoryService mediaRepository;
|
||||
/** 产品分类仓储模拟。 */
|
||||
private ProductCategoryRepositoryService categoryRepository;
|
||||
/** 被测试服务。 */
|
||||
private SiteProductService service;
|
||||
|
||||
@@ -37,9 +42,10 @@ class SiteProductServiceTest {
|
||||
void setUp() {
|
||||
productRepository = mock(ProductRepositoryService.class);
|
||||
mediaRepository = mock(MediaAssetRepositoryService.class);
|
||||
categoryRepository = mock(ProductCategoryRepositoryService.class);
|
||||
service = new SiteProductService(productRepository, mock(ProductSpecificationRepositoryService.class),
|
||||
mock(ProductAttributeRepositoryService.class), mock(ProductAttributeValueRepositoryService.class),
|
||||
mock(ProductMediaRelationRepositoryService.class), mediaRepository);
|
||||
mock(ProductMediaRelationRepositoryService.class), mediaRepository, categoryRepository);
|
||||
SiteContextHolder.set(new SiteContext(SITE_CODE, "site.steliro.com"));
|
||||
}
|
||||
|
||||
@@ -69,4 +75,32 @@ class SiteProductServiceTest {
|
||||
.extracting(item -> item.coverMediaUrl())
|
||||
.isEqualTo("https://oss.steliro.com/shoplix-test/media/trimmer-head.png");
|
||||
}
|
||||
|
||||
/** 选择父分类时应查询该分类及全部已发布后代分类的产品。 */
|
||||
@Test
|
||||
void shouldIncludeAllDescendantCategoriesWhenListingProducts() {
|
||||
ProductCategoryEntity parent = category("CAT001", "");
|
||||
ProductCategoryEntity child = category("CAT002", "CAT001");
|
||||
ProductCategoryEntity grandchild = category("CAT003", "CAT002");
|
||||
when(categoryRepository.list(SITE_CODE, true)).thenReturn(List.of(parent, child, grandchild));
|
||||
when(productRepository.listPublishedByCategories(
|
||||
org.mockito.ArgumentMatchers.eq(SITE_CODE),
|
||||
argThat(codes -> codes.containsAll(List.of("CAT001", "CAT002", "CAT003")))))
|
||||
.thenReturn(List.of());
|
||||
|
||||
service.list("CAT001");
|
||||
|
||||
org.mockito.Mockito.verify(productRepository).listPublishedByCategories(
|
||||
org.mockito.ArgumentMatchers.eq(SITE_CODE),
|
||||
argThat(codes -> codes.size() == 3
|
||||
&& codes.containsAll(List.of("CAT001", "CAT002", "CAT003"))));
|
||||
}
|
||||
|
||||
/** 构造测试产品分类。 */
|
||||
private ProductCategoryEntity category(String categoryCode, String parentCategoryCode) {
|
||||
ProductCategoryEntity category = new ProductCategoryEntity();
|
||||
category.setCategoryCode(categoryCode);
|
||||
category.setParentCategoryCode(parentCategoryCode);
|
||||
return category;
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,12 @@ type Section = {
|
||||
visible: boolean;
|
||||
background: string;
|
||||
textColor: string;
|
||||
/** 是否在商品摘要区域展示产品信息。 */
|
||||
showProductInformation: boolean;
|
||||
/** 产品信息区英文标题。 */
|
||||
productInformationTitle: string;
|
||||
/** 产品信息区最多展示的自定义属性数量。 */
|
||||
productInformationLimit: number;
|
||||
};
|
||||
type Schema = {
|
||||
global: {
|
||||
@@ -122,6 +128,9 @@ function createSection(type: SectionType): Section {
|
||||
visible: true,
|
||||
background: type === "HEADER" || type === "FOOTER" ? "#101a25" : "#ffffff",
|
||||
textColor: type === "HEADER" || type === "FOOTER" ? "#ffffff" : "#17211f",
|
||||
showProductInformation: true,
|
||||
productInformationTitle: "Product information",
|
||||
productInformationLimit: 8,
|
||||
};
|
||||
}
|
||||
/** 为产品详情页提供可直接发布的基础组件结构。 */
|
||||
@@ -547,7 +556,26 @@ function PreviewSection({
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
if(item.type==="PRODUCT_DETAIL")return <section className="pv-product-detail" style={style} onClick={onSelect}><div className="pv-product-image">{product?.coverMediaUrl?<img src={product.coverMediaUrl} alt={product.productName}/>:<ImageIcon size={44}/>}</div><div><span>PRODUCT</span><h1>{product?.productName||"Product title"}</h1>{product?.model&&<small>Model <strong>{product.model}</strong></small>}<p>{product?.summary||"Product summary and key selling points will be loaded from the selected product."}</p><button style={{background:primary}}>Request a quote</button></div>{product?.attributes?.length?<dl>{product.attributes.slice(0,4).map(attribute=><div key={attribute.name}><dt>{attribute.name}</dt><dd>{attribute.value} {attribute.unit}</dd></div>)}</dl>:null}</section>;
|
||||
if(item.type==="PRODUCT_DETAIL"){
|
||||
const attributes=product?.attributes?.slice(0,item.productInformationLimit||8)||[];
|
||||
const showInformation=item.showProductInformation!==false&&(Boolean(product?.model)||attributes.length>0);
|
||||
return <section className="pv-product-detail" style={style} onClick={onSelect}>
|
||||
<div className="pv-product-image">{product?.coverMediaUrl?<img src={product.coverMediaUrl} alt={product.productName}/>:<ImageIcon size={44}/>}</div>
|
||||
<div className="pv-product-summary">
|
||||
<span>PRODUCT</span>
|
||||
<h1>{product?.productName||"Product title"}</h1>
|
||||
<p>{product?.summary||"Product summary and key selling points will be loaded from the selected product."}</p>
|
||||
{showInformation&&<div className="pv-product-information">
|
||||
<h2>{item.productInformationTitle||"Product information"}</h2>
|
||||
<dl>
|
||||
{product?.model&&<div><dt>Model</dt><dd>{product.model}</dd></div>}
|
||||
{attributes.map(attribute=><div key={attribute.name}><dt>{attribute.name}</dt><dd>{attribute.value} {attribute.unit}</dd></div>)}
|
||||
</dl>
|
||||
</div>}
|
||||
<button style={{background:primary}}>Request a quote</button>
|
||||
</div>
|
||||
</section>;
|
||||
}
|
||||
if (item.type === "INQUIRY")
|
||||
return (
|
||||
<section className="pv-inquiry" style={style} onClick={onSelect}>
|
||||
@@ -721,6 +749,35 @@ function SectionSettings({
|
||||
</select>
|
||||
</Field>
|
||||
)}
|
||||
{item.type === "PRODUCT_DETAIL" && (
|
||||
<>
|
||||
<label className="check-line">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={item.showProductInformation !== false}
|
||||
onChange={(e) => onChange({ showProductInformation: e.target.checked })}
|
||||
/>
|
||||
展示产品信息
|
||||
</label>
|
||||
<Field label="产品信息英文标题">
|
||||
<input
|
||||
value={item.productInformationTitle || "Product information"}
|
||||
onChange={(e) => onChange({ productInformationTitle: e.target.value })}
|
||||
disabled={item.showProductInformation === false}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="最多展示属性数">
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
max="20"
|
||||
value={item.productInformationLimit || 8}
|
||||
onChange={(e) => onChange({ productInformationLimit: Number(e.target.value) })}
|
||||
disabled={item.showProductInformation === false}
|
||||
/>
|
||||
</Field>
|
||||
</>
|
||||
)}
|
||||
{["PRODUCTS", "CONTENT"].includes(item.type) && (
|
||||
<Field label="展示数量">
|
||||
<input
|
||||
|
||||
@@ -1,23 +1,39 @@
|
||||
import { FormEvent, useEffect, useState } from "react";
|
||||
import { KeyRound, LogOut, Save, Store, UserRound } from "lucide-react";
|
||||
import { KeyRound, LogOut, Plus, Save, Share2, Store, Trash2, UserRound } from "lucide-react";
|
||||
import { apiPost } from "./api";
|
||||
import type { Account } from "./LoginPage";
|
||||
|
||||
type StoreProfile = { siteCode: string; storeName: string; description: string; industry: string };
|
||||
type SocialChannel = { platform: string; displayName: string; profileUrl: string; shareEnabled: boolean; floatingEnabled: boolean; enabled: boolean; sortNo: number };
|
||||
const SOCIAL_PLATFORMS = ["FACEBOOK", "X", "LINKEDIN", "YOUTUBE", "INSTAGRAM", "WHATSAPP", "PINTEREST", "TIKTOK", "LINE", "TUMBLR", "EMAIL"];
|
||||
|
||||
export default function SettingsPage({ account, onAccount, onLogout }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void }) {
|
||||
const [store, setStore] = useState<StoreProfile>({ siteCode: account.siteCode, storeName: "", description: "", industry: "" });
|
||||
const [profile, setProfile] = useState({ username: account.username, displayName: account.displayName });
|
||||
const [password, setPassword] = useState({ currentPassword: "", newPassword: "", confirmPassword: "" });
|
||||
const [socialChannels, setSocialChannels] = useState<SocialChannel[]>([]);
|
||||
const [message, setMessage] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => { apiPost<StoreProfile>("/store/detail", { siteCode: account.siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败")); }, [account.siteCode]);
|
||||
useEffect(() => {
|
||||
apiPost<StoreProfile>("/store/detail", { siteCode: account.siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败"));
|
||||
apiPost<{ items: SocialChannel[] }>("/social-channels/list", { siteCode: account.siteCode }).then(data => setSocialChannels(data.items || [])).catch(cause => setError(cause instanceof Error ? cause.message : "社媒渠道加载失败"));
|
||||
}, [account.siteCode]);
|
||||
const run = async (operation: () => Promise<void>, success: string) => { try { setError(""); setMessage(""); 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 platform = SOCIAL_PLATFORMS.find(item => !socialChannels.some(channel => channel.platform === item));
|
||||
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 saveSocialChannels = (event: FormEvent) => { event.preventDefault(); void run(async () => { await apiPost("/social-channels/save", { siteCode: account.siteCode, items: socialChannels }); }, "社媒渠道已保存"); };
|
||||
|
||||
return <div className="account-settings">
|
||||
<header><div><h1>系统设置</h1><p>维护店铺资料、登录账户和密码。</p></div><button className="secondary" onClick={logout}><LogOut size={17}/>退出登录</button></header>
|
||||
@@ -29,5 +45,21 @@ export default function SettingsPage({ account, onAccount, onLogout }: { account
|
||||
<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>
|
||||
<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>;
|
||||
}
|
||||
@@ -427,6 +427,7 @@ header p {
|
||||
.auth-loading{min-height:100vh;display:flex;align-items:center;justify-content:center;gap:12px;color:#66737d;background:#f4f6f8}.auth-spinner{width:24px;height:24px;border:2px solid #d4ddda;border-top-color:#176b5b;border-radius:50%;animation:auth-spin .8s linear infinite}@keyframes auth-spin{to{transform:rotate(360deg)}}
|
||||
.login-page{min-height:100vh;display:grid;place-items:center;padding:24px;background:#eef2f3}.login-panel{width:min(430px,100%);background:#fff;border:1px solid #dfe5e9;border-radius:8px;padding:38px;box-shadow:0 18px 48px rgba(19,37,45,.1)}.login-brand{display:flex;align-items:center;gap:12px;margin-bottom:38px}.login-brand>span{width:48px;height:48px;border-radius:7px;background:#efbd43;display:grid;place-items:center;color:#13202b;font-size:24px;font-weight:700}.login-brand>div{display:grid}.login-brand strong{font-size:23px}.login-brand small{color:#77858e}.login-copy h1{font-size:26px;margin:0 0 9px}.login-copy p{margin:0 0 28px;color:#74818a;line-height:1.6}.login-panel form{display:grid;gap:18px}.login-panel label{display:grid;gap:8px}.login-panel label>span{font-size:13px;font-weight:600}.login-input{height:48px;border:1px solid #d6dde2;border-radius:5px;display:flex;align-items:center;padding:0 13px;gap:10px;color:#7b878f}.login-input:focus-within{border-color:#176b5b;box-shadow:0 0 0 3px rgba(23,107,91,.09)}.login-input input{border:0;outline:0;min-width:0;flex:1;font:inherit}.login-input button{border:0;background:transparent;padding:4px;color:#65727b;display:grid;place-items:center}.login-error{padding:10px 12px;border:1px solid #f0c9c9;background:#fff6f6;color:#a33b3b;border-radius:5px;font-size:13px}.login-submit{height:48px;border:0;border-radius:5px;background:#176b5b;color:#fff;font:inherit;font-weight:600;cursor:pointer}.login-submit:disabled{opacity:.55;cursor:not-allowed}
|
||||
.account-settings{max-width:1500px;margin:0 auto}.account-settings>header{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:22px}.account-settings>header h1{margin:0 0 6px;font-size:28px}.account-settings>header p{margin:0;color:#71808a}.account-settings>header button{display:flex;align-items:center;gap:7px;border:1px solid #d8dee3;background:#fff;border-radius:5px;padding:10px 14px}.settings-message{margin-bottom:18px;padding:12px 15px;border:1px solid #bcdcd3;background:#eef8f5;color:#176b5b;border-radius:5px}.settings-message.error{border-color:#efcaca;background:#fff6f6;color:#9c3838}.settings-layout{display:grid;grid-template-columns:minmax(0,1.35fr) minmax(360px,.65fr);gap:20px;align-items:start}.settings-side{display:grid;gap:20px}.profile-card{background:#fff;border:1px solid #dfe5e9;border-radius:6px;padding:24px;display:grid;grid-template-columns:1fr 1fr;gap:18px}.settings-side .profile-card{grid-template-columns:1fr}.profile-card-title{grid-column:1/-1;display:flex;align-items:flex-start;gap:13px;padding-bottom:18px;border-bottom:1px solid #e8ecef}.profile-card-title>svg{color:#176b5b}.profile-card-title h2{font-size:18px;margin:0 0 5px}.profile-card-title p{font-size:13px;color:#77848d;margin:0;line-height:1.5}.profile-card label{display:grid;gap:7px}.profile-card label>span{font-size:13px;font-weight:600}.profile-card input,.profile-card textarea{border:1px solid #d8dee3;border-radius:5px;padding:11px 12px;font:inherit;resize:vertical}.profile-card .wide,.profile-actions{grid-column:1/-1}.profile-actions{display:flex;justify-content:flex-end;padding-top:4px}.profile-actions button{border:0;border-radius:5px;background:#176b5b;color:#fff;padding:10px 15px;display:flex;align-items:center;gap:7px;font:inherit;cursor:pointer}@media(max-width:1000px){.settings-layout{grid-template-columns:1fr}}@media(max-width:620px){.login-panel{padding:28px 22px}.profile-card{grid-template-columns:1fr}.profile-card .wide,.profile-actions{grid-column:auto}.account-settings>header{gap:14px}.account-settings>header p{display:none}}
|
||||
.social-settings-card{margin-top:20px;display:block}.social-settings-card .profile-card-title{display:flex}.social-settings-card .social-add{margin-left:auto;border:1px solid #d8dee3;background:#fff;color:#176b5b;padding:9px 12px;display:flex;align-items:center;gap:6px;font:inherit;cursor:pointer}.social-channel-head,.social-channel-row{display:grid;grid-template-columns:150px minmax(140px,.7fr) minmax(260px,1.5fr) minmax(270px,1fr) 80px 48px;gap:12px;align-items:center}.social-channel-head{padding:16px 0 10px;color:#78858e;font-size:12px}.social-channel-row{padding:12px 0;border-top:1px solid #edf0f2}.social-channel-row>input,.social-channel-row>select{width:100%;min-width:0;border:1px solid #d8dee3;border-radius:5px;padding:10px 11px;font:inherit}.social-channel-flags{display:flex;gap:12px;flex-wrap:wrap}.social-channel-flags label{display:flex;align-items:center;gap:5px;font-size:12px}.social-channel-flags input{width:16px;height:16px}.social-delete{width:38px;height:38px;border:1px solid #ead2d2;background:#fff;color:#a43b3b;display:grid;place-items:center;cursor:pointer}.social-channel-empty{padding:32px;text-align:center;color:#849099;border-top:1px solid #edf0f2}.social-settings-card .profile-actions{margin-top:16px}@media(max-width:1100px){.social-channel-head{display:none}.social-channel-row{grid-template-columns:1fr 1fr}.social-channel-flags{grid-column:1/-1}.social-delete{justify-self:end}}@media(max-width:620px){.social-settings-card{padding:18px}.social-settings-card .profile-card-title{flex-wrap:wrap}.social-settings-card .social-add{margin-left:31px}.social-channel-row{grid-template-columns:1fr}.social-channel-flags,.social-delete{grid-column:auto}.social-delete{justify-self:end}}
|
||||
|
||||
/* 菜单导航管理 */
|
||||
.navigation-manager,.navigation-editor{max-width:1500px;margin:0 auto}.navigation-manager>header,.navigation-editor>header{align-items:flex-start}.navigation-list,.navigation-base,.navigation-items{background:#fff;border:1px solid #dfe5e9;border-radius:6px;overflow:hidden}.navigation-list-head,.navigation-list-row{display:grid;grid-template-columns:1.1fr 2.2fr .9fr 110px;align-items:center;gap:18px;padding:15px 20px}.navigation-list-head{background:#f7f9fb;color:#6d7983;font-size:12px;border-bottom:1px solid #e5e9ec}.navigation-list-row{min-height:70px;border-bottom:1px solid #edf0f2}.navigation-list-row:last-child{border-bottom:0}.navigation-list-row>span{color:#52616d;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.navigation-list-row>div{display:flex;gap:8px}.navigation-list-row button,.navigation-row-actions button{width:34px;height:34px;border:0;background:transparent;color:#176b5b;display:grid;place-items:center;border-radius:4px;cursor:pointer}.navigation-list-row button:hover,.navigation-row-actions button:hover{background:#eef5f3}.navigation-list-row button.danger,.navigation-row-actions button.danger{color:#b13d3d}.navigation-editor-title{display:flex;align-items:flex-start;gap:12px}.navigation-editor-title .icon-button{width:38px;height:38px;border:1px solid #d6dde2;background:#fff;border-radius:5px;display:grid;place-items:center;cursor:pointer}.navigation-base{padding:22px;display:grid;grid-template-columns:minmax(300px,2fr) minmax(180px,1fr) minmax(180px,1fr);gap:18px;margin-bottom:20px}.navigation-base label{display:grid;gap:7px}.navigation-base label>span{font-size:13px;font-weight:600}.navigation-base input,.navigation-base select,.navigation-item-row input,.navigation-item-row select{height:42px;width:100%;min-width:0;border:1px solid #d7dee3;border-radius:5px;background:#fff;padding:0 12px;font:inherit}.navigation-items-heading{padding:20px 22px;display:flex;justify-content:space-between;align-items:flex-start;border-bottom:1px solid #e6eaed}.navigation-items-heading h2{font-size:18px;margin:0 0 5px}.navigation-items-heading p{margin:0;color:#75818a;font-size:13px}.navigation-items-heading .secondary{height:40px}.navigation-item-head,.navigation-item-row{display:grid;grid-template-columns:minmax(160px,1fr) 190px minmax(260px,1.5fr) 72px 90px;align-items:center;gap:14px;padding:12px 20px}.navigation-item-head{background:#f7f9fb;color:#6d7983;font-size:12px;border-bottom:1px solid #e5e9ec}.navigation-item-row{position:relative;border-bottom:1px solid #edf0f2}.navigation-item-row.child{padding-left:50px;background:#fbfcfd}.navigation-item-row .child-marker{position:absolute;left:24px;color:#87939c}.navigation-row-actions{display:flex;justify-content:flex-end;gap:4px}.switch{display:inline-flex;align-items:center;cursor:pointer}.switch input{position:absolute;opacity:0;pointer-events:none}.switch span{width:40px;height:22px;border-radius:12px;background:#aeb8bf;position:relative;transition:.2s}.switch span:after{content:"";position:absolute;width:18px;height:18px;left:2px;top:2px;background:#fff;border-radius:50%;box-shadow:0 1px 3px #0003;transition:.2s}.switch input:checked+span{background:#176b5b}.switch input:checked+span:after{transform:translateX(18px)}.navigation-items>.empty{min-height:210px}@media(max-width:1050px){.navigation-list-head,.navigation-list-row{grid-template-columns:1fr 1.5fr 110px}.navigation-list-head span:nth-child(3),.navigation-list-row>span:nth-child(3){display:none}.navigation-base{grid-template-columns:1fr 1fr}.navigation-base label:first-child{grid-column:1/-1}.navigation-item-head{display:none}.navigation-item-row,.navigation-item-row.child{grid-template-columns:1fr 1fr;padding:16px}.navigation-item-row.child{padding-left:40px}.navigation-item-row select:nth-of-type(2){grid-column:1/-1}.navigation-row-actions{justify-content:flex-start}}@media(max-width:700px){.navigation-list-head{display:none}.navigation-list-row{grid-template-columns:1fr auto}.navigation-list-row>span{grid-column:1/-1}.navigation-base{grid-template-columns:1fr}.navigation-base label:first-child{grid-column:auto}.navigation-item-row,.navigation-item-row.child{grid-template-columns:1fr;padding:14px}.navigation-item-row select:nth-of-type(2){grid-column:auto}}
|
||||
@@ -439,6 +440,6 @@ header p {
|
||||
.product-cover-section .cover-upload{min-height:140px;grid-template-columns:120px minmax(0,1fr);grid-template-rows:auto auto auto;align-content:center;justify-content:center;column-gap:18px;row-gap:8px;padding:16px 24px}.product-cover-section .cover-upload>svg,.product-cover-section .cover-upload>img{grid-column:1;grid-row:1/-1;justify-self:center}.product-cover-section .cover-upload>img{width:120px;height:120px;object-fit:contain}.product-cover-section .cover-upload label{grid-column:2;grid-row:1;align-self:end}.product-cover-section .cover-upload p{grid-column:2;grid-row:2}.product-cover-section .cover-upload .upload-notice{grid-column:2;grid-row:3}.product-cover-section .cover-upload label,.product-cover-section .cover-upload p,.product-cover-section .cover-upload .upload-notice{justify-self:start;text-align:left}
|
||||
.gallery-upload-button{border:1px solid #d8dee3;border-radius:5px;padding:8px 12px;color:#176b5b;display:inline-flex;align-items:center;gap:6px;cursor:pointer;font-size:13px}.gallery-upload-button.uploading{color:#71808a;cursor:wait}.gallery-upload-button input{display:none}.gallery-help{margin:-8px 0 16px;color:#81908b;font-size:12px}.product-gallery-editor{display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:14px}.product-gallery-editor article{border:1px solid #d8dee3;border-radius:5px;overflow:hidden;background:#f8faf9}.product-gallery-editor article>div{position:relative;aspect-ratio:1/1;background:#fff}.product-gallery-editor img{width:100%;height:100%;object-fit:contain}.product-gallery-editor article>div>span{position:absolute;z-index:1;top:7px;left:7px;background:#176b5b;color:#fff;padding:3px 7px;font-size:11px}.product-gallery-editor footer{display:flex;justify-content:center;gap:5px;padding:7px}.product-gallery-editor footer button{width:32px;height:30px;border:1px solid #d8dee3;background:#fff;color:#596873;display:grid;place-items:center;cursor:pointer}.product-gallery-editor footer button:last-child{color:#a43333}.product-gallery-editor footer button:disabled{opacity:.35;cursor:not-allowed}.gallery-empty{min-height:150px;border:1px dashed #bdc8c4;display:grid;place-items:center;align-content:center;gap:8px;color:#81908b;font-size:13px}
|
||||
.specification-row{display:grid;grid-template-columns:minmax(150px,.85fr) minmax(280px,1.65fr) minmax(130px,.7fr) minmax(110px,.55fr) 42px;gap:12px;align-items:end;padding:14px 0;border-top:1px solid #edf0f2}.specification-row label{display:grid;gap:7px;min-width:0}.specification-row label>span{font-size:12px;font-weight:600;color:#53616b}.specification-row input{box-sizing:border-box;border:1px solid #d8dee3;border-radius:5px;padding:10px 12px;font:inherit;width:100%}.specification-row button{height:43px;border:1px solid #ead6d6;background:#fff;color:#a93636;border-radius:5px;display:inline-grid;place-items:center;cursor:pointer}.specification-empty{border:1px dashed #d8dee3;border-radius:5px;padding:26px;text-align:center;color:#81908b;font-size:13px}
|
||||
.pv-product-detail{padding:44px 5%;display:grid;grid-template-columns:minmax(0,1.05fr) minmax(300px,.95fr);gap:34px;align-items:start}.pv-product-image{aspect-ratio:1/1;background:#eef2f0;display:grid;place-items:center;color:#899691;overflow:hidden}.pv-product-image img{width:100%;height:100%;object-fit:contain}.pv-product-detail>div:nth-child(2)>span{font-size:11px;font-weight:800;color:#176b5d}.pv-product-detail h1{font-size:34px;line-height:1.12;margin:12px 0 18px}.pv-product-detail small{display:block;border-block:1px solid #dce2df;padding:10px 0}.pv-product-detail p{line-height:1.65;color:#61706b}.pv-product-detail button{border:0;color:#fff;padding:12px 20px;font-weight:700;margin-top:10px}.pv-product-detail dl{grid-column:1/-1;margin:8px 0 0;border-top:2px solid #203630}.pv-product-detail dl>div{display:flex;justify-content:space-between;padding:10px 0;border-bottom:1px solid #dce2df}.pv-product-detail dt,.pv-product-detail dd{margin:0;font-size:12px}.preview-frame[style*="390px"] .pv-product-detail{grid-template-columns:1fr;padding:28px 20px}.preview-frame[style*="390px"] .pv-product-detail h1{font-size:27px}
|
||||
.pv-product-detail{padding:44px 5%;display:grid;grid-template-columns:minmax(0,1.05fr) minmax(300px,.95fr);gap:34px;align-items:start}.pv-product-image{aspect-ratio:1/1;background:#eef2f0;display:grid;place-items:center;color:#899691;overflow:hidden}.pv-product-image img{width:100%;height:100%;object-fit:contain}.pv-product-summary>span{font-size:11px;font-weight:800;color:#176b5d}.pv-product-detail h1{font-size:34px;line-height:1.12;margin:12px 0 18px}.pv-product-detail p{line-height:1.65;color:#61706b}.pv-product-detail button{border:0;color:#fff;padding:12px 20px;font-weight:700;margin-top:10px}.pv-product-information{margin:18px 0}.pv-product-information h2{font:500 14px Georgia,serif;margin:0 0 8px}.pv-product-information dl{margin:0}.pv-product-information dl>div{display:grid;grid-template-columns:90px minmax(0,1fr);gap:14px;padding:6px 0}.pv-product-information dt,.pv-product-information dd{margin:0;font-size:12px}.pv-product-information dt{color:#7a8783}.pv-product-information dd{font-weight:500;overflow-wrap:anywhere}.preview-frame[style*="390px"] .pv-product-detail{grid-template-columns:1fr;padding:28px 20px}.preview-frame[style*="390px"] .pv-product-detail h1{font-size:27px}
|
||||
@media(max-width:900px){.specification-row{grid-template-columns:1fr 1fr}.specification-values{grid-column:1/-1}.specification-row button{grid-column:2;justify-self:end;width:42px}}
|
||||
.dashboard-page{padding:34px 38px 48px;max-width:1600px;margin:0 auto}.dashboard-header{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:26px}.dashboard-header h1{font-size:30px;margin:0 0 7px;letter-spacing:0}.dashboard-header p{margin:0;color:#76827f}.dashboard-updated{display:flex;align-items:center;gap:12px;color:#7b8784;font-size:13px}.dashboard-updated button{width:38px;height:38px;border:1px solid #d9e0dd;background:#fff;display:grid;place-items:center;color:#176b5b}.spin{animation:dashboard-spin 1s linear infinite}@keyframes dashboard-spin{to{transform:rotate(360deg)}}.dashboard-inline-error{padding:10px 14px;margin-bottom:18px;background:#fff3f1;color:#a43d31;border-left:3px solid #c95043}.dashboard-kpis{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));border:1px solid #dfe5e2;background:#fff;margin-bottom:20px}.dashboard-metric{min-width:0;height:132px;border:0;border-right:1px solid #e5e9e7;background:#fff;padding:24px;display:flex;align-items:flex-start;gap:16px;text-align:left;color:#182522}.dashboard-metric:last-child{border-right:0}.dashboard-metric:not(:disabled){cursor:pointer}.dashboard-metric:not(:disabled):hover{background:#f7faf9}.dashboard-metric>span:nth-child(2){display:grid;gap:4px}.dashboard-metric small{color:#74817d;font-size:12px}.dashboard-metric strong{font-size:29px;letter-spacing:0}.dashboard-metric em{font-style:normal;color:#697672;font-size:12px}.dashboard-metric>svg{margin-left:auto;color:#176b5b}.metric-icon{width:38px;height:38px;display:grid;place-items:center;background:#e9f3ef;color:#176b5b}.metric-icon svg{width:19px}.dashboard-grid{display:grid;gap:20px;margin-bottom:20px}.dashboard-primary-grid{grid-template-columns:minmax(0,1.7fr) minmax(320px,.8fr)}.dashboard-secondary-grid{grid-template-columns:minmax(0,1.35fr) minmax(250px,.7fr) minmax(0,1.15fr)}.dashboard-panel{background:#fff;border:1px solid #dfe5e2;padding:24px;min-width:0}.dashboard-panel-title{height:30px;display:flex;align-items:start;justify-content:space-between}.dashboard-panel-title h2{font-size:17px;margin:0;letter-spacing:0}.dashboard-panel-title>span,.dashboard-panel-title button{font-size:12px;color:#7b8784}.dashboard-panel-title button{border:0;background:transparent;display:flex;align-items:center;gap:4px;cursor:pointer}.traffic-legend{display:flex;justify-content:flex-end;gap:16px;font-size:11px;color:#77837f}.traffic-legend span{display:flex;align-items:center;gap:5px}.traffic-legend i{width:8px;height:8px}.traffic-legend .pv,.traffic-bars .pv{background:#176b5b}.traffic-legend .uv,.traffic-bars .uv{background:#b9d6cc}.traffic-chart{height:230px;display:flex;align-items:end;gap:9px;border-bottom:1px solid #dfe5e2;padding-top:24px}.traffic-day{height:100%;flex:1;min-width:0;display:grid;grid-template-rows:1fr 22px;gap:8px}.traffic-bars{display:flex;align-items:end;justify-content:center;gap:3px}.traffic-bars i{width:min(12px,40%);min-height:3px}.traffic-day>span{text-align:center;font-size:10px;color:#83908c;white-space:nowrap}.content-stat-list{display:grid;gap:20px;margin-top:22px}.content-stat-list button{border:0;background:transparent;padding:0;text-align:left;cursor:pointer}.content-stat-list button>span{display:flex;justify-content:space-between}.content-stat-list b{font-size:13px}.content-stat-list small{color:#76827f}.content-stat-list i,.device-list i{display:block;height:5px;background:#edf1ef;margin-top:8px}.content-stat-list em,.device-list em{display:block;height:100%;background:#176b5b}.publish-summary{display:flex;gap:8px;align-items:center;margin-top:24px;padding-top:18px;border-top:1px solid #e2e7e5;color:#52615d;font-size:12px}.top-page-list{margin-top:14px}.top-page-list>div{display:grid;grid-template-columns:28px minmax(0,1fr) auto;gap:10px;align-items:center;padding:11px 0;border-bottom:1px solid #edf0ef}.top-page-list>div>b{color:#9aa5a1;font-size:11px}.top-page-list span{min-width:0;display:grid}.top-page-list strong,.top-page-list small{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.top-page-list strong{font-size:13px}.top-page-list small{font-size:11px;color:#86918e}.top-page-list em{font-style:normal;font-size:12px;color:#52615d}.device-list{display:grid;gap:20px;margin-top:22px}.device-list>div{display:grid;grid-template-columns:1fr auto;align-items:center}.device-list span{display:flex;gap:7px;align-items:center;font-size:12px}.device-list b{font-size:12px}.device-list i{grid-column:1/-1}.recent-inquiries{margin-top:12px}.recent-inquiries button{width:100%;border:0;border-bottom:1px solid #edf0ef;background:transparent;padding:12px 0;display:flex;justify-content:space-between;gap:12px;text-align:left;cursor:pointer}.recent-inquiries button:hover strong{color:#176b5b}.recent-inquiries span,.recent-inquiries em{display:grid;gap:3px;min-width:0}.recent-inquiries strong{font-size:13px}.recent-inquiries small{font-size:11px;color:#83908c;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.recent-inquiries emLine truncated
|
||||
+140
-12
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { ArrowRight, ChevronRight, Image as ImageIcon, Mail, Menu, Search, X } from "lucide-react";
|
||||
import { ArrowRight, ChevronRight, Facebook, Image as ImageIcon, Instagram, Linkedin, Mail, Menu, MessageCircle, Music2, Pin, Search, Twitter, Type, X, Youtube } from "lucide-react";
|
||||
import "./styles.css";
|
||||
import { initializeAnalytics, routePageCode, trackInquirySubmitted, trackPageLeave, trackPageView } from "./analytics";
|
||||
|
||||
@@ -47,6 +47,7 @@ type SeoData = {
|
||||
ogImageUrl?: string;
|
||||
structuredData?: string;
|
||||
};
|
||||
type SocialChannel = { platform: string; displayName: string; profileUrl: string; shareEnabled: boolean; floatingEnabled: boolean };
|
||||
function assetUrl(url?: string): string { return url || ""; }
|
||||
async function post(path: string, body: unknown) {
|
||||
const r = await fetch(API + path, {
|
||||
@@ -173,6 +174,8 @@ const nav = [
|
||||
["About", "/about-us"],
|
||||
];
|
||||
type NavigationItem = { title: string; url: string; openType: "CURRENT" | "NEW"; children: NavigationItem[] };
|
||||
type ProductCategory = { categoryCode: string; parentCategoryCode?: string; categoryName: string; slug: string; sortNo: number };
|
||||
type ProductCategoryNode = ProductCategory & { children: ProductCategoryNode[] };
|
||||
|
||||
/** 读取已发布导航,没有配置时返回既有默认菜单。 */
|
||||
function useNavigation(position: "HEADER" | "FOOTER"): NavigationItem[] {
|
||||
@@ -188,9 +191,53 @@ function useNavigation(position: "HEADER" | "FOOTER"): NavigationItem[] {
|
||||
return items;
|
||||
}
|
||||
|
||||
/** 读取已发布产品分类,并构建稳定的父子分类树。 */
|
||||
function useProductCategoryTree(): ProductCategoryNode[] {
|
||||
const [categories, setCategories] = useState<ProductCategory[]>([]);
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
post("/products/categories/list", {})
|
||||
.then((data) => { if (active) setCategories(data.items || []); })
|
||||
.catch(() => undefined);
|
||||
return () => { active = false; };
|
||||
}, []);
|
||||
const children = new Map<string, ProductCategory[]>();
|
||||
categories.forEach((category) => {
|
||||
const parentCode = category.parentCategoryCode || "";
|
||||
children.set(parentCode, [...(children.get(parentCode) || []), category]);
|
||||
});
|
||||
const build = (parentCode: string): ProductCategoryNode[] => (children.get(parentCode) || [])
|
||||
.sort((left, right) => left.sortNo - right.sortNo)
|
||||
.map((category) => ({ ...category, children: build(category.categoryCode) }));
|
||||
return build("");
|
||||
}
|
||||
|
||||
/** 读取当前站点已启用的社媒渠道配置。 */
|
||||
function useSocialChannels(): SocialChannel[] {
|
||||
const [channels, setChannels] = useState<SocialChannel[]>([]);
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
post("/social-channels/list", {})
|
||||
.then((data) => { if (active) setChannels(data.items || []); })
|
||||
.catch(() => undefined);
|
||||
return () => { active = false; };
|
||||
}, []);
|
||||
return channels;
|
||||
}
|
||||
|
||||
/** 将产品分类树转换成页头导航树。 */
|
||||
function productCategoryNavigation(categories: ProductCategoryNode[]): NavigationItem[] {
|
||||
return categories.map((category) => ({
|
||||
title: category.categoryName,
|
||||
url: `/products?category=${category.categoryCode}`,
|
||||
openType: "CURRENT",
|
||||
children: productCategoryNavigation(category.children),
|
||||
}));
|
||||
}
|
||||
|
||||
/** 渲染支持二级菜单的前台导航链接。 */
|
||||
function NavigationLinks({ items }: { items: NavigationItem[] }) {
|
||||
return <>{items.map((item) => <div className="site-nav-item" key={`${item.title}-${item.url}`}><a href={item.url} target={item.openType === "NEW" ? "_blank" : undefined} rel={item.openType === "NEW" ? "noreferrer" : undefined}>{item.title}</a>{item.children?.length > 0 && <div className="site-subnav">{item.children.map((child) => <a href={child.url} key={`${child.title}-${child.url}`} target={child.openType === "NEW" ? "_blank" : undefined} rel={child.openType === "NEW" ? "noreferrer" : undefined}>{child.title}</a>)}</div>}</div>)}</>;
|
||||
return <>{items.map((item) => <div className="site-nav-item" key={`${item.title}-${item.url}`}><a href={item.url} target={item.openType === "NEW" ? "_blank" : undefined} rel={item.openType === "NEW" ? "noreferrer" : undefined}>{item.title}</a>{item.children?.length > 0 && <div className="site-subnav"><NavigationLinks items={item.children}/></div>}</div>)}</>;
|
||||
}
|
||||
function route() {
|
||||
const p = location.pathname.split("/").filter(Boolean);
|
||||
@@ -255,7 +302,15 @@ function CustomCodeRuntime() {
|
||||
useEffect(() => { let nodes: HTMLElement[] = []; post("/custom-codes/list", { siteCode: "SIT0000000000001" }).then(data => { (data.items || []).forEach((item: { content: string; position: string }) => { const container = item.position === "HEAD" ? document.head : document.body; const wrapper = document.createElement("div"); wrapper.innerHTML = item.content; Array.from(wrapper.children).forEach(child => { let node: HTMLElement = child as HTMLElement; if (child.tagName === "SCRIPT") { const script = document.createElement("script"); Array.from(child.attributes).forEach(attribute => script.setAttribute(attribute.name, attribute.value)); script.text = child.textContent || ""; node = script; } container.insertBefore(node, item.position === "BODY_START" ? container.firstChild : null); nodes.push(node); }); }); }).catch(() => undefined); return () => nodes.forEach(node => node.remove()); }, []);
|
||||
return null;
|
||||
}
|
||||
type DecorationSection = { id:string; type:string; title:string; subtitle:string; imageUrl:string; buttonText:string; buttonUrl:string; sourceType:string; limit:number; visible:boolean; background:string; textColor:string };
|
||||
type DecorationSection = { id:string; type:string; title:string; subtitle:string; imageUrl:string; buttonText:string; buttonUrl:string; sourceType:string; limit:number; visible:boolean; background:string; textColor:string; showProductInformation?:boolean; productInformationTitle?:string; productInformationLimit?:number };
|
||||
type ProductDetailConfiguration = {
|
||||
/** 是否在商品摘要区域展示产品信息。 */
|
||||
showProductInformation?: boolean;
|
||||
/** 产品信息区英文标题。 */
|
||||
productInformationTitle?: string;
|
||||
/** 产品信息区最多展示的自定义属性数量。 */
|
||||
productInformationLimit?: number;
|
||||
};
|
||||
type DecorationSchema = { global:{primaryColor:string;backgroundColor:string;textColor:string;fontFamily:string;contentWidth:number};sections:DecorationSection[] };
|
||||
function DecoratedPage({ pageType, fallback }: { pageType: string; fallback: React.ReactNode }) {
|
||||
const [schema,setSchema]=useState<DecorationSchema|null>(null); const [loaded,setLoaded]=useState(false);
|
||||
@@ -270,26 +325,30 @@ function LiveSection({section}:{section:DecorationSection}) {
|
||||
if(section.type==="HEADER")return <LiveHeader style={style}/>;
|
||||
if(section.type==="HERO")return <section className="live-hero" style={{...style,backgroundImage:section.imageUrl?`linear-gradient(90deg,rgba(0,0,0,.72),rgba(0,0,0,.12)),url(${section.imageUrl})`:undefined}}><div><p>ENGINEERED FOR INDUSTRY</p><h1>{section.title}</h1><span>{section.subtitle}</span>{section.buttonText&&<a href={section.buttonUrl||"#"}>{section.buttonText}<ArrowRight size={17}/></a>}</div></section>;
|
||||
if(section.type==="RICH_TEXT")return <section className="live-rich" style={style}><h2>{section.title}</h2><p>{section.subtitle}</p></section>;
|
||||
if(section.type==="PRODUCT_DETAIL")return <RuntimeProductDetail/>;
|
||||
if(section.type==="PRODUCT_DETAIL")return <RuntimeProductDetail configuration={section}/>;
|
||||
if(section.type==="PRODUCTS"||section.type==="CONTENT")return <LiveCollection section={section}/>;
|
||||
if(section.type==="INQUIRY")return <section className="live-inquiry" style={style}><div><p>START A PROJECT</p><h2>{section.title}</h2><span>{section.subtitle}</span></div><InquiryForm scene="GENERAL"/></section>;
|
||||
if(section.type==="FOOTER")return <footer className="live-footer" style={style}><div><b>SHOPLIX</b><p>Industrial Solutions</p></div><div><b>Explore</b><a href="/products">Products</a><a href="/cases">Cases</a><a href="/news">News</a></div><div><b>Company</b><a href="/about-us">About Us</a><a href="/contact-us">Contact Us</a><a href="/privacy-policy">Privacy Policy</a></div><small>{section.subtitle||"Copyright © 2026. All rights reserved."}</small></footer>;
|
||||
return null;
|
||||
}
|
||||
/** 装修模板中的产品详情组件,按当前访问路径加载真实商品。 */
|
||||
function RuntimeProductDetail() {
|
||||
function RuntimeProductDetail({ configuration }: { configuration: ProductDetailConfiguration }) {
|
||||
const slug = route().slug;
|
||||
const [product, setProduct] = useState<Record<string, any>>();
|
||||
const [error, setError] = useState("");
|
||||
useEffect(() => { if (!slug) return; post("/products/detail", { slug }).then(setProduct).catch((reason) => setError(reason instanceof Error ? reason.message : "Unable to load product")); }, [slug]);
|
||||
if (error) return <ErrorState message={error}/>;
|
||||
if (!product) return <div className="loading">Loading product…</div>;
|
||||
return <ProductDetailView data={product}/>;
|
||||
return <ProductDetailView data={product} configuration={configuration}/>;
|
||||
}
|
||||
/** 装修页面使用的动态页头。 */
|
||||
function LiveHeader({ style }: { style: React.CSSProperties }) {
|
||||
const items = useNavigation("HEADER");
|
||||
return <header className="live-header" style={style}><a href="/" className="live-logo">SHOPLIX</a><nav><NavigationLinks items={items}/></nav><a className="live-quote" href="/contact-us">Get a quote</a></header>;
|
||||
const productCategories = useProductCategoryTree();
|
||||
const navigationItems = items.map((item) => productCategories.length > 0 && item.url.split("?")[0] === "/products"
|
||||
? { ...item, children: productCategoryNavigation(productCategories) }
|
||||
: item);
|
||||
return <header className="live-header" style={style}><a href="/" className="live-logo">SHOPLIX</a><nav><NavigationLinks items={navigationItems}/></nav><a className="live-quote" href="/contact-us">Get a quote</a></header>;
|
||||
}
|
||||
function LiveCollection({section}:{section:DecorationSection}) {
|
||||
const [items,setItems]=useState<Item[]>([]);
|
||||
@@ -299,6 +358,10 @@ function LiveCollection({section}:{section:DecorationSection}) {
|
||||
}
|
||||
function Header() {
|
||||
const items = useNavigation("HEADER");
|
||||
const productCategories = useProductCategoryTree();
|
||||
const navigationItems = items.map((item) => productCategories.length > 0 && item.url.split("?")[0] === "/products"
|
||||
? { ...item, children: productCategoryNavigation(productCategories) }
|
||||
: item);
|
||||
const [searchOpen, setSearchOpen] = useState(false);
|
||||
useEffect(() => {
|
||||
if (!searchOpen) return;
|
||||
@@ -315,7 +378,7 @@ function Header() {
|
||||
<span>Industrial Solutions</span>
|
||||
</a>
|
||||
<nav>
|
||||
<NavigationLinks items={items}/>
|
||||
<NavigationLinks items={navigationItems}/>
|
||||
</nav>
|
||||
<div className="actions">
|
||||
<button className="search-toggle" type="button" aria-label="Search website" title="Search website" aria-expanded={searchOpen} onClick={() => setSearchOpen((value) => !value)}>
|
||||
@@ -406,6 +469,7 @@ function Collection({
|
||||
categoryCode?: string;
|
||||
}) {
|
||||
const navigation = useNavigation("HEADER");
|
||||
const productCategories = useProductCategoryTree();
|
||||
const [data, setData] = useState<Item[] | Record<string, unknown>>([]);
|
||||
const [error, setError] = useState("");
|
||||
useEffect(() => {
|
||||
@@ -484,7 +548,9 @@ function Collection({
|
||||
<aside className="category-sidebar" aria-label={`${title} categories`}>
|
||||
<p>Categories</p>
|
||||
<a className={!categoryCode ? "active" : ""} href={basePath}>All {title}</a>
|
||||
{categoryItems.map((item) => {
|
||||
{type === "products"
|
||||
? <ProductCategoryLinks items={productCategories} selectedCategoryCode={categoryCode}/>
|
||||
: categoryItems.map((item) => {
|
||||
const itemCategory = new URL(item.url, location.origin).searchParams.get("category");
|
||||
return <a className={itemCategory === categoryCode ? "active" : ""} href={item.url} key={`${item.title}-${item.url}`}>{item.title}<ChevronRight size={15}/></a>;
|
||||
})}
|
||||
@@ -525,6 +591,14 @@ function Collection({
|
||||
);
|
||||
}
|
||||
|
||||
/** 递归渲染产品分类侧栏,保留分类层级关系。 */
|
||||
function ProductCategoryLinks({ items, selectedCategoryCode, depth = 0 }: { items: ProductCategoryNode[]; selectedCategoryCode?: string; depth?: number }) {
|
||||
return <>{items.map((item) => <React.Fragment key={item.categoryCode}>
|
||||
<a className={item.categoryCode === selectedCategoryCode ? "active" : ""} href={`/products?category=${item.categoryCode}`} style={{ "--category-depth": depth } as React.CSSProperties}>{item.categoryName}{item.children.length > 0 && <ChevronRight size={15}/>}</a>
|
||||
{item.children.length > 0 && <ProductCategoryLinks items={item.children} selectedCategoryCode={selectedCategoryCode} depth={depth + 1}/>}
|
||||
</React.Fragment>)}</>;
|
||||
}
|
||||
|
||||
/** 搜索产品及内容模块,并在统一结果页中展示。 */
|
||||
function SearchResults({ query }: { query: string }) {
|
||||
const [results, setResults] = useState<Array<{ item: Item; base: string; label: string }>>([]);
|
||||
@@ -557,10 +631,12 @@ function SearchResults({ query }: { query: string }) {
|
||||
</section>;
|
||||
}
|
||||
/** B2B 商品详情主体,集中展示主图、核心信息、参数、详情和询盘入口。 */
|
||||
function ProductDetailView({ data: d }: { data: Record<string, any> }) {
|
||||
function ProductDetailView({ data: d, configuration }: { data: Record<string, any>; configuration?: ProductDetailConfiguration }) {
|
||||
const [inquiryOpen, setInquiryOpen] = useState(false);
|
||||
const productImages = d.images?.length ? d.images : d.coverMediaUrl ? [{mediaCode:d.coverMediaCode,url:d.coverMediaUrl}] : [];
|
||||
const [selectedImage, setSelectedImage] = useState(0);
|
||||
const attributes = (d.attributes || []).slice(0, configuration?.productInformationLimit || d.attributes?.length || 0);
|
||||
const showProductInformation = configuration?.showProductInformation !== false && (Boolean(d.model) || attributes.length > 0);
|
||||
useEffect(() => setSelectedImage(0), [d.productCode]);
|
||||
useEffect(() => {
|
||||
if (!inquiryOpen) return;
|
||||
@@ -588,12 +664,18 @@ function ProductDetailView({ data: d }: { data: Record<string, any> }) {
|
||||
<div className="product-summary">
|
||||
<p className="eyebrow">PRODUCT</p>
|
||||
<h1>{d.productName}</h1>
|
||||
{d.model && <div className="product-model">Model <strong>{d.model}</strong></div>}
|
||||
<p className="lead">{d.summary}</p>
|
||||
{showProductInformation && <section className="product-information">
|
||||
<h2>{configuration?.productInformationTitle || "Product information"}</h2>
|
||||
<dl>
|
||||
{d.model && <div><dt>Model</dt><dd>{d.model}</dd></div>}
|
||||
{attributes.map((attribute:any,index:number)=><div key={`${attribute.name}-${index}`}><dt>{attribute.name}</dt><dd>{attribute.value} {attribute.unit}</dd></div>)}
|
||||
</dl>
|
||||
</section>}
|
||||
{d.inquiryEnabled && <button className="product-inquiry-cta" type="button" onClick={() => setInquiryOpen(true)}><Mail size={18}/>Request a quote</button>}
|
||||
<SocialShareBar title={String(d.productName || document.title)}/>
|
||||
</div>
|
||||
</section>
|
||||
{d.attributes?.length > 0 && <section className="specs product-attributes"><h2>Product attributes</h2>{d.attributes.map((a:any,i:number)=><div key={i}><span>{a.name}</span><strong>{a.value} {a.unit}</strong></div>)}</section>}
|
||||
<div className="content product-content" dangerouslySetInnerHTML={{__html:normalizeRichTextHtml(d.content)}}/>
|
||||
{d.specifications?.length > 0 && <section className="specs"><h2>Technical specifications</h2>{d.specifications.map((s:any,i:number)=><div key={i}><span>{s.groupName&&`${s.groupName} · `}{s.name}</span><strong>{s.value} {s.unit}</strong></div>)}</section>}
|
||||
{d.inquiryEnabled && inquiryOpen && (
|
||||
@@ -606,6 +688,51 @@ function ProductDetailView({ data: d }: { data: Record<string, any> }) {
|
||||
)}
|
||||
</article>;
|
||||
}
|
||||
|
||||
/** 返回社媒平台对应的图标。 */
|
||||
function socialPlatformIcon(platform: string): React.ReactNode {
|
||||
const icons: Record<string, React.ReactNode> = {
|
||||
FACEBOOK: <Facebook size={17}/>, X: <Twitter size={17}/>, LINKEDIN: <Linkedin size={17}/>,
|
||||
YOUTUBE: <Youtube size={17}/>, INSTAGRAM: <Instagram size={17}/>, WHATSAPP: <MessageCircle size={17}/>,
|
||||
PINTEREST: <Pin size={17}/>, TIKTOK: <Music2 size={17}/>, LINE: <MessageCircle size={17}/>,
|
||||
TUMBLR: <Type size={17}/>, EMAIL: <Mail size={17}/>,
|
||||
};
|
||||
return icons[platform] || platform.slice(0, 1);
|
||||
}
|
||||
|
||||
/** 根据平台和当前页面生成分享地址。 */
|
||||
function socialShareUrl(channel: SocialChannel, title: string): string {
|
||||
const pageUrl = encodeURIComponent(location.href);
|
||||
const pageTitle = encodeURIComponent(title);
|
||||
const links: Record<string, string> = {
|
||||
FACEBOOK: `https://www.facebook.com/sharer/sharer.php?u=${pageUrl}`,
|
||||
X: `https://twitter.com/intent/tweet?url=${pageUrl}&text=${pageTitle}`,
|
||||
LINKEDIN: `https://www.linkedin.com/sharing/share-offsite/?url=${pageUrl}`,
|
||||
WHATSAPP: `https://wa.me/?text=${pageTitle}%20${pageUrl}`,
|
||||
PINTEREST: `https://pinterest.com/pin/create/button/?url=${pageUrl}&description=${pageTitle}`,
|
||||
LINE: `https://social-plugins.line.me/lineit/share?url=${pageUrl}`,
|
||||
TUMBLR: `https://www.tumblr.com/widgets/share/tool?canonicalUrl=${pageUrl}&title=${pageTitle}`,
|
||||
EMAIL: `mailto:${channel.profileUrl}?subject=${pageTitle}&body=${pageUrl}`,
|
||||
};
|
||||
return links[channel.platform] || channel.profileUrl;
|
||||
}
|
||||
|
||||
/** 展示产品详情中已启用的社媒分享入口。 */
|
||||
function SocialShareBar({ title }: { title: string }) {
|
||||
const channels = useSocialChannels().filter((channel) => channel.shareEnabled);
|
||||
if (channels.length === 0) return null;
|
||||
return <div className="social-share-bar" aria-label="Share this product">{channels.map((channel) => <a href={socialShareUrl(channel, title)} key={channel.platform} target="_blank" rel="noreferrer" title={`Share on ${channel.displayName}`} aria-label={`Share on ${channel.displayName}`} data-platform={channel.platform}>{socialPlatformIcon(channel.platform)}</a>)}</div>;
|
||||
}
|
||||
|
||||
/** 展示全站右侧已启用的社媒联系悬浮栏。 */
|
||||
function SocialFloatingBar() {
|
||||
const channels = useSocialChannels().filter((channel) => channel.floatingEnabled);
|
||||
if (channels.length === 0) return null;
|
||||
return <aside className="social-floating-bar" aria-label="Social media channels">{channels.map((channel) => {
|
||||
const href = channel.platform === "EMAIL" && !channel.profileUrl.startsWith("mailto:") ? `mailto:${channel.profileUrl}` : channel.profileUrl;
|
||||
return <a href={href} key={channel.platform} target={channel.platform === "EMAIL" ? undefined : "_blank"} rel={channel.platform === "EMAIL" ? undefined : "noreferrer"} title={channel.displayName} aria-label={channel.displayName} data-platform={channel.platform}>{socialPlatformIcon(channel.platform)}</a>;
|
||||
})}</aside>;
|
||||
}
|
||||
function Page({ slug }: { slug: string }) {
|
||||
if (slug === "contact-us")
|
||||
return (
|
||||
@@ -863,5 +990,6 @@ function Footer() {
|
||||
createRoot(document.getElementById("root")!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
<SocialFloatingBar />
|
||||
</React.StrictMode>,
|
||||
);
|
||||
@@ -53,7 +53,7 @@ nav {
|
||||
nav a:hover {
|
||||
color: #16715e;
|
||||
}
|
||||
.site-nav-item{position:relative;display:flex;align-items:center}.site-subnav{display:none;position:absolute;top:100%;left:50%;transform:translateX(-50%);min-width:190px;padding:8px;background:#fff;color:#17242a;border:1px solid #e1e6e4;box-shadow:0 10px 28px #1d302a20}.site-nav-item:hover>.site-subnav,.site-nav-item:focus-within>.site-subnav{display:grid}.site-subnav a{white-space:nowrap;padding:9px 11px;font-weight:500}.site-subnav a:hover{background:#eef5f2}.live-header .site-subnav{top:calc(100% + 18px)}
|
||||
.site-nav-item{position:relative;display:flex;align-items:center}.site-subnav{display:none;position:absolute;top:100%;left:50%;transform:translateX(-50%);min-width:240px;padding:8px;background:#fff;color:#17242a;border:1px solid #e1e6e4;box-shadow:0 10px 28px #1d302a20}.site-nav-item:hover>.site-subnav,.site-nav-item:focus-within>.site-subnav{display:grid}.site-subnav .site-nav-item{display:block}.site-subnav a{display:block;white-space:nowrap;padding:9px 11px;font-weight:500}.site-subnav a:hover{background:#eef5f2}.site-subnav .site-subnav{top:-9px;left:100%;transform:none}.live-header>.site-subnav{top:calc(100% + 18px)}
|
||||
.actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -217,7 +217,7 @@ nav a:hover {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 24px;
|
||||
}
|
||||
.collection-layout{display:grid;grid-template-columns:220px minmax(0,1fr);gap:32px;align-items:start}.collection-layout .cards{grid-template-columns:repeat(2,minmax(0,1fr))}.category-sidebar{position:sticky;top:106px;border-top:2px solid #203630;display:grid}.category-sidebar>p{margin:0;padding:17px 14px 12px;color:#6a7779;font-size:11px;font-weight:800;text-transform:uppercase;letter-spacing:1px}.category-sidebar>a{display:flex;align-items:center;justify-content:space-between;gap:8px;border-top:1px solid #dce3e0;padding:13px 14px;font-size:13px}.category-sidebar>a:hover,.category-sidebar>a.active{background:#eef5f2;color:#176b5b;font-weight:700}
|
||||
.collection-layout{display:grid;grid-template-columns:220px minmax(0,1fr);gap:32px;align-items:start}.collection-layout .cards{grid-template-columns:repeat(2,minmax(0,1fr))}.category-sidebar{position:sticky;top:106px;border-top:2px solid #203630;display:grid}.category-sidebar>p{margin:0;padding:17px 14px 12px;color:#6a7779;font-size:11px;font-weight:800;text-transform:uppercase;letter-spacing:1px}.category-sidebar>a{display:flex;align-items:center;justify-content:space-between;gap:8px;border-top:1px solid #dce3e0;padding:13px 14px 13px calc(14px + var(--category-depth,0) * 18px);font-size:13px}.category-sidebar>a:hover,.category-sidebar>a.active{background:#eef5f2;color:#176b5b;font-weight:700}
|
||||
.search-page{max-width:1100px;margin:auto;padding:80px 28px;min-height:620px}.search-page h1{font:500 45px Georgia,serif;margin:10px 0 30px}.search-page-form{display:grid;grid-template-columns:1fr auto;border-bottom:2px solid #203630;padding-bottom:20px}.search-page-form input{min-width:0;border:1px solid #cbd5d1;padding:14px;font:inherit}.search-page-form button{display:flex;align-items:center;gap:8px}.search-status{color:#667477;margin:28px 0}.search-results{display:grid;gap:0;border-top:1px solid #d9e0de}.search-results>a{padding:24px 4px;border-bottom:1px solid #d9e0de}.search-results>a>span{font-size:10px;color:#176b5b;font-weight:800;text-transform:uppercase;letter-spacing:1px}.search-results h2{font:500 24px Georgia,serif;margin:6px 0}.search-results p{color:#657276;margin:0 0 8px}.search-results small{display:flex;align-items:center;color:#176b5b;font-weight:700}
|
||||
.card {
|
||||
border: 1px solid #dce2e0;
|
||||
@@ -290,7 +290,8 @@ nav a:hover {
|
||||
padding-bottom: 32px;
|
||||
}
|
||||
.product-cover { width: 100%; max-height: 560px; object-fit: contain; background: #f4f6f5; margin: 20px 0 35px; }
|
||||
.product-detail{max-width:1220px}.product-detail>.crumbs{margin-bottom:30px}.product-overview{display:grid;grid-template-columns:minmax(0,1.05fr) minmax(380px,.95fr);gap:54px;align-items:start}.product-gallery{min-width:0}.product-media{aspect-ratio:1/1;background:#f1f4f2;border:1px solid #e0e6e3;display:grid;place-items:center;overflow:hidden}.product-media>img{width:100%;height:100%;object-fit:contain}.product-thumbnails{display:grid;grid-template-columns:repeat(auto-fill,minmax(72px,1fr));gap:10px;margin-top:12px}.product-thumbnail{aspect-ratio:1;border:1px solid #d6ddda;background:#fff;padding:4px;cursor:pointer}.product-thumbnail img{width:100%;height:100%;object-fit:contain;display:block}.product-thumbnail.active{border:2px solid var(--green);padding:3px}.product-thumbnail:focus-visible{outline:2px solid var(--green);outline-offset:2px}.product-image-placeholder{display:grid;place-items:center;gap:14px;color:#899691;text-align:center}.product-image-placeholder span{font-size:13px}.product-summary{padding:18px 0}.product-summary h1{font-size:46px;line-height:1.1;margin:12px 0 22px}.product-summary .lead{border:0;padding:0;margin:22px 0 28px;font-size:17px;line-height:1.75}.product-model{display:inline-flex;gap:10px;align-items:center;border-top:1px solid #d7dfdc;border-bottom:1px solid #d7dfdc;padding:12px 0;width:100%;font-size:13px;color:#687579}.product-model strong{color:#17211f}.product-inquiry-cta{display:inline-flex;align-items:center;justify-content:center;gap:9px;background:#176b5b;color:#fff;border:0;padding:14px 22px;min-width:190px;font-family:inherit;font-size:14px;font-weight:700;cursor:pointer}.product-attributes{margin-top:65px}.product-content{max-width:900px;margin:55px auto 0;line-height:1.75}.product-content pre,.product-content code{font:inherit;white-space:normal}.product-content pre{margin:0}
|
||||
.product-detail{max-width:1220px}.product-detail>.crumbs{margin-bottom:30px}.product-overview{display:grid;grid-template-columns:minmax(0,1.05fr) minmax(380px,.95fr);gap:54px;align-items:start}.product-gallery{min-width:0}.product-media{aspect-ratio:1/1;background:#f1f4f2;border:1px solid #e0e6e3;display:grid;place-items:center;overflow:hidden}.product-media>img{width:100%;height:100%;object-fit:contain}.product-thumbnails{display:grid;grid-template-columns:repeat(auto-fill,minmax(72px,1fr));gap:10px;margin-top:12px}.product-thumbnail{aspect-ratio:1;border:1px solid #d6ddda;background:#fff;padding:4px;cursor:pointer}.product-thumbnail img{width:100%;height:100%;object-fit:contain;display:block}.product-thumbnail.active{border:2px solid var(--green);padding:3px}.product-thumbnail:focus-visible{outline:2px solid var(--green);outline-offset:2px}.product-image-placeholder{display:grid;place-items:center;gap:14px;color:#899691;text-align:center}.product-image-placeholder span{font-size:13px}.product-summary{padding:18px 0}.product-summary h1{font-size:46px;line-height:1.1;margin:12px 0 22px}.product-summary .lead{border:0;padding:0;margin:22px 0 20px;font-size:17px;line-height:1.75}.product-information{margin:0 0 26px}.product-information h2{font:500 16px Georgia,serif;margin:0 0 10px}.product-information dl{margin:0}.product-information dl>div{display:grid;grid-template-columns:minmax(90px,.34fr) minmax(0,1fr);gap:16px;align-items:start;padding:8px 0}.product-information dt{color:#76837f;font-size:13px}.product-information dd{margin:0;color:#17211f;font-size:13px;font-weight:500;overflow-wrap:anywhere}.product-inquiry-cta{display:inline-flex;align-items:center;justify-content:center;gap:9px;background:#176b5b;color:#fff;border:0;padding:14px 22px;min-width:190px;font-family:inherit;font-size:14px;font-weight:700;cursor:pointer}.product-content{max-width:900px;margin:55px auto 0;line-height:1.75}.product-content pre,.product-content code{font:inherit;white-space:normal}.product-content pre{margin:0}
|
||||
.social-share-bar{display:flex;align-items:center;gap:10px;margin-top:22px}.social-share-bar a,.social-floating-bar a{width:32px;height:32px;border-radius:50%;display:grid;place-items:center;background:#18221f;color:#fff;font:bold 13px Arial,sans-serif}.social-share-bar a[data-platform="FACEBOOK"],.social-floating-bar a[data-platform="FACEBOOK"]{background:#1877f2}.social-share-bar a[data-platform="LINKEDIN"],.social-floating-bar a[data-platform="LINKEDIN"]{background:#0a66c2}.social-share-bar a[data-platform="YOUTUBE"],.social-floating-bar a[data-platform="YOUTUBE"]{background:#f00}.social-share-bar a[data-platform="WHATSAPP"],.social-floating-bar a[data-platform="WHATSAPP"]{background:#25d366}.social-share-bar a[data-platform="PINTEREST"],.social-floating-bar a[data-platform="PINTEREST"]{background:#bd081c}.social-share-bar a[data-platform="LINE"],.social-floating-bar a[data-platform="LINE"]{background:#06c755}.social-floating-bar{position:fixed;z-index:20;right:22px;top:50%;transform:translateY(-50%);display:grid;gap:10px;padding:12px 9px;background:#171b1a;border-radius:22px;box-shadow:0 10px 28px #10161438}.social-floating-bar a{width:34px;height:34px}.social-floating-bar a:hover,.social-share-bar a:hover{transform:translateY(-2px)}
|
||||
.modal-open{overflow:hidden}.inquiry-modal-backdrop{position:fixed;inset:0;z-index:1000;background:#101a18a8;display:grid;place-items:center;padding:24px}.inquiry-modal{position:relative;width:min(860px,100%);max-height:calc(100vh - 48px);overflow:auto;background:#fff;box-shadow:0 18px 60px #07100e40}.inquiry-modal-close{position:absolute;z-index:2;top:18px;right:18px;width:42px;height:42px;border:1px solid #d5ddda;background:#fff;color:#17211f;display:grid;place-items:center;cursor:pointer}.inquiry-modal .inquiry-box{margin:0;border-top:0;padding:42px}.inquiry-modal .inquiry-box h2{padding-right:50px}
|
||||
.content {
|
||||
font-size: 17px;
|
||||
@@ -454,7 +455,8 @@ footer small {
|
||||
.detail h1 {
|
||||
font-size: 42px;
|
||||
}
|
||||
.product-overview{grid-template-columns:1fr;gap:24px}.product-thumbnails{display:flex;overflow-x:auto}.product-thumbnail{width:72px;min-width:72px}.product-summary{padding:0}.product-summary h1{font-size:36px}.product-inquiry-cta{width:100%;box-sizing:border-box}.product-attributes{margin-top:45px}.product-content{margin-top:40px}
|
||||
.product-overview{grid-template-columns:1fr;gap:24px}.product-thumbnails{display:flex;overflow-x:auto}.product-thumbnail{width:72px;min-width:72px}.product-summary{padding:0}.product-summary h1{font-size:36px}.product-information dl>div{grid-template-columns:100px minmax(0,1fr)}.product-inquiry-cta{width:100%;box-sizing:border-box}.product-content{margin-top:40px}
|
||||
.social-floating-bar{right:10px;top:auto;bottom:18px;transform:none;display:flex;padding:8px}.social-floating-bar a{width:32px;height:32px}
|
||||
footer {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user