功能:后台登录增加店铺必选
This commit is contained in:
@@ -93,6 +93,7 @@ adminApi.interceptors.response.use(
|
||||
export interface AdminLoginRequest {
|
||||
account: string
|
||||
password: string
|
||||
shopId: number
|
||||
}
|
||||
|
||||
export interface AdminLoginResponse {
|
||||
|
||||
@@ -32,6 +32,19 @@
|
||||
@pressEnter="handleLogin"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="登录店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
size="large"
|
||||
placeholder="请选择登录店铺"
|
||||
:loading="shopLoading"
|
||||
:options="shopOptions"
|
||||
:disabled="shopLoading || shopOptions.length === 0"
|
||||
show-search
|
||||
:filter-option="filterShopOption"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
@@ -55,32 +68,80 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
import { adminAuthApi } from '@/api/admin'
|
||||
import { shopApi, type ShopSimpleVO } from '@/api/shop'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const shopLoading = ref(false)
|
||||
const shops = ref<ShopSimpleVO[]>([])
|
||||
const { loadUserPermissions } = usePermission()
|
||||
|
||||
const formState = reactive({
|
||||
account: '',
|
||||
password: ''
|
||||
password: '',
|
||||
shopId: undefined as number | undefined
|
||||
})
|
||||
|
||||
const shopOptions = computed(() =>
|
||||
shops.value.map(shop => ({
|
||||
label: shop.name,
|
||||
value: shop.id
|
||||
}))
|
||||
)
|
||||
|
||||
const formRules = {
|
||||
account: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择登录店铺', trigger: 'change' }]
|
||||
} as any
|
||||
|
||||
const filterShopOption = (input: string, option: { label?: string | number } | undefined) =>
|
||||
String(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
|
||||
const restoreLoginShop = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(cached)
|
||||
if (parsed?.shopId) {
|
||||
formState.shopId = parsed.shopId
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('恢复后台登录店铺失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadShops = async () => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
shops.value = await shopApi.getShopsSimple() as unknown as ShopSimpleVO[]
|
||||
if (!formState.shopId && shops.value.length === 1) {
|
||||
const [onlyShop] = shops.value
|
||||
if (onlyShop) {
|
||||
formState.shopId = onlyShop.id
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取登录店铺列表失败:', error)
|
||||
message.error('店铺列表加载失败,请刷新后重试')
|
||||
} finally {
|
||||
shopLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
@@ -88,7 +149,8 @@ const handleLogin = async () => {
|
||||
|
||||
const res = await adminAuthApi.login({
|
||||
account: formState.account,
|
||||
password: formState.password
|
||||
password: formState.password,
|
||||
shopId: formState.shopId as number
|
||||
})
|
||||
|
||||
|
||||
@@ -116,6 +178,11 @@ const handleLogin = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
restoreLoginShop()
|
||||
loadShops()
|
||||
})
|
||||
|
||||
const goToFrontend = () => {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
|
||||
+35
@@ -523,6 +523,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
throw new RuntimeException("您没有后台管理权限");
|
||||
}
|
||||
|
||||
Long resolvedShopId = resolveAdminLoginShopId(userDO, loginRequestDTO.getShopId());
|
||||
if (!resolvedShopId.equals(userDO.getShopId())) {
|
||||
userDO.setShopId(resolvedShopId);
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
userMapper.updateById(userDO);
|
||||
}
|
||||
|
||||
String accessToken = jwtUtil.generateAccessToken(userDO.getId(), userDO.getAccount());
|
||||
String refreshToken = jwtUtil.generateRefreshToken(userDO.getId(), userDO.getAccount());
|
||||
|
||||
@@ -542,6 +549,34 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
return responseVO;
|
||||
}
|
||||
|
||||
private Long resolveAdminLoginShopId(UserDO userDO, Long requestedShopId) {
|
||||
if (requestedShopId == null || requestedShopId <= 0) {
|
||||
throw new RuntimeException("请选择登录店铺");
|
||||
}
|
||||
|
||||
ShopVO shopVO = shopService.getShopById(requestedShopId);
|
||||
if (shopVO == null) {
|
||||
throw new RuntimeException("所选店铺不存在或已失效");
|
||||
}
|
||||
|
||||
if (Integer.valueOf(4).equals(userDO.getType())) {
|
||||
return requestedShopId;
|
||||
}
|
||||
|
||||
Long boundShopId = normalizeShopId(userDO.getShopId());
|
||||
if (boundShopId == null) {
|
||||
return requestedShopId;
|
||||
}
|
||||
if (!boundShopId.equals(requestedShopId)) {
|
||||
throw new RuntimeException("当前账号只能选择所属店铺登录");
|
||||
}
|
||||
return boundShopId;
|
||||
}
|
||||
|
||||
private Long normalizeShopId(Long shopId) {
|
||||
return shopId != null && shopId > 0 ? shopId : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(RegisterRequestDTO registerRequestDTO) {
|
||||
if (!verificationCodeService.verifyCode(registerRequestDTO.getPhone(), registerRequestDTO.getVerificationCode())) {
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
- 前端使用axios创建API实例,配置baseURL为`http://wcy111.top:8088/api`
|
||||
- 请求拦截器会在请求头中添加Authorization token
|
||||
- 响应拦截器会处理错误和token过期逻辑
|
||||
- 后台登录页会先调用 `GET /api/shop/list/simple` 加载店铺简表,并要求用户在提交 `POST /api/admin/auth/login` 前显式选择店铺
|
||||
|
||||
2. **Token管理**:
|
||||
- 前端使用双token模式:accessToken(2小时过期)和refreshToken(7天过期)
|
||||
@@ -54,6 +55,7 @@
|
||||
- AuthInterceptor会进一步验证token的有效性
|
||||
- 验证token是否过期、是否为accessToken类型
|
||||
- 从token中提取用户信息并设置到请求属性中
|
||||
- 后台账号密码登录会强制校验 `shopId`,防止仅靠前端“选店铺”表单限制被绕过
|
||||
- 订单创建时还会校验购物车归属、同店铺/同美甲师约束、预约时间有效性、门店营业时间以及美甲师已有预约冲突
|
||||
- 用户资产相关操作改为通过 `UserAssetService` 统一事务处理,保证余额、累计充值、流水、VIP 状态一次提交
|
||||
- 订单结算会区分 `USER_COUPON` 与 `SYSTEM_VIP` 两类优惠来源;未显式选券时只自动补用最佳 VIP 自动券,不会自动消耗普通用户券
|
||||
@@ -587,7 +589,7 @@ registry.addInterceptor(authInterceptor)
|
||||
- `POST /api/user/login` - 用户登录
|
||||
- `POST /api/user/register` - 用户注册
|
||||
- `POST /api/user/refresh-token` - 刷新token
|
||||
- `POST /api/admin/auth/login` - 管理员登录
|
||||
- `POST /api/admin/auth/login` - 管理员登录,必须携带 `shopId`
|
||||
|
||||
### 9.2 业务相关
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# 2026-03-20 后台登录增加店铺必选
|
||||
|
||||
## 本轮目标
|
||||
|
||||
- 为后台登录页增加“必须选择店铺”的前端交互
|
||||
- 为后台账号密码登录增加服务端强校验,避免仅靠前端限制被绕过
|
||||
- 保持当前后台店铺边界不被放宽
|
||||
|
||||
## 变更内容
|
||||
|
||||
### 1. 后台登录页改为必选店铺
|
||||
|
||||
- 更新 [AdminLoginView.vue](/E:/code/xiaowang/Frontend/src/views/admin/AdminLoginView.vue)
|
||||
- 登录表单新增“登录店铺”下拉
|
||||
- 店铺数据通过免鉴权接口 `GET /api/shop/list/simple` 加载
|
||||
- 登录请求改为携带 `shopId`
|
||||
- 如果本地缓存里已有上次后台登录的店铺,会自动回填;只有一家店铺时会自动选中
|
||||
|
||||
### 2. 后端管理员登录增加店铺校验
|
||||
|
||||
- 更新 [UserServiceImpl.java](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/UserServiceImpl.java)
|
||||
- `adminLogin` 现在必须传入合法的 `shopId`
|
||||
- 店长、美甲师:
|
||||
- 如果账号已绑定店铺,则只能选择自己的所属店铺登录
|
||||
- 如果账号尚未绑定店铺,则沿用现有前台登录口径,在首次后台登录时写入所选店铺
|
||||
- 平台管理员:
|
||||
- 登录时也必须显式选择一个店铺
|
||||
- 选择结果会回写到当前账号的 `shopId` 字段,供登录态和页面上下文展示使用
|
||||
|
||||
## 边界说明
|
||||
|
||||
- 本轮没有改变平台管理员 `type = 4` 的平台级权限身份,只是把“选店铺”变成后台登录的必填项。
|
||||
- 现有后台业务接口的店铺作用域规则保持不变,美甲师、店长仍按已有所属店铺边界受限。
|
||||
|
||||
## 验证
|
||||
|
||||
- 前端执行 `npm run build` 通过
|
||||
- 后端执行 `mvn -q -DskipTests compile` 通过
|
||||
Reference in New Issue
Block a user