This commit is contained in:
lixiao 2025-07-29 14:32:48 +08:00
parent e79100d770
commit 64d657f784
8 changed files with 127 additions and 55 deletions

View File

@ -8,6 +8,7 @@ import promptAction from '@ohos.promptAction';
export default struct Exiting { export default struct Exiting {
@State showVideo: boolean = false @State showVideo: boolean = false
@State base64: string = "" @State base64: string = ""
public title: string = "提示"
private controller: CustomDialogController private controller: CustomDialogController
private xComponentController: XComponentController = new XComponentController() private xComponentController: XComponentController = new XComponentController()
private cameraUtils: CameraUtils = new CameraUtils(getContext(this) as common.UIAbilityContext) private cameraUtils: CameraUtils = new CameraUtils(getContext(this) as common.UIAbilityContext)
@ -15,17 +16,13 @@ export default struct Exiting {
private loading: boolean = false private loading: boolean = false
public onSubmit?: (base64: string) => void public onSubmit?: (base64: string) => void
async aboutToDisappear(): Promise<void> {
this.cameraUtils.stopPreview()
await this.cameraUtils.destroy()
}
build() { build() {
Column() { Column() {
Row() { Flex({ justifyContent: FlexAlign.SpaceBetween }) {
Text().width(18)
Text("提示").fontSize(28).fontColor(0xffffff) Text("提示").fontSize(28).fontColor(0xffffff)
Blank() Text().width(18)
Image($rawfile("img/close.png")).width(18) // Image($rawfile("img/close.png")).width(18)
} }
.width("100%") .width("100%")
.linearGradient({ .linearGradient({
@ -60,7 +57,9 @@ export default struct Exiting {
buttonType: CusButtonType.Info buttonType: CusButtonType.Info
}) })
.margin({ right: 6 }) .margin({ right: 6 })
.onClick(() => { .onClick(async () => {
this.cameraUtils.stopPreview()
await this.cameraUtils.destroy()
this.controller.close() this.controller.close()
}) })
CusButton({ CusButton({
@ -82,7 +81,7 @@ export default struct Exiting {
message: JSON.stringify(e) message: JSON.stringify(e)
}) })
}).finally(() => { }).finally(() => {
this.loading = true this.loading = false
}) })
}) })
} else { } else {
@ -100,7 +99,8 @@ export default struct Exiting {
buttonType: CusButtonType.Primary buttonType: CusButtonType.Primary
}) })
.margin({ left: 6 }) .margin({ left: 6 })
.onClick(() => { .onClick(async () => {
await this.cameraUtils.stopPreview()
this.cameraUtils.destroy() this.cameraUtils.destroy()
this.onSubmit?.(this.base64) this.onSubmit?.(this.base64)
}) })

View File

@ -15,10 +15,11 @@ export default struct TipDialog {
build() { build() {
Column() { Column() {
Row() { Flex({ justifyContent: FlexAlign.SpaceBetween }) {
Text().width(18)
Text("提示").fontSize(28).fontColor(0xffffff) Text("提示").fontSize(28).fontColor(0xffffff)
Blank() Text().width(18)
Image($rawfile("img/close.png")).width(18) // Image($rawfile("img/close.png")).width(18)
} }
.width("100%") .width("100%")
.linearGradient({ .linearGradient({

View File

@ -4,13 +4,10 @@ import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want'; import Want from '@ohos.app.ability.Want';
import window from '@ohos.window'; import window from '@ohos.window';
import { requestPermission } from '../utils/SystemUtils'; import { requestPermission } from '../utils/SystemUtils';
import Logger, { LoggerLevel } from '../utils/Logger'; import Logger, { LoggerLevel, LoggerMode } from '../utils/Logger';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(_want: Want, _launchParam: AbilityConstant.LaunchParam): void { onCreate(_want: Want, _launchParam: AbilityConstant.LaunchParam): void {
Logger.init({
level: LoggerLevel.Debug
})
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
} }
@ -20,11 +17,16 @@ export default class EntryAbility extends UIAbility {
async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> { async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
let window = await windowStage.getMainWindow() let window = await windowStage.getMainWindow()
window.setWindowSystemBarEnable(["status"]) window.setWindowSystemBarEnable(["status"])
window.setWindowLayoutFullScreen(true) window.setWindowLayoutFullScreen(true)
requestPermission(this.context, ['ohos.permission.CAMERA', 'ohos.permission.FILE_ACCESS_MANAGER']) requestPermission(this.context, ['ohos.permission.CAMERA', "ohos.permission.READ_IMAGEVIDEO", 'ohos.permission.READ_MEDIA', 'ohos.permission.WRITE_MEDIA', 'ohos.permission.FILE_ACCESS_MANAGER'])
.then(() => { .then(() => {
Logger.init({
level: LoggerLevel.Debug,
mode: LoggerMode.Production
})
windowStage.loadContent('pages/Login', (err) => { windowStage.loadContent('pages/Login', (err) => {
if (err.code) { if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');

View File

@ -1,10 +1,57 @@
import Footer from '../components/Footer' import Footer from '../components/Footer'
import window from '@ohos.window'
import Header from '../components/Header' import Header from '../components/Header'
interface ProjectItem {
name: string
value?: string
picture?: string
}
interface Project {
name: string
items: Array<ProjectItem>
}
const Projects: Array<Project> = [
{
name: "左前45°查验项目",
items: [{ name: "车身颜色" }, { name: "车辆外观" }, { name: "号牌板" }, { name: "车辆品牌" }]
},
{
name: "右后45°查验项目",
items: [{ name: "车身颜色" }, { name: "车辆外观" }, { name: "车辆品牌" }, { name: "反光背心" }, { name: "三脚架" }]
},
{
name: "轮胎规格查验项目",
items: [{ name: "轮胎规格" }, { name: "轮胎规格" }, { name: "轮胎规格" }, { name: "轮胎规格" }]
},
{
name: "车辆喷涂查验项目",
items: [{ name: "总质量" }, { name: "栏板高度" }, { name: "核定载人数" }]
},
{
name: "车辆铭牌查验项目",
items: [{ name: "品牌" }, { name: "栏板高度" }, { name: "生产日期" }, { name: "车辆识别代号" }, {
name: "生产厂家"
}]
},
{
name: "车辆铭牌查验项目",
items: [{ name: "车辆识别代号" }]
},
{
name: "发动机号查验项目",
items: [{ name: "发动机号" }]
},
]
@Entry @Entry
@Component @Component
struct ProjectCheck { struct ProjectCheck {
@State projects: Array<Project> = Projects
@State current: number = 0
aboutToAppear(): void { aboutToAppear(): void {
} }
@ -13,10 +60,17 @@ struct ProjectCheck {
Column() { Column() {
Header() Header()
Row() { Row() {
Image($rawfile('img/check/scan.png')).layoutWeight(1).margin({ right: 32 }).height("100%") Image($rawfile('img/check/background.png')).layoutWeight(1).margin({ right: 32 }).height("100%")
Column() { Column() {
Text(this.projects[this.current].name).fontSize(36).fontColor(0x161B21).fontWeight(700).margin({ bottom: 64 })
}.width("33%") Text("识别结果").fontSize(24).fontColor(0x161B21).fontWeight(700).margin({ bottom: 30 })
ForEach(this.projects[this.current].items, (item: ProjectItem) => {
RowSplit() {
Text(item.name).width("16%").fontWeight(700).fontSize(18).fontColor(0x161B21)
Text(item.value).layoutWeight(1).fontSize(18).fontColor(0x102A9A).padding({ left: 20 })
}.resizeable(false).borderColor(0xAEC4E8).margin({ bottom: 12 })
})
}.width("33%").height("100%").alignItems(HorizontalAlign.Start).justifyContent(FlexAlign.Start)
}.layoutWeight(1).width("100%").padding({ left: 32, top: 40, right: 32, bottom: 40 }).backgroundColor(0xd7ebfd) }.layoutWeight(1).width("100%").padding({ left: 32, top: 40, right: 32, bottom: 40 }).backgroundColor(0xd7ebfd)
Footer() Footer()

View File

@ -1,6 +1,7 @@
import Footer from '../components/Footer' import Footer from '../components/Footer'
import Header from '../components/Header' import Header from '../components/Header'
import TakePhotoDialog from '../components/TakePhotoDialog' import TakePhotoDialog from '../components/TakePhotoDialog'
import router from '@ohos.router'
@Entry @Entry
@Component @Component
@ -10,6 +11,9 @@ struct Waiting {
onSubmit: (base64: string) => { onSubmit: (base64: string) => {
AppStorage.setOrCreate("photo1", base64) AppStorage.setOrCreate("photo1", base64)
this.controller.close() this.controller.close()
router.pushUrl({
url: "pages/ProjectCheck"
})
} }
}), }),
customStyle: true, customStyle: true,
@ -36,7 +40,7 @@ struct Waiting {
Text("完成上述内容后点击屏幕") Text("完成上述内容后点击屏幕")
.fontColor(0x3F4042) .fontColor(0x3F4042)
.fontSize(32) .fontSize(32).margin({ top: 12 })
} }
} }

View File

@ -8,9 +8,9 @@ interface LoggerOption {
} }
export enum LoggerLevel { export enum LoggerLevel {
Info,
Warn,
Error, Error,
Warn,
Info,
Debug Debug
} }
@ -20,8 +20,9 @@ export enum LoggerMode {
} }
const MB = 1024 * 1024 const MB = 1024 * 1024
const PATH = "/data/log/duolun/log" const DuolunPath = '/mnt/hmdfs/100/account/device_view/local/files/duolun'
const TAG = "Logger" const LogPath = "/mnt/hmdfs/100/account/device_view/local/files/duolun/logs"
const Tag = "Logger"
function formatDate(date: Date, fmt = 'yyyy-MM-dd') { function formatDate(date: Date, fmt = 'yyyy-MM-dd') {
date = date instanceof Date ? date : new Date(date); date = date instanceof Date ? date : new Date(date);
@ -55,7 +56,6 @@ function pathJoin(...path: string[]) {
return path.join("/") return path.join("/")
} }
export default class Logger { export default class Logger {
private static mode: LoggerMode = LoggerMode.Development private static mode: LoggerMode = LoggerMode.Development
private static level: LoggerLevel = LoggerLevel.Info private static level: LoggerLevel = LoggerLevel.Info
@ -65,21 +65,33 @@ export default class Logger {
private static fd: number = 0 private static fd: number = 0
private static createDir() { private static createDir() {
if (!fs.accessSync(PATH)) { try {
fs.mkdirSync(PATH) if (!fs.accessSync(DuolunPath)) {
} fs.mkdirSync(DuolunPath)
if (!fs.accessSync(pathJoin(PATH, Logger.date))) { }
fs.mkdirSync(pathJoin(PATH, Logger.date)) if (!fs.accessSync(LogPath)) {
fs.mkdirSync(LogPath)
}
let path = pathJoin(LogPath, Logger.date)
if (!fs.accessSync(path)) {
fs.mkdirSync(path)
}
} catch (e) {
hilog.error(0x0000, Tag, JSON.stringify(e))
} }
} }
private static createNewFile() { private static createNewFile() {
Logger.date = formatDate(new Date(), "yyyy_MM_dd") try {
Logger.time = formatDate(new Date(), "HH_mm_ss.SSS") Logger.date = formatDate(new Date(), "yyyy_MM_dd")
let path = pathJoin(PATH, Logger.date, Logger.time, "log") Logger.time = formatDate(new Date(), "HH_mm_ss.SSS")
if (!fs.accessSync(path)) { let path = pathJoin(LogPath, Logger.date, Logger.time) + ".log"
let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.APPEND | fs.OpenMode.WRITE_ONLY) if (!fs.accessSync(path)) {
Logger.fd = file.fd let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.APPEND | fs.OpenMode.WRITE_ONLY)
Logger.fd = file.fd
}
} catch (e) {
hilog.error(0x0000, Tag, JSON.stringify(e))
} }
} }
@ -87,14 +99,14 @@ export default class Logger {
if (type > Logger.level) { if (type > Logger.level) {
return return
} }
const map = ["info", "warn", "error", "debug"] const map = ["error", "warn", "info", "debug"]
if (Logger.mode === LoggerMode.Development) { if (Logger.mode === LoggerMode.Development) {
hilog.debug(0x0000, TAG, `${map[type]} start`) hilog.debug(0x0000, Tag, `${map[type]} start`)
let resultMessage = message.join(" ") let resultMessage = message.join(" ")
for (let i = 0; i < resultMessage.length; i + 100) { for (let i = 0; i < resultMessage.length; i += 200) {
hilog.debug(0x0000, TAG, resultMessage.slice(i, i + 100)) hilog.debug(0x0000, Tag, resultMessage.slice(i, i + 200))
} }
hilog.debug(0x0000, TAG, `${map[type]} end`) hilog.debug(0x0000, Tag, `${map[type]} end`)
} else { } else {
try { try {
if (fs.statSync(Logger.fd).size >= Logger.size) { if (fs.statSync(Logger.fd).size >= Logger.size) {
@ -102,17 +114,19 @@ export default class Logger {
} }
fs.writeSync(Logger.fd, `[${formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")}]-[${map[type]}]: ${message.join(" ")}\n`) fs.writeSync(Logger.fd, `[${formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")}]-[${map[type]}]: ${message.join(" ")}\n`)
} catch (e) { } catch (e) {
hilog.error(0x0000, TAG, JSON.stringify(e)) hilog.error(0x0000, Tag, JSON.stringify(e))
} }
} }
} }
static init(option?: LoggerOption) { static init(option?: LoggerOption) {
Logger.level = option.level || LoggerLevel.Info Logger.level = option?.level || LoggerLevel.Info
Logger.size = option.size || MB * 10 Logger.size = option?.size || MB * 10
Logger.mode = option.mode || LoggerMode.Development Logger.mode = option?.mode || LoggerMode.Development
Logger.createDir() if (Logger.mode === LoggerMode.Production) {
Logger.createNewFile() Logger.createDir()
Logger.createNewFile()
}
} }
static info(...message: string[]) { static info(...message: string[]) {

View File

@ -43,9 +43,6 @@
{ {
"name": "ohos.permission.FILE_ACCESS_MANAGER" "name": "ohos.permission.FILE_ACCESS_MANAGER"
}, },
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC",
},
{ {
"name": "ohos.permission.STORAGE_MANAGER" "name": "ohos.permission.STORAGE_MANAGER"
}, },
@ -78,7 +75,7 @@
}, },
{ {
"name": "ohos.permission.sec.ACCESS_UDID" "name": "ohos.permission.sec.ACCESS_UDID"
} },
] ]
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB