Bladeren bron

代码提交

cxs 2 weken geleden
bovenliggende
commit
ad0bb5a3f6
3 gewijzigde bestanden met toevoegingen van 66 en 2 verwijderingen
  1. 61 2
      src/App.vue
  2. 2 0
      src/layouts/components/Header/components/Avatar.vue
  3. 3 0
      src/views/login/components/LoginForm.vue

+ 61 - 2
src/App.vue

@@ -5,15 +5,21 @@
 </template>
 
 <script setup lang="ts">
-import { onMounted, reactive, computed } from "vue";
+import {onMounted, reactive, computed, ref} from "vue";
 import { useI18n } from "vue-i18n";
 import { getBrowserLang } from "@/utils";
 import { useTheme } from "@/hooks/useTheme";
-import { ElConfigProvider } from "element-plus";
+import {ElConfigProvider, ElNotification} from "element-plus";
 import { LanguageType } from "./stores/interface";
 import { useGlobalStore } from "@/stores/modules/global";
 import en from "element-plus/es/locale/lang/en";
 import zhCn from "element-plus/es/locale/lang/zh-cn";
+import {Login, Platform} from "@/api/interface";
+import {loginApi} from "@/api/modules/login";
+import {initDynamicRouter} from "@/routers/modules/dynamicRouter";
+import {HOME_URL} from "@/config";
+import {useUserStore} from "@/stores/modules/user";
+import {getPlatformList} from "@/api/modules/allData";
 
 const globalStore = useGlobalStore();
 
@@ -41,6 +47,59 @@ const assemblySize = computed(() => globalStore.assemblySize);
 
 // element button config
 const buttonConfig = reactive({ autoInsertSpace: false });
+
+
+
+const loginForm = reactive<Login.ReqLoginForm>({
+  rememberMe: false,
+  username: "",
+  password: ""
+});
+
+const userStore = useUserStore();
+const loginStationsList = async () => {
+  loginForm.username = localStorage.getItem('username2')
+  loginForm.password = localStorage.getItem('password2')
+  if(!loginForm.username||!loginForm.password){
+    return
+  }
+  try {
+    const {data} = await loginApi({...loginForm, password: loginForm.password});
+    if (!data.user) {
+      return;
+    }
+
+    userStore.setToken(Date.now().toString());
+    userStore.setUserInfo(data.user)
+    userStore.setAsInfo(data.asInfo)
+    getStationsList();
+  } finally {
+  }
+};
+// 站号列表更新
+const getStationsList = async () => {
+  const userStore = useUserStore();
+  const user = computed(() => userStore.userInfo);
+  const Info = computed(() => userStore.asInfo);
+
+  // 查询自动站列表
+  const queryas = ref<Platform>({ pageSize: 20000, pageNum: 1 });
+  const { data } = await getPlatformList(queryas.value);
+  const array2 = data.list;
+
+  if (user.value.role_id === '管理员') {
+    userStore.setStations(array2);
+  } else {
+    const codesToMatch = Info.value.map(item => item.as_code);
+    const filteredArray = array2.filter(item => codesToMatch.includes(item.as_code));
+    userStore.setStations(filteredArray);
+  }
+};
+
+onMounted(() => {
+  loginStationsList()
+})
+
 </script>
 <style>
 body {

+ 2 - 0
src/layouts/components/Header/components/Avatar.vue

@@ -64,6 +64,8 @@ const logout = () => {
     userStore.setAsInfo([]);
     userStore.setUserInfo({})
     userStore.clearAllData()
+    localStorage.removeItem('username2');
+    localStorage.removeItem('password2');
 
     // 3.重定向到登陆页
     router.replace(LOGIN_URL);

+ 3 - 0
src/views/login/components/LoginForm.vue

@@ -69,6 +69,9 @@ const login = (formEl: FormInstance | undefined) => {
       localStorage.removeItem('rememberMe');
     }
 
+    localStorage.setItem('username2', String(loginForm.username));
+    localStorage.setItem('password2', String(loginForm.password));
+
     try {
       // 1.执行登录接口
       const { data } = await loginApi({ ...loginForm, password: loginForm.password });