作者 xiaoqiu

优化了代码,对新增修改维保记录以及用户编辑个人信息等功能进行优化

... ... @@ -26,7 +26,7 @@ export const loginOut = () => {
})
}
export interface updateStateParams {
export interface updateStateParams {
relateId: number
state: string
}
... ...
... ... @@ -94,6 +94,7 @@ export interface companyData {
levelModifyDate: null;
endTime: string;
password?: string
code?: string;
}
... ...
... ... @@ -34,7 +34,7 @@ function closeBtnBuilder(closeBlock: () => void) {
.height(60)
.borderRadius(30)
.margin({ top: 50, right: 40 })
.onClick((event) => {
.onClick(() => {
closeBlock()
})
}
... ... @@ -50,7 +50,7 @@ let adHeight: number = Math.round(screenHeight)
@Entry
@Component
export struct SplashAdDemoPage {
struct SplashAdDemoPage {
private mAdCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
private splashAd: CSJSplashAd | undefined
context = getContext(this)
... ... @@ -58,6 +58,7 @@ export struct SplashAdDemoPage {
@State errorMsg: string | undefined = undefined;
@State startLoad: boolean = false;
private mLoadListener: CSJSplashAdLoadListener = {
// 加载成功,直接展示广告
onAdLoaded: (splashAd: CSJSplashAd) => {
console.log("开屏回调 - onAdLoaded")
this.splashAd = splashAd;
... ... @@ -73,20 +74,25 @@ export struct SplashAdDemoPage {
this.useCustomCloseBtn ? globalCloseBtnBuilder : undefined)
}
},
// 加载失败,关闭广告并跳转到登录页
onError: (code: number, message: string) => {
this.errorMsg = "onError code: " + code + "message: " + message;
console.log(`开屏回调 - onError code: ${code} message: ${message}`)
this.closeWin()
router.replaceUrl({url: "pages/Login"})
},
// 广告渲染成功,展示广告
onRenderSuccess: (splashAd: CSJSplashAd) => {
this.splashAd = splashAd;
this.adLoadSuccess = true;
this.startLoad = false;
console.log("开屏回调 - onRenderSuccess")
},
onRenderFail: (code: number, message: string) => {
// 广告渲染失败,关闭广告并跳转到登录页
onRenderFail: () => {
console.log("开屏回调 - onRenderFail")
this.closeWin()
router.replaceUrl({url: "pages/Login"})
}
}
@State widthLabelText: string = "宽:" + adWidth
... ... @@ -100,11 +106,7 @@ export struct SplashAdDemoPage {
}
aboutToAppear(){
let adSlot = new AdSlotBuilder()
<<<<<<< HEAD
.setCodeId("103438700")
=======
.setCodeId("103397742")
>>>>>>> 2191e70067b776ee401629441f16bd4644393902
.setAcceptSize(adWidth,
adHeight)
.build()
... ... @@ -119,7 +121,6 @@ export struct SplashAdDemoPage {
Progress({ value: 0, total: 10, type: ProgressType.Ring })
.width(120).color('#409EFF').backgroundColor('#fff')
.style({ strokeWidth: 10, status: ProgressStatus.LOADING })
Image($r('app.media.logo')).width(60).height(60)
}
}.width('100%').height('100%').justifyContent(FlexAlign.Center)
... ... @@ -127,43 +128,44 @@ export struct SplashAdDemoPage {
// CSJSplashAdInteractionListener
private mSplashAdInteractionListener: CSJSplashAdInteractionListener = {
// 广告展示
onDidShow: () => {
console.log("开屏回调 - onDidShow")
// 聚合show信息获取
let info = this.splashAd?.getMediaExtraInfo()
if (info instanceof MediationAdInfo) {
let showcpm = info.getShowEcpm()
if (showcpm) {
console.log("GMMediation_showcpm", "adnName:"+showcpm.getAdnName())
console.log("GMMediation_showcpm", "ritType:"+showcpm.getRitType())
console.log("GMMediation_showcpm", "adnRitId:"+showcpm.getAdnRitId())
console.log("GMMediation_showcpm", "ecpm:"+showcpm.getEcpm())
let showCpm = info.getShowEcpm()
if (showCpm) {
console.log("GMMediation_showCpm", "adnName:"+showCpm.getAdnName())
console.log("GMMediation_showCpm", "ritType:"+showCpm.getRitType())
console.log("GMMediation_showCpm", "adnRitId:"+showCpm.getAdnRitId())
console.log("GMMediation_showCpm", "eCpm:"+showCpm.getEcpm())
}
}
},
// 关闭广告 closeType.value对应以下关闭原因1: 点击跳过,2: 展示倒计时时间到达,3: 点击广告,0: 其他
onDidClose: (closeType: CSJSplashAdCloseType) => {
this.splashAd = undefined
// 方式二:需自行移除广告
this.mWindow?.destroyWindow()
router.pushUrl({ url: "pages/Login"})
this.closeWin()
if(closeType.value == 1 || closeType.value == 2) {
this.closeWin()
router.pushUrl({ url: "pages/Login"})
}
},
// 广告被点击了
onDidClick: () => {
console.log("开屏回调 - onDidClick")
router.pushUrl({ url: "pages/Login"})
this.closeWin()
},
// 视频广告播放完成
onVideoDidPlayFinish: () => {
console.log("开屏回调 - onVideoDidPlayFinish")
this.closeWin()
},
// 视频广告播放错误
onVideoDidPlayFail: () => {
console.log("开屏回调 - onVideoDidPlayFail")
this.closeWin()
router.replaceUrl({url: "pages/Login"})
}
}
}
\ No newline at end of file
... ...
... ... @@ -34,12 +34,12 @@ interface comprehensiveType {
}
let params = router.getParams() as routerParams
let reportId: number | undefined = params?.reportId
// 查看原始记录编号是否存在
let queryReportNo = async (reportNo: string) => {
let res: AxiosResponse<RecordsList> = await getRecordsList({pageNum: 1, pageSize: 10, reportNo})
return res.data.total > 0
}
// 模糊查询
//模糊查询1:利用字符串的indexOf方法
function searchByIndexOf(keyWord: string, list: equipmentType[]){
... ... @@ -108,7 +108,8 @@ struct AddRecords {
@Builder indicatorBuilder(icon: ResourceStr) {
Image(icon)
}
searchController: SearchController = new SearchController()
personId = preferencesUtil.get('XF_PERSON_ID', 0)
flag: boolean = true
// 添加维保记录类型参数
@State addForm: addParamsType = {
reportName: '',
... ... @@ -129,11 +130,12 @@ struct AddRecords {
projectList: [],
equipmentList: [],
maintenancePeopleList: [],
technicalDirectorId: ''
technicalDirectorId: '',
county: '',
city: '',
}
personId = preferencesUtil.get('XF_PERSON_ID', 0)
@State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
@State comprehensiveReview: comprehensiveType = {
@State comprehensiveReview: comprehensiveType = { // 综合评述
range: '',
facility: '',
existingProblem: '',
... ... @@ -141,7 +143,7 @@ struct AddRecords {
other: '',
correctedProblems: '',
}
// 回显数据使用
// 回显消防设施和仪器设备数据使用
@State viewEquipmentList: string[] = []
@State fireFacilitiesList: string[] = []
// 维保人员列表
... ... @@ -158,10 +160,12 @@ struct AddRecords {
// 初始设备列表
@State initEquipmentList: equipmentType[] = []
@State errorMsg: string = ''
flag: boolean = true
@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)
... ... @@ -179,6 +183,8 @@ struct AddRecords {
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
... ... @@ -189,6 +195,7 @@ struct AddRecords {
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
})
... ... @@ -207,12 +214,8 @@ struct AddRecords {
this.companyPersonList = res.data.rows
})
}
@State changeValue: string = '';
@State text: string = "请选择维保记录类型"
@State index: number = 2
@State space: number = 8
@State arrowPosition: ArrowPosition = ArrowPosition.END
// 搜索框实例
searchController: SearchController = new SearchController()
// 选择区域弹窗
areaController: CustomDialogController = new CustomDialogController({
... ... @@ -225,7 +228,8 @@ struct AddRecords {
this.addForm.county = value[2]
}
}),
customStyle: true
customStyle: true,
autoCancel: false
})
// 加载弹窗
... ... @@ -236,6 +240,61 @@ struct AddRecords {
alignment: DialogAlignment.Center,
autoCancel: false
})
// 获取维保记录类型
getReportType = async (dictValue: string) => {
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
}
}
// 提交表单
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: '请选择维保人员'})
}
if(this.errorMsg !== '') {
return promptAction.showToast({message: '校验失败'})
}
if(!this.addForm.maintenancePeopleList?.includes(this.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: '添加成功'
})
router.back()
}
}
build() {
Column(){
NavHeader({title: '添加原始记录'})
... ... @@ -419,19 +478,7 @@ struct AddRecords {
Text(item.dictLabel)
}.margin({right: 5,bottom: 5})
Row().width(80).height(30).backgroundColor(Color.White).opacity(0.1)
.onClick(() => {
this.addForm.reportType = item.dictValue
if(this.flag) {
this.addForm.projectList = []
this.fireFacilitiesList = []
this.addForm.fireFacilities = ''
this.flag = false
getLatestProjectList(item.dictValue).then((res: AxiosResponse<LatestProjectTest>) => {
this.latestProjectList = res.data.data
this.flag = true
})
}
})
.onClick(async () => { await this.getReportType(item.dictValue) })
}
})
}
... ... @@ -591,44 +638,8 @@ struct AddRecords {
Row(){
Text('提交').borderRadius(5).width('100%').height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(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: '请选择维保人员'})
}
if(this.errorMsg !== '') {
return promptAction.showToast({message: '校验失败'})
}
if(!this.addForm.maintenancePeopleList?.includes(this.personId.toString())){
return promptAction.showToast({message: '本人必须在维护人员中'})
}
if(this.isEdit){
this.loadingController.open()
this.addForm.result = mergeRichText(this.comprehensiveReview)
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: '添加成功'
})
router.back()
}
.onClick(() => {
this.submitForm()
})
}.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10})
}.width('100%').height('100%').backgroundColor('#f2f3f7')
... ...
... ... @@ -130,11 +130,8 @@ struct EditUser {
Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
if(this.personCertificateInfo?.certificateNo == '') {
return promptAction.showToast({message: '证书编号不能为空'})
} else if(this.personCertificateInfo?.issueDate == '') {
return promptAction.showToast({message: '日期不能为空'})
}
let valueArr = Object.values(this.personCertificateInfo) as (string | number)[]
if(!valueArr.every(item => item !== '')) return promptAction.showToast({message: '请填写完整信息'})
if(this.isEdit) {
await updatePersonalCertificate(this.personCertificateInfo)
promptAction.showToast({
... ...
... ... @@ -3,13 +3,14 @@ import { companyTest, companyData } from '../api/userType'
import preferencesUtil from '../utils/preferences'
import baseUrl from '../utils/baseUrl'
import { ValidateInputHandle } from '../utils/validateInputHandle'
import { updateCompanyInfo, getEmailCode, getCompanyInfo } from '../api/user'
import { updateCompanyInfo, getEmailCode, getCompanyInfo, emailType } from '../api/user'
import { promptAction } from '@kit.ArkUI';
import { AxiosResponse } from '@ohos/axios'
import PhotoBrowser from '../dialog/PhotoBrowserDialog'
import { uploadFile, uploadResult } from '../utils/uploadFile'
import { request } from '@kit.BasicServicesKit'
import NavHeader from '../components/NavHeader'
import LoadingDialog from '../dialog/LoadingDialog'
@Entry
@Component
struct EditUser {
... ... @@ -21,6 +22,9 @@ struct EditUser {
@State pickerValue:string[] = [this.companyInfo.province, this.companyInfo.city, this.companyInfo.county] //省市区选中值
@State photoList: string[] = [baseUrl + this.companyInfo.businessLicensePic]
@State initEmail: string = this.companyInfo.email
@State codeStr: string = '' // 存储验证码对比
@State timerCount: number = 300
// 区域选择
areaController: CustomDialogController = new CustomDialogController({
builder: AreaPickerDialog({
value: this.pickerValue,//首次默认选中值
... ... @@ -32,8 +36,18 @@ struct EditUser {
this.companyInfo.county = this.pickerValue[2]
}
}),
customStyle: true
customStyle: true,
autoCancel: false
})
// 加载弹窗
loadingController: CustomDialogController = new CustomDialogController({
builder: LoadingDialog(),
customStyle: true,
offset: { dx: 0, dy: 0 },
alignment: DialogAlignment.Center,
autoCancel: false
})
// 图片预览
photoBrowserController: CustomDialogController = new CustomDialogController({
builder: PhotoBrowser({ imagesList: this.photoList}),
customStyle: true,
... ... @@ -41,6 +55,51 @@ struct EditUser {
alignment: DialogAlignment.Top,
})
// 获取验证码
getCode = async () => {
if(this.codeStr == '') {
this.loadingController.open()
let emailRes: AxiosResponse<emailType> = await getEmailCode(this.companyInfo.email)
this.codeStr = emailRes.data.data
this.loadingController.close()
let timer = setInterval(() => {
this.timerCount--
if(this.timerCount === 0){
clearInterval(timer)
this.codeStr = ''
this.timerCount = 300
}
}, 1000)
promptAction.showToast({
message: '已发送至邮箱,请查收'
})
} else {
promptAction.showToast({
message: '验证码已发送,300s内不在发送'
})
}
}
// 提交修改
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(!ValidateInputHandle(this.companyInfo.lmTel, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
if(!ValidateInputHandle(this.companyInfo.email, 'email')) 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: '验证码输入有误'})
await updateCompanyInfo(this.companyInfo)
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)
promptAction.showToast({ message: '修改成功', duration: 2000 })
}
aboutToAppear() {
this.companyInfo.address = this.pickerValue.join(' ')
}
build() {
Column(){
NavHeader({title: '修改企业信息'})
... ... @@ -60,9 +119,7 @@ struct EditUser {
}.width(90)
TextInput({placeholder: '请输入邮箱', text: $$this.companyInfo.email})
.backgroundColor('#fff').layoutWeight(1).type(InputType.Email)
.onChange((value) => {
this.isShowCode = this.initEmail !== value
})
.onChange((value) => { this.isShowCode = this.initEmail !== value })
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
... ... @@ -72,14 +129,9 @@ struct EditUser {
Row(){
TextInput({placeholder: '请输入验证码', text: $$this.companyInfo.postCode})
.backgroundColor('#fff').layoutWeight(1).type(InputType.Email)
Text('获取验证码').fontSize(12).backgroundColor('#1890ff').borderRadius(5)
Text(this.codeStr == '' ? '获取验证码' : `${this.timerCount}s后重新获取`).fontSize(12).backgroundColor('#1890ff').borderRadius(5)
.padding({top: 4, bottom: 4, left: 10, right: 10}).fontColor('#fff')
.onClick(async () => {
await getEmailCode(this.companyInfo.email)
promptAction.showToast({
message: '已发送至邮箱,请查收'
})
})
.onClick(() => { this.getCode() })
}.layoutWeight(1)
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
.visibility(this.isShowCode ? Visibility.Visible : Visibility.None)
... ... @@ -88,7 +140,7 @@ struct EditUser {
Image($r('app.media.require')).width(20)
Text('联系人')
}.width(90)
TextInput({placeholder: '请输入身份证号', text: $$this.companyInfo.linkMan})
TextInput({placeholder: '请输入联系人', text: $$this.companyInfo.linkMan})
.backgroundColor('#fff').layoutWeight(1)
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
... ... @@ -104,7 +156,7 @@ struct EditUser {
Image($r('app.media.require')).width(20)
Text('统一社会信用代码')
}
TextInput({placeholder: '请输入手机号', text: $$this.companyInfo.businessLicenseNo})
TextInput({placeholder: '统一社会信用代码', text: $$this.companyInfo.businessLicenseNo})
.backgroundColor('#fff').layoutWeight(1)
.showError(ValidateInputHandle(this.companyInfo.businessLicenseNo, 'businessLicenseNo') ? '' : '请正确输入社会统一信用代码')
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
... ... @@ -140,7 +192,7 @@ struct EditUser {
Text(this.pickerValue.join(' ')).layoutWeight(1).padding({top: 8, bottom: 8, left: 16, right: 16})
.backgroundColor('#fff').fontColor('#999').textOverflow({overflow: TextOverflow.Ellipsis}).maxLines(2)
.onClick(() => {
this.areaController?.open()
this.areaController.open()
})
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
}.backgroundColor('#fff').width('100%').padding({left: 5, right: 5}).borderRadius(10)
... ... @@ -148,26 +200,7 @@ struct EditUser {
Row({ space: 10}){
Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
if(this.companyInfo?.businessLicenseNo == '') {
return promptAction.showToast({message: '社会统一代码不能为空'})
} else if(this.companyInfo?.email == '') {
return promptAction.showToast({message: '邮箱不能为空'})
} else if(this.companyInfo?.linkMan == '') {
return promptAction.showToast({message: '联系人不能为空'})
} else if(this.companyInfo?.lmTel == '') {
return promptAction.showToast({message: '手机号不能为空'})
}
await updateCompanyInfo(this.companyInfo)
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)
promptAction.showToast({
message: '修改成功',
duration: 2000
})
})
.onClick(async () => { this.submitForm() })
Text('图片预览').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
... ...
... ... @@ -3,14 +3,14 @@ import { ValidateInputHandle } from '../utils/validateInputHandle'
import { personData, personTest } from '../api/userType'
import preferencesUtil from '../utils/preferences'
import baseUrl from '../utils/baseUrl'
import { updatePersonInfo, getPersonInfo, getEmailCode } from '../api/user'
import { updatePersonInfo, getPersonInfo, getEmailCode, emailType } from '../api/user'
import { promptAction } from '@kit.ArkUI';
import { AxiosResponse } from '@ohos/axios'
import PhotoBrowser from '../dialog/PhotoBrowserDialog'
import { uploadFile, uploadResult } from '../utils/uploadFile'
import { request } from '@kit.BasicServicesKit'
import NavHeader from '../components/NavHeader'
import LoadingDialog from '../dialog/LoadingDialog'
@Entry
@Component
... ... @@ -21,8 +21,14 @@ struct EditUser {
@State isShowCode: boolean = false
@State userInfo: personData = JSON.parse(preferencesUtil.get('XF_PERSON_INFO', '') as string)
@State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
@State photoList: string[] = [baseUrl + this.userInfo.personalImg, baseUrl + this.userInfo.idImgFront, baseUrl + this.userInfo.idImgBack,]
@State photoList: string[] = [baseUrl + this.userInfo.personalImg, baseUrl + this.userInfo.idImgFront, baseUrl + this.userInfo.idImgBack]
@State initEmail: string = this.userInfo.email
@State codeStr: string = '' // 存储验证码对比
@State timerCount: number = 300
aboutToAppear() {
this.userInfo.address = this.pickerValue.join(' ')
}
// 区域弹窗
areaController: CustomDialogController = new CustomDialogController({
builder: AreaPickerDialog({
value:this.pickerValue,//首次默认选中值
... ... @@ -31,18 +37,66 @@ struct EditUser {
this.userInfo.address = this.pickerValue.join(' ')
}
}),
customStyle: true
customStyle: true,
autoCancel: false
})
private selectedDate: Date = new Date('2000-01-01')
// 图片预览
photoBrowserController: CustomDialogController = new CustomDialogController({
builder: PhotoBrowser({ imagesList: this.photoList}),
customStyle: true,
offset: { dx: 0, dy: 0 },
alignment: DialogAlignment.Top,
})
aboutToAppear(): void {
console.log(JSON.stringify(this.userInfo))
// 加载弹窗
loadingController: CustomDialogController = new CustomDialogController({
builder: LoadingDialog(),
customStyle: true,
offset: { dx: 0, dy: 0 },
alignment: DialogAlignment.Center,
autoCancel: false
})
// 获取验证码
getCode = async () => {
if(this.codeStr == '') {
this.loadingController.open()
let emailRes: AxiosResponse<emailType> = await getEmailCode(this.userInfo.email)
this.codeStr = emailRes.data.data
this.loadingController.close()
let timer = setInterval(() => {
this.timerCount--
if(this.timerCount === 0){
clearInterval(timer)
this.codeStr = ''
this.timerCount = 300
}
}, 1000)
promptAction.showToast({
message: '已发送至邮箱,请查收'
})
} else {
promptAction.showToast({
message: '验证码已发送,300s内不在发送'
})
}
}
// 提交修改
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(!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: '邮箱输入有误'})
if(this.isShowCode && (this.userInfo.code == '' || this.userInfo.code == undefined)) return promptAction.showToast({message: '请输入验证码'})
if(this.isShowCode && this.userInfo.code !== this.codeStr) return promptAction.showToast({message: '验证码输入有误'})
await updatePersonInfo(this.userInfo)
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)
promptAction.showToast({ message: '修改成功', duration: 2000 })
}
build() {
Column(){
NavHeader({title: '编辑个人信息'})
... ... @@ -77,13 +131,10 @@ struct EditUser {
Row(){
TextInput({placeholder: '请输入验证码', text: $$this.userInfo.code})
.backgroundColor('#fff').layoutWeight(1)
Text('获取验证码').fontSize(12).backgroundColor('#1890ff').borderRadius(5)
Text(this.codeStr == '' ? '获取验证码' : `${this.timerCount}s后重新获取`).fontSize(12).backgroundColor('#1890ff').borderRadius(5)
.padding({top: 4, bottom: 4, left: 10, right: 10}).fontColor('#fff')
.onClick(async () => {
await getEmailCode(this.userInfo.email)
promptAction.showToast({
message: '已发送至邮箱,请查收'
})
.onClick(() => {
this.getCode()
})
}.layoutWeight(1)
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
... ... @@ -233,34 +284,13 @@ struct EditUser {
}.backgroundColor('#fff').width('100%').padding({left: 5, right: 5}).borderRadius(10)
}.padding(10).margin({bottom: 20, top: 10})
}.layoutWeight(1).scrollBar(BarState.Off)
// 底部区域
Row({ space: 10}){
Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
if(this.userInfo?.personName == '') {
return promptAction.showToast({message: '姓名不能为空'})
} else if(this.userInfo?.email == '') {
return promptAction.showToast({message: '邮箱不能为空'})
} else if(this.userInfo?.idNo == '') {
return promptAction.showToast({message: '身份证不能为空'})
} else if(this.userInfo?.phone == '') {
return promptAction.showToast({message: '手机号不能为空'})
} else if(this.userInfo?.idImgFront == '') {
return promptAction.showToast({message: '身份证件不能为空'})
} else if(this.userInfo?.idImgBack == '') {
return promptAction.showToast({message: '身份证件不能为空'})
} else if(this.userInfo?.personalImg == '') {
return promptAction.showToast({message: '请上传头像'})
}
await updatePersonInfo(this.userInfo)
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)
promptAction.showToast({
message: '修改成功',
duration: 2000
})
.onClick(() => {
this.submitForm()
})
Text('图片预览').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
... ...
... ... @@ -14,7 +14,7 @@ import NavHeader from '../components/NavHeader'
@Entry
@Component
struct UserRegister {
struct Register {
@Builder indicatorBuilder(icon: ResourceStr) {
Image(icon)
}
... ... @@ -52,12 +52,12 @@ struct UserRegister {
password: ''
}
@State confirmPassword: string = ''
@State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
dialogController: CustomDialogController = new CustomDialogController({
builder: CompanyCommit(),
autoCancel: false,
customStyle: true
})
@State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
areaController: CustomDialogController = new CustomDialogController({
builder: AreaPickerDialog({
value:this.pickerValue,//首次默认选中值
... ... @@ -69,11 +69,9 @@ struct UserRegister {
this.companyInfo.county = value[2]
}
}),
customStyle: true
customStyle: true,
autoCancel: false
})
async aboutToAppear() {
this.dialogController.open()
}
// 查询用户名是否被占用
queryName = async (userName: string) => {
... ... @@ -86,6 +84,14 @@ struct UserRegister {
const res: AxiosResponse<queryIdNoType> = await queryIdNo(id)
this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入'
}
async aboutToAppear() {
this.dialogController.open()
this.companyInfo.address = this.pickerValue.join(' ')
this.companyInfo.province = this.pickerValue[0]
this.companyInfo.city = this.pickerValue[1]
this.companyInfo.county = this.pickerValue[2]
}
build() {
Column(){
NavHeader({title: '注册'})
... ... @@ -277,26 +283,13 @@ struct UserRegister {
Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
console.log(JSON.stringify(this.companyInfo))
if(this.confirmPassword !== this.companyInfo.password) {
return promptAction.showToast({message: '两次密码输入不一致'})
}
if(this.companyInfo?.businessLicenseNo == '') {
return promptAction.showToast({message: '社会统一代码不能为空'})
} else if(this.companyInfo?.email == '') {
return promptAction.showToast({message: '邮箱不能为空'})
} else if(this.companyInfo?.linkMan == '') {
return promptAction.showToast({message: '联系人不能为空'})
} else if(this.companyInfo?.lmTel == '') {
return promptAction.showToast({message: '手机号不能为空'})
} else if(this.companyInfo?.username == '') {
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: '注册成功',
duration: 2000
})
promptAction.showToast({ message: '注册成功' })
router.back()
})
}.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10})
... ...
... ... @@ -38,15 +38,16 @@ struct UserRegister {
userId: 0,
state: ''
}
private selectedDate: Date = new Date('2000-01-01')
@State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
@State initEmail: string = this.userInfo.email
@State confirmPassword: string = ''
private selectedDate: Date = new Date('2000-01-01')
dialogController: CustomDialogController = new CustomDialogController({
builder: UserCommit(),
autoCancel: false,
customStyle: true
})
@State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
@State initEmail: string = this.userInfo.email
// 区域弹窗
areaController: CustomDialogController = new CustomDialogController({
builder: AreaPickerDialog({
value:this.pickerValue,//首次默认选中值
... ... @@ -55,23 +56,23 @@ struct UserRegister {
this.userInfo.address = this.pickerValue.join(' ')
}
}),
customStyle: true
customStyle: true,
autoCancel: false
})
async aboutToAppear() {
this.dialogController.open()
}
// 查询用户名是否被占用
queryName = async (userName: string) => {
const res: AxiosResponse<queryUserNameType> = await queryUsername(userName)
this.userErrorMsg = res.data.data == 1 ? '' : res.data.msg
}
}
// 查身份证是否被占用
queryId = async (id: string) => {
const res: AxiosResponse<queryIdNoType> = await queryIdNo(id)
this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入'
}
}
async aboutToAppear() {
this.dialogController.open()
this.userInfo.address = this.pickerValue.join(' ')
}
build() {
Column(){
NavHeader({title: '用户注册'})
... ... @@ -281,29 +282,14 @@ struct UserRegister {
Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
if(this.confirmPassword !== this.userInfo.password) {
return promptAction.showToast({message: '两次密码输入不一致'})
}
if(this.userInfo?.personName == '') {
return promptAction.showToast({message: '姓名不能为空'})
} else if(this.userInfo?.email == '') {
return promptAction.showToast({message: '邮箱不能为空'})
} else if(this.userInfo?.idNo == '') {
return promptAction.showToast({message: '身份证不能为空'})
} else if(this.userInfo?.phone == '') {
return promptAction.showToast({message: '手机号不能为空'})
} else if(this.userInfo.idImgFront == '') {
return promptAction.showToast({message: '身份证件不能为空'})
} else if(this.userInfo.idImgBack == '') {
return promptAction.showToast({message: '身份证件不能为空'})
} else if(this.userInfo?.personalImg == '') {
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: '注册成功',
duration: 2000
})
promptAction.showToast({ message: '注册成功' })
router.back()
})
}.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10})
... ...
... ... @@ -10,7 +10,7 @@ export function ValidateInputHandle(input: string, type: typeValue): boolean {
const phoneRegex = /^1[3456789]\d{9}$/
return phoneRegex.test(input)
case "email":
const emailRegex = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(com|cn|net|org|edu|gov|io|co)$/;
return emailRegex.test(input)
case "businessLicenseNo":
const businessLicenseNoRegex = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/
... ...