获取用户id调整

This commit is contained in:
joylink_fanyuhong 2024-11-12 13:41:17 +08:00
parent b429bf5ce3
commit 3c41293f0b
4 changed files with 35 additions and 36 deletions

View File

@ -3,28 +3,20 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { watch, onMounted } from 'vue'; import { onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { useAuthStore } from 'src/stores/auth-store'; import { useAuthStore } from 'src/stores/auth-store';
import { getLoginUserInfo } from 'src/api/UserApi'; import { getLoginUserInfo } from 'src/api/UserApi';
import { getJwtToken } from './configs/TokenManage';
defineOptions({ defineOptions({
name: 'App', name: 'App',
}); });
const route = useRoute();
const authStore = useAuthStore(); const authStore = useAuthStore();
watch(
() => route.params.token,
async () => {
if (route.params.token) {
const res = await getLoginUserInfo();
authStore.setUserId(res.loginUserInfo.id);
}
}
);
onMounted(async () => { onMounted(async () => {
if (getJwtToken()) {
const res = await getLoginUserInfo(); const res = await getLoginUserInfo();
authStore.setUserId(res.loginUserInfo.id); authStore.setUserId(res.loginUserInfo.id);
}
}); });
</script> </script>

View File

@ -181,20 +181,20 @@ export async function getLoginUserInfo() {
return response.data.data; return response.data.data;
} }
/** // /**
* jwt令牌(mqtt验证) // * 获取jwt令牌(mqtt验证)
*/ // */
export async function getJwt() { // export async function getJwt() {
const query = ` // const query = `
query getJwt { // query getJwt {
getJwt // getJwt
} // }
`; // `;
const response = await api.post('', { // const response = await api.post('', {
query: query, // query: query,
}); // });
return response.data.data; // return response.data.data;
} // }
/** /**
* *

View File

@ -20,7 +20,6 @@ import {
import { useDrawStore } from 'src/stores/draw-store'; import { useDrawStore } from 'src/stores/draw-store';
import { iscsGraphicData } from 'src/protos/iscs_graphic_data'; import { iscsGraphicData } from 'src/protos/iscs_graphic_data';
import { getDraft } from 'src/api/DraftApi'; import { getDraft } from 'src/api/DraftApi';
import { getJwt } from 'src/api/UserApi';
import { fromUint8Array, toUint8Array } from 'js-base64'; import { fromUint8Array, toUint8Array } from 'js-base64';
import { getWebsocketUrl } from 'src/configs/UrlManage'; import { getWebsocketUrl } from 'src/configs/UrlManage';
import { sync_data_message } from 'src/protos/sync_data_message'; import { sync_data_message } from 'src/protos/sync_data_message';
@ -171,6 +170,7 @@ import {
FireIntercommunicationSignalTemplate, FireIntercommunicationSignalTemplate,
} from 'src/graphics/FAS/fireIntercommunicationSignal/FireIntercommunicationSignal'; } from 'src/graphics/FAS/fireIntercommunicationSignal/FireIntercommunicationSignal';
// import { getOnlyToken } from 'src/configs/TokenManage'; // import { getOnlyToken } from 'src/configs/TokenManage';
import { getJwtToken } from 'src/configs/TokenManage';
let drawApp: IDrawApp | null = null; let drawApp: IDrawApp | null = null;
@ -194,12 +194,10 @@ export function initIscsDrawApp(): IDrawApp {
dataLoader: loadDrawDatas, dataLoader: loadDrawDatas,
isSupportDeletion: isSupportDeletion, isSupportDeletion: isSupportDeletion,
}); });
getJwt().then((res) => {
drawApp.enableWsMassaging({ drawApp.enableWsMassaging({
engine: ClientEngine.MQTT, engine: ClientEngine.MQTT,
wsUrl: `${getWebsocketUrl()}`, wsUrl: `${getWebsocketUrl()}`,
token: res.getJwt as string, token: getJwtToken() as string,
});
}); });
const app = drawApp; const app = drawApp;

View File

@ -54,8 +54,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { getDefaultOrg, getOrgByCode, login } from 'src/api/UserApi'; import {
getDefaultOrg,
getLoginUserInfo,
getOrgByCode,
login,
} from 'src/api/UserApi';
import { clearJwtToken, saveJwtToken } from 'src/configs/TokenManage'; import { clearJwtToken, saveJwtToken } from 'src/configs/TokenManage';
import { useAuthStore } from 'src/stores/auth-store';
import { onMounted, reactive, ref } from 'vue'; import { onMounted, reactive, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
@ -78,6 +84,7 @@ onMounted(async () => {
console.log(orgInfo, 6666); console.log(orgInfo, 6666);
}); });
const authStore = useAuthStore();
async function doLogin() { async function doLogin() {
clearJwtToken(); clearJwtToken();
const res = await login(loginInfo); const res = await login(loginInfo);
@ -91,6 +98,8 @@ async function doLogin() {
visible.value = true; visible.value = true;
const token = res.data.data.userLogin; const token = res.data.data.userLogin;
saveJwtToken(token); saveJwtToken(token);
const userRes = await getLoginUserInfo();
authStore.setUserId(userRes.loginUserInfo.id);
router.push({ name: 'iscsDraft' }); router.push({ name: 'iscsDraft' });
} }
} }