This commit is contained in:
2025-04-29 17:58:58 +08:00
parent 095d8335ac
commit 086643b834
5 changed files with 99 additions and 61 deletions
@@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaCheckLogin;
import com.budwk.app.base.constant.RedisConstant;
import com.budwk.app.base.exception.BaseException;
import com.budwk.app.base.result.Result;
import com.budwk.app.client.auth.models.Client_user;
import com.budwk.app.client.auth.service.ClientAuthService;
import com.budwk.app.client.auth.vo.ClientLoginBody;
import com.budwk.app.sys.services.SysMsgService;
@@ -86,6 +87,15 @@ public class ClientAuthController {
}
}
@At("/info")
@Ok("json")
@SaCheckLogin(type = StpClientUtil.TYPE)
public Result info() {
Client_user user = dao.fetch(Client_user.class, StpClientUtil.STP.getLoginIdAsLong());
return Result.success(user);
}
/**
* 退出登录
*/
@@ -69,10 +69,20 @@ public class ClientGroupController {
return Result.success(list);
}
/**
* 查询自己在那个团队
* @param activityId
* @return
*/
@At("/info/?")
@SaCheckLogin(type = StpClientUtil.TYPE)
public Result info(Long activityId) {
Sql sql = Sqls.create("select * from act_group where activityId=@activityId").setParam("activityId", activityId);
ActGroupUser groupUser = dao.fetch(ActGroupUser.class, Cnd.where(ActGroupUser::getUserId, "=", StpClientUtil.STP.getLoginIdAsLong())
.and(ActGroupUser::getActivityId, "=", activityId));
if(Lang.isEmpty(groupUser)){
return Result.error("您还没加入任何团队");
}
Sql sql = Sqls.create("select * from act_group where id=@id").setParam("id", groupUser.getGroupId());
sql.setCallback(Sqls.callback.map());
NutMap map = (NutMap) dao.execute(sql).getResult();
Sql sqlGroupUser = Sqls.create("""
@@ -85,6 +95,8 @@ public class ClientGroupController {
`act_group_user` t1
LEFT JOIN act_user t2 ON t1.userId = t2.userId
WHERE t1.groupId=@groupId
ORDER BY
t1.isLeader DESC
""").setParam("groupId", map.getString("id"));
List<NutMap> groupUsers = clientActivityService.listMap(sqlGroupUser);
map.put("groupUsers", groupUsers);
+6 -3
View File
@@ -1,10 +1,13 @@
<script>
import { setupRouterInterceptor, getDefaultWhiteList } from './utils/routerInterceptor'
import {setupRouterInterceptor, getDefaultWhiteList} from './utils/routerInterceptor'
export default {
globalData: {
user: null
},
onLaunch: function () {
console.log('App Launch')
// 初始化路由拦截器
setupRouterInterceptor(getDefaultWhiteList())
},
@@ -46,7 +49,7 @@ html, body {
overflow-x: hidden;
}
uni-page-body{
uni-page-body {
height: 100%;
}
+21 -24
View File
@@ -1,6 +1,6 @@
<template>
<view class="page-container">
<view v-if="actList&&actList?.length>0">
<view v-if="team">
<t-sticky>
<t-dropdown-menu class="top-dropdown-menu">
<t-dropdown-item :options="actOptions" :value="pageForm.actId" @change="actChange"/>
@@ -17,7 +17,7 @@
<div class="team-basic-info">
<div class="team-name">{{ team.groupName }}</div>
<div class="team-meta">创建于 {{moment(team.createdAt).format("YYYY-MM-DD HH:mm")}}</div>
<div class="team-meta">创建于 {{ moment(team.createdAt).format("YYYY-MM-DD HH:mm") }}</div>
</div>
</div>
@@ -41,9 +41,9 @@
</div>
<!-- 项目报名按钮 -->
<div class="action-section" v-if="team.isSelfLeader">
<div class="action-section" >
<t-button block theme="danger" size="large" class="register-btn" @click="goToEventRegistration">
参与项目报名
{{ team.isSelfLeader ? '参与项目报名' : '查看项目报名' }}
</t-button>
</div>
@@ -103,9 +103,20 @@
</div>
</div>
</view>
<view v-else>暂无团队</view>
</view>
<view v-else style="background-color: #FFFFFF">
<view >
<t-result>
<template #image>
<t-image src="https://tdesign.gtimg.com/mobile/demos/result1.png" class="external-class-image" />
</template>
<template #title>
<div>暂无团队</div>
</template>
</t-result>
</view>
</view>
</view>
<t-dialog
v-model:visible="leaderConfirmVisible"
title="申请成为队长"
@@ -126,8 +137,6 @@
</div>
</template>
</t-dialog>
</template>
<script setup>
@@ -155,21 +164,7 @@ const pageForm = reactive({
const teamId = ''
let team = ref({
id: teamId,
name: 'xx队',
logoUrl: null,
createdDate: '2023-10-15',
eventId: '',
eventName: '',
memberCount: 12,
rank: 5,
score: 256,
description: 'xxxxxxxxxxxxxxxxxxx',
// 团队成员
groupUsers: []
});
let team = ref(null);
// 申请成为队长弹框提示
const leaderConfirmVisible = ref(false)
@@ -190,6 +185,7 @@ const onLeaderConfirm = async () => {
pageForm.groupId = team.value.id
const {code, msg} = await useRequest().post('/client/group/apply-leader/' + team.value.id);
if (code === 0) {
await getTeamInfo();
Toast({message: '申请成功', theme: 'success'});
leaderConfirmVisible.value = false
} else {
@@ -205,13 +201,14 @@ const goToEventRegistration = () => {
uni.navigateTo({url: '/pages/activity/team-form/index?id=' + pageForm.actId})
};
// 根据活动查询队伍信息
const getTeamInfo = async () => {
try {
const {code, msg, data} = await useRequest().post('/client/group/info/' + pageForm.actId);
if (code === 0) {
team.value = data
console.log(team.value.groupUsers.find(t=>t.userId===uni.getStorageSync('userId')))
console.log()
} else {
Toast({message: msg, theme: 'error'});
}
+49 -33
View File
@@ -1,4 +1,5 @@
import {Dialog} from "tdesign-mobile-vue";
import {useRequest} from "@/utils/request";
/**
* 路由拦截器配置
@@ -41,44 +42,61 @@ function addNavigationInterceptors(whiteList) {
* @param {Array} whiteList - 白名单页面列表
* @returns {Object|boolean} - 继续导航或阻止导航
*/
function routeInterceptor(args, whiteList) {
async function routeInterceptor(args, whiteList) {
// 获取目标路径
const token = uni.getStorageSync('token')
const targetUrl = args.url
// 检查目标路径是否在白名单中
const isInWhiteList = whiteList.some(path => {
return targetUrl.startsWith(path) || targetUrl === path
})
let isInWhiteList = targetUrl === '/'
if (!isInWhiteList) {
// 检查目标路径是否在白名单中
isInWhiteList = whiteList.some(path => {
return targetUrl.startsWith(path) || targetUrl === path
})
}
console.log('路由拦截检查:', {url: targetUrl, isInWhiteList, hasToken: !!token})
// 如果不在白名单且未登录,则跳转到登录页
if (!isInWhiteList && !token) {
console.log('拦截导航,跳转到登录页')
// 保存用户尝试访问的页面,以便登录后跳回
try {
uni.setStorageSync('REDIRECT_URL', targetUrl)
} catch (e) {
}
Dialog.confirm({
title: '提示',
content: '您尚未登录,是否前往登录页面?',
cancelBtn: '取消',
confirmBtn: '确认',
onConfirm: () => {
uni.navigateTo({
url: '/pages/login/index'
})
},
onCancel: () => {
console.log('取消登录')
if (!isInWhiteList) {
if (token) {
// 获取用户信息
const {user} = getApp().globalData
if (user == null) {
const {code, data, msg} = await useRequest().get('/client/auth/info')
if (code === 0) {
getApp().globalData.user = data
return args
}
}
})
// 阻止原导航
return false
return args
} else {
console.log('拦截导航,跳转到登录页')
// 保存用户尝试访问的页面,以便登录后跳回
try {
uni.setStorageSync('REDIRECT_URL', targetUrl)
} catch (e) {
}
Dialog.confirm({
title: '提示',
content: '您尚未登录,是否前往登录页面?',
cancelBtn: '取消',
confirmBtn: '确认',
onConfirm: () => {
uni.navigateTo({
url: '/pages/login/index'
})
},
onCancel: () => {
console.log('取消登录')
}
})
// 阻止原导航
return false
}
}
// 继续原导航
return args
@@ -90,9 +108,7 @@ function routeInterceptor(args, whiteList) {
*/
export const getDefaultWhiteList = () => {
return [
'/',
'/pages/index/index',
'/pages/login/index',
'/pages/profile/index'
'/pages/login/index'
]
}