第一次提交

This commit is contained in:
xiaoxiao
2025-05-09 15:47:54 +08:00
parent 25e596b591
commit f9d7986df0
357 changed files with 26943 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
+17
View File
@@ -0,0 +1,17 @@
/**
* Use these variables when you tailor your ArkTS code. They must be of the const type.
*/
export const HAR_VERSION = '1.0.0';
export const BUILD_MODE_NAME = 'debug';
export const DEBUG = true;
export const TARGET_NAME = 'default';
/**
* BuildProfile Class is used only for compatibility purposes.
*/
export default class BuildProfile {
static readonly HAR_VERSION = HAR_VERSION;
static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
static readonly DEBUG = DEBUG;
static readonly TARGET_NAME = TARGET_NAME;
}
+27
View File
@@ -0,0 +1,27 @@
export { hdHttp, HdResponse } from './src/main/ets/utils/request'
export { authStore, HdUser, AUTH_STORE_KEY } from './src/main/ets/utils/auth'
export { logger } from './src/main/ets/utils/logger'
export { getTimeText, getPercentText } from './src/main/ets/utils/base'
export { themeManager } from './src/main/ets/utils/themeManager'
export { Base64Util } from './src/main/ets/utils/Base64Util'
export { ChangeUtil } from './src/main/ets/utils/ChangeUtil'
export { HdNav } from './src/main/ets/components/HdNav'
export { BasicConstant } from './src/main/ets/constants/BasicConstant'
export { preferenceStore } from './src/main/ets/utils/PreferenceStore'
export { LoginInfo,Data } from './src/main/ets/models/LoginInfoModel'
export { DataWebModel } from './src/main/ets/models/DataWebModel'
export { PromptActionClass } from './src/main/ets/components/PromptActionClass'
export { RequestDefaultModel } from './src/main/ets/models/RequestDefaultModel'
+31
View File
@@ -0,0 +1,31 @@
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": false,
"files": [
"./obfuscation-rules.txt"
]
},
"consumerFiles": [
"./consumer-rules.txt"
]
}
},
},
],
"targets": [
{
"name": "default"
},
{
"name": "ohosTest"
}
]
}
View File
+6
View File
@@ -0,0 +1,6 @@
import { harTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
+23
View File
@@ -0,0 +1,23 @@
# Define project specific obfuscation rules here.
# You can include the obfuscation configuration files in the current module's build-profile.json5.
#
# For more details, see
# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5
# Obfuscation options:
# -disable-obfuscation: disable all obfuscations
# -enable-property-obfuscation: obfuscate the property names
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
# -compact: remove unnecessary blank spaces and all line feeds
# -remove-log: remove all console.* statements
# -print-namecache: print the name cache that contains the mapping from the old names to new names
# -apply-namecache: reuse the given cache file
# Keep options:
# -keep-property-name: specifies property names that you want to keep
# -keep-global-name: specifies names that you want to keep in the global scope
-enable-property-obfuscation
-enable-toplevel-obfuscation
-enable-filename-obfuscation
-enable-export-obfuscation
+9
View File
@@ -0,0 +1,9 @@
{
"name": "@itcast/basic",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"dependencies": {}
}
@@ -0,0 +1,90 @@
import { router } from '@kit.ArkUI'
@Builder
function defaultBuilder(): void {
}
@Component
export struct HdNav {
@StorageProp('topHeight')
topHeight: number = 0
@Prop
title: string = ''
@Prop
textColor: ResourceStr = $r('app.color.top_title')
@Prop
bgColor: ResourceStr = $r('app.color.top_bg')
@Prop
hasBorder: boolean = false
@Prop
leftIcon: ResourceStr = $r('app.media.top_back')
@Prop
rightIcon: ResourceStr = $r('sys.media.ohos_ic_public_more')
@Prop
showRightIcon: boolean = true
@Prop
showLeftIcon: boolean = true
@Prop
showRightText: boolean = false
@Prop
rightText: string = ''
@BuilderParam
titleBuilder: () => void = defaultBuilder
@BuilderParam
menuBuilder: () => void = defaultBuilder
build() {
Row({ space: 16 }) {
if (this.showLeftIcon) {
Image(this.leftIcon)
.size({ width: 24, height: 24 })
.margin({left:-5})
.onClick(() => router.back())
.fillColor($r('app.color.black'))
}
else {
Blank()
.width(24)
}
Row() {
if (this.title) {
Text(this.title)
.fontWeight(600)
.layoutWeight(1)
.textAlign(TextAlign.Center)
.fontSize(20)
.fontColor(this.textColor)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
} else if (this.titleBuilder) {
this.titleBuilder()
}
}
.height(56)
.layoutWeight(1)
if (this.showRightIcon) {
Image(this.rightIcon)
.size({ width: 24, height: 24 })
.objectFit(ImageFit.Contain)
.bindMenu(this.menuBuilder)
} else if (this.showRightText)
{
Text(this.rightText)
.fontSize(16)
.fontColor(this.textColor)
.margin({right:10})
}
else {
Blank()
.width(24)
}
}
.padding({ left: 16, right: 16, top: this.topHeight })
.height(56 + this.topHeight)
.width('100%')
.backgroundColor(this.bgColor)
}
}
@@ -0,0 +1,24 @@
import { webview } from '@kit.ArkWeb'
import { logger } from '../utils/logger'
@Component
export struct HdWeb {
layoutMode: WebLayoutMode = WebLayoutMode.NONE
src: ResourceStr = $rawfile('detail.html')
onLoad: () => void = () => {
}
controller: webview.WebviewController = new webview.WebviewController()
build() {
Web({ src: this.src, controller: this.controller })
.javaScriptAccess(true)
.onPageEnd(() => {
this.onLoad()
})
.onErrorReceive(event => {
logger.error(event!.error.getErrorInfo())
})
.layoutMode(this.layoutMode)
.layoutWeight(1)
}
}
@@ -0,0 +1,62 @@
import { BusinessError } from '@kit.BasicServicesKit';
import { ComponentContent, promptAction, UIContext } from '@kit.ArkUI';
export class PromptActionClass {
static ctx: UIContext;
static contentNode: ComponentContent<Object>;
static options: promptAction.BaseDialogOptions;
static setContext(context: UIContext) {
PromptActionClass.ctx = context;
}
static setContentNode(node: ComponentContent<Object>) {
PromptActionClass.contentNode = node;
}
static setOptions(options: promptAction.BaseDialogOptions) {
PromptActionClass.options = options;
}
static openDialog() {
if (PromptActionClass.contentNode !== null) {
PromptActionClass.ctx.getPromptAction().openCustomDialog(PromptActionClass.contentNode, PromptActionClass.options)
.then(() => {
console.info('OpenCustomDialog complete.')
})
.catch((error: BusinessError) => {
let message = (error as BusinessError).message;
let code = (error as BusinessError).code;
console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);
})
}
}
static closeDialog() {
if (PromptActionClass.contentNode !== null) {
PromptActionClass.ctx.getPromptAction().closeCustomDialog(PromptActionClass.contentNode)
.then(() => {
console.info('CloseCustomDialog complete.')
})
.catch((error: BusinessError) => {
let message = (error as BusinessError).message;
let code = (error as BusinessError).code;
console.error(`CloseCustomDialog args error code is ${code}, message is ${message}`);
})
}
}
static updateDialog(options: promptAction.BaseDialogOptions) {
if (PromptActionClass.contentNode !== null) {
PromptActionClass.ctx.getPromptAction().updateCustomDialog(PromptActionClass.contentNode, options)
.then(() => {
console.info('UpdateCustomDialog complete.')
})
.catch((error: BusinessError) => {
let message = (error as BusinessError).message;
let code = (error as BusinessError).code;
console.error(`UpdateCustomDialog args error code is ${code}, message is ${message}`);
})
}
}
}
@@ -0,0 +1,18 @@
export class BasicConstant {
static readonly SPACE_SM = 4
static readonly SPACE_MD = 10
static readonly SPACE_LG = 16
static readonly getyyzc="https://doc.igandan.com/app/integral/permission_expert.html";//隐私政策
static readonly getzcxy = "http://app.igandan.com/expert_zcxy.jsp";// 注册协议正式地址
//测试环境
static readonly urlimage = "https://dev-app.igandan.com/app/";
static readonly urlmyLan = "https://dev-app.igandan.com/app/expertAPI/";
static readonly urlapp = "https://dev-app.igandan.com//app/expertApp/"
static readonly urlHtml = "http://dev-doc.igandan.com/app/"
static readonly imageHeader = "http://doc.igandan.com/app/"
static readonly urlExpert = "https://dev-app.igandan.com/app/expert/"
static readonly getStartpage=BasicConstant.urlapp + "startpage";
}
@@ -0,0 +1,4 @@
export class DataWebModel {
url: string = '';
title: string = '';
}
@@ -0,0 +1,55 @@
import { List } from '@kit.ArkTS';
export interface LoginInfo{
special: List<SpecialDisease> ;
YX_accid:string ;
code:string;
data:Data;
YX_token:string;
nginxPath:string;
message:string;
}
interface SpecialDisease{
diseaseName:string;
diseaseUuid:string;
}
export interface Data{
isEnable:number;
isVisit:number;
modifyDate:string;
currentSpec:string;
deviceType:number;
currentType:number;
deviceSpec:string;
positionName:string;
userName:string;
createDate:string;
password:string;
officeName:string;
certificateImg:string;
birthDate:string;
isStar:number;
countyId:number;
cityId:number;
email:string;
photo:string;
qrcode:string;
mobile:string;
hospitalName:string;
officeUuid:string;
checkInfo:string;
hospitalUuid:string;
officePhone:string;
positionUuid:string;
nation:number;
wechat_qrcode:string;
sex:number;
provId:number;
uuid:string;
intro:string;
certificate:string;
state:number;
realName:string;
specialy:Array<object>;
}
@@ -0,0 +1,13 @@
export interface RequestDefaultModel{
code:string;
data:DefaulyData[];
message:string;
}
export interface DefaulyData {
'officeName':string;
'officeUuid':string;
'name':string;
'uuid':string;
}
@@ -0,0 +1,84 @@
import util from '@ohos.util';
import { buffer } from '@kit.ArkTS';
/**
* Base64 工具类
* author: 鸿蒙布道师
* since: 2025/03/31
*/
export class Base64Util {
/**
* 创建 Base64Helper 实例
* @returns Base64Helper 实例
*/
private static createBase64Helper(): util.Base64Helper {
return new util.Base64Helper();
}
/**
* 编码为 Uint8Array(异步)
* @param array 输入的 Uint8Array 数据
* @returns 编码后的 Uint8Array 对象
*/
static encode(array: Uint8Array): Promise<Uint8Array> {
const base64 = Base64Util.createBase64Helper();
return base64.encode(array);
}
/**
* 编码为 Uint8Array(同步)
* @param array 输入的 Uint8Array 数据
* @returns 编码后的 Uint8Array 对象
*/
static encodeSync(array: Uint8Array): Uint8Array {
const base64 = Base64Util.createBase64Helper();
return base64.encodeSync(array);
}
/**
* 编码为字符串(异步)
* @param array 输入的 Uint8Array 数据
* @param options 可选参数
* @returns 编码后的字符串
*/
static encodeToStr(array: Uint8Array, options?: util.Type): Promise<string> {
const base64 = Base64Util.createBase64Helper();
return base64.encodeToString(array, options);
}
/**
* 编码为字符串(同步)
* @param array 输入的 Uint8Array 数据
* @param options 可选参数
* @returns 编码后的字符串
*/
static encodeToStrSync(keyValueStr:string): string {
let array: Uint8Array=new Uint8Array(buffer.from(keyValueStr, 'utf-8').buffer)
const base64 = Base64Util.createBase64Helper();
return base64.encodeToStringSync(array, util.Type.BASIC).replaceAll("=", "");
}
/**
* 解码为 Uint8Array(异步)
* @param input 输入的 Uint8Array 或字符串
* @param options 可选参数
* @returns 解码后的 Uint8Array 对象
*/
static decode(input: Uint8Array | string, options?: util.Type): Promise<Uint8Array> {
const base64 = Base64Util.createBase64Helper();
return base64.decode(input, options);
}
/**
* 解码为 Uint8Array(同步)
* @param input 输入的 Uint8Array 或字符串
* @param options 可选参数
* @returns 解码后的 Uint8Array 对象
*/
static decodeSync(input: Uint8Array | string, options?: util.Type): Uint8Array {
const base64 = Base64Util.createBase64Helper();
return base64.decodeSync(input, options);
}
}
@@ -0,0 +1,58 @@
import HashMap from '@ohos.util.HashMap';
import { Base64Util } from './Base64Util';
import { CryptoJS } from '@ohos/crypto-js';
export class ChangeUtil {
/**
* 将HashMap转成JsonString
* @param map
* @returns
*/
static map2Json(map:HashMap<string, string>): string {
let jsonObject: Record<string, Object> = {};
map.forEach((value, key) => {
if(key != undefined && value != undefined){
jsonObject[key] = value;
}
})
return JSON.stringify(jsonObject);
}
static getSign(extraDatas1: HashMap<string, string>, secret: string): string {
if(secret!=null) {
let keyValueStr: string = "";
let entriesArray: Array<string> = Array.from(extraDatas1.keys());
entriesArray.sort();
let sortedMap:HashMap<string, string> = new HashMap();
entriesArray.forEach((value: string, index: number) => {
sortedMap.set(value,extraDatas1.get(value));
keyValueStr +=value+extraDatas1.get(value)
});
keyValueStr = keyValueStr.replace(" ", "");
keyValueStr = keyValueStr + CryptoJS.MD5(secret).toString();
let Md5keyValueStr: string = CryptoJS.MD5(keyValueStr).toString();
let base64Str:string=Base64Util.encodeToStrSync(Md5keyValueStr);
return base64Str;
}
else
{
return '';
}
}
static isMobileNum(mobiles:string): boolean {
const reg2: RegExp = new RegExp('^(1[3-9])[0-9]{9}$')
return reg2.test(mobiles);
}
static isPassword(password:string): boolean {
const reg2: RegExp = new RegExp('^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$')
return reg2.test(password);
}
}
@@ -0,0 +1,44 @@
import { preferences } from '@kit.ArkData'
class PreferenceStore {
KEY = 'gdxz_config'
store: preferences.Preferences | null = null
getStore() {
if (!this.store) {
this.store = preferences.getPreferencesSync(getContext(), { name: this.KEY })
}
return this.store
}
setItemString(keyword: string,value:string) {
this.getStore().putSync(keyword, value)
this.getStore().flush()
}
setItemBoolean(keyword: string,value:boolean) {
this.getStore().putSync(keyword, value)
this.getStore().flush()
}
delItem(keyword: string) {
this.getStore().deleteSync(keyword)
this.getStore().flush()
}
getItemString(keyword: string) {
return this.getStore().getSync(keyword,'')
}
getItemBooleanT(keyword: string):boolean {
return this.getStore().getSync(keyword,true) as boolean
}
getItemBooleanF(keyword: string):boolean {
return this.getStore().getSync(keyword,false) as boolean
}
clear() {
this.getStore().clearSync()
}
getAll() {
const obj = this.getStore().getAllSync()
return Object.keys(obj)
}
}
export const preferenceStore = new PreferenceStore()
+73
View File
@@ -0,0 +1,73 @@
import { preferences } from '@kit.ArkData'
import { router } from '@kit.ArkUI'
import { Data } from '../models/LoginInfoModel'
export interface HdUser {
id: string
username: string
avatar: string
token: string
refreshToken: string
nickName?: string
totalTime?: number
clockinNumbers?: number
}
export const AUTH_STORE_KEY = 'authStore'
class AuthStore {
store: preferences.Preferences | null = null
getStore() {
if (!this.store) {
this.store = preferences.getPreferencesSync(getContext(), { name: AUTH_STORE_KEY })
}
return this.store
}
async setUser(user: Data) {
AppStorage.setOrCreate('user', user)
await this.getStore().put(AUTH_STORE_KEY, JSON.stringify(user))
await this.getStore().flush()
}
async delUser() {
AppStorage.setOrCreate('user', {})
await this.getStore().put(AUTH_STORE_KEY, '{}')
await this.getStore().flush()
}
initUser() {
const json = this.getStore().getSync(AUTH_STORE_KEY, '{}') as string
AppStorage.setOrCreate('user', JSON.parse(json))
}
getUser() {
return AppStorage.get<Data>('user') || {} as Data
}
checkAuth(options: router.RouterOptions | Function) {
// if (this.getUser().token) {
// if (typeof options === 'function') {
// options()
// } else {
// router.pushUrl(options)
// }
// } else {
// if (typeof options === 'function') {
// router.pushUrl({
// url: 'pages/LoginPage',
// })
// } else {
// const params = options.params as Record<string, string> || {}
// params.return_path = options.url
// router.pushUrl({
// url: 'pages/LoginPage',
// params: params
// })
// }
// }
}
}
export const authStore = new AuthStore()
+10
View File
@@ -0,0 +1,10 @@
export const getTimeText = (time: number = 0, hasUnit = true) => {
if (time < 3600) {
return String(Math.floor(time / 60)) + (hasUnit ? ' 分钟' : '')
} else {
return String(Math.round(time / 3600 * 10) / 10) + (hasUnit ? ' 小时' : '')
}
}
export const getPercentText =
(value: number, total: number) => Math.round(value / total * 100) + '%'
@@ -0,0 +1,289 @@
import { http } from '@kit.NetworkKit';
import { authStore } from './auth';
import { promptAction, router } from '@kit.ArkUI';
import { BusinessError } from '@ohos.base';
import { logger } from './logger';
import { HashMap } from '@kit.ArkTS';
import { CryptoJS } from '@ohos/crypto-js'
import { Base64Util } from './Base64Util';
import { ChangeUtil } from './ChangeUtil'
interface HdRequestOptions {
baseURL?: string
}
type HdParams = Record<string, string | number | boolean>
export interface HdResponse<T> {
code: number
message: string
data: T
}
export interface TimestampBean {
timestamp:string
}
class HdHttp {
baseURL: string
constructor(options: HdRequestOptions) {
this.baseURL = options.baseURL || ''
}
private request1<T>(path: string, method: http.RequestMethod = http.RequestMethod.GET, extraDatas:HashMap<string, string>) {
const httpInstance = http.createHttp()
let fullUrl = this.baseURL + path
let promise = httpInstance.request(
// 请求url地址
fullUrl,
{
// 请求方式
method: http.RequestMethod.POST,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json',
'sign':this.getSign(extraDatas)
},
extraData:ChangeUtil.map2Json(extraDatas)
});
logger.info('Response JSON.stringify(extraDatas)' + ChangeUtil.map2Json(extraDatas))
return promise.then((data) => {
logger.info('Response request:' + data.result);
if (data.result) {
const result = data.result as HdResponse<T>
logger.info('Response result:' + result);
return result
}
return Promise.reject(data.result)
// if (data.responseCode === http.ResponseCode.OK) {
// console.info('Response request:' + data.result);
//
// }
// else
// {
//
// }
// return Promise.reject(data.result)
}
).catch((err:BusinessError) => {
logger.info('Response httpReq request:' + JSON.stringify(err));
return Promise.reject(err)
}).finally(() => {
httpInstance.destroy()
})
}
private request<T>(path: string, method: http.RequestMethod = http.RequestMethod.POST, extraDatas :HashMap<string, string>) {
const httpInstance = http.createHttp()
const options: http.HttpRequestOptions = {
method: http.RequestMethod.POST,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json',
'sign':this.getSign(extraDatas)
},
extraData:ChangeUtil.map2Json(extraDatas)
}
let fullUrl = this.baseURL + path
return httpInstance.request(fullUrl, options).then((res) => {
logger.info('Response fullUrl:' +fullUrl+ res.result);
const result = res.result as HdResponse<T>
return result
}).catch((err: BusinessError) => {
logger.info(fullUrl+`Response succeeded: ${err}`);
promptAction.showToast({ message: err.message || '网络错误' })
return Promise.reject(err)
}).finally(() => {
httpInstance.destroy()
})
}
private requestafter<T>(path: string, method: http.RequestMethod = http.RequestMethod.GET, extraData?: Object) {
const httpInstance = http.createHttp()
const options: http.HttpRequestOptions = {
method: http.RequestMethod.GET,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json'
}
}
let fullUrl = this.baseURL + path
if (method === http.RequestMethod.GET && extraData) {
const strArr = Object.keys(extraData)
.filter(key => (extraData as HdParams)[key] !== undefined)
.map(key => `${key}=${(extraData as HdParams)[key]}`)
fullUrl += `?${strArr.join('&')}`
} else {
options.extraData = extraData
}
return httpInstance.request(fullUrl, options).then((res) => {
return Promise.reject(res.result)
}).catch((err: BusinessError) => {
logger.error(fullUrl+`Response succeeded: ${err}+${err.name}+${err.message}+${err.data}+${err.stack}`);
// logger.error(fullUrl, err.code?.toString(), err.message)
promptAction.showToast({ message: err.message || '网络错误' })
return Promise.reject(err)
}).finally(() => {
httpInstance.destroy()
})
}
get<T>(url: string, data?: Object): Promise<HdResponse<T>> {
return this.requestafter<T>(url, http.RequestMethod.GET, data)
}
post<T>(url: string, data?: Object): Promise<HdResponse<T>> {
return this.requestafter<T>(url, http.RequestMethod.POST, data)
}
put<T>(url: string, data?: Object): Promise<HdResponse<T>> {
return this.requestafter<T>(url, http.RequestMethod.PUT, data)
}
delete<T>(url: string, data?: Object): Promise<HdResponse<T>> {
return this.requestafter<T>(url, http.RequestMethod.DELETE, data)
}
posts<T>(url: string, data: HashMap<string, string>): Promise<HdResponse<T>> {
return this.request<T>(url, http.RequestMethod.POST, data)
}
httpReq<T>(url: string, datas: HashMap<string, string>): Promise<HdResponse<T>> {
// 创建httpRequest对象。
let httpRequest = http.createHttp();
let url1 = "https://dev-app.igandan.com/app/manager/getSystemTimeStamp";
let promise = httpRequest.request(
// 请求url地址
url1,
{
// 请求方式
method: http.RequestMethod.GET,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json'
}
});
// 处理响应结果。
return promise.then((data) => {
if (data.responseCode === http.ResponseCode.OK) {
logger.info('Response httpReq:' + data.result);
let json:TimestampBean = JSON.parse(data.result.toString()) as TimestampBean;
let tp = json.timestamp;
datas.set("user_uuid", '');
datas.set("client_type", 'A');
datas.set("version",'4.0.0' );
datas.set('timestamp',tp+'');
return this.posts<T>(url, datas);
}
else
{
return this.posts<T>(url, datas);
}
}
).catch((err:BusinessError) => {
logger.info('Response httpReq error:' + JSON.stringify(err));
return Promise.reject(err);
}).finally(() => {
httpRequest.destroy()
})
}
httpReqSimply<T>(url: string) {
// 创建httpRequest对象。
let httpRequest = http.createHttp();
let promise = httpRequest.request(
// 请求url地址
url,
{
// 请求方式
method: http.RequestMethod.POST,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json'
}
});
// 处理响应结果。
return promise.then((data) => {
logger.info('Response httpReqSimply:' + JSON.stringify(data));
const result = data.result as HdResponse<T>
return result
}
).catch((err:BusinessError) => {
logger.info('Response httpReq error:' + JSON.stringify(err));
return Promise.reject(err);
}).finally(() => {
httpRequest.destroy()
})
}
getSign(extraDatas1:HashMap<string, string>): string {
let secret= extraDatas1.get("timestamp")
if(secret!=null) {
let keyValueStr: string = "";
let entriesArray: Array<string> = Array.from(extraDatas1.keys());
entriesArray.sort();
let sortedMap:HashMap<string, string> = new HashMap();
entriesArray.forEach((value: string, index: number) => {
sortedMap.set(value,extraDatas1.get(value));
keyValueStr +=value+extraDatas1.get(value)
});
keyValueStr = keyValueStr.replace(" ", "");
keyValueStr = keyValueStr + CryptoJS.MD5(secret).toString();
let Md5keyValueStr: string = CryptoJS.MD5(keyValueStr).toString();
let base64Str:string=Base64Util.encodeToStrSync(Md5keyValueStr);
return base64Str;
}
else
{
return '';
}
}
}
export const hdHttp = new HdHttp({ baseURL: '' })
@@ -0,0 +1,33 @@
import hilog from '@ohos.hilog'
const DOMAIN = 0xFF09
const PREFIX = 'PASS_INTERVIEW_LOGGER'
const FORMAT = '%{public}s, %{public}s'
class Logger {
debug(...args: string[]) {
hilog.debug(DOMAIN, PREFIX, FORMAT, args)
}
info(...args: string[]) {
hilog.info(DOMAIN, PREFIX, FORMAT, args)
}
warn(...args: string[]) {
hilog.warn(DOMAIN, PREFIX, FORMAT, args)
}
error(...args: string[]) {
hilog.error(DOMAIN, PREFIX, FORMAT, args)
}
fatal(...args: string[]) {
hilog.fatal(DOMAIN, PREFIX, FORMAT, args)
}
isLoggable(level: hilog.LogLevel) {
hilog.isLoggable(DOMAIN, PREFIX, level)
}
}
export const logger = new Logger()
@@ -0,0 +1,290 @@
import { http } from '@kit.NetworkKit';
import { authStore } from './auth';
import { promptAction, router } from '@kit.ArkUI';
import { BusinessError } from '@ohos.base';
import { logger } from './logger';
import { HashMap } from '@kit.ArkTS';
import { CryptoJS } from '@ohos/crypto-js'
import { Base64Util } from './Base64Util';
import { ChangeUtil } from './ChangeUtil'
import { BasicConstant } from '../constants/BasicConstant'
interface HdRequestOptions {
baseURL?: string
}
type HdParams = Record<string, string | number | boolean>
export interface HdResponse<T> {
code: number
message: string
data: T
}
export interface TimestampBean {
timestamp:string
}
class HdHttp {
baseURL: string
constructor(options: HdRequestOptions) {
this.baseURL = options.baseURL || ''
}
private request1<T>(path: string, method: http.RequestMethod = http.RequestMethod.GET, extraDatas:HashMap<string, string>) {
const httpInstance = http.createHttp()
let fullUrl = this.baseURL + path
let promise = httpInstance.request(
// 请求url地址
fullUrl,
{
// 请求方式
method: http.RequestMethod.POST,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json',
'sign':this.getSign(extraDatas)
},
extraData:ChangeUtil.map2Json(extraDatas)
});
logger.info('Response JSON.stringify(extraDatas)' + ChangeUtil.map2Json(extraDatas))
return promise.then((data) => {
logger.info('Response request:' + data.result);
if (data.result) {
const result = data.result as HdResponse<T>
logger.info('Response result:' + result);
return result
}
return Promise.reject(data.result)
// if (data.responseCode === http.ResponseCode.OK) {
// console.info('Response request:' + data.result);
//
// }
// else
// {
//
// }
// return Promise.reject(data.result)
}
).catch((err:BusinessError) => {
logger.info('Response httpReq request:' + JSON.stringify(err));
return Promise.reject(err)
}).finally(() => {
httpInstance.destroy()
})
}
private request<T>(path: string, method: http.RequestMethod = http.RequestMethod.POST, extraDatas :HashMap<string, string>) {
const httpInstance = http.createHttp()
const options: http.HttpRequestOptions = {
method: http.RequestMethod.POST,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json',
'sign':this.getSign(extraDatas)
},
extraData:ChangeUtil.map2Json(extraDatas)
}
let fullUrl = this.baseURL + path
return httpInstance.request(fullUrl, options).then((res) => {
logger.info('Response fullUrl:' +fullUrl+ res.result);
const result = res.result as HdResponse<T>
return result
}).catch((err: BusinessError) => {
logger.info(fullUrl+`Response succeeded: ${err}`);
promptAction.showToast({ message: err.message || '网络错误' })
return Promise.reject(err)
}).finally(() => {
httpInstance.destroy()
})
}
private requestafter<T>(path: string, method: http.RequestMethod = http.RequestMethod.GET, extraData?: Object) {
const httpInstance = http.createHttp()
const options: http.HttpRequestOptions = {
method: http.RequestMethod.GET,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json'
}
}
let fullUrl = this.baseURL + path
if (method === http.RequestMethod.GET && extraData) {
const strArr = Object.keys(extraData)
.filter(key => (extraData as HdParams)[key] !== undefined)
.map(key => `${key}=${(extraData as HdParams)[key]}`)
fullUrl += `?${strArr.join('&')}`
} else {
options.extraData = extraData
}
return httpInstance.request(fullUrl, options).then((res) => {
return Promise.reject(res.result)
}).catch((err: BusinessError) => {
logger.error(fullUrl+`Response succeeded: ${err}+${err.name}+${err.message}+${err.data}+${err.stack}`);
// logger.error(fullUrl, err.code?.toString(), err.message)
promptAction.showToast({ message: err.message || '网络错误' })
return Promise.reject(err)
}).finally(() => {
httpInstance.destroy()
})
}
get<T>(url: string, data?: Object): Promise<HdResponse<T>> {
return this.requestafter<T>(url, http.RequestMethod.GET, data)
}
post<T>(url: string, data?: Object): Promise<HdResponse<T>> {
return this.requestafter<T>(url, http.RequestMethod.POST, data)
}
put<T>(url: string, data?: Object): Promise<HdResponse<T>> {
return this.requestafter<T>(url, http.RequestMethod.PUT, data)
}
delete<T>(url: string, data?: Object): Promise<HdResponse<T>> {
return this.requestafter<T>(url, http.RequestMethod.DELETE, data)
}
posts<T>(url: string, data: HashMap<string, string>): Promise<HdResponse<T>> {
return this.request<T>(url, http.RequestMethod.POST, data)
}
httpReq<T>(url: string, datas: HashMap<string, string>): Promise<HdResponse<T>> {
// 创建httpRequest对象。
let httpRequest = http.createHttp();
let url1 = "https://dev-app.igandan.com/app/manager/getSystemTimeStamp";
let promise = httpRequest.request(
// 请求url地址
url1,
{
// 请求方式
method: http.RequestMethod.GET,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json'
}
});
// 处理响应结果。
return promise.then((data) => {
if (data.responseCode === http.ResponseCode.OK) {
logger.info('Response httpReq:' + data.result);
let json:TimestampBean = JSON.parse(data.result.toString()) as TimestampBean;
let tp = json.timestamp;
datas.set("user_uuid", authStore.getUser().uuid?authStore.getUser().uuid:'');
datas.set("client_type", 'A');
datas.set("version",'4.0.0' );
datas.set('timestamp',tp+'');
return this.posts<T>(url, datas);
}
else
{
return this.posts<T>(url, datas);
}
}
).catch((err:BusinessError) => {
logger.info('Response httpReq error:' + JSON.stringify(err));
return Promise.reject(err);
}).finally(() => {
httpRequest.destroy()
})
}
httpReqSimply<T>(url: string) {
// 创建httpRequest对象。
let httpRequest = http.createHttp();
let promise = httpRequest.request(
// 请求url地址
url,
{
// 请求方式
method: http.RequestMethod.POST,
// 可选,默认为60s
connectTimeout: 60000,
// 可选,默认为60s
readTimeout: 60000,
// 开发者根据自身业务需要添加header字段
header: {
'Content-Type': 'application/json'
}
});
// 处理响应结果。
return promise.then((data) => {
logger.info('Response httpReqSimply:' + JSON.stringify(data));
const result = data.result as HdResponse<T>
return result
}
).catch((err:BusinessError) => {
logger.info('Response httpReq error:' + JSON.stringify(err));
return Promise.reject(err);
}).finally(() => {
httpRequest.destroy()
})
}
getSign(extraDatas1:HashMap<string, string>): string {
let secret= extraDatas1.get("timestamp")
if(secret!=null) {
let keyValueStr: string = "";
let entriesArray: Array<string> = Array.from(extraDatas1.keys());
entriesArray.sort();
let sortedMap:HashMap<string, string> = new HashMap();
entriesArray.forEach((value: string, index: number) => {
sortedMap.set(value,extraDatas1.get(value));
keyValueStr +=value+extraDatas1.get(value)
});
keyValueStr = keyValueStr.replace(" ", "");
keyValueStr = keyValueStr + CryptoJS.MD5(secret).toString();
let Md5keyValueStr: string = CryptoJS.MD5(keyValueStr).toString();
let base64Str:string=Base64Util.encodeToStrSync(Md5keyValueStr);
return base64Str;
}
else
{
return '';
}
}
}
export const hdHttp = new HdHttp({ baseURL: '' })
@@ -0,0 +1,83 @@
/**
* 1. 主题设置
* 2. 沉浸式设置
* 3. 通知栏设置
*/
import { ConfigurationConstant } from '@kit.AbilityKit'
import { window } from '@kit.ArkUI'
import { logger } from './logger'
class ThemeManager {
windowStage: window.Window | null = null
async getWindowStage() {
if (this.windowStage) {
return this.windowStage
} else {
return await window.getLastWindow(getContext())
}
}
initThemeSetting() {
const app = getContext().getApplicationContext()
app.on('environment', {
onConfigurationUpdated: (config) => {
logger.info('===', JSON.stringify(config))
if (config.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) {
this.settingStatusBarBlack()
}
if (config.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK) {
this.settingStatusBarWhite()
}
if (config.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET) {
// TODO
}
},
onMemoryLevel: (_level) => {
// TODO
}
})
// 获取应用当前主题
PersistentStorage.persistProp<ConfigurationConstant.ColorMode>('appColorMode',
ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT)
const appColorMode = AppStorage.get<ConfigurationConstant.ColorMode>('appColorMode')
app.setColorMode(appColorMode)
}
settingStatusBarWhite() {
this.settingStatusBar({ statusBarContentColor: '#FFFFFF' })
}
settingStatusBarBlack() {
this.settingStatusBar({ statusBarContentColor: '#000000' })
}
settingStatusBar(config: window.SystemBarProperties) {
this.getWindowStage()
.then((windowStage: window.Window) => {
windowStage.setWindowSystemBarProperties(config)
})
}
enableFullScreen() {
this.getWindowStage()
.then((windowStage: window.Window) => {
windowStage.setWindowLayoutFullScreen(true)
const topArea = windowStage.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)
AppStorage.setOrCreate('topHeight', px2vp(topArea.topRect.height))
const bottomArea = windowStage.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)
AppStorage.setOrCreate('bottomHeight', px2vp(bottomArea.bottomRect.height))
})
}
disableFullScreen() {
this.getWindowStage()
.then((windowStage: window.Window) => {
windowStage.setWindowLayoutFullScreen(false)
AppStorage.setOrCreate('topHeight', 0)
AppStorage.setOrCreate('bottomHeight', 0)
})
}
}
export const themeManager = new ThemeManager()
+11
View File
@@ -0,0 +1,11 @@
{
"module": {
"name": "basic",
"type": "har",
"deviceTypes": [
"default",
"tablet",
"2in1"
]
}
}
@@ -0,0 +1,64 @@
{
"color": [
{
"name": "common_gray_01",
"value": "#222222"
},
{
"name": "common_gray_02",
"value": "#ffbebbb4"
},
{
"name": "common_gray_03",
"value": "#666666"
},
{
"name": "common_gray_bg",
"value": "#f3f4f5"
},
{
"name": "common_gray_border",
"value": "#e8e7ee"
},
{
"name": "common_main_color",
"value": "#FA6D1D"
},
{
"name": "common_green",
"value": "#41B883"
},
{
"name": "common_blue",
"value": "#3266EE"
},
{
"name": "common_blue_bg",
"value": "#EDF2FF"
},
{
"name": "black",
"value": "#131313"
},
{
"name": "white",
"value": "#ffffff"
},
{
"name": "home_gray",
"value": "#EDECF2"
},
{
"name": "top_title",
"value": "#8D2316"
},
{
"name": "top_bg",
"value": "#FFEFEFEF"
},
{
"name": "main_color",
"value": "#923C35"
}
]
}
@@ -0,0 +1,100 @@
{
"float": [
{
"name": "common_border_width",
"value": "0.5vp"
},
{
"name": "common_gutter",
"value": "16vp"
},
{
"name": "navigation_title_font20",
"value": "20fp"
},
{
"name": "common_font14",
"value": "14fp"
},
{
"name": "common_font12",
"value": "12fp"
},
{
"name": "common_font10",
"value": "10fp"
},
{
"name": "common_font8",
"value": "8fp"
},
{
"name": "common_space4",
"value": "4vp"
},
{
"name": "common_space10",
"value": "10vp"
},
{
"name": "common_space16",
"value": "16vp"
},
{
"name": "hd_search_icon_size",
"value": "14vp"
},
{
"name": "hd_search_height",
"value": "32vp"
},
{
"name": "hd_search_radius",
"value": "16vp"
},
{
"name": "hd_clock_font",
"value": "18fp"
},
{
"name": "hd_clock_text_width",
"value": "50vp"
},
{
"name": "hd_clock_width",
"value": "74vp"
},
{
"name": "hd_clock_height",
"value": "28vp"
},
{
"name": "hd_tag_width",
"value": "34vp"
},
{
"name": "hd_tag_height",
"value": "18vp"
},
{
"name": "hd_tag_radius",
"value": "2vp"
},
{
"name": "hd_list_load_height",
"value": "80vp"
},
{
"name": "hd_list_load_font",
"value": "14fp"
},
{
"name": "hd_list_load_icon",
"value": "24vp"
},
{
"name": "page_text_font_size",
"value": "50fp"
}
]
}
@@ -0,0 +1,40 @@
{
"string": [
{
"name": "hd_search_placeholder",
"value": "搜索题目"
},
{
"name": "hd_clock_continue",
"value": "已连续打卡"
},
{
"name": "hd_clock_day",
"value": " 天"
},
{
"name": "hd_tag_simple",
"value": "简单"
},
{
"name": "hd_tag_general",
"value": "一般"
},
{
"name": "hd_tag_difficult",
"value": "困难"
},
{
"name": "hd_list_loading",
"value": "加载中..."
},
{
"name": "hd_list_finished",
"value": "没有更多了~"
},
{
"name": "hd_clock_in",
"value": "打卡"
}
]
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24" version="1.1">
<title>Public/ic_public_back</title>
<defs>
<path d="M5.31079777,13.7499686 L11.2803301,19.7196699 L11.3140714,19.7556673 C11.5727547,20.0502619 11.5615076,20.4991526 11.2803301,20.7803301 C10.9991526,21.0615076 10.5502619,21.0727547 10.2556673,20.8140714 L10.2196699,20.7803301 L3.18929777,13.7499686 L5.31079777,13.7499686 Z M11.2803301,3.21966991 C11.5615076,3.5008474 11.5727547,3.94973814 11.3140714,4.24433269 L11.2803301,4.28033009 L4.3105,11.25 L21,11.25 C21.3994202,11.25 21.7259152,11.56223 21.7487268,11.9559318 L21.75,12 C21.75,12.3994202 21.43777,12.7259152 21.0440682,12.7487268 L21,12.75 L3.10355339,12.75 C2.8383369,12.75 2.58398299,12.6446432 2.39644661,12.4571068 C2.01893979,12.0796 2.00635623,11.4753589 2.35869593,11.0827365 L2.39644661,11.0428932 L10.2196699,3.21966991 C10.5125631,2.9267767 10.9874369,2.9267767 11.2803301,3.21966991 Z" id="_path-1"/>
</defs>
<g id="_Public/ic_public_back" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<mask id="_mask-2" fill="white">
<use xlink:href="#_path-1"/>
</mask>
<use id="_形状结合" fill="#000000" fill-rule="nonzero" xlink:href="#_path-1"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 KiB

@@ -0,0 +1,35 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function abilityTest() {
describe('ActsAbilityTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
})
})
}
@@ -0,0 +1,5 @@
import abilityTest from './Ability.test';
export default function testsuite() {
abilityTest();
}
+13
View File
@@ -0,0 +1,13 @@
{
"module": {
"name": "basic_test",
"type": "feature",
"deviceTypes": [
"default",
"tablet",
"2in1"
],
"deliveryWithInstall": true,
"installationFree": false
}
}
+5
View File
@@ -0,0 +1,5 @@
import localUnitTest from './LocalUnit.test';
export default function testsuite() {
localUnitTest();
}
+33
View File
@@ -0,0 +1,33 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function localUnitTest() {
describe('localUnitTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
});
});
}