获取用户id调整
This commit is contained in:
parent
b429bf5ce3
commit
3c41293f0b
20
src/App.vue
20
src/App.vue
@ -3,28 +3,20 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { watch, onMounted } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { onMounted } from 'vue';
|
||||
import { useAuthStore } from 'src/stores/auth-store';
|
||||
import { getLoginUserInfo } from 'src/api/UserApi';
|
||||
import { getJwtToken } from './configs/TokenManage';
|
||||
defineOptions({
|
||||
name: 'App',
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const authStore = useAuthStore();
|
||||
watch(
|
||||
() => route.params.token,
|
||||
async () => {
|
||||
if (route.params.token) {
|
||||
const res = await getLoginUserInfo();
|
||||
authStore.setUserId(res.loginUserInfo.id);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
const res = await getLoginUserInfo();
|
||||
authStore.setUserId(res.loginUserInfo.id);
|
||||
if (getJwtToken()) {
|
||||
const res = await getLoginUserInfo();
|
||||
authStore.setUserId(res.loginUserInfo.id);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -181,20 +181,20 @@ export async function getLoginUserInfo() {
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jwt令牌(mqtt验证)
|
||||
*/
|
||||
export async function getJwt() {
|
||||
const query = `
|
||||
query getJwt {
|
||||
getJwt
|
||||
}
|
||||
`;
|
||||
const response = await api.post('', {
|
||||
query: query,
|
||||
});
|
||||
return response.data.data;
|
||||
}
|
||||
// /**
|
||||
// * 获取jwt令牌(mqtt验证)
|
||||
// */
|
||||
// export async function getJwt() {
|
||||
// const query = `
|
||||
// query getJwt {
|
||||
// getJwt
|
||||
// }
|
||||
// `;
|
||||
// const response = await api.post('', {
|
||||
// query: query,
|
||||
// });
|
||||
// return response.data.data;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取默认组织信息
|
||||
|
@ -20,7 +20,6 @@ import {
|
||||
import { useDrawStore } from 'src/stores/draw-store';
|
||||
import { iscsGraphicData } from 'src/protos/iscs_graphic_data';
|
||||
import { getDraft } from 'src/api/DraftApi';
|
||||
import { getJwt } from 'src/api/UserApi';
|
||||
import { fromUint8Array, toUint8Array } from 'js-base64';
|
||||
import { getWebsocketUrl } from 'src/configs/UrlManage';
|
||||
import { sync_data_message } from 'src/protos/sync_data_message';
|
||||
@ -171,6 +170,7 @@ import {
|
||||
FireIntercommunicationSignalTemplate,
|
||||
} from 'src/graphics/FAS/fireIntercommunicationSignal/FireIntercommunicationSignal';
|
||||
// import { getOnlyToken } from 'src/configs/TokenManage';
|
||||
import { getJwtToken } from 'src/configs/TokenManage';
|
||||
|
||||
let drawApp: IDrawApp | null = null;
|
||||
|
||||
@ -194,12 +194,10 @@ export function initIscsDrawApp(): IDrawApp {
|
||||
dataLoader: loadDrawDatas,
|
||||
isSupportDeletion: isSupportDeletion,
|
||||
});
|
||||
getJwt().then((res) => {
|
||||
drawApp.enableWsMassaging({
|
||||
engine: ClientEngine.MQTT,
|
||||
wsUrl: `${getWebsocketUrl()}`,
|
||||
token: res.getJwt as string,
|
||||
});
|
||||
drawApp.enableWsMassaging({
|
||||
engine: ClientEngine.MQTT,
|
||||
wsUrl: `${getWebsocketUrl()}`,
|
||||
token: getJwtToken() as string,
|
||||
});
|
||||
|
||||
const app = drawApp;
|
||||
|
@ -54,8 +54,14 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
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 { useAuthStore } from 'src/stores/auth-store';
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
@ -78,6 +84,7 @@ onMounted(async () => {
|
||||
console.log(orgInfo, 6666);
|
||||
});
|
||||
|
||||
const authStore = useAuthStore();
|
||||
async function doLogin() {
|
||||
clearJwtToken();
|
||||
const res = await login(loginInfo);
|
||||
@ -91,6 +98,8 @@ async function doLogin() {
|
||||
visible.value = true;
|
||||
const token = res.data.data.userLogin;
|
||||
saveJwtToken(token);
|
||||
const userRes = await getLoginUserInfo();
|
||||
authStore.setUserId(userRes.loginUserInfo.id);
|
||||
router.push({ name: 'iscsDraft' });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user