huangbin 4 rokov pred
rodič
commit
ba90ab7925

+ 7 - 0
README.md

@@ -22,3 +22,10 @@ yarn lint
 
 ### Customize configuration
 See [Configuration Reference](https://cli.vuejs.org/config/).
+
+与 wpf 交互逻辑
+
+是否有用户名和密码,
+    如果有则走静默登录(不跳转登录页面,直接调用登录逻辑);
+    如果没有,则走前端正常登录逻辑(非静默登录:直接跳转到登录页面,进行登录)
+

+ 1 - 1
public/config/app.config.json

@@ -1,3 +1,3 @@
 {
-    "apiUrl": "http://218.17.158.45:21001/cfg?key=test_176"
+    "apiUrl": "http://192.168.31.175:8080/cfg?key=test_175"
 }

+ 4 - 0
src/common/methods/mixin/index.ts

@@ -43,3 +43,7 @@ export const cacheInitData = (callback: Function): void => {
 export const setLoadComplete = (status: boolean) => {
     isLoadComplete = status;
 };
+
+export const getLoadIsComplete = (): boolean => {
+    return isLoadComplete
+}

+ 28 - 5
src/router/index.ts

@@ -1,7 +1,11 @@
 import * as EnumType from '@/common/constants/routerName';
+import { setLoadComplete } from '@/common/methods';
+import { getLoadIsComplete } from '@/common/methods/mixin';
 import Main from '@/layout/components/main.vue';
 import Layout from '@/layout/index.vue';
-import { isLogin } from '@/services/bus/login';
+import { globalDataRefresh } from '@/services/bus';
+import { isLogin, login } from '@/services/bus/login';
+import { localStorageUtil } from '@/utils/storage';
 import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
 import eventBus from '../utils/eventBus';
 
@@ -865,10 +869,29 @@ router.beforeEach((to, from, next) => {
         next();
     } else {
         // 前往其他页 判断是否是登录状态
-        if (isLogin()) return next();
-        // 不是登录状态不能去'我的'页面,跳至首页
-        // if (to.fullPath.indexOf('/mine') !== -1) next('/');
-        else next();
+        if (isLogin()) {
+            return next();
+        } else {
+            // const account = '1456456000000103'
+            // const password = 'd41efe629f9ed46baaa8f1ced2de518c645060e1965807776334820e55ce07c2'
+            if (!getLoadIsComplete()) {
+                console.log('to', to);
+                setLoadComplete(false)
+                globalDataRefresh().then(() => {
+                    const { ACCOUNT, PASSWORD } = to.query
+                    login(ACCOUNT as string, PASSWORD as string, [], true).then(res => {
+                        setLoadComplete(true)
+                        localStorageUtil.setItem('loginAccount', ACCOUNT); // 缓存登录账号
+                        eventBus.$emit('loginSuccess', true);
+                        next({ name: 'home' })
+                    }).catch(err => {
+                        console.log('err', err);
+                    })
+                })
+            } else {
+                next()
+            }
+        }
     }
 });
 export default router;

+ 2 - 2
src/services/bus/login.ts

@@ -17,12 +17,12 @@ export const logout = (): void => {
     logoutResponse();
 };
 
-export const login = async (logidCode: string, password: String, byteArr: Uint8Array[]): Promise<LoginResponse> => {
+export const login = async (logidCode: string, password: string, byteArr: Uint8Array[], isEncryt = false): Promise<LoginResponse> => {
     try {
         /** 建立行情交易长链 */
         await APP.connectTrading();
         const account = await GetLoginID(logidCode);
-        const loginData = await loginAction(account, password, byteArr);
+        const loginData = await loginAction(account, password, byteArr, isEncryt);
         // localstorage 缓存登录信息,处理页面刷新
         setLoginData(loginData);
         await Promise.all([GetErmcpGoods(), GetPCMenus(), QueryTableDefine(), getServerTime(), LoginQuery(), QueryDeliveryGoodsDetail(), getTaAccount()])

+ 2 - 1
src/services/dataCenter/index.ts

@@ -1,5 +1,5 @@
 import { reactive, toRefs } from 'vue';
-import { LastUpdateTimeModel, LoginaccountModel, TradeDateModel, userAccountModel, UserInfoModel } from './initDataModel/account';
+import { LastUpdateTimeModel, LoginaccountModel, TradeDateModel, userAccountModel, UserInfoModel, WPFInfo } from './initDataModel/account';
 import { NeedClearSourceDataType, NoClearSourceDataType } from './interface';
 
 /**
@@ -19,6 +19,7 @@ const needClearSourceData: NeedClearSourceDataType = {
     tableHead: [],
     Goods: [],
     DeliveryGoodsList: [],
+    WPFInfo: new WPFInfo(),
 
     queryClientFixedADConfigs: [],
     checkTokenTimeDiff: Math.floor(Math.random() * 6 + 5) * 60 * 1000,

+ 7 - 3
src/services/dataCenter/initDataModel/account.ts

@@ -1,6 +1,5 @@
-import { LastUpdateTime, TradeDate } from '@/services/dataCenter/interafce/account';
-import Long from 'long';
-import { Loginaccount, Userinfo, Useraccount } from '@/services/go/useInfo/interface';
+import { LastUpdateTime, TradeDate, WPFINfO } from '@/services/dataCenter/interafce/account';
+import { Loginaccount, Useraccount, Userinfo } from '@/services/go/useInfo/interface';
 
 /**
  *  获取最后更新时间模型类
@@ -140,3 +139,8 @@ export class userAccountModel implements Useraccount {
     userid = 0;
     usertype = 0;
 }
+
+export class WPFInfo implements WPFINfO {
+    account: '';
+    name: '';
+}

+ 5 - 0
src/services/dataCenter/interafce/account.ts

@@ -116,3 +116,8 @@ export interface TradeDate {
     tradedate2: string;
     updatetime: string;
 }
+
+export interface WPFINfO {
+    account: string;
+    name: string;
+}

+ 2 - 0
src/services/dataCenter/interface.ts

@@ -5,6 +5,7 @@ import * as mineType from '@/services/http/mine/interface';
 import * as Type from '@/services/http/notice/interface';
 import * as advert from '../http/advert/interface';
 import { QuoteDay } from '../http/quote/interface';
+import { WPFInfo } from './initDataModel/account';
 import { AccountListItem, LastUpdateTime, TradeDate } from './interafce/account';
 import { SystemParam } from './interafce/error';
 
@@ -37,6 +38,7 @@ export interface NeedClearSourceDataType {
     tableHead: TableDefineRsp[]; // 动态表头
     Goods: Goods[],
     DeliveryGoodsList: ErmcpDeliveryGoodsDetailEx[], // 现货品种
+    WPFInfo: WPFInfo,
 
     queryClientFixedADConfigs: advert.fixedADConfigs[]; //首页图片广告
     checkTokenTimeDiff: number; // 轮休校验token时间差

+ 2 - 3
src/services/socket/login/index.ts

@@ -12,9 +12,8 @@ import { LoginResponse } from './interface/index';
 
 let preDate = Date.now();
 
-export const loginAction = (logidCode: String, password: String, ClientSystemInfo: Uint8Array[]): Promise<LoginResponse> => {
-    const userAPassWord = `${logidCode}${password}`;
-    const LoginPWD = sha256.hex(userAPassWord);
+export const loginAction = (logidCode: string, password: string, ClientSystemInfo: Uint8Array[], isEncryt = false): Promise<LoginResponse> => {
+    const LoginPWD = isEncryt ? password : sha256.hex(`${logidCode}${password}`);
     const reqParams = {
         LoginPWD,
         LoginID: logidCode,

+ 0 - 0
src/views/account/login.ts


+ 45 - 44
src/views/account/login.vue

@@ -73,6 +73,7 @@ import { localStorageUtil } from '@/utils/storage/index';
 import { setLoadComplete } from '@/common/methods';
 import eventBus from '@/utils/eventBus/index';
 import { QWebChannel } from '@/utils/qt/qwebchannel.js';
+import { qtAction } from './qt';
 
 interface Form {
     account: string;
@@ -94,54 +95,54 @@ function setRememberAccount(): void {
         Object.assign(initForm, { account, isRemember: true });
     }
 }
-declare global {
-    interface Window {
-        qt: {
-            webChannelTransport: {
-                send: (payload: any) => void;
-                onmessage: (payload: any) => void;
-            };
-        };
-    }
-}
-function qtAction() {
-    // 获取 与qt交互实例
-    let qtWebChannel: any = null;
-    const webChannelTransport = window.qt?.webChannelTransport;
-    if (webChannelTransport) {
-        new QWebChannel(webChannelTransport, (channel: any) => {
-            // all published objects are available in channel.objects under
-            // the identifier set in their attached WebChannel.id property
-            qtWebChannel = channel.objects.bridge;
-            console.log('qtWebChannel', qtWebChannel);
-        });
-    }
+// declare global {
+//     interface Window {
+//         qt: {
+//             webChannelTransport: {
+//                 send: (payload: any) => void;
+//                 onmessage: (payload: any) => void;
+//             };
+//         };
+//     }
+// }
+// function qtAction() {
+//     // 获取 与qt交互实例
+//     let qtWebChannel: any = null;
+//     const webChannelTransport = window.qt?.webChannelTransport;
+//     if (webChannelTransport) {
+//         new QWebChannel(webChannelTransport, (channel: any) => {
+//             // all published objects are available in channel.objects under
+//             // the identifier set in their attached WebChannel.id property
+//             qtWebChannel = channel.objects.bridge;
+//             console.log('qtWebChannel', qtWebChannel);
+//         });
+//     }
 
-    function getQtInfo(): Promise<Uint8Array[]> {
-        if (qtWebChannel) {
-            return qtWebChannel.getSystemInfo().then((res: any) => {
-                return base64ToUint8Array(res);
-            });
-        } else {
-            console.warn('qtWebChannel is null');
-            return Promise.resolve([]);
-        }
-    }
-    return { getQtInfo };
-}
+//     function getQtInfo(): Promise<Uint8Array[]> {
+//         if (qtWebChannel) {
+//             return qtWebChannel.getSystemInfo().then((res: any) => {
+//                 return base64ToUint8Array(res);
+//             });
+//         } else {
+//             console.warn('qtWebChannel is null');
+//             return Promise.resolve([]);
+//         }
+//     }
+//     return { getQtInfo };
+// }
 
-function base64ToUint8Array(base64String: string) {
-    let padding = '='.repeat((4 - (base64String.length % 4)) % 4);
-    let base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
+// function base64ToUint8Array(base64String: string) {
+//     let padding = '='.repeat((4 - (base64String.length % 4)) % 4);
+//     let base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
 
-    let rawData = window.atob(base64);
-    let outputArray = new Uint8Array(rawData.length);
+//     let rawData = window.atob(base64);
+//     let outputArray = new Uint8Array(rawData.length);
 
-    for (var i = 0; i < rawData.length; ++i) {
-        outputArray[i] = rawData.charCodeAt(i);
-    }
-    return outputArray;
-}
+//     for (var i = 0; i < rawData.length; ++i) {
+//         outputArray[i] = rawData.charCodeAt(i);
+//     }
+//     return outputArray;
+// }
 
 export default defineComponent({
     name: 'login',

+ 51 - 0
src/views/account/qt.ts

@@ -0,0 +1,51 @@
+import { QWebChannel } from '@/utils/qt/qwebchannel.js';
+
+declare global {
+    interface Window {
+        qt: {
+            webChannelTransport: {
+                send: (payload: any) => void;
+                onmessage: (payload: any) => void;
+            };
+        };
+    }
+}
+
+function base64ToUint8Array(base64String: string) {
+    const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
+    const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
+
+    const rawData = window.atob(base64);
+    const outputArray = new Uint8Array(rawData.length);
+
+    for (let i = 0; i < rawData.length; ++i) {
+        outputArray[i] = rawData.charCodeAt(i);
+    }
+    return outputArray;
+}
+export function qtAction() {
+    // 获取 与qt交互实例
+    let qtWebChannel: any = null;
+    const webChannelTransport = window.qt?.webChannelTransport;
+    if (webChannelTransport) {
+        new QWebChannel(webChannelTransport, (channel: any) => {
+            // all published objects are available in channel.objects under
+            // the identifier set in their attached WebChannel.id property
+            qtWebChannel = channel.objects.bridge;
+            console.log('qtWebChannel', qtWebChannel);
+        });
+    }
+
+    function getQtInfo(): Promise<Uint8Array[]> {
+        if (qtWebChannel) {
+            return qtWebChannel.getSystemInfo().then((res: any) => {
+                return base64ToUint8Array(res);
+            });
+        } else {
+            console.warn('qtWebChannel is null');
+            return Promise.resolve([]);
+        }
+    }
+    return { getQtInfo };
+}
+