shishuangxi

头信息添加登录信息

1 import HashMap from '@ohos.util.HashMap' 1 import HashMap from '@ohos.util.HashMap'
2 import { ConfigConstants } from 'wdConstant' 2 import { ConfigConstants } from 'wdConstant'
3 -import { DateTimeUtils, Logger } from 'wdKit' 3 +import { DateTimeUtils, Logger, SPHelper } from 'wdKit'
4 4
5 /** 5 /**
6 * 网络请求业务侧工具类 6 * 网络请求业务侧工具类
@@ -68,6 +68,9 @@ export class HttpUrlUtils { @@ -68,6 +68,9 @@ export class HttpUrlUtils {
68 static readonly MORNING_EVENING_COMP_INFO_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo"; 68 static readonly MORNING_EVENING_COMP_INFO_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo";
69 69
70 private static hostUrl: string = HttpUrlUtils.HOST_UAT; 70 private static hostUrl: string = HttpUrlUtils.HOST_UAT;
  71 + private static userId=''
  72 + private static userType=''
  73 + private static token=''
71 74
72 static getCommonHeaders(): HashMap<string, string> { 75 static getCommonHeaders(): HashMap<string, string> {
73 let headers: HashMap<string, string> = new HashMap<string, string>() 76 let headers: HashMap<string, string> = new HashMap<string, string>()
@@ -80,7 +83,9 @@ export class HttpUrlUtils { @@ -80,7 +83,9 @@ export class HttpUrlUtils {
80 headers.set('timestamp', HttpUrlUtils.getTimestamp()) 83 headers.set('timestamp', HttpUrlUtils.getTimestamp())
81 headers.set('RMRB-X-TOKEN', HttpUrlUtils.getXToken()) 84 headers.set('RMRB-X-TOKEN', HttpUrlUtils.getXToken())
82 headers.set('device_id', HttpUrlUtils.getDeviceId()) 85 headers.set('device_id', HttpUrlUtils.getDeviceId())
83 - // headers.set('cookie', 'RMRB-X-TOKEN=eyJhbGciOiJIUzI1NiIsImtpZCI6ImQ4WkI2QkhxSEZrdjJ2U25BNlRwZEdKRjBHcjItVzBvS2FaYzdLOUUycmcifQ.eyJpc3MiOiJwZW9wbGVzLWRhaWx5LWZvdXJhIiwic3ViIjoicGVvcGxlcy1kYWlseS1mb3VyYSIsImV4cCI6MTcwMzY0OTYwNiwidXNlcklkIjo0NTk3NzYyOTc0NzQ5NDksInVzZXJWZXJzaW9uIjoiNDU5Nzc2Mjk3NDc0OTQ5XzIiLCJ1c2VyTmFtZSI6IkJ1bGlraWtpMTgxIiwidXNlclR5cGUiOjIsImNyZWF0b3JJZCI6NDI2NTM5MH0.jhQ9kylcm3FxWf0-lBMZuLkdtIQ6XpFnAi0AFZJNwfc') 86 + if(HttpUrlUtils.token!=''){
  87 + headers.set('cookie', 'RMRB-X-TOKEN='+HttpUrlUtils.token)
  88 + }
84 headers.set('build_version', HttpUrlUtils.getVersion()) 89 headers.set('build_version', HttpUrlUtils.getVersion())
85 headers.set('adcode', HttpUrlUtils.getAdCode()) 90 headers.set('adcode', HttpUrlUtils.getAdCode())
86 headers.set('os_version', HttpUrlUtils.getOsVersion()) 91 headers.set('os_version', HttpUrlUtils.getOsVersion())
@@ -221,11 +226,11 @@ export class HttpUrlUtils { @@ -221,11 +226,11 @@ export class HttpUrlUtils {
221 226
222 private static getUserId() { 227 private static getUserId() {
223 // TODO 对接登录 228 // TODO 对接登录
224 - return '459776297474949'; 229 + return HttpUrlUtils.userId;
225 } 230 }
226 231
227 private static getUserType() { 232 private static getUserType() {
228 - return '2'; 233 + return HttpUrlUtils.userType;
229 } 234 }
230 235
231 static getVerifyCodeUrl() { 236 static getVerifyCodeUrl() {
@@ -242,4 +247,16 @@ export class HttpUrlUtils { @@ -242,4 +247,16 @@ export class HttpUrlUtils {
242 let url = HttpUrlUtils.hostUrl + "/api/rmrb-user-center/auth/zh/c/checkVerifyCode"; 247 let url = HttpUrlUtils.hostUrl + "/api/rmrb-user-center/auth/zh/c/checkVerifyCode";
243 return url; 248 return url;
244 } 249 }
  250 +
  251 + public static setUserId(userId:string){
  252 + HttpUrlUtils.userId=userId;
  253 + }
  254 +
  255 + public static setUserType(userType:string){
  256 + HttpUrlUtils.userType=userType;
  257 + }
  258 +
  259 + public static setUserToken(token:string){
  260 + HttpUrlUtils.token=token;
  261 + }
245 } 262 }
@@ -8,6 +8,7 @@ import buffer from '@ohos.buffer' @@ -8,6 +8,7 @@ import buffer from '@ohos.buffer'
8 import { 8 import {
9 SpConstants 9 SpConstants
10 } from '../../../../../../../commons/wdNetwork/oh_modules/wdConstant/src/main/ets/constants/SpConstants' 10 } from '../../../../../../../commons/wdNetwork/oh_modules/wdConstant/src/main/ets/constants/SpConstants'
  11 +import { HttpUrlUtils } from 'wdNetwork/src/main/ets/http/HttpUrlUtils'
11 12
12 const TAG = "LoginViewModel" 13 const TAG = "LoginViewModel"
13 14
@@ -42,7 +43,9 @@ export class LoginViewModel { @@ -42,7 +43,9 @@ export class LoginViewModel {
42 SPHelper.default.save(SpConstants.USER_STATUS, data.status) 43 SPHelper.default.save(SpConstants.USER_STATUS, data.status)
43 SPHelper.default.save(SpConstants.USER_Type, data.userType) 44 SPHelper.default.save(SpConstants.USER_Type, data.userType)
44 SPHelper.default.save(SpConstants.USER_NAME, data.userName) 45 SPHelper.default.save(SpConstants.USER_NAME, data.userName)
45 - 46 + HttpUrlUtils.setUserId(data.id+"")
  47 + HttpUrlUtils.setUserType(data.userType+"")
  48 + HttpUrlUtils.setUserToken(data.jwtToken)
46 success(data) 49 success(data)
47 }).catch(() => { 50 }).catch(() => {
48 fail() 51 fail()
@@ -64,7 +67,9 @@ export class LoginViewModel { @@ -64,7 +67,9 @@ export class LoginViewModel {
64 SPHelper.default.save(SpConstants.USER_STATUS, data.status) 67 SPHelper.default.save(SpConstants.USER_STATUS, data.status)
65 SPHelper.default.save(SpConstants.USER_Type, data.userType) 68 SPHelper.default.save(SpConstants.USER_Type, data.userType)
66 SPHelper.default.save(SpConstants.USER_NAME, data.userName) 69 SPHelper.default.save(SpConstants.USER_NAME, data.userName)
67 - 70 + HttpUrlUtils.setUserId(data.id+"")
  71 + HttpUrlUtils.setUserType(data.userType+"")
  72 + HttpUrlUtils.setUserToken(data.jwtToken)
68 success(data) 73 success(data)
69 }).catch((value: string) => { 74 }).catch((value: string) => {
70 fail(value) 75 fail(value)