功能:改造Salon小程序OpenID快捷登录
This commit is contained in:
+5
-1
@@ -44,7 +44,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||||||
"/user/refresh-token",
|
"/user/refresh-token",
|
||||||
"/user/send-verification-code",
|
"/user/send-verification-code",
|
||||||
"/user/phone-login",
|
"/user/phone-login",
|
||||||
"/user/wechat-mini/**",
|
"/user/wechat-mini/auto-login",
|
||||||
|
"/user/wechat-mini/phone-login",
|
||||||
|
"/user/wechat-mini/confirm-login",
|
||||||
|
"/user/wechat-mini/status",
|
||||||
|
"/user/wechat-mini/quick-login",
|
||||||
"/user/workbench/register/**",
|
"/user/workbench/register/**",
|
||||||
"/user/workbench/shops/available",
|
"/user/workbench/shops/available",
|
||||||
"/user/reset-password-by-phone",
|
"/user/reset-password-by-phone",
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package com.xiaowang.jacyucloudsalon.core.modules.integration.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/** 微信小程序一键绑定手机号请求。 */
|
||||||
|
@Data
|
||||||
|
public class WechatMiniBindPhoneRequestDTO {
|
||||||
|
@NotBlank(message = "微信手机号凭证不能为空")
|
||||||
|
private String phoneCode;
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.xiaowang.jacyucloudsalon.core.modules.integration.dto;
|
||||||
|
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.common.dto.AgreementAwareRequest;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/** 微信小程序 OpenID 快捷登录请求。 */
|
||||||
|
@Data
|
||||||
|
public class WechatMiniQuickLoginRequestDTO implements AgreementAwareRequest {
|
||||||
|
@NotBlank(message = "微信登录凭证不能为空")
|
||||||
|
private String wxCode;
|
||||||
|
private Long preferredShopId;
|
||||||
|
private Boolean agreementAccepted;
|
||||||
|
private Map<String, String> agreementVersions;
|
||||||
|
private String clientType;
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.xiaowang.jacyucloudsalon.core.modules.integration.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/** 仅供后端消费的微信注册票据载荷。 */
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WechatMiniRegistrationTicket {
|
||||||
|
private Long userId;
|
||||||
|
private String appId;
|
||||||
|
private String openId;
|
||||||
|
}
|
||||||
+11
@@ -3,6 +3,9 @@ package com.xiaowang.jacyucloudsalon.core.modules.integration.service;
|
|||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniAutoLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniAutoLoginRequestDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniConfirmLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniConfirmLoginRequestDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniPhoneLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniPhoneLoginRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniQuickLoginRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniBindPhoneRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniRegistrationTicket;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.vo.WechatMiniLoginResultVO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.vo.WechatMiniLoginResultVO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,6 +13,14 @@ import com.xiaowang.jacyucloudsalon.core.modules.integration.vo.WechatMiniLoginR
|
|||||||
*/
|
*/
|
||||||
public interface WechatMiniAuthService {
|
public interface WechatMiniAuthService {
|
||||||
|
|
||||||
|
WechatMiniLoginResultVO status(WechatMiniAutoLoginRequestDTO requestDTO);
|
||||||
|
|
||||||
|
WechatMiniLoginResultVO quickLogin(WechatMiniQuickLoginRequestDTO requestDTO);
|
||||||
|
|
||||||
|
boolean bindPhone(Long userId, WechatMiniBindPhoneRequestDTO requestDTO);
|
||||||
|
|
||||||
|
WechatMiniRegistrationTicket consumeRegistrationTicket(String ticket);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run business method `autoLogin`.
|
* Run business method `autoLogin`.
|
||||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||||
|
|||||||
+175
@@ -8,6 +8,12 @@ import com.xiaowang.jacyucloudsalon.core.common.BusinessException;
|
|||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniAutoLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniAutoLoginRequestDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniConfirmLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniConfirmLoginRequestDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniPhoneLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniPhoneLoginRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniQuickLoginRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniBindPhoneRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniRegistrationTicket;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.entity.WorkbenchRegistrationApplicationDO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.entity.WorkbenchRegistrationStatus;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.mapper.WorkbenchRegistrationApplicationMapper;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.user.entity.UserDO;
|
import com.xiaowang.jacyucloudsalon.core.modules.user.entity.UserDO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.entity.WechatMiniBindingDO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.entity.WechatMiniBindingDO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.user.mapper.UserMapper;
|
import com.xiaowang.jacyucloudsalon.core.modules.user.mapper.UserMapper;
|
||||||
@@ -54,6 +60,7 @@ public class WechatMiniAuthServiceImpl implements WechatMiniAuthService {
|
|||||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||||
*/
|
*/
|
||||||
private static final String TICKET_KEY_PREFIX = "user:wechat-mini:login-ticket:";
|
private static final String TICKET_KEY_PREFIX = "user:wechat-mini:login-ticket:";
|
||||||
|
private static final String REGISTRATION_TICKET_KEY_PREFIX = "user:wechat-mini:registration-ticket:";
|
||||||
private static final Duration TICKET_TTL = Duration.ofMinutes(5);
|
private static final Duration TICKET_TTL = Duration.ofMinutes(5);
|
||||||
/**
|
/**
|
||||||
* Variable `wechatMiniClientService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
* Variable `wechatMiniClientService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||||
@@ -87,6 +94,124 @@ public class WechatMiniAuthServiceImpl implements WechatMiniAuthService {
|
|||||||
* Variable `snowflakeIdGenerator`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
* Variable `snowflakeIdGenerator`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
|
||||||
*/
|
*/
|
||||||
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
private final TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||||
|
private final WorkbenchRegistrationApplicationMapper registrationApplicationMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WechatMiniLoginResultVO status(WechatMiniAutoLoginRequestDTO requestDTO) {
|
||||||
|
WechatMiniClientService.SessionInfo sessionInfo = wechatMiniClientService.code2Session(requestDTO.getWxCode());
|
||||||
|
WechatMiniBindingDO binding = findAnyBindingByOpenId(sessionInfo.openId());
|
||||||
|
if (binding == null) {
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_NEW_USER, "当前微信尚未申请使用");
|
||||||
|
}
|
||||||
|
if (!Integer.valueOf(1).equals(binding.getStatus())) {
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_DISABLED, "微信身份关联已停用,请联系管理员");
|
||||||
|
}
|
||||||
|
UserDO user = userMapper.selectById(binding.getUserId());
|
||||||
|
if (user == null || Integer.valueOf(1).equals(user.getIsDelete())) {
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_DISABLED, "账号已失效,请联系管理员");
|
||||||
|
}
|
||||||
|
WorkbenchRegistrationApplicationDO application = findLatestApplication(user.getId());
|
||||||
|
if (application != null && WorkbenchRegistrationStatus.REJECTED.equals(application.getStatus())) {
|
||||||
|
return applicationState(WechatMiniLoginResultVO.STATUS_REJECTED, "申请已被驳回,可修改后重新提交", application);
|
||||||
|
}
|
||||||
|
if (application != null && (WorkbenchRegistrationStatus.PENDING_ADMIN.equals(application.getStatus())
|
||||||
|
|| WorkbenchRegistrationStatus.PENDING_MANAGER.equals(application.getStatus()))) {
|
||||||
|
return applicationState(WechatMiniLoginResultVO.STATUS_PENDING_REVIEW, "申请审核中", application);
|
||||||
|
}
|
||||||
|
if (Integer.valueOf(1).equals(user.getStatus())) {
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_READY, "账号可以登录");
|
||||||
|
}
|
||||||
|
if (Integer.valueOf(0).equals(user.getType()) && application == null) {
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_NEW_USER, "请继续完成身份申请");
|
||||||
|
}
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_DISABLED, "账号已停用,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public WechatMiniLoginResultVO quickLogin(WechatMiniQuickLoginRequestDTO requestDTO) {
|
||||||
|
WechatMiniClientService.SessionInfo sessionInfo = wechatMiniClientService.code2Session(requestDTO.getWxCode());
|
||||||
|
WechatMiniBindingDO binding = findAnyBindingByOpenId(sessionInfo.openId());
|
||||||
|
if (binding == null) {
|
||||||
|
UserDO user = new UserDO();
|
||||||
|
user.setNickname("微信用户" + snowflakeIdGenerator.nextIdString().substring(13));
|
||||||
|
user.setType(0);
|
||||||
|
user.setStatus(0);
|
||||||
|
user.setPhoneVerified(0);
|
||||||
|
user.setEmailVerified(0);
|
||||||
|
user.setIsDelete(0);
|
||||||
|
userMapper.insert(user);
|
||||||
|
ensureBinding(user.getId(), sessionInfo.openId(), sessionInfo.unionId());
|
||||||
|
return registrationResult(user.getId(), sessionInfo.openId(), null);
|
||||||
|
}
|
||||||
|
if (!Integer.valueOf(1).equals(binding.getStatus())) {
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_DISABLED, "微信身份关联已停用,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
UserDO user = userMapper.selectById(binding.getUserId());
|
||||||
|
if (user == null || Integer.valueOf(1).equals(user.getIsDelete())) {
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_DISABLED, "账号已失效,请联系管理员");
|
||||||
|
}
|
||||||
|
WorkbenchRegistrationApplicationDO application = findLatestApplication(user.getId());
|
||||||
|
if (application != null && WorkbenchRegistrationStatus.REJECTED.equals(application.getStatus())) {
|
||||||
|
return registrationResult(user.getId(), sessionInfo.openId(), application);
|
||||||
|
}
|
||||||
|
if (application != null && (WorkbenchRegistrationStatus.PENDING_ADMIN.equals(application.getStatus())
|
||||||
|
|| WorkbenchRegistrationStatus.PENDING_MANAGER.equals(application.getStatus()))) {
|
||||||
|
return applicationState(WechatMiniLoginResultVO.STATUS_PENDING_REVIEW, "申请审核中", application);
|
||||||
|
}
|
||||||
|
if (!Integer.valueOf(1).equals(user.getStatus())) {
|
||||||
|
if (Integer.valueOf(0).equals(user.getType()) && application == null) {
|
||||||
|
return registrationResult(user.getId(), sessionInfo.openId(), null);
|
||||||
|
}
|
||||||
|
return WechatMiniLoginResultVO.state(WechatMiniLoginResultVO.STATUS_DISABLED, "账号已停用,请联系管理员");
|
||||||
|
}
|
||||||
|
return loginOrSelectShop(user, normalizeShopId(requestDTO.getPreferredShopId()), sessionInfo, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean bindPhone(Long userId, WechatMiniBindPhoneRequestDTO requestDTO) {
|
||||||
|
UserDO user = userMapper.selectById(userId);
|
||||||
|
if (user == null || Integer.valueOf(1).equals(user.getIsDelete())) {
|
||||||
|
throw new BusinessException("用户不存在");
|
||||||
|
}
|
||||||
|
String phone = normalizePhone(wechatMiniClientService.getPhoneNumber(requestDTO.getPhoneCode()));
|
||||||
|
if (!phone.matches(PHONE_REGEX)) {
|
||||||
|
throw new BusinessException("获取到的微信手机号格式不正确");
|
||||||
|
}
|
||||||
|
UserDO occupied = findActiveUserByPhone(phone);
|
||||||
|
if (occupied != null && !Objects.equals(occupied.getId(), userId)) {
|
||||||
|
throw new BusinessException("该手机号已被其他账号绑定");
|
||||||
|
}
|
||||||
|
user.setPhone(phone);
|
||||||
|
user.setPhoneVerified(1);
|
||||||
|
userMapper.updateById(user);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WechatMiniRegistrationTicket consumeRegistrationTicket(String ticket) {
|
||||||
|
if (!StringUtils.hasText(ticket)) {
|
||||||
|
throw new BusinessException("注册票据不能为空");
|
||||||
|
}
|
||||||
|
String key = REGISTRATION_TICKET_KEY_PREFIX + ticket;
|
||||||
|
String payload = redisTemplate.opsForValue().get(key);
|
||||||
|
if (!StringUtils.hasText(payload) || !Boolean.TRUE.equals(redisTemplate.delete(key))) {
|
||||||
|
throw new BusinessException("注册票据已失效,请重新发起快捷登录");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
WechatMiniRegistrationTicket value = objectMapper.readValue(payload, WechatMiniRegistrationTicket.class);
|
||||||
|
WechatMiniBindingDO binding = findBindingByOpenId(value.getOpenId());
|
||||||
|
if (binding == null || !Objects.equals(binding.getUserId(), value.getUserId())
|
||||||
|
|| !Objects.equals(value.getAppId(), wechatMiniClientService.getConfiguredAppId())) {
|
||||||
|
throw new BusinessException("注册票据与微信身份不匹配");
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
} catch (JsonProcessingException exception) {
|
||||||
|
throw new BusinessException("解析微信注册票据失败", exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/**
|
||||||
@@ -225,6 +350,46 @@ public class WechatMiniAuthServiceImpl implements WechatMiniAuthService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WorkbenchRegistrationApplicationDO findLatestApplication(Long userId) {
|
||||||
|
return registrationApplicationMapper.selectOne(
|
||||||
|
new LambdaQueryWrapper<WorkbenchRegistrationApplicationDO>()
|
||||||
|
.eq(WorkbenchRegistrationApplicationDO::getUserId, userId)
|
||||||
|
.eq(WorkbenchRegistrationApplicationDO::getIsDelete, 0)
|
||||||
|
.orderByDesc(WorkbenchRegistrationApplicationDO::getCreateTime)
|
||||||
|
.last("limit 1")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private WechatMiniLoginResultVO applicationState(String status, String message,
|
||||||
|
WorkbenchRegistrationApplicationDO application) {
|
||||||
|
WechatMiniLoginResultVO result = WechatMiniLoginResultVO.state(status, message);
|
||||||
|
result.setRegistrationStatus(application.getStatus());
|
||||||
|
result.setRegistrationRejectReason(application.getRejectReason());
|
||||||
|
result.setRegistrationApplicationId(application.getId());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WechatMiniLoginResultVO registrationResult(Long userId, String openId,
|
||||||
|
WorkbenchRegistrationApplicationDO application) {
|
||||||
|
WechatMiniRegistrationTicket payload = new WechatMiniRegistrationTicket(
|
||||||
|
userId, wechatMiniClientService.getConfiguredAppId(), openId);
|
||||||
|
String ticket = "wxreg_" + snowflakeIdGenerator.nextIdString();
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForValue().set(REGISTRATION_TICKET_KEY_PREFIX + ticket,
|
||||||
|
objectMapper.writeValueAsString(payload), TICKET_TTL);
|
||||||
|
} catch (JsonProcessingException exception) {
|
||||||
|
throw new BusinessException("生成微信注册票据失败", exception);
|
||||||
|
}
|
||||||
|
WechatMiniLoginResultVO result = WechatMiniLoginResultVO.registration(
|
||||||
|
ticket,
|
||||||
|
application == null ? null : application.getStatus(),
|
||||||
|
application == null ? null : application.getRejectReason(),
|
||||||
|
application == null ? null : application.getId()
|
||||||
|
);
|
||||||
|
result.setConsentUserId(userId);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private WechatMiniLoginResultVO loginOrSelectShop(
|
private WechatMiniLoginResultVO loginOrSelectShop(
|
||||||
UserDO userDO,
|
UserDO userDO,
|
||||||
Long preferredShopId,
|
Long preferredShopId,
|
||||||
@@ -359,6 +524,16 @@ public class WechatMiniAuthServiceImpl implements WechatMiniAuthService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WechatMiniBindingDO findAnyBindingByOpenId(String openId) {
|
||||||
|
return wechatMiniBindingMapper.selectOne(
|
||||||
|
new LambdaQueryWrapper<WechatMiniBindingDO>()
|
||||||
|
.eq(WechatMiniBindingDO::getAppId, wechatMiniClientService.getConfiguredAppId())
|
||||||
|
.eq(WechatMiniBindingDO::getOpenId, openId)
|
||||||
|
.orderByDesc(WechatMiniBindingDO::getStatus)
|
||||||
|
.last("limit 1")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List records for the current query or current user scope.
|
* List records for the current query or current user scope.
|
||||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||||
|
|||||||
+28
@@ -1,5 +1,6 @@
|
|||||||
package com.xiaowang.jacyucloudsalon.core.modules.integration.vo;
|
package com.xiaowang.jacyucloudsalon.core.modules.integration.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -27,6 +28,12 @@ public class WechatMiniLoginResultVO {
|
|||||||
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||||
*/
|
*/
|
||||||
public static final String STATUS_NEED_MANUAL_LOGIN = "NEED_MANUAL_LOGIN";
|
public static final String STATUS_NEED_MANUAL_LOGIN = "NEED_MANUAL_LOGIN";
|
||||||
|
public static final String STATUS_NEW_USER = "NEW_USER";
|
||||||
|
public static final String STATUS_NEED_REGISTRATION = "NEED_REGISTRATION";
|
||||||
|
public static final String STATUS_PENDING_REVIEW = "PENDING_REVIEW";
|
||||||
|
public static final String STATUS_REJECTED = "REJECTED";
|
||||||
|
public static final String STATUS_READY = "READY";
|
||||||
|
public static final String STATUS_DISABLED = "DISABLED";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Field `status` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
* Field `status` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||||
@@ -72,6 +79,27 @@ public class WechatMiniLoginResultVO {
|
|||||||
private String registrationStatus;
|
private String registrationStatus;
|
||||||
private String registrationRejectReason;
|
private String registrationRejectReason;
|
||||||
private Long registrationApplicationId;
|
private Long registrationApplicationId;
|
||||||
|
@JsonIgnore
|
||||||
|
private Long consentUserId;
|
||||||
|
|
||||||
|
public static WechatMiniLoginResultVO state(String status, String message) {
|
||||||
|
WechatMiniLoginResultVO result = new WechatMiniLoginResultVO();
|
||||||
|
result.setStatus(status);
|
||||||
|
result.setMessage(message);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WechatMiniLoginResultVO registration(String ticket, String registrationStatus,
|
||||||
|
String rejectReason, Long applicationId) {
|
||||||
|
WechatMiniLoginResultVO result = state(STATUS_NEED_REGISTRATION, "请完善身份和门店资料并提交审核");
|
||||||
|
result.setNewUser(true);
|
||||||
|
result.setRegistrationRequired(true);
|
||||||
|
result.setRegistrationTicket(ticket);
|
||||||
|
result.setRegistrationStatus(registrationStatus);
|
||||||
|
result.setRegistrationRejectReason(rejectReason);
|
||||||
|
result.setRegistrationApplicationId(applicationId);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purpose: success supports WechatMiniLoginResultVO.java by holding or executing the success business role.
|
* Purpose: success supports WechatMiniLoginResultVO.java by holding or executing the success business role.
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ public class WorkbenchRegistrationController {
|
|||||||
this.shopMapper = shopMapper;
|
this.shopMapper = shopMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/register/phone")
|
@PostMapping({"/register/phone", "/register/wechat-mini"})
|
||||||
public Result<WorkbenchRegistrationStatusVO> registerByPhone(@RequestBody WorkbenchRegistrationRequestDTO request) {
|
public Result<WorkbenchRegistrationStatusVO> registerByPhone(@RequestBody WorkbenchRegistrationRequestDTO request) {
|
||||||
return Result.success(registrationService.register(request));
|
return Result.success(registrationService.register(request));
|
||||||
}
|
}
|
||||||
|
|||||||
-5
@@ -8,11 +8,6 @@ import lombok.Setter;
|
|||||||
public class WorkbenchRegistrationRequestDTO {
|
public class WorkbenchRegistrationRequestDTO {
|
||||||
private Long applicationId;
|
private Long applicationId;
|
||||||
private String registrationTicket;
|
private String registrationTicket;
|
||||||
private String wxCode;
|
|
||||||
private String phone;
|
|
||||||
private String verificationCode;
|
|
||||||
private String password;
|
|
||||||
private String confirmPassword;
|
|
||||||
private String roleType;
|
private String roleType;
|
||||||
private Long shopId;
|
private Long shopId;
|
||||||
private String shopName;
|
private String shopName;
|
||||||
|
|||||||
+43
-102
@@ -1,9 +1,6 @@
|
|||||||
package com.xiaowang.jacyucloudsalon.core.modules.registration.service.impl;
|
package com.xiaowang.jacyucloudsalon.core.modules.registration.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.auth.service.VerificationCodeService;
|
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.auth.service.PhoneRegistrationTicketService;
|
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.auth.vo.PhoneRegistrationTicketVO;
|
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.dto.WorkbenchRegistrationRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.dto.WorkbenchRegistrationRequestDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.entity.WorkbenchRegistrationApplicationDO;
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.entity.WorkbenchRegistrationApplicationDO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.entity.WorkbenchRegistrationRole;
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.entity.WorkbenchRegistrationRole;
|
||||||
@@ -11,9 +8,8 @@ import com.xiaowang.jacyucloudsalon.core.modules.registration.entity.WorkbenchRe
|
|||||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.mapper.WorkbenchRegistrationApplicationMapper;
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.mapper.WorkbenchRegistrationApplicationMapper;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.service.WorkbenchRegistrationService;
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.service.WorkbenchRegistrationService;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.registration.vo.WorkbenchRegistrationStatusVO;
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.vo.WorkbenchRegistrationStatusVO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.entity.WechatMiniBindingDO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.service.WechatMiniAuthService;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.mapper.WechatMiniBindingMapper;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniRegistrationTicket;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.service.WechatMiniClientService;
|
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.shop.entity.ShopDO;
|
import com.xiaowang.jacyucloudsalon.core.modules.shop.entity.ShopDO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.shop.mapper.ShopMapper;
|
import com.xiaowang.jacyucloudsalon.core.modules.shop.mapper.ShopMapper;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.shop.support.UserShopBindingSupport;
|
import com.xiaowang.jacyucloudsalon.core.modules.shop.support.UserShopBindingSupport;
|
||||||
@@ -22,7 +18,6 @@ import com.xiaowang.jacyucloudsalon.core.modules.shop.mapper.UserShopBindingMapp
|
|||||||
import com.xiaowang.jacyucloudsalon.core.modules.user.entity.UserDO;
|
import com.xiaowang.jacyucloudsalon.core.modules.user.entity.UserDO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.user.mapper.UserMapper;
|
import com.xiaowang.jacyucloudsalon.core.modules.user.mapper.UserMapper;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.user.service.UserService;
|
import com.xiaowang.jacyucloudsalon.core.modules.user.service.UserService;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@@ -33,106 +28,93 @@ import java.util.UUID;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationService {
|
public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationService {
|
||||||
private static final String REGISTER_SCENE = "PLANNING_MANAGER_REGISTER";
|
|
||||||
private final WorkbenchRegistrationApplicationMapper applicationMapper;
|
private final WorkbenchRegistrationApplicationMapper applicationMapper;
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
private final ShopMapper shopMapper;
|
private final ShopMapper shopMapper;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final VerificationCodeService verificationCodeService;
|
|
||||||
private final PhoneRegistrationTicketService phoneRegistrationTicketService;
|
|
||||||
private final UserShopBindingSupport userShopBindingSupport;
|
private final UserShopBindingSupport userShopBindingSupport;
|
||||||
private final UserShopBindingMapper userShopBindingMapper;
|
private final UserShopBindingMapper userShopBindingMapper;
|
||||||
private final WechatMiniBindingMapper wechatMiniBindingMapper;
|
private final WechatMiniAuthService wechatMiniAuthService;
|
||||||
private final WechatMiniClientService wechatMiniClientService;
|
|
||||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
|
||||||
|
|
||||||
public WorkbenchRegistrationServiceImpl(
|
public WorkbenchRegistrationServiceImpl(
|
||||||
WorkbenchRegistrationApplicationMapper applicationMapper,
|
WorkbenchRegistrationApplicationMapper applicationMapper,
|
||||||
UserMapper userMapper,
|
UserMapper userMapper,
|
||||||
ShopMapper shopMapper,
|
ShopMapper shopMapper,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
VerificationCodeService verificationCodeService,
|
|
||||||
PhoneRegistrationTicketService phoneRegistrationTicketService,
|
|
||||||
UserShopBindingSupport userShopBindingSupport,
|
UserShopBindingSupport userShopBindingSupport,
|
||||||
UserShopBindingMapper userShopBindingMapper,
|
UserShopBindingMapper userShopBindingMapper,
|
||||||
WechatMiniBindingMapper wechatMiniBindingMapper,
|
WechatMiniAuthService wechatMiniAuthService
|
||||||
WechatMiniClientService wechatMiniClientService
|
|
||||||
) {
|
) {
|
||||||
this.applicationMapper = applicationMapper;
|
this.applicationMapper = applicationMapper;
|
||||||
this.userMapper = userMapper;
|
this.userMapper = userMapper;
|
||||||
this.shopMapper = shopMapper;
|
this.shopMapper = shopMapper;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.verificationCodeService = verificationCodeService;
|
|
||||||
this.phoneRegistrationTicketService = phoneRegistrationTicketService;
|
|
||||||
this.userShopBindingSupport = userShopBindingSupport;
|
this.userShopBindingSupport = userShopBindingSupport;
|
||||||
this.userShopBindingMapper = userShopBindingMapper;
|
this.userShopBindingMapper = userShopBindingMapper;
|
||||||
this.wechatMiniBindingMapper = wechatMiniBindingMapper;
|
this.wechatMiniAuthService = wechatMiniAuthService;
|
||||||
this.wechatMiniClientService = wechatMiniClientService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public WorkbenchRegistrationStatusVO register(WorkbenchRegistrationRequestDTO request) {
|
public WorkbenchRegistrationStatusVO register(WorkbenchRegistrationRequestDTO request) {
|
||||||
require(request != null, "注册信息不能为空");
|
require(request != null, "注册信息不能为空");
|
||||||
String phone = requireText(request.getPhone(), "手机号不能为空");
|
|
||||||
PhoneRegistrationTicketVO ticket = null;
|
|
||||||
if (StringUtils.hasText(request.getRegistrationTicket())) {
|
|
||||||
ticket = phoneRegistrationTicketService.consume(request.getRegistrationTicket(), phone);
|
|
||||||
phone = ticket.getPhone();
|
|
||||||
} else {
|
|
||||||
require(verificationCodeService.verifyCode(phone, request.getVerificationCode()), "验证码错误或已过期");
|
|
||||||
}
|
|
||||||
String roleType = requireText(request.getRoleType(), "请选择注册身份").toUpperCase();
|
String roleType = requireText(request.getRoleType(), "请选择注册身份").toUpperCase();
|
||||||
require(WorkbenchRegistrationRole.MANAGER.equals(roleType) || WorkbenchRegistrationRole.STAFF.equals(roleType), "注册身份不合法");
|
require(WorkbenchRegistrationRole.MANAGER.equals(roleType) || WorkbenchRegistrationRole.STAFF.equals(roleType), "注册身份不合法");
|
||||||
require(request.getAgreementAccepted() == null || request.getAgreementAccepted(), "请先同意用户协议和隐私政策");
|
require(request.getAgreementAccepted() == null || request.getAgreementAccepted(), "请先同意用户协议和隐私政策");
|
||||||
UserDO existing = userMapper.selectOne(Wrappers.lambdaQuery(UserDO.class).eq(UserDO::getPhone, phone).eq(UserDO::getIsDelete, 0).last("limit 1"));
|
|
||||||
if (ticket != null) {
|
String managerShopName = WorkbenchRegistrationRole.MANAGER.equals(roleType)
|
||||||
require(ticket.getUserId() == null || existing != null && ticket.getUserId().equals(existing.getId()), "手机号注册凭证与账号不匹配");
|
? requireText(request.getShopName(), "店铺名称不能为空") : null;
|
||||||
|
ShopDO selectedStaffShop = null;
|
||||||
|
if (WorkbenchRegistrationRole.STAFF.equals(roleType)) {
|
||||||
|
require(request.getShopId() != null, "请选择要加入的店铺");
|
||||||
|
selectedStaffShop = shopMapper.selectOne(Wrappers.lambdaQuery(ShopDO.class).eq(ShopDO::getId, request.getShopId()).eq(ShopDO::getStatus, 1).eq(ShopDO::getIsDelete, 0));
|
||||||
|
require(selectedStaffShop != null, "店铺不存在或暂未营业");
|
||||||
|
}
|
||||||
|
|
||||||
|
WechatMiniRegistrationTicket ticket = wechatMiniAuthService.consumeRegistrationTicket(
|
||||||
|
requireText(request.getRegistrationTicket(), "注册票据不能为空"));
|
||||||
|
UserDO user = userMapper.selectById(ticket.getUserId());
|
||||||
|
require(user != null && !Integer.valueOf(1).equals(user.getIsDelete()), "注册用户不存在");
|
||||||
|
|
||||||
|
WorkbenchRegistrationApplicationDO application = request.getApplicationId() == null
|
||||||
|
? findLatest(user.getId()) : applicationMapper.selectById(request.getApplicationId());
|
||||||
|
if (application != null) {
|
||||||
|
require(user.getId().equals(application.getUserId()), "注册申请与账号不匹配");
|
||||||
|
require(WorkbenchRegistrationStatus.REJECTED.equals(application.getStatus()), "该注册申请当前不可重新提交");
|
||||||
} else {
|
} else {
|
||||||
require(existing == null, "该手机号已注册,请直接登录或查看审核状态");
|
application = new WorkbenchRegistrationApplicationDO();
|
||||||
}
|
|
||||||
boolean passwordProvided = StringUtils.hasText(request.getPassword()) || StringUtils.hasText(request.getConfirmPassword());
|
|
||||||
if (ticket == null) {
|
|
||||||
require(passwordProvided, "密码不能为空");
|
|
||||||
}
|
|
||||||
if (passwordProvided) {
|
|
||||||
require(request.getPassword().equals(request.getConfirmPassword()), "两次密码不一致");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ShopDO shop = null;
|
ShopDO shop = null;
|
||||||
if (WorkbenchRegistrationRole.MANAGER.equals(roleType)) {
|
if (WorkbenchRegistrationRole.MANAGER.equals(roleType)) {
|
||||||
String shopName = requireText(request.getShopName(), "店铺名称不能为空");
|
shop = WorkbenchRegistrationRole.MANAGER.equals(application.getRoleType()) && application.getShopId() != null
|
||||||
|
? shopMapper.selectById(application.getShopId()) : null;
|
||||||
|
if (shop == null) {
|
||||||
shop = new ShopDO();
|
shop = new ShopDO();
|
||||||
shop.setShopName(shopName);
|
}
|
||||||
|
shop.setShopName(managerShopName);
|
||||||
shop.setAddress(request.getShopAddress());
|
shop.setAddress(request.getShopAddress());
|
||||||
shop.setDescription("Salon店务工作台注册申请");
|
shop.setDescription("Salon店务工作台注册申请");
|
||||||
shop.setBusinessHours("10:00-22:00");
|
shop.setBusinessHours("10:00-22:00");
|
||||||
shop.setStatus(0);
|
shop.setStatus(0);
|
||||||
shop.setIsDelete(0);
|
shop.setIsDelete(0);
|
||||||
|
if (shop.getId() == null) {
|
||||||
shopMapper.insert(shop);
|
shopMapper.insert(shop);
|
||||||
} else {
|
} else {
|
||||||
require(request.getShopId() != null, "请选择要加入的店铺");
|
shopMapper.updateById(shop);
|
||||||
shop = shopMapper.selectOne(Wrappers.lambdaQuery(ShopDO.class).eq(ShopDO::getId, request.getShopId()).eq(ShopDO::getStatus, 1).eq(ShopDO::getIsDelete, 0));
|
}
|
||||||
require(shop != null, "店铺不存在或暂未营业");
|
} else {
|
||||||
|
shop = selectedStaffShop;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDO user = existing == null ? new UserDO() : existing;
|
|
||||||
user.setShopId(shop.getId());
|
user.setShopId(shop.getId());
|
||||||
user.setNickname((WorkbenchRegistrationRole.MANAGER.equals(roleType) ? shop.getShopName() + "店长" : "Salon店员"));
|
if (!StringUtils.hasText(user.getNickname()) || user.getNickname().startsWith("微信用户")) {
|
||||||
user.setAccount(phone);
|
user.setNickname(WorkbenchRegistrationRole.MANAGER.equals(roleType) ? shop.getShopName() + "店长" : "Salon店员");
|
||||||
user.setPassword(passwordProvided ? passwordEncoder.encode(request.getPassword()) : "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW");
|
}
|
||||||
user.setPhone(phone);
|
|
||||||
user.setContactPhone(phone);
|
|
||||||
user.setPhoneVerified(1);
|
|
||||||
user.setType(WorkbenchRegistrationRole.MANAGER.equals(roleType) ? 2 : 3);
|
user.setType(WorkbenchRegistrationRole.MANAGER.equals(roleType) ? 2 : 3);
|
||||||
user.setStatus(0);
|
user.setStatus(0);
|
||||||
user.setIsDelete(0);
|
user.setIsDelete(0);
|
||||||
if (existing == null) {
|
|
||||||
userMapper.insert(user);
|
|
||||||
} else {
|
|
||||||
userMapper.updateById(user);
|
userMapper.updateById(user);
|
||||||
}
|
|
||||||
bindWechatUser(request.getWxCode(), user.getId());
|
|
||||||
if (WorkbenchRegistrationRole.MANAGER.equals(roleType)) {
|
if (WorkbenchRegistrationRole.MANAGER.equals(roleType)) {
|
||||||
createPendingBinding(user.getId(), shop.getId());
|
createPendingBinding(user.getId(), shop.getId());
|
||||||
} else {
|
} else {
|
||||||
@@ -140,13 +122,6 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
|||||||
userShopBindingSupport.updateBindingStatus(user.getId(), shop.getId(), 0);
|
userShopBindingSupport.updateBindingStatus(user.getId(), shop.getId(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkbenchRegistrationApplicationDO application = ticket == null || ticket.getApplicationId() == null
|
|
||||||
? new WorkbenchRegistrationApplicationDO()
|
|
||||||
: applicationMapper.selectById(ticket.getApplicationId());
|
|
||||||
if (application.getId() != null) {
|
|
||||||
require(existing != null && existing.getId().equals(application.getUserId()), "注册申请与账号不匹配");
|
|
||||||
require(WorkbenchRegistrationStatus.REJECTED.equals(application.getStatus()), "该注册申请当前不可重新提交");
|
|
||||||
}
|
|
||||||
if (!StringUtils.hasText(application.getApplicationNo())) {
|
if (!StringUtils.hasText(application.getApplicationNo())) {
|
||||||
application.setApplicationNo("SALON-" + UUID.randomUUID().toString().replace("-", "").substring(0, 20).toUpperCase());
|
application.setApplicationNo("SALON-" + UUID.randomUUID().toString().replace("-", "").substring(0, 20).toUpperCase());
|
||||||
}
|
}
|
||||||
@@ -156,6 +131,9 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
|||||||
application.setShopName(shop.getShopName());
|
application.setShopName(shop.getShopName());
|
||||||
application.setShopAddress(shop.getAddress());
|
application.setShopAddress(shop.getAddress());
|
||||||
application.setStatus(WorkbenchRegistrationRole.MANAGER.equals(roleType) ? WorkbenchRegistrationStatus.PENDING_ADMIN : WorkbenchRegistrationStatus.PENDING_MANAGER);
|
application.setStatus(WorkbenchRegistrationRole.MANAGER.equals(roleType) ? WorkbenchRegistrationStatus.PENDING_ADMIN : WorkbenchRegistrationStatus.PENDING_MANAGER);
|
||||||
|
application.setRejectReason(null);
|
||||||
|
application.setReviewerId(null);
|
||||||
|
application.setReviewedAt(null);
|
||||||
application.setIsDelete(0);
|
application.setIsDelete(0);
|
||||||
if (application.getId() == null) {
|
if (application.getId() == null) {
|
||||||
applicationMapper.insert(application);
|
applicationMapper.insert(application);
|
||||||
@@ -176,22 +154,7 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public WorkbenchRegistrationStatusVO resubmit(WorkbenchRegistrationRequestDTO request) {
|
public WorkbenchRegistrationStatusVO resubmit(WorkbenchRegistrationRequestDTO request) {
|
||||||
require(request != null && request.getApplicationId() != null, "申请信息不能为空");
|
require(request != null && request.getApplicationId() != null, "申请信息不能为空");
|
||||||
WorkbenchRegistrationApplicationDO application = applicationMapper.selectById(request.getApplicationId());
|
return register(request);
|
||||||
require(application != null && WorkbenchRegistrationStatus.REJECTED.equals(application.getStatus()), "该申请当前不可重新提交");
|
|
||||||
String phone = requireText(request.getPhone(), "手机号不能为空");
|
|
||||||
if (StringUtils.hasText(request.getRegistrationTicket())) {
|
|
||||||
PhoneRegistrationTicketVO ticket = phoneRegistrationTicketService.consume(request.getRegistrationTicket(), phone);
|
|
||||||
require(ticket.getApplicationId() != null && ticket.getApplicationId().equals(application.getId()), "手机号注册凭证与申请不匹配");
|
|
||||||
require(ticket.getUserId() == null || ticket.getUserId().equals(application.getUserId()), "手机号注册凭证与账号不匹配");
|
|
||||||
} else {
|
|
||||||
require(verificationCodeService.verifyCode(phone, request.getVerificationCode()), "验证码错误或已过期");
|
|
||||||
}
|
|
||||||
application.setStatus(WorkbenchRegistrationRole.MANAGER.equals(application.getRoleType()) ? WorkbenchRegistrationStatus.PENDING_ADMIN : WorkbenchRegistrationStatus.PENDING_MANAGER);
|
|
||||||
application.setRejectReason(null);
|
|
||||||
application.setReviewerId(null);
|
|
||||||
application.setReviewedAt(null);
|
|
||||||
applicationMapper.updateById(application);
|
|
||||||
return toStatus(application);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -285,28 +248,6 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
|
|||||||
userShopBindingMapper.updateById(binding);
|
userShopBindingMapper.updateById(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindWechatUser(String wxCode, Long userId) {
|
|
||||||
if (!StringUtils.hasText(wxCode)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
WechatMiniClientService.SessionInfo sessionInfo = wechatMiniClientService.code2Session(wxCode);
|
|
||||||
String appId = wechatMiniClientService.getConfiguredAppId();
|
|
||||||
WechatMiniBindingDO binding = wechatMiniBindingMapper.selectOne(Wrappers.lambdaQuery(WechatMiniBindingDO.class).eq(WechatMiniBindingDO::getAppId, appId).eq(WechatMiniBindingDO::getOpenId, sessionInfo.openId()).last("limit 1"));
|
|
||||||
if (binding == null) {
|
|
||||||
binding = new WechatMiniBindingDO();
|
|
||||||
binding.setAppId(appId);
|
|
||||||
binding.setOpenId(sessionInfo.openId());
|
|
||||||
}
|
|
||||||
binding.setUserId(userId);
|
|
||||||
binding.setUnionId(sessionInfo.unionId());
|
|
||||||
binding.setStatus(1);
|
|
||||||
if (binding.getId() == null) {
|
|
||||||
wechatMiniBindingMapper.insert(binding);
|
|
||||||
} else {
|
|
||||||
wechatMiniBindingMapper.updateById(binding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void require(boolean condition, String message) {
|
private void require(boolean condition, String message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
throw new IllegalArgumentException(message);
|
throw new IllegalArgumentException(message);
|
||||||
|
|||||||
+34
-3
@@ -56,6 +56,8 @@ import com.xiaowang.jacyucloudsalon.core.modules.file.dto.ChunkUploadInitRequest
|
|||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniAutoLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniAutoLoginRequestDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniConfirmLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniConfirmLoginRequestDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniPhoneLoginRequestDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniPhoneLoginRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniQuickLoginRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniBindPhoneRequestDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.user.dto.UserDTO;
|
import com.xiaowang.jacyucloudsalon.core.modules.user.dto.UserDTO;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.user.vo.UserAgreementConsentVO;
|
import com.xiaowang.jacyucloudsalon.core.modules.user.vo.UserAgreementConsentVO;
|
||||||
/**
|
/**
|
||||||
@@ -475,6 +477,23 @@ public class UserController {
|
|||||||
return Result.success(wechatMiniAuthService.autoLogin(requestDTO));
|
return Result.success(wechatMiniAuthService.autoLogin(requestDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/wechat-mini/status")
|
||||||
|
@OperationGuard(action = "wechat-mini-status", ttlSeconds = 2, message = "状态检测中,请稍后重试")
|
||||||
|
public Result<WechatMiniLoginResultVO> wechatMiniStatus(@Valid @RequestBody WechatMiniAutoLoginRequestDTO requestDTO) {
|
||||||
|
return Result.success(wechatMiniAuthService.status(requestDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/wechat-mini/quick-login")
|
||||||
|
@OperationGuard(action = "wechat-mini-quick-login", ttlSeconds = 8, message = "登录处理中,请勿重复提交")
|
||||||
|
public Result<WechatMiniLoginResultVO> wechatMiniQuickLogin(HttpServletRequest request,
|
||||||
|
@Valid @RequestBody WechatMiniQuickLoginRequestDTO requestDTO) {
|
||||||
|
requestThrottleService.checkWechatMiniLogin(request, "wechat-mini-quick");
|
||||||
|
legalAgreementService.requireAccepted(requestDTO);
|
||||||
|
WechatMiniLoginResultVO result = wechatMiniAuthService.quickLogin(requestDTO);
|
||||||
|
recordWechatConsentIfLoggedIn(result, requestDTO, "WECHAT_MINI_QUICK_LOGIN", request);
|
||||||
|
return Result.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/wechat-mini/phone-login")
|
@PostMapping("/wechat-mini/phone-login")
|
||||||
@OperationGuard(action = "wechat-mini-phone-login", ttlSeconds = 8, message = "登录处理中,请勿重复提交")
|
@OperationGuard(action = "wechat-mini-phone-login", ttlSeconds = 8, message = "登录处理中,请勿重复提交")
|
||||||
/**
|
/**
|
||||||
@@ -646,9 +665,13 @@ public class UserController {
|
|||||||
AgreementAwareRequest dto,
|
AgreementAwareRequest dto,
|
||||||
String entry,
|
String entry,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
if (result != null && result.getUserInfo() != null) {
|
if (result != null) {
|
||||||
legalAgreementService.recordConsent(result.getUserInfo().getId(), dto, entry, request);
|
Long userId = result.getUserInfo() == null ? result.getConsentUserId() : result.getUserInfo().getId();
|
||||||
securityAuditLogService.record(result.getUserInfo().getId(), null, entry, "SUCCESS", null, request);
|
if (userId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
legalAgreementService.recordConsent(userId, dto, entry, request);
|
||||||
|
securityAuditLogService.record(userId, null, entry, "SUCCESS", null, request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,6 +715,14 @@ public class UserController {
|
|||||||
return Result.success(success);
|
return Result.success(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/wechat-mini/bind-phone")
|
||||||
|
@OperationGuard(action = "wechat-mini-bind-phone", ttlSeconds = 10, message = "手机号绑定处理中,请勿重复提交")
|
||||||
|
public Result<Boolean> bindWechatMiniPhone(HttpServletRequest request,
|
||||||
|
@Valid @RequestBody WechatMiniBindPhoneRequestDTO requestDTO) {
|
||||||
|
Long userId = (Long) request.getAttribute("userId");
|
||||||
|
return Result.success(wechatMiniAuthService.bindPhone(userId, requestDTO));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绑定邮箱
|
* 绑定邮箱
|
||||||
*
|
*
|
||||||
|
|||||||
+1
@@ -784,6 +784,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
|||||||
userVO.setNickname(userDO.getNickname());
|
userVO.setNickname(userDO.getNickname());
|
||||||
userVO.setAccount(userDO.getAccount());
|
userVO.setAccount(userDO.getAccount());
|
||||||
userVO.setPhone(userDO.getPhone());
|
userVO.setPhone(userDO.getPhone());
|
||||||
|
userVO.setPhoneVerified(userDO.getPhoneVerified());
|
||||||
userVO.setContactPhone(userDO.getContactPhone());
|
userVO.setContactPhone(userDO.getContactPhone());
|
||||||
userVO.setBirthday(userDO.getBirthday());
|
userVO.setBirthday(userDO.getBirthday());
|
||||||
userVO.setWechatId(userDO.getWechatId());
|
userVO.setWechatId(userDO.getWechatId());
|
||||||
|
|||||||
+1
@@ -111,6 +111,7 @@ public class UserVO {
|
|||||||
* 手机号
|
* 手机号
|
||||||
*/
|
*/
|
||||||
private String phone;
|
private String phone;
|
||||||
|
private Integer phoneVerified;
|
||||||
/**
|
/**
|
||||||
* 联系电话
|
* 联系电话
|
||||||
*/
|
*/
|
||||||
|
|||||||
+116
@@ -0,0 +1,116 @@
|
|||||||
|
package com.xiaowang.jacyucloudsalon.core.modules.integration.service.impl;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniAutoLoginRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.dto.WechatMiniQuickLoginRequestDTO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.entity.WechatMiniBindingDO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.mapper.WechatMiniBindingMapper;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.service.WechatMiniClientService;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.vo.WechatMiniLoginResultVO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.registration.mapper.WorkbenchRegistrationApplicationMapper;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.shop.support.UserShopBindingSupport;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.user.entity.UserDO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.user.mapper.UserMapper;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.user.service.UserService;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class WechatMiniAuthServiceImplTest {
|
||||||
|
@Mock private WechatMiniClientService clientService;
|
||||||
|
@Mock private WechatMiniBindingMapper bindingMapper;
|
||||||
|
@Mock private UserMapper userMapper;
|
||||||
|
@Mock private UserService userService;
|
||||||
|
@Mock private UserShopBindingSupport shopBindingSupport;
|
||||||
|
@Mock private StringRedisTemplate redisTemplate;
|
||||||
|
@Mock private ValueOperations<String, String> valueOperations;
|
||||||
|
@Mock private TimeOrderedSnowflakeIdGenerator idGenerator;
|
||||||
|
@Mock private WorkbenchRegistrationApplicationMapper applicationMapper;
|
||||||
|
|
||||||
|
private WechatMiniAuthServiceImpl service;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
service = new WechatMiniAuthServiceImpl(clientService, bindingMapper, userMapper, userService,
|
||||||
|
shopBindingSupport, redisTemplate, new ObjectMapper(), idGenerator, applicationMapper);
|
||||||
|
when(clientService.getConfiguredAppId()).thenReturn("wx-app");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void statusDoesNotCreateUnknownUser() {
|
||||||
|
when(clientService.code2Session("probe-code"))
|
||||||
|
.thenReturn(new WechatMiniClientService.SessionInfo("openid-1", null, "session"));
|
||||||
|
when(bindingMapper.selectOne(any())).thenReturn(null);
|
||||||
|
WechatMiniAutoLoginRequestDTO request = new WechatMiniAutoLoginRequestDTO();
|
||||||
|
request.setWxCode("probe-code");
|
||||||
|
|
||||||
|
WechatMiniLoginResultVO result = service.status(request);
|
||||||
|
|
||||||
|
assertEquals(WechatMiniLoginResultVO.STATUS_NEW_USER, result.getStatus());
|
||||||
|
verify(userMapper, never()).insert(any());
|
||||||
|
verifyNoInteractions(userService, redisTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void quickLoginCreatesSinglePendingIdentityWithoutAccountOrPassword() {
|
||||||
|
when(clientService.code2Session("login-code"))
|
||||||
|
.thenReturn(new WechatMiniClientService.SessionInfo("openid-1", "union-1", "session"));
|
||||||
|
when(bindingMapper.selectOne(any())).thenReturn(null);
|
||||||
|
when(bindingMapper.selectList(any())).thenReturn(List.of());
|
||||||
|
when(userMapper.insert(any())).thenAnswer(invocation -> {
|
||||||
|
((UserDO) invocation.getArgument(0)).setId(101L);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
when(idGenerator.nextIdString()).thenReturn("1234567890123456789");
|
||||||
|
when(redisTemplate.opsForValue()).thenReturn(valueOperations);
|
||||||
|
WechatMiniQuickLoginRequestDTO request = new WechatMiniQuickLoginRequestDTO();
|
||||||
|
request.setWxCode("login-code");
|
||||||
|
|
||||||
|
WechatMiniLoginResultVO result = service.quickLogin(request);
|
||||||
|
|
||||||
|
assertEquals(WechatMiniLoginResultVO.STATUS_NEED_REGISTRATION, result.getStatus());
|
||||||
|
assertNotNull(result.getRegistrationTicket());
|
||||||
|
verify(userMapper, times(1)).insert(argThat(user -> user.getAccount() == null
|
||||||
|
&& user.getPassword() == null && Integer.valueOf(0).equals(user.getStatus())));
|
||||||
|
verify(bindingMapper, times(1)).insert(argThat(binding -> "openid-1".equals(binding.getOpenId())
|
||||||
|
&& Long.valueOf(101L).equals(binding.getUserId())));
|
||||||
|
verifyNoInteractions(userService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void inactiveReviewedUserCannotReceiveToken() {
|
||||||
|
WechatMiniBindingDO binding = new WechatMiniBindingDO();
|
||||||
|
binding.setUserId(101L);
|
||||||
|
binding.setStatus(1);
|
||||||
|
UserDO user = new UserDO();
|
||||||
|
user.setId(101L);
|
||||||
|
user.setType(2);
|
||||||
|
user.setStatus(0);
|
||||||
|
user.setIsDelete(0);
|
||||||
|
when(clientService.code2Session("login-code"))
|
||||||
|
.thenReturn(new WechatMiniClientService.SessionInfo("openid-1", null, "session"));
|
||||||
|
when(bindingMapper.selectOne(any())).thenReturn(binding);
|
||||||
|
when(userMapper.selectById(101L)).thenReturn(user);
|
||||||
|
when(applicationMapper.selectOne(any())).thenReturn(null);
|
||||||
|
WechatMiniQuickLoginRequestDTO request = new WechatMiniQuickLoginRequestDTO();
|
||||||
|
request.setWxCode("login-code");
|
||||||
|
|
||||||
|
WechatMiniLoginResultVO result = service.quickLogin(request);
|
||||||
|
|
||||||
|
assertEquals(WechatMiniLoginResultVO.STATUS_DISABLED, result.getStatus());
|
||||||
|
assertNull(result.getAccessToken());
|
||||||
|
verifyNoInteractions(userService);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-1
@@ -94,7 +94,11 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
"/api/user/refresh-token",
|
"/api/user/refresh-token",
|
||||||
"/api/user/send-verification-code",
|
"/api/user/send-verification-code",
|
||||||
"/api/user/phone-login",
|
"/api/user/phone-login",
|
||||||
"/api/user/wechat-mini/**",
|
"/api/user/wechat-mini/auto-login",
|
||||||
|
"/api/user/wechat-mini/phone-login",
|
||||||
|
"/api/user/wechat-mini/confirm-login",
|
||||||
|
"/api/user/wechat-mini/status",
|
||||||
|
"/api/user/wechat-mini/quick-login",
|
||||||
"/api/user/workbench/register/**",
|
"/api/user/workbench/register/**",
|
||||||
"/api/user/workbench/shops/available",
|
"/api/user/workbench/shops/available",
|
||||||
"/api/user/reset-password-by-phone",
|
"/api/user/reset-password-by-phone",
|
||||||
|
|||||||
@@ -144,7 +144,11 @@ fingertip-designer:
|
|||||||
- /api/user/refresh-token
|
- /api/user/refresh-token
|
||||||
- /api/user/send-verification-code
|
- /api/user/send-verification-code
|
||||||
- /api/user/phone-login
|
- /api/user/phone-login
|
||||||
- /api/user/wechat-mini/**
|
- /api/user/wechat-mini/auto-login
|
||||||
|
- /api/user/wechat-mini/phone-login
|
||||||
|
- /api/user/wechat-mini/confirm-login
|
||||||
|
- /api/user/wechat-mini/status
|
||||||
|
- /api/user/wechat-mini/quick-login
|
||||||
- /api/user/workbench/register/**
|
- /api/user/workbench/register/**
|
||||||
- /api/user/workbench/shops/available
|
- /api/user/workbench/shops/available
|
||||||
- /api/user/reset-password-by-phone
|
- /api/user/reset-password-by-phone
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ module.exports = {
|
|||||||
|
|
||||||
register(data) {
|
register(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/user/workbench/register/phone',
|
url: '/user/workbench/register/wechat-mini',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
params: { __baseUrl: API_DOMAIN },
|
params: { __baseUrl: API_DOMAIN },
|
||||||
data
|
data
|
||||||
@@ -99,6 +99,24 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
wechatStatus(wxCode) {
|
||||||
|
return request({
|
||||||
|
url: '/user/wechat-mini/status',
|
||||||
|
method: 'POST',
|
||||||
|
params: { __baseUrl: API_DOMAIN },
|
||||||
|
data: { wxCode }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
wechatQuickLogin(data) {
|
||||||
|
return request({
|
||||||
|
url: '/user/wechat-mini/quick-login',
|
||||||
|
method: 'POST',
|
||||||
|
params: { __baseUrl: API_DOMAIN },
|
||||||
|
data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
wechatPhoneLogin(data) {
|
wechatPhoneLogin(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/user/wechat-mini/phone-login',
|
url: '/user/wechat-mini/phone-login',
|
||||||
|
|||||||
@@ -20,5 +20,32 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
bindWechatPhone(phoneCode) {
|
||||||
|
return request({
|
||||||
|
url: '/user/wechat-mini/bind-phone',
|
||||||
|
method: 'POST',
|
||||||
|
params: { __baseUrl: API_DOMAIN },
|
||||||
|
data: { phoneCode }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
bindPhone(data) {
|
||||||
|
return request({
|
||||||
|
url: '/user/bind-phone',
|
||||||
|
method: 'POST',
|
||||||
|
params: { __baseUrl: API_DOMAIN },
|
||||||
|
data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
sendBindPhoneCode(phone) {
|
||||||
|
return request({
|
||||||
|
url: '/user/send-verification-code',
|
||||||
|
method: 'POST',
|
||||||
|
params: { __baseUrl: API_DOMAIN },
|
||||||
|
data: { phone, sceneCode: 'USER_BIND_PHONE' }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+70
-1
@@ -1,4 +1,5 @@
|
|||||||
const auth = require('./utils/auth')
|
const auth = require('./utils/auth')
|
||||||
|
const authApi = require('./api/auth')
|
||||||
const { BRAND_CONFIG } = require('./utils/config')
|
const { BRAND_CONFIG } = require('./utils/config')
|
||||||
|
|
||||||
App({
|
App({
|
||||||
@@ -6,11 +7,73 @@ App({
|
|||||||
appName: BRAND_CONFIG.appName,
|
appName: BRAND_CONFIG.appName,
|
||||||
shopName: BRAND_CONFIG.defaultShopName,
|
shopName: BRAND_CONFIG.defaultShopName,
|
||||||
userInfo: null,
|
userInfo: null,
|
||||||
planningNeedRefresh: false
|
planningNeedRefresh: false,
|
||||||
|
wechatLoginState: null
|
||||||
},
|
},
|
||||||
|
|
||||||
onLaunch() {
|
onLaunch() {
|
||||||
this.bootstrapSession()
|
this.bootstrapSession()
|
||||||
|
this.bootstrapWechatLogin()
|
||||||
|
},
|
||||||
|
|
||||||
|
getWechatCode() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
wx.login({
|
||||||
|
success: result => result.code ? resolve(result.code) : reject(new Error('未获取到微信登录凭证')),
|
||||||
|
fail: reject
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
async bootstrapWechatLogin() {
|
||||||
|
try {
|
||||||
|
const status = await authApi.wechatStatus(await this.getWechatCode())
|
||||||
|
this.publishWechatLoginState(status)
|
||||||
|
const preference = auth.getLoginPreference()
|
||||||
|
if (!preference.rememberMe || status.status !== 'READY') {
|
||||||
|
auth.clearSession()
|
||||||
|
this.globalData.userInfo = null
|
||||||
|
this.goLoginIfNeeded()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const result = await authApi.wechatQuickLogin({
|
||||||
|
wxCode: await this.getWechatCode(),
|
||||||
|
preferredShopId: preference.preferredShopId,
|
||||||
|
agreementAccepted: true,
|
||||||
|
agreementVersions: preference.agreementVersions || {},
|
||||||
|
clientType: 'WECHAT_MINI'
|
||||||
|
})
|
||||||
|
this.publishWechatLoginState(result)
|
||||||
|
if (result.status === 'SUCCESS' && result.accessToken) {
|
||||||
|
this.setSession(result)
|
||||||
|
wx.reLaunch({ url: '/pages/planning/index' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wx.reLaunch({ url: '/pages/login/index' })
|
||||||
|
} catch (error) {
|
||||||
|
auth.clearSession()
|
||||||
|
this.globalData.userInfo = null
|
||||||
|
this.publishWechatLoginState({
|
||||||
|
status: 'ERROR',
|
||||||
|
message: error.message || '自动登录失败,请点击重试'
|
||||||
|
})
|
||||||
|
this.goLoginIfNeeded()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
goLoginIfNeeded() {
|
||||||
|
const pages = getCurrentPages()
|
||||||
|
const current = pages.length ? pages[pages.length - 1].route : ''
|
||||||
|
if (current !== 'pages/login/index') wx.reLaunch({ url: '/pages/login/index' })
|
||||||
|
},
|
||||||
|
|
||||||
|
publishWechatLoginState(state) {
|
||||||
|
this.globalData.wechatLoginState = state
|
||||||
|
const pages = getCurrentPages()
|
||||||
|
const current = pages.length ? pages[pages.length - 1] : null
|
||||||
|
if (current && current.route === 'pages/login/index' && typeof current.setData === 'function') {
|
||||||
|
current.setData({ loginState: state })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
bootstrapSession() {
|
bootstrapSession() {
|
||||||
@@ -29,5 +92,11 @@ App({
|
|||||||
clearSession() {
|
clearSession() {
|
||||||
auth.clearSession()
|
auth.clearSession()
|
||||||
this.globalData.userInfo = null
|
this.globalData.userInfo = null
|
||||||
|
},
|
||||||
|
|
||||||
|
logoutDevice() {
|
||||||
|
auth.clearDeviceLoginState()
|
||||||
|
this.globalData.userInfo = null
|
||||||
|
this.globalData.wechatLoginState = null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"pages/leave-management/index",
|
"pages/leave-management/index",
|
||||||
"pages/color-setting/index",
|
"pages/color-setting/index",
|
||||||
"pages/profile/index",
|
"pages/profile/index",
|
||||||
|
"pages/account-settings/index",
|
||||||
"pages/shop-settings/index",
|
"pages/shop-settings/index",
|
||||||
"pages/export/index",
|
"pages/export/index",
|
||||||
"pages/password/index",
|
"pages/password/index",
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
const userApi = require('../../api/user')
|
||||||
|
const authApi = require('../../api/auth')
|
||||||
|
const auth = require('../../utils/auth')
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
profile: {},
|
||||||
|
loading: true,
|
||||||
|
binding: false,
|
||||||
|
smsForm: { phone: '', code: '' },
|
||||||
|
codeLoading: false,
|
||||||
|
countdown: 0,
|
||||||
|
timer: null
|
||||||
|
},
|
||||||
|
|
||||||
|
onShow() { this.loadProfile() },
|
||||||
|
|
||||||
|
async loadProfile() {
|
||||||
|
this.setData({ loading: true })
|
||||||
|
try {
|
||||||
|
const profile = await userApi.info()
|
||||||
|
this.setData({ profile, 'smsForm.phone': profile.phone || '' })
|
||||||
|
const app = getApp()
|
||||||
|
const session = auth.getSession()
|
||||||
|
app.setSession({ ...session, userInfo: { ...(session.userInfo || {}), ...profile } })
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '账号信息加载失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ loading: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onInput(event) {
|
||||||
|
const field = event.currentTarget.dataset.field
|
||||||
|
const value = field === 'phone' ? String(event.detail.value || '').replace(/\D/g, '').slice(0, 11) : event.detail.value
|
||||||
|
this.setData({ [`smsForm.${field}`]: value })
|
||||||
|
},
|
||||||
|
|
||||||
|
async bindWechatPhone(event) {
|
||||||
|
const phoneCode = event.detail && event.detail.code
|
||||||
|
if (!phoneCode) {
|
||||||
|
wx.showToast({ title: '未获得手机号授权', icon: 'none' }); return
|
||||||
|
}
|
||||||
|
this.setData({ binding: true })
|
||||||
|
try {
|
||||||
|
await userApi.bindWechatPhone(phoneCode)
|
||||||
|
await this.loadProfile()
|
||||||
|
wx.showToast({ title: '手机号已绑定' })
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '绑定失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ binding: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async sendCode() {
|
||||||
|
const phone = String(this.data.smsForm.phone || '')
|
||||||
|
if (!/^1[3-9]\d{9}$/.test(phone)) {
|
||||||
|
wx.showToast({ title: '请输入正确手机号', icon: 'none' }); return
|
||||||
|
}
|
||||||
|
if (this.data.codeLoading || this.data.countdown) return
|
||||||
|
this.setData({ codeLoading: true })
|
||||||
|
try {
|
||||||
|
await userApi.sendBindPhoneCode(phone)
|
||||||
|
this.startCountdown()
|
||||||
|
wx.showToast({ title: '验证码已发送' })
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '验证码发送失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ codeLoading: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
startCountdown() {
|
||||||
|
if (this.data.timer) clearInterval(this.data.timer)
|
||||||
|
this.setData({ countdown: 60 })
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
const next = this.data.countdown - 1
|
||||||
|
if (next <= 0) { clearInterval(timer); this.setData({ countdown: 0, timer: null }); return }
|
||||||
|
this.setData({ countdown: next })
|
||||||
|
}, 1000)
|
||||||
|
this.setData({ timer })
|
||||||
|
},
|
||||||
|
|
||||||
|
async bindSmsPhone() {
|
||||||
|
const form = this.data.smsForm
|
||||||
|
if (!/^1[3-9]\d{9}$/.test(form.phone) || !/^\d{6}$/.test(String(form.code || ''))) {
|
||||||
|
wx.showToast({ title: '请输入正确手机号和6位验证码', icon: 'none' }); return
|
||||||
|
}
|
||||||
|
this.setData({ binding: true })
|
||||||
|
try {
|
||||||
|
await userApi.bindPhone({ phone: form.phone, verificationCode: form.code })
|
||||||
|
await this.loadProfile()
|
||||||
|
wx.showToast({ title: '手机号已绑定' })
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '绑定失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ binding: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async logout() {
|
||||||
|
const confirmed = await new Promise(resolve => wx.showModal({ title: '退出登录', content: '退出后将关闭自动登录,并清除本机提醒设置。', success: result => resolve(result.confirm), fail: () => resolve(false) }))
|
||||||
|
if (!confirmed) return
|
||||||
|
try { await authApi.logout() } catch (error) {}
|
||||||
|
getApp().logoutDevice()
|
||||||
|
wx.reLaunch({ url: '/pages/login/index' })
|
||||||
|
},
|
||||||
|
|
||||||
|
onUnload() { if (this.data.timer) clearInterval(this.data.timer) }
|
||||||
|
})
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"navigationBarTitleText": "账号设置"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<view class="page settings-page">
|
||||||
|
<view class="card identity-card"><view class="identity-mark">微</view><view class="identity-copy"><text class="identity-title">微信身份</text><text class="identity-status">已安全关联当前账号</text></view><text class="linked-badge">已关联</text></view>
|
||||||
|
<view class="card phone-card"><view class="section-title">手机号</view><view class="phone-status"><text>{{profile.phoneVerified == 1 ? (profile.maskedPhone || profile.phone) : '尚未绑定'}}</text><text class="status-tag {{profile.phoneVerified == 1 ? 'done' : ''}}">{{profile.phoneVerified == 1 ? '已验证' : '待绑定'}}</text></view><button class="wechat-phone-btn" open-type="getPhoneNumber" loading="{{binding}}" bindgetphonenumber="bindWechatPhone">微信一键{{profile.phoneVerified == 1 ? '更换' : '绑定'}}</button><view class="divider"><text>或使用短信验证码</text></view><view class="field"><input value="{{smsForm.phone}}" data-field="phone" bindinput="onInput" type="number" maxlength="11" placeholder="请输入手机号" /></view><view class="code-row"><input value="{{smsForm.code}}" data-field="code" bindinput="onInput" type="number" maxlength="6" placeholder="6位验证码" /><button bindtap="sendCode" disabled="{{codeLoading || countdown > 0}}">{{countdown > 0 ? countdown + 's' : '获取验证码'}}</button></view><button class="sms-bind-btn" loading="{{binding}}" bindtap="bindSmsPhone">验证并绑定</button></view>
|
||||||
|
<view class="account-note">手机号仅用于账号安全与必要联系,不作为微信快捷登录标识。</view>
|
||||||
|
<button class="logout-btn" bindtap="logout">退出登录</button>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.settings-page { padding-top:24rpx; }.identity-card { display:flex; align-items:center; padding:26rpx; }.identity-mark { display:flex; align-items:center; justify-content:center; width:68rpx; height:68rpx; border-radius:20rpx; background:#dcebe1; color:#35634d; font-size:28rpx; font-weight:800; }.identity-copy { display:flex; flex:1; flex-direction:column; margin-left:18rpx; }.identity-title,.section-title { color:#30483c; font-size:28rpx; font-weight:800; }.identity-status { margin-top:6rpx; color:#8a9a91; font-size:21rpx; }.linked-badge,.status-tag { padding:7rpx 14rpx; border-radius:999rpx; background:#e5f2e8; color:#397055; font-size:20rpx; }
|
||||||
|
.phone-card { margin-top:20rpx; padding:28rpx; }.phone-status { display:flex; align-items:center; justify-content:space-between; margin-top:20rpx; padding:20rpx; border-radius:14rpx; background:#f4f8f5; color:#425b4e; font-size:26rpx; }.status-tag { background:#fff0db; color:#9a682e; }.status-tag.done { background:#e5f2e8; color:#397055; }.wechat-phone-btn,.sms-bind-btn { height:80rpx; margin-top:22rpx; border-radius:14rpx; background:#35634d; color:#fff; font-size:26rpx; line-height:80rpx; }.divider { display:flex; align-items:center; justify-content:center; margin:28rpx 0 18rpx; color:#9aa79f; font-size:20rpx; }.field input,.code-row input { box-sizing:border-box; height:78rpx; padding:0 20rpx; border:1rpx solid #dde8e0; border-radius:12rpx; background:#f8faf8; }.code-row { display:flex; gap:12rpx; margin-top:14rpx; }.code-row input { min-width:0; flex:1; }.code-row button { width:190rpx; height:78rpx; padding:0; border-radius:12rpx; background:#e7f0ea; color:#426c57; font-size:23rpx; line-height:78rpx; }.sms-bind-btn { background:#eef4f0; color:#35634d; }.account-note { margin:24rpx 18rpx; color:#8e9c94; font-size:21rpx; line-height:1.6; }.logout-btn { margin-top:52rpx; background:transparent; color:#a24f42; font-size:25rpx; }
|
||||||
@@ -1,595 +1,179 @@
|
|||||||
const authApi = require('../../api/auth')
|
const authApi = require('../../api/auth')
|
||||||
|
const auth = require('../../utils/auth')
|
||||||
const { BRAND_CONFIG } = require('../../utils/config')
|
const { BRAND_CONFIG } = require('../../utils/config')
|
||||||
|
|
||||||
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
function wxLoginCode() {
|
||||||
const LOGIN_PREFERENCE_KEY = 'fingertip_manager_login_preference'
|
return new Promise((resolve, reject) => wx.login({
|
||||||
|
success: result => result.code ? resolve(result.code) : reject(new Error('未获取到微信登录凭证')),
|
||||||
function buildSession(data) {
|
fail: reject
|
||||||
const userInfo = data.userInfo || data.user || {}
|
|
||||||
return {
|
|
||||||
...data,
|
|
||||||
accessToken: data.accessToken || data.token,
|
|
||||||
userInfo,
|
|
||||||
shopName: data.shopName || userInfo.shopName || (data.shop && data.shop.shopName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSelectableShopIds(session) {
|
|
||||||
const userInfo = session.userInfo || {}
|
|
||||||
if (Array.isArray(userInfo.shopIds)) {
|
|
||||||
return userInfo.shopIds
|
|
||||||
}
|
|
||||||
return Array.isArray(session.shopIds) ? session.shopIds : []
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSelectableShopNames(session) {
|
|
||||||
const userInfo = session.userInfo || {}
|
|
||||||
if (Array.isArray(userInfo.shopNames)) {
|
|
||||||
return userInfo.shopNames
|
|
||||||
}
|
|
||||||
return Array.isArray(session.shopNames) ? session.shopNames : []
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildShopOptions(session) {
|
|
||||||
const shopIds = getSelectableShopIds(session)
|
|
||||||
const shopNames = getSelectableShopNames(session)
|
|
||||||
return shopIds.map((shopId, index) => ({
|
|
||||||
id: shopId,
|
|
||||||
name: shopNames[index] || `店铺 ${shopId}`
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildShopOptionsFromSelection(selection) {
|
function shopOptions(result) {
|
||||||
const shops = selection && Array.isArray(selection.shops) ? selection.shops : []
|
return (Array.isArray(result.shops) ? result.shops : []).map(item => ({
|
||||||
return shops.map(shop => ({
|
id: item.id,
|
||||||
id: shop.id,
|
name: item.shopName || item.name || `门店 ${item.id}`
|
||||||
name: shop.shopName || shop.name || `店铺 ${shop.id}`,
|
|
||||||
description: selection && selection.message ? selection.message : ''
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function isShopSelectionRequiredError(error) {
|
|
||||||
const message = error && error.message ? error.message : ''
|
|
||||||
return message.indexOf('选择店铺') !== -1 || message.indexOf('请选择店铺') !== -1 || message.indexOf('请选择登录店铺') !== -1
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertShopSession(session) {
|
|
||||||
const userInfo = session.userInfo || {}
|
|
||||||
if (!userInfo.shopId) {
|
|
||||||
throw new Error('请选择店铺后再进入管理师端')
|
|
||||||
}
|
|
||||||
return session
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLoginPreference() {
|
|
||||||
try {
|
|
||||||
return wx.getStorageSync(LOGIN_PREFERENCE_KEY) || {}
|
|
||||||
} catch (error) {
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setLoginPreference(preference) {
|
|
||||||
wx.setStorageSync(LOGIN_PREFERENCE_KEY, preference || {})
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearLoginPreference() {
|
|
||||||
wx.removeStorageSync(LOGIN_PREFERENCE_KEY)
|
|
||||||
}
|
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
loginView: 'entry',
|
appName: BRAND_CONFIG.appName,
|
||||||
loginMode: 'phone',
|
|
||||||
form: {
|
|
||||||
account: '',
|
|
||||||
password: '',
|
|
||||||
phone: '',
|
|
||||||
code: ''
|
|
||||||
},
|
|
||||||
loading: false,
|
loading: false,
|
||||||
codeLoading: false,
|
rememberMe: false,
|
||||||
countdown: 0,
|
|
||||||
codeSent: false,
|
|
||||||
countdownTimer: null,
|
|
||||||
agreementAccepted: false,
|
agreementAccepted: false,
|
||||||
|
agreements: [],
|
||||||
agreementLoading: false,
|
agreementLoading: false,
|
||||||
agreementError: '',
|
agreementError: '',
|
||||||
|
selectedAgreement: {},
|
||||||
agreementModalVisible: false,
|
agreementModalVisible: false,
|
||||||
selectedAgreement: null,
|
loginState: null,
|
||||||
rememberMe: false,
|
|
||||||
agreements: [],
|
|
||||||
appName: BRAND_CONFIG.appName,
|
|
||||||
shopSelectVisible: false,
|
shopSelectVisible: false,
|
||||||
shopSelectMode: '',
|
|
||||||
shopOptions: [],
|
shopOptions: [],
|
||||||
switchingShop: false,
|
loginTicket: '',
|
||||||
wechatLoginTicket: ''
|
switchingShop: false
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
const preference = getLoginPreference()
|
this.setData({ rememberMe: !!auth.getLoginPreference().rememberMe })
|
||||||
if (preference.rememberMe) {
|
this.consumeAppState()
|
||||||
this.setData({
|
|
||||||
// 记住账号不代表默认使用密码登录,工作台优先引导手机号验证码登录。
|
|
||||||
loginMode: 'phone',
|
|
||||||
rememberMe: true,
|
|
||||||
'form.account': preference.account || '',
|
|
||||||
'form.phone': preference.phone || ''
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.loadAgreements()
|
this.loadAgreements()
|
||||||
},
|
},
|
||||||
|
|
||||||
onInput(event) {
|
onShow() { this.consumeAppState() },
|
||||||
const field = event.currentTarget.dataset.field
|
|
||||||
const value = field === 'phone'
|
|
||||||
? String(event.detail.value || '').replace(/\D/g, '').slice(0, 11)
|
|
||||||
: event.detail.value
|
|
||||||
this.setData({
|
|
||||||
[`form.${field}`]: value
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
switchLoginMode(event) {
|
consumeAppState() {
|
||||||
const loginMode = event.currentTarget.dataset.mode
|
const state = getApp().globalData.wechatLoginState
|
||||||
if (loginMode === 'entry') {
|
if (state) this.setData({ loginState: state })
|
||||||
this.setData({ loginView: 'entry' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (loginMode === this.data.loginMode && this.data.loginView === 'form') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.setData({ loginMode, loginView: 'form' })
|
|
||||||
},
|
|
||||||
|
|
||||||
async sendLoginCode() {
|
|
||||||
if (!this.ensureAgreementAccepted()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const phone = String(this.data.form.phone || '').trim()
|
|
||||||
if (!PHONE_REGEX.test(phone)) {
|
|
||||||
wx.showToast({ title: '请输入正确手机号', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (this.data.codeLoading || this.data.countdown > 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.setData({ codeLoading: true })
|
|
||||||
try {
|
|
||||||
await authApi.sendLoginCode(phone)
|
|
||||||
wx.showToast({ title: '验证码已发送' })
|
|
||||||
this.setData({ codeSent: true })
|
|
||||||
this.startCountdown()
|
|
||||||
} catch (error) {
|
|
||||||
wx.showToast({ title: error.message || '验证码发送失败', icon: 'none' })
|
|
||||||
} finally {
|
|
||||||
this.setData({ codeLoading: false })
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async loadAgreements() {
|
async loadAgreements() {
|
||||||
if (this.data.agreements.length) {
|
if (this.data.agreementLoading || this.data.agreements.length) return
|
||||||
return this.data.agreements
|
|
||||||
}
|
|
||||||
if (this.data.agreementLoading) {
|
|
||||||
return this.data.agreements
|
|
||||||
}
|
|
||||||
this.setData({ agreementLoading: true, agreementError: '' })
|
this.setData({ agreementLoading: true, agreementError: '' })
|
||||||
try {
|
try {
|
||||||
const agreements = await authApi.getCurrentAgreements()
|
const agreements = await authApi.getCurrentAgreements()
|
||||||
const normalizedAgreements = Array.isArray(agreements) ? agreements : []
|
this.setData({ agreements: Array.isArray(agreements) ? agreements : [] })
|
||||||
this.setData({ agreements: normalizedAgreements })
|
|
||||||
return normalizedAgreements
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const agreementError = error.message || '协议内容加载失败,请稍后重试'
|
this.setData({ agreementError: error.message || '协议加载失败' })
|
||||||
this.setData({ agreementError })
|
|
||||||
return []
|
|
||||||
} finally {
|
} finally {
|
||||||
this.setData({ agreementLoading: false })
|
this.setData({ agreementLoading: false })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleAgreement() {
|
toggleAgreement() { this.setData({ agreementAccepted: !this.data.agreementAccepted }) },
|
||||||
this.setData({
|
|
||||||
agreementAccepted: !this.data.agreementAccepted
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
async openAgreement(event) {
|
|
||||||
const type = event.currentTarget.dataset.type
|
|
||||||
const agreements = await this.loadAgreements()
|
|
||||||
const selectedAgreement = agreements.find(item => item.agreementType === type)
|
|
||||||
if (!selectedAgreement) {
|
|
||||||
wx.showToast({ title: this.data.agreementError || '协议内容暂不可用', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.setData({
|
|
||||||
selectedAgreement,
|
|
||||||
agreementModalVisible: true
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
closeAgreementModal() {
|
|
||||||
this.setData({
|
|
||||||
agreementModalVisible: false,
|
|
||||||
selectedAgreement: null
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
stopTap() {
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleRememberMe() {
|
toggleRememberMe() {
|
||||||
const rememberMe = !this.data.rememberMe
|
const rememberMe = !this.data.rememberMe
|
||||||
this.setData({ rememberMe })
|
this.setData({ rememberMe })
|
||||||
if (!rememberMe) {
|
if (!rememberMe) auth.clearLoginPreference()
|
||||||
clearLoginPreference()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
saveLoginPreference() {
|
async openAgreement(event) {
|
||||||
if (!this.data.rememberMe) {
|
await this.loadAgreements()
|
||||||
clearLoginPreference()
|
const selectedAgreement = this.data.agreements.find(item => item.agreementType === event.currentTarget.dataset.type)
|
||||||
|
if (!selectedAgreement) {
|
||||||
|
wx.showToast({ title: this.data.agreementError || '协议暂不可用', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const form = this.data.form
|
this.setData({ selectedAgreement, agreementModalVisible: true })
|
||||||
setLoginPreference({
|
|
||||||
rememberMe: true,
|
|
||||||
loginMode: this.data.loginMode,
|
|
||||||
account: String(form.account || '').trim(),
|
|
||||||
phone: String(form.phone || '').trim()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
buildAgreementPayload() {
|
closeAgreementModal() { this.setData({ agreementModalVisible: false, selectedAgreement: {} }) },
|
||||||
|
acceptAgreementModal() { this.setData({ agreementModalVisible: false, selectedAgreement: {}, agreementAccepted: true }) },
|
||||||
|
stopTap() {},
|
||||||
|
|
||||||
|
agreementPayload() {
|
||||||
const agreementVersions = {}
|
const agreementVersions = {}
|
||||||
;(this.data.agreements || []).forEach(item => {
|
this.data.agreements.forEach(item => {
|
||||||
if (item && item.agreementType && item.version) {
|
if (item.agreementType && item.version) agreementVersions[item.agreementType] = item.version
|
||||||
agreementVersions[item.agreementType] = item.version
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
return {
|
return { agreementAccepted: true, agreementVersions, clientType: 'WECHAT_MINI' }
|
||||||
agreementAccepted: !!this.data.agreementAccepted,
|
|
||||||
agreementVersions,
|
|
||||||
clientType: 'WECHAT_MINI'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
ensureAgreementAccepted() {
|
async ensureCanLogin() {
|
||||||
|
await this.loadAgreements()
|
||||||
if (!this.data.agreementAccepted) {
|
if (!this.data.agreementAccepted) {
|
||||||
wx.showToast({ title: '请先阅读并同意用户协议和隐私政策', icon: 'none' })
|
await new Promise(resolve => wx.showModal({
|
||||||
|
title: '请先勾选协议',
|
||||||
|
content: '阅读并勾选用户协议和隐私政策后,才能使用快捷登录。',
|
||||||
|
showCancel: false,
|
||||||
|
complete: resolve
|
||||||
|
}))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const versions = this.buildAgreementPayload().agreementVersions
|
const versions = this.agreementPayload().agreementVersions
|
||||||
if (!versions.USER_TERMS || !versions.PRIVACY_POLICY) {
|
if (!versions.USER_TERMS || !versions.PRIVACY_POLICY) {
|
||||||
wx.showToast({ title: this.data.agreementError || '协议版本加载中,请稍后再试', icon: 'none' })
|
wx.showToast({ title: this.data.agreementError || '协议版本加载中,请稍后重试', icon: 'none' })
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if (!this.data.rememberMe) {
|
||||||
|
const confirmed = await new Promise(resolve => wx.showModal({
|
||||||
|
title: '仅本次登录',
|
||||||
|
content: '未勾选“记住我”,下次打开小程序时需要重新点击快捷登录。',
|
||||||
|
confirmText: '继续登录',
|
||||||
|
success: result => resolve(result.confirm),
|
||||||
|
fail: () => resolve(false)
|
||||||
|
}))
|
||||||
|
if (!confirmed) return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
async resolveLoginSession(data) {
|
async quickLogin() {
|
||||||
const session = buildSession(data)
|
if (this.data.loading || !(await this.ensureCanLogin())) return
|
||||||
const userInfo = session.userInfo || {}
|
this.setData({ loading: true })
|
||||||
if (userInfo.shopId) {
|
|
||||||
return session
|
|
||||||
}
|
|
||||||
const shopOptions = buildShopOptions(session)
|
|
||||||
if (!shopOptions.length) {
|
|
||||||
throw new Error('当前账号没有可用店铺,无法进入管理师端')
|
|
||||||
}
|
|
||||||
if (shopOptions.length === 1) {
|
|
||||||
return this.loginForShop(shopOptions[0].id)
|
|
||||||
}
|
|
||||||
this.setData({
|
|
||||||
shopOptions,
|
|
||||||
shopSelectVisible: true,
|
|
||||||
shopSelectMode: 'login'
|
|
||||||
})
|
|
||||||
return null
|
|
||||||
},
|
|
||||||
|
|
||||||
openRegistrationFlow(data) {
|
|
||||||
const ticket = String(data.registrationTicket || '').trim()
|
|
||||||
const status = data.registrationStatus
|
|
||||||
if (status === 'PENDING_ADMIN' || status === 'PENDING_MANAGER') {
|
|
||||||
wx.showToast({ title: status === 'PENDING_ADMIN' ? '管理员审核中' : '店长审核中', icon: 'none', duration: 2500 })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!ticket) {
|
|
||||||
wx.showToast({ title: data.registrationRejectReason || '该手机号需要先完成身份注册', icon: 'none', duration: 2200 })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wx.showToast({ title: '手机号已验证,请完成身份注册', icon: 'none', duration: 1600 })
|
|
||||||
const query = [
|
|
||||||
`registrationTicket=${encodeURIComponent(ticket)}`,
|
|
||||||
`phone=${encodeURIComponent(data.phone || this.data.form.phone || '')}`,
|
|
||||||
data.wxCode ? `wxCode=${encodeURIComponent(data.wxCode)}` : '',
|
|
||||||
data.registrationApplicationId ? `applicationId=${encodeURIComponent(data.registrationApplicationId)}` : ''
|
|
||||||
].filter(Boolean).join('&')
|
|
||||||
setTimeout(() => wx.navigateTo({ url: `/pages/register/index?${query}` }), 700)
|
|
||||||
},
|
|
||||||
|
|
||||||
buildLoginRequestData(shopId) {
|
|
||||||
const form = this.data.form
|
|
||||||
if (this.data.loginMode === 'phone') {
|
|
||||||
return {
|
|
||||||
phone: String(form.phone || '').trim(),
|
|
||||||
verificationCode: String(form.code || '').trim(),
|
|
||||||
rememberMe: !!this.data.rememberMe,
|
|
||||||
...this.buildAgreementPayload(),
|
|
||||||
...(shopId ? { shopId } : {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
account: form.account,
|
|
||||||
password: form.password,
|
|
||||||
rememberMe: !!this.data.rememberMe,
|
|
||||||
...this.buildAgreementPayload(),
|
|
||||||
...(shopId ? { shopId } : {})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
requestLogin(shopId) {
|
|
||||||
const data = this.buildLoginRequestData(shopId)
|
|
||||||
return this.data.loginMode === 'phone'
|
|
||||||
? authApi.phoneLogin(data)
|
|
||||||
: authApi.login(data)
|
|
||||||
},
|
|
||||||
|
|
||||||
async loginForShop(shopId) {
|
|
||||||
return assertShopSession(buildSession(await this.requestLogin(shopId)))
|
|
||||||
},
|
|
||||||
|
|
||||||
async loadLoginShopOptions() {
|
|
||||||
const form = this.data.form
|
|
||||||
const selection = this.data.loginMode === 'phone'
|
|
||||||
? await authApi.getPhoneLoginShops(String(form.phone || '').trim())
|
|
||||||
: await authApi.getLoginShops(String(form.account || '').trim())
|
|
||||||
const shopOptions = buildShopOptionsFromSelection(selection)
|
|
||||||
if (!shopOptions.length) {
|
|
||||||
throw new Error((selection && selection.message) || '当前账号没有可用店铺,无法进入管理师端')
|
|
||||||
}
|
|
||||||
return shopOptions
|
|
||||||
},
|
|
||||||
|
|
||||||
async openLoginShopSelector() {
|
|
||||||
const shopOptions = await this.loadLoginShopOptions()
|
|
||||||
if (shopOptions.length === 1) {
|
|
||||||
await this.loginWithSelectedShop(shopOptions[0].id)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.setData({
|
|
||||||
shopOptions,
|
|
||||||
shopSelectVisible: true,
|
|
||||||
shopSelectMode: 'login'
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
closeShopSelector() {
|
|
||||||
this.setData({
|
|
||||||
shopOptions: [],
|
|
||||||
shopSelectMode: '',
|
|
||||||
shopSelectVisible: false
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
async tryOpenLoginShopSelector() {
|
|
||||||
try {
|
try {
|
||||||
await this.openLoginShopSelector()
|
const result = await authApi.wechatQuickLogin({ wxCode: await wxLoginCode(), ...this.agreementPayload() })
|
||||||
return true
|
this.setData({ loginState: result })
|
||||||
|
await this.handleResult(result)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false
|
this.setData({ loginState: { status: 'ERROR', message: error.message || '快捷登录失败,请重试' } })
|
||||||
|
} finally {
|
||||||
|
this.setData({ loading: false })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async selectLoginShop(event) {
|
async handleResult(result) {
|
||||||
if (this.data.switchingShop) {
|
if (result.status === 'SUCCESS' && result.accessToken) return this.finishLogin(result)
|
||||||
|
if (result.status === 'SELECT_SHOP') {
|
||||||
|
this.setData({ shopOptions: shopOptions(result), loginTicket: result.ticket, shopSelectVisible: true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const shopId = event.currentTarget.dataset.id
|
if (result.status === 'NEED_REGISTRATION' && result.registrationTicket) {
|
||||||
if (!shopId) {
|
const query = [
|
||||||
wx.showToast({ title: '请选择店铺', icon: 'none' })
|
`registrationTicket=${encodeURIComponent(result.registrationTicket)}`,
|
||||||
|
result.registrationApplicationId ? `applicationId=${encodeURIComponent(result.registrationApplicationId)}` : ''
|
||||||
|
].filter(Boolean).join('&')
|
||||||
|
wx.navigateTo({ url: `/pages/register/index?${query}` })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
wx.showToast({ title: result.message || '当前账号暂不能登录', icon: 'none', duration: 2500 })
|
||||||
|
},
|
||||||
|
|
||||||
|
async selectShop(event) {
|
||||||
|
if (this.data.switchingShop) return
|
||||||
this.setData({ switchingShop: true })
|
this.setData({ switchingShop: true })
|
||||||
try {
|
try {
|
||||||
if (this.data.shopSelectMode === 'login') {
|
const result = await authApi.wechatConfirmLogin({
|
||||||
await this.loginWithSelectedShop(shopId)
|
ticket: this.data.loginTicket,
|
||||||
} else if (this.data.shopSelectMode === 'wechat') {
|
shopId: event.currentTarget.dataset.id,
|
||||||
await this.loginWithWechatSelectedShop(shopId)
|
...this.agreementPayload()
|
||||||
} else {
|
})
|
||||||
await this.switchSelectedShop(shopId)
|
if (result.status !== 'SUCCESS' || !result.accessToken) throw new Error(result.message || '进入门店失败')
|
||||||
}
|
this.finishLogin(result)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
wx.showToast({ title: error.message || '进入店铺失败', icon: 'none' })
|
wx.showToast({ title: error.message || '进入门店失败', icon: 'none' })
|
||||||
} finally {
|
} finally {
|
||||||
this.setData({ switchingShop: false })
|
this.setData({ switchingShop: false })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async loginWithSelectedShop(shopId) {
|
finishLogin(result) {
|
||||||
const session = await this.loginForShop(shopId)
|
|
||||||
const app = getApp()
|
|
||||||
app.setSession(session)
|
|
||||||
this.saveLoginPreference()
|
|
||||||
this.closeShopSelector()
|
|
||||||
wx.reLaunch({ url: '/pages/planning/index' })
|
|
||||||
},
|
|
||||||
|
|
||||||
async switchSelectedShop(shopId) {
|
|
||||||
const session = buildSession(await authApi.switchShop(shopId))
|
|
||||||
const app = getApp()
|
|
||||||
app.setSession(session)
|
|
||||||
this.closeShopSelector()
|
|
||||||
wx.reLaunch({ url: '/pages/planning/index' })
|
|
||||||
},
|
|
||||||
|
|
||||||
async loginWithWechatSelectedShop(shopId) {
|
|
||||||
const result = await authApi.wechatConfirmLogin({ ticket: this.data.wechatLoginTicket, shopId, ...this.buildAgreementPayload() })
|
|
||||||
if (result.status !== 'SUCCESS' || !result.accessToken) {
|
|
||||||
throw new Error(result.message || '进入店铺失败')
|
|
||||||
}
|
|
||||||
getApp().setSession(result)
|
getApp().setSession(result)
|
||||||
this.closeShopSelector()
|
auth.setLoginPreference(this.data.rememberMe ? {
|
||||||
|
rememberMe: true,
|
||||||
|
preferredShopId: result.userInfo && result.userInfo.shopId,
|
||||||
|
agreementVersions: this.agreementPayload().agreementVersions
|
||||||
|
} : { rememberMe: false })
|
||||||
wx.reLaunch({ url: '/pages/planning/index' })
|
wx.reLaunch({ url: '/pages/planning/index' })
|
||||||
},
|
|
||||||
|
|
||||||
startCountdown() {
|
|
||||||
if (this.data.countdownTimer) {
|
|
||||||
clearInterval(this.data.countdownTimer)
|
|
||||||
}
|
|
||||||
this.setData({ countdown: 60 })
|
|
||||||
const timer = setInterval(() => {
|
|
||||||
const next = this.data.countdown - 1
|
|
||||||
if (next <= 0) {
|
|
||||||
clearInterval(timer)
|
|
||||||
this.setData({ countdown: 0, countdownTimer: null })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.setData({ countdown: next })
|
|
||||||
}, 1000)
|
|
||||||
this.setData({ countdownTimer: timer })
|
|
||||||
},
|
|
||||||
|
|
||||||
onUnload() {
|
|
||||||
if (this.data.countdownTimer) {
|
|
||||||
clearInterval(this.data.countdownTimer)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async submit() {
|
|
||||||
if (this.data.loading) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const form = this.data.form
|
|
||||||
if (this.data.loginMode === 'password' && (!form.account || !form.password)) {
|
|
||||||
wx.showToast({ title: '请填写账号和密码', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (this.data.loginMode === 'phone' && (!PHONE_REGEX.test(String(form.phone || '').trim()) || !String(form.code || '').trim())) {
|
|
||||||
wx.showToast({ title: '请输入正确手机号和验证码', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await this.loadAgreements()
|
|
||||||
if (!this.ensureAgreementAccepted()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.setData({ loading: true })
|
|
||||||
try {
|
|
||||||
const app = getApp()
|
|
||||||
const data = await this.requestLogin('')
|
|
||||||
if (this.data.loginMode === 'phone' && data && data.registrationRequired) {
|
|
||||||
this.openRegistrationFlow(data)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const session = await this.resolveLoginSession(data)
|
|
||||||
if (!session) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
app.setSession(assertShopSession(session))
|
|
||||||
this.saveLoginPreference()
|
|
||||||
wx.reLaunch({ url: '/pages/planning/index' })
|
|
||||||
} catch (error) {
|
|
||||||
if (String(error.message || '').indexOf('禁用') !== -1) {
|
|
||||||
await this.showRegistrationStatus()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (isShopSelectionRequiredError(error)) {
|
|
||||||
try {
|
|
||||||
if (!this.data.shopSelectVisible) {
|
|
||||||
await this.openLoginShopSelector()
|
|
||||||
}
|
|
||||||
} catch (shopError) {
|
|
||||||
wx.showToast({ title: shopError.message || '店铺列表加载失败', icon: 'none' })
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wx.showToast({ title: error.message || '登录失败', icon: 'none' })
|
|
||||||
} finally {
|
|
||||||
this.setData({ loading: false })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async showRegistrationStatus() {
|
|
||||||
try {
|
|
||||||
const phone = this.data.loginMode === 'phone' ? this.data.form.phone : this.data.form.account
|
|
||||||
const status = await authApi.getRegistrationStatus(String(phone || '').trim())
|
|
||||||
const statusText = {
|
|
||||||
PENDING_ADMIN: '管理员审核中',
|
|
||||||
PENDING_MANAGER: '店长审核中',
|
|
||||||
REJECTED: `申请已驳回:${status.rejectReason || '请修改资料后重新提交'}`,
|
|
||||||
APPROVED: '账号已审核,请稍后重试登录'
|
|
||||||
}[status.status] || '账号暂不可用'
|
|
||||||
wx.showToast({ title: statusText, icon: 'none', duration: 3000 })
|
|
||||||
} catch (statusError) {
|
|
||||||
wx.showToast({ title: statusError.message || '账号已被禁用', icon: 'none' })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async getWechatCode() {
|
|
||||||
const result = await new Promise((resolve, reject) => wx.login({ success: resolve, fail: reject }))
|
|
||||||
return result.code
|
|
||||||
},
|
|
||||||
|
|
||||||
goRegister(wxCode) {
|
|
||||||
const query = wxCode ? `?wxCode=${encodeURIComponent(wxCode)}` : ''
|
|
||||||
wx.navigateTo({ url: `/pages/register/index${query}` })
|
|
||||||
},
|
|
||||||
|
|
||||||
async wechatLogin() {
|
|
||||||
try {
|
|
||||||
const loginResult = await new Promise((resolve, reject) => {
|
|
||||||
wx.login({ success: resolve, fail: reject })
|
|
||||||
})
|
|
||||||
const result = await authApi.wechatAutoLogin(loginResult.code)
|
|
||||||
if (result.status === 'NEED_MANUAL_LOGIN') {
|
|
||||||
wx.showToast({ title: '新账号请先完成手机号注册和身份审核', icon: 'none', duration: 2500 })
|
|
||||||
const wxCode = await this.getWechatCode()
|
|
||||||
setTimeout(() => this.goRegister(wxCode), 900)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (result.status !== 'SUCCESS' || !result.accessToken) {
|
|
||||||
throw new Error(result.message || '微信登录暂不可用')
|
|
||||||
}
|
|
||||||
getApp().setSession(result)
|
|
||||||
wx.reLaunch({ url: '/pages/planning/index' })
|
|
||||||
} catch (error) {
|
|
||||||
wx.showToast({ title: error.message || '微信快捷登录失败', icon: 'none' })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async wechatPhoneLogin(event) {
|
|
||||||
if (this.data.loading || !this.ensureAgreementAccepted()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const phoneCode = event && event.detail && event.detail.code
|
|
||||||
if (!phoneCode) {
|
|
||||||
wx.showToast({ title: '请授权手机号后登录', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.setData({ loading: true })
|
|
||||||
try {
|
|
||||||
const wxCode = await this.getWechatCode()
|
|
||||||
const result = await authApi.wechatPhoneLogin({ wxCode, phoneCode, ...this.buildAgreementPayload() })
|
|
||||||
if (result.registrationRequired) {
|
|
||||||
this.openRegistrationFlow({ ...result, wxCode })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (result.status === 'SELECT_SHOP') {
|
|
||||||
this.setData({ shopOptions: buildShopOptionsFromSelection(result), shopSelectVisible: true, shopSelectMode: 'wechat', wechatLoginTicket: result.ticket, switchingShop: false })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (result.status !== 'SUCCESS' || !result.accessToken) {
|
|
||||||
throw new Error(result.message || '微信手机号登录暂不可用')
|
|
||||||
}
|
|
||||||
getApp().setSession(result)
|
|
||||||
wx.reLaunch({ url: '/pages/planning/index' })
|
|
||||||
} catch (error) {
|
|
||||||
wx.showToast({ title: error.message || '微信手机号登录失败', icon: 'none' })
|
|
||||||
} finally {
|
|
||||||
this.setData({ loading: false })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
{
|
{
|
||||||
"navigationBarTitleText": "登录"
|
"navigationBarTitleText": "登录",
|
||||||
|
"navigationBarBackgroundColor": "#FFFFFF",
|
||||||
|
"navigationBarTextStyle": "black",
|
||||||
|
"backgroundColor": "#FFFFFF"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,16 @@
|
|||||||
<view class="page no-tab auth-page">
|
<view class="login-page">
|
||||||
<view class="topbar"><text class="topbar-title">登录 Salon</text></view>
|
<view class="login-main">
|
||||||
<view wx:if="{{loginView === 'entry'}}" class="entry-view">
|
<view class="brand-area"><image class="login-logo" src="/assets/images/app-icon.png" mode="aspectFill"></image><text class="brand-name">{{appName}}</text><text class="brand-sub">Salon 门店工作台</text></view>
|
||||||
<view class="brand entry-brand"><image class="logo" src="/assets/images/app-icon.png" mode="aspectFill"></image><text class="brand-name">{{appName}}</text><text class="brand-sub">门店工作台</text></view>
|
<view wx:if="{{loginState && loginState.status !== 'READY' && loginState.status !== 'NEW_USER'}}" class="state-line"><text class="state-title">{{loginState.status === 'PENDING_REVIEW' ? '申请审核中' : loginState.status === 'REJECTED' ? '申请需要修改' : loginState.status === 'DISABLED' ? '账号暂不可用' : loginState.status === 'ERROR' ? '连接失败' : '账号状态'}}</text><text class="state-message">{{loginState.registrationRejectReason || loginState.message}}</text></view>
|
||||||
<view class="entry-actions"><button class="primary-btn entry-primary" open-type="getPhoneNumber" bindgetphonenumber="wechatPhoneLogin">快捷登录</button><button class="secondary-btn entry-secondary" data-mode="phone" bindtap="switchLoginMode">验证码登录</button><view class="entry-password" data-mode="password" bindtap="switchLoginMode">账号密码登录</view><view class="entry-register" bindtap="goRegister">注册账号 <text>›</text></view></view>
|
<view class="action-area">
|
||||||
<view class="agreement-row entry-agreement" bindtap="toggleAgreement"><view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view><view class="agreement-copy"><text>我已阅读并同意</text><text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text><text>和</text><text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text></view></view>
|
<button class="quick-btn" loading="{{loading}}" disabled="{{loading || agreementLoading}}" bindtap="quickLogin"><text class="wechat-symbol">微</text><text>微信快捷登录</text></button>
|
||||||
|
<view class="remember-row" bindtap="toggleRememberMe"><view class="check {{rememberMe ? 'checked' : ''}}">{{rememberMe ? '✓' : ''}}</view><text>记住我,下次自动登录</text></view>
|
||||||
</view>
|
</view>
|
||||||
<view wx:if="{{loginView === 'form'}}" class="form-view">
|
|
||||||
<view class="form-heading"><view class="back-entry" data-mode="entry" bindtap="switchLoginMode">‹ <text>返回</text></view><view class="form-title">{{loginMode === 'phone' ? '手机号登录' : '账号密码登录'}}</view><view class="form-subtitle">{{loginMode === 'phone' ? '使用手机号验证码登录工作台' : '使用管理员提供的账号登录'}}</view></view>
|
|
||||||
<view wx:if="{{loginMode === 'password'}}" class="field compact-field"><text class="field-label">账号</text><input value="{{form.account}}" data-field="account" bindinput="onInput" placeholder="请输入账号" /></view>
|
|
||||||
<view wx:if="{{loginMode === 'password'}}" class="field compact-field"><text class="field-label">密码</text><input value="{{form.password}}" data-field="password" bindinput="onInput" password placeholder="请输入密码" /></view>
|
|
||||||
<view wx:if="{{loginMode === 'phone'}}" class="field compact-field"><text class="field-label">手机号</text><input value="{{form.phone}}" data-field="phone" bindinput="onInput" type="text" maxlength="11" placeholder="请输入手机号" /></view>
|
|
||||||
<view wx:if="{{loginMode === 'phone'}}" class="field compact-field"><text class="field-label">验证码</text><view class="code-row"><input class="code-input" value="{{form.code}}" data-field="code" bindinput="onInput" type="text" maxlength="6" placeholder="请输入验证码" /><button class="code-btn {{countdown > 0 ? 'counting' : ''}}" loading="{{codeLoading}}" disabled="{{codeLoading || countdown > 0}}" bindtap="sendLoginCode"><text wx:if="{{countdown > 0}}">重新获取 {{countdown}}s</text><text wx:else>{{codeSent ? '重新获取' : '获取验证码'}}</text></button></view></view>
|
|
||||||
<view class="agreement-row" bindtap="toggleAgreement"><view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view><view class="agreement-copy"><text>我已阅读并同意</text><text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text><text>和</text><text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text></view></view>
|
|
||||||
<view wx:if="{{agreementError}}" class="agreement-error" bindtap="loadAgreements">{{agreementError}},点此重试</view><view class="remember-row" bindtap="toggleRememberMe"><view class="agreement-check {{rememberMe ? 'checked' : ''}}">{{rememberMe ? '✓' : ''}}</view><view class="agreement-copy">记住我,保持登录更久</view></view><button class="primary-btn login-btn {{agreementAccepted ? '' : 'disabled'}}" loading="{{loading}}" disabled="{{loading || agreementLoading}}" bindtap="submit">{{agreementLoading ? '协议加载中...' : '登录'}}</button>
|
|
||||||
<view class="form-links"><view bindtap="switchLoginMode" data-mode="phone" wx:if="{{loginMode === 'password'}}">验证码登录</view><view bindtap="switchLoginMode" data-mode="password" wx:if="{{loginMode === 'phone'}}">账号密码登录</view><view bindtap="goRegister">注册账号</view></view>
|
|
||||||
</view>
|
</view>
|
||||||
<view wx:if="{{agreementModalVisible}}" class="agreement-mask" catchtouchmove="stopTap"><view class="agreement-modal"><view class="agreement-modal-title">{{selectedAgreement.title || '协议详情'}}</view><view class="agreement-modal-meta">版本:{{selectedAgreement.version || '-'}}</view><scroll-view class="agreement-modal-body" scroll-y><text>{{selectedAgreement.content || '暂无协议内容'}}</text></scroll-view><button class="primary-btn agreement-modal-close" bindtap="closeAgreementModal">我知道了</button></view></view>
|
<view class="agreement-footer">
|
||||||
<view wx:if="{{shopSelectVisible}}" class="shop-select-mask"><view class="shop-select-dialog"><view class="shop-select-header"><text class="shop-select-title">选择店铺</text><text class="shop-select-subtitle">请选择本次登录的店铺</text></view><scroll-view class="shop-option-list" scroll-y><view wx:for="{{shopOptions}}" wx:key="id" class="shop-option {{switchingShop ? 'disabled' : ''}}" data-id="{{item.id}}" bindtap="selectLoginShop"><view class="shop-option-icon">店</view><view class="shop-option-copy"><text class="shop-option-name">{{item.name}}</text><text class="shop-option-id">{{item.description || ('ID ' + item.id)}}</text></view></view></scroll-view><view wx:if="{{switchingShop}}" class="shop-switching">正在进入店铺...</view></view></view>
|
<view class="agreement-line" bindtap="toggleAgreement"><view class="check small {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view><view class="agreement-copy"><text>登录即表示已阅读并同意</text><text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text><text>和</text><text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text></view></view>
|
||||||
|
<view wx:if="{{agreementError}}" class="agreement-error" bindtap="loadAgreements">{{agreementError}},点击重试</view>
|
||||||
|
</view>
|
||||||
|
<view wx:if="{{agreementModalVisible}}" class="modal-mask" catchtouchmove="stopTap"><view class="agreement-sheet"><view class="sheet-handle"></view><text class="modal-title">{{selectedAgreement.title || '隐私保护提示'}}</text><text class="modal-version">版本 {{selectedAgreement.version || '-'}}</text><scroll-view class="modal-body" scroll-y><text>{{selectedAgreement.content || '暂无协议内容'}}</text></scroll-view><view class="sheet-actions"><button class="sheet-btn secondary" bindtap="closeAgreementModal">关闭</button><button class="sheet-btn primary" bindtap="acceptAgreementModal">同意并继续</button></view></view></view>
|
||||||
|
<view wx:if="{{shopSelectVisible}}" class="modal-mask center"><view class="shop-dialog"><text class="modal-title">选择本次登录门店</text><view wx:for="{{shopOptions}}" wx:key="id" class="shop-option" data-id="{{item.id}}" bindtap="selectShop"><view class="shop-icon">店</view><text>{{item.name}}</text><text class="shop-arrow">›</text></view><text wx:if="{{switchingShop}}" class="switching">正在进入门店…</text></view></view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -1,554 +1,3 @@
|
|||||||
.auth-page {
|
.login-page { box-sizing:border-box; display:flex; min-height:calc(100vh - 88rpx); flex-direction:column; padding:0 56rpx 38rpx; background:#fff; }.login-main { display:flex; flex:1; flex-direction:column; }.brand-area { display:flex; flex-direction:column; align-items:center; padding-top:190rpx; }.login-logo { width:196rpx; height:196rpx; border-radius:46rpx; }.brand-name { margin-top:26rpx; color:#202522; font-size:40rpx; font-weight:800; letter-spacing:3rpx; }.brand-sub { margin-top:10rpx; color:#9a9f9c; font-size:22rpx; letter-spacing:4rpx; }.action-area { margin-top:118rpx; }.quick-btn { display:flex; align-items:center; justify-content:center; height:92rpx; border-radius:999rpx; background:#2f8f78; color:#fff; font-size:30rpx; font-weight:500; line-height:92rpx; box-shadow:0 10rpx 20rpx rgba(47,143,120,.16); }.quick-btn::after { border:0; }.wechat-symbol { display:flex; align-items:center; justify-content:center; width:38rpx; height:38rpx; margin-right:14rpx; border:2rpx solid rgba(255,255,255,.9); border-radius:50%; font-size:18rpx; font-weight:800; line-height:38rpx; }.remember-row { display:flex; align-items:center; justify-content:center; margin-top:30rpx; color:#737a76; font-size:23rpx; }.check { display:flex; align-items:center; justify-content:center; width:32rpx; height:32rpx; margin-right:12rpx; border:2rpx solid #b7bdb9; border-radius:50%; color:#fff; font-size:19rpx; }.check.small { width:28rpx; height:28rpx; flex:none; margin-right:8rpx; border-radius:7rpx; }.check.checked { border-color:#2f8f78; background:#2f8f78; }.state-line { display:flex; flex-direction:column; align-items:center; margin-top:34rpx; }.state-title { color:#765b32; font-size:24rpx; font-weight:700; }.state-message { margin-top:7rpx; color:#9a8260; font-size:20rpx; text-align:center; }.agreement-footer { padding-top:50rpx; }.agreement-line { display:flex; align-items:flex-start; justify-content:center; }.agreement-copy { color:#a0a4a1; font-size:20rpx; line-height:1.55; text-align:center; }.agreement-link { color:#6b7570; }.agreement-error { margin-top:10rpx; color:#ad6954; font-size:19rpx; text-align:center; }
|
||||||
display: flex;
|
.modal-mask { position:fixed; z-index:20; inset:0; display:flex; align-items:flex-end; background:rgba(0,0,0,.56); }.modal-mask.center { align-items:center; justify-content:center; padding:36rpx; }.agreement-sheet { box-sizing:border-box; width:100%; max-height:74vh; padding:16rpx 42rpx 48rpx; border-radius:28rpx 28rpx 0 0; background:#fff; }.sheet-handle { width:72rpx; height:8rpx; margin:0 auto 34rpx; border-radius:999rpx; background:#e4e5e4; }.modal-title { display:block; color:#222724; font-size:34rpx; font-weight:800; }.modal-version { display:block; margin-top:10rpx; color:#a1a5a2; font-size:21rpx; }.modal-body { height:38vh; margin-top:24rpx; color:#707773; font-size:25rpx; line-height:1.75; white-space:pre-wrap; }.sheet-actions { display:flex; gap:24rpx; margin-top:30rpx; }.sheet-btn { height:88rpx; flex:1; border-radius:14rpx; font-size:29rpx; line-height:88rpx; }.sheet-btn.secondary { background:#f3f3f3; color:#242824; }.sheet-btn.primary { background:#19be72; color:#fff; }.shop-dialog { box-sizing:border-box; width:100%; padding:34rpx; border-radius:24rpx; background:#fff; }.shop-option { display:flex; align-items:center; margin-top:20rpx; padding:22rpx; border-radius:16rpx; background:#f3f8f5; color:#344b40; font-size:26rpx; }.shop-icon { display:flex; align-items:center; justify-content:center; width:52rpx; height:52rpx; margin-right:16rpx; border-radius:14rpx; background:#dbe9df; color:#35634d; font-weight:800; }.shop-arrow { margin-left:auto; color:#82948a; font-size:34rpx; }.switching { display:block; margin-top:20rpx; color:#82948a; text-align:center; }
|
||||||
flex-direction: column;
|
@media (max-height:700px) { .brand-area { padding-top:90rpx; }.action-area { margin-top:70rpx; }.login-logo { width:160rpx; height:160rpx; } }
|
||||||
justify-content: flex-start;
|
|
||||||
padding: 34rpx 28rpx 48rpx;
|
|
||||||
background: #f4f8f5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.brand {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 24rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
|
||||||
width: 112rpx;
|
|
||||||
height: 112rpx;
|
|
||||||
border-radius: 30rpx;
|
|
||||||
background: #e5eee9;
|
|
||||||
box-shadow: 0 16rpx 34rpx rgba(111, 143, 131, 0.24);
|
|
||||||
}
|
|
||||||
|
|
||||||
.brand-name {
|
|
||||||
margin-top: 24rpx;
|
|
||||||
color: #2e4a3d;
|
|
||||||
font-size: 42rpx;
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
.brand-sub {
|
|
||||||
margin-top: 8rpx;
|
|
||||||
color: #7b8f82;
|
|
||||||
font-size: 23rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-card {
|
|
||||||
padding: 30rpx 24rpx 26rpx;
|
|
||||||
border: 1rpx solid #e1ebe3;
|
|
||||||
border-radius: 24rpx;
|
|
||||||
background: #fbfdfb;
|
|
||||||
box-shadow: 0 18rpx 46rpx rgba(55, 94, 72, .08);
|
|
||||||
}
|
|
||||||
|
|
||||||
.welcome-copy { color: #2e4a3d; font-size: 34rpx; font-weight: 800; }
|
|
||||||
.welcome-hint { margin-top: 8rpx; color: #87978c; font-size: 23rpx; }
|
|
||||||
|
|
||||||
.mode-tabs {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
||||||
gap: 12rpx;
|
|
||||||
margin: 12rpx 0 10rpx;
|
|
||||||
padding: 8rpx;
|
|
||||||
border-radius: 12px;
|
|
||||||
background: #edf5ef;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mode-tab {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
min-height: 64rpx;
|
|
||||||
border-radius: 10px;
|
|
||||||
color: #766f66;
|
|
||||||
font-size: 24rpx;
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mode-tab.active {
|
|
||||||
background: #ffffff;
|
|
||||||
color: #3d6652;
|
|
||||||
box-shadow: 0 8rpx 18rpx rgba(58, 48, 34, 0.08);
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-row {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
width: 100%;
|
|
||||||
min-width: 0;
|
|
||||||
gap: 14rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-card .field {
|
|
||||||
display: block;
|
|
||||||
min-height: 0;
|
|
||||||
padding: 0;
|
|
||||||
border: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-card .field-label {
|
|
||||||
display: block;
|
|
||||||
width: auto;
|
|
||||||
margin-bottom: 12rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-card .field input {
|
|
||||||
display: block;
|
|
||||||
box-sizing: border-box;
|
|
||||||
width: 100%;
|
|
||||||
height: 84rpx;
|
|
||||||
flex: none;
|
|
||||||
padding: 0 24rpx;
|
|
||||||
border: 1rpx solid #dfe9e1;
|
|
||||||
border-radius: 14rpx;
|
|
||||||
background: #f7faf7;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-input {
|
|
||||||
width: auto !important;
|
|
||||||
min-width: 0;
|
|
||||||
flex: 1 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-btn {
|
|
||||||
width: 176rpx;
|
|
||||||
min-width: 176rpx;
|
|
||||||
max-width: 176rpx;
|
|
||||||
height: 68rpx;
|
|
||||||
flex: none;
|
|
||||||
padding: 0;
|
|
||||||
border: 1rpx solid #b9d0c0;
|
|
||||||
border-radius: 12rpx;
|
|
||||||
background: #edf5ef;
|
|
||||||
color: #6f8f83;
|
|
||||||
font-size: 24rpx;
|
|
||||||
font-weight: 700;
|
|
||||||
line-height: 68rpx;
|
|
||||||
text-align: center;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-btn.counting {
|
|
||||||
color: #aaa39a;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-row,
|
|
||||||
.remember-row {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 14rpx;
|
|
||||||
margin-top: 22rpx;
|
|
||||||
color: #736c63;
|
|
||||||
font-size: 24rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.remember-row {
|
|
||||||
margin-top: 18rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-check {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 34rpx;
|
|
||||||
min-width: 34rpx;
|
|
||||||
height: 34rpx;
|
|
||||||
border: 1rpx solid #bfb7ad;
|
|
||||||
border-radius: 8rpx;
|
|
||||||
color: #fffdf8;
|
|
||||||
font-size: 22rpx;
|
|
||||||
font-weight: 900;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-check.checked {
|
|
||||||
border-color: #6f8f83;
|
|
||||||
background: #6f8f83;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-copy {
|
|
||||||
flex: 1;
|
|
||||||
line-height: 1.45;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-link {
|
|
||||||
color: #55786d;
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-error {
|
|
||||||
margin-top: 16rpx;
|
|
||||||
color: #c36a6a;
|
|
||||||
font-size: 23rpx;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.login-btn {
|
|
||||||
margin-top: 28rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.login-btn.disabled {
|
|
||||||
opacity: 0.56;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-links {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
margin-top: 18rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wechat-btn {
|
|
||||||
margin-top: 34rpx;
|
|
||||||
border: 1rpx solid #c9dbce;
|
|
||||||
background: #edf5ef;
|
|
||||||
color: #3d6652;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-select-mask {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
z-index: 20;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
padding: 48rpx;
|
|
||||||
background: rgba(36, 33, 29, 0.38);
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-select-dialog {
|
|
||||||
width: 100%;
|
|
||||||
max-height: 76vh;
|
|
||||||
padding: 28rpx;
|
|
||||||
border-radius: 8px;
|
|
||||||
background: #fffdf8;
|
|
||||||
box-shadow: 0 24rpx 64rpx rgba(58, 48, 34, 0.18);
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-select-header {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 8rpx;
|
|
||||||
margin-bottom: 22rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-select-title {
|
|
||||||
color: #24211d;
|
|
||||||
font-size: 32rpx;
|
|
||||||
font-weight: 900;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-select-subtitle {
|
|
||||||
color: #928a80;
|
|
||||||
font-size: 24rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-option-list {
|
|
||||||
max-height: 520rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-option {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 18rpx;
|
|
||||||
min-height: 112rpx;
|
|
||||||
margin-bottom: 14rpx;
|
|
||||||
padding: 18rpx;
|
|
||||||
border: 1rpx solid #ece3d7;
|
|
||||||
border-radius: 8px;
|
|
||||||
background: #fbf7f0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-option.disabled {
|
|
||||||
opacity: 0.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-option-icon {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 72rpx;
|
|
||||||
min-width: 72rpx;
|
|
||||||
height: 72rpx;
|
|
||||||
border-radius: 8px;
|
|
||||||
background: #e5eee9;
|
|
||||||
color: #55786d;
|
|
||||||
font-size: 26rpx;
|
|
||||||
font-weight: 900;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-option-copy {
|
|
||||||
display: flex;
|
|
||||||
min-width: 0;
|
|
||||||
flex: 1;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 8rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-option-name {
|
|
||||||
color: #2f2a25;
|
|
||||||
font-size: 28rpx;
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-option-id {
|
|
||||||
color: #9a9288;
|
|
||||||
font-size: 22rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.shop-switching {
|
|
||||||
margin-top: 12rpx;
|
|
||||||
color: #6f8f83;
|
|
||||||
font-size: 24rpx;
|
|
||||||
font-weight: 700;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-mask {
|
|
||||||
position: fixed;
|
|
||||||
inset: 0;
|
|
||||||
z-index: 90;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
padding: 28rpx;
|
|
||||||
background: rgba(36, 33, 29, 0.42);
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-modal {
|
|
||||||
width: 100%;
|
|
||||||
max-height: 82vh;
|
|
||||||
padding: 30rpx 28rpx;
|
|
||||||
border-radius: 24rpx;
|
|
||||||
background: #fffdf8;
|
|
||||||
box-shadow: 0 24rpx 64rpx rgba(58, 48, 34, 0.18);
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-modal-title {
|
|
||||||
color: #24211d;
|
|
||||||
font-size: 32rpx;
|
|
||||||
font-weight: 900;
|
|
||||||
line-height: 1.35;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-modal-meta {
|
|
||||||
margin-top: 10rpx;
|
|
||||||
color: #928a80;
|
|
||||||
font-size: 22rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-modal-body {
|
|
||||||
height: 640rpx;
|
|
||||||
max-height: 56vh;
|
|
||||||
margin-top: 22rpx;
|
|
||||||
padding: 20rpx;
|
|
||||||
border-radius: 18rpx;
|
|
||||||
background: #f3eee7;
|
|
||||||
color: #2f2a25;
|
|
||||||
font-size: 24rpx;
|
|
||||||
line-height: 1.85;
|
|
||||||
}
|
|
||||||
|
|
||||||
.agreement-modal-close {
|
|
||||||
margin-top: 22rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 简洁登录布局沿用 Salon 现有绿色配色和控件语言。 */
|
|
||||||
.auth-page {
|
|
||||||
box-sizing: border-box;
|
|
||||||
min-height: 100vh;
|
|
||||||
padding: 0 36rpx 48rpx;
|
|
||||||
background: #f4f8f5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topbar {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
height: 96rpx;
|
|
||||||
border-bottom: 1rpx solid #e7eee9;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topbar-title {
|
|
||||||
color: #2e4a3d;
|
|
||||||
font-size: 32rpx;
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-view,
|
|
||||||
.form-view {
|
|
||||||
width: 100%;
|
|
||||||
max-width: 680rpx;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-brand {
|
|
||||||
margin-top: 132rpx;
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-brand .logo {
|
|
||||||
width: 128rpx;
|
|
||||||
height: 128rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-brand .brand-name {
|
|
||||||
margin-top: 22rpx;
|
|
||||||
font-size: 42rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-brand .brand-sub {
|
|
||||||
margin-top: 10rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-actions {
|
|
||||||
margin-top: 132rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-primary,
|
|
||||||
.entry-secondary {
|
|
||||||
width: 100%;
|
|
||||||
height: 92rpx;
|
|
||||||
margin: 0;
|
|
||||||
border-radius: 14rpx;
|
|
||||||
font-size: 29rpx;
|
|
||||||
line-height: 92rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-primary {
|
|
||||||
background: #6f8f83;
|
|
||||||
color: #fffdf8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-secondary {
|
|
||||||
margin-top: 22rpx;
|
|
||||||
border: 1rpx solid #9fbcac;
|
|
||||||
background: #fbfdfb;
|
|
||||||
color: #55786d;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-password,
|
|
||||||
.entry-register {
|
|
||||||
color: #6f8f83;
|
|
||||||
font-size: 26rpx;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-password {
|
|
||||||
margin-top: 30rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-register {
|
|
||||||
margin-top: 24rpx;
|
|
||||||
color: #8b968f;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-register text {
|
|
||||||
margin-left: 4rpx;
|
|
||||||
font-size: 32rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry-agreement {
|
|
||||||
margin-top: 118rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-view {
|
|
||||||
padding-top: 54rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-heading {
|
|
||||||
position: relative;
|
|
||||||
margin-bottom: 72rpx;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.back-entry {
|
|
||||||
position: absolute;
|
|
||||||
top: -8rpx;
|
|
||||||
left: 0;
|
|
||||||
color: #6f8f83;
|
|
||||||
font-size: 30rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.back-entry text {
|
|
||||||
margin-left: 4rpx;
|
|
||||||
font-size: 24rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-title {
|
|
||||||
color: #2e4a3d;
|
|
||||||
font-size: 42rpx;
|
|
||||||
font-weight: 800;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-subtitle {
|
|
||||||
margin-top: 12rpx;
|
|
||||||
color: #87978c;
|
|
||||||
font-size: 23rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.compact-field {
|
|
||||||
margin-top: 28rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.compact-field .field-label {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.compact-field input {
|
|
||||||
box-sizing: border-box;
|
|
||||||
width: 100%;
|
|
||||||
height: 88rpx;
|
|
||||||
padding: 0 8rpx;
|
|
||||||
border-bottom: 1rpx solid #dce7df;
|
|
||||||
background: transparent;
|
|
||||||
color: #2e4a3d;
|
|
||||||
font-size: 29rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.compact-field .code-row {
|
|
||||||
border-bottom: 1rpx solid #dce7df;
|
|
||||||
}
|
|
||||||
|
|
||||||
.compact-field .code-input {
|
|
||||||
height: 88rpx;
|
|
||||||
border-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.compact-field .code-btn {
|
|
||||||
width: 190rpx;
|
|
||||||
min-width: 190rpx;
|
|
||||||
max-width: 190rpx;
|
|
||||||
height: 72rpx;
|
|
||||||
border: 0;
|
|
||||||
background: transparent;
|
|
||||||
color: #55786d;
|
|
||||||
line-height: 72rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-view .agreement-row {
|
|
||||||
margin-top: 44rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-view .remember-row {
|
|
||||||
margin-top: 20rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-view .login-btn {
|
|
||||||
height: 88rpx;
|
|
||||||
margin-top: 38rpx;
|
|
||||||
border-radius: 14rpx;
|
|
||||||
line-height: 88rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-links {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 48rpx;
|
|
||||||
margin-top: 28rpx;
|
|
||||||
color: #6f8f83;
|
|
||||||
font-size: 24rpx;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
const planningApi = require('../../api/planning')
|
const planningApi = require('../../api/planning')
|
||||||
const dateUtil = require('../../utils/date')
|
const dateUtil = require('../../utils/date')
|
||||||
|
const userApi = require('../../api/user')
|
||||||
|
const auth = require('../../utils/auth')
|
||||||
|
const { uploadProfileImage } = require('../../utils/upload')
|
||||||
|
|
||||||
function canCreateAppointment() {
|
function canCreateAppointment() {
|
||||||
const app = getApp()
|
const app = getApp()
|
||||||
@@ -82,7 +85,11 @@ Page({
|
|||||||
pendingCount: 0,
|
pendingCount: 0,
|
||||||
canCreateAppointment: true,
|
canCreateAppointment: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
calendarError: ''
|
calendarError: '',
|
||||||
|
phoneBannerVisible: false,
|
||||||
|
profilePromptVisible: false,
|
||||||
|
profileSaving: false,
|
||||||
|
profileForm: { nickname: '', avatar: '' }
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
@@ -99,6 +106,71 @@ Page({
|
|||||||
wx.removeStorageSync('planningNeedRefresh')
|
wx.removeStorageSync('planningNeedRefresh')
|
||||||
this.loadCalendar()
|
this.loadCalendar()
|
||||||
}
|
}
|
||||||
|
this.refreshAccountPrompts()
|
||||||
|
},
|
||||||
|
|
||||||
|
async refreshAccountPrompts() {
|
||||||
|
try {
|
||||||
|
const profile = await userApi.info()
|
||||||
|
const session = auth.getSession()
|
||||||
|
getApp().setSession({ ...session, userInfo: { ...(session.userInfo || {}), ...profile } })
|
||||||
|
const today = dateUtil.formatDate(new Date())
|
||||||
|
const dismissed = wx.getStorageSync(auth.PHONE_BANNER_DISMISSED_KEY)
|
||||||
|
const missingNickname = !String(profile.nickname || '').trim() || String(profile.nickname).startsWith('微信用户')
|
||||||
|
const skipped = wx.getStorageSync(auth.PROFILE_PROMPT_SKIPPED_KEY) === '1'
|
||||||
|
this.setData({
|
||||||
|
phoneBannerVisible: Number(profile.phoneVerified) !== 1 && dismissed !== today,
|
||||||
|
profilePromptVisible: !skipped && (missingNickname || !profile.avatar),
|
||||||
|
profileForm: { nickname: missingNickname ? '' : profile.nickname, avatar: profile.avatar || '' }
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
// 资料提醒失败不影响规划数据。
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
openAccountSettings() { wx.navigateTo({ url: '/pages/account-settings/index' }) },
|
||||||
|
|
||||||
|
dismissPhoneBanner() {
|
||||||
|
wx.setStorageSync(auth.PHONE_BANNER_DISMISSED_KEY, dateUtil.formatDate(new Date()))
|
||||||
|
this.setData({ phoneBannerVisible: false })
|
||||||
|
},
|
||||||
|
|
||||||
|
onNicknameInput(event) { this.setData({ 'profileForm.nickname': event.detail.value }) },
|
||||||
|
|
||||||
|
async chooseWechatAvatar(event) {
|
||||||
|
const filePath = event.detail && event.detail.avatarUrl
|
||||||
|
if (!filePath) return
|
||||||
|
this.setData({ profileSaving: true })
|
||||||
|
try {
|
||||||
|
const avatar = await uploadProfileImage(filePath)
|
||||||
|
this.setData({ 'profileForm.avatar': avatar })
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ profileSaving: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
skipProfilePrompt() {
|
||||||
|
wx.setStorageSync(auth.PROFILE_PROMPT_SKIPPED_KEY, '1')
|
||||||
|
this.setData({ profilePromptVisible: false })
|
||||||
|
},
|
||||||
|
|
||||||
|
async saveWechatProfile() {
|
||||||
|
const nickname = String(this.data.profileForm.nickname || '').trim()
|
||||||
|
if (!nickname || !this.data.profileForm.avatar) {
|
||||||
|
wx.showToast({ title: '请选择头像并填写昵称', icon: 'none' }); return
|
||||||
|
}
|
||||||
|
this.setData({ profileSaving: true })
|
||||||
|
try {
|
||||||
|
await userApi.updateInfo({ nickname, avatar: this.data.profileForm.avatar })
|
||||||
|
this.setData({ profilePromptVisible: false })
|
||||||
|
wx.showToast({ title: '资料已保存' })
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '资料保存失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ profileSaving: false })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
switchView(event) {
|
switchView(event) {
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
<view class="page planning-page">
|
<view class="page planning-page">
|
||||||
|
<view wx:if="{{phoneBannerVisible}}" class="phone-banner">
|
||||||
|
<view class="phone-banner-track" bindtap="openAccountSettings"><text>绑定手机号,便于账号安全验证与重要通知</text><text>点击前往账号设置</text></view>
|
||||||
|
<view class="phone-banner-close" catchtap="dismissPhoneBanner">×</view>
|
||||||
|
</view>
|
||||||
<view class="card control-card">
|
<view class="card control-card">
|
||||||
<view class="date-row">
|
<view class="date-row">
|
||||||
<view class="date-side">
|
<view class="date-side">
|
||||||
@@ -26,6 +30,15 @@
|
|||||||
</scroll-view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<view wx:if="{{profilePromptVisible}}" class="profile-prompt-mask">
|
||||||
|
<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"><image wx:if="{{profileForm.avatar}}" src="{{profileForm.avatar}}" mode="aspectFill"></image><text wx:else>选择头像</text></button>
|
||||||
|
<input class="wechat-nickname" type="nickname" value="{{profileForm.nickname}}" bindinput="onNicknameInput" placeholder="填写微信昵称" />
|
||||||
|
<button class="profile-save" loading="{{profileSaving}}" bindtap="saveWechatProfile">保存资料</button><button class="profile-skip" bindtap="skipProfilePrompt">暂时跳过</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
<view wx:if="{{calendarError}}" class="calendar-error-card">
|
<view wx:if="{{calendarError}}" class="calendar-error-card">
|
||||||
<view class="calendar-error-copy">
|
<view class="calendar-error-copy">
|
||||||
<text class="calendar-error-title">规划数据加载失败</text>
|
<text class="calendar-error-title">规划数据加载失败</text>
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
padding-top: 18rpx;
|
padding-top: 18rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.phone-banner { display:flex; align-items:center; margin-bottom:18rpx; padding:16rpx 18rpx; border-radius:14rpx; background:#fff2d8; color:#815f2b; overflow:hidden; }.phone-banner-track { display:flex; flex:1; width:0; gap:50rpx; white-space:nowrap; animation:phoneBannerScroll 10s linear infinite; font-size:22rpx; }.phone-banner-close { position:relative; z-index:2; margin-left:18rpx; padding:6rpx; background:#fff2d8; font-size:32rpx; }.profile-prompt-mask { position:fixed; z-index:30; inset:0; display:flex; align-items:center; justify-content:center; padding:40rpx; background:rgba(25,41,33,.55); }.profile-prompt { box-sizing:border-box; display:flex; width:100%; flex-direction:column; align-items:center; padding:36rpx; border-radius:24rpx; background:#fff; }.profile-prompt-title { color:#30483c; font-size:32rpx; font-weight:800; }.profile-prompt-desc { margin-top:10rpx; color:#89988f; font-size:22rpx; text-align:center; }.wechat-avatar { display:flex; align-items:center; justify-content:center; width:128rpx; height:128rpx; margin-top:28rpx; padding:0; border-radius:50%; background:#e6f0e9; color:#416c56; font-size:22rpx; overflow:hidden; }.wechat-avatar image { width:100%; height:100%; }.wechat-nickname { box-sizing:border-box; width:100%; height:80rpx; margin-top:24rpx; padding:0 22rpx; border:1rpx solid #dce8df; border-radius:13rpx; background:#f7faf8; }.profile-save { width:100%; height:80rpx; margin-top:22rpx; border-radius:14rpx; background:#35634d; color:#fff; line-height:80rpx; }.profile-skip { margin-top:12rpx; background:transparent; color:#7e8e85; font-size:23rpx; }
|
||||||
|
@keyframes phoneBannerScroll { from { transform:translateX(0); } to { transform:translateX(-48%); } }
|
||||||
|
|
||||||
.today-btn {
|
.today-btn {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ Page({
|
|||||||
},
|
},
|
||||||
menus: [
|
menus: [
|
||||||
{ title: '个人信息', action: 'editProfile' },
|
{ title: '个人信息', action: 'editProfile' },
|
||||||
|
{ title: '账号设置', url: '/pages/account-settings/index' },
|
||||||
{ title: '店铺设置', url: '/pages/shop-settings/index' },
|
{ title: '店铺设置', url: '/pages/shop-settings/index' },
|
||||||
{ title: '数据导出', url: '/pages/export/index' },
|
{ title: '数据导出', url: '/pages/export/index' },
|
||||||
{ title: '修改密码', url: '/pages/password/index' },
|
|
||||||
{ title: '关于系统', url: '/pages/about/index' }
|
{ title: '关于系统', url: '/pages/about/index' }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -146,6 +146,8 @@ Page({
|
|||||||
nickname: profile.nickname || '',
|
nickname: profile.nickname || '',
|
||||||
avatar: profile.avatar || '',
|
avatar: profile.avatar || '',
|
||||||
phone: profile.phone || currentUserInfo.phone || '',
|
phone: profile.phone || currentUserInfo.phone || '',
|
||||||
|
phoneVerified: profile.phoneVerified,
|
||||||
|
maskedPhone: profile.maskedPhone || '',
|
||||||
contactPhone: profile.contactPhone || '',
|
contactPhone: profile.contactPhone || '',
|
||||||
wechatId: profile.wechatId || '',
|
wechatId: profile.wechatId || '',
|
||||||
signature: profile.signature || '',
|
signature: profile.signature || '',
|
||||||
|
|||||||
@@ -1,112 +1,82 @@
|
|||||||
const authApi = require('../../api/auth')
|
const authApi = require('../../api/auth')
|
||||||
|
|
||||||
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
step: 1,
|
step: 1,
|
||||||
role: 'manager',
|
role: 'manager',
|
||||||
passwordMode: false,
|
form: { shopName: '', shopAddress: '', shopId: '' },
|
||||||
form: { phone: '', code: '', password: '', confirmPassword: '', shopName: '', shopAddress: '', shopId: '' },
|
|
||||||
wxCode: '',
|
|
||||||
registrationTicket: '',
|
registrationTicket: '',
|
||||||
applicationId: '',
|
applicationId: '',
|
||||||
phoneVerified: false,
|
|
||||||
shopOptions: [],
|
shopOptions: [],
|
||||||
shopIndex: 0,
|
shopIndex: 0,
|
||||||
selectedShopName: '',
|
selectedShopName: '',
|
||||||
loading: false,
|
loading: false,
|
||||||
codeLoading: false,
|
ticketInvalid: false
|
||||||
countdown: 0,
|
|
||||||
codeSent: false,
|
|
||||||
countdownTimer: null,
|
|
||||||
agreementAccepted: false
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async onLoad(options) {
|
async onLoad(options) {
|
||||||
const registrationTicket = options && options.registrationTicket ? options.registrationTicket : ''
|
const registrationTicket = options && options.registrationTicket ? options.registrationTicket : ''
|
||||||
this.setData({
|
this.setData({
|
||||||
wxCode: options && options.wxCode ? options.wxCode : '',
|
|
||||||
registrationTicket,
|
registrationTicket,
|
||||||
applicationId: options && options.applicationId ? options.applicationId : '',
|
applicationId: options && options.applicationId ? options.applicationId : '',
|
||||||
phoneVerified: Boolean(registrationTicket),
|
ticketInvalid: !registrationTicket
|
||||||
'form.phone': options && options.phone ? options.phone : '',
|
|
||||||
step: registrationTicket ? 2 : 1
|
|
||||||
})
|
})
|
||||||
try {
|
try {
|
||||||
const shopOptions = await authApi.getAvailableRegistrationShops()
|
const shops = await authApi.getAvailableRegistrationShops()
|
||||||
this.setData({ shopOptions: Array.isArray(shopOptions) ? shopOptions : [] })
|
this.setData({
|
||||||
|
shopOptions: (Array.isArray(shops) ? shops : []).map(item => ({
|
||||||
|
id: item.id,
|
||||||
|
name: item.shopName || item.name,
|
||||||
|
address: item.address || ''
|
||||||
|
}))
|
||||||
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setData({ shopOptions: [] })
|
this.setData({ shopOptions: [] })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onInput(event) {
|
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
|
||||||
const field = event.currentTarget.dataset.field
|
|
||||||
const value = field === 'phone'
|
|
||||||
? String(event.detail.value || '').replace(/\D/g, '').slice(0, 11)
|
|
||||||
: event.detail.value
|
|
||||||
this.setData({ [`form.${field}`]: value })
|
|
||||||
},
|
|
||||||
|
|
||||||
togglePasswordMode() { this.setData({ passwordMode: !this.data.passwordMode }) },
|
|
||||||
|
|
||||||
toggleAgreement() { this.setData({ agreementAccepted: !this.data.agreementAccepted }) },
|
|
||||||
|
|
||||||
async sendCode() {
|
|
||||||
if (!this.data.agreementAccepted) { wx.showToast({ title: '请先同意用户协议和隐私政策', icon: 'none' }); return }
|
|
||||||
const phone = String(this.data.form.phone || '').trim()
|
|
||||||
if (!PHONE_REGEX.test(phone)) { wx.showToast({ title: '请输入正确手机号', icon: 'none' }); return }
|
|
||||||
if (this.data.codeLoading || this.data.countdown > 0) return
|
|
||||||
this.setData({ codeLoading: true })
|
|
||||||
try { await authApi.sendCode(phone); wx.showToast({ title: '验证码已发送' }); this.setData({ codeSent: true }); this.startCountdown() } catch (error) { wx.showToast({ title: error.message || '发送失败', icon: 'none' }) } finally { this.setData({ codeLoading: false }) }
|
|
||||||
},
|
|
||||||
|
|
||||||
continueFromPhone() {
|
|
||||||
const form = this.data.form
|
|
||||||
if (!PHONE_REGEX.test(String(form.phone || '').trim()) || !/^\d{6}$/.test(String(form.code || '').trim())) { wx.showToast({ title: '请输入正确手机号和6位验证码', icon: 'none' }); return }
|
|
||||||
if (this.data.passwordMode && (!form.password || form.password !== form.confirmPassword)) { wx.showToast({ title: '请确认两次密码一致', icon: 'none' }); return }
|
|
||||||
this.setData({ step: 2 })
|
|
||||||
},
|
|
||||||
|
|
||||||
selectRole(event) { this.setData({ role: event.currentTarget.dataset.role }) },
|
selectRole(event) { this.setData({ role: event.currentTarget.dataset.role }) },
|
||||||
|
continueFromRole() { if (!this.data.ticketInvalid) this.setData({ step: 2 }) },
|
||||||
continueFromRole() { this.setData({ step: 3 }) },
|
|
||||||
|
|
||||||
selectShop(event) {
|
selectShop(event) {
|
||||||
const index = Number(event.detail.value)
|
const index = Number(event.detail.value)
|
||||||
const shop = this.data.shopOptions[index]
|
const shop = this.data.shopOptions[index]
|
||||||
if (!shop) return
|
if (shop) this.setData({ shopIndex: index, selectedShopName: shop.name, 'form.shopId': shop.id })
|
||||||
this.setData({ shopIndex: index, selectedShopName: shop.name, 'form.shopId': shop.id })
|
|
||||||
},
|
},
|
||||||
|
|
||||||
goBackStep() { this.setData({ step: Math.max(1, this.data.step - 1) }) },
|
goBackStep() { this.setData({ step: 1 }) },
|
||||||
|
|
||||||
async getCurrentWxCode() {
|
|
||||||
const result = await new Promise((resolve, reject) => wx.login({ success: resolve, fail: reject }))
|
|
||||||
return result.code
|
|
||||||
},
|
|
||||||
|
|
||||||
async submit() {
|
async submit() {
|
||||||
const form = this.data.form
|
const form = this.data.form
|
||||||
if (this.data.role === 'manager' && !String(form.shopName || '').trim()) { wx.showToast({ title: '请输入店铺名称', icon: 'none' }); return }
|
if (!this.data.registrationTicket) {
|
||||||
if (this.data.role === 'staff' && !form.shopId) { wx.showToast({ title: '请选择要加入的店铺', icon: 'none' }); return }
|
wx.showToast({ title: '注册票据已失效,请返回重新快捷登录', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.data.role === 'manager' && !String(form.shopName || '').trim()) {
|
||||||
|
wx.showToast({ title: '请输入店铺名称', icon: 'none' }); return
|
||||||
|
}
|
||||||
|
if (this.data.role === 'staff' && !form.shopId) {
|
||||||
|
wx.showToast({ title: '请选择要加入的店铺', icon: 'none' }); return
|
||||||
|
}
|
||||||
this.setData({ loading: true })
|
this.setData({ loading: true })
|
||||||
try {
|
try {
|
||||||
const wxCode = this.data.registrationTicket ? await this.getCurrentWxCode() : this.data.wxCode
|
await authApi.register({
|
||||||
await authApi.register({ phone: form.phone, verificationCode: this.data.registrationTicket ? undefined : form.code, registrationTicket: this.data.registrationTicket || undefined, applicationId: this.data.applicationId || undefined, password: form.password, confirmPassword: form.confirmPassword, shopName: form.shopName, shopAddress: form.shopAddress, shopId: form.shopId, roleType: this.data.role === 'manager' ? 'MANAGER' : 'STAFF', agreementAccepted: true, wxCode })
|
registrationTicket: this.data.registrationTicket,
|
||||||
this.setData({ step: 4 })
|
applicationId: this.data.applicationId || undefined,
|
||||||
} catch (error) { wx.showToast({ title: error.message || '提交失败', icon: 'none' }) } finally { this.setData({ loading: false }) }
|
shopName: String(form.shopName || '').trim(),
|
||||||
|
shopAddress: String(form.shopAddress || '').trim(),
|
||||||
|
shopId: form.shopId || undefined,
|
||||||
|
roleType: this.data.role === 'manager' ? 'MANAGER' : 'STAFF',
|
||||||
|
agreementAccepted: true
|
||||||
|
})
|
||||||
|
this.setData({ step: 3, registrationTicket: '' })
|
||||||
|
} catch (error) {
|
||||||
|
wx.showToast({ title: error.message || '提交失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
this.setData({ loading: false })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
startCountdown() {
|
back() { wx.reLaunch({ url: '/pages/login/index' }) }
|
||||||
if (this.data.countdownTimer) clearInterval(this.data.countdownTimer)
|
|
||||||
this.setData({ countdown: 60 })
|
|
||||||
const timer = setInterval(() => { const next = this.data.countdown - 1; if (next <= 0) { clearInterval(timer); this.setData({ countdown: 0, countdownTimer: null }); return } this.setData({ countdown: next }) }, 1000)
|
|
||||||
this.setData({ countdownTimer: timer })
|
|
||||||
},
|
|
||||||
|
|
||||||
onUnload() { if (this.data.countdownTimer) clearInterval(this.data.countdownTimer) },
|
|
||||||
|
|
||||||
back() { wx.navigateBack() }
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
<view class="page no-tab auth-page">
|
<view class="page no-tab auth-page">
|
||||||
<view class="auth-header"><image class="logo" src="/assets/images/app-icon.png" mode="aspectFill"></image><view class="header-copy"><text class="brand-name">Salon</text><text class="brand-sub">门店工作台 · 创建你的工作身份</text></view></view>
|
<view class="auth-header"><image class="logo" src="/assets/images/app-icon.png" mode="aspectFill"></image><view class="header-copy"><text class="brand-name">Salon</text><text class="brand-sub">用微信身份申请门店工作权限</text></view></view>
|
||||||
<view class="progress-row"><view class="progress-step {{step >= 1 ? 'active' : ''}}"><text>1</text><label>验证手机</label></view><view class="progress-line {{step >= 2 ? 'active' : ''}}"></view><view class="progress-step {{step >= 2 ? 'active' : ''}}"><text>2</text><label>选择身份</label></view><view class="progress-line {{step >= 3 ? 'active' : ''}}"></view><view class="progress-step {{step >= 3 ? 'active' : ''}}"><text>3</text><label>提交审核</label></view></view>
|
<view class="progress-row"><view class="progress-step {{step >= 1 ? 'active' : ''}}"><text>1</text><label>选择身份</label></view><view class="progress-line {{step >= 2 ? 'active' : ''}}"></view><view class="progress-step {{step >= 2 ? 'active' : ''}}"><text>2</text><label>门店资料</label></view><view class="progress-line {{step >= 3 ? 'active' : ''}}"></view><view class="progress-step {{step >= 3 ? 'active' : ''}}"><text>3</text><label>等待审核</label></view></view>
|
||||||
<view wx:if="{{step === 1}}" class="card form-card">
|
<view wx:if="{{ticketInvalid}}" class="card result-card"><view class="result-icon">!</view><view class="section-title">申请入口已失效</view><view class="section-desc">请返回登录页重新点击微信快捷登录,获取新的申请凭证。</view><button class="primary-btn" bindtap="back">返回登录</button></view>
|
||||||
<view class="section-title">验证手机号</view><view class="section-desc">手机号将作为你的工作台登录账号</view>
|
<view wx:elif="{{step === 1}}" class="card form-card"><view class="section-title">选择工作身份</view><view class="section-desc">无需手机号和密码,审核人会根据你的身份处理申请</view><view class="role-list"><view class="role-option {{role === 'manager' ? 'selected' : ''}}" data-role="manager" bindtap="selectRole"><view class="role-icon">店</view><view class="role-copy"><text class="role-title">店长</text><text class="role-desc">创建并负责一家 Salon 门店</text></view><text class="role-mark">{{role === 'manager' ? '✓' : '○'}}</text></view><view class="role-option {{role === 'staff' ? 'selected' : ''}}" data-role="staff" bindtap="selectRole"><view class="role-icon">员</view><view class="role-copy"><text class="role-title">店员</text><text class="role-desc">加入已有门店协同工作</text></view><text class="role-mark">{{role === 'staff' ? '✓' : '○'}}</text></view></view><button class="primary-btn" bindtap="continueFromRole">继续</button></view>
|
||||||
<view class="field"><text class="field-label">手机号</text><input value="{{form.phone}}" data-field="phone" bindinput="onInput" type="number" maxlength="11" disabled="{{phoneVerified}}" placeholder="请输入手机号" /><text wx:if="{{phoneVerified}}" class="verified-tip">手机号已验证</text></view>
|
<view wx:elif="{{step === 2}}" class="card form-card"><view class="section-title">{{role === 'manager' ? '完善店铺资料' : '选择要加入的店铺'}}</view><view class="section-desc">{{role === 'manager' ? '提交后由平台管理员审核' : '提交后由对应店长审核'}}</view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" placeholder="请输入店铺名称" /></view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺地址</text><input value="{{form.shopAddress}}" data-field="shopAddress" bindinput="onInput" placeholder="请输入门店地址" /></view><view wx:if="{{role === 'staff'}}" class="field"><text class="field-label">选择店铺</text><picker range="{{shopOptions}}" range-key="name" value="{{shopIndex}}" bindchange="selectShop"><view class="picker-value {{selectedShopName ? 'filled' : ''}}">{{selectedShopName || '请选择要加入的店铺'}}</view></picker></view><view wx:if="{{role === 'staff'}}" class="notice">审核通过前不会获得门店业务权限</view><button class="primary-btn" loading="{{loading}}" bindtap="submit">提交审核</button><view class="back-entry" bindtap="goBackStep">返回上一步</view></view>
|
||||||
<view class="field"><text class="field-label">验证码</text><view class="code-row"><input class="code-input" value="{{form.code}}" data-field="code" bindinput="onInput" type="number" placeholder="请输入6位验证码" /><button class="code-btn {{countdown > 0 ? 'counting' : ''}}" loading="{{codeLoading}}" disabled="{{codeLoading || countdown > 0}}" bindtap="sendCode"><text wx:if="{{countdown > 0}}">{{countdown}}s 后重发</text><text wx:else>{{codeSent ? '重新获取' : '获取验证码'}}</text></button></view></view>
|
<view wx:elif="{{step === 3}}" class="card result-card"><view class="result-icon">✓</view><view class="section-title">申请已提交</view><view class="section-desc">{{role === 'manager' ? '平台管理员审核通过后,即可使用快捷登录。' : '店长审核通过后,即可使用快捷登录。'}}</view><view class="result-status">当前状态:<text>等待审核</text></view><button class="primary-btn" bindtap="back">返回登录</button></view>
|
||||||
<view class="agreement-row" bindtap="toggleAgreement"><view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view><view class="agreement-copy">我已阅读并同意《用户协议》和《隐私政策》</view></view><view class="secondary-entry" bindtap="togglePasswordMode">使用密码注册 <text>›</text></view>
|
<view class="safe-note">OpenID 仅用于识别你的微信身份,不会在页面中展示。</view>
|
||||||
<view wx:if="{{passwordMode}}" class="password-panel"><view class="field"><text class="field-label">设置密码</text><input value="{{form.password}}" data-field="password" bindinput="onInput" password placeholder="至少8位密码" /></view><view class="field"><text class="field-label">确认密码</text><input value="{{form.confirmPassword}}" data-field="confirmPassword" bindinput="onInput" password placeholder="再次输入密码" /></view></view>
|
|
||||||
<button class="primary-btn" loading="{{loading}}" bindtap="continueFromPhone">继续</button>
|
|
||||||
</view>
|
|
||||||
<view wx:if="{{step === 2}}" class="card form-card"><view class="section-title">你要加入哪种工作身份?</view><view class="section-desc">不同身份需要由不同的负责人审核</view><view class="role-list"><view class="role-option {{role === 'manager' ? 'selected' : ''}}" data-role="manager" bindtap="selectRole"><view class="role-icon">店</view><view class="role-copy"><text class="role-title">店长</text><text class="role-desc">创建并负责一家 Salon 门店</text></view><text class="role-mark">{{role === 'manager' ? '✓' : '○'}}</text></view><view class="role-option {{role === 'staff' ? 'selected' : ''}}" data-role="staff" bindtap="selectRole"><view class="role-icon">员</view><view class="role-copy"><text class="role-title">店员</text><text class="role-desc">加入已有门店协同工作</text></view><text class="role-mark">{{role === 'staff' ? '✓' : '○'}}</text></view></view><button class="primary-btn" bindtap="continueFromRole">继续</button><view class="back-entry" bindtap="goBackStep">返回上一步</view></view>
|
|
||||||
<view wx:if="{{step === 3}}" class="card form-card"><view class="section-title">{{role === 'manager' ? '完善店铺资料' : '选择要加入的店铺'}}</view><view class="section-desc">{{role === 'manager' ? '提交后由管理员审核,审核通过后即可登录' : '提交后由对应店长审核,审核通过后即可登录'}}</view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" placeholder="请输入店铺名称" /></view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺地址</text><input value="{{form.shopAddress}}" data-field="shopAddress" bindinput="onInput" placeholder="请输入门店所在地址" /></view><view wx:if="{{role === 'staff'}}" class="field"><text class="field-label">选择店铺</text><picker range="{{shopOptions}}" range-key="name" value="{{shopIndex}}" bindchange="selectShop"><view class="picker-value {{selectedShopName ? 'filled' : ''}}">{{selectedShopName || '请选择要加入的店铺'}}</view></picker></view><view wx:if="{{role === 'staff'}}" class="notice">店员申请会发送给所选店铺的店长审核</view><button class="primary-btn" loading="{{loading}}" bindtap="submit">提交审核</button><view class="back-entry" bindtap="goBackStep">返回上一步</view></view>
|
|
||||||
<view wx:if="{{step === 4}}" class="card result-card"><view class="result-icon">✓</view><view class="section-title">申请已提交</view><view class="section-desc">{{role === 'manager' ? '管理员审核通过后,你就可以登录 Salon 工作台。' : '店长审核通过后,你就可以登录 Salon 工作台。'}}</view><view class="result-status">当前状态:<text>等待审核</text></view><button class="primary-btn" bindtap="back">返回登录</button></view>
|
|
||||||
<view class="safe-note">注册并不代表立即获得工作台权限,审核通过后才可登录。</view>
|
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
const SESSION_KEY = 'fingertip_manager_session'
|
const SESSION_KEY = 'fingertip_manager_session'
|
||||||
|
const LOGIN_PREFERENCE_KEY = 'jayucloud_salon_login_preference'
|
||||||
|
const PHONE_BANNER_DISMISSED_KEY = 'jayucloud_salon_phone_banner_dismissed'
|
||||||
|
const PROFILE_PROMPT_SKIPPED_KEY = 'jayucloud_salon_profile_prompt_skipped'
|
||||||
|
|
||||||
function getSession() {
|
function getSession() {
|
||||||
try {
|
try {
|
||||||
@@ -21,9 +24,34 @@ function getAccessToken() {
|
|||||||
return session.accessToken || session.token || ''
|
return session.accessToken || session.token || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLoginPreference() {
|
||||||
|
try { return wx.getStorageSync(LOGIN_PREFERENCE_KEY) || {} } catch (error) { return {} }
|
||||||
|
}
|
||||||
|
|
||||||
|
function setLoginPreference(preference) {
|
||||||
|
wx.setStorageSync(LOGIN_PREFERENCE_KEY, preference || {})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearLoginPreference() {
|
||||||
|
wx.removeStorageSync(LOGIN_PREFERENCE_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearDeviceLoginState() {
|
||||||
|
clearSession()
|
||||||
|
clearLoginPreference()
|
||||||
|
wx.removeStorageSync(PHONE_BANNER_DISMISSED_KEY)
|
||||||
|
wx.removeStorageSync(PROFILE_PROMPT_SKIPPED_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getSession,
|
getSession,
|
||||||
setSession,
|
setSession,
|
||||||
clearSession,
|
clearSession,
|
||||||
getAccessToken
|
getAccessToken,
|
||||||
|
getLoginPreference,
|
||||||
|
setLoginPreference,
|
||||||
|
clearLoginPreference,
|
||||||
|
clearDeviceLoginState,
|
||||||
|
PHONE_BANNER_DISMISSED_KEY,
|
||||||
|
PROFILE_PROMPT_SKIPPED_KEY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Salon 小程序 OpenID 快捷登录说明
|
||||||
|
|
||||||
|
更新时间:2026-10-10
|
||||||
|
|
||||||
|
## 改造范围
|
||||||
|
|
||||||
|
- `JC-Salon-WeChat` 仅展示微信快捷登录,不再展示手机号、验证码和密码登录入口。
|
||||||
|
- `JC-Salon-Core` 新增微信状态探测、快捷登录、注册票据及微信手机号绑定接口。
|
||||||
|
- `docs/scripts/sql/init/jayucloud-salon.sql` 重新定义空库用户基线:账号和密码允许为空,手机号唯一且允许多行 `NULL`。
|
||||||
|
- 未修改 ArtList,未生成迁移或清库脚本,未连接或操作任何实际数据库。
|
||||||
|
|
||||||
|
本次初始化 SQL 调整是经确认的空库模型重定义,属于对仓库“冻结初始化 SQL”规则的明确任务级例外;已有环境的数据处理由后续独立任务负责。
|
||||||
|
|
||||||
|
## 接口与状态
|
||||||
|
|
||||||
|
- `POST /user/wechat-mini/status`:只探测,不创建用户、不签发 Token。
|
||||||
|
- `POST /user/wechat-mini/quick-login`:新 OpenID 创建待审核用户,已审核用户登录。
|
||||||
|
- `POST /user/wechat-mini/confirm-login`:多门店用户选择门店后完成登录。
|
||||||
|
- `POST /user/wechat-mini/bind-phone`:登录后使用微信手机号凭证完成绑定。
|
||||||
|
- 注册票据有效期为 5 分钟,只能使用一次,并在服务端校验用户、AppID 与 OpenID 绑定关系。
|
||||||
|
|
||||||
|
探测状态包括 `NEW_USER`、`PENDING_REVIEW`、`REJECTED`、`READY`、`DISABLED`。只有 `SUCCESS` 登录结果会返回业务 Token。
|
||||||
|
|
||||||
|
## 小程序行为
|
||||||
|
|
||||||
|
- 每次启动先获取新的微信 code 探测状态;探测 code 不复用于登录。
|
||||||
|
- 本机开启“记住我”且状态为 `READY` 时,再获取新 code 自动登录。
|
||||||
|
- 登录后可在“账号设置”使用微信一键绑定或短信验证码绑定手机号。
|
||||||
|
- 规划页未绑定手机号横幅可关闭到当天;主动退出会清除会话、记住我、当天横幅关闭状态和资料提示跳过状态。
|
||||||
|
- 昵称和头像缺失时使用 `chooseAvatar` 与 `input type="nickname"` 引导完善,可在本机跳过。
|
||||||
|
|
||||||
|
## 部署前检查
|
||||||
|
|
||||||
|
1. 确认微信小程序 AppID、AppSecret 配置正确,服务端可访问微信登录及手机号接口。
|
||||||
|
2. 确认 Redis 可用,注册票据与多门店登录票据依赖 Redis 短期存储。
|
||||||
|
3. 新建空库时执行更新后的 `jayucloud-salon.sql`;不得直接对已有环境执行该初始化文件。
|
||||||
|
4. 网关与 Core 白名单已收紧为明确的探测、登录和确认登录路径;`/api/user/wechat-mini/bind-phone` 不在白名单中,必须携带有效登录会话。
|
||||||
|
5. 仓库内 Salon 的 dev、SIT、prod Nacos `gateway.yaml` 已同步该白名单口径;发布配置前应复核目标命名空间,本文不执行任何配置发布。
|
||||||
@@ -597,7 +597,7 @@ create table t_user
|
|||||||
primary key comment '用户主键索引',
|
primary key comment '用户主键索引',
|
||||||
shop_id bigint unsigned default 0 null comment '所属店铺ID,关联店铺表主键(0表示无所属店铺)',
|
shop_id bigint unsigned default 0 null comment '所属店铺ID,关联店铺表主键(0表示无所属店铺)',
|
||||||
nickname varchar(50) not null comment '用户昵称',
|
nickname varchar(50) not null comment '用户昵称',
|
||||||
account varchar(50) not null comment '用户账号(登录用)',
|
account varchar(50) null comment '用户账号(登录用,微信快捷登录用户可为空)',
|
||||||
phone varchar(50) null comment '手机号',
|
phone varchar(50) null comment '手机号',
|
||||||
contact_phone varchar(50) null comment '联系电话',
|
contact_phone varchar(50) null comment '联系电话',
|
||||||
birthday date null comment '生日',
|
birthday date null comment '生日',
|
||||||
@@ -606,7 +606,7 @@ create table t_user
|
|||||||
email varchar(100) null comment '邮箱',
|
email varchar(100) null comment '邮箱',
|
||||||
phone_verified tinyint unsigned default 0 null comment '手机号是否已验证:0-未验证,1-已验证',
|
phone_verified tinyint unsigned default 0 null comment '手机号是否已验证:0-未验证,1-已验证',
|
||||||
email_verified tinyint unsigned default 0 null comment '邮箱是否已验证:0-未验证,1-已验证',
|
email_verified tinyint unsigned default 0 null comment '邮箱是否已验证:0-未验证,1-已验证',
|
||||||
password varchar(100) not null comment '用户密码(加密存储)',
|
password varchar(100) null comment '用户密码(加密存储,微信快捷登录用户可为空)',
|
||||||
signature varchar(200) default '' null comment '用户签名',
|
signature varchar(200) default '' null comment '用户签名',
|
||||||
level varchar(20) default '普通' null comment '用户等级',
|
level varchar(20) default '普通' null comment '用户等级',
|
||||||
type tinyint not null comment '用户类型,(0-用户,2-店长,3-美甲师,4-管理员)',
|
type tinyint not null comment '用户类型,(0-用户,2-店长,3-美甲师,4-管理员)',
|
||||||
@@ -617,7 +617,9 @@ create table t_user
|
|||||||
status tinyint unsigned default 1 null comment '用户状态:1-正常,0-禁用',
|
status tinyint unsigned default 1 null comment '用户状态:1-正常,0-禁用',
|
||||||
avatar varchar(512) null comment '头像链接',
|
avatar varchar(512) null comment '头像链接',
|
||||||
constraint uk_account
|
constraint uk_account
|
||||||
unique (account) comment '用户账号唯一索引'
|
unique (account) comment '用户账号唯一索引',
|
||||||
|
constraint uk_user_phone
|
||||||
|
unique (phone) comment '用户手机号唯一索引(允许多行NULL)'
|
||||||
)
|
)
|
||||||
comment '系统用户信息表';
|
comment '系统用户信息表';
|
||||||
|
|
||||||
@@ -625,10 +627,6 @@ create index idx_email
|
|||||||
on t_user (email)
|
on t_user (email)
|
||||||
comment '按邮箱查询的索引';
|
comment '按邮箱查询的索引';
|
||||||
|
|
||||||
create index idx_phone
|
|
||||||
on t_user (phone)
|
|
||||||
comment '按手机号查询的索引';
|
|
||||||
|
|
||||||
create index idx_shop_id
|
create index idx_shop_id
|
||||||
on t_user (shop_id)
|
on t_user (shop_id)
|
||||||
comment '按店铺查询用户的索引';
|
comment '按店铺查询用户的索引';
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
# 项目变更记录
|
# 项目变更记录
|
||||||
|
|
||||||
|
## 2026-10-10 Salon 小程序 OpenID 快捷登录改造
|
||||||
|
|
||||||
|
- Salon 小程序登录页收敛为微信快捷登录,支持启动状态探测、本机记住登录、多门店选择、审核状态与驳回重提。
|
||||||
|
- 新 OpenID 先创建唯一的待审核用户与微信绑定,角色/门店申请通过一次性注册票据补全同一用户;审核通过前不签发业务 Token。
|
||||||
|
- 手机号改为登录后的可选绑定资料,新增账号设置、微信一键绑定、短信绑定及规划页当天可关闭提醒。
|
||||||
|
- 使用微信 `chooseAvatar` 与 `nickname` 合规组件引导补充资料,个人中心移除修改密码入口。
|
||||||
|
- 按本次明确约束仅更新 Salon 空库初始化 SQL,账号和密码允许为空、手机号增加唯一约束;未生成迁移脚本,未操作实际数据库,未修改 ArtList。
|
||||||
|
- 新增 `docs/scripts/Salon小程序OpenID快捷登录说明_20261010.md`,记录接口、启动行为、部署检查及初始化 SQL 例外原因。
|
||||||
|
- Salon Gateway、Core 及三套 Salon Nacos 配置源将微信匿名白名单收紧到明确登录路径,确保登录后的微信手机号绑定接口必须认证;未发布任何 Nacos 配置。
|
||||||
|
|
||||||
## 2026-09-04 SIT Salon 部署前置配置确认
|
## 2026-09-04 SIT Salon 部署前置配置确认
|
||||||
|
|
||||||
- 已确认 SIT `jayucloud_salon` 数据库完成初始化,SIT 发布继续跳过数据库执行。
|
- 已确认 SIT `jayucloud_salon` 数据库完成初始化,SIT 发布继续跳过数据库执行。
|
||||||
|
|||||||
@@ -139,7 +139,11 @@ fingertip-designer:
|
|||||||
- /api/user/refresh-token
|
- /api/user/refresh-token
|
||||||
- /api/user/send-verification-code
|
- /api/user/send-verification-code
|
||||||
- /api/user/phone-login
|
- /api/user/phone-login
|
||||||
- /api/user/wechat-mini/**
|
- /api/user/wechat-mini/auto-login
|
||||||
|
- /api/user/wechat-mini/phone-login
|
||||||
|
- /api/user/wechat-mini/confirm-login
|
||||||
|
- /api/user/wechat-mini/status
|
||||||
|
- /api/user/wechat-mini/quick-login
|
||||||
- /api/user/workbench/register/**
|
- /api/user/workbench/register/**
|
||||||
- /api/user/workbench/shops/available
|
- /api/user/workbench/shops/available
|
||||||
- /api/user/reset-password-by-phone
|
- /api/user/reset-password-by-phone
|
||||||
|
|||||||
@@ -136,7 +136,11 @@ fingertip-designer:
|
|||||||
- /api/user/refresh-token
|
- /api/user/refresh-token
|
||||||
- /api/user/send-verification-code
|
- /api/user/send-verification-code
|
||||||
- /api/user/phone-login
|
- /api/user/phone-login
|
||||||
- /api/user/wechat-mini/**
|
- /api/user/wechat-mini/auto-login
|
||||||
|
- /api/user/wechat-mini/phone-login
|
||||||
|
- /api/user/wechat-mini/confirm-login
|
||||||
|
- /api/user/wechat-mini/status
|
||||||
|
- /api/user/wechat-mini/quick-login
|
||||||
- /api/user/workbench/register/**
|
- /api/user/workbench/register/**
|
||||||
- /api/user/workbench/shops/available
|
- /api/user/workbench/shops/available
|
||||||
- /api/user/reset-password-by-phone
|
- /api/user/reset-password-by-phone
|
||||||
|
|||||||
@@ -136,7 +136,11 @@ fingertip-designer:
|
|||||||
- /api/user/refresh-token
|
- /api/user/refresh-token
|
||||||
- /api/user/send-verification-code
|
- /api/user/send-verification-code
|
||||||
- /api/user/phone-login
|
- /api/user/phone-login
|
||||||
- /api/user/wechat-mini/**
|
- /api/user/wechat-mini/auto-login
|
||||||
|
- /api/user/wechat-mini/phone-login
|
||||||
|
- /api/user/wechat-mini/confirm-login
|
||||||
|
- /api/user/wechat-mini/status
|
||||||
|
- /api/user/wechat-mini/quick-login
|
||||||
- /api/user/workbench/register/**
|
- /api/user/workbench/register/**
|
||||||
- /api/user/workbench/shops/available
|
- /api/user/workbench/shops/available
|
||||||
- /api/user/reset-password-by-phone
|
- /api/user/reset-password-by-phone
|
||||||
|
|||||||
Reference in New Issue
Block a user