gaoluyang
5 天以前 bc07cf1a936795d229a0f51d24cd2032580db542
湟水峡
1.头部修改
已修改2个文件
106 ■■■■■ 文件已修改
src/layout/components/Navbar.vue 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/login.vue 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/layout/components/Navbar.vue
@@ -6,6 +6,30 @@
      <breadcrumb v-if="!settingsStore.topNav" id="breadcrumb-container" class="breadcrumb-container" />
    </div>
    <!--    <top-nav v-if="settingsStore.topNav" id="topmenu-container" class="topmenu-container" />-->
    <div class="right-menu">
      <!-- 消息通知 -->
<!--      <el-popover-->
<!--        v-model:visible="notificationVisible"-->
<!--        :width="500"-->
<!--        placement="bottom-end"-->
<!--        trigger="click"-->
<!--        :popper-options="{ modifiers: [{ name: 'offset', options: { offset: [0, 10] } }] }"-->
<!--        popper-class="notification-popover"-->
<!--      >-->
<!--        <template #reference>-->
<!--          <div class="notification-container right-menu-item hover-effect">-->
<!--            <el-badge :value="unreadCount" :hidden="unreadCount === 0" class="notification-badge">-->
<!--              <el-icon :size="20" style="cursor: pointer;">-->
<!--                <Bell />-->
<!--              </el-icon>-->
<!--            </el-badge>-->
<!--          </div>-->
<!--        </template>-->
<!--        <NotificationCenter-->
<!--          @unreadCountChange="handleUnreadCountChange"-->
<!--          ref="notificationCenterRef"-->
<!--        />-->
<!--      </el-popover>-->
      <div class="avatar-container">
        <el-dropdown @command="handleCommand" class="right-menu-item hover-effect" trigger="click">
          <div class="avatar-wrapper">
@@ -28,10 +52,12 @@
        </el-dropdown>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ElMessageBox } from 'element-plus'
import { Bell } from '@element-plus/icons-vue'
import Breadcrumb from '@/components/Breadcrumb'
import TopNav from '@/components/TopNav'
import Hamburger from '@/components/Hamburger'
@@ -40,6 +66,7 @@
import HeaderSearch from '@/components/HeaderSearch'
import RuoYiGit from '@/components/RuoYi/Git'
import RuoYiDoc from '@/components/RuoYi/Doc'
// import NotificationCenter from './NotificationCenter/index.vue'
import useAppStore from '@/store/modules/app'
import useUserStore from '@/store/modules/user'
import useSettingsStore from '@/store/modules/settings'
@@ -47,7 +74,9 @@
const appStore = useAppStore()
const userStore = useUserStore()
const settingsStore = useSettingsStore()
const factoryList = ref([])
const notificationVisible = ref(false)
const notificationCenterRef = ref(null)
const unreadCount = ref(0)
function toggleSideBar() {
  appStore.toggleSideBar()
}
@@ -90,39 +119,42 @@
  settingsStore.toggleTheme()
}
// function getUserLoginFacotryList() {
//   if (userStore.id) {
//     userLoginFacotryList({ userId: userStore.id }).then(res => {
//       console.log('res', res)
//       factoryList.value = res.data
//     })
//   } else {
//     factoryList.value = []
//   }
// }
function handleFactoryChange(command) {
  console.log('command', command)
  handleLogin(command.deptId);
// 消息通知相关
function handleUnreadCountChange(count) {
  unreadCount.value = count
}
function handleLogin(currentFatoryId) {
  const loginForm = {
    username: Cookies.get("username"),
    password: Cookies.get("password") === undefined ? null : decrypt(Cookies.get("password")),
    currentFatoryId: currentFatoryId
  }
  userStore.loginCheckFactory(loginForm).then(res => {
    forceReload();
  }).catch((err) => {
    console.log(err)
// 组件挂载时加载未读数量和定时刷新
let unreadCountTimer = null
onMounted(() => {
  // 延迟加载,确保组件已渲染
  nextTick(() => {
    if (notificationCenterRef.value) {
      notificationCenterRef.value.loadUnreadCount()
    }
  })
}
function forceReload() {
  const currentUrl = window.location.origin + window.location.pathname;
  const timestamp = new Date().getTime();
  window.location.href = `${currentUrl}?reload=${timestamp}`;
}
  // 定时刷新未读数量(每30秒)
  unreadCountTimer = setInterval(() => {
    if (notificationCenterRef.value) {
      notificationCenterRef.value.loadUnreadCount()
    }
  }, 30000)
})
// 监听 popover 显示状态,打开时加载消息列表
watch(notificationVisible, (val) => {
  if (val && notificationCenterRef.value) {
    nextTick(() => {
      notificationCenterRef.value.loadMessages()
    })
  }
})
onUnmounted(() => {
  if (unreadCountTimer) {
    clearInterval(unreadCountTimer)
  }
})
</script>
<style lang='scss' scoped>
src/views/login.vue
@@ -28,11 +28,11 @@
          <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
        </el-input>
      </el-form-item>
      <el-form-item prop="currentFatoryId">
        <el-select v-model="loginForm.currentFatoryId" placeholder="请选择公司" filterable>
          <el-option  v-for="item in factoryList" :key="item.deptId" :label="item.deptName" :value="item.deptId" />
        </el-select>
      </el-form-item>
<!--      <el-form-item prop="currentFatoryId">-->
<!--        <el-select v-model="loginForm.currentFatoryId" placeholder="请选择公司" filterable>-->
<!--          <el-option  v-for="item in factoryList" :key="item.deptId" :label="item.deptName" :value="item.deptId" />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item prop="code" v-if="captchaEnabled">-->
<!--        <el-input-->
<!--          v-model="loginForm.code"-->
@@ -89,7 +89,6 @@
  username: "",
  password: "",
  rememberMe: false,
  currentFatoryId:'',
})
const loginRules = {
@@ -107,7 +106,6 @@
const redirect = ref(undefined)
const factoryList = ref([])
const currentFatoryId = ref('')
watch(route, (newRoute) => {
    redirect.value = newRoute.query && newRoute.query.redirect