作者 xiaoqiu

优化了各项校验功能,修复了添加和修改维保记录的部分bug

... ... @@ -125,7 +125,7 @@ export interface personCertificateRow {
validEndTime?: null;
issueDate?: string;
certificateImg?: string;
memo?: null;
memo?: string;
state?: string;
}
... ...
... ... @@ -5,7 +5,7 @@ import { personData, personCertificateRow, companyWalletTest, companyWalletRow,
import baseUrl from '../utils/baseUrl'
import { getCompanyPersonList } from '../api/originalRecords'
import { companyPersonTest, companyPersonRow } from '../api/recordsType'
import { getCompanyWallet, updateState } from '../api/user'
import { getCompanyWallet, updateState, getPay, beanType } from '../api/user'
import { AxiosResponse } from '@ohos/axios'
import { promptAction } from '@kit.ArkUI'
import LoadingDialog from '../dialog/LoadingDialog'
... ... @@ -20,6 +20,7 @@ function textRight() {
.fontSize(14).lineHeight(19).fontColor('#999')
}
// 定义离职状态
let getTextInfo = (state: string | null) => {
if(state == '0') {
return '已离职'
... ... @@ -47,11 +48,18 @@ export default struct MainPage {
})
@Link userInfo: personData
@Link companyInfo: companyData
@Link isEdit: boolean
@Link personCertificateInfo: personCertificateRow
@State walletData: companyWalletRow | null = null
@State companyData: companyPersonRow | null = null
@Link isEdit: boolean
@State isShowPay: boolean = false
timer: number = 0
roleName = preferencesUtil.get('XF_ROLE_NAME', '')
// 获取是否显示充值
getShowPay = async () => {
const payInfo: AxiosResponse<beanType> = await getPay()
this.isShowPay = payInfo.data.msg === "true"
}
async aboutToAppear() {
let personId = preferencesUtil.get('XF_PERSON_ID', 0)
let companyId = preferencesUtil.get('XF_COMPANY_ID', 0)
... ... @@ -63,10 +71,21 @@ export default struct MainPage {
const companyInfo: AxiosResponse<companyPersonTest> = await getCompanyPersonList({pageNum: 1, pageSize: 10, personId: Number(personId)})
this.companyData = companyInfo.data.rows[0]
}
if(this.roleName == 'company') {
this.timer = setInterval(async () => {
await this.getShowPay()
}, 60000)
}
// 获取公司钱包信息
const walletInfo: AxiosResponse<companyWalletTest> = await getCompanyWallet({pageNum: 1, pageSize: 10, companyId: Number(companyId)})
this.walletData = walletInfo.data.rows[0]
}
// 组件销毁时关闭定时任务
aboutToDisappear() {
if(this.timer !== 0) {
clearInterval(this.timer)
this.timer = 0
}
}
build() {
Stack(){
... ... @@ -88,7 +107,7 @@ export default struct MainPage {
router.pushUrl({
url: "pages/MyWallet"
})
})
}).visibility(this.roleName == 'company' && this.isShowPay ? Visibility.Visible: Visibility.None)
}.width('100%').padding({left: 10,right: 10}).margin({top: 44})
.visibility(this.roleName == 'company' ? Visibility.Visible: Visibility.None)
}.width('100%').height(256).padding({left: 15,right: 15})
... ...
... ... @@ -34,6 +34,10 @@ interface comprehensiveType {
}
let params = router.getParams() as routerParams
let reportId: number | undefined = params?.reportId
let personId = preferencesUtil.get('XF_PERSON_ID', 0)
let companyId: number = preferencesUtil.get('XF_COMPANY_ID', 0) as number
let roleName = preferencesUtil.get('XF_ROLE_NAME', '')
// 查看原始记录编号是否存在
let queryReportNo = async (reportNo: string) => {
... ... @@ -59,7 +63,10 @@ function searchByIndexOf(keyWord: string, list: equipmentType[]){
// 提取的富文本内容分别赋值
function multiply(range: string, facility: string, existingProblem: string,cumulativeIssues:string, correctedProblems: string, ...other: string[]){
let otherValue: string = other.length > 1 ? other?.slice(1).join('、') : other[0].slice(3)
let otherValue: string = ''
if(Array.isArray(other)) {
otherValue = other.length > 1 ? other?.slice(1).join('、') : other[0].slice(3)
}
let newObj:comprehensiveType = {
range: range.split(':')[1],
facility: facility.split(':')[1],
... ... @@ -68,20 +75,42 @@ function multiply(range: string, facility: string, existingProblem: string,cumul
correctedProblems: correctedProblems.split(':')[1],
other: otherValue
}
return newObj
return newObj
}
// 提取富文本中的内容解析后导出
function extractRichText(str: string): comprehensiveType{
let richText = str.replace(/<.*?>/g, '?')
let arrValue: string[] = richText.split('?').filter(item => item !== '')
let otherArr: string[] = []
if(arrValue.length > 5){
for (let index = 5; index < arrValue.length; index++) {
otherArr.push(arrValue[index])
function extractRichText(str: string | null): comprehensiveType{
if(str === null) {
return {
range: '',
facility: '',
existingProblem: '',
cumulativeIssues: '',
correctedProblems: '',
other: '',
}
} else {
let richText = str.replace(/<.*?>/g, '?')
let arrValue: string[] = richText.split('?').filter(item => item !== '')
let otherArr: string[] = []
if(arrValue.length > 5){
for (let index = 5; index < arrValue.length; index++) {
otherArr.push(arrValue[index])
}
return multiply(arrValue[0], arrValue[1], arrValue[2], arrValue[3], arrValue[4], ...otherArr)
} else if(arrValue.length === 5) {
return multiply(arrValue[0], arrValue[1], arrValue[2], arrValue[3], arrValue[4], '其他:')
} else {
return {
range: '',
facility: '',
existingProblem: '',
cumulativeIssues: '',
correctedProblems: '',
other: str.replace(/<.*?>/g, ''),
}
}
}
return multiply(arrValue[0], arrValue[1], arrValue[2], arrValue[3], arrValue[4], ...otherArr)
}
// 提交修改时合并富文本内容
... ... @@ -101,6 +130,11 @@ function mergeRichText(comprehensive: comprehensiveType): string{
.border({width: 1, color: '#eee'}).backgroundColor(Color.Transparent)
.placeholderColor('#999').borderRadius(4).placeholderFont({size: 14})
}
@Extend(TextArea) function TextAreaReview () {
.width('100%').fontSize(14).fontColor('#999').lineHeight(20)
.border({width: 1, color: '#eee'}).backgroundColor(Color.Transparent)
.placeholderColor('#999').borderRadius(4).placeholderFont({size: 14})
}
@Entry
@Component
... ... @@ -108,8 +142,6 @@ struct AddRecords {
@Builder indicatorBuilder(icon: ResourceStr) {
Image(icon)
}
personId = preferencesUtil.get('XF_PERSON_ID', 0)
flag: boolean = true
// 添加维保记录类型参数
@State addForm: addParamsType = {
reportName: '',
... ... @@ -161,59 +193,6 @@ struct AddRecords {
@State initEquipmentList: equipmentType[] = []
@State errorMsg: string = ''
@State text: string = "请选择维保记录类型"
async aboutToAppear() {
// reportId等于undefined为编辑状态
this.isEdit = reportId !== undefined
this.addForm.city = this.pickerValue[1]
this.addForm.county = this.pickerValue[2]
if(reportId){
this.addForm.reportId = reportId
const res: AxiosResponse<reportDetailTest> = await getReportDetail(reportId)
let result: reportDetailData = res.data.data
this.addForm.reportName = result.reportName
this.addForm.applyCompanyName = result.applyCompanyName
this.addForm.reportNo = result.reportNo
this.addForm.reportType = result.reportType
this.addForm.maintenanceTime = result.maintenanceTime
this.addForm.maintenanceEndTime = result.maintenanceEndTime
this.addForm.equipmentList = result.equipment.split(',')
this.addForm.fireFacilities = result.fireFacilities
this.addForm.maintenancePeople = result.maintenancePeople
this.addForm.result = result.result.replace(/<.*?>/g, '')
this.addForm.state = result.state
this.addForm.technicalDirectorId = result.technicalDirectorId
this.addForm.maintenancePeopleList = result.technicalDirectorId?.split(',')
this.addForm.city = result.city
this.addForm.county = result.county
this.addForm.approvePersonId = result.approvePersonId as number
this.addForm.projectList = result.projectList.map(item => {
return { projectId: item.projectId } as projectType
})
this.fireFacilitiesList = this.addForm.fireFacilities.split('、')
this.viewEquipmentList = result.equipment.split(',')
this.PeopleList = result.technicalDirectorId?.split(',') || []
this.pickerValue = ['广西壮族自治区', result.city as string, result.county as string]
this.comprehensiveReview = extractRichText(result.result)
}
// 获取项目的类型列表
getMaintenanceType().then((res: AxiosResponse<quarterTest>) => {
this.recordsType = res.data.data
})
// 获取消防设施
getLatestProjectList(this.addForm.reportType as string).then((res: AxiosResponse<LatestProjectTest>) => {
this.latestProjectList = res.data.data
})
const companyId: number = preferencesUtil.get('XF_COMPANY_ID', 0) as number
this.addForm.companyId = companyId
// 获取仪器设备
getEquipmentList({pageNum: 1, pageSize: 500, companyId: companyId }).then((res: AxiosResponse<equipmentTest>) => {
this.equipmentList = res.data.rows
this.initEquipmentList = res.data.rows
})
getCompanyPersonList({pageNum: 1, pageSize: 200, companyId: companyId, state: '2' }).then((res: AxiosResponse<companyPersonTest>) => {
this.companyPersonList = res.data.rows
})
}
// 搜索框实例
searchController: SearchController = new SearchController()
... ... @@ -241,60 +220,114 @@ struct AddRecords {
autoCancel: false
})
// 初始化数据
initData = () => {
// 获取项目的类型列表
getMaintenanceType().then((res: AxiosResponse<quarterTest>) => {
this.recordsType = res.data.data
})
// 获取消防设施
getLatestProjectList(this.addForm.reportType as string).then((res: AxiosResponse<LatestProjectTest>) => {
this.latestProjectList = res.data.data
})
this.addForm.companyId = companyId
// 获取仪器设备
getEquipmentList({pageNum: 1, pageSize: 500, companyId: companyId }).then((res: AxiosResponse<equipmentTest>) => {
this.equipmentList = res.data.rows
this.initEquipmentList = res.data.rows
})
getCompanyPersonList({pageNum: 1, pageSize: 200, companyId: companyId, state: '2' }).then((res: AxiosResponse<companyPersonTest>) => {
this.companyPersonList = res.data.rows
})
}
// 获取维保记录类型
getReportType = async (dictValue: string) => {
this.loadingController.open()
this.addForm.reportType = dictValue
if(this.flag) {
this.addForm.projectList = []
this.fireFacilitiesList = []
this.addForm.fireFacilities = ''
this.flag = false
let result: AxiosResponse<LatestProjectTest> = await getLatestProjectList(dictValue)
this.latestProjectList = result.data.data
this.flag = true
}
this.addForm.projectList = []
this.fireFacilitiesList = []
this.addForm.fireFacilities = ''
let result: AxiosResponse<LatestProjectTest> = await getLatestProjectList(dictValue)
this.latestProjectList = result.data.data
this.loadingController.close()
}
// 添加记录方法
addReport = async () => {
this.loadingController.open()
this.addForm.maintenanceDate = [this.addForm.maintenanceTime as string, this.addForm.maintenanceEndTime as string]
await addRecords(this.addForm)
this.loadingController.close()
promptAction.showToast({ message: '添加成功' })
router.back()
}
// 更新记录方法
uploadReport = async () => {
this.loadingController.open()
await updateRecords(this.addForm)
this.loadingController.close()
promptAction.showToast({ message: '更新成功' })
}
// 提交表单
submitForm = async () => {
if(this.addForm.reportName == '') {
return promptAction.showToast({message: '项目名称为必填项'})
} else if(this.addForm.reportNo == '') {
return promptAction.showToast({message: '项目编号为必填项'})
} else if(this.addForm.applyCompanyName == ''){
return promptAction.showToast({message: '消防设施管理单位为必填项'})
} else if(this.addForm.maintenanceTime == '请选择起始日期' || this.addForm.maintenanceEndTime == '请选择结束日期'){
return promptAction.showToast({message: '维保日期为必填项'})
} else if(this.addForm.fireFacilities == ''){
return promptAction.showToast({message: '至少选择一下消防设施'})
} else if(this.addForm.maintenancePeople == ''){
return promptAction.showToast({message: '请选择维保人员'})
this.addForm.result = mergeRichText(this.comprehensiveReview)
if(this.addForm.reportName === '' || this.addForm.reportNo === '' || this.addForm.applyCompanyName === '' || this.addForm.maintenanceTime === '请选择起始日期' || this.addForm.maintenanceEndTime === '请选择结束日期' || this.addForm.fireFacilities === '' || this.addForm.maintenancePeople === '') {
return promptAction.showToast({message: '* 号为必填项'})
}
if(this.comprehensiveReview.range === '' || this.comprehensiveReview.existingProblem === '' || this.comprehensiveReview.cumulativeIssues === '' || this.comprehensiveReview.correctedProblems === ''){
return promptAction.showToast({message: '综合评述带 * 号必填'})
}
if(this.errorMsg !== '') {
return promptAction.showToast({message: '校验失败'})
return promptAction.showToast({message: '校验失败,编号已被使用'})
}
if(!this.addForm.maintenancePeopleList?.includes(this.personId.toString())){
if(roleName === 'person' && !this.addForm.maintenancePeopleList?.includes(personId.toString())){
return promptAction.showToast({message: '本人必须在维护人员中'})
}
this.addForm.result = mergeRichText(this.comprehensiveReview)
if(this.isEdit){
this.loadingController.open()
await updateRecords(this.addForm)
this.loadingController.close()
promptAction.showToast({
message: '更新成功'
})
} else {
this.loadingController.open()
this.addForm.maintenanceDate = [this.addForm.maintenanceTime as string, this.addForm.maintenanceEndTime as string]
await addRecords(this.addForm)
this.loadingController.close()
promptAction.showToast({
message: '添加成功'
this.isEdit ? await this.uploadReport() : await this.addReport()
}
// 页面加载时调用
async aboutToAppear() {
this.initData()
// reportId不等于undefined为编辑状态
this.isEdit = reportId !== undefined
this.addForm.city = this.pickerValue[1]
this.addForm.county = this.pickerValue[2]
if(reportId){
this.addForm.reportId = reportId
const res: AxiosResponse<reportDetailTest> = await getReportDetail(reportId)
let result: reportDetailData = res.data.data
this.addForm.reportName = result.reportName
this.addForm.applyCompanyName = result.applyCompanyName
this.addForm.reportNo = result.reportNo
this.addForm.reportType = result.reportType
this.addForm.maintenanceTime = result.maintenanceTime
this.addForm.maintenanceEndTime = result.maintenanceEndTime
this.addForm.equipmentList = result.equipment?.split(',')
this.addForm.fireFacilities = result.fireFacilities
this.addForm.maintenancePeople = result.maintenancePeople
this.addForm.result = result.result?.replace(/<.*?>/g, '')
this.fireFacilitiesList = result.fireFacilities?.split('、') || []
this.addForm.state = result.state
this.addForm.technicalDirectorId = result.technicalDirectorId || ''
this.addForm.maintenancePeopleList = result.technicalDirectorId?.split(',') || []
this.addForm.city = result.city || '南宁市'
this.addForm.county = result.county || '青秀区'
this.addForm.approvePersonId = result.approvePersonId as number
this.addForm.projectList = result.projectList.map(item => {
return { projectId: item.projectId } as projectType
})
router.back()
this.viewEquipmentList = result.equipment?.split(',') || []
this.PeopleList = result.technicalDirectorId?.split(',') || []
this.pickerValue = ['广西壮族自治区', result.city as string || '南宁市', result.county as string || '青秀区']
this.comprehensiveReview = extractRichText(result.result)
// 获取消防设施
let LatestRes: AxiosResponse<LatestProjectTest> = await getLatestProjectList(this.addForm.reportType as string)
this.latestProjectList = LatestRes.data.data
}
}
build() {
Column(){
NavHeader({title: '添加原始记录'})
... ... @@ -345,7 +378,7 @@ struct AddRecords {
Image($r('app.media.require')).width(20)
Text('维保起始日期')
}.width(120)
Text(this.addForm.maintenanceTime).padding({top: 8, bottom: 8, left: 16, right: 16})
Text(this.addForm.maintenanceTime || '请选择日期').padding({top: 8, bottom: 8, left: 16, right: 16})
.backgroundColor('#fff').layoutWeight(1).fontColor('#000').onClick(() => {
CalendarPickerDialog.show({
onAccept: (value) => {
... ... @@ -359,7 +392,7 @@ struct AddRecords {
Image($r('app.media.require')).width(20)
Text('维保结束日期')
}.width(120)
Text(this.addForm.maintenanceEndTime).padding({top: 8, bottom: 8, left: 16, right: 16})
Text(this.addForm.maintenanceEndTime || '请选择日期').padding({top: 8, bottom: 8, left: 16, right: 16})
.backgroundColor('#fff').layoutWeight(1).fontColor('#000').onClick(() => {
CalendarPickerDialog.show({
onAccept: (value) => {
... ... @@ -368,6 +401,17 @@ struct AddRecords {
})
})
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('项目区域')
}.width(90)
Text(this.pickerValue.join(' ')).layoutWeight(1).padding({top: 8, bottom: 8, left: 16, right: 16})
.backgroundColor('#fff').textOverflow({overflow: TextOverflow.Ellipsis}).maxLines(2)
.onClick(() => {
this.areaController?.open()
})
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Column({space: 10}){
Row(){
Image($r('app.media.require')).width(20)
... ... @@ -422,7 +466,10 @@ struct AddRecords {
.shape(CheckBoxShape.ROUNDED_SQUARE)
.onChange((value: boolean) => {
if(value){
this.addForm.maintenancePeopleList?.push(children.personId.toString())
// 如果选择的人员列表中不存在此人员列表中,则添加
if(!this.addForm.maintenancePeopleList?.includes(children.personId.toString())){
this.addForm.maintenancePeopleList?.push(children.personId.toString())
}
}else {
this.addForm.maintenancePeopleList = this.addForm.maintenancePeopleList?.filter((item: string) => item !== children.personId.toString())
}
... ... @@ -450,17 +497,6 @@ struct AddRecords {
TextInput({placeholder: '请输入消防设施管理单位', text: $$this.addForm.applyCompanyName})
.backgroundColor('#fff')
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('项目区域')
}.width(90)
Text(this.pickerValue.join(' ')).layoutWeight(1).padding({top: 8, bottom: 8, left: 16, right: 16})
.backgroundColor('#fff').textOverflow({overflow: TextOverflow.Ellipsis}).maxLines(2)
.onClick(() => {
this.areaController?.open()
})
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Column(){
Row(){
Image($r('app.media.require')).width(20)
... ... @@ -511,10 +547,11 @@ struct AddRecords {
Row(){
Checkbox({ name: children.projectName, group: 'checkboxGroup' })
.selectedColor('#1890ff')
.select(this.fireFacilitiesList.includes(children.projectName))
.select(this.fireFacilitiesList?.includes(children.projectName))
.shape(CheckBoxShape.ROUNDED_SQUARE)
.onChange((value) => {
if(value){
if(this.addForm.projectList?.some((item) => item.projectId === children.projectId)) return
this.addForm.projectList?.push({ projectId: children.projectId })
} else {
this.addForm.projectList = this.addForm.projectList?.filter((item) => item.projectId !== children.projectId)
... ... @@ -582,7 +619,7 @@ struct AddRecords {
Row(){
Checkbox({ name: children.equipmentName, group: 'checkboxGroup2' })
.selectedColor('#1890ff')
.select(this.viewEquipmentList.includes(children.equipmentName))
.select(this.viewEquipmentList?.includes(children.equipmentName))
.shape(CheckBoxShape.ROUNDED_SQUARE)
.mark({
strokeColor:Color.White,
... ... @@ -606,29 +643,44 @@ struct AddRecords {
}.padding({left: 10})
Column({space: 10}){
Column({space: 10}){
Text('本月维保范围').TitleReview()
Row({space: 5}){
Image($r('app.media.require')).width(20)
Text('本月维保范围').TitleReview()
}.width('100%')
TextInput({placeholder: '请输入本月维保范围(填写楼层)', text: $$this.comprehensiveReview.range}).TextInputReview()
}.width('100%').alignItems(HorizontalAlign.Start)
Column({space: 10}){
Text('消防设施包含').TitleReview()
Text(this.comprehensiveReview.facility || '勾选主要消防设施').width('100%').height(40).fontSize(14).padding({top: 8, bottom: 8, left: 16, right: 16})
Row({space: 5}){
Image($r('app.media.require')).width(20)
Text('消防设施包含').TitleReview()
}.width('100%')
Text(this.comprehensiveReview.facility || '勾选主要消防设施').width('100%').height('auto').fontSize(14).padding({top: 8, bottom: 8, left: 16, right: 16})
.border({width: 1, color: '#eee'}).borderRadius(4).fontColor('#999').textAlign(TextAlign.Start)
}.width('100%').alignItems(HorizontalAlign.Start)
Column({space: 10}){
Text('存在问题').TitleReview()
TextInput({placeholder: '请输入存在问题', text: this.comprehensiveReview.existingProblem}).TextInputReview()
Row({space: 5}){
Image($r('app.media.require')).width(20)
Text('存在问题').TitleReview()
}.width('100%')
TextArea({ placeholder: '请输入存在问题', text: $$this.comprehensiveReview.existingProblem }).TextAreaReview()
}.width('100%').alignItems(HorizontalAlign.Start)
Column({space: 10}){
Text('累计问题').TitleReview()
TextInput({placeholder: '请输入累计问题', text: $$this.comprehensiveReview.cumulativeIssues}).TextInputReview()
Row({space: 5}){
Image($r('app.media.require')).width(20)
Text('累计问题').TitleReview()
}.width('100%')
TextArea({ placeholder: '请输入累计问题', text: $$this.comprehensiveReview.cumulativeIssues }).TextAreaReview()
}.width('100%').alignItems(HorizontalAlign.Start)
Column({space: 10}){
Text('已整改问题').TitleReview()
TextInput({placeholder: '请输入已整改问题', text: $$this.comprehensiveReview.correctedProblems}).TextInputReview()
Row({space: 5}){
Image($r('app.media.require')).width(20)
Text('已整改问题').TitleReview()
}.width('100%')
TextArea({ placeholder: '请输入已整改问题', text: $$this.comprehensiveReview.correctedProblems }).TextAreaReview()
}.width('100%').alignItems(HorizontalAlign.Start)
Column({space: 10}){
Text('其他').TitleReview()
TextInput({placeholder: '其他内容', text: $$this.comprehensiveReview.other}).TextInputReview()
TextArea({ placeholder: '请输入其他内容', text: $$this.comprehensiveReview.other }).TextAreaReview()
}.width('100%').alignItems(HorizontalAlign.Start)
}
}.width('100%').alignItems(HorizontalAlign.Start).margin({top: 20}).padding({bottom: 30})
... ... @@ -645,6 +697,7 @@ struct AddRecords {
}.width('100%').height('100%').backgroundColor('#f2f3f7')
}
// 退出动画
pageTransition() {
// 该页面退出动画时长为1200ms,尽量与另一页面的进入动画时长匹配
PageTransitionExit({ duration: 500 })
... ...
... ... @@ -21,6 +21,7 @@ struct EditUser {
certificateId: 1,
certificateImg: '',
issueDate: '选择日期',
memo: '无',
personId
}
@State selectValue: string = '请选择证书类型'
... ... @@ -116,6 +117,7 @@ struct EditUser {
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('备注')
}.width(100)
TextArea({
... ...
... ... @@ -4,15 +4,12 @@ import { BusinessError } from '@ohos.base';
import { promptAction, router } from '@kit.ArkUI'
import { common } from '@kit.AbilityKit';
import { FileUtil, CommonConstants } from '../utils/FileUtil';
// import { uploadFileByTask } from '../utils/uploadCloud'
import { commonRouterParams } from '../utils/UserAuth'
/**
* 视频录制
*/
let context = getContext(this) as common.UIAbilityContext;
let routerParamsData: commonRouterParams = router.getParams() as commonRouterParams;
@Entry
@Component
struct CreateCamera {
... ... @@ -67,11 +64,8 @@ struct CreateCamera {
this.timer = 0
promptAction.showToast({ message: '已完成录制,开始上传' })
await this.stopRecord();
routerParamsData.videoPath = this.path;
router.back({
url:'',
params: routerParamsData
})
AppStorage.set('videoPath', this.path);
router.back()
} else {
promptAction.showToast({ message: '已开始录制,再次点击完成录制' })
this.timer = setInterval(async () => {
... ... @@ -81,11 +75,8 @@ struct CreateCamera {
this.timer = 0
promptAction.showToast({ message: '已完成录制,开始上传' })
await this.stopRecord();
routerParamsData.videoPath = this.path;
router.back({
url:'',
params: routerParamsData
})
AppStorage.set('videoPath', this.path);
router.back()
}
}, 1000);
await this.startRecord();
... ... @@ -118,43 +109,44 @@ struct CreateCamera {
}
this.cameraManager.on('cameraStatus', (err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo) => {
promptAction.showToast({ message: `camera : ${cameraStatusInfo.camera.cameraId},status: ${cameraStatusInfo.status}` })
console.log(`camera : ${cameraStatusInfo.camera.cameraId},status: ${cameraStatusInfo.status}`)
// promptAction.showToast({ message: `camera : ${cameraStatusInfo.camera.cameraId},status: ${cameraStatusInfo.status}` })
});
let cameraArray: Array<camera.CameraDevice> = [];
try {
cameraArray = this.cameraManager.getSupportedCameras();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `getSupportedCameras call failed. error code: ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `getSupportedCameras call failed. error code: ${err.code}` })
}
if (cameraArray.length <= 0) {
promptAction.showToast({ message: 'cameraManager.getSupportedCameras error' })
// promptAction.showToast({ message: 'cameraManager.getSupportedCameras error' })
return;
}
let cameraOutputCap: camera.CameraOutputCapability =
this.cameraManager.getSupportedOutputCapability(cameraArray[0], camera.SceneMode.NORMAL_VIDEO);
if (!cameraOutputCap) {
promptAction.showToast({ message: 'cameraManager.getSupportedOutputCapability error' })
// promptAction.showToast({ message: 'cameraManager.getSupportedOutputCapability error' })
return;
}
promptAction.showToast({ message: 'outputCapability: ' + JSON.stringify(cameraOutputCap) })
// promptAction.showToast({ message: 'outputCapability: ' + JSON.stringify(cameraOutputCap) })
let previewProfilesArray: Array<camera.Profile> = cameraOutputCap.previewProfiles;
if (!previewProfilesArray) {
promptAction.showToast({ message: 'createOutput previewProfilesArray === null || undefined' })
// promptAction.showToast({ message: 'createOutput previewProfilesArray === null || undefined' })
}
let photoProfilesArray: Array<camera.Profile> = cameraOutputCap.photoProfiles;
if (!photoProfilesArray) {
promptAction.showToast({ message: 'createOutput photoProfilesArray === null || undefined' })
// promptAction.showToast({ message: 'createOutput photoProfilesArray === null || undefined' })
}
let videoProfilesArray: Array<camera.VideoProfile> = cameraOutputCap.videoProfiles;
if (!videoProfilesArray) {
promptAction.showToast({ message: 'createOutput videoProfilesArray === null || undefined' })
// promptAction.showToast({ message: 'createOutput videoProfilesArray === null || undefined' })
}
let videoSize: camera.Size = {
... ... @@ -166,7 +158,7 @@ struct CreateCamera {
});
if (!videoProfile) {
promptAction.showToast({ message: 'videoProfile is not found' })
promptAction.showToast({ message: '没有找到视频文件' })
return;
}
... ... @@ -198,8 +190,8 @@ struct CreateCamera {
try {
this.avRecorder = await media.createAVRecorder();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `createAVRecorder call failed. error code: ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `createAVRecorder call failed. error code: ${err.code}` })
}
if (this.avRecorder === undefined) {
... ... @@ -209,16 +201,16 @@ struct CreateCamera {
try {
await this.avRecorder.prepare(aVRecorderConfig);
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `prepare call failed. error code: ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `prepare call failed. error code: ${err.code}` })
}
let videoSurfaceId: string | undefined = undefined;
try {
videoSurfaceId = await this.avRecorder.getInputSurface();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `getInputSurface call failed. error code: ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `getInputSurface call failed. error code: ${err.code}` })
}
if (videoSurfaceId === undefined) {
return;
... ... @@ -227,26 +219,26 @@ struct CreateCamera {
try {
this.videoOutput = this.cameraManager.createVideoOutput(videoProfile, videoSurfaceId);
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to create the videoOutput instance. error: ${JSON.stringify(err)}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to create the videoOutput instance. error: ${JSON.stringify(err)}` })
}
if (this.videoOutput === undefined) {
return;
}
this.videoOutput.on('frameStart', () => {
promptAction.showToast({ message: 'Video frame started' })
// promptAction.showToast({ message: 'Video frame started' })
});
this.videoOutput.on('error', (error: BusinessError) => {
promptAction.showToast({ message: `Video frame error code: ${error.code}` })
this.videoOutput.on('error', () => {
// promptAction.showToast({ message: `Video frame error code: ${error.code}` })
});
try {
this.captureSession = this.cameraManager.createSession(camera.SceneMode.NORMAL_VIDEO) as camera.VideoSession;
;
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to create the CaptureSession instance. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to create the CaptureSession instance. errorCode = ${err.code}` })
}
if (this.captureSession === undefined) {
return;
... ... @@ -255,46 +247,46 @@ struct CreateCamera {
try {
this.captureSession.beginConfig();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to beginConfig. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to beginConfig. errorCode = ${err.code}` })
}
let cameraInput: camera.CameraInput | undefined = undefined;
try {
cameraInput = this.cameraManager.createCameraInput(cameraArray[0]);
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to createCameraInput. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to createCameraInput. errorCode = ${err.code}` })
}
if (cameraInput === undefined) {
return;
}
let cameraDevice: camera.CameraDevice = cameraArray[0];
cameraInput.on('error', cameraDevice, (error: BusinessError) => {
promptAction.showToast({ message: `Camera input error code: ${error.code}` })
cameraInput.on('error', cameraDevice, () => {
// promptAction.showToast({ message: `Camera input error code: ${error.code}` })
});
try {
await cameraInput.open();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to open cameraInput. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to open cameraInput. errorCode = ${err.code}` })
}
try {
this.captureSession.addInput(cameraInput);
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to add cameraInput. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to add cameraInput. errorCode = ${err.code}` })
}
let previewOutput: camera.PreviewOutput | undefined = undefined;
try {
previewOutput = this.cameraManager.createPreviewOutput(videoProfile, surfaceId);
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to create the previewOutput instance. error: ${JSON.stringify(err)}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to create the previewOutput instance. error: ${JSON.stringify(err)}` })
}
if (previewOutput === undefined) {
... ... @@ -304,37 +296,37 @@ struct CreateCamera {
try {
this.captureSession.addOutput(previewOutput);
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to add previewOutput. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to add previewOutput. errorCode = ${err.code}` })
}
try {
this.captureSession.addOutput(this.videoOutput);
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to add videoOutput. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to add videoOutput. errorCode = ${err.code}` })
}
try {
await this.captureSession.commitConfig();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to commitConfig. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to commitConfig. errorCode = ${err.code}` })
}
try {
await this.captureSession.start();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `Failed to start captureSession. errorCode = ${err.code}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `Failed to start captureSession. errorCode = ${err.code}` })
}
this.videoOutput.start((err: BusinessError) => {
if (err) {
promptAction.showToast({ message: `Failed to start the video output. error: ${JSON.stringify(err)}` })
// promptAction.showToast({ message: `Failed to start the video output. error: ${JSON.stringify(err)}` })
return;
}
promptAction.showToast({message: 'Callback invoked to indicate the video output start success.'})
// promptAction.showToast({message: 'Callback invoked to indicate the video output start success.'})
});
}
... ... @@ -344,8 +336,8 @@ struct CreateCamera {
try {
await this.avRecorder.start();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `avRecorder start error: ${JSON.stringify(err)}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `avRecorder start error: ${JSON.stringify(err)}` })
}
}
}
... ... @@ -357,22 +349,22 @@ struct CreateCamera {
if (this.videoOutput) {
this.videoOutput.stop((err: BusinessError) => {
if (err) {
promptAction.showToast({ message: `Failed to stop the video output. error: ${JSON.stringify(err)}` })
// promptAction.showToast({ message: `Failed to stop the video output. error: ${JSON.stringify(err)}` })
return;
}
promptAction.showToast({message: 'Callback invoked to indicate the video output stop success.'})
// promptAction.showToast({message: 'Callback invoked to indicate the video output stop success.'})
});
}
try {
await this.avRecorder.stop();
await this.avRecorder.release();
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `avRecorder stop error: ${JSON.stringify(err)}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `avRecorder stop error: ${JSON.stringify(err)}` })
}
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `avRecorder stop error: ${JSON.stringify(err)}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `avRecorder stop error: ${JSON.stringify(err)}` })
}
try {
if (this.captureSession) {
... ... @@ -394,8 +386,8 @@ struct CreateCamera {
this.captureSession = undefined;
}
} catch (error) {
let err = error as BusinessError;
promptAction.showToast({ message: `avRecorder stop error: ${JSON.stringify(err)}` })
// let err = error as BusinessError;
// promptAction.showToast({ message: `avRecorder stop error: ${JSON.stringify(err)}` })
}
}
}
... ...
... ... @@ -38,6 +38,7 @@ struct DetailRecords {
@State maintenanceComment: string = ''
@State isShowCloudDown: boolean = false
aboutToAppear(): void {
AppStorage.setOrCreate('videoPath', '');
if(!AppStorage.get('isShowTip')) {
this.uploadController.open()
}
... ...
... ... @@ -2,7 +2,7 @@ import AreaPickerDialog from '../dialog/AreaPickerDialog'
import { companyTest, companyData } from '../api/userType'
import preferencesUtil from '../utils/preferences'
import baseUrl from '../utils/baseUrl'
import { ValidateInputHandle } from '../utils/validateInputHandle'
import { ValidateInputHandle, ValidateHandle } from '../utils/validateInputHandle'
import { updateCompanyInfo, getEmailCode, getCompanyInfo, emailType } from '../api/user'
import { promptAction } from '@kit.ArkUI';
import { AxiosResponse } from '@ohos/axios'
... ... @@ -24,6 +24,7 @@ struct EditUser {
@State initEmail: string = this.companyInfo.email
@State codeStr: string = '' // 存储验证码对比
@State timerCount: number = 300
formKey: string[] = ['companyName', 'email', 'postCode', 'linkMan', 'lmTel', 'businessLicenseNo', 'businessLicensePic', 'address']
// 区域选择
areaController: CustomDialogController = new CustomDialogController({
builder: AreaPickerDialog({
... ... @@ -55,6 +56,15 @@ struct EditUser {
alignment: DialogAlignment.Top,
})
// 校验函数
ValidateHandle = (arr: string[], obj: companyData): boolean => {
let keyArr: string[] = Object.keys(obj)
let valueArr: (string | number | null)[] = Object.values(obj)
for(let i = 0; i < keyArr.length; i++) {
if(arr.includes(keyArr[i]) && valueArr[i] == '') return false
}
return true
}
// 获取验证码
getCode = async () => {
if(this.codeStr == '') {
... ... @@ -82,11 +92,10 @@ struct EditUser {
// 提交修改
submitForm = async () => {
let valueArr = Object.values(this.companyInfo) as (string | null | number)[]
let isEmpty = valueArr.every(item => item !== '')
if(!isEmpty) return promptAction.showToast({message: '带星号的为必填项'})
if(!this.ValidateHandle(this.formKey, this.companyInfo)) return promptAction.showToast({message: '带星号的为必填项'})
if(!ValidateInputHandle(this.companyInfo.lmTel, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
if(!ValidateInputHandle(this.companyInfo.email, 'email')) return promptAction.showToast({message: '邮箱输入有误'})
if(!ValidateInputHandle(this.companyInfo.businessLicenseNo, 'businessLicenseNo')) return promptAction.showToast({message: '请正确填写社会信用代码'})
if(this.isShowCode && (this.companyInfo.code == '' || this.companyInfo.code == undefined)) return promptAction.showToast({message: '请输入验证码'})
if(this.isShowCode && this.companyInfo.code !== this.codeStr) return promptAction.showToast({message: '验证码输入有误'})
... ... @@ -97,7 +106,10 @@ struct EditUser {
promptAction.showToast({ message: '修改成功', duration: 2000 })
}
aboutToAppear() {
async aboutToAppear() {
const info: AxiosResponse<companyTest> = await getCompanyInfo()
preferencesUtil.set('XF_COMPANY_INFO', JSON.stringify(info.data.data))
this.companyInfo = JSON.parse(preferencesUtil.get('XF_COMPANY_INFO', '') as string)
this.companyInfo.address = this.pickerValue.join(' ')
}
build() {
... ... @@ -119,6 +131,7 @@ struct EditUser {
}.width(90)
TextInput({placeholder: '请输入邮箱', text: $$this.companyInfo.email})
.backgroundColor('#fff').layoutWeight(1).type(InputType.Email)
.showError(ValidateInputHandle(this.companyInfo.email, 'email') ? '' : '请正确输入邮箱')
.onChange((value) => { this.isShowCode = this.initEmail !== value })
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
... ... @@ -150,6 +163,7 @@ struct EditUser {
}
TextInput({placeholder: '请输入手机号', text: $$this.companyInfo.lmTel})
.backgroundColor('#fff').layoutWeight(1).type(InputType.PhoneNumber)
.showError(ValidateInputHandle(this.companyInfo.lmTel, 'phone') ? '' : '请正确输入手机号')
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
... ...
... ... @@ -25,7 +25,11 @@ struct EditUser {
@State initEmail: string = this.userInfo.email
@State codeStr: string = '' // 存储验证码对比
@State timerCount: number = 300
aboutToAppear() {
formKey: string[] = ['personName', 'email', 'birthDate', 'idNo', 'phone', 'personalImg', 'idImgFront', 'idImgBack']
async aboutToAppear() {
const info: AxiosResponse<personTest> = await getPersonInfo()
preferencesUtil.set('XF_PERSON_INFO', JSON.stringify(info.data.data))
this.userInfo = JSON.parse(preferencesUtil.get('XF_PERSON_INFO', '') as string)
this.userInfo.address = this.pickerValue.join(' ')
}
// 区域弹窗
... ... @@ -80,11 +84,20 @@ struct EditUser {
})
}
}
// 校验函数
ValidateHandle = (arr: string[], obj: personData): boolean => {
let keyArr: string[] = Object.keys(obj)
let valueArr: (string | number | null)[] = Object.values(obj)
for(let i = 0; i < keyArr.length; i++) {
if(arr.includes(keyArr[i]) && valueArr[i] == '') return false
}
return true
}
// 提交修改
submitForm = async () => {
let valueArr = Object.values(this.userInfo) as (string | null | number)[]
let isEmpty = valueArr.every(item => item !== '')
if(!isEmpty) return promptAction.showToast({message: '带星号的为必填项'})
if(!this.ValidateHandle(this.formKey, this.userInfo)) return promptAction.showToast({message: '带星号的为必填项'})
if(!ValidateInputHandle(this.userInfo.idNo, 'idCard')) return promptAction.showToast({message: '身份证输入有误'})
if(!ValidateInputHandle(this.userInfo.phone, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
if(!ValidateInputHandle(this.userInfo.email, 'email')) return promptAction.showToast({message: '邮箱输入有误'})
... ...
... ... @@ -32,10 +32,10 @@ struct FireProtectionDetail {
webviewController: webview.WebviewController = new webview.WebviewController()
onPageShow() {
let pathUrl = (router.getParams() as commonRouterParams)?.videoPath || ''
console.log('pathUrl', pathUrl)
if (pathUrl !== '' || pathUrl !== undefined || pathUrl !== null) {
let pathUrl: string | null | undefined = AppStorage.get('videoPath')
if (pathUrl !== '' && pathUrl !== undefined && pathUrl !== null) {
this.uploadMethods(this.cosKeyStr, this.relateId, pathUrl, 'mp4')
AppStorage.set('videoPath', '')
}
}
aboutToAppear(): void {
... ... @@ -140,7 +140,7 @@ struct FireProtectionDetail {
} else if(formatData[0] == '鸿蒙视频上传'){
// 使用相机录像
if (checkAccessToken(this.permissions)) {
router.pushUrl({ url: 'pages/CreateCamera', params: this.projectInfo })
router.pushUrl({ url: 'pages/CreateCamera' })
}
}
return false
... ...
... ... @@ -68,12 +68,6 @@ struct MyWallet {
this.walletData = walletInfo.data.rows[0]
}
// 获取是否显示充值
// getShowPay = async () => {
// const payInfo: AxiosResponse<beanType> = await getPay()
// this.isShowPay = payInfo.data.msg == "true"
// }
async aboutToAppear(){
Promise.all([
this.getList(),
... ...
import AreaPickerDialog from '../dialog/AreaPickerDialog'
import { personData, personTest } from '../api/userType'
import baseUrl from '../utils/baseUrl'
import { router } from '@kit.ArkUI';
import { AxiosResponse } from '@ohos/axios'
import NavHeader from '../components/NavHeader'
import { getPersonDetail } from '../api/user'
import PhotoBrowser from '../dialog/PhotoBrowserDialog'
interface routerQuery {
personId: number
}
... ... @@ -53,20 +55,20 @@ struct EditUser {
companyId: 0,
}
@State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
areaController: CustomDialogController = new CustomDialogController({
builder: AreaPickerDialog({
value:this.pickerValue,//首次默认选中值
onChange: (value:string[]) => {//选择改变回调
this.pickerValue = value
this.userInfo.address = this.pickerValue.join(' ')
}
}),
customStyle: true
@State photoList: (string | ResourceStr)[] = [] // 预览图片列表
// 图片预览
photoBrowserController: CustomDialogController = new CustomDialogController({
builder: PhotoBrowser({ imagesList: this.photoList}),
customStyle: true,
offset: { dx: 0, dy: 0 },
alignment: DialogAlignment.Top,
})
async aboutToAppear(){
let res: AxiosResponse<personTest> = await getPersonDetail(personId)
this.userInfo = res.data.data
this.photoList = [baseUrl + this.userInfo.personalImg || $r('app.media.userAvatar'), baseUrl + this.userInfo.idImgFront || $r('app.media.idCard'), baseUrl + this.userInfo.idImgBack || $r('app.media.unIdCard')]
}
build() {
Column(){
... ... @@ -134,7 +136,7 @@ struct EditUser {
}.width(90)
Row(){
Image(baseUrl + this.userInfo.personalImg || $r('app.media.userAvatar')).width(60)
}.margin({left: 20})
}.margin({left: 20}).onClick(() => this.photoBrowserController.open())
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}).width('100%')
.justifyContent(FlexAlign.SpaceBetween).height(80)
Row(){
... ... @@ -143,7 +145,7 @@ struct EditUser {
}.width(90)
Row(){
Image(baseUrl + this.userInfo.idImgFront || $r('app.media.idCard')).width(60)
}.margin({left: 20})
}.margin({left: 20}).onClick(() => this.photoBrowserController.open())
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}).width('100%')
.justifyContent(FlexAlign.SpaceBetween).height(80)
Row(){
... ... @@ -152,7 +154,7 @@ struct EditUser {
}.width(90)
Row(){
Image(baseUrl + this.userInfo.idImgBack || $r('app.media.unIdCard')).width(60)
}.margin({left: 20})
}.margin({left: 20}).onClick(() => this.photoBrowserController.open())
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}).width('100%')
.justifyContent(FlexAlign.SpaceBetween).height(80)
Row(){
... ...
... ... @@ -10,6 +10,7 @@ import { uploadFile, uploadResult } from '../utils/uploadFile'
import { uploadDocFile } from '../utils/uploadDocmentFile'
import { request } from '@kit.BasicServicesKit'
import NavHeader from '../components/NavHeader'
import LoadingDialog from '../dialog/LoadingDialog'
@Entry
... ... @@ -53,6 +54,7 @@ struct Register {
}
@State confirmPassword: string = ''
@State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
formKey: string[] = ['username', 'password', 'companyName', 'peopleNum', 'floorage', 'linkMan', 'email', 'lmTel', 'siteVoucher', 'businessLicenseNo', 'businessLicensePic']
dialogController: CustomDialogController = new CustomDialogController({
builder: CompanyCommit(),
autoCancel: false,
... ... @@ -85,6 +87,23 @@ struct Register {
this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入'
}
// 校验函数
ValidateHandle = (arr: string[], obj: companyData): boolean => {
let keyArr: string[] = Object.keys(obj)
let valueArr: (string | number | null)[] = Object.values(obj)
for(let i = 0; i < keyArr.length; i++) {
if(arr.includes(keyArr[i]) && valueArr[i] == '') return false
}
return true
}
// 加载弹窗
loadingController: CustomDialogController = new CustomDialogController({
builder: LoadingDialog(),
customStyle: true,
offset: { dx: 0, dy: 0 },
alignment: DialogAlignment.Center,
autoCancel: false
})
async aboutToAppear() {
this.dialogController.open()
this.companyInfo.address = this.pickerValue.join(' ')
... ... @@ -196,6 +215,7 @@ struct Register {
.backgroundColor('#1890ff').fontColor('#fff').borderRadius(4)
.onClick(async () => {
let that = this
that.loadingController.open()
let uploader = await uploadDocFile() as request.UploadTask
// 3. 监控上传错误
uploader.on('fail', (err) => {
... ... @@ -205,6 +225,8 @@ struct Register {
uploader.on('headerReceive',(res)=>{
let uploadInfo = JSON.parse(res['body']) as uploadResult
that.companyInfo.siteVoucher = uploadInfo.fileName as string
that.loadingController.close()
promptAction.showToast({message: '上传成功'})
})
})
Button('查看文件').controlSize(ControlSize.SMALL).type(ButtonType.Normal)
... ... @@ -283,11 +305,10 @@ struct Register {
Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
if(!this.ValidateHandle(this.formKey, this.companyInfo)) return promptAction.showToast({message: '带星号的为必填项'})
if(this.confirmPassword !== this.companyInfo.password) return promptAction.showToast({message: '两次密码输入不一致'})
if(!ValidateInputHandle(this.companyInfo.lmTel, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
if(!ValidateInputHandle(this.companyInfo.email, 'email')) return promptAction.showToast({message: '邮箱输入有误'})
let ValuesArr = Object.values(this.companyInfo) as (string | number | null)[]
if(!ValuesArr.every(item => item !== '')) return promptAction.showToast({message: '带型号的为必填项'})
await companyRegister(this.companyInfo)
promptAction.showToast({ message: '注册成功' })
router.back()
... ...
... ... @@ -42,6 +42,7 @@ struct UserRegister {
@State initEmail: string = this.userInfo.email
@State confirmPassword: string = ''
private selectedDate: Date = new Date('2000-01-01')
formKey: string[] = ['username', 'password', 'personName', 'birthDate', 'idNo', 'phone', 'personalImg', 'idImgFront', 'idImgBack']
dialogController: CustomDialogController = new CustomDialogController({
builder: UserCommit(),
autoCancel: false,
... ... @@ -66,8 +67,21 @@ struct UserRegister {
}
// 查身份证是否被占用
queryId = async (id: string) => {
const res: AxiosResponse<queryIdNoType> = await queryIdNo(id)
this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入'
if(id === '') {
this.idErrorMsg = '请输入身份证号'
} else {
const res: AxiosResponse<queryIdNoType> = await queryIdNo(id)
this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入'
}
}
// 校验函数
ValidateHandle = (arr: string[], obj: personData): boolean => {
let keyArr: string[] = Object.keys(obj)
let valueArr: (string | number | null)[] = Object.values(obj)
for(let i = 0; i < keyArr.length; i++) {
if(arr.includes(keyArr[i]) && valueArr[i] == '') return false
}
return true
}
async aboutToAppear() {
this.dialogController.open()
... ... @@ -282,12 +296,11 @@ struct UserRegister {
Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
if(!this.ValidateHandle(this.formKey, this.userInfo)) return promptAction.showToast({message: '带星号的为必填项'})
if(this.confirmPassword !== this.userInfo.password) return promptAction.showToast({message: '两次密码输入不一致'})
if(!ValidateInputHandle(this.userInfo.idNo, 'idCard')) return promptAction.showToast({message: '身份证输入有误'})
if(!ValidateInputHandle(this.userInfo.phone, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
if(!ValidateInputHandle(this.userInfo.email, 'email')) return promptAction.showToast({message: '邮箱输入有误'})
let valuesArr = Object.values(this.userInfo) as (string | number)[]
if(!valuesArr.every(item => item !== '')) return promptAction.showToast({message: '带星号的为必填项'})
await userRegister(this.userInfo)
promptAction.showToast({ message: '注册成功' })
router.back()
... ...
... ... @@ -12,7 +12,7 @@ export async function reqPermissionsFromUser(permissions: Array<Permissions>, co
if(grantStatus.every((numberItem: number) => numberItem === 0)){
promptAction.showToast({message: '授权成功'})
} else {
promptAction.showToast({message: '用户已取消授权'})
console.log('用户已取消授权')
}
} catch (err) {
promptAction.showToast({message: `Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`})
... ... @@ -27,7 +27,7 @@ export function checkAccessToken(permissions: Array<Permissions>): boolean {
try {
return permissions.every((permissionItem: Permissions) => atManager.verifyAccessTokenSync(callerTokenId, permissionItem) !== -1)
} catch (err) {
promptAction.showToast({message: `checkAccessToken catch err->${JSON.stringify(err)}`})
console.log(`checkAccessToken catch err->${JSON.stringify(err)}`)
return false
}
}
... ...
... ... @@ -111,7 +111,7 @@ export async function uploadFile() {
try {
let systemPhotoImagePath = await selectImg() // 选择图片
// let systemPhotoImagePath = await cameraPickerImg() // 使用相机拍照
if(systemPhotoImagePath == '') return promptAction.showToast({message: '未选择图片'})
if(systemPhotoImagePath === '' || systemPhotoImagePath === undefined || systemPhotoImagePath === null) return promptAction.showToast({message: '未选择图片'})
const fileData: string[] = await copyCachePath(systemPhotoImagePath)
let uploader = await request.uploadFile(getContext(),{ // 上传图片
url:'http://xfwbzshd.crgx.net/common/upload', // 请求地址
... ...
... ... @@ -29,3 +29,34 @@ export function ValidateInputHandle(input: string, type: typeValue): boolean {
throw new Error("传入的参数有误!")
}
}
// 校验函数
export function ValidateHandle(arr: string[], obj: Record<string, (string | number | null)>): boolean {
let keyArr: string[] = Object.keys(obj)
let valueArr = Object.values(obj) as (string | number | null )[]
for(let i = 0; i < keyArr.length; i++) {
console.log(keyArr[i], valueArr[i])
if(arr.includes(keyArr[i]) && valueArr[i] === '') return false
}
return true
}
interface objType {
username: string;
password: string;
phone: string;
email: string;
businessLicenseNo: string;
idCard: number;
}
let arrNew = ['username', 'password', 'phone', 'email', 'businessLicenseNo', 'idCard']
let objNew: objType = {
username: '',
password: '',
phone: '',
email: '',
businessLicenseNo: '',
idCard: 1234
}
\ No newline at end of file
... ...