作者 xiaoqiu

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

@@ -94,6 +94,7 @@ export interface companyData { @@ -94,6 +94,7 @@ export interface companyData {
94 levelModifyDate: null; 94 levelModifyDate: null;
95 endTime: string; 95 endTime: string;
96 password?: string 96 password?: string
  97 + code?: string;
97 } 98 }
98 99
99 100
@@ -34,7 +34,7 @@ function closeBtnBuilder(closeBlock: () => void) { @@ -34,7 +34,7 @@ function closeBtnBuilder(closeBlock: () => void) {
34 .height(60) 34 .height(60)
35 .borderRadius(30) 35 .borderRadius(30)
36 .margin({ top: 50, right: 40 }) 36 .margin({ top: 50, right: 40 })
37 - .onClick((event) => { 37 + .onClick(() => {
38 closeBlock() 38 closeBlock()
39 }) 39 })
40 } 40 }
@@ -50,7 +50,7 @@ let adHeight: number = Math.round(screenHeight) @@ -50,7 +50,7 @@ let adHeight: number = Math.round(screenHeight)
50 50
51 @Entry 51 @Entry
52 @Component 52 @Component
53 -export struct SplashAdDemoPage { 53 +struct SplashAdDemoPage {
54 private mAdCreator: CSJAdCreator = CSJAdSdk.getAdCreator() 54 private mAdCreator: CSJAdCreator = CSJAdSdk.getAdCreator()
55 private splashAd: CSJSplashAd | undefined 55 private splashAd: CSJSplashAd | undefined
56 context = getContext(this) 56 context = getContext(this)
@@ -58,6 +58,7 @@ export struct SplashAdDemoPage { @@ -58,6 +58,7 @@ export struct SplashAdDemoPage {
58 @State errorMsg: string | undefined = undefined; 58 @State errorMsg: string | undefined = undefined;
59 @State startLoad: boolean = false; 59 @State startLoad: boolean = false;
60 private mLoadListener: CSJSplashAdLoadListener = { 60 private mLoadListener: CSJSplashAdLoadListener = {
  61 + // 加载成功,直接展示广告
61 onAdLoaded: (splashAd: CSJSplashAd) => { 62 onAdLoaded: (splashAd: CSJSplashAd) => {
62 console.log("开屏回调 - onAdLoaded") 63 console.log("开屏回调 - onAdLoaded")
63 this.splashAd = splashAd; 64 this.splashAd = splashAd;
@@ -73,20 +74,25 @@ export struct SplashAdDemoPage { @@ -73,20 +74,25 @@ export struct SplashAdDemoPage {
73 this.useCustomCloseBtn ? globalCloseBtnBuilder : undefined) 74 this.useCustomCloseBtn ? globalCloseBtnBuilder : undefined)
74 } 75 }
75 }, 76 },
76 - 77 + // 加载失败,关闭广告并跳转到登录页
77 onError: (code: number, message: string) => { 78 onError: (code: number, message: string) => {
78 this.errorMsg = "onError code: " + code + "message: " + message; 79 this.errorMsg = "onError code: " + code + "message: " + message;
79 console.log(`开屏回调 - onError code: ${code} message: ${message}`) 80 console.log(`开屏回调 - onError code: ${code} message: ${message}`)
  81 + this.closeWin()
  82 + router.replaceUrl({url: "pages/Login"})
80 }, 83 },
81 - 84 + // 广告渲染成功,展示广告
82 onRenderSuccess: (splashAd: CSJSplashAd) => { 85 onRenderSuccess: (splashAd: CSJSplashAd) => {
83 this.splashAd = splashAd; 86 this.splashAd = splashAd;
84 this.adLoadSuccess = true; 87 this.adLoadSuccess = true;
85 this.startLoad = false; 88 this.startLoad = false;
86 console.log("开屏回调 - onRenderSuccess") 89 console.log("开屏回调 - onRenderSuccess")
87 }, 90 },
88 - onRenderFail: (code: number, message: string) => { 91 + // 广告渲染失败,关闭广告并跳转到登录页
  92 + onRenderFail: () => {
89 console.log("开屏回调 - onRenderFail") 93 console.log("开屏回调 - onRenderFail")
  94 + this.closeWin()
  95 + router.replaceUrl({url: "pages/Login"})
90 } 96 }
91 } 97 }
92 @State widthLabelText: string = "宽:" + adWidth 98 @State widthLabelText: string = "宽:" + adWidth
@@ -100,11 +106,7 @@ export struct SplashAdDemoPage { @@ -100,11 +106,7 @@ export struct SplashAdDemoPage {
100 } 106 }
101 aboutToAppear(){ 107 aboutToAppear(){
102 let adSlot = new AdSlotBuilder() 108 let adSlot = new AdSlotBuilder()
103 -<<<<<<< HEAD  
104 .setCodeId("103438700") 109 .setCodeId("103438700")
105 -=======  
106 - .setCodeId("103397742")  
107 ->>>>>>> 2191e70067b776ee401629441f16bd4644393902  
108 .setAcceptSize(adWidth, 110 .setAcceptSize(adWidth,
109 adHeight) 111 adHeight)
110 .build() 112 .build()
@@ -119,7 +121,6 @@ export struct SplashAdDemoPage { @@ -119,7 +121,6 @@ export struct SplashAdDemoPage {
119 Progress({ value: 0, total: 10, type: ProgressType.Ring }) 121 Progress({ value: 0, total: 10, type: ProgressType.Ring })
120 .width(120).color('#409EFF').backgroundColor('#fff') 122 .width(120).color('#409EFF').backgroundColor('#fff')
121 .style({ strokeWidth: 10, status: ProgressStatus.LOADING }) 123 .style({ strokeWidth: 10, status: ProgressStatus.LOADING })
122 -  
123 Image($r('app.media.logo')).width(60).height(60) 124 Image($r('app.media.logo')).width(60).height(60)
124 } 125 }
125 }.width('100%').height('100%').justifyContent(FlexAlign.Center) 126 }.width('100%').height('100%').justifyContent(FlexAlign.Center)
@@ -127,43 +128,44 @@ export struct SplashAdDemoPage { @@ -127,43 +128,44 @@ export struct SplashAdDemoPage {
127 128
128 // CSJSplashAdInteractionListener 129 // CSJSplashAdInteractionListener
129 private mSplashAdInteractionListener: CSJSplashAdInteractionListener = { 130 private mSplashAdInteractionListener: CSJSplashAdInteractionListener = {
  131 + // 广告展示
130 onDidShow: () => { 132 onDidShow: () => {
131 console.log("开屏回调 - onDidShow") 133 console.log("开屏回调 - onDidShow")
132 // 聚合show信息获取 134 // 聚合show信息获取
133 let info = this.splashAd?.getMediaExtraInfo() 135 let info = this.splashAd?.getMediaExtraInfo()
134 if (info instanceof MediationAdInfo) { 136 if (info instanceof MediationAdInfo) {
135 - let showcpm = info.getShowEcpm()  
136 - if (showcpm) {  
137 - console.log("GMMediation_showcpm", "adnName:"+showcpm.getAdnName())  
138 - console.log("GMMediation_showcpm", "ritType:"+showcpm.getRitType())  
139 - console.log("GMMediation_showcpm", "adnRitId:"+showcpm.getAdnRitId())  
140 - console.log("GMMediation_showcpm", "ecpm:"+showcpm.getEcpm()) 137 + let showCpm = info.getShowEcpm()
  138 + if (showCpm) {
  139 + console.log("GMMediation_showCpm", "adnName:"+showCpm.getAdnName())
  140 + console.log("GMMediation_showCpm", "ritType:"+showCpm.getRitType())
  141 + console.log("GMMediation_showCpm", "adnRitId:"+showCpm.getAdnRitId())
  142 + console.log("GMMediation_showCpm", "eCpm:"+showCpm.getEcpm())
141 } 143 }
142 } 144 }
143 }, 145 },
144 - 146 + // 关闭广告 closeType.value对应以下关闭原因1: 点击跳过,2: 展示倒计时时间到达,3: 点击广告,0: 其他
145 onDidClose: (closeType: CSJSplashAdCloseType) => { 147 onDidClose: (closeType: CSJSplashAdCloseType) => {
146 this.splashAd = undefined 148 this.splashAd = undefined
147 // 方式二:需自行移除广告 149 // 方式二:需自行移除广告
148 this.mWindow?.destroyWindow() 150 this.mWindow?.destroyWindow()
149 - router.pushUrl({ url: "pages/Login"}) 151 + if(closeType.value == 1 || closeType.value == 2) {
150 this.closeWin() 152 this.closeWin()
  153 + router.pushUrl({ url: "pages/Login"})
  154 + }
151 }, 155 },
152 - 156 + // 广告被点击了
153 onDidClick: () => { 157 onDidClick: () => {
154 console.log("开屏回调 - onDidClick") 158 console.log("开屏回调 - onDidClick")
155 - router.pushUrl({ url: "pages/Login"})  
156 - this.closeWin()  
157 }, 159 },
158 - 160 + // 视频广告播放完成
159 onVideoDidPlayFinish: () => { 161 onVideoDidPlayFinish: () => {
160 console.log("开屏回调 - onVideoDidPlayFinish") 162 console.log("开屏回调 - onVideoDidPlayFinish")
161 - this.closeWin()  
162 }, 163 },
163 - 164 + // 视频广告播放错误
164 onVideoDidPlayFail: () => { 165 onVideoDidPlayFail: () => {
165 console.log("开屏回调 - onVideoDidPlayFail") 166 console.log("开屏回调 - onVideoDidPlayFail")
166 this.closeWin() 167 this.closeWin()
  168 + router.replaceUrl({url: "pages/Login"})
167 } 169 }
168 } 170 }
169 } 171 }
@@ -34,12 +34,12 @@ interface comprehensiveType { @@ -34,12 +34,12 @@ interface comprehensiveType {
34 } 34 }
35 let params = router.getParams() as routerParams 35 let params = router.getParams() as routerParams
36 let reportId: number | undefined = params?.reportId 36 let reportId: number | undefined = params?.reportId
  37 +
37 // 查看原始记录编号是否存在 38 // 查看原始记录编号是否存在
38 let queryReportNo = async (reportNo: string) => { 39 let queryReportNo = async (reportNo: string) => {
39 let res: AxiosResponse<RecordsList> = await getRecordsList({pageNum: 1, pageSize: 10, reportNo}) 40 let res: AxiosResponse<RecordsList> = await getRecordsList({pageNum: 1, pageSize: 10, reportNo})
40 return res.data.total > 0 41 return res.data.total > 0
41 } 42 }
42 -  
43 // 模糊查询 43 // 模糊查询
44 //模糊查询1:利用字符串的indexOf方法 44 //模糊查询1:利用字符串的indexOf方法
45 function searchByIndexOf(keyWord: string, list: equipmentType[]){ 45 function searchByIndexOf(keyWord: string, list: equipmentType[]){
@@ -108,7 +108,8 @@ struct AddRecords { @@ -108,7 +108,8 @@ struct AddRecords {
108 @Builder indicatorBuilder(icon: ResourceStr) { 108 @Builder indicatorBuilder(icon: ResourceStr) {
109 Image(icon) 109 Image(icon)
110 } 110 }
111 - searchController: SearchController = new SearchController() 111 + personId = preferencesUtil.get('XF_PERSON_ID', 0)
  112 + flag: boolean = true
112 // 添加维保记录类型参数 113 // 添加维保记录类型参数
113 @State addForm: addParamsType = { 114 @State addForm: addParamsType = {
114 reportName: '', 115 reportName: '',
@@ -129,11 +130,12 @@ struct AddRecords { @@ -129,11 +130,12 @@ struct AddRecords {
129 projectList: [], 130 projectList: [],
130 equipmentList: [], 131 equipmentList: [],
131 maintenancePeopleList: [], 132 maintenancePeopleList: [],
132 - technicalDirectorId: '' 133 + technicalDirectorId: '',
  134 + county: '',
  135 + city: '',
133 } 136 }
134 - personId = preferencesUtil.get('XF_PERSON_ID', 0)  
135 @State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值 137 @State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
136 - @State comprehensiveReview: comprehensiveType = { 138 + @State comprehensiveReview: comprehensiveType = { // 综合评述
137 range: '', 139 range: '',
138 facility: '', 140 facility: '',
139 existingProblem: '', 141 existingProblem: '',
@@ -141,7 +143,7 @@ struct AddRecords { @@ -141,7 +143,7 @@ struct AddRecords {
141 other: '', 143 other: '',
142 correctedProblems: '', 144 correctedProblems: '',
143 } 145 }
144 - // 回显数据使用 146 + // 回显消防设施和仪器设备数据使用
145 @State viewEquipmentList: string[] = [] 147 @State viewEquipmentList: string[] = []
146 @State fireFacilitiesList: string[] = [] 148 @State fireFacilitiesList: string[] = []
147 // 维保人员列表 149 // 维保人员列表
@@ -158,10 +160,12 @@ struct AddRecords { @@ -158,10 +160,12 @@ struct AddRecords {
158 // 初始设备列表 160 // 初始设备列表
159 @State initEquipmentList: equipmentType[] = [] 161 @State initEquipmentList: equipmentType[] = []
160 @State errorMsg: string = '' 162 @State errorMsg: string = ''
161 - flag: boolean = true 163 + @State text: string = "请选择维保记录类型"
162 async aboutToAppear() { 164 async aboutToAppear() {
163 // reportId等于undefined为编辑状态 165 // reportId等于undefined为编辑状态
164 this.isEdit = reportId !== undefined 166 this.isEdit = reportId !== undefined
  167 + this.addForm.city = this.pickerValue[1]
  168 + this.addForm.county = this.pickerValue[2]
165 if(reportId){ 169 if(reportId){
166 this.addForm.reportId = reportId 170 this.addForm.reportId = reportId
167 const res: AxiosResponse<reportDetailTest> = await getReportDetail(reportId) 171 const res: AxiosResponse<reportDetailTest> = await getReportDetail(reportId)
@@ -179,6 +183,8 @@ struct AddRecords { @@ -179,6 +183,8 @@ struct AddRecords {
179 this.addForm.state = result.state 183 this.addForm.state = result.state
180 this.addForm.technicalDirectorId = result.technicalDirectorId 184 this.addForm.technicalDirectorId = result.technicalDirectorId
181 this.addForm.maintenancePeopleList = result.technicalDirectorId?.split(',') 185 this.addForm.maintenancePeopleList = result.technicalDirectorId?.split(',')
  186 + this.addForm.city = result.city
  187 + this.addForm.county = result.county
182 this.addForm.approvePersonId = result.approvePersonId as number 188 this.addForm.approvePersonId = result.approvePersonId as number
183 this.addForm.projectList = result.projectList.map(item => { 189 this.addForm.projectList = result.projectList.map(item => {
184 return { projectId: item.projectId } as projectType 190 return { projectId: item.projectId } as projectType
@@ -189,6 +195,7 @@ struct AddRecords { @@ -189,6 +195,7 @@ struct AddRecords {
189 this.pickerValue = ['广西壮族自治区', result.city as string, result.county as string] 195 this.pickerValue = ['广西壮族自治区', result.city as string, result.county as string]
190 this.comprehensiveReview = extractRichText(result.result) 196 this.comprehensiveReview = extractRichText(result.result)
191 } 197 }
  198 + // 获取项目的类型列表
192 getMaintenanceType().then((res: AxiosResponse<quarterTest>) => { 199 getMaintenanceType().then((res: AxiosResponse<quarterTest>) => {
193 this.recordsType = res.data.data 200 this.recordsType = res.data.data
194 }) 201 })
@@ -207,12 +214,8 @@ struct AddRecords { @@ -207,12 +214,8 @@ struct AddRecords {
207 this.companyPersonList = res.data.rows 214 this.companyPersonList = res.data.rows
208 }) 215 })
209 } 216 }
210 -  
211 - @State changeValue: string = '';  
212 - @State text: string = "请选择维保记录类型"  
213 - @State index: number = 2  
214 - @State space: number = 8  
215 - @State arrowPosition: ArrowPosition = ArrowPosition.END 217 + // 搜索框实例
  218 + searchController: SearchController = new SearchController()
216 219
217 // 选择区域弹窗 220 // 选择区域弹窗
218 areaController: CustomDialogController = new CustomDialogController({ 221 areaController: CustomDialogController = new CustomDialogController({
@@ -225,7 +228,8 @@ struct AddRecords { @@ -225,7 +228,8 @@ struct AddRecords {
225 this.addForm.county = value[2] 228 this.addForm.county = value[2]
226 } 229 }
227 }), 230 }),
228 - customStyle: true 231 + customStyle: true,
  232 + autoCancel: false
229 }) 233 })
230 234
231 // 加载弹窗 235 // 加载弹窗
@@ -236,6 +240,61 @@ struct AddRecords { @@ -236,6 +240,61 @@ struct AddRecords {
236 alignment: DialogAlignment.Center, 240 alignment: DialogAlignment.Center,
237 autoCancel: false 241 autoCancel: false
238 }) 242 })
  243 +
  244 + // 获取维保记录类型
  245 + getReportType = async (dictValue: string) => {
  246 + this.addForm.reportType = dictValue
  247 + if(this.flag) {
  248 + this.addForm.projectList = []
  249 + this.fireFacilitiesList = []
  250 + this.addForm.fireFacilities = ''
  251 + this.flag = false
  252 + let result: AxiosResponse<LatestProjectTest> = await getLatestProjectList(dictValue)
  253 + this.latestProjectList = result.data.data
  254 + this.flag = true
  255 + }
  256 + }
  257 + // 提交表单
  258 + submitForm = async () => {
  259 + if(this.addForm.reportName == '') {
  260 + return promptAction.showToast({message: '项目名称为必填项'})
  261 + } else if(this.addForm.reportNo == '') {
  262 + return promptAction.showToast({message: '项目编号为必填项'})
  263 + } else if(this.addForm.applyCompanyName == ''){
  264 + return promptAction.showToast({message: '消防设施管理单位为必填项'})
  265 + } else if(this.addForm.maintenanceTime == '请选择起始日期' || this.addForm.maintenanceEndTime == '请选择结束日期'){
  266 + return promptAction.showToast({message: '维保日期为必填项'})
  267 + } else if(this.addForm.fireFacilities == ''){
  268 + return promptAction.showToast({message: '至少选择一下消防设施'})
  269 + } else if(this.addForm.maintenancePeople == ''){
  270 + return promptAction.showToast({message: '请选择维保人员'})
  271 + }
  272 + if(this.errorMsg !== '') {
  273 + return promptAction.showToast({message: '校验失败'})
  274 + }
  275 + if(!this.addForm.maintenancePeopleList?.includes(this.personId.toString())){
  276 + return promptAction.showToast({message: '本人必须在维护人员中'})
  277 + }
  278 + this.addForm.result = mergeRichText(this.comprehensiveReview)
  279 + if(this.isEdit){
  280 + this.loadingController.open()
  281 + await updateRecords(this.addForm)
  282 + this.loadingController.close()
  283 + promptAction.showToast({
  284 + message: '更新成功'
  285 + })
  286 + } else {
  287 + this.loadingController.open()
  288 + this.addForm.maintenanceDate = [this.addForm.maintenanceTime as string, this.addForm.maintenanceEndTime as string]
  289 + await addRecords(this.addForm)
  290 + this.loadingController.close()
  291 + promptAction.showToast({
  292 + message: '添加成功'
  293 + })
  294 + router.back()
  295 + }
  296 + }
  297 +
239 build() { 298 build() {
240 Column(){ 299 Column(){
241 NavHeader({title: '添加原始记录'}) 300 NavHeader({title: '添加原始记录'})
@@ -419,19 +478,7 @@ struct AddRecords { @@ -419,19 +478,7 @@ struct AddRecords {
419 Text(item.dictLabel) 478 Text(item.dictLabel)
420 }.margin({right: 5,bottom: 5}) 479 }.margin({right: 5,bottom: 5})
421 Row().width(80).height(30).backgroundColor(Color.White).opacity(0.1) 480 Row().width(80).height(30).backgroundColor(Color.White).opacity(0.1)
422 - .onClick(() => {  
423 - this.addForm.reportType = item.dictValue  
424 - if(this.flag) {  
425 - this.addForm.projectList = []  
426 - this.fireFacilitiesList = []  
427 - this.addForm.fireFacilities = ''  
428 - this.flag = false  
429 - getLatestProjectList(item.dictValue).then((res: AxiosResponse<LatestProjectTest>) => {  
430 - this.latestProjectList = res.data.data  
431 - this.flag = true  
432 - })  
433 - }  
434 - }) 481 + .onClick(async () => { await this.getReportType(item.dictValue) })
435 } 482 }
436 }) 483 })
437 } 484 }
@@ -591,44 +638,8 @@ struct AddRecords { @@ -591,44 +638,8 @@ struct AddRecords {
591 Row(){ 638 Row(){
592 Text('提交').borderRadius(5).width('100%').height(30).fontColor('#fff') 639 Text('提交').borderRadius(5).width('100%').height(30).fontColor('#fff')
593 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center) 640 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
594 - .onClick(async () => {  
595 - if(this.addForm.reportName == '') {  
596 - return promptAction.showToast({message: '项目名称为必填项'})  
597 - } else if(this.addForm.reportNo == '') {  
598 - return promptAction.showToast({message: '项目编号为必填项'})  
599 - } else if(this.addForm.applyCompanyName == ''){  
600 - return promptAction.showToast({message: '消防设施管理单位为必填项'})  
601 - } else if(this.addForm.maintenanceTime == '请选择起始日期' || this.addForm.maintenanceEndTime == '请选择结束日期'){  
602 - return promptAction.showToast({message: '维保日期为必填项'})  
603 - } else if(this.addForm.fireFacilities == ''){  
604 - return promptAction.showToast({message: '至少选择一下消防设施'})  
605 - } else if(this.addForm.maintenancePeople == ''){  
606 - return promptAction.showToast({message: '请选择维保人员'})  
607 - }  
608 - if(this.errorMsg !== '') {  
609 - return promptAction.showToast({message: '校验失败'})  
610 - }  
611 - if(!this.addForm.maintenancePeopleList?.includes(this.personId.toString())){  
612 - return promptAction.showToast({message: '本人必须在维护人员中'})  
613 - }  
614 - if(this.isEdit){  
615 - this.loadingController.open()  
616 - this.addForm.result = mergeRichText(this.comprehensiveReview)  
617 - await updateRecords(this.addForm)  
618 - this.loadingController.close()  
619 - promptAction.showToast({  
620 - message: '更新成功'  
621 - })  
622 - } else {  
623 - this.loadingController.open()  
624 - this.addForm.maintenanceDate = [this.addForm.maintenanceTime as string, this.addForm.maintenanceEndTime as string]  
625 - await addRecords(this.addForm)  
626 - this.loadingController.close()  
627 - promptAction.showToast({  
628 - message: '添加成功'  
629 - })  
630 - router.back()  
631 - } 641 + .onClick(() => {
  642 + this.submitForm()
632 }) 643 })
633 }.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10}) 644 }.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10})
634 }.width('100%').height('100%').backgroundColor('#f2f3f7') 645 }.width('100%').height('100%').backgroundColor('#f2f3f7')
@@ -130,11 +130,8 @@ struct EditUser { @@ -130,11 +130,8 @@ struct EditUser {
130 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff') 130 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
131 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center) 131 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
132 .onClick(async () => { 132 .onClick(async () => {
133 - if(this.personCertificateInfo?.certificateNo == '') {  
134 - return promptAction.showToast({message: '证书编号不能为空'})  
135 - } else if(this.personCertificateInfo?.issueDate == '') {  
136 - return promptAction.showToast({message: '日期不能为空'})  
137 - } 133 + let valueArr = Object.values(this.personCertificateInfo) as (string | number)[]
  134 + if(!valueArr.every(item => item !== '')) return promptAction.showToast({message: '请填写完整信息'})
138 if(this.isEdit) { 135 if(this.isEdit) {
139 await updatePersonalCertificate(this.personCertificateInfo) 136 await updatePersonalCertificate(this.personCertificateInfo)
140 promptAction.showToast({ 137 promptAction.showToast({
@@ -3,13 +3,14 @@ import { companyTest, companyData } from '../api/userType' @@ -3,13 +3,14 @@ import { companyTest, companyData } from '../api/userType'
3 import preferencesUtil from '../utils/preferences' 3 import preferencesUtil from '../utils/preferences'
4 import baseUrl from '../utils/baseUrl' 4 import baseUrl from '../utils/baseUrl'
5 import { ValidateInputHandle } from '../utils/validateInputHandle' 5 import { ValidateInputHandle } from '../utils/validateInputHandle'
6 -import { updateCompanyInfo, getEmailCode, getCompanyInfo } from '../api/user' 6 +import { updateCompanyInfo, getEmailCode, getCompanyInfo, emailType } from '../api/user'
7 import { promptAction } from '@kit.ArkUI'; 7 import { promptAction } from '@kit.ArkUI';
8 import { AxiosResponse } from '@ohos/axios' 8 import { AxiosResponse } from '@ohos/axios'
9 import PhotoBrowser from '../dialog/PhotoBrowserDialog' 9 import PhotoBrowser from '../dialog/PhotoBrowserDialog'
10 import { uploadFile, uploadResult } from '../utils/uploadFile' 10 import { uploadFile, uploadResult } from '../utils/uploadFile'
11 import { request } from '@kit.BasicServicesKit' 11 import { request } from '@kit.BasicServicesKit'
12 import NavHeader from '../components/NavHeader' 12 import NavHeader from '../components/NavHeader'
  13 +import LoadingDialog from '../dialog/LoadingDialog'
13 @Entry 14 @Entry
14 @Component 15 @Component
15 struct EditUser { 16 struct EditUser {
@@ -21,6 +22,9 @@ struct EditUser { @@ -21,6 +22,9 @@ struct EditUser {
21 @State pickerValue:string[] = [this.companyInfo.province, this.companyInfo.city, this.companyInfo.county] //省市区选中值 22 @State pickerValue:string[] = [this.companyInfo.province, this.companyInfo.city, this.companyInfo.county] //省市区选中值
22 @State photoList: string[] = [baseUrl + this.companyInfo.businessLicensePic] 23 @State photoList: string[] = [baseUrl + this.companyInfo.businessLicensePic]
23 @State initEmail: string = this.companyInfo.email 24 @State initEmail: string = this.companyInfo.email
  25 + @State codeStr: string = '' // 存储验证码对比
  26 + @State timerCount: number = 300
  27 + // 区域选择
24 areaController: CustomDialogController = new CustomDialogController({ 28 areaController: CustomDialogController = new CustomDialogController({
25 builder: AreaPickerDialog({ 29 builder: AreaPickerDialog({
26 value: this.pickerValue,//首次默认选中值 30 value: this.pickerValue,//首次默认选中值
@@ -32,8 +36,18 @@ struct EditUser { @@ -32,8 +36,18 @@ struct EditUser {
32 this.companyInfo.county = this.pickerValue[2] 36 this.companyInfo.county = this.pickerValue[2]
33 } 37 }
34 }), 38 }),
35 - customStyle: true 39 + customStyle: true,
  40 + autoCancel: false
36 }) 41 })
  42 + // 加载弹窗
  43 + loadingController: CustomDialogController = new CustomDialogController({
  44 + builder: LoadingDialog(),
  45 + customStyle: true,
  46 + offset: { dx: 0, dy: 0 },
  47 + alignment: DialogAlignment.Center,
  48 + autoCancel: false
  49 + })
  50 + // 图片预览
37 photoBrowserController: CustomDialogController = new CustomDialogController({ 51 photoBrowserController: CustomDialogController = new CustomDialogController({
38 builder: PhotoBrowser({ imagesList: this.photoList}), 52 builder: PhotoBrowser({ imagesList: this.photoList}),
39 customStyle: true, 53 customStyle: true,
@@ -41,6 +55,51 @@ struct EditUser { @@ -41,6 +55,51 @@ struct EditUser {
41 alignment: DialogAlignment.Top, 55 alignment: DialogAlignment.Top,
42 }) 56 })
43 57
  58 + // 获取验证码
  59 + getCode = async () => {
  60 + if(this.codeStr == '') {
  61 + this.loadingController.open()
  62 + let emailRes: AxiosResponse<emailType> = await getEmailCode(this.companyInfo.email)
  63 + this.codeStr = emailRes.data.data
  64 + this.loadingController.close()
  65 + let timer = setInterval(() => {
  66 + this.timerCount--
  67 + if(this.timerCount === 0){
  68 + clearInterval(timer)
  69 + this.codeStr = ''
  70 + this.timerCount = 300
  71 + }
  72 + }, 1000)
  73 + promptAction.showToast({
  74 + message: '已发送至邮箱,请查收'
  75 + })
  76 + } else {
  77 + promptAction.showToast({
  78 + message: '验证码已发送,300s内不在发送'
  79 + })
  80 + }
  81 + }
  82 +
  83 + // 提交修改
  84 + submitForm = async () => {
  85 + let valueArr = Object.values(this.companyInfo) as (string | null | number)[]
  86 + let isEmpty = valueArr.every(item => item !== '')
  87 + if(!isEmpty) return promptAction.showToast({message: '带星号的为必填项'})
  88 + if(!ValidateInputHandle(this.companyInfo.lmTel, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
  89 + if(!ValidateInputHandle(this.companyInfo.email, 'email')) return promptAction.showToast({message: '邮箱输入有误'})
  90 + if(this.isShowCode && (this.companyInfo.code == '' || this.companyInfo.code == undefined)) return promptAction.showToast({message: '请输入验证码'})
  91 + if(this.isShowCode && this.companyInfo.code !== this.codeStr) return promptAction.showToast({message: '验证码输入有误'})
  92 +
  93 + await updateCompanyInfo(this.companyInfo)
  94 + const info: AxiosResponse<companyTest> = await getCompanyInfo()
  95 + preferencesUtil.set('XF_COMPANY_INFO', JSON.stringify(info.data.data))
  96 + this.companyInfo = JSON.parse(preferencesUtil.get('XF_COMPANY_INFO', '') as string)
  97 + promptAction.showToast({ message: '修改成功', duration: 2000 })
  98 + }
  99 +
  100 + aboutToAppear() {
  101 + this.companyInfo.address = this.pickerValue.join(' ')
  102 + }
44 build() { 103 build() {
45 Column(){ 104 Column(){
46 NavHeader({title: '修改企业信息'}) 105 NavHeader({title: '修改企业信息'})
@@ -60,9 +119,7 @@ struct EditUser { @@ -60,9 +119,7 @@ struct EditUser {
60 }.width(90) 119 }.width(90)
61 TextInput({placeholder: '请输入邮箱', text: $$this.companyInfo.email}) 120 TextInput({placeholder: '请输入邮箱', text: $$this.companyInfo.email})
62 .backgroundColor('#fff').layoutWeight(1).type(InputType.Email) 121 .backgroundColor('#fff').layoutWeight(1).type(InputType.Email)
63 - .onChange((value) => {  
64 - this.isShowCode = this.initEmail !== value  
65 - }) 122 + .onChange((value) => { this.isShowCode = this.initEmail !== value })
66 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}) 123 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
67 Row(){ 124 Row(){
68 Row(){ 125 Row(){
@@ -72,14 +129,9 @@ struct EditUser { @@ -72,14 +129,9 @@ struct EditUser {
72 Row(){ 129 Row(){
73 TextInput({placeholder: '请输入验证码', text: $$this.companyInfo.postCode}) 130 TextInput({placeholder: '请输入验证码', text: $$this.companyInfo.postCode})
74 .backgroundColor('#fff').layoutWeight(1).type(InputType.Email) 131 .backgroundColor('#fff').layoutWeight(1).type(InputType.Email)
75 - Text('获取验证码').fontSize(12).backgroundColor('#1890ff').borderRadius(5) 132 + Text(this.codeStr == '' ? '获取验证码' : `${this.timerCount}s后重新获取`).fontSize(12).backgroundColor('#1890ff').borderRadius(5)
76 .padding({top: 4, bottom: 4, left: 10, right: 10}).fontColor('#fff') 133 .padding({top: 4, bottom: 4, left: 10, right: 10}).fontColor('#fff')
77 - .onClick(async () => {  
78 - await getEmailCode(this.companyInfo.email)  
79 - promptAction.showToast({  
80 - message: '已发送至邮箱,请查收'  
81 - })  
82 - }) 134 + .onClick(() => { this.getCode() })
83 }.layoutWeight(1) 135 }.layoutWeight(1)
84 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}) 136 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
85 .visibility(this.isShowCode ? Visibility.Visible : Visibility.None) 137 .visibility(this.isShowCode ? Visibility.Visible : Visibility.None)
@@ -88,7 +140,7 @@ struct EditUser { @@ -88,7 +140,7 @@ struct EditUser {
88 Image($r('app.media.require')).width(20) 140 Image($r('app.media.require')).width(20)
89 Text('联系人') 141 Text('联系人')
90 }.width(90) 142 }.width(90)
91 - TextInput({placeholder: '请输入身份证号', text: $$this.companyInfo.linkMan}) 143 + TextInput({placeholder: '请输入联系人', text: $$this.companyInfo.linkMan})
92 .backgroundColor('#fff').layoutWeight(1) 144 .backgroundColor('#fff').layoutWeight(1)
93 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}) 145 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
94 Row(){ 146 Row(){
@@ -104,7 +156,7 @@ struct EditUser { @@ -104,7 +156,7 @@ struct EditUser {
104 Image($r('app.media.require')).width(20) 156 Image($r('app.media.require')).width(20)
105 Text('统一社会信用代码') 157 Text('统一社会信用代码')
106 } 158 }
107 - TextInput({placeholder: '请输入手机号', text: $$this.companyInfo.businessLicenseNo}) 159 + TextInput({placeholder: '统一社会信用代码', text: $$this.companyInfo.businessLicenseNo})
108 .backgroundColor('#fff').layoutWeight(1) 160 .backgroundColor('#fff').layoutWeight(1)
109 .showError(ValidateInputHandle(this.companyInfo.businessLicenseNo, 'businessLicenseNo') ? '' : '请正确输入社会统一信用代码') 161 .showError(ValidateInputHandle(this.companyInfo.businessLicenseNo, 'businessLicenseNo') ? '' : '请正确输入社会统一信用代码')
110 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}) 162 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
@@ -140,7 +192,7 @@ struct EditUser { @@ -140,7 +192,7 @@ struct EditUser {
140 Text(this.pickerValue.join(' ')).layoutWeight(1).padding({top: 8, bottom: 8, left: 16, right: 16}) 192 Text(this.pickerValue.join(' ')).layoutWeight(1).padding({top: 8, bottom: 8, left: 16, right: 16})
141 .backgroundColor('#fff').fontColor('#999').textOverflow({overflow: TextOverflow.Ellipsis}).maxLines(2) 193 .backgroundColor('#fff').fontColor('#999').textOverflow({overflow: TextOverflow.Ellipsis}).maxLines(2)
142 .onClick(() => { 194 .onClick(() => {
143 - this.areaController?.open() 195 + this.areaController.open()
144 }) 196 })
145 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}) 197 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
146 }.backgroundColor('#fff').width('100%').padding({left: 5, right: 5}).borderRadius(10) 198 }.backgroundColor('#fff').width('100%').padding({left: 5, right: 5}).borderRadius(10)
@@ -148,26 +200,7 @@ struct EditUser { @@ -148,26 +200,7 @@ struct EditUser {
148 Row({ space: 10}){ 200 Row({ space: 10}){
149 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff') 201 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
150 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center) 202 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
151 - .onClick(async () => {  
152 - if(this.companyInfo?.businessLicenseNo == '') {  
153 - return promptAction.showToast({message: '社会统一代码不能为空'})  
154 - } else if(this.companyInfo?.email == '') {  
155 - return promptAction.showToast({message: '邮箱不能为空'})  
156 - } else if(this.companyInfo?.linkMan == '') {  
157 - return promptAction.showToast({message: '联系人不能为空'})  
158 - } else if(this.companyInfo?.lmTel == '') {  
159 - return promptAction.showToast({message: '手机号不能为空'})  
160 - }  
161 -  
162 - await updateCompanyInfo(this.companyInfo)  
163 - const info: AxiosResponse<companyTest> = await getCompanyInfo()  
164 - preferencesUtil.set('XF_COMPANY_INFO', JSON.stringify(info.data.data))  
165 - this.companyInfo = JSON.parse(preferencesUtil.get('XF_COMPANY_INFO', '') as string)  
166 - promptAction.showToast({  
167 - message: '修改成功',  
168 - duration: 2000  
169 - })  
170 - }) 203 + .onClick(async () => { this.submitForm() })
171 Text('图片预览').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff') 204 Text('图片预览').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
172 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center) 205 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
173 .onClick(async () => { 206 .onClick(async () => {
@@ -3,14 +3,14 @@ import { ValidateInputHandle } from '../utils/validateInputHandle' @@ -3,14 +3,14 @@ import { ValidateInputHandle } from '../utils/validateInputHandle'
3 import { personData, personTest } from '../api/userType' 3 import { personData, personTest } from '../api/userType'
4 import preferencesUtil from '../utils/preferences' 4 import preferencesUtil from '../utils/preferences'
5 import baseUrl from '../utils/baseUrl' 5 import baseUrl from '../utils/baseUrl'
6 -import { updatePersonInfo, getPersonInfo, getEmailCode } from '../api/user' 6 +import { updatePersonInfo, getPersonInfo, getEmailCode, emailType } from '../api/user'
7 import { promptAction } from '@kit.ArkUI'; 7 import { promptAction } from '@kit.ArkUI';
8 import { AxiosResponse } from '@ohos/axios' 8 import { AxiosResponse } from '@ohos/axios'
9 import PhotoBrowser from '../dialog/PhotoBrowserDialog' 9 import PhotoBrowser from '../dialog/PhotoBrowserDialog'
10 import { uploadFile, uploadResult } from '../utils/uploadFile' 10 import { uploadFile, uploadResult } from '../utils/uploadFile'
11 import { request } from '@kit.BasicServicesKit' 11 import { request } from '@kit.BasicServicesKit'
12 import NavHeader from '../components/NavHeader' 12 import NavHeader from '../components/NavHeader'
13 - 13 +import LoadingDialog from '../dialog/LoadingDialog'
14 14
15 @Entry 15 @Entry
16 @Component 16 @Component
@@ -21,8 +21,14 @@ struct EditUser { @@ -21,8 +21,14 @@ struct EditUser {
21 @State isShowCode: boolean = false 21 @State isShowCode: boolean = false
22 @State userInfo: personData = JSON.parse(preferencesUtil.get('XF_PERSON_INFO', '') as string) 22 @State userInfo: personData = JSON.parse(preferencesUtil.get('XF_PERSON_INFO', '') as string)
23 @State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值 23 @State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
24 - @State photoList: string[] = [baseUrl + this.userInfo.personalImg, baseUrl + this.userInfo.idImgFront, baseUrl + this.userInfo.idImgBack,] 24 + @State photoList: string[] = [baseUrl + this.userInfo.personalImg, baseUrl + this.userInfo.idImgFront, baseUrl + this.userInfo.idImgBack]
25 @State initEmail: string = this.userInfo.email 25 @State initEmail: string = this.userInfo.email
  26 + @State codeStr: string = '' // 存储验证码对比
  27 + @State timerCount: number = 300
  28 + aboutToAppear() {
  29 + this.userInfo.address = this.pickerValue.join(' ')
  30 + }
  31 + // 区域弹窗
26 areaController: CustomDialogController = new CustomDialogController({ 32 areaController: CustomDialogController = new CustomDialogController({
27 builder: AreaPickerDialog({ 33 builder: AreaPickerDialog({
28 value:this.pickerValue,//首次默认选中值 34 value:this.pickerValue,//首次默认选中值
@@ -31,18 +37,66 @@ struct EditUser { @@ -31,18 +37,66 @@ struct EditUser {
31 this.userInfo.address = this.pickerValue.join(' ') 37 this.userInfo.address = this.pickerValue.join(' ')
32 } 38 }
33 }), 39 }),
34 - customStyle: true 40 + customStyle: true,
  41 + autoCancel: false
35 }) 42 })
36 private selectedDate: Date = new Date('2000-01-01') 43 private selectedDate: Date = new Date('2000-01-01')
  44 + // 图片预览
37 photoBrowserController: CustomDialogController = new CustomDialogController({ 45 photoBrowserController: CustomDialogController = new CustomDialogController({
38 builder: PhotoBrowser({ imagesList: this.photoList}), 46 builder: PhotoBrowser({ imagesList: this.photoList}),
39 customStyle: true, 47 customStyle: true,
40 offset: { dx: 0, dy: 0 }, 48 offset: { dx: 0, dy: 0 },
41 alignment: DialogAlignment.Top, 49 alignment: DialogAlignment.Top,
42 }) 50 })
43 - aboutToAppear(): void {  
44 - console.log(JSON.stringify(this.userInfo)) 51 + // 加载弹窗
  52 + loadingController: CustomDialogController = new CustomDialogController({
  53 + builder: LoadingDialog(),
  54 + customStyle: true,
  55 + offset: { dx: 0, dy: 0 },
  56 + alignment: DialogAlignment.Center,
  57 + autoCancel: false
  58 + })
  59 + // 获取验证码
  60 + getCode = async () => {
  61 + if(this.codeStr == '') {
  62 + this.loadingController.open()
  63 + let emailRes: AxiosResponse<emailType> = await getEmailCode(this.userInfo.email)
  64 + this.codeStr = emailRes.data.data
  65 + this.loadingController.close()
  66 + let timer = setInterval(() => {
  67 + this.timerCount--
  68 + if(this.timerCount === 0){
  69 + clearInterval(timer)
  70 + this.codeStr = ''
  71 + this.timerCount = 300
  72 + }
  73 + }, 1000)
  74 + promptAction.showToast({
  75 + message: '已发送至邮箱,请查收'
  76 + })
  77 + } else {
  78 + promptAction.showToast({
  79 + message: '验证码已发送,300s内不在发送'
  80 + })
  81 + }
  82 + }
  83 + // 提交修改
  84 + submitForm = async () => {
  85 + let valueArr = Object.values(this.userInfo) as (string | null | number)[]
  86 + let isEmpty = valueArr.every(item => item !== '')
  87 + if(!isEmpty) return promptAction.showToast({message: '带星号的为必填项'})
  88 + if(!ValidateInputHandle(this.userInfo.idNo, 'idCard')) return promptAction.showToast({message: '身份证输入有误'})
  89 + if(!ValidateInputHandle(this.userInfo.phone, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
  90 + if(!ValidateInputHandle(this.userInfo.email, 'email')) return promptAction.showToast({message: '邮箱输入有误'})
  91 + if(this.isShowCode && (this.userInfo.code == '' || this.userInfo.code == undefined)) return promptAction.showToast({message: '请输入验证码'})
  92 + if(this.isShowCode && this.userInfo.code !== this.codeStr) return promptAction.showToast({message: '验证码输入有误'})
  93 + await updatePersonInfo(this.userInfo)
  94 + const info: AxiosResponse<personTest> = await getPersonInfo()
  95 + preferencesUtil.set('XF_PERSON_INFO', JSON.stringify(info.data.data))
  96 + this.userInfo = JSON.parse(preferencesUtil.get('XF_PERSON_INFO', '') as string)
  97 + promptAction.showToast({ message: '修改成功', duration: 2000 })
45 } 98 }
  99 +
46 build() { 100 build() {
47 Column(){ 101 Column(){
48 NavHeader({title: '编辑个人信息'}) 102 NavHeader({title: '编辑个人信息'})
@@ -77,13 +131,10 @@ struct EditUser { @@ -77,13 +131,10 @@ struct EditUser {
77 Row(){ 131 Row(){
78 TextInput({placeholder: '请输入验证码', text: $$this.userInfo.code}) 132 TextInput({placeholder: '请输入验证码', text: $$this.userInfo.code})
79 .backgroundColor('#fff').layoutWeight(1) 133 .backgroundColor('#fff').layoutWeight(1)
80 - Text('获取验证码').fontSize(12).backgroundColor('#1890ff').borderRadius(5) 134 + Text(this.codeStr == '' ? '获取验证码' : `${this.timerCount}s后重新获取`).fontSize(12).backgroundColor('#1890ff').borderRadius(5)
81 .padding({top: 4, bottom: 4, left: 10, right: 10}).fontColor('#fff') 135 .padding({top: 4, bottom: 4, left: 10, right: 10}).fontColor('#fff')
82 - .onClick(async () => {  
83 - await getEmailCode(this.userInfo.email)  
84 - promptAction.showToast({  
85 - message: '已发送至邮箱,请查收'  
86 - }) 136 + .onClick(() => {
  137 + this.getCode()
87 }) 138 })
88 }.layoutWeight(1) 139 }.layoutWeight(1)
89 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10}) 140 }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
@@ -233,34 +284,13 @@ struct EditUser { @@ -233,34 +284,13 @@ struct EditUser {
233 }.backgroundColor('#fff').width('100%').padding({left: 5, right: 5}).borderRadius(10) 284 }.backgroundColor('#fff').width('100%').padding({left: 5, right: 5}).borderRadius(10)
234 }.padding(10).margin({bottom: 20, top: 10}) 285 }.padding(10).margin({bottom: 20, top: 10})
235 }.layoutWeight(1).scrollBar(BarState.Off) 286 }.layoutWeight(1).scrollBar(BarState.Off)
  287 +
  288 + // 底部区域
236 Row({ space: 10}){ 289 Row({ space: 10}){
237 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff') 290 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
238 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center) 291 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
239 - .onClick(async () => {  
240 - if(this.userInfo?.personName == '') {  
241 - return promptAction.showToast({message: '姓名不能为空'})  
242 - } else if(this.userInfo?.email == '') {  
243 - return promptAction.showToast({message: '邮箱不能为空'})  
244 - } else if(this.userInfo?.idNo == '') {  
245 - return promptAction.showToast({message: '身份证不能为空'})  
246 - } else if(this.userInfo?.phone == '') {  
247 - return promptAction.showToast({message: '手机号不能为空'})  
248 - } else if(this.userInfo?.idImgFront == '') {  
249 - return promptAction.showToast({message: '身份证件不能为空'})  
250 - } else if(this.userInfo?.idImgBack == '') {  
251 - return promptAction.showToast({message: '身份证件不能为空'})  
252 - } else if(this.userInfo?.personalImg == '') {  
253 - return promptAction.showToast({message: '请上传头像'})  
254 - }  
255 -  
256 - await updatePersonInfo(this.userInfo)  
257 - const info: AxiosResponse<personTest> = await getPersonInfo()  
258 - preferencesUtil.set('XF_PERSON_INFO', JSON.stringify(info.data.data))  
259 - this.userInfo = JSON.parse(preferencesUtil.get('XF_PERSON_INFO', '') as string)  
260 - promptAction.showToast({  
261 - message: '修改成功',  
262 - duration: 2000  
263 - }) 292 + .onClick(() => {
  293 + this.submitForm()
264 }) 294 })
265 Text('图片预览').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff') 295 Text('图片预览').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
266 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center) 296 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
@@ -14,7 +14,7 @@ import NavHeader from '../components/NavHeader' @@ -14,7 +14,7 @@ import NavHeader from '../components/NavHeader'
14 14
15 @Entry 15 @Entry
16 @Component 16 @Component
17 -struct UserRegister { 17 +struct Register {
18 @Builder indicatorBuilder(icon: ResourceStr) { 18 @Builder indicatorBuilder(icon: ResourceStr) {
19 Image(icon) 19 Image(icon)
20 } 20 }
@@ -52,12 +52,12 @@ struct UserRegister { @@ -52,12 +52,12 @@ struct UserRegister {
52 password: '' 52 password: ''
53 } 53 }
54 @State confirmPassword: string = '' 54 @State confirmPassword: string = ''
  55 + @State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
55 dialogController: CustomDialogController = new CustomDialogController({ 56 dialogController: CustomDialogController = new CustomDialogController({
56 builder: CompanyCommit(), 57 builder: CompanyCommit(),
57 autoCancel: false, 58 autoCancel: false,
58 customStyle: true 59 customStyle: true
59 }) 60 })
60 - @State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值  
61 areaController: CustomDialogController = new CustomDialogController({ 61 areaController: CustomDialogController = new CustomDialogController({
62 builder: AreaPickerDialog({ 62 builder: AreaPickerDialog({
63 value:this.pickerValue,//首次默认选中值 63 value:this.pickerValue,//首次默认选中值
@@ -69,11 +69,9 @@ struct UserRegister { @@ -69,11 +69,9 @@ struct UserRegister {
69 this.companyInfo.county = value[2] 69 this.companyInfo.county = value[2]
70 } 70 }
71 }), 71 }),
72 - customStyle: true 72 + customStyle: true,
  73 + autoCancel: false
73 }) 74 })
74 - async aboutToAppear() {  
75 - this.dialogController.open()  
76 - }  
77 75
78 // 查询用户名是否被占用 76 // 查询用户名是否被占用
79 queryName = async (userName: string) => { 77 queryName = async (userName: string) => {
@@ -86,6 +84,14 @@ struct UserRegister { @@ -86,6 +84,14 @@ struct UserRegister {
86 const res: AxiosResponse<queryIdNoType> = await queryIdNo(id) 84 const res: AxiosResponse<queryIdNoType> = await queryIdNo(id)
87 this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入' 85 this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入'
88 } 86 }
  87 +
  88 + async aboutToAppear() {
  89 + this.dialogController.open()
  90 + this.companyInfo.address = this.pickerValue.join(' ')
  91 + this.companyInfo.province = this.pickerValue[0]
  92 + this.companyInfo.city = this.pickerValue[1]
  93 + this.companyInfo.county = this.pickerValue[2]
  94 + }
89 build() { 95 build() {
90 Column(){ 96 Column(){
91 NavHeader({title: '注册'}) 97 NavHeader({title: '注册'})
@@ -277,26 +283,13 @@ struct UserRegister { @@ -277,26 +283,13 @@ struct UserRegister {
277 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff') 283 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
278 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center) 284 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
279 .onClick(async () => { 285 .onClick(async () => {
280 - console.log(JSON.stringify(this.companyInfo))  
281 - if(this.confirmPassword !== this.companyInfo.password) {  
282 - return promptAction.showToast({message: '两次密码输入不一致'})  
283 - }  
284 - if(this.companyInfo?.businessLicenseNo == '') {  
285 - return promptAction.showToast({message: '社会统一代码不能为空'})  
286 - } else if(this.companyInfo?.email == '') {  
287 - return promptAction.showToast({message: '邮箱不能为空'})  
288 - } else if(this.companyInfo?.linkMan == '') {  
289 - return promptAction.showToast({message: '联系人不能为空'})  
290 - } else if(this.companyInfo?.lmTel == '') {  
291 - return promptAction.showToast({message: '手机号不能为空'})  
292 - } else if(this.companyInfo?.username == '') {  
293 - return promptAction.showToast({message: '用户名不能为空'})  
294 - } 286 + if(this.confirmPassword !== this.companyInfo.password) return promptAction.showToast({message: '两次密码输入不一致'})
  287 + if(!ValidateInputHandle(this.companyInfo.lmTel, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
  288 + if(!ValidateInputHandle(this.companyInfo.email, 'email')) return promptAction.showToast({message: '邮箱输入有误'})
  289 + let ValuesArr = Object.values(this.companyInfo) as (string | number | null)[]
  290 + if(!ValuesArr.every(item => item !== '')) return promptAction.showToast({message: '带型号的为必填项'})
295 await companyRegister(this.companyInfo) 291 await companyRegister(this.companyInfo)
296 - promptAction.showToast({  
297 - message: '注册成功',  
298 - duration: 2000  
299 - }) 292 + promptAction.showToast({ message: '注册成功' })
300 router.back() 293 router.back()
301 }) 294 })
302 }.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10}) 295 }.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10})
@@ -38,15 +38,16 @@ struct UserRegister { @@ -38,15 +38,16 @@ struct UserRegister {
38 userId: 0, 38 userId: 0,
39 state: '' 39 state: ''
40 } 40 }
41 - private selectedDate: Date = new Date('2000-01-01') 41 + @State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值
  42 + @State initEmail: string = this.userInfo.email
42 @State confirmPassword: string = '' 43 @State confirmPassword: string = ''
  44 + private selectedDate: Date = new Date('2000-01-01')
43 dialogController: CustomDialogController = new CustomDialogController({ 45 dialogController: CustomDialogController = new CustomDialogController({
44 builder: UserCommit(), 46 builder: UserCommit(),
45 autoCancel: false, 47 autoCancel: false,
46 customStyle: true 48 customStyle: true
47 }) 49 })
48 - @State pickerValue:string[] = ['广西壮族自治区','南宁市','青秀区']//省市区选中值  
49 - @State initEmail: string = this.userInfo.email 50 + // 区域弹窗
50 areaController: CustomDialogController = new CustomDialogController({ 51 areaController: CustomDialogController = new CustomDialogController({
51 builder: AreaPickerDialog({ 52 builder: AreaPickerDialog({
52 value:this.pickerValue,//首次默认选中值 53 value:this.pickerValue,//首次默认选中值
@@ -55,23 +56,23 @@ struct UserRegister { @@ -55,23 +56,23 @@ struct UserRegister {
55 this.userInfo.address = this.pickerValue.join(' ') 56 this.userInfo.address = this.pickerValue.join(' ')
56 } 57 }
57 }), 58 }),
58 - customStyle: true 59 + customStyle: true,
  60 + autoCancel: false
59 }) 61 })
60 - async aboutToAppear() {  
61 - this.dialogController.open()  
62 - }  
63 -  
64 // 查询用户名是否被占用 62 // 查询用户名是否被占用
65 queryName = async (userName: string) => { 63 queryName = async (userName: string) => {
66 const res: AxiosResponse<queryUserNameType> = await queryUsername(userName) 64 const res: AxiosResponse<queryUserNameType> = await queryUsername(userName)
67 this.userErrorMsg = res.data.data == 1 ? '' : res.data.msg 65 this.userErrorMsg = res.data.data == 1 ? '' : res.data.msg
68 -}  
69 - 66 + }
70 // 查身份证是否被占用 67 // 查身份证是否被占用
71 queryId = async (id: string) => { 68 queryId = async (id: string) => {
72 const res: AxiosResponse<queryIdNoType> = await queryIdNo(id) 69 const res: AxiosResponse<queryIdNoType> = await queryIdNo(id)
73 this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入' 70 this.idErrorMsg = res.data.total == 0 ? '' : '身份证号码已存在,请重新输入'
74 -} 71 + }
  72 + async aboutToAppear() {
  73 + this.dialogController.open()
  74 + this.userInfo.address = this.pickerValue.join(' ')
  75 + }
75 build() { 76 build() {
76 Column(){ 77 Column(){
77 NavHeader({title: '用户注册'}) 78 NavHeader({title: '用户注册'})
@@ -281,29 +282,14 @@ struct UserRegister { @@ -281,29 +282,14 @@ struct UserRegister {
281 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff') 282 Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
282 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center) 283 .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
283 .onClick(async () => { 284 .onClick(async () => {
284 - if(this.confirmPassword !== this.userInfo.password) {  
285 - return promptAction.showToast({message: '两次密码输入不一致'})  
286 - }  
287 - if(this.userInfo?.personName == '') {  
288 - return promptAction.showToast({message: '姓名不能为空'})  
289 - } else if(this.userInfo?.email == '') {  
290 - return promptAction.showToast({message: '邮箱不能为空'})  
291 - } else if(this.userInfo?.idNo == '') {  
292 - return promptAction.showToast({message: '身份证不能为空'})  
293 - } else if(this.userInfo?.phone == '') {  
294 - return promptAction.showToast({message: '手机号不能为空'})  
295 - } else if(this.userInfo.idImgFront == '') {  
296 - return promptAction.showToast({message: '身份证件不能为空'})  
297 - } else if(this.userInfo.idImgBack == '') {  
298 - return promptAction.showToast({message: '身份证件不能为空'})  
299 - } else if(this.userInfo?.personalImg == '') {  
300 - return promptAction.showToast({message: '请上传头像'})  
301 - } 285 + if(this.confirmPassword !== this.userInfo.password) return promptAction.showToast({message: '两次密码输入不一致'})
  286 + if(!ValidateInputHandle(this.userInfo.idNo, 'idCard')) return promptAction.showToast({message: '身份证输入有误'})
  287 + if(!ValidateInputHandle(this.userInfo.phone, 'phone')) return promptAction.showToast({message: '手机号输入有误'})
  288 + if(!ValidateInputHandle(this.userInfo.email, 'email')) return promptAction.showToast({message: '邮箱输入有误'})
  289 + let valuesArr = Object.values(this.userInfo) as (string | number)[]
  290 + if(!valuesArr.every(item => item !== '')) return promptAction.showToast({message: '带星号的为必填项'})
302 await userRegister(this.userInfo) 291 await userRegister(this.userInfo)
303 - promptAction.showToast({  
304 - message: '注册成功',  
305 - duration: 2000  
306 - }) 292 + promptAction.showToast({ message: '注册成功' })
307 router.back() 293 router.back()
308 }) 294 })
309 }.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10}) 295 }.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10})
@@ -10,7 +10,7 @@ export function ValidateInputHandle(input: string, type: typeValue): boolean { @@ -10,7 +10,7 @@ export function ValidateInputHandle(input: string, type: typeValue): boolean {
10 const phoneRegex = /^1[3456789]\d{9}$/ 10 const phoneRegex = /^1[3456789]\d{9}$/
11 return phoneRegex.test(input) 11 return phoneRegex.test(input)
12 case "email": 12 case "email":
13 - const emailRegex = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/ 13 + const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(com|cn|net|org|edu|gov|io|co)$/;
14 return emailRegex.test(input) 14 return emailRegex.test(input)
15 case "businessLicenseNo": 15 case "businessLicenseNo":
16 const businessLicenseNoRegex = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/ 16 const businessLicenseNoRegex = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/