优化结构
This commit is contained in:
parent
04aebbe02d
commit
1e18d932f8
@ -3,7 +3,7 @@ import hilog from '@ohos.hilog';
|
|||||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
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/system';
|
import { requestPermission } from '../utils/SystemUtils';
|
||||||
|
|
||||||
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 {
|
||||||
|
|||||||
@ -68,12 +68,12 @@ struct Home {
|
|||||||
// router.pushUrl({
|
// router.pushUrl({
|
||||||
// url: "pages/ProjectCheck"
|
// url: "pages/ProjectCheck"
|
||||||
// }, router.RouterMode.Single)
|
// }, router.RouterMode.Single)
|
||||||
// router.pushUrl({
|
|
||||||
// url: "pages/Scan"
|
|
||||||
// }, router.RouterMode.Single)
|
|
||||||
router.pushUrl({
|
router.pushUrl({
|
||||||
url: "pages/Sign"
|
url: "pages/Scan"
|
||||||
}, router.RouterMode.Single)
|
}, router.RouterMode.Single)
|
||||||
|
// router.pushUrl({
|
||||||
|
// url: "pages/Sign"
|
||||||
|
// }, router.RouterMode.Single)
|
||||||
})
|
})
|
||||||
}.width("100%")
|
}.width("100%")
|
||||||
}.layoutWeight(1).padding({ left: "36%", right: "36%", top: "10%" })
|
}.layoutWeight(1).padding({ left: "36%", right: "36%", top: "10%" })
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { CameraUtils } from '../utils/cameraUtils';
|
import { CameraUtils } from '../utils/CameraUtils';
|
||||||
import Header from '../components/Header';
|
import Header from '../components/Header';
|
||||||
import Footer from '../components/Footer';
|
import Footer from '../components/Footer';
|
||||||
import common from '@ohos.app.ability.common';
|
import common from '@ohos.app.ability.common';
|
||||||
@ -6,17 +6,17 @@ import common from '@ohos.app.ability.common';
|
|||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct Scan {
|
struct Scan {
|
||||||
@State showVideo: boolean = false
|
@State showVideo: boolean = true
|
||||||
private xComponentController: XComponentController = new XComponentController()
|
private xComponentController: XComponentController = new XComponentController()
|
||||||
private cameraUtils: CameraUtils = new CameraUtils(getContext(this) as common.UIAbilityContext)
|
private cameraUtils?: CameraUtils
|
||||||
private surfaceId: string = ""
|
private surfaceId: string = ""
|
||||||
|
|
||||||
aboutToAppear(): void {
|
aboutToAppear(): void {
|
||||||
|
this.cameraUtils = new CameraUtils(getContext(this) as common.UIAbilityContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
aboutToDisappear(): void {
|
aboutToDisappear(): void {
|
||||||
this.cameraUtils.destroy()
|
this.cameraUtils?.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
@ -31,8 +31,8 @@ struct Scan {
|
|||||||
controller: this.xComponentController
|
controller: this.xComponentController
|
||||||
}).onLoad(() => {
|
}).onLoad(() => {
|
||||||
this.surfaceId = this.xComponentController.getXComponentSurfaceId()
|
this.surfaceId = this.xComponentController.getXComponentSurfaceId()
|
||||||
this.cameraUtils.init(this.surfaceId).then(() => {
|
this.cameraUtils?.init(this.surfaceId).then(() => {
|
||||||
this.cameraUtils.startPreview()
|
this.cameraUtils?.startPreview()
|
||||||
})
|
})
|
||||||
}).width("100%").height("100%").renderFit(RenderFit.RESIZE_CONTAIN)
|
}).width("100%").height("100%").renderFit(RenderFit.RESIZE_CONTAIN)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -52,33 +52,38 @@ struct Sign {
|
|||||||
Header()
|
Header()
|
||||||
Column() {
|
Column() {
|
||||||
Text("车主签名").fontSize(32).fontColor(0x161B21).fontWeight(700).margin({ top: 36, bottom: 36 })
|
Text("车主签名").fontSize(32).fontColor(0x161B21).fontWeight(700).margin({ top: 36, bottom: 36 })
|
||||||
Canvas(this.context)
|
if (this.base64) {
|
||||||
.backgroundColor(0xffffff)
|
Image(this.base64).layoutWeight(1).width("100%")
|
||||||
.layoutWeight(1)
|
} else {
|
||||||
.width("100%")
|
Canvas(this.context)
|
||||||
.onReady(() => {
|
.backgroundColor(0xffffff)
|
||||||
this.isReady = true
|
.layoutWeight(1)
|
||||||
this.context.fillStyle = "#ffffff"
|
.width("100%")
|
||||||
this.context.fillRect(0, 0, this.context.width, this.context.height)
|
.onReady(() => {
|
||||||
})
|
this.isReady = true
|
||||||
.onTouch(event => {
|
this.context.fillStyle = "#ffffff"
|
||||||
switch (event.type) {
|
this.context.fillRect(0, 0, this.context.width, this.context.height)
|
||||||
case TouchType.Down:
|
})
|
||||||
this.onStart(event)
|
.onTouch(event => {
|
||||||
break
|
switch (event.type) {
|
||||||
case TouchType.Up:
|
case TouchType.Down:
|
||||||
this.onStop(event)
|
this.onStart(event)
|
||||||
break
|
break
|
||||||
case TouchType.Move:
|
case TouchType.Up:
|
||||||
this.onMove(event)
|
this.onStop(event)
|
||||||
break
|
break
|
||||||
case TouchType.Cancel:
|
case TouchType.Move:
|
||||||
this.onStop(event)
|
this.onMove(event)
|
||||||
break
|
break
|
||||||
default:
|
case TouchType.Cancel:
|
||||||
return
|
this.onStop(event)
|
||||||
}
|
break
|
||||||
})
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
Row() {
|
Row() {
|
||||||
CusButton({ label: "确认", buttonType: CusButtonType.Primary }).margin({ right: 12 }).onClick(() => {
|
CusButton({ label: "确认", buttonType: CusButtonType.Primary }).margin({ right: 12 }).onClick(() => {
|
||||||
this.submit()
|
this.submit()
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import common from '@ohos.app.ability.common'
|
import common from '@ohos.app.ability.common';
|
||||||
import fs from '@ohos.file.fs';
|
import fs from '@ohos.file.fs';
|
||||||
import zlib from '@ohos.zlib';
|
import zlib from '@ohos.zlib';
|
||||||
|
|
||||||
101
entry/src/main/ets/utils/TcpUtils.ets
Normal file
101
entry/src/main/ets/utils/TcpUtils.ets
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import socket from '@ohos.net.socket'
|
||||||
|
import util from '@ohos.util'
|
||||||
|
import { BusinessError } from '@ohos.base'
|
||||||
|
|
||||||
|
interface TcpClientOption {
|
||||||
|
address: string
|
||||||
|
port: number
|
||||||
|
maxReconnectCount?: number
|
||||||
|
timeout?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
type Callback<T = string | BusinessError | void> = (message: T) => void
|
||||||
|
|
||||||
|
type EventType = "message" | "error"
|
||||||
|
|
||||||
|
|
||||||
|
class TcpClient {
|
||||||
|
private socket: socket.TCPSocket
|
||||||
|
private address: string
|
||||||
|
private port: number
|
||||||
|
private maxReconnectCount: number
|
||||||
|
private timeout: number
|
||||||
|
private messageCallback: Map<EventType, Callback[]> = new Map()
|
||||||
|
|
||||||
|
constructor(option?: TcpClientOption) {
|
||||||
|
this.messageCallback.set("message", [])
|
||||||
|
this.messageCallback.set("error", [])
|
||||||
|
this.address = option.address
|
||||||
|
this.port = option.port
|
||||||
|
this.maxReconnectCount = option.maxReconnectCount || 5
|
||||||
|
this.timeout = option.timeout || 1000 * 6
|
||||||
|
this.socket = socket.constructTCPSocketInstance()
|
||||||
|
}
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
return this.socket.connect({
|
||||||
|
address: {
|
||||||
|
address: this.address,
|
||||||
|
port: this.port
|
||||||
|
},
|
||||||
|
timeout: this.timeout
|
||||||
|
}).then(() => {
|
||||||
|
this.socket.on("message", (data) => {
|
||||||
|
let string = util.TextDecoder.create().decodeWithStream(new Uint8Array(data.message))
|
||||||
|
this.messageCallback.get("message").forEach(cb => {
|
||||||
|
cb(string)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
this.socket.on("error", (error) => {
|
||||||
|
this.messageCallback.get("error").forEach(cb => {
|
||||||
|
cb(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
reconnect() {
|
||||||
|
this.socket.close()
|
||||||
|
this.socket = socket.constructTCPSocketInstance()
|
||||||
|
this.connect()
|
||||||
|
}
|
||||||
|
|
||||||
|
on(event: EventType, cb: Callback) {
|
||||||
|
switch (event) {
|
||||||
|
case "message":
|
||||||
|
this.messageCallback.get("message")!.push(cb)
|
||||||
|
break;
|
||||||
|
case "error":
|
||||||
|
this.messageCallback.get("error")!.push(cb)
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
off(event: EventType, cb: Callback) {
|
||||||
|
let index: number
|
||||||
|
switch (event) {
|
||||||
|
case "message":
|
||||||
|
index = this.messageCallback.get("message")!.findIndex(item => item === cb)
|
||||||
|
this.messageCallback.get("message")!.splice(index, 1)
|
||||||
|
break;
|
||||||
|
case "error":
|
||||||
|
index = this.messageCallback.get("error")!.findIndex(item => item === cb)
|
||||||
|
this.messageCallback.get("error")!.splice(index, 1)
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send(data: string | ArrayBuffer) {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
this.socket.send({ data }).then(resolve).catch((err: BusinessError) => {
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.socket.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 274 KiB |
Loading…
x
Reference in New Issue
Block a user