| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <template>
- <el-container class="app-wrapper">
- <el-aside :width="sidebarOpened ? '210px' : '64px'" class="sidebar-container">
- <div class="logo">
- <img src="@/assets/logo.svg" alt="logo" />
- <h1 v-show="sidebarOpened">摄像头管理</h1>
- </div>
- <el-menu
- :default-active="activeMenu"
- :collapse="!sidebarOpened"
- :collapse-transition="false"
- background-color="#304156"
- text-color="#bfcbd9"
- active-text-color="#409eff"
- router
- >
- <el-menu-item index="/machine">
- <el-icon><Monitor /></el-icon>
- <template #title>机器管理</template>
- </el-menu-item>
- <el-menu-item index="/camera">
- <el-icon><VideoCamera /></el-icon>
- <template #title>摄像头管理</template>
- </el-menu-item>
- <el-menu-item index="/user">
- <el-icon><UserFilled /></el-icon>
- <template #title>用户管理</template>
- </el-menu-item>
- <el-sub-menu index="/stream">
- <template #title>
- <el-icon><Film /></el-icon>
- <span>Cloudflare Stream</span>
- </template>
- <el-menu-item index="/stream/videos">
- <el-icon><Film /></el-icon>
- <template #title>视频管理</template>
- </el-menu-item>
- <el-menu-item index="/stream/live">
- <el-icon><VideoCameraFilled /></el-icon>
- <template #title>直播管理</template>
- </el-menu-item>
- <el-menu-item index="/stream/config">
- <el-icon><Setting /></el-icon>
- <template #title>Stream 配置</template>
- </el-menu-item>
- <el-menu-item index="/stream-test">
- <el-icon><Monitor /></el-icon>
- <template #title>快速测试</template>
- </el-menu-item>
- </el-sub-menu>
- </el-menu>
- </el-aside>
- <el-container class="main-container">
- <el-header class="app-header">
- <div class="header-left">
- <el-icon class="collapse-btn" @click="toggleSidebar">
- <Fold v-if="sidebarOpened" />
- <Expand v-else />
- </el-icon>
- <el-breadcrumb separator="/">
- <el-breadcrumb-item v-for="item in breadcrumbs" :key="item.path">
- {{ item.meta?.title }}
- </el-breadcrumb-item>
- </el-breadcrumb>
- </div>
- <div class="header-right">
- <el-dropdown @command="handleCommand">
- <span class="user-info">
- <el-avatar :size="32" :src="'https://cube.elemecdn.com/0/88/03b0d39583f4b3a790e9d12d41f23e23jps.jpg'" />
- <span class="username">{{ userInfo?.username }}</span>
- <el-icon><ArrowDown /></el-icon>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item command="changePassword">修改密码</el-dropdown-item>
- <el-dropdown-item command="logout">退出登录</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- </div>
- </el-header>
- <el-main class="app-main">
- <router-view v-slot="{ Component }">
- <transition name="fade" mode="out-in">
- <component :is="Component" />
- </transition>
- </router-view>
- </el-main>
- </el-container>
- <!-- 修改密码弹窗 -->
- <el-dialog v-model="passwordDialogVisible" title="修改密码" width="400px" :close-on-click-modal="false">
- <el-form ref="passwordFormRef" :model="passwordForm" :rules="passwordRules" label-width="80px">
- <el-form-item label="原密码" prop="oldPassword">
- <el-input v-model="passwordForm.oldPassword" type="password" show-password placeholder="请输入原密码" />
- </el-form-item>
- <el-form-item label="新密码" prop="newPassword">
- <el-input v-model="passwordForm.newPassword" type="password" show-password placeholder="请输入新密码" />
- </el-form-item>
- <el-form-item label="确认密码" prop="confirmPassword">
- <el-input v-model="passwordForm.confirmPassword" type="password" show-password placeholder="请再次输入新密码" />
- </el-form-item>
- </el-form>
- <template #footer>
- <el-button @click="passwordDialogVisible = false">取消</el-button>
- <el-button type="primary" :loading="passwordLoading" @click="handleChangePassword">确定</el-button>
- </template>
- </el-dialog>
- </el-container>
- </template>
- <script setup lang="ts">
- import { computed, onMounted, ref, reactive } from 'vue'
- import { useRoute, useRouter } from 'vue-router'
- import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
- import {
- VideoCamera,
- Fold,
- Expand,
- ArrowDown,
- Monitor,
- Film,
- VideoCameraFilled,
- Setting,
- UserFilled
- } from '@element-plus/icons-vue'
- import { useAppStore } from '@/store/app'
- import { useUserStore } from '@/store/user'
- import { changePassword } from '@/api/login'
- const route = useRoute()
- const router = useRouter()
- const appStore = useAppStore()
- const userStore = useUserStore()
- const sidebarOpened = computed(() => appStore.sidebarOpened)
- const userInfo = computed(() => userStore.userInfo)
- const activeMenu = computed(() => {
- const { path } = route
- return path
- })
- const breadcrumbs = computed(() => {
- return route.matched.filter((item) => item.meta && item.meta.title && !item.meta.hidden)
- })
- function toggleSidebar() {
- appStore.toggleSidebar()
- }
- // 修改密码相关
- const passwordDialogVisible = ref(false)
- const passwordLoading = ref(false)
- const passwordFormRef = ref<FormInstance>()
- const passwordForm = reactive({
- oldPassword: '',
- newPassword: '',
- confirmPassword: ''
- })
- const validateConfirmPassword = (_rule: any, value: string, callback: any) => {
- if (value !== passwordForm.newPassword) {
- callback(new Error('两次输入的密码不一致'))
- } else {
- callback()
- }
- }
- const passwordRules: FormRules = {
- oldPassword: [{ required: true, message: '请输入原密码', trigger: 'blur' }],
- newPassword: [
- { required: true, message: '请输入新密码', trigger: 'blur' },
- { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
- ],
- confirmPassword: [
- { required: true, message: '请再次输入新密码', trigger: 'blur' },
- { validator: validateConfirmPassword, trigger: 'blur' }
- ]
- }
- function resetPasswordForm() {
- passwordForm.oldPassword = ''
- passwordForm.newPassword = ''
- passwordForm.confirmPassword = ''
- passwordFormRef.value?.clearValidate()
- }
- async function handleChangePassword() {
- if (!passwordFormRef.value) return
- await passwordFormRef.value.validate(async (valid) => {
- if (valid) {
- passwordLoading.value = true
- try {
- const res = await changePassword({
- oldPassword: passwordForm.oldPassword,
- newPassword: passwordForm.newPassword
- })
- if (res.code === 200) {
- ElMessage.success('密码修改成功,请重新登录')
- passwordDialogVisible.value = false
- resetPasswordForm()
- await userStore.logoutAction()
- router.push('/login')
- } else {
- ElMessage.error(res.message || '密码修改失败')
- }
- } catch (error: any) {
- ElMessage.error(error.message || '密码修改失败')
- } finally {
- passwordLoading.value = false
- }
- }
- })
- }
- async function handleCommand(command: string) {
- if (command === 'changePassword') {
- resetPasswordForm()
- passwordDialogVisible.value = true
- } else if (command === 'logout') {
- await userStore.logoutAction()
- router.push('/login')
- }
- }
- onMounted(() => {
- userStore.getUserInfo()
- })
- </script>
- <style lang="scss" scoped>
- .app-wrapper {
- height: 100%;
- }
- .sidebar-container {
- background-color: #304156;
- transition: width 0.3s;
- overflow: hidden;
- .logo {
- height: 60px;
- display: flex;
- align-items: center;
- padding: 0 15px;
- background-color: #2b3a4a;
- img {
- width: 32px;
- height: 32px;
- }
- h1 {
- margin-left: 12px;
- font-size: 16px;
- font-weight: 600;
- color: #fff;
- white-space: nowrap;
- }
- }
- .el-menu {
- border-right: none;
- }
- }
- .main-container {
- flex-direction: column;
- min-height: 100%;
- overflow: hidden;
- }
- .app-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- height: 60px;
- background-color: #fff;
- box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
- .header-left {
- display: flex;
- align-items: center;
- .collapse-btn {
- font-size: 20px;
- cursor: pointer;
- margin-right: 15px;
- color: #5a5e66;
- &:hover {
- color: #409eff;
- }
- }
- }
- .header-right {
- .user-info {
- display: flex;
- align-items: center;
- cursor: pointer;
- .username {
- margin: 0 8px;
- color: #5a5e66;
- }
- }
- }
- }
- .app-main {
- background-color: #f5f7fa;
- overflow: auto;
- }
- .fade-enter-active,
- .fade-leave-active {
- transition: opacity 0.2s ease;
- }
- .fade-enter-from,
- .fade-leave-to {
- opacity: 0;
- }
- </style>
|