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 @@
"Bash(find:*)", "Bash(find:*)",
"Bash(xargs -I {} sh -c 'echo \"\"\"\"=== {} ===\"\"\"\" && grep -E \"\"\"\"<module>|<artifactId>\"\"\"\" {} 2>/dev/null | head -20')", "Bash(xargs -I {} sh -c 'echo \"\"\"\"=== {} ===\"\"\"\" && grep -E \"\"\"\"<module>|<artifactId>\"\"\"\" {} 2>/dev/null | head -20')",
"mcp__chrome-devtools__list_console_messages", "mcp__chrome-devtools__list_console_messages",
"Bash(dir:*)" "Bash(dir:*)",
"Bash(curl:*)",
"Bash(xargs cat:*)"
], ],
"deny": [], "deny": [],
"ask": [] "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 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onBeforeUnmount, onMounted, reactive, ref } from "vue"; import { onBeforeUnmount, onMounted, reactive, ref, watch } from "vue";
import { useStore } from "vuex"; import { useStore } from "vuex";
import { useRouter } from "vue-router"; import { useRouter, useRoute } from "vue-router";
import { Api, NoobHead } from "noob-mengyxu"; import { Api, NoobHead } from "noob-mengyxu";
import md5 from "js-md5"; import md5 from "js-md5";
@ -35,6 +35,7 @@ const { Head, MenuTree, HeadPersonal, Fullscreen, StyleChange, LangChange, SizeC
const { state, commit, dispatch } = useStore(); const { state, commit, dispatch } = useStore();
const emit = defineEmits(["updatePwd", "logout"]); const emit = defineEmits(["updatePwd", "logout"]);
const router = useRouter(); const router = useRouter();
const route = useRoute();
const appMain = reactive({ const appMain = reactive({
height: window.innerHeight + "px", height: window.innerHeight + "px",
backgroundColor: state.style.bodyBg, backgroundColor: state.style.bodyBg,
@ -120,6 +121,7 @@ const getUser = (first?) => {
const onLogout = () => { const onLogout = () => {
Api.pub.logout().then((rsp) => { Api.pub.logout().then((rsp) => {
getUser(); getUser();
emit("logout");
}); });
}; };
@ -132,14 +134,25 @@ const updatePwd = (pwd) => {
}; };
onMounted(() => { onMounted(() => {
router.push("/"); // router.push("/"); // redundant - already navigated from login
dispatch("getMenus"); dispatch("getMenus");
getUser(true); getUser(); // Don't show loading screen after successful login
interval = setInterval(getUser, 5000); interval = setInterval(getUser, 5000);
window.onresize = onResize; window.onresize = 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(() => { onBeforeUnmount(() => {
clearInterval(interval); clearInterval(interval);
}); });

38
plugs/store/index.ts

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

Loading…
Cancel
Save