Переглянути джерело

手写签名完成

master
徐勤民 3 тижднів тому
джерело
коміт
b042a5fb77
6 змінених файлів з 137 додано та 66 видалено
  1. +15
    -0
      src/main/ets/bean/data/UploadStampData.ets
  2. +19
    -0
      src/main/ets/http/ApiConfig.ets
  3. +1
    -1
      src/main/ets/manager/CaManagerReal.ets
  4. +96
    -64
      src/main/ets/pages/EditDrawStamp.ets
  5. +1
    -1
      src/main/ets/public/CaManager.ets
  6. +5
    -0
      src/main/ets/public/callBack/BJCACallMsg.ets

+ 15
- 0
src/main/ets/bean/data/UploadStampData.ets Переглянути файл

@@ -0,0 +1,15 @@
export class UploadStampData {
clientList: string[]
userId: string
openId: string
stampBase64: string

constructor(clientList: string[], userId: string, openId: string, stampBase64: string) {
this.clientList = clientList
this.userId = userId
this.openId = openId
this.stampBase64 = stampBase64
}


}

+ 19
- 0
src/main/ets/http/ApiConfig.ets Переглянути файл

@@ -104,6 +104,7 @@ export const sureSignForSignAuto: ApiElem = {
apiNo: 'sureSignForSignAuto',
url: 'am/v3/selfSign/authorize/sure'
}

/**
* 停止自动签名(托管证书方式)
*/
@@ -111,6 +112,7 @@ export const getSignAutoQuit: ApiElem = {
apiNo: 'getSignAutoQuit',
url: 'am/v3/selfSign/quit'
}

/**
* 获取自动签信息
*/
@@ -119,6 +121,23 @@ export const getSignAutoInfo: ApiElem = {
url: 'am/v3/selfSign/getSelfSignInfo'
}

const uploadStampPicForDoctor: ApiElem = {
apiNo: 'getUserInfoForDoctor',
url: 'am/v3/doctor/stamp/bind'
}

const uploadStampPicForMass: ApiElem = {
apiNo: 'getUserInfoForMass',
url: 'am/v3/userCenter/user/setHeadImage'
}

/**
* 上传签章图片
*/
export const uploadStampPic = (): ApiElem => {
return GlobalValue.getInstance().certEnvType === CertEnvType.MASS ? uploadStampPicForDoctor : uploadStampPicForDoctor
}






+ 1
- 1
src/main/ets/manager/CaManagerReal.ets Переглянути файл

@@ -191,7 +191,7 @@ export class CaManagerReal {
* @param phone
* @param listener BJCACallMsg.(NOT_CLIENT|NOT_PHONE|ROUTER|SUCCESS|CANCEL|CERT_NOT_EXISTS|ERROR_CERT_INFO)
*/
public static drawStamp(phone: string, listener: (result: CallBackMsg) => void) {
public static drawStamp(phone: string, listener: (result: CallBackForData<string>) => void) {
if (!BackManager.get().checkParams(phone, listener)) {
return
}


+ 96
- 64
src/main/ets/pages/EditDrawStamp.ets Переглянути файл

@@ -1,9 +1,12 @@
import { AlgorithmHelper, ToolsHelper } from '@szyx/sdk_base'
import { AlgorithmHelper, LoadingView, ToolsHelper } from '@szyx/sdk_base'
import { router, window } from '@kit.ArkUI'
import { BackManager } from '../manager/BackManager'
import { BJCACallMsg } from '../public/callBack/BJCACallMsg'
import { BJCACallMsg, CallBackForData } from '../public/callBack/BJCACallMsg'
import mediaquery from '@ohos.mediaquery'
import { buffer } from '@kit.ArkTS'
import { ApiUtils } from '../http/ApiUtils'
import { GlobalValue } from '../common/GlobalValue'
import { uploadStampPic } from '../http/ApiConfig'
import { UploadStampData } from '../bean/data/UploadStampData'


@Entry({ routeName: 'EditDrawStampPage' })
@@ -25,12 +28,14 @@ export struct EditDrawStamp {
private miny: number = 0
private maxx: number = 0
private maxy: number = 0
private success?: CallBackForData<string>
@State isLoading: boolean = false

aboutToAppear() {
this.listener.on('change', (mediaQueryResult) => {
if (mediaQueryResult.matches) {
this.isLandscape = true
this.context.save()
// this.context.save()
}
});
this.context.fillStyle = 0xffff0000
@@ -43,8 +48,8 @@ export struct EditDrawStamp {
aboutToDisappear() {
this.w?.setPreferredOrientation(window.Orientation.UNSPECIFIED)
BackManager.get()
.call(!this.isLandscape ? BJCACallMsg.SUCCESS :
this.isReady && this.num > 0 ? BJCACallMsg.SUCCESS : BJCACallMsg.CANCEL)
.call(!this.isLandscape ? BJCACallMsg.DRAW_NOT_INIT :
this.isReady && this.num > 0 && this.success ? this.success : BJCACallMsg.CANCEL)
}

checkEffectivePoint(x: number, y: number) {
@@ -75,67 +80,94 @@ export struct EditDrawStamp {
}

build() {
Row() {
Stack({ alignContent: Alignment.TopEnd }) {
Canvas(this.context)
.width('100%')
.height('100%')
.onReady(() => {
this.isReady = true
Stack() {
LoadingView({ isLoading: this.isLoading }) {
Row() {
Stack({ alignContent: Alignment.TopEnd }) {
Canvas(this.context)
.width('100%')
.height('100%')
.onReady(() => {
this.isReady = true
})
this.Empty() // 初始UI
this.Canvas() // 画布
}.layoutWeight(1).onAreaChange((oldValue: Area, newValue: Area) => {
console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`)
this.offCanvas = new OffscreenCanvas((newValue.width) as number, (newValue.height) as number)
})
this.Empty() // 初始UI
this.Canvas() // 画布
}.layoutWeight(1).onAreaChange((oldValue: Area, newValue: Area) => {
console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`)
this.offCanvas = new OffscreenCanvas((newValue.width) as number, (newValue.height) as number)
})

Column() {
Column() {

Button('关闭', {
stateEffect: true,
type: ButtonType.Normal,
buttonStyle: ButtonStyleMode.NORMAL
})
.width(120)
.height(40)
.fontColor('#333333')
.onClick(() => {
router.back()
})
Button('清空内容', {
stateEffect: true,
type: ButtonType.Normal,
buttonStyle: ButtonStyleMode.NORMAL
})
.width(120)
.height(40)
.fontColor('#333333')
.margin({ top: 40, bottom: 40 })
.onClick(() => {
this.context.clearRect(0, 0, this.offCanvas.width, this.offCanvas.height)
this.context.resetTransform(); // 重置变换矩阵
this.offCanvas = new OffscreenCanvas(this.offCanvas.width, this.offCanvas.height)
this.context.restore()
this.num = 0
})
Button('完成', {
stateEffect: true,
type: ButtonType.Normal,
buttonStyle: ButtonStyleMode.NORMAL
})
.width(120)
.height(40)
.fontColor('#333333')
.onClick(() => {
// console.log('>>>>>>>>',
// buffer.from(this.context.getImageData(this.minx, this.miny, this.maxx, this.maxy).data)
// .toString('base64'))
})
}.visibility(this.isLandscape ? Visibility.Visible : Visibility.None)
Button('关闭', {
stateEffect: true,
type: ButtonType.Normal,
buttonStyle: ButtonStyleMode.NORMAL
})
.width(120)
.height(40)
.fontColor('#333333')
.onClick(() => {
router.back()
})
Button('清空内容', {
stateEffect: true,
type: ButtonType.Normal,
buttonStyle: ButtonStyleMode.NORMAL
})
.width(120)
.height(40)
.fontColor('#333333')
.margin({ top: 40, bottom: 40 })
.onClick(() => {
this.context.clearRect(0, 0, this.offCanvas.width, this.offCanvas.height)
this.context.resetTransform(); // 重置变换矩阵
this.offCanvas = new OffscreenCanvas(this.offCanvas.width, this.offCanvas.height)
// this.context.restore()
this.num = 0
})
Button('完成', {
stateEffect: true,
type: ButtonType.Normal,
buttonStyle: ButtonStyleMode.NORMAL
})
.width(120)
.height(40)
.fontColor('#333333')
.onClick(() => {
if (this.num === 0) {
ToolsHelper.showMessage("请手写后再保存")
return
}
this.isLoading = true
let base64 = this.context.toDataURL("image/png", 1).split(',')[1]
// 停止自动签
ApiUtils.post<string>(uploadStampPic(), new UploadStampData(
[GlobalValue.getInstance().certClientId!],
GlobalValue.getInstance().userId!,
GlobalValue.getInstance().getOpenId()!,
base64,
))
.then(() => {
GlobalValue.getInstance().stampPic = base64
this.isLoading = false
this.success = {
code: 1001,
msg: '手写签名修改成功',
data: base64
}
router.back()
}).catch((error: Error) => {
this.isLoading = false
ToolsHelper.showMessage(error.message)
})
})
}.visibility(this.isLandscape ? Visibility.Visible : Visibility.None)
}
.width('100%')
.height('100%')
}
}
.width('100%')
.height('100%')
}

// 画布
@@ -159,7 +191,7 @@ export struct EditDrawStamp {
this.y = e.y
break;
case TouchType.Move:
if (this.num > 400) {
if (this.num > 350) {
ToolsHelper.showMessage("笔画过于复杂")
return
}


+ 1
- 1
src/main/ets/public/CaManager.ets Переглянути файл

@@ -62,7 +62,7 @@ export class CaManager {
* 设置手写签章图片
* @param listener BJCACallMsg.SUCCESS.code & base64 || BJCACallMsg.FAILED.code
*/
public drawStamp(phone: string, listener: (result: CallBackMsg) => void) {
public drawStamp(phone: string, listener: (result: CallBackForData<string>) => void) {
CaManagerReal.drawStamp(phone, listener)
}



+ 5
- 0
src/main/ets/public/callBack/BJCACallMsg.ets Переглянути файл

@@ -75,6 +75,11 @@ export class BJCACallMsg {
code: 20002,
msg: '手写组件初始化失败'
}
public static DRAW_SUCCESS: CallBackForData<string> = {
code: 1001,
msg: '手写签名修改成功',
data:''
}
// 签名相关
public static SIGN_CANCEL: CallBackForData<string> = {
code: 1002,


Завантаження…
Відмінити
Зберегти