fix: 添加权限请求功能,优化设备信息获���和中心表初始化
This commit is contained in:
parent
e040b707dd
commit
b37b5e9581
@ -78,6 +78,10 @@ export interface InitializeTheCentralTableType {
|
||||
host?: string
|
||||
videoVersion?: string
|
||||
context?: common.UIAbilityContext
|
||||
mode?: string
|
||||
paraKdid?: string
|
||||
kdid?: string
|
||||
centerHost?: string
|
||||
}
|
||||
|
||||
// 以下是各个表的类型
|
||||
|
||||
@ -19,9 +19,10 @@ import imageBtn from './compontents/imageBtn';
|
||||
import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
|
||||
import { BaseInfoType } from '../model/Common';
|
||||
import { CarInfoType } from '../model/CarCheck';
|
||||
import { MASYSSETTableType, TimeInfo } from '../model';
|
||||
import { GetCarInfo, GetDeviceInfo } from './index/utils';
|
||||
import { GetSyncData } from '../utils/table/Operation';
|
||||
import { InitializeTheCentralTableType, MASYSSETTableType, TimeInfo } from '../model';
|
||||
import { GetCarInfo, GetDeviceInfo, UseAuth } from './index/utils';
|
||||
import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
|
||||
@Entry
|
||||
@ -364,6 +365,7 @@ struct Index {
|
||||
this.angle = 0
|
||||
this.loading = false
|
||||
AppStorage.set('lsh', '1111111111111')
|
||||
// TODO 未改
|
||||
// globalThis.errorDialog = this.errorDialog
|
||||
// globalThis.udpEvent = new UdpEvent();
|
||||
GetSyncData<MASYSSETTableType>("MA_SYSSET").then((res: MASYSSETTableType[]) => {
|
||||
@ -385,13 +387,13 @@ struct Index {
|
||||
|
||||
// console.log('mode',mode)
|
||||
|
||||
const param = {
|
||||
const param: InitializeTheCentralTableType = {
|
||||
carId: this.carInfo?.carId,
|
||||
examinationRoomId: this.carInfo?.examinationRoomId,
|
||||
judgeVersion: this.baseInfo.judgeVersion,
|
||||
shellVersion: this.baseInfo.version,
|
||||
paraKdid: this.timeInfo?.paraKdid || this.timeInfo?.kdid,
|
||||
kdid: this..timeInfo?.kdid || this.timeInfo?.paraKdid,
|
||||
kdid: this.timeInfo?.kdid || this.timeInfo?.paraKdid,
|
||||
mode: this.timeInfo?.mode,
|
||||
context: this.context,
|
||||
host: AppStorage.get('host'),
|
||||
@ -401,27 +403,16 @@ struct Index {
|
||||
this.loading = true
|
||||
console.log("sql 1111")
|
||||
|
||||
getSingleCenterTable(param).then((ret) => {
|
||||
console.log('teststetfinsh1', ret)
|
||||
// DB.queryListBySql('select * from MA_SYSSET', [{
|
||||
// name: "v_no",
|
||||
// type: ColumnType.STRING,
|
||||
// columnName: "v_no"
|
||||
// }]).then((res) => {
|
||||
// console.log('sql success', JSON.stringify(res))
|
||||
// }).catch((err) => {
|
||||
// console.log('sql error1', err)
|
||||
// })
|
||||
// getSingleCenterTable(param).then((ret) => {
|
||||
InitializeTheCentralTable(param).then((ret) => {
|
||||
if (ret) {
|
||||
getSyncData('MA_SYSSET').then(data => {
|
||||
console.log('datadata', JSON.stringify(data))
|
||||
GetSyncData<MASYSSETTableType>("MA_SYSSET").then(data => {
|
||||
data.forEach(sys => {
|
||||
//判断是否能点开始考试
|
||||
if (sys.v_no === '854') {
|
||||
AppStorage.setOrCreate('param854Str', sys.v_value)
|
||||
}
|
||||
if (sys.v_no === '824' && decodeURIComponent(sys.v_value) == '0') {
|
||||
// this.Param612Str= decodeURIComponent(sys.v_value)
|
||||
router.pushUrl({
|
||||
url: 'pages/CarCheck',
|
||||
params: {
|
||||
@ -438,47 +429,7 @@ struct Index {
|
||||
|
||||
}
|
||||
})
|
||||
// workerInstance.postMessage(param);
|
||||
// workerInstance.onmessage = (e: MessageEvents): void => {
|
||||
// console.log("baoyihu after postMessage :", JSON.stringify(e.data));
|
||||
// // @ts-ignore
|
||||
// let workData: WorkData = e.data;
|
||||
// this.loading = false
|
||||
// if (workData.isComplete) {
|
||||
// if(globalThis.singlePlay){
|
||||
// router.pushUrl({
|
||||
// url: 'pages/UserInfo',
|
||||
// }, router.RouterMode.Single)
|
||||
// return
|
||||
// }
|
||||
// getSyncData('MA_SYSSET').then(data => {
|
||||
// console.log('datadata', JSON.stringify(data))
|
||||
// // @ts-ignore
|
||||
// data.forEach(sys => {
|
||||
// //判断是否能点开始考试
|
||||
// if(sys.v_no === '854'){
|
||||
// globalThis.param854Str=sys.v_value
|
||||
// }
|
||||
// if (sys.v_no === '824'&&decodeURIComponent(sys.v_value)=='0') {
|
||||
// // this.Param612Str= decodeURIComponent(sys.v_value)
|
||||
// router.pushUrl({
|
||||
// url:'pages/CarCheck',
|
||||
// params: {
|
||||
// 'fromIndex':true
|
||||
// }
|
||||
// }, router.RouterMode.Single)
|
||||
// }else{
|
||||
// router.pushUrl({
|
||||
// url: 'pages/ExaminerLogin',
|
||||
// }, router.RouterMode.Single)
|
||||
// }
|
||||
// })
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// workerInstance.terminate();
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
async heartMsg() {
|
||||
@ -493,24 +444,28 @@ struct Index {
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0])
|
||||
}
|
||||
|
||||
const param = {
|
||||
id: 31,
|
||||
list: tmpList,
|
||||
carNo: this.carInfo.carNo,
|
||||
placeId: this.carInfo.examinationRoomId
|
||||
}
|
||||
// TODO 未改
|
||||
// const param = {
|
||||
// id: 31,
|
||||
// list: tmpList,
|
||||
// carNo: this.carInfo.carNo,
|
||||
// placeId: this.carInfo.examinationRoomId
|
||||
// }
|
||||
// globalThis.udpClient2.initHeartSendMsg(param,this.context)
|
||||
if (globalThis.udpClient2.getStatus()) {
|
||||
globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
}
|
||||
// if (globalThis.udpClient2.getStatus()) {
|
||||
// globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
// }
|
||||
}
|
||||
|
||||
async onPageShow() {
|
||||
console.log('ttttt', 1111)
|
||||
this.singlePlay = AppStorage.get('singlePlay')
|
||||
this.baseInfo = AppStorage.get('baseInfo') as BaseInfoType
|
||||
await this.userAuth();
|
||||
// await this.userAuth();
|
||||
UseAuth(this.context).then(() => {
|
||||
this.initParams()
|
||||
}).catch(() => {
|
||||
});
|
||||
if (this.singlePlay == undefined || this.singlePlay == null) {
|
||||
// setVideoParam()
|
||||
console.log('diyidiy')
|
||||
@ -524,7 +479,7 @@ struct Index {
|
||||
// })
|
||||
// let rawFile = value;
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error: BusinessError) => {
|
||||
console.log("getRawFileContent promise error is " + error);
|
||||
});
|
||||
|
||||
@ -548,37 +503,36 @@ struct Index {
|
||||
|
||||
}
|
||||
|
||||
userAuth() {
|
||||
return new Promise((reslove, reject) => {
|
||||
const permissions: Array<Permissions> =
|
||||
["ohos.permission.SET_TIME", "ohos.permission.READ_IMAGEVIDEO", "ohos.permission.DISTRIBUTED_DATASYNC",
|
||||
'ohos.permission.CONNECTIVITY_INTERNAL', 'ohos.permission.CAMERA', 'ohos.permission.READ_MEDIA',
|
||||
'ohos.permission.WRITE_MEDIA', 'ohos.permission.FILE_ACCESS_MANAGER'];
|
||||
let context = this.context;
|
||||
let atManager = abilityAccessCtrl.createAtManager();
|
||||
// requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
|
||||
|
||||
atManager.requestPermissionsFromUser(context, permissions).then((data) => {
|
||||
this.initParams()
|
||||
let grantStatus: Array<number> = data.authResults;
|
||||
let length: number = grantStatus.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (grantStatus[i] === 0) {
|
||||
// 用户授权,可以继续访问目标操作
|
||||
reslove(true)
|
||||
} else {
|
||||
reject()
|
||||
// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 授权成功
|
||||
}).catch((err) => {
|
||||
console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
// userAuth() {
|
||||
// return new Promise((reslove, reject) => {
|
||||
// const permissions: Array<Permissions> =
|
||||
// ["ohos.permission.SET_TIME", "ohos.permission.READ_IMAGEVIDEO", "ohos.permission.DISTRIBUTED_DATASYNC",
|
||||
// 'ohos.permission.CONNECTIVITY_INTERNAL', 'ohos.permission.CAMERA', 'ohos.permission.READ_MEDIA',
|
||||
// 'ohos.permission.WRITE_MEDIA', 'ohos.permission.FILE_ACCESS_MANAGER'];
|
||||
// let context = this.context;
|
||||
// let atManager = abilityAccessCtrl.createAtManager();
|
||||
//
|
||||
// atManager.requestPermissionsFromUser(context, permissions).then((data) => {
|
||||
// this.initParams()
|
||||
// let grantStatus: Array<number> = data.authResults;
|
||||
// let length: number = grantStatus.length;
|
||||
// for (let i = 0; i < length; i++) {
|
||||
// if (grantStatus[i] === 0) {
|
||||
// // 用户授权,可以继续访问目标操作
|
||||
// reslove(true)
|
||||
// } else {
|
||||
// reject()
|
||||
// // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// // 授权成功
|
||||
// }).catch((err: BusinessError) => {
|
||||
// console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);
|
||||
// })
|
||||
// })
|
||||
//
|
||||
// }
|
||||
|
||||
async initParams() {
|
||||
//设置plc udp 同步requesthost
|
||||
@ -615,10 +569,6 @@ struct Index {
|
||||
}
|
||||
}, 1000)
|
||||
this.createAlbum()
|
||||
//下载模型
|
||||
// await this.getModel()
|
||||
// const arr = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00]
|
||||
// globalThis.udpClientByTopLine.sendMsg(Array2Byte(arr).buffer)
|
||||
}
|
||||
|
||||
async getModel() {
|
||||
|
||||
@ -5,6 +5,8 @@ import Prompt from "@system.prompt";
|
||||
import { CarConfigurationParamsType, ObtainCarExamInfoParams } from "../../model";
|
||||
import dayTs from "../../utils/Date";
|
||||
import { obtainCarExamInfo } from "../../api";
|
||||
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
||||
import { BusinessError } from "@ohos.base";
|
||||
|
||||
//获取设备信息
|
||||
export async function GetDeviceInfo(context: common.UIAbilityContext): Promise<string> {
|
||||
@ -33,6 +35,7 @@ export async function GetCarInfo() {
|
||||
time: dayTs(date).format("YYYY-MM-DD HH:mm:ss"),
|
||||
deviceNo: AppStorage.get('deviceNo')
|
||||
};
|
||||
// TODO 待完善
|
||||
let res: ESObject = await obtainCarExamInfo(params)
|
||||
if (res.obtainCarExamInfoRsp.body) {
|
||||
const carInfo: ESObject = res?.obtainCarExamInfoRsp?.body
|
||||
@ -40,3 +43,29 @@ export async function GetCarInfo() {
|
||||
AppStorage.setOrCreate('carInfo', carInfo)
|
||||
}
|
||||
}
|
||||
|
||||
export async function UseAuth(context: common.UIAbilityContext): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const permissions: Array<Permissions> =
|
||||
["ohos.permission.SET_TIME", "ohos.permission.READ_IMAGEVIDEO", "ohos.permission.DISTRIBUTED_DATASYNC",
|
||||
'ohos.permission.CONNECTIVITY_INTERNAL', 'ohos.permission.CAMERA', 'ohos.permission.READ_MEDIA',
|
||||
'ohos.permission.WRITE_MEDIA', 'ohos.permission.FILE_ACCESS_MANAGER'];
|
||||
abilityAccessCtrl.createAtManager().requestPermissionsFromUser(context, permissions).then(res => {
|
||||
let grantStatus: Array<number> = res.authResults;
|
||||
let length: number = grantStatus.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (grantStatus[i] === 0) {
|
||||
// 用户授权,可以继续访问目标操作
|
||||
resolve(true)
|
||||
} else {
|
||||
reject(false)
|
||||
// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
|
||||
return;
|
||||
}
|
||||
}
|
||||
}).catch((err: BusinessError) => {
|
||||
console.log("获取权限失败", JSON.stringify(err))
|
||||
reject(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user