| 
					
				 | 
			
			
				@@ -0,0 +1,77 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { defineStore } from 'pinia'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { DAHUALogin, DAHUALoginParams, LoginResponse } from '@/api/dahua'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import isString from 'lodash/isString'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { parseStr } from '@/utils'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import md5 from 'crypto-js/md5'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { DA_HUA, DA_HUA_URL_PREFIX } from '@/constants/constants'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import hex from 'crypto-js/format-hex'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { ElMessage } from 'element-plus'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+export interface DaHuaStateType {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+export interface DaHuaActionsType { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  DAHUALogin(): void; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+export default defineStore<'daHua', DaHuaStateType, {}, DaHuaActionsType>( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  'daHua', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    state: () => ({}), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    actions: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      async DAHUALogin() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const { password, username } = DA_HUA; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const firstLoginRes = await fetch( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            `${DA_HUA_URL_PREFIX}/videoService/accounts/authorize`, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              method: 'POST', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              headers: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                'Content-Type': 'application/json', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                'X-Subject-Token': '', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              body: JSON.stringify({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                userName: username, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                clientType: 'winpc', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ipAddress: '', //可不传 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                pid: 2548, //可不传 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              }), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const firstLogin = (await firstLoginRes.json()) as unknown as { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            realm?: string; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            randomKey: string; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const md1 = md5(password); //第1次加密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const md2 = md5(username + md1); //第2次加密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const md3 = md5(md2); //第3次加密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const md4 = md5(username + ':' + firstLogin.realm + ':' + md3); //第4次加密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const signature = md5(md4 + ':' + firstLogin.randomKey); //第5次加密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const data = await DAHUALogin({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userName: username, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            signature: signature.toString(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            randomKey: firstLogin.randomKey, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            encryptType: 'MD5', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            clientType: 'winpc', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pid: 2548, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          const next = isString(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ? parseStr<LoginResponse>(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            : data ?? {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          localStorage.setItem('DAHUA_token', JSON.stringify(next.token || '')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          localStorage.setItem( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'DAHUA_userId', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            JSON.stringify(next.userId || ''), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (err) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          console.log(err); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          ElMessage.error({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            message: '大华应急指挥调度实战平台鉴权失败, 请尝试刷新页面重试', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+); 
			 |