From b11e93651840694d178ed65e27838597b2a874f4 Mon Sep 17 00:00:00 2001 From: lijun Date: Fri, 6 Feb 2026 00:44:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9UniApp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/auth/AppAuthController.java | 25 +- .../app/auth/vo/AppAuthLoginRespVO.java | 3 + .../app/user/vo/AppMemberUserInfoRespVO.java | 3 + .../dal/mysql/user/MemberUserMapper.java | 1 + .../service/auth/MemberAuthService.java | 8 + .../service/auth/MemberAuthServiceImpl.java | 13 +- yanzhu-ui/yanzhu-ui-mall-uniapp/.env | 8 +- yanzhu-ui/yanzhu-ui-mall-uniapp/package.json | 3 +- .../pages/index/category.vue | 2 +- .../pages/index/index.vue | 8 + .../sheep/api/infra/file.js | 5 +- .../sheep/components/s-auth-modal/index.scss | 10 +- .../components/s-auth-modal/s-auth-modal.vue | 25 +- .../sheep/request/index.js | 12 +- .../yanzhu-ui-mall-uniapp/sheep/store/user.js | 5 + .../yanzhu-ui-mall-uniapp/vite.config.js | 8 + yanzhu-ui/yanzhu-ui-mall-uniapp/yarn.lock | 267 ++++++++++++++++++ 17 files changed, 377 insertions(+), 29 deletions(-) create mode 100644 yanzhu-ui/yanzhu-ui-mall-uniapp/yarn.lock diff --git a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/auth/AppAuthController.java b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/auth/AppAuthController.java index 42c3115..0271d17 100644 --- a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/auth/AppAuthController.java +++ b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/auth/AppAuthController.java @@ -7,6 +7,7 @@ import com.yanzhu.framework.security.config.SecurityProperties; import com.yanzhu.framework.security.core.util.SecurityFrameworkUtils; import com.yanzhu.module.member.controller.app.auth.vo.*; import com.yanzhu.module.member.convert.auth.AuthConvert; +import com.yanzhu.module.member.dal.dataobject.user.MemberUserDO; import com.yanzhu.module.member.service.auth.MemberAuthService; import com.yanzhu.module.system.api.social.SocialClientApi; import com.yanzhu.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO; @@ -26,9 +27,13 @@ import javax.validation.Valid; import static com.yanzhu.framework.common.pojo.CommonResult.success; import static com.yanzhu.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; +import com.yanzhu.framework.tenant.core.aop.TenantIgnore; +import com.yanzhu.framework.tenant.core.context.TenantContextHolder; + @Tag(name = "用户 APP - 认证") @RestController @RequestMapping("/member/auth") +@TenantIgnore @Validated @Slf4j public class AppAuthController { @@ -46,7 +51,20 @@ public class AppAuthController { @Operation(summary = "使用手机 + 密码登录") @PermitAll public CommonResult login(@RequestBody @Valid AppAuthLoginReqVO reqVO) { - return success(authService.login(reqVO)); + // 先设置忽略租户,查询用户时不进行租户过滤 + TenantContextHolder.setIgnore(true); + try { + // 先根据手机号查询用户,获取租户ID + MemberUserDO user = authService.getUserByMobile(reqVO.getMobile()); + if (user != null && user.getTenantId() != null) { + TenantContextHolder.setTenantId(user.getTenantId()); + TenantContextHolder.setIgnore(false); + } + return success(authService.login(reqVO)); + } finally { + // 清除上下文 + TenantContextHolder.clear(); + } } @PostMapping("/logout") @@ -75,6 +93,11 @@ public class AppAuthController { @Operation(summary = "使用手机 + 验证码登录") @PermitAll public CommonResult smsLogin(@RequestBody @Valid AppAuthSmsLoginReqVO reqVO) { + // 先根据手机号查询用户,获取租户ID + MemberUserDO user = authService.getUserByMobile(reqVO.getMobile()); + if (user != null && user.getTenantId() != null) { + TenantContextHolder.setTenantId(user.getTenantId()); + } return success(authService.smsLogin(reqVO)); } diff --git a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/auth/vo/AppAuthLoginRespVO.java b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/auth/vo/AppAuthLoginRespVO.java index 1ea6785..adf1ad2 100644 --- a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/auth/vo/AppAuthLoginRespVO.java +++ b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/auth/vo/AppAuthLoginRespVO.java @@ -35,4 +35,7 @@ public class AppAuthLoginRespVO { @Schema(description = "社交用户 openid", example = "qq768") private String openid; + @Schema(description = "租户编号", example = "1") + private Long tenantId; + } diff --git a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java index 544c836..206bd49 100644 --- a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java +++ b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/controller/app/user/vo/AppMemberUserInfoRespVO.java @@ -38,6 +38,9 @@ public class AppMemberUserInfoRespVO { @Schema(description = "是否成为推广员", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") private Boolean brokerageEnabled; + @Schema(description = "租户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "162") + private Long tenantId; + @Schema(description = "用户 App - 会员等级") @Data public static class Level { diff --git a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/dal/mysql/user/MemberUserMapper.java b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/dal/mysql/user/MemberUserMapper.java index 5438de1..e75f21c 100644 --- a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/dal/mysql/user/MemberUserMapper.java @@ -22,6 +22,7 @@ import java.util.stream.Collectors; @Mapper public interface MemberUserMapper extends BaseMapperX { + @com.yanzhu.framework.tenant.core.aop.TenantIgnore default MemberUserDO selectByMobile(String mobile) { return selectOne(MemberUserDO::getMobile, mobile); } diff --git a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/service/auth/MemberAuthService.java b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/service/auth/MemberAuthService.java index 9acd61a..5475125 100644 --- a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/service/auth/MemberAuthService.java +++ b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/service/auth/MemberAuthService.java @@ -85,4 +85,12 @@ public interface MemberAuthService { */ AppAuthLoginRespVO refreshToken(String refreshToken); + /** + * 根据手机号获取用户信息 + * + * @param mobile 手机号 + * @return 用户信息 + */ + com.yanzhu.module.member.dal.dataobject.user.MemberUserDO getUserByMobile(String mobile); + } diff --git a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/service/auth/MemberAuthServiceImpl.java b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/service/auth/MemberAuthServiceImpl.java index 9aa1dd2..56ce6f1 100644 --- a/yanzhu-module-member/src/main/java/com/yanzhu/module/member/service/auth/MemberAuthServiceImpl.java +++ b/yanzhu-module-member/src/main/java/com/yanzhu/module/member/service/auth/MemberAuthServiceImpl.java @@ -152,8 +152,7 @@ public class MemberAuthServiceImpl implements MemberAuthService { return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL, openid); } - private AppAuthLoginRespVO createTokenAfterLoginSuccess(MemberUserDO user, String mobile, - LoginLogTypeEnum logType, String openid) { + private AppAuthLoginRespVO createTokenAfterLoginSuccess(MemberUserDO user, String mobile, LoginLogTypeEnum logType, String openid) { // 插入登陆日志 createLoginLog(user.getId(), mobile, logType, LoginResultEnum.SUCCESS); // 创建 Token 令牌 @@ -161,7 +160,10 @@ public class MemberAuthServiceImpl implements MemberAuthService { .setUserId(user.getId()).setUserType(getUserType().getValue()) .setClientId(OAuth2ClientConstants.CLIENT_ID_DEFAULT)); // 构建返回结果 - return AuthConvert.INSTANCE.convert(accessTokenRespDTO, openid); + AppAuthLoginRespVO respVO = AuthConvert.INSTANCE.convert(accessTokenRespDTO, openid); + // 设置租户ID + respVO.setTenantId(user.getTenantId()); + return respVO; } @Override @@ -257,6 +259,11 @@ public class MemberAuthServiceImpl implements MemberAuthService { return AuthConvert.INSTANCE.convert(accessTokenDO, null); } + @Override + public MemberUserDO getUserByMobile(String mobile) { + return userService.getUserByMobile(mobile); + } + private void createLogoutLog(Long userId) { LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO(); reqDTO.setLogType(LoginLogTypeEnum.LOGOUT_SELF.getType()); diff --git a/yanzhu-ui/yanzhu-ui-mall-uniapp/.env b/yanzhu-ui/yanzhu-ui-mall-uniapp/.env index 4f95bd4..ac9e161 100644 --- a/yanzhu-ui/yanzhu-ui-mall-uniapp/.env +++ b/yanzhu-ui/yanzhu-ui-mall-uniapp/.env @@ -3,9 +3,13 @@ SHOPRO_VERSION=v2.4.1 # 后端接口 - 正式环境(通过 process.env.NODE_ENV 非 development) #SHOPRO_BASE_URL=http://api-dashboard.yudao.iocoder.cn -SHOPRO_BASE_URL=http://127.0.0.1:48080 +#SHOPRO_BASE_URL=http://127.0.0.1:48080 +SHOPRO_BASE_URL= +#http://62.234.3.186 # 后端接口 - 测试环境(通过 process.env.NODE_ENV = development) -SHOPRO_DEV_BASE_URL=http://127.0.0.1:48080 +#SHOPRO_DEV_BASE_URL=http://127.0.0.1:48080 +SHOPRO_DEV_BASE_URL= +#http://62.234.3.186 ### SHOPRO_DEV_BASE_URL=http://10.171.1.188:48080 ### SHOPRO_DEV_BASE_URL = http://yunai.natapp1.cc diff --git a/yanzhu-ui/yanzhu-ui-mall-uniapp/package.json b/yanzhu-ui/yanzhu-ui-mall-uniapp/package.json index 93a5c24..151a979 100644 --- a/yanzhu-ui/yanzhu-ui-mall-uniapp/package.json +++ b/yanzhu-ui/yanzhu-ui-mall-uniapp/package.json @@ -89,11 +89,12 @@ }, "dependencies": { "dayjs": "^1.11.7", - "lodash": "^4.17.21", + "lodash": "^4.17.23", "lodash-es": "^4.17.21", "luch-request": "^3.0.8", "pinia": "^2.0.33", "pinia-plugin-persist-uni": "^1.2.0", + "vue": "^3.5.11", "weixin-js-sdk": "^1.6.0" }, "devDependencies": { diff --git a/yanzhu-ui/yanzhu-ui-mall-uniapp/pages/index/category.vue b/yanzhu-ui/yanzhu-ui-mall-uniapp/pages/index/category.vue index a95f4f0..9b8e491 100644 --- a/yanzhu-ui/yanzhu-ui-mall-uniapp/pages/index/category.vue +++ b/yanzhu-ui/yanzhu-ui-mall-uniapp/pages/index/category.vue @@ -181,7 +181,7 @@ &::before { content: ''; width: 64rpx; - height: 12rpx; + height: 88rpx; background: linear-gradient( 90deg, var(--ui-BG-Main-gradient), diff --git a/yanzhu-ui/yanzhu-ui-mall-uniapp/pages/index/index.vue b/yanzhu-ui/yanzhu-ui-mall-uniapp/pages/index/index.vue index 63a324c..e0e2ff4 100644 --- a/yanzhu-ui/yanzhu-ui-mall-uniapp/pages/index/index.vue +++ b/yanzhu-ui/yanzhu-ui-mall-uniapp/pages/index/index.vue @@ -25,6 +25,8 @@ import { onLoad, onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app'; import sheep from '@/sheep'; import $share from '@/sheep/platform/share'; + import { showAuthModal } from '@/sheep/hooks/useModal'; + import $store from '@/sheep/store'; // 隐藏原生tabBar uni.hideTabBar({ fail: () => {}, @@ -91,6 +93,12 @@ } } // #endif + + // 检查登录状态 + const userStore = $store('user'); + if (!userStore.isLogin) { + showAuthModal('smsLogin'); + } }); // 下拉刷新 diff --git a/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/api/infra/file.js b/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/api/infra/file.js index a4cd093..c034f61 100644 --- a/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/api/infra/file.js +++ b/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/api/infra/file.js @@ -1,4 +1,5 @@ -import { baseUrl, apiPath, tenantId } from '@/sheep/config'; +import { baseUrl, apiPath } from '@/sheep/config'; +import { getTenantId } from '@/sheep/request'; import request, { getAccessToken } from '@/sheep/request'; const FileApi = { @@ -14,7 +15,7 @@ const FileApi = { name: 'file', header: { Accept: '*/*', - 'tenant-id': tenantId, + 'tenant-id': getTenantId(), Authorization: 'Bearer ' + getAccessToken(), }, formData: { diff --git a/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/components/s-auth-modal/index.scss b/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/components/s-auth-modal/index.scss index c4424e7..ae10eb1 100644 --- a/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/components/s-auth-modal/index.scss +++ b/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/components/s-auth-modal/index.scss @@ -83,12 +83,16 @@ .login-btn-start { width: 158rpx; height: 56rpx; - line-height: normal; - background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient)); + line-height: 56rpx; + background: linear-gradient(90deg, var(--ui-BG-Main, #409eff), var(--ui-BG-Main-gradient, #66b1ff)) !important; border-radius: 28rpx; font-size: 26rpx; font-weight: 500; - color: #fff; + color: #fff !important; + border: none; + outline: none; + display: inline-block; + text-align: center; } .type-btn { diff --git a/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/components/s-auth-modal/s-auth-modal.vue b/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/components/s-auth-modal/s-auth-modal.vue index ee74f32..0eec1c4 100644 --- a/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/components/s-auth-modal/s-auth-modal.vue +++ b/yanzhu-ui/yanzhu-ui-mall-uniapp/sheep/components/s-auth-modal/s-auth-modal.vue @@ -1,6 +1,6 @@