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