zhangjie 6 months ago
parent
commit
86ac11f015
5 changed files with 21 additions and 11 deletions
  1. 13 6
      electron/main/index.ts
  2. 2 2
      src/App.vue
  3. 2 3
      src/api/interceptor.ts
  4. 2 0
      src/store/modules/user/index.ts
  5. 2 0
      src/store/modules/user/types.ts

+ 13 - 6
electron/main/index.ts

@@ -5,7 +5,18 @@ import { electronApp, optimizer, is } from '@electron-toolkit/utils';
 import icon from '../../resources/icon.png?asset';
 import useElectron from './useElectron';
 import useWinProcess from './useWinProcess';
-// import log from './logger';
+import log from './logger';
+
+// 免登录流程
+function silenceAuthorityHandle(mainWindow) {
+  const arg = process.argv;
+  log.info(`process.argv:${JSON.stringify(arg)}`);
+  // mainWindow.webContents.send('silence-authority', arg[1]);
+  mainWindow.webContents.send(
+    'silence-authority',
+    'zgiOtrHS2nq9q3SOr0iOYAW1JJsG2w1lrqdv0PB2IrT9ijPBsKxT7I7u2077RaKAPbwfEj+9f/zr+RHzOZFsaYZo5GuoJLMdJPKvvOnpG/3jk6GsdPFlMooCjs5LzJKutFiFOj/xsXoOGdxqIYXWWH6sROZQAKhvBIu2Mfem6+fZhy66baK/s0ihec59gOTQ8lsjyJzf8To2K0EyapRWGVpFwljAmaQ1HfhfUUoRIYTIHW89wqRU3KYjB5oJQRQnVYLA7v0H9kK0smmX3N3Kbc0V9LtHUIiU/teGvWaa6ty43SAJqci9IRZEh35xzM9IjtzvR/9LHQWZqTLuVSZ+JmCwfKKGFV39ewYjrjmFk34tIW5yvmQ9oUugpi2T3xhdMA7aeNkkoK0tgm3hwqri3KdziGcqdEdkqhfW2vapwPDy4m5g/JH7ulNLI0nfDmPpTNsWgWXjUnmAQNWAp4In1oH8TMRNHImMbsxz4RhcBz/z/YCWl89zk/vA4TOtQDV99s66+8kVhTQEjDXffz6z2T5hZTGaPMv/lSCo1Fo01VM='
+  );
+}
 
 function createWindow(): void {
   // Create the browser window.
@@ -25,6 +36,7 @@ function createWindow(): void {
 
   mainWindow.on('ready-to-show', () => {
     mainWindow.show();
+    silenceAuthorityHandle(mainWindow);
   });
 
   mainWindow.webContents.setWindowOpenHandler((details) => {
@@ -32,11 +44,6 @@ function createWindow(): void {
     return { action: 'deny' };
   });
 
-  // TODO:方案要改
-  // const arg = process.argv;
-  // log.info(`process.argv:${JSON.stringify(arg)}`);
-  // mainWindow.webContents.send('silence-authority', arg[1]);
-
   // HMR for renderer base on electron-vite cli.
   // Load the remote URL for development or the local html file for production.
   if (is.dev && process.env.ELECTRON_RENDERER_URL) {

+ 2 - 2
src/App.vue

@@ -24,7 +24,7 @@
 
   interface AuthKey {
     user: Partial<UserState>;
-    domain: string;
+    apiUrl: string;
   }
 
   function registSilenceAuthEvent() {
@@ -41,7 +41,7 @@
     const data = authKeyData.user;
     if (!data.accessToken) return;
 
-    appStore.setInfo({ domain: authKeyData.domain });
+    appStore.setInfo({ domain: authKeyData.apiUrl });
 
     data.privilegeId = '';
     userStore.setInfo(data);

+ 2 - 3
src/api/interceptor.ts

@@ -13,7 +13,6 @@ import {
 } from '@arco-design/web-vue';
 import { initSyncTime, fetchTime } from '../utils/syncServerTime';
 import { getAuthorization } from '../utils/crypto';
-import { DEVICE_ID, PLATFORM } from '../constants/app';
 import { objTypeOf, pickByNotNull } from '../utils/utils';
 import { useUserStore, useAppStore } from '../store';
 
@@ -58,8 +57,8 @@ const modifyConfig = (config: AxiosRequestConfig): void => {
     headers.Authorization = Authorization;
     headers.time = String(timestamp);
   }
-  headers.deviceId = DEVICE_ID;
-  headers.platform = PLATFORM;
+  headers.deviceId = userStore.deviceId;
+  headers.platform = userStore.platform;
   headers.domain = appStore.domain;
 
   config.url = `${appStore.domain}${config.url}`;

+ 2 - 0
src/store/modules/user/index.ts

@@ -28,6 +28,8 @@ const useUserStore = defineStore('user', {
     version: '',
     privilegeId: '',
     uiSetting: null,
+    deviceId: '',
+    platform: '',
   }),
 
   getters: {

+ 2 - 0
src/store/modules/user/types.ts

@@ -40,4 +40,6 @@ export interface UserState {
   privilegeId: string;
   version: string;
   uiSetting: null;
+  deviceId: string;
+  platform: string;
 }