Browse Source

login

master
maochaoying 2 years ago
parent
commit
48824670e0
  1. 15
      src/components/LoginForm.vue
  2. 12
      src/pages/Home.vue
  3. 11
      src/pages/Login.vue
  4. 8
      src/store/modules/user.js
  5. 2
      src/store/modules/websocket.js

15
src/components/LoginForm.vue

@ -21,12 +21,13 @@
<script setup> <script setup>
import Eye from '@/assets/img/login/eye.png' import Eye from '@/assets/img/login/eye.png'
import Open from '@/assets/img/login/open.png' import Open from '@/assets/img/login/open.png'
import { useWebSocketStore } from '@/store'
import { useWebSocketStore, useUserStore } from '@/store'
import { ref } from 'vue' import { ref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { loginJSON } from '@/mock/command' import { loginJSON } from '@/mock/command'
const router = useRouter() const router = useRouter()
const userStore = useUserStore()
const webSocketStore = useWebSocketStore() const webSocketStore = useWebSocketStore()
const showPassword = ref(false) const showPassword = ref(false)
const username = ref('') const username = ref('')
@ -48,7 +49,17 @@ const handleLogin = () => {
} }
tip.value = '' tip.value = ''
webSocketStore?.sendCommandMsg(loginJSON(username.value, password.value)) webSocketStore?.sendCommandMsg(loginJSON(username.value, password.value))
if (username.value == 'admin' && password.value == '123') {
//
let flag = false
userStore.allUserList?.map(item => {
if (item.uid == username.value && password.value == item.passwd) {
//
flag = true
userStore.updatePermission(item.permission_level)
userStore.updateLoginUser(item.uid)
}
})
if (flag) {
router.push('/') router.push('/')
} }
} }

12
src/pages/Home.vue

@ -73,6 +73,7 @@
<div <div
:class="activeTab == 4 ? 'tab_btn active_btn' : 'tab_btn'" :class="activeTab == 4 ? 'tab_btn active_btn' : 'tab_btn'"
@click="changeTab(4)" @click="changeTab(4)"
v-if="userStore.loginUserPermission != 3"
> >
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -96,6 +97,7 @@
<div <div
:class="activeTab == 5 ? 'tab_btn active_btn' : 'tab_btn'" :class="activeTab == 5 ? 'tab_btn active_btn' : 'tab_btn'"
@click="changeTab(5)" @click="changeTab(5)"
v-if="userStore.loginUserPermission != 3"
> >
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -183,13 +185,19 @@ import LiquidHandle from 'cpns/LiquidHandle'
import Setting from 'cpns/Setting' import Setting from 'cpns/Setting'
import Test from 'cpns/Test' import Test from 'cpns/Test'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { useOperatorStore, useWebSocketStore, useSettingStore } from '@/store'
import {
useOperatorStore,
useWebSocketStore,
useSettingStore,
useUserStore,
} from '@/store'
import { logoutJSON, getStateJSON } from '@/mock/command' import { logoutJSON, getStateJSON } from '@/mock/command'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
const router = useRouter() const router = useRouter()
const webSocketStore = useWebSocketStore() const webSocketStore = useWebSocketStore()
const settingStore = useSettingStore() const settingStore = useSettingStore()
const userStore = useUserStore()
const { socketCommandInstance } = storeToRefs(webSocketStore) const { socketCommandInstance } = storeToRefs(webSocketStore)
webSocketStore.initCommandSocket() webSocketStore.initCommandSocket()
webSocketStore.initEventSocket() webSocketStore.initEventSocket()
@ -220,7 +228,7 @@ onMounted(() => {
}, 1000) }, 1000)
setTimeout(() => { setTimeout(() => {
webSocketStore.sendCommandMsg(getStateJSON) webSocketStore.sendCommandMsg(getStateJSON)
}, 2000)
}, 1000)
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {

11
src/pages/Login.vue

@ -27,12 +27,13 @@
import Restart from '@/assets/img/login/restart.png' import Restart from '@/assets/img/login/restart.png'
import Shutdown from '@/assets/img/login/shutdown.png' import Shutdown from '@/assets/img/login/shutdown.png'
import LoginForm from 'cpns/LoginForm.vue' import LoginForm from 'cpns/LoginForm.vue'
import { shutdownJSON } from '@/mock/command'
import { shutdownJSON, getAllUserJSON } from '@/mock/command'
import { useWebSocketStore } from '@/store' import { useWebSocketStore } from '@/store'
import { ref, onUnmounted } from 'vue'
import { ref, onUnmounted, onMounted } from 'vue'
const webSocketStore = useWebSocketStore() const webSocketStore = useWebSocketStore()
webSocketStore.initCommandSocket() webSocketStore.initCommandSocket()
webSocketStore.initEventSocket() webSocketStore.initEventSocket()
const showShutdown = ref(false) const showShutdown = ref(false)
const shutSecond = ref(5) const shutSecond = ref(5)
const timer = ref(null) const timer = ref(null)
@ -53,6 +54,12 @@ onUnmounted(() => {
timer.value = null timer.value = null
}) })
onMounted(() => {
setTimeout(() => {
webSocketStore?.sendCommandMsg(getAllUserJSON)
}, 1000)
})
const reboot = () => {} const reboot = () => {}
</script> </script>

8
src/store/modules/user.js

@ -6,10 +6,18 @@ export const useUserStore = defineStore({
return { return {
allUserList: [], allUserList: [],
operUser: '', operUser: '',
loginUser: '',
loginUserPermission: 3,
} }
}, },
// actions // actions
actions: { actions: {
updatePermission(loginUserPermission) {
this.loginUserPermission = loginUserPermission
},
updateLoginUser(loginUser) {
this.loginUser = loginUser
},
updateOperUser(operUser) { updateOperUser(operUser) {
this.operUser = operUser this.operUser = operUser
}, },

2
src/store/modules/websocket.js

@ -45,6 +45,8 @@ export const useWebSocketStore = defineStore({
break break
case 'stopDisinfection': case 'stopDisinfection':
break break
case 'login':
break
default: default:
break break
} }

Loading…
Cancel
Save