Browse Source

fix: reset `getUser` retrieval timer upon user login

hechang27-sprt 6 months ago
parent
commit
80e2b78acf
  1. 4
      .claude/settings.local.json
  2. 12102
      package-lock.json
  3. 21
      packages/manage/router/index.vue
  4. 38
      plugs/store/index.ts

4
.claude/settings.local.json

@ -15,7 +15,9 @@ @@ -15,7 +15,9 @@
"Bash(find:*)",
"Bash(xargs -I {} sh -c 'echo \"\"\"\"=== {} ===\"\"\"\" && grep -E \"\"\"\"<module>|<artifactId>\"\"\"\" {} 2>/dev/null | head -20')",
"mcp__chrome-devtools__list_console_messages",
"Bash(dir:*)"
"Bash(dir:*)",
"Bash(curl:*)",
"Bash(xargs cat:*)"
],
"deny": [],
"ask": []

12102
package-lock.json generated

File diff suppressed because it is too large Load Diff

21
packages/manage/router/index.vue

@ -24,9 +24,9 @@ @@ -24,9 +24,9 @@
</template>
<script lang="ts" setup>
import { onBeforeUnmount, onMounted, reactive, ref } from "vue";
import { onBeforeUnmount, onMounted, reactive, ref, watch } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { useRouter, useRoute } from "vue-router";
import { Api, NoobHead } from "noob-mengyxu";
import md5 from "js-md5";
@ -35,6 +35,7 @@ const { Head, MenuTree, HeadPersonal, Fullscreen, StyleChange, LangChange, SizeC @@ -35,6 +35,7 @@ const { Head, MenuTree, HeadPersonal, Fullscreen, StyleChange, LangChange, SizeC
const { state, commit, dispatch } = useStore();
const emit = defineEmits(["updatePwd", "logout"]);
const router = useRouter();
const route = useRoute();
const appMain = reactive({
height: window.innerHeight + "px",
backgroundColor: state.style.bodyBg,
@ -120,6 +121,7 @@ const getUser = (first?) => { @@ -120,6 +121,7 @@ const getUser = (first?) => {
const onLogout = () => {
Api.pub.logout().then((rsp) => {
getUser();
emit("logout");
});
};
@ -132,14 +134,25 @@ const updatePwd = (pwd) => { @@ -132,14 +134,25 @@ const updatePwd = (pwd) => {
};
onMounted(() => {
router.push("/");
// router.push("/"); // redundant - already navigated from login
dispatch("getMenus");
getUser(true);
getUser(); // Don't show loading screen after successful login
interval = setInterval(getUser, 5000);
window.onresize = onResize;
onResize();
});
// Watch for navigation from login page
watch(
() => route.path,
(newPath, oldPath) => {
if (oldPath === "/login" && newPath !== "/login" && !state.user?.userId) {
getUser();
interval = setInterval(getUser, 5000);
}
}
);
onBeforeUnmount(() => {
clearInterval(interval);
});

38
plugs/store/index.ts

@ -1,13 +1,14 @@ @@ -1,13 +1,14 @@
import { createStore as create } from 'vuex';
import { Styles, Size } from '../config';
import { getByCodes, getMenus, logout, getActions } from '../api/public';
import { mapping } from '../api/role';
import { createStore as create } from "vuex";
import { Styles, Size } from "../config";
import { getByCodes, getMenus, logout, getActions } from "../api/public";
import { mapping } from "../api/role";
import { clearAndAssign } from "noob-mengyxu/utils";
export class State {
dict = {
active_status: {
A: '启用',
B: '禁用',
A: "启用",
B: "禁用",
},
};
roles = {};
@ -43,7 +44,7 @@ export class Actions { @@ -43,7 +44,7 @@ export class Actions {
dict[item.code] = item.name;
});
}
commit('updateDict', [key, dict]);
commit("updateDict", [key, dict]);
}
}
});
@ -51,29 +52,30 @@ export class Actions { @@ -51,29 +52,30 @@ export class Actions {
getRoleMap = ({ state, commit }) => {
state.roleRefresh &&
mapping().then((rsp) => {
commit('updateState', ['roles', rsp]);
commit('updateState', ['roleRefresh', false]);
commit("updateState", ["roles", rsp]);
commit("updateState", ["roleRefresh", false]);
});
};
getMenus = ({ state, commit }) => {
getMenus().then((rsp) => commit('updateState', ['menus', rsp]));
getMenus().then((rsp) => commit("updateState", ["menus", rsp]));
};
getMyActions = ({ state, commit }, content) => {
getActions(content).then((rsp) => commit('updateState', ['actions', rsp]));
getActions(content).then((rsp) => commit("updateState", ["actions", rsp]));
};
login = (store) => {
const { state, commit } = store;
state.size.headHeight = state.size.head + 'px';
state.size.asideWidth = state.size.aside + 'px';
commit('initSize');
state.size.headHeight = state.size.head + "px";
state.size.asideWidth = state.size.aside + "px";
commit("initSize");
this.getMenus(store);
};
}
export class Mutations {
updateState = (state, param) => {
state[param[0]] = param[1];
updateState = (state, [k, v]) => {
state[k] = v;
};
initSize = (state, param) => {
const size = state.size;
const aside = parseInt(size.asideWidth);
@ -86,11 +88,11 @@ export class Mutations { @@ -86,11 +88,11 @@ export class Mutations {
size.height = param[0];
size.width = param[1];
}
size.mainHeight = Math.floor(size.height - head) + 'px';
size.mainHeight = Math.floor(size.height - head) + "px";
size.tableHeight = size.height - 2 * (mainPad + searchRowPad) - 3 - searchRow - head;
size.pTableHeight = size.tableHeight - size.pageHeight;
size.headLeftWidth = size.width - aside - headRightWidth - 20 + 'px';
size.headLeftWidth = size.width - aside - headRightWidth - 20 + "px";
};
updateDict = (state, param) => {
state.dict[param[0]] = param[1];

Loading…
Cancel
Save