Skip to content

Commit

Permalink
适配管理员管理界面
Browse files Browse the repository at this point in the history
  • Loading branch information
unify-z committed Aug 28, 2024
1 parent 1970589 commit b09796e
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<el-menu-item index="1" @click="router.push('/dashboard')">主页</el-menu-item>
<el-menu-item index="2" @click="router.push('/dashboard/rank')">排行榜</el-menu-item>
<el-menu-item index="3" @click="router.push('/dashboard/myclusters')">我的节点</el-menu-item>
<el-menu-item index="4" v-if="isAdmin.valueOf" @click="router.push('/dashboard/admin')">管理页</el-menu-item>
<el-menu-item>
<el-button @click="switchThemes()">
<el-icon>
Expand All @@ -16,7 +17,7 @@
</el-button>
</el-menu-item>
<el-menu-item>
<el-button v-if="!isTokenPresent()" @click="router.push('/auth/login')" type="primary">登录</el-button>
<el-button v-if="!isTokenPresent()" @click="router.push('/dashboard/auth/login')" type="primary">登录</el-button>
<div v-else style="display: flex; align-items: center;">
<img :src="userInfo.avatar_url" alt="Avatar" style="width: 40px; height: 40px; border-radius: 50%;">
<span style="margin-left: 8px;">{{ userInfo.login }}</span>
Expand Down Expand Up @@ -44,10 +45,10 @@ const isTokenPresent = (): boolean => {
const token = Cookies.get('token');
return !!token;
}
const isAdmin = ref(false)
const userInfo = ref({
avatar_url: '',
login: ''
login: '',
})
const getuserinfo = async () => {
Expand All @@ -56,6 +57,14 @@ const getuserinfo = async () => {
withCredentials: true,
});
userInfo.value = response.data;
if (response.data.is_super_admin){
isAdmin.value = true
}else{
isAdmin.value = false
}
console.log(isAdmin.value)
} catch (error) {
console.error('Error:', error);
}
Expand Down
102 changes: 102 additions & 0 deletions src/pages/dashboard/admin/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<template>
<div>
<el-card style="margin-top:20px; display: grid; place-items: center;">
<el-button type="primary" @click="showDialog()" style="margin: 0 10px;">创建节点</el-button>
<el-button type="primary" @click="banCluster()" style="margin: 0 10px;">封禁节点</el-button>
<el-button type="primary" @click="unbanCluster()" style="margin: 0 10px;">解封节点</el-button>
</el-card>
<el-dialog v-model="dialogVisible" title="创建节点" width="50%">
<el-form label-position="top" label-width="100px">
<el-form-item label="节点名称">
<el-input v-model="clusterName" placeholder="节点名称"></el-input>
</el-form-item>
<el-form-item label="带宽">
<el-input v-model="bandwidth" placeholder="带宽"></el-input>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="createCluster">提交</el-button>
</span>
</template>
</el-dialog>
</div>
</template>

<script setup lang="js">
import { ref } from 'vue';
import { ElMessageBox, ElMessage, ElButton, ElDialog, ElForm, ElFormItem, ElInput } from 'element-plus';
import axios from 'axios';
const dialogVisible = ref(false);
const clusterName = ref('');
const bandwidth = ref('');
async function createCluster(){
const url = `https://saltwood.top:9393/93AtHome/super/cluster/create`
try {
await axios.post(url, {
clusterName: clusterName.value,
bandwidth: bandwidth.value,
}, {
withCredentials: true,
});
ElMessage.success('节点创建成功');
dialogVisible.value = false;
fetchClusters();
} catch (error) {
ElMessage.error('节点创建失败: ' + error);
console.error(error);
}
}
function banCluster(){
ElMessageBox.prompt('输入要封禁的节点Id', '提示', {
confirmButtonText: '提交',
cancelButtonText: '取消',
placeholder: 'ClusterId'
})
.then(async ({ value }) => {
const url = `https://saltwood.top:9393/93AtHome/super/cluster/ban`
try{
await axios.post(url, {
ban: true,
clusterId: value,
}, {
withCredentials: true,
});
ElMessage.success('节点封禁成功');
}catch(error){
ElMessage.error('节点封禁失败: ' + error);
console.log(error)
}
})
}
function unbanCluster(){
ElMessageBox.prompt('输入要解封的节点Id', '提示', {
confirmButtonText: '提交',
cancelButtonText: '取消',
placeholder: 'ClusterId'
})
.then(async ({ value }) => {
const url = `https://saltwood.top:9393/93AtHome/super/cluster/ban`
try{
await axios.post(url, {
ban: false,
clusterId: value,
}, {
withCredentials: true,
});
ElMessage.success('节点解封成功');
}catch(error){
ElMessage.error('节点封禁失败: ' + error);
console.log(error)
}
})
}
function showDialog() {
dialogVisible.value = true;
}
</script>
5 changes: 0 additions & 5 deletions src/pages/dashboard/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,4 @@ export default {
position: relative;
}
.btn-back {
position: absolute;
top: 0;
left: 0;
}
</style>
3 changes: 2 additions & 1 deletion src/pages/dashboard/myclusters/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Port: ${resp.port || 'null'}<br>
赞助商网址: ${resp.sponsorUrl || 'null'}<br>
创建日期: ${resp.createdAt || 'null'}<br>
状态: ${resp.isOnline ? '启用' : '离线'}<br>
封禁状态: ${resp.isBanned ? '已封禁' : '未封禁'}<br>
离线原因: ${resp.downreason}<br>
请求数: ${resp.hits}<br>
流量: ${resp.traffic}<br>
Expand Down Expand Up @@ -160,7 +161,7 @@ function unbindcluster(id){
try {
ElMessageBox.confirm(
'此操作不可逆,是否继续?',
'Warning',
'警告',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
Expand Down

0 comments on commit b09796e

Please sign in to comment.