Skip to content

Commit

Permalink
fix:访问他人地盘时,不能刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
eee555 committed Jul 4, 2024
1 parent 811dcff commit 696b58c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
4 changes: 3 additions & 1 deletion back_end/saolei/msuser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def get_info(request):
"avatar": image_data,
"signature": user.signature,
"popularity": user.popularity,
"designators": user.userms.designators
"designators": user.userms.designators,
"is_banned": user.is_banned,
"country": user.country
}
return JsonResponse(response)
else:
Expand Down
4 changes: 2 additions & 2 deletions front_end/src/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const login = async () => {
// 先用cookie尝试登录,可能登不上
// 再用用户名密码
var params = new URLSearchParams()
const _id = localStorage.getItem("user_id");
const _id = localStorage.getItem("history_user_id");
params.append('user_id', _id ? _id : "");
params.append('username', user_name.value)
params.append('password', user_password.value)
Expand Down Expand Up @@ -306,7 +306,7 @@ const login = async () => {
// // 如果本次是自动登录成功的,下次依然自动登录
// remember_me.value = true;
// }
// localStorage.setItem("user_id", response.data.id + "");
localStorage.setItem("history_user_id", response.data.id + "");
} else if (response.data.status >= 101) {
hint_message.value = response.data.msg;
// console.log("登录失败");
Expand Down
7 changes: 5 additions & 2 deletions front_end/src/components/PlayerName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import Wait from '@/components/Wait.vue';
import { useRouter } from 'vue-router'
import { ms_to_s } from "@/utils"
const router = useRouter()
import { useUserStore } from '../store'
const store = useUserStore()
const data = defineProps({
Expand Down Expand Up @@ -167,8 +169,9 @@ function to_fixed_n(input: string | number | undefined, to_fixed: number): strin
const visit_me = (user_id: Number) => {
// proxy.$store.commit('updatePlayer', { "id": id.value, "realname":realname.value });
// localStorage.setItem("player", JSON.stringify({ "id": id.value, "realname":realname.value }));
localStorage.setItem("player", JSON.stringify({ "id": id.value }));
router.push("player")
// localStorage.setItem("player", JSON.stringify({ "id": id.value }));
store.player.id = +id.value;
router.push(`player\/${store.player.id}`)
}
</script>
Expand Down
7 changes: 4 additions & 3 deletions front_end/src/views/PlayerRecordView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<script lang="ts" setup>
// 个人主页的个人纪录部分
import { onMounted, ref, Ref } from 'vue'
import { onMounted, ref, Ref, nextTick } from 'vue'
import useCurrentInstance from "@/utils/common/useCurrentInstance";
import PreviewNumber from '@/components/PreviewNumber.vue';
import { genFileId, ElMessage } from 'element-plus'
Expand Down Expand Up @@ -85,12 +85,13 @@ const indexMethod = (index: number) => {
return ["", t.t('common.level.b'), t.t('common.level.i'), t.t('common.level.e')][index + 1]
}
onMounted(() => {
// 此处和父组件配合,等一下从store里获取用户的id
nextTick(() => {
// const player = proxy.$store.state.player;
// const player = JSON.parse(localStorage.getItem("player") as string);
// username.value = player.name;
// 把左侧的头像、姓名、个性签名、记录请求过来
proxy.$axios.get('/msuser/records/',
{
Expand Down
5 changes: 4 additions & 1 deletion front_end/src/views/PlayerVideosView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const { proxy } = useCurrentInstance();
import { Record, RecordBIE } from "@/utils/common/structInterface";
import VideoList from '@/components/VideoList.vue';
// import { fa } from 'element-plus/es/locale';
import { useUserStore } from '../store'
const store = useUserStore()
const loading = ref(true)
Expand All @@ -22,7 +24,8 @@ const videos_queue = ref<any[]>([]);
onMounted(() => {
// const player = proxy.$store.state.player;
const player = JSON.parse(localStorage.getItem("player") as string);
// const player = JSON.parse(localStorage.getItem("player") as string);
const player = store.player;
proxy.$axios.get('/video/query_by_id/',
{
params: {id: player.id}
Expand Down
16 changes: 14 additions & 2 deletions front_end/src/views/PlayerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,17 @@ onMounted(() => {
// 把左侧的头像、姓名、个性签名、记录请求过来
let player_id = +proxy.$route.params.id;
// http://localhost:8080/#/player/1
// 首先看url里有没有带参,如果有,就访问这个用户;其次看store里有没有用户id。
if (Number.isInteger(player_id) && player_id >= 1) {
player.id = player_id;
localStorage.setItem("player", JSON.stringify({ "id": player_id }));
store.player.id = player_id;
// localStorage.setItem("player", JSON.stringify({ "id": player_id }));
} else {
player.id = JSON.parse(localStorage.getItem("player") as string).id as number;
// player.id = JSON.parse(localStorage.getItem("player") as string).id as number;
player.id = store.player.id;
}
show_edit_button = player.id == store.user.id;
Expand All @@ -173,6 +179,12 @@ onMounted(() => {
}
).then(function (response) {
const data = response.data;
store.player.realname = data.realname;
store.player.username = data.username;
store.player.is_banned = data.is_banned;
store.player.country = data.country;
userid.value = data.id;
realname.value = data.realname;
username.value = data.username;
Expand Down

0 comments on commit 696b58c

Please sign in to comment.