fix: 优化一些公共方法
This commit is contained in:
parent
163793b5b1
commit
3999e1d32b
@ -43,8 +43,7 @@ import {
|
||||
} from '../model';
|
||||
import { GetSyncData } from '../utils/table/Operation';
|
||||
import dayTs from '../utils/Date';
|
||||
import { GetCurrentTime } from '../utils/Common';
|
||||
import { chunkArr } from './judgeSDK/utils/Common';
|
||||
import { CutArray, GetCurrentTime } from '../utils/Common';
|
||||
import FileUtils from '../utils/FileUtils';
|
||||
|
||||
|
||||
@ -812,7 +811,7 @@ struct Index {
|
||||
if (this.examSubject == "2") {
|
||||
Flex({ wrap: FlexWrap.Wrap, direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween }) {
|
||||
List({}) {
|
||||
ForEach(chunkArr(this.projects, 2), (item: [ProjectInfo, ProjectInfo]) => {
|
||||
ForEach(CutArray(this.projects, 2), (item: [ProjectInfo, ProjectInfo]) => {
|
||||
ListItem() {
|
||||
Row() {
|
||||
Row() {
|
||||
|
||||
@ -9,7 +9,7 @@ import FileModel from './utils/fileModel';
|
||||
import FilePhoto from './utils/filePhoto';
|
||||
import FileLog from './utils/fileLog';
|
||||
import JudgeTask from './utils/judgeTask';
|
||||
import { JudgeConfig } from "../../config";
|
||||
import { JudgeConfig } from '../../config';
|
||||
import { LANE } from '../judgeSDK/api/judgeSDK.d';
|
||||
import { GetSyncData, SqlInsertTable } from '../../utils/table/Operation';
|
||||
|
||||
@ -33,8 +33,8 @@ import {
|
||||
import { uploadExamProgressData, writeObjectOut } from '../../api/judge';
|
||||
import { endRecordVideo, saveStartRecordVideo } from '../../utils/Video';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { convertGpsCoord2, deepClone } from './utils/Common';
|
||||
import { GetCurrentTime } from '../../utils/Common';
|
||||
|
||||
import { ConvertDdmmToDecimalDegrees, GetCurrentTime,DeepClone } from '../../utils/Common';
|
||||
import UsbService from '../../utils/USB';
|
||||
import FileUtils from '../../utils/FileUtils';
|
||||
import {
|
||||
@ -49,7 +49,6 @@ import {
|
||||
JudgeCallBackData,
|
||||
JudgeConfigObj,
|
||||
JudgeConfigObjKmItems,
|
||||
JudgeEventKf,
|
||||
JudgeInitObj,
|
||||
JudgeKFXM,
|
||||
JudgeKSJS,
|
||||
@ -264,8 +263,8 @@ export default class Judge {
|
||||
handDistance = async () => {
|
||||
const dwzt = this.tempData?.gps?.dwzt || "";
|
||||
const jdzt = this.tempData?.gps?.jdzt || "";
|
||||
const tJD = convertGpsCoord2(this.tempData?.gps?.jd || 0)
|
||||
const tWD = convertGpsCoord2(this.tempData?.gps?.wd || 0)
|
||||
const tJD = ConvertDdmmToDecimalDegrees(this.tempData?.gps?.jd || 0)
|
||||
const tWD = ConvertDdmmToDecimalDegrees(this.tempData?.gps?.wd || 0)
|
||||
if (this.prevJd && dwzt == 4 && jdzt == 3) {
|
||||
const distance = await examCalcGpsDistance({
|
||||
jd1: this.prevJd,
|
||||
@ -1052,7 +1051,7 @@ export default class Judge {
|
||||
//更新UI
|
||||
if (event == 1 || event == 2 || event == 3 || event == 6) {
|
||||
const copyProjectsObj: object = this.judgeUI.projectsObj;
|
||||
judgeUI.projectsObj = deepClone(copyProjectsObj);
|
||||
judgeUI.projectsObj = DeepClone(copyProjectsObj);
|
||||
}
|
||||
}
|
||||
// 更改考试状态
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
// 根据指定个数分割数组
|
||||
export function chunkArr<T>(arr: T[], size: number): T[][] {
|
||||
//判断如果不是数组(就没有length),或者size没有传值,size小于1,就返回空数组
|
||||
if (!arr.length || !size || size < 1) {
|
||||
return []
|
||||
}
|
||||
let start = 0
|
||||
let end = 0
|
||||
let result: T[][] = []
|
||||
for (let i = 0; i < Math.ceil(arr.length / size); i++) {
|
||||
start = i * size
|
||||
end = start + size
|
||||
result.push(arr.slice(start, end))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
//对象深拷贝
|
||||
export function deepClone<T extends Object>(target: T): T {
|
||||
// 如果是对象,且不是原始值null
|
||||
if (typeof target === 'object' && target !== null) {
|
||||
// 创建容器
|
||||
const result: ESObject = Array.isArray(target) ? [] : {};
|
||||
const keys = Object.keys(target) as Array<keyof T>; //注解二
|
||||
keys.forEach(key => {
|
||||
Reflect.set(result, key, deepClone(Reflect.get(target, key)));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
// 如果是原始值,则直接返回
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
//经纬度转换
|
||||
export function convertGpsCoord2(num: number): number {
|
||||
const tempNum = Math.floor(num);
|
||||
const du = Math.floor(tempNum / 100);
|
||||
const fen = tempNum % 100 + num - tempNum;
|
||||
return du + fen / 60
|
||||
}
|
||||
@ -96,6 +96,12 @@ export function NumberToByteArray(number: number | string, len: number): number[
|
||||
return arrBytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* 将字符串填充为指定长度的字符串,前面补0
|
||||
* @param str 要填充的字符串或数字
|
||||
* @param len 目标长度
|
||||
* @return 返回填充后的字符串
|
||||
*/
|
||||
export function FillZero(str: string | number, len: number): string {
|
||||
str = str.toString();
|
||||
if (str.length >= len || len <= 0) {
|
||||
@ -104,3 +110,49 @@ export function FillZero(str: string | number, len: number): string {
|
||||
const zeroStr = '0'.repeat(len - str.length);
|
||||
return zeroStr + str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数组按指定大小分块
|
||||
* @param arr 原始数组
|
||||
* @param size 每块大小(必须 >= 1)
|
||||
* @returns 分块后的二维数组
|
||||
*/
|
||||
export function CutArray<T>(arr: readonly T[], size: number): T[][] {
|
||||
if (!Array.isArray(arr) || size < 1) return [];
|
||||
|
||||
const result: T[][] = [];
|
||||
for (let i = 0; i < arr.length; i += size) {
|
||||
result.push(arr.slice(i, i + size));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将GPS坐标从度分格式(DDMM.MMMM)转换为十进制度格式
|
||||
* @param ddmm - 度分格式坐标(例如 11630.1234 表示116度30.1234分)
|
||||
* @returns 十进制度格式坐标(例如 116.502056666...)
|
||||
*/
|
||||
export function ConvertDdmmToDecimalDegrees(ddmm: number): number {
|
||||
// 提取度数部分:除以100后取整
|
||||
const degrees = Math.floor(ddmm / 100);
|
||||
// 提取分数部分(包含小数):对100取模
|
||||
const minutes = ddmm % 100;
|
||||
// 将分数转换为度并相加:1度=60分
|
||||
return degrees + minutes / 60;
|
||||
}
|
||||
|
||||
//对象深拷贝
|
||||
export function DeepClone<T extends Object>(target: T): T {
|
||||
// 如果是对象,且不是原始值null
|
||||
if (typeof target === 'object' && target !== null) {
|
||||
// 创建容器
|
||||
const result: ESObject = Array.isArray(target) ? [] : {};
|
||||
const keys = Object.keys(target) as Array<keyof T>; //注解二
|
||||
keys.forEach(key => {
|
||||
Reflect.set(result, key, DeepClone(Reflect.get(target, key)));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
// 如果是原始值,则直接返回
|
||||
return target;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user