Skip to content

Commit

Permalink
Merge pull request eee555#39 from putianyi889/patch-30
Browse files Browse the repository at this point in the history
管理员审核、冻结UI
  • Loading branch information
eee555 authored Jun 3, 2024
2 parents 2a3a6e4 + 847d67e commit 6fd5173
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 19 deletions.
4 changes: 2 additions & 2 deletions back_end/saolei/userprofile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def user_login(request):
# login(request, request.user)
response['msg'] = response['msg'] = {
"id": request.user.id, "username": request.user.username,
"realname": request.user.realname, "is_banned": request.user.is_banned}
"realname": request.user.realname, "is_banned": request.user.is_banned, "is_staff": request.user.is_staff}
return JsonResponse(response)
# if user_id:=request.session.get("_auth_user_id"):
# if user:=User.objects.get(id=user_id):
Expand All @@ -59,7 +59,7 @@ def user_login(request):
login(request, user)
response['msg'] = {
"id": user.id, "username": user.username,
"realname": user.realname, "is_banned": user.is_banned}
"realname": user.realname, "is_banned": user.is_banned, "is_staff": user.is_staff}
if 'user_id' in data and data['user_id'] != str(user.id):
# 检测到小号
logger.info(f'{data["user_id"][:50]} is diffrent from {str(user.id)}.')
Expand Down
3 changes: 2 additions & 1 deletion back_end/saolei/videomanager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def video_query(request):

values = video_all_fields

# 排序
if data["r"] == "true":
ob = "-" + data["o"]
else:
Expand Down Expand Up @@ -362,7 +363,7 @@ def approve(request):
update_video_num(video_i)
cache.hdel("review_queue", _id)
# logger.info(f'{request.user.id} approve {json.dumps(ids)} response {json.dumps(res)}')
return JsonResponse(json.dumps(res), safe=False)
return JsonResponse(res, safe=False)
else:
return HttpResponse("别瞎玩")

Expand Down
74 changes: 70 additions & 4 deletions front_end/src/components/VideoList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
src="/flop/index.html" ref="video_iframe"></iframe>
</el-dialog>
</Teleport>
<el-table :data="videos_trans" :show-header="false" @row-click="preview"
<el-table :data="videos_trans" :show-header="false" @row-click="preview" table-layout="auto"
style="width: 100%; color: black;font-size: 16px;">
<el-table-column prop="time" min-width="200" />
<el-table-column v-if="need_player_name" min-width="80">
Expand All @@ -20,6 +20,13 @@
<el-table-column prop="mode" min-width="80" />
<el-table-column prop="rtime" min-width="90" />
<el-table-column prop="bv" min-width="60" />
<el-table-column style="white-space: nowrap;">
<template #default="scope">
<el-button v-if="review_mode" type="success" circle :icon="Check" @click="handleApprove(scope.row)" />
<el-button v-if="store.user.is_staff" type="danger" circle :icon="Close"
@click="handleFreeze(scope.row)" />
</template>
</el-table-column>
<!-- <el-table-column min-width="200">
<template #default="scope">
<PreviewDownload :id="scope.row.key"></PreviewDownload>
Expand All @@ -37,7 +44,13 @@ import PlayerName from '@/components/PlayerName.vue';
const preview_visible = ref(false);
import useCurrentInstance from "@/utils/common/useCurrentInstance";
import { getRowIdentity } from 'element-plus/es/components/table/src/util';
import { ms_to_s } from '@/utils';
import { Check, Close } from '@element-plus/icons-vue';
import { ElNotification } from 'element-plus';
import { useUserStore } from '@/store';
const store = useUserStore()
import { ms_to_s, approve, freeze } from '@/utils';
const { proxy } = useCurrentInstance();
const data = defineProps({
Expand All @@ -54,13 +67,19 @@ const data = defineProps({
need_player_name: {
type: Boolean,
default: true
},
review_mode: {
type: Boolean,
default: false
}
})
const emit = defineEmits(['update'])
const videos_trans = computed(() => {
data.videos.forEach((v: any) => {
// console.log(v);
v.time = utc_to_local_format(v.time);
if (v.level == "b") {
v.level = "初级";
Expand All @@ -69,7 +88,7 @@ const videos_trans = computed(() => {
} else if (v.level == "e") {
v.level = "高级";
}
v.rtime = ms_to_s(v.timems)+ "s";
v.rtime = ms_to_s(v.timems) + "s";
if (v.mode == "00") {
v.mode = "标准";
} else if (v.mode == "01") {
Expand Down Expand Up @@ -161,6 +180,53 @@ const playVideo = function (uri: string) {
});
}
const handleApprove = async function (row: any) {
let status = await approve(proxy, row.key);
if (status == 'True') {
ElNotification({
title: '审核成功',
message: '录像已通过审核',
type: 'success',
})
} else if (status == 'False') {
ElNotification({
title: '审核失败',
message: '录像已通过审核',
type: 'warning',
})
} else {
ElNotification({
title: '审核失败',
message: '发生未知错误: status=' + status,
type: 'error',
})
}
emit('update')
}
const handleFreeze = async function (row: any) {
let status = await freeze(proxy, row.key);
if (status == 'True') {
ElNotification({
title: '审核成功',
message: '录像已通过审核',
type: 'success',
})
} else if (status == 'False') {
ElNotification({
title: '审核失败',
message: '录像已通过审核',
type: 'warning',
})
} else {
ElNotification({
title: '审核失败',
message: '发生未知错误: status=' + status,
type: 'error',
})
}
emit('update')
}
</script>
<style></style>
1 change: 1 addition & 0 deletions front_end/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const useUserStore = defineStore('user', {
username: "",
realname: "",
is_banned: false,
is_staff: true,
country: ""
}, // 真正的用户
// 访问谁的地盘不再具有记忆性。即点“我的地盘”,将永远是“我”的地盘
Expand Down
25 changes: 25 additions & 0 deletions front_end/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,29 @@ export function ms_to_s(ms: number): string {
return `${Math.floor(ms / 1000)}.${(ms % 1000 + "").padStart(3, '0')}`;
}

import { ComponentCustomProperties } from "vue";
export async function approve(proxy: ComponentCustomProperties & Record<string, any>, id: number) {
var status;
await proxy.$axios.get('video/approve?ids=[' + id + ']').then(function (response) {
const data = response.data;
if (data.length != 1) {
console.log(data)
throw new Error('Unexpected error')
}
status = data[0]
}).catch()
return status
}

export async function freeze(proxy: ComponentCustomProperties & Record<string, any>, id: number) {
var status;
await proxy.$axios.get('video/freeze?ids=[' + id + ']').then(function (response) {
const data = response.data;
if (data.length != 1) {
console.log(data)
throw new Error('Unexpected error')
}
status = data[0]
}).catch()
return status
}
36 changes: 24 additions & 12 deletions front_end/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<VideoList :videos="newest_queue" :reverse="true"></VideoList>
</el-tab-pane>
<el-tab-pane label="审核队列" class="bottom_tabs" :lazy="true">
<VideoList :videos="review_queue"></VideoList>
<VideoList :videos="review_queue" :review_mode="store.user.is_staff" @update="update_review_queue" v-loading="review_queue_updating"></VideoList>
</el-tab-pane>
</el-tabs>
</el-main>
Expand All @@ -45,22 +45,17 @@ import { to_fixed_n } from "@/utils";
const { proxy } = useCurrentInstance();
import { utc_to_local_format } from "@/utils/system/tools";
import { useUserStore } from '../store'
const store = useUserStore()
const review_queue = ref<any[]>([]);
const newest_queue = ref<any[]>([]);
const news_queue = ref<any[]>([]);
const review_queue_updating = ref(false);
onMounted(() => {
proxy.$axios.get('/video/review_queue/',
{
params: {}
}
).then(function (response) {
for (let key in response.data) {
response.data[key] = JSON.parse(response.data[key] as string);
response.data[key]["key"] = Number.parseInt(key);
review_queue.value.push(response.data[key]);
}
})
update_review_queue()
proxy.$axios.get('/video/newest_queue/',
{
params: {}
Expand Down Expand Up @@ -123,6 +118,23 @@ const trans_index = (i: string) => {
}
}
const update_review_queue = async () => {
review_queue_updating.value = true
await proxy.$axios.get('/video/review_queue/',
{
params: {}
}
).then(function (response) {
review_queue.value.splice(0,review_queue.value.length)
for (let key in response.data) {
response.data[key] = JSON.parse(response.data[key] as string);
response.data[key]["key"] = Number.parseInt(key);
review_queue.value.push(response.data[key]);
}
})
review_queue_updating.value = false
}
</script>

<style scope lang='less'>
Expand Down

0 comments on commit 6fd5173

Please sign in to comment.