页面刷新
This commit is contained in:
@@ -6,14 +6,15 @@ import { BasicConstant, ChangePhotoGrids,
|
||||
preferenceStore, ViewImageInfo } from "@itcast/basic"
|
||||
import { PhotoActionSheet } from '@itcast/basic'
|
||||
import { AnswerListBean } from "../model/ConsulModel"
|
||||
import { router } from "@kit.ArkUI"
|
||||
import { promptAction, router } from "@kit.ArkUI"
|
||||
import { PerfactInputSheet } from "@itcast/basic/src/main/ets/Views/PerfactInputSheet"
|
||||
import { BusinessError } from "@kit.BasicServicesKit"
|
||||
import { HashMap } from "@kit.ArkTS"
|
||||
import { rcp } from '@kit.RemoteCommunicationKit';
|
||||
|
||||
@Component
|
||||
export struct MyOpinionComp {
|
||||
@State photos: string[] = []
|
||||
@State base64Array:string[] = []
|
||||
@State previewIndex: number = -1
|
||||
@State maxSelectNumber: number = 6
|
||||
|
||||
@@ -30,15 +31,20 @@ export struct MyOpinionComp {
|
||||
hashMap: HashMap<string, Object> = new HashMap();
|
||||
hashMapImg: HashMap<string, string> = new HashMap();
|
||||
|
||||
onAddImg()
|
||||
{
|
||||
onAddImg() {
|
||||
this.photoSheetDialog.open()
|
||||
}
|
||||
onRemoveImg()
|
||||
{
|
||||
|
||||
onRemoveImg() {
|
||||
this.photos.splice(this.removeIndex, 1)
|
||||
this.maxSelectNumber =6- this.photos.length;
|
||||
|
||||
ChangeUtil.convertUrisOrUrlsToBase64(this.photos).then(base64Array => {
|
||||
console.info('转换结果:', base64Array+'转换个数:'+base64Array.length)
|
||||
this.base64Array = base64Array
|
||||
}).catch((err:BusinessError) => {
|
||||
console.error('批量转换失败:', err)
|
||||
})
|
||||
}
|
||||
private custom!:CustomDialogController;
|
||||
dialog: CustomDialogController = new CustomDialogController({
|
||||
@@ -46,6 +52,7 @@ export struct MyOpinionComp {
|
||||
customStyle: true,
|
||||
alignment: DialogAlignment.Center
|
||||
})
|
||||
|
||||
initDialog() {
|
||||
this.custom = new CustomDialogController({
|
||||
builder:PerfactInputSheet({
|
||||
@@ -57,16 +64,12 @@ export struct MyOpinionComp {
|
||||
inputPlaceholder:'您有未发布的内容,是否保存?',
|
||||
style:'2',
|
||||
inputCallBack:(input: string,title:string)=>{
|
||||
if(title=='needcancelCallBack')
|
||||
{
|
||||
if(title=='needcancelCallBack') {
|
||||
preferenceStore.setItemString('MyOpinionComp'+this.params.uuid,'')
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
preferenceStore.setItemString('MyOpinionComp'+this.params.uuid,this.text)
|
||||
}
|
||||
router.back()
|
||||
|
||||
}
|
||||
}),
|
||||
alignment: DialogAlignment.Center,
|
||||
@@ -76,6 +79,7 @@ export struct MyOpinionComp {
|
||||
height: '100%'
|
||||
})
|
||||
}
|
||||
|
||||
private initPhotoDialog() {
|
||||
this.photoSheetDialog = new CustomDialogController({
|
||||
builder: PhotoActionSheet({
|
||||
@@ -89,12 +93,16 @@ export struct MyOpinionComp {
|
||||
} else if (typeof uris === 'string') {
|
||||
selectedUris = [uris];
|
||||
}
|
||||
|
||||
this.photos.push(...selectedUris);
|
||||
this.photos.push(...selectedUris);
|
||||
this.maxSelectNumber = 6- this.photos.length;
|
||||
|
||||
ChangeUtil.convertUrisOrUrlsToBase64(selectedUris).then(base64Array => {
|
||||
console.info('转换结果:', base64Array+'转换个数:'+base64Array.length)
|
||||
this.base64Array = base64Array
|
||||
}).catch((err:BusinessError) => {
|
||||
console.error('批量转换失败:', err)
|
||||
})
|
||||
}
|
||||
|
||||
}),
|
||||
alignment: DialogAlignment.Bottom,
|
||||
customStyle: true,
|
||||
@@ -103,28 +111,29 @@ export struct MyOpinionComp {
|
||||
height: '100%'
|
||||
});
|
||||
}
|
||||
|
||||
aboutToAppear(): void {
|
||||
console.log('Response aboutToAppear')
|
||||
this.initPhotoDialog()
|
||||
this.initDialog()
|
||||
if(this.params.isHistory =='true')
|
||||
{
|
||||
if(this.params.isHistory =='true') {
|
||||
this.text=this.params.myAnswer.note
|
||||
if(this.params.myAnswer.imgs!=null)
|
||||
{
|
||||
if(this.params.myAnswer.imgs!=null) {
|
||||
this.photos.push(...this.changeToImgs(this.params.myAnswer.imgs.split(",")))
|
||||
this.maxSelectNumber = 6- this.photos.length;
|
||||
|
||||
ChangeUtil.convertUrisOrUrlsToBase64(this.changeToImgs(this.params.myAnswer.imgs.split(","))).then(base64Array => {
|
||||
console.info('转换结果:', base64Array+'转换个数:'+base64Array.length)
|
||||
this.base64Array = base64Array
|
||||
}).catch((err:BusinessError) => {
|
||||
console.error('批量转换失败:', err)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.text=preferenceStore.getItemString('MyOpinionComp'+this.params.uuid)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
HdNav({ title: '我的意见', showRightIcon: false, showLeftIcon: true ,isLeftAction:true,leftItemAction:()=>{
|
||||
@@ -181,83 +190,94 @@ export struct MyOpinionComp {
|
||||
// params: { uuid:this.params.uuid,isHistory:this.params.isHistory,myAnswer:this.getMyanswer(this.AnswerList)}
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
.backgroundColor(Color.White)
|
||||
.width('100%')
|
||||
|
||||
|
||||
|
||||
}
|
||||
.height('100%')
|
||||
.width('100%')
|
||||
}
|
||||
|
||||
async getUploadImg()
|
||||
{
|
||||
async getUploadImg() {
|
||||
this.hashMapImg.clear();
|
||||
|
||||
if(this.photos.length>0)
|
||||
{
|
||||
if(this.photos.length>0) {
|
||||
for (let index = 0; index < this.photos.length; index++) {
|
||||
if(this.photos[index].includes('http'))
|
||||
{
|
||||
if(this.photos[index].includes('http')) {
|
||||
this.hashMapImg.set('img'+index+1,await ChangeUtil.getImageBase64(this.photos[index]))
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.hashMapImg.set('img'+index+1, await ChangeUtil.convertUriToBase64(this.photos[index]))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return this.hashMapImg
|
||||
}
|
||||
|
||||
async updateInterrogationAnswer()
|
||||
{
|
||||
async updateInterrogationAnswer() {
|
||||
this.dialog.open()
|
||||
this.hashMap.clear();
|
||||
this.hashMap.set("note",this.text);
|
||||
this.hashMap.set('uuid', this.params.uuid)
|
||||
this.hashMap.set('imgsBean',await this.getUploadImg())
|
||||
this.hashMap.set('imgsBean',this.assembleBase64Images(this.base64Array))
|
||||
hdHttp.httpReqObject<string>(BasicConstant.updateInterrogationAnswer,this.hashMap).then(async (res: HdResponse<string>) => {
|
||||
this.dialog.close()
|
||||
|
||||
|
||||
|
||||
let json:Record<string,string> = JSON.parse(res+'') as Record<string,string>;
|
||||
promptAction.showToast({ message: json.message })
|
||||
if(json.code == '200') {
|
||||
router.back()
|
||||
}
|
||||
}).catch((err: BusinessError) => {
|
||||
this.dialog.close()
|
||||
|
||||
})
|
||||
|
||||
// let req = new rcp.Request("http://example.com", "POST", headers, simpleForm, cookies, transferRange, configuration);
|
||||
}
|
||||
|
||||
changeToImg( imgListurl:string[])
|
||||
{
|
||||
changeToImg( imgListurl:string[]) {
|
||||
let imgListtmps:ViewImageInfo[]=[]
|
||||
imgListurl.forEach((url: string) => {
|
||||
let item = {uri:url} as ViewImageInfo
|
||||
imgListtmps.push(item)
|
||||
})
|
||||
return imgListtmps
|
||||
|
||||
}
|
||||
changeToImgs( imgListurl:string[])
|
||||
{
|
||||
|
||||
changeToImgs( imgListurl:string[]) {
|
||||
let imgListtmps:string[]=[]
|
||||
imgListurl.forEach((url: string) => {
|
||||
let item = BasicConstant.urlHtml + url
|
||||
imgListtmps.push(item)
|
||||
})
|
||||
return imgListtmps
|
||||
}
|
||||
|
||||
/**
|
||||
* 将base64数组组装为对象
|
||||
* @param base64Array base64字符串数组
|
||||
* @param maxImages 最大图片数量,默认8
|
||||
* @returns 包含img1~imgN字段的对象
|
||||
*/
|
||||
assembleBase64Images(
|
||||
base64Array: string[],
|
||||
maxImages: number = 6
|
||||
): Record<string, string> {
|
||||
const imgObject: Record<string, string> = {};
|
||||
// 确定实际处理的图片数量
|
||||
const processCount = Math.min(base64Array.length, maxImages);
|
||||
for (let i = 0; i < processCount; i++) {
|
||||
const originalBase64 = base64Array[i];
|
||||
// 清理base64前缀[9,10](@ref)
|
||||
const cleanBase64 = originalBase64.replace(
|
||||
/^data:image\/\w+;base64,/i,
|
||||
''
|
||||
);
|
||||
// 生成字段名
|
||||
const fieldName = `img${i + 1}`;
|
||||
imgObject[fieldName] = cleanBase64;
|
||||
}
|
||||
return imgObject;
|
||||
}
|
||||
}
|
||||
|
||||
interface param{
|
||||
uuid:string,
|
||||
isHistory:string,
|
||||
|
||||
Reference in New Issue
Block a user