修复Salon对象存储头像展示

This commit is contained in:
2026-11-01 00:41:51 +08:00
parent e52e04685d
commit f30abbc26c
29 changed files with 229 additions and 28 deletions
@@ -700,7 +700,7 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
return null;
}
String accessibleUrl = objectStorageUrlSupport.toAccessibleUrl(avatar);
return StringUtils.hasText(accessibleUrl) ? accessibleUrl : avatar;
return StringUtils.hasText(accessibleUrl) ? accessibleUrl : null;
}
/**
@@ -1,6 +1,8 @@
package com.xiaowang.jayucloud.salon.core.modules.file.support;
import com.xiaowang.jayucloud.salon.core.config.ObjectStorageProperties;
import com.xiaowang.jayucloud.salon.core.modules.file.config.AliyunOssConfig;
import com.xiaowang.jayucloud.salon.core.modules.file.config.MinioStorageConfig;
import com.xiaowang.jayucloud.salon.core.modules.file.config.QiniuKodoConfig;
import com.xiaowang.jayucloud.salon.core.modules.file.service.AliyunOssService;
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageOrchestrationService;
@@ -21,6 +23,8 @@ public class ObjectStorageUrlSupport {
private static final int UPLOAD_STATUS_SUCCEEDED = 1;
private final PrimaryObjectStorageService primaryObjectStorageService;
private final MinioStorageConfig minioStorageConfig;
private final AliyunOssConfig aliyunOssConfig;
private final QiniuKodoConfig qiniuKodoConfig;
private final AliyunOssService aliyunOssService;
private final ObjectStorageProperties objectStorageProperties;
@@ -32,7 +36,7 @@ public class ObjectStorageUrlSupport {
}
String objectName = extractObjectName(fileUrl);
if (!StringUtils.hasText(objectName)) {
return fileUrl;
return isKnownStorageUrl(fileUrl) ? null : fileUrl;
}
try {
return objectStorageOrchestrationService.getPresignedUrl(
@@ -116,6 +120,9 @@ public class ObjectStorageUrlSupport {
}
String normalizedUrl = fileUrl.trim();
if (normalizedUrl.startsWith("oss://")) {
return extractBucketObjectName(normalizedUrl.substring("oss://".length()), aliyunOssConfig.getBucketName());
}
if (!normalizedUrl.startsWith("http://") && !normalizedUrl.startsWith("https://")) {
return stripQuery(stripLeadingSlash(normalizedUrl));
}
@@ -123,10 +130,17 @@ public class ObjectStorageUrlSupport {
try {
URI fileUri = URI.create(normalizedUrl);
URI domainUri = URI.create(normalizeDomain(qiniuKodoConfig.getDomain()));
if (!sameAuthority(fileUri, domainUri)) {
return "";
if (sameAuthority(fileUri, domainUri)) {
return stripQuery(stripLeadingSlash(fileUri.getPath()));
}
return stripQuery(stripLeadingSlash(fileUri.getPath()));
if (sameConfiguredAuthority(fileUri, minioStorageConfig.getEndpoint())
|| sameConfiguredAuthority(fileUri, minioStorageConfig.getPublicEndpoint())) {
return extractBucketObjectName(fileUri.getPath(), minioStorageConfig.getBucketName());
}
if (sameConfiguredAuthority(fileUri, aliyunOssConfig.getEndpoint())) {
return extractBucketObjectName(fileUri.getPath(), aliyunOssConfig.getBucketName());
}
return "";
} catch (Exception e) {
log.warn("解析对象存储链接失败, fileUrl={}", fileUrl, e);
return "";
@@ -163,6 +177,9 @@ public class ObjectStorageUrlSupport {
}
private String normalizeDomain(String domain) {
if (!StringUtils.hasText(domain)) {
return "";
}
String normalized = domain.trim();
while (normalized.endsWith("/")) {
normalized = normalized.substring(0, normalized.length() - 1);
@@ -174,13 +191,55 @@ public class ObjectStorageUrlSupport {
}
private boolean sameAuthority(URI left, URI right) {
return left.getScheme() != null
&& left.getScheme().equalsIgnoreCase(right.getScheme())
return right != null
&& left.getHost() != null
&& right.getHost() != null
&& left.getHost().equalsIgnoreCase(right.getHost())
&& normalizedPort(left) == normalizedPort(right);
}
private boolean sameConfiguredAuthority(URI fileUri, String endpoint) {
if (!StringUtils.hasText(endpoint)) {
return false;
}
try {
return sameAuthority(fileUri, URI.create(normalizeDomain(endpoint)));
} catch (Exception ignored) {
return false;
}
}
private String extractBucketObjectName(String rawPath, String bucketName) {
String path = stripQuery(stripLeadingSlash(rawPath));
if (!StringUtils.hasText(path) || !StringUtils.hasText(bucketName)) {
return "";
}
String bucketPrefix = bucketName.trim() + "/";
return path.startsWith(bucketPrefix) ? path.substring(bucketPrefix.length()) : path;
}
private boolean isKnownStorageUrl(String fileUrl) {
if (!StringUtils.hasText(fileUrl)) {
return false;
}
String normalized = fileUrl.trim();
if (normalized.startsWith("oss://")) {
return true;
}
if (!normalized.startsWith("http://") && !normalized.startsWith("https://")) {
return false;
}
try {
URI uri = URI.create(normalized);
return sameConfiguredAuthority(uri, qiniuKodoConfig.getDomain())
|| sameConfiguredAuthority(uri, minioStorageConfig.getEndpoint())
|| sameConfiguredAuthority(uri, minioStorageConfig.getPublicEndpoint())
|| sameConfiguredAuthority(uri, aliyunOssConfig.getEndpoint());
} catch (Exception ignored) {
return false;
}
}
private int normalizedPort(URI uri) {
if (uri.getPort() >= 0) {
return uri.getPort();
@@ -30,6 +30,7 @@ import com.xiaowang.jayucloud.salon.core.modules.order.service.OrderService;
import com.xiaowang.jayucloud.salon.core.modules.planning.service.PlanningService;
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
import com.xiaowang.jayucloud.salon.core.modules.order.support.OrderStatus;
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.salon.core.modules.planning.support.PlanningCalendarSupport;
import com.xiaowang.jayucloud.salon.core.modules.planning.support.PlanningTodayOverviewSupport;
import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator;
@@ -96,6 +97,7 @@ public class PlanningServiceImpl implements PlanningService {
private final AppointmentCapacityService appointmentCapacityService;
private final OrderService orderService;
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
private final ObjectStorageUrlSupport objectStorageUrlSupport;
@Override
public PlanningCalendarVO getCalendar(UserDO currentUser, LocalDate startDate, LocalDate endDate, Long artistId) {
@@ -425,7 +427,7 @@ public class PlanningServiceImpl implements PlanningService {
vo.setName(firstNonBlank(user.getNickname(), user.getAccount(), "美甲师" + (i + 1)));
vo.setShortName(PlanningCalendarSupport.shortName(vo.getName()));
vo.setPhone(firstNonBlank(user.getContactPhone(), user.getPhone(), ""));
vo.setAvatar(user.getAvatar());
vo.setAvatar(objectStorageUrlSupport.toAccessibleUrl(user.getAvatar()));
vo.setColor(info != null && StringUtils.hasText(info.getColor())
? info.getColor() : colorForArtist(user.getId(), i));
vo.setStatus(info == null || info.getStatus() == null ? user.getStatus() : info.getStatus());
@@ -31,6 +31,7 @@ import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserMapper;
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
import com.xiaowang.jayucloud.salon.core.modules.system.service.SystemParameterConfigService;
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageFileService;
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.salon.core.modules.file.vo.ObjectStorageFileVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@@ -64,6 +65,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
private final TransactionTemplate transactionTemplate;
private final WechatMiniBindingMapper wechatMiniBindingMapper;
private final ObjectStorageFileService objectStorageFileService;
private final ObjectStorageUrlSupport objectStorageUrlSupport;
public WorkbenchRegistrationServiceImpl(
WorkbenchRegistrationApplicationMapper applicationMapper,
@@ -79,7 +81,8 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
ShopBusinessExpiryService shopBusinessExpiryService,
PlatformTransactionManager transactionManager,
WechatMiniBindingMapper wechatMiniBindingMapper,
ObjectStorageFileService objectStorageFileService
ObjectStorageFileService objectStorageFileService,
ObjectStorageUrlSupport objectStorageUrlSupport
) {
this.applicationMapper = applicationMapper;
this.userMapper = userMapper;
@@ -95,6 +98,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
this.transactionTemplate = new TransactionTemplate(transactionManager);
this.wechatMiniBindingMapper = wechatMiniBindingMapper;
this.objectStorageFileService = objectStorageFileService;
this.objectStorageUrlSupport = objectStorageUrlSupport;
}
@Override
@@ -324,7 +328,8 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
if (request != null && Boolean.TRUE.equals(request.getUseApplicantAvatar()) && application.getApplicantAvatarFileId() != null) {
requireApplicantProfileApproved(application);
ObjectStorageFileVO file = contentModerationFile(application.getApplicantAvatarFileId());
target.setAvatar(file.getFileUrl());
target.setAvatar(objectStorageUrlSupport.toStoredUrl(StringUtils.hasText(file.getObjectName())
? file.getObjectName() : file.getFileUrl()));
}
target.setStatus(1);
userMapper.updateById(target);
@@ -367,7 +372,8 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
return users.stream()
.filter(user -> !hasActiveWechatBinding(user.getId()))
.filter(user -> !hasPendingAssociation(user.getId(), applicationId))
.map(user -> new WorkbenchRegistrationArtistVO(user.getId(), user.getNickname(), user.getAvatar()))
.map(user -> new WorkbenchRegistrationArtistVO(user.getId(), user.getNickname(),
objectStorageUrlSupport.toAccessibleUrl(user.getAvatar())))
.collect(Collectors.toList());
}
@@ -0,0 +1,61 @@
package com.xiaowang.jayucloud.salon.core.modules.file.support;
import com.xiaowang.jayucloud.salon.core.config.ObjectStorageProperties;
import com.xiaowang.jayucloud.salon.core.modules.file.config.AliyunOssConfig;
import com.xiaowang.jayucloud.salon.core.modules.file.config.MinioStorageConfig;
import com.xiaowang.jayucloud.salon.core.modules.file.config.QiniuKodoConfig;
import com.xiaowang.jayucloud.salon.core.modules.file.service.AliyunOssService;
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageOrchestrationService;
import com.xiaowang.jayucloud.salon.core.modules.file.service.PrimaryObjectStorageService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class ObjectStorageUrlSupportTest {
private ObjectStorageUrlSupport support;
private ObjectStorageOrchestrationService orchestrationService;
@BeforeEach
void setUp() {
MinioStorageConfig minio = new MinioStorageConfig();
minio.setEndpoint("http://192.168.10.14:9000");
minio.setPublicEndpoint("https://sit.minio.yunail.art");
minio.setBucketName("jayucloud-salon-sit");
AliyunOssConfig aliyun = new AliyunOssConfig();
aliyun.setEndpoint("https://oss-cn-hangzhou.aliyuncs.com");
aliyun.setBucketName("salon");
QiniuKodoConfig qiniu = new QiniuKodoConfig();
qiniu.setDomain("https://sit.qiniu.yunail.art");
ObjectStorageProperties properties = new ObjectStorageProperties();
properties.setSignedUrlExpireMinutes(60);
orchestrationService = mock(ObjectStorageOrchestrationService.class);
support = new ObjectStorageUrlSupport(mock(PrimaryObjectStorageService.class), minio, aliyun,
qiniu, mock(AliyunOssService.class), properties, orchestrationService);
}
@Test
void extractsObjectNameFromMinioInternalAndPublicUrls() {
assertEquals("avatar/7/photo.jpg", support.extractObjectName(
"http://192.168.10.14:9000/jayucloud-salon-sit/avatar/7/photo.jpg"));
assertEquals("avatar/7/photo.jpg", support.extractObjectName(
"https://sit.minio.yunail.art/jayucloud-salon-sit/avatar/7/photo.jpg?X-Amz-Signature=test"));
}
@Test
void keepsQiniuAndOssReferencesSupported() {
assertEquals("avatar/7/photo.jpg", support.extractObjectName("https://sit.qiniu.yunail.art/avatar/7/photo.jpg"));
assertEquals("avatar/7/photo.jpg", support.extractObjectName("oss://salon/avatar/7/photo.jpg"));
}
@Test
void doesNotReturnKnownPrivateUrlWhenSigningFails() {
when(orchestrationService.getPresignedUrl("avatar/7/photo.jpg", 60))
.thenThrow(new IllegalStateException("storage unavailable"));
assertNull(support.toAccessibleUrl("https://sit.minio.yunail.art/jayucloud-salon-sit/avatar/7/photo.jpg"));
}
}
@@ -15,6 +15,7 @@ import com.xiaowang.jayucloud.salon.core.modules.planning.dto.PlanningAppointmen
import com.xiaowang.jayucloud.salon.core.modules.planning.dto.PlanningBackfillOrderCreateDTO;
import com.xiaowang.jayucloud.salon.core.modules.planning.mapper.AppointmentReservationMapper;
import com.xiaowang.jayucloud.salon.core.modules.planning.service.AppointmentCapacityService;
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.salon.core.modules.product.mapper.ProductMapper;
import com.xiaowang.jayucloud.salon.core.modules.product.entity.ProductDO;
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
@@ -61,6 +62,7 @@ class PlanningServiceImplTest {
@Mock private AppointmentCapacityService appointmentCapacityService;
@Mock private OrderService orderService;
@Mock private TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
@Mock private ObjectStorageUrlSupport objectStorageUrlSupport;
private PlanningServiceImpl service;
@@ -68,7 +70,8 @@ class PlanningServiceImplTest {
void setUp() {
service = new PlanningServiceImpl(adminScopeHelper, userMapper, userService, nailArtistInfoMapper, artistScheduleMapper,
artistScheduleExceptionMapper, appointmentReservationMapper, orderMapper, orderItemMapper,
productMapper, shopMapper, shopBusinessExpiryService, appointmentCapacityService, orderService, snowflakeIdGenerator);
productMapper, shopMapper, shopBusinessExpiryService, appointmentCapacityService, orderService, snowflakeIdGenerator,
objectStorageUrlSupport);
}
@Test
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.xiaowang.jayucloud.salon.core.modules.integration.service.WechatMiniAuthService;
import com.xiaowang.jayucloud.salon.core.modules.integration.mapper.WechatMiniBindingMapper;
import com.xiaowang.jayucloud.salon.core.modules.file.service.ObjectStorageFileService;
import com.xiaowang.jayucloud.salon.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.salon.core.modules.privacy.moderation.LocalMockContentModerationProvider;
import com.xiaowang.jayucloud.salon.core.modules.privacy.moderation.ModerationOutcome;
import com.xiaowang.jayucloud.salon.core.modules.privacy.entity.ContentModerationRecordDO;
@@ -57,6 +58,7 @@ class WorkbenchRegistrationServiceImplTest {
@Mock private PlatformTransactionManager transactionManager;
@Mock private WechatMiniBindingMapper wechatMiniBindingMapper;
@Mock private ObjectStorageFileService objectStorageFileService;
@Mock private ObjectStorageUrlSupport objectStorageUrlSupport;
private WorkbenchRegistrationServiceImpl service;
@@ -65,7 +67,7 @@ class WorkbenchRegistrationServiceImplTest {
service = new WorkbenchRegistrationServiceImpl(applicationMapper, userMapper, shopMapper, userService,
userShopBindingSupport, userShopBindingMapper, wechatMiniAuthService, systemParameterConfigService,
contentModerationService, contentModerationRecordMapper, shopBusinessExpiryService, transactionManager,
wechatMiniBindingMapper, objectStorageFileService);
wechatMiniBindingMapper, objectStorageFileService, objectStorageUrlSupport);
}
@Test
@@ -33,6 +33,12 @@ Component({
if (item) this.triggerEvent('select', { item })
},
onAvatarError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isInteger(index) || !this.data.items[index]) return
this.setData({ [`items[${index}].avatar`]: '' })
},
retry() {
this.triggerEvent('retry')
},
@@ -30,7 +30,7 @@
<view wx:elif="{{items.length === 0}}" class="selector-state">{{emptyText}}</view>
<view wx:else class="selector-list {{viewMode === 'card' ? 'card-view' : ''}}">
<view wx:for="{{items}}" wx:key="id" class="selector-item {{selectedId == item.id ? 'selected' : ''}} {{viewMode === 'card' ? 'card-view' : ''}}" data-index="{{index}}" bindtap="selectItem">
<image wx:if="{{item.avatar}}" class="selector-avatar" src="{{item.avatar}}" mode="aspectFill"></image>
<image wx:if="{{item.avatar}}" class="selector-avatar" src="{{item.avatar}}" mode="aspectFill" data-index="{{index}}" binderror="onAvatarError"></image>
<view class="selector-copy {{item.avatar ? '' : 'without-avatar'}}">
<view class="selector-title-row">
<text class="selector-item-title">{{item.title}}</text>
@@ -25,6 +25,14 @@ Component({
const item = this.data.items[Number(event.currentTarget.dataset.index)]
if (item) this.triggerEvent('select', { item })
},
onCoverImageError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isInteger(index) || !this.data.items[index]) return
this.setData({ [`items[${index}].coverImage`]: '' })
},
onManualImageError() {
this.setData({ manualImageUrl: '' })
},
openManual() { this.triggerEvent('openmanual') },
backToList() { this.triggerEvent('backtolist') },
onManualInput(event) {
@@ -12,7 +12,7 @@
<view wx:elif="{{items.length === 0}}" class="product-selector-state">{{emptyText}}</view>
<view wx:else class="product-selector-list">
<view wx:for="{{items}}" wx:key="id" class="product-selector-item {{selectedId == item.id ? 'selected' : ''}}" data-index="{{index}}" bindtap="selectItem">
<image wx:if="{{item.coverImage}}" class="product-selector-cover" src="{{item.coverImage}}" mode="aspectFill"></image><view wx:else class="product-selector-cover placeholder">图</view>
<image wx:if="{{item.coverImage}}" class="product-selector-cover" src="{{item.coverImage}}" mode="aspectFill" data-index="{{index}}" binderror="onCoverImageError"></image><view wx:else class="product-selector-cover placeholder">图</view>
<view class="product-selector-copy"><view class="product-selector-name-row"><text class="product-selector-name">{{item.title}}</text><text class="product-selector-price">{{item.priceText || (item.price == null ? '价格待定' : '¥' + item.price)}}</text></view><text class="product-selector-meta">{{item.durationText || '时长待定'}} · {{item.artistText || '全部美甲师'}}</text><view class="product-selector-tags"><text wx:for="{{item.tagList}}" wx:for-item="tag" wx:key="*this">{{tag}}</text></view></view><text class="product-selector-check">{{selectedId == item.id ? '✓' : '›'}}</text>
</view>
</view>
@@ -22,7 +22,7 @@
<block wx:else>
<scroll-view class="product-selector-scroll manual" scroll-y enhanced show-scrollbar="{{false}}">
<view class="manual-product-card"><view class="manual-product-grid"><input value="{{manualForm.title}}" data-field="title" bindinput="onManualInput" placeholder="作品名称" /><input value="{{manualForm.price}}" data-field="price" bindinput="onManualInput" type="digit" placeholder="价格" /></view><view wx:if="{{showManualExtra}}" class="manual-product-more" bindtap="toggleMore">{{manualMoreExpanded ? '⌃ 收起更多信息' : '⌄ 补充更多信息'}}</view></view>
<view wx:if="{{showManualExtra && manualMoreExpanded}}" class="manual-product-extra"><textarea value="{{manualForm.description}}" data-field="description" bindinput="onManualInput" placeholder="作品描述(选填)"></textarea><input value="{{manualForm.tags}}" data-field="tags" bindinput="onManualInput" placeholder="标签,多个用逗号分隔(选填)" /><input value="{{manualForm.targetAudience}}" data-field="targetAudience" bindinput="onManualInput" placeholder="适合人群(选填)" /><input value="{{manualForm.precautions}}" data-field="precautions" bindinput="onManualInput" placeholder="注意事项(选填)" /><view class="manual-product-image-row"><image wx:if="{{manualImageUrl}}" src="{{manualImageUrl}}" class="manual-product-image" mode="aspectFill"></image><view wx:else class="manual-product-image placeholder">图</view><button bindtap="chooseImage" loading="{{manualImageUploading}}">上传图片</button><button wx:if="{{manualImageUrl}}" bindtap="removeImage">移除</button></view></view>
<view wx:if="{{showManualExtra && manualMoreExpanded}}" class="manual-product-extra"><textarea value="{{manualForm.description}}" data-field="description" bindinput="onManualInput" placeholder="作品描述(选填)"></textarea><input value="{{manualForm.tags}}" data-field="tags" bindinput="onManualInput" placeholder="标签,多个用逗号分隔(选填)" /><input value="{{manualForm.targetAudience}}" data-field="targetAudience" bindinput="onManualInput" placeholder="适合人群(选填)" /><input value="{{manualForm.precautions}}" data-field="precautions" bindinput="onManualInput" placeholder="注意事项(选填)" /><view class="manual-product-image-row"><image wx:if="{{manualImageUrl}}" src="{{manualImageUrl}}" class="manual-product-image" mode="aspectFill" binderror="onManualImageError"></image><view wx:else class="manual-product-image placeholder">图</view><button bindtap="chooseImage" loading="{{manualImageUploading}}">上传图片</button><button wx:if="{{manualImageUrl}}" bindtap="removeImage">移除</button></view></view>
</scroll-view>
<view class="product-selector-footer manual-footer"><button class="product-selector-confirm" bindtap="confirmManual">使用此作品</button><button class="product-selector-back" bindtap="backToList">‹ 返回作品列表</button></view>
</block>
@@ -2065,6 +2065,10 @@ Page({
this.persistDraft(true)
},
onSelectedProductImageError() {
this.setData({ 'selectedProduct.coverImage': '' })
},
back() {
wx.navigateBack()
}
@@ -27,7 +27,7 @@
<text class="chevron">›</text>
</button>
<view wx:else class="selected-style-card" bindtap="openManualProduct">
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill"></image>
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill" binderror="onSelectedProductImageError"></image>
<view wx:else class="field-icon">✦</view>
<view class="selected-style-copy"><text class="selected-style-title">{{selectedProduct.title}}</text><text class="selected-style-meta">参考价 {{selectedProductPriceText || '待定'}} · 本次 {{form.amount || '待填'}} 元 · {{form.durationMinutes || '60'}} 分钟</text></view>
<button class="switch-manual-action" catchtap="openManualProduct">调整</button>
@@ -121,6 +121,7 @@ Page({
async chooseManualProductImage() { if (this.data.manualImageUploading) return; const remaining = 9 - (this.data.form.manualProductImages || []).length; if (remaining <= 0) { wx.showToast({ title: '最多添加9张图片', icon: 'none' }); return } try { this.setData({ manualImageUploading: true }); const paths = await chooseImages(remaining); for (const filePath of paths) { const result = await uploadObjectFile(filePath); const fileId = result.id || result.fileId; if (!fileId) throw new Error('图片上传成功但未返回文件ID'); this.setData(imagePatch((this.data.form.manualProductImages || []).concat({ fileId: String(fileId), fileUrl: result.fileUrl || result.primaryUrl || '', previewUrl: filePath }))) } } catch (error) { wx.showToast({ title: error.message || '图片上传失败', icon: 'none' }) } finally { this.setData({ manualImageUploading: false }) } },
removeManualProductImage(event) { const index = Number(event.currentTarget.dataset.index); this.setData(imagePatch((this.data.form.manualProductImages || []).filter((item, itemIndex) => itemIndex !== index))) },
onManualProductImageError(event) { const index = Number(event.currentTarget.dataset.index); const images = this.data.form.manualProductImages || []; if (!images[index] || !images[index].fileUrl) return; const fallback = images.slice(); fallback[index] = { ...fallback[index], previewUrl: fallback[index].fileUrl }; this.setData(imagePatch(fallback)) },
onSelectedProductImageError() { this.setData({ 'selectedProduct.coverImage': '' }) },
onInput(event) { const field = event.currentTarget.dataset.field; const value = event.detail.value; this.setData({ [`form.${field}`]: value, ...(field === 'amount' ? { 'manualProductDraft.price': value } : {}) }) },
onDateChange(event) { this.setData({ 'form.serviceDate': event.detail.value }) },
onTimeChange(event) { this.setData({ 'form.serviceTime': event.detail.value }) },
@@ -25,7 +25,7 @@
<text class="chevron">›</text>
</button>
<view wx:else class="selected-style-card" bindtap="openManualProduct">
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill"></image>
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill" binderror="onSelectedProductImageError"></image>
<view wx:else class="field-icon">✦</view>
<view class="selected-style-copy"><text class="selected-style-title">{{selectedProduct.title}}</text><text class="selected-style-meta">参考价 {{selectedProductPriceText || '待定'}} · 本次 {{form.amount || '待填'}} 元 · {{form.durationMinutes || '60'}} 分钟</text></view>
<button class="switch-manual-action" catchtap="openManualProduct">调整</button>
@@ -56,10 +56,11 @@ Page({
if (!filePath) return
this.setData({ avatarUploading: true })
const uploadResult = await uploadObjectFile(filePath)
const avatarUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
// 私有对象存储地址可能无法被小程序直接访问,上传完成后先用本地临时文件即时预览。
const storedAvatar = uploadResult.fileUrl || uploadResult.primaryUrl || ''
this.setData({
'form.avatar': avatarUrl,
'form.avatarUrl': avatarUrl
'form.avatar': storedAvatar,
'form.avatarUrl': filePath
})
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
@@ -72,6 +73,10 @@ Page({
this.setData({ 'form.avatar': '', 'form.avatarUrl': '' })
},
onAvatarError() {
this.setData({ 'form.avatarUrl': '' })
},
stopTouchMove() {
},
@@ -5,7 +5,7 @@
</view>
<view class="card avatar-card" bindtap="chooseAvatar">
<image wx:if="{{form.avatarUrl}}" class="avatar-preview" src="{{form.avatarUrl}}" mode="aspectFill"></image>
<image wx:if="{{form.avatarUrl}}" class="avatar-preview" src="{{form.avatarUrl}}" mode="aspectFill" binderror="onAvatarError"></image>
<image wx:else class="avatar-preview" src="/assets/images/default-user-avatar.png" mode="aspectFit"></image>
<view class="avatar-copy">
<text class="avatar-title">美甲师头像</text>
@@ -44,6 +44,10 @@ Page({
wx.navigateTo({ url: `${event.currentTarget.dataset.url}?id=${this.data.id}` })
},
onAvatarError() {
this.setData({ 'employee.avatar': '' })
},
back() {
wx.navigateBack()
}
@@ -5,7 +5,8 @@
</view>
<view wx:else class="card employee-head">
<view class="avatar" style="background: {{employee.color}};">{{employee.shortName}}</view>
<view wx:if="{{employee.avatar}}" class="avatar image-avatar" style="background: {{employee.color}};"><image src="{{employee.avatar}}" mode="aspectFill" binderror="onAvatarError"></image></view>
<view wx:else class="avatar" style="background: {{employee.color}};">{{employee.shortName}}</view>
<view>
<text class="employee-name">{{employee.name}}</text>
<text class="tag" style="background: {{employee.color}}; color: #fff;">美甲师色</text>
@@ -26,6 +26,12 @@
color: #fff;
font-size: 34rpx;
font-weight: 900;
overflow: hidden;
}
.image-avatar image {
width: 100%;
height: 100%;
}
.employee-name {
+12
View File
@@ -291,6 +291,18 @@ Page({
}
},
onEmployeeAvatarError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isInteger(index) || !this.data.employees[index]) return
this.setData({ [`employees[${index}].avatar`]: '' })
},
onReviewAvatarError(event) {
const index = Number(event.currentTarget.dataset.index)
if (!Number.isInteger(index) || !this.data.reviewApplications[index]) return
this.setData({ [`reviewApplications[${index}].applicantAvatar`]: '' })
},
openDetail(event) {
wx.navigateTo({ url: `/pages/employee-detail/index?id=${event.currentTarget.dataset.id}` })
},
+2 -2
View File
@@ -20,7 +20,7 @@
<view wx:elif="{{reviewApplications.length === 0}}" class="review-state">暂无待审核美甲师申请</view>
<view wx:else class="review-list">
<view wx:for="{{reviewApplications}}" wx:key="id" class="review-item">
<image class="review-avatar" src="{{item.applicantAvatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill"></image>
<image class="review-avatar" src="{{item.applicantAvatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill" data-index="{{index}}" binderror="onReviewAvatarError"></image>
<view class="review-info">
<text class="review-name">{{item.applicantDisplayName}}</text>
<text wx:if="{{item.targetArtistUserId}}" class="review-meta">已预关联美甲师</text>
@@ -45,7 +45,7 @@
<view wx:for="{{employees}}" wx:key="id" class="card employee-card" data-id="{{item.id}}" bindtap="openDetail">
<view class="employee-left">
<view wx:if="{{item.avatar}}" class="avatar image-avatar">
<image src="{{item.avatar}}" mode="aspectFill"></image>
<image src="{{item.avatar}}" mode="aspectFill" data-index="{{index}}" binderror="onEmployeeAvatarError"></image>
</view>
<view wx:else class="avatar" style="background: {{item.color}};">{{item.shortName}}</view>
<view>
+4
View File
@@ -331,6 +331,10 @@ Page({
this.loadCalendar()
},
onProfileAvatarError() {
this.setData({ 'profileForm.avatar': '' })
},
selectWeekDate(event) {
const appointmentDate = dateUtil.formatDate(event.currentTarget.dataset.date)
const target = toLocalDate(appointmentDate)
+1 -1
View File
@@ -44,7 +44,7 @@
<view class="profile-prompt">
<text class="profile-prompt-title">完善你的工作名片</text><text class="profile-prompt-desc">头像和昵称会用于门店协作展示,可暂时跳过。</text>
<button class="wechat-avatar" open-type="chooseAvatar" bindchooseavatar="chooseWechatAvatar" disabled="{{profileSaving}}">
<image class="wechat-avatar-image {{profileForm.avatar ? 'is-real' : 'is-default'}}" src="{{profileForm.avatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill"></image>
<image class="wechat-avatar-image {{profileForm.avatar ? 'is-real' : 'is-default'}}" src="{{profileForm.avatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill" binderror="onProfileAvatarError"></image>
<view class="wechat-avatar-hint">{{profileSaving ? '上传中' : '点击更换'}}</view>
</button>
<input class="wechat-nickname" type="nickname" value="{{profileForm.nickname}}" bindinput="onNicknameInput" placeholder="填写微信昵称" />
@@ -139,6 +139,10 @@ Page({
}
},
onAvatarImageError() {
this.setData({ 'form.avatar': '' })
},
async chooseWechatAvatar(event) {
if (this.data.loading || this.data.avatarUploading || this.data.saving) return
try {
@@ -3,7 +3,7 @@
<view class="card avatar-card">
<view class="avatar-preview" bindtap="chooseAvatar">
<image wx:if="{{form.avatar}}" src="{{form.avatar}}" mode="aspectFill"></image>
<image wx:if="{{form.avatar}}" src="{{form.avatar}}" mode="aspectFill" binderror="onAvatarImageError"></image>
<text wx:else class="avatar-letter">{{avatarText}}</text>
<view class="avatar-change-tip">{{avatarUploading ? '上传中' : '点击更换'}}</view>
</view>
+4
View File
@@ -90,6 +90,10 @@ Page({
wx.navigateTo({ url: event.currentTarget.dataset.url })
},
onProfileAvatarError() {
this.setData({ 'profileCard.avatar': '' })
},
async loadProfile() {
try {
const profile = await profileCache.getProfile()
+1 -1
View File
@@ -2,7 +2,7 @@
<view class="card profile-card">
<view class="profile-main">
<view class="account-avatar">
<image wx:if="{{profileCard.avatar}}" src="{{profileCard.avatar}}" mode="aspectFill"></image>
<image wx:if="{{profileCard.avatar}}" src="{{profileCard.avatar}}" mode="aspectFill" binderror="onProfileAvatarError"></image>
<text wx:else>{{profileCard.avatarText}}</text>
</view>
<view class="profile-copy">
+9
View File
@@ -1,5 +1,14 @@
# 项目变更记录
## 2026-11-01 Salon 对象存储头像与文件展示修复
- 修复 DEV/SIT 使用 MinIO 时,数据库中的内网或公共 MinIO 地址无法解析对象名,导致头像、作品和其他文件不能生成可访问签名地址的问题;统一支持 MinIO 内网端点、MinIO 公共端点、七牛域名和 OSS 引用。
- 已识别的私有对象存储地址在签名失败时不再原样返回,避免小程序拿到不可访问或不应公开的内网地址;外部默认头像仍保持兼容。
- 日程员工列表、注册审核候选美甲师统一使用可访问头像地址;审核采用申请头像时保存规范化存储地址,避免把临时/内网 URL 写入员工资料。
- 小程序新增美甲师上传后优先使用本地临时文件预览;员工列表、员工详情、审核关联选择器、作品选择器、预约/补录款式图片和个人资料头像增加加载失败回退。
- 新增 `JC-Salon-Core/src/test/java/com/xiaowang/jayucloud/salon/core/modules/file/support/ObjectStorageUrlSupportTest.java`,覆盖 MinIO 内外网 URL、七牛、OSS 解析及签名失败不泄露私有地址;该测试目录受仓库 `test/` 忽略规则影响,提交时需显式纳入。
- Core 对象存储、日程、注册关联相关测试 29 项通过;小程序相关测试及 JavaScript 语法检查通过。
## 2026-10-30 Salon 安全接入配置服务启动循环修复
- 安全接入配置服务不再依赖 `AdminScopeHelper` / `UserServiceImpl`,改为在服务边界校验调用方必须为平台管理员 `type = 4`,保留配置读取和写入的管理员门禁。