|
@@ -0,0 +1,522 @@
|
|
|
|
|
+import { IBestToast, YTAvoid, yTRouter, yTToast } from 'basic'
|
|
|
|
|
+import { photoAccessHelper } from '@kit.MediaLibraryKit';
|
|
|
|
|
+import { DiaryDatePicker } from '../components/DiaryDatePicker';
|
|
|
|
|
+import { DiaryData, PageStatus, Variable } from '../models';
|
|
|
|
|
+import { DiaryViewModel } from '../viewModels/DiaryViewModel';
|
|
|
|
|
+import { DateUtils } from '../utils/DateUtils';
|
|
|
|
|
+import { DiaryTimePicker } from '../components/DiaryTimePicker';
|
|
|
|
|
+import { RecodeViewModel } from '../viewModels/RecodeViewModel';
|
|
|
|
|
+import { DoubleConfirm } from '../components/DoubleConfirm';
|
|
|
|
|
+import { Context } from '@ohos.abilityAccessCtrl';
|
|
|
|
|
+import { common } from '@kit.AbilityKit';
|
|
|
|
|
+import image from '@ohos.multimedia.image';
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 新增/编辑 日记
|
|
|
|
|
+ */
|
|
|
|
|
+@Component
|
|
|
|
|
+struct IncreaseDiaryPage {
|
|
|
|
|
+ @StorageProp(YTAvoid.SAFE_TOP_KEY) safeTop: number = 0
|
|
|
|
|
+ // 页面编辑中的状态 - 默认为可编辑
|
|
|
|
|
+ @State pageReadOnly: boolean = false
|
|
|
|
|
+ // 时间选择器 开启控制
|
|
|
|
|
+ @State showTimePicker: boolean = false
|
|
|
|
|
+ // 日期选择器 开启控制
|
|
|
|
|
+ @State showDatePicker: boolean = false
|
|
|
|
|
+ // 日记详细数据
|
|
|
|
|
+ @State diaryData: DiaryData = {};
|
|
|
|
|
+ // 页面状态, 默认为日记
|
|
|
|
|
+ @State pageStatus: PageStatus = PageStatus.DIARY
|
|
|
|
|
+
|
|
|
|
|
+ private linearInfo: LinearGradientOptions = {
|
|
|
|
|
+ colors: [ ['#B9FD2A', 0.01], ['#F5FD6D', 1] ],
|
|
|
|
|
+ angle: 150
|
|
|
|
|
+ }
|
|
|
|
|
+ private conText: Context = this.getUIContext().getHostContext() as Context
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 选择图片
|
|
|
|
|
+ */
|
|
|
|
|
+ async photoSelect(){
|
|
|
|
|
+ let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
|
|
|
|
|
+ PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
|
|
|
|
|
+ PhotoSelectOptions.maxSelectNumber = 1;
|
|
|
|
|
+ let photoPicker = new photoAccessHelper.PhotoViewPicker();
|
|
|
|
|
+
|
|
|
|
|
+ let photoSelectResult: photoAccessHelper.PhotoSelectResult = await photoPicker.select(PhotoSelectOptions);
|
|
|
|
|
+ let photoList = photoSelectResult.photoUris;
|
|
|
|
|
+ if (photoList.length > 0) {
|
|
|
|
|
+ if(!this.diaryData.imageUrls) this.diaryData.imageUrls = [];
|
|
|
|
|
+ this.diaryData.imageUrls = [...this.diaryData.imageUrls, ...photoList];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 点击 完成 按钮
|
|
|
|
|
+ */
|
|
|
|
|
+ async onComplete() {
|
|
|
|
|
+ if(this.pageReadOnly) {
|
|
|
|
|
+ this.pageReadOnly = false;
|
|
|
|
|
+ Variable.pageReadOnly = false
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!this.diaryData.title || !this.diaryData.content) {
|
|
|
|
|
+ IBestToast.show({ message: '请填写标题和内容' })
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 浅拷贝
|
|
|
|
|
+ let diaryData = JSON.parse(JSON.stringify(this.diaryData)) as DiaryData
|
|
|
|
|
+ // 统一时间格式
|
|
|
|
|
+
|
|
|
|
|
+ // 图片上传逻辑
|
|
|
|
|
+ if (diaryData.imageUrls && diaryData.imageUrls.length != 0) {
|
|
|
|
|
+ console.log("图片上传中" + JSON.stringify(diaryData.imageUrls))
|
|
|
|
|
+
|
|
|
|
|
+ // 使用map创建Promise数组,然后用Promise.all等待所有上传完成
|
|
|
|
|
+ const uploadPromises = diaryData.imageUrls?.map(async (url: string) => {
|
|
|
|
|
+ if(url?.split(':')?.[0] === 'file') {
|
|
|
|
|
+ console.log("开始上传图片 " + url)
|
|
|
|
|
+ let _url = await DiaryViewModel.uploadImage(this.conText, url)
|
|
|
|
|
+ return _url
|
|
|
|
|
+ }
|
|
|
|
|
+ return url
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 等待所有上传完成
|
|
|
|
|
+ const imageUrl = await Promise.all(uploadPromises)
|
|
|
|
|
+ console.log("图片上传结果" + JSON.stringify(imageUrl))
|
|
|
|
|
+
|
|
|
|
|
+ // 将处理后的URL赋值回diaryData
|
|
|
|
|
+ diaryData.imageUrls = imageUrl
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否是新增日记 - 有 id 时为 修改日记
|
|
|
|
|
+ if(!this.diaryData.id) {
|
|
|
|
|
+ diaryData.diaryDate += ':00'
|
|
|
|
|
+ this.onSubmit(diaryData)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.onUpdate(diaryData)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 新建 日记、小记录
|
|
|
|
|
+ async onSubmit(data: DiaryData) {
|
|
|
|
|
+ let ans: boolean = false
|
|
|
|
|
+ console.log("保存")
|
|
|
|
|
+
|
|
|
|
|
+ if(this.pageStatus === PageStatus.DIARY) {
|
|
|
|
|
+ ans = await DiaryViewModel.saveDiaryLog(data)
|
|
|
|
|
+ console.log("日记-保存结果" + JSON.stringify(ans))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ data.noteTime = data.diaryDate
|
|
|
|
|
+ ans = await RecodeViewModel.saveNote(data)
|
|
|
|
|
+ console.log("小记录-保存结果" + JSON.stringify(ans))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(ans) {
|
|
|
|
|
+ IBestToast.show({ message: '保存成功' })
|
|
|
|
|
+ yTRouter.routerBack()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ IBestToast.show({ message: '保存失败' })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 修改日记、小记录
|
|
|
|
|
+ async onUpdate(data: DiaryData) {
|
|
|
|
|
+ let ans: boolean = false
|
|
|
|
|
+ console.log("修改")
|
|
|
|
|
+ if(this.pageStatus === PageStatus.DIARY) {
|
|
|
|
|
+ let time = DateUtils.formatDateToCustomString(new Date()).split(' ')[1]
|
|
|
|
|
+ data.diaryDate = data.diaryDate?.split(' ')[0] + ' ' +time
|
|
|
|
|
+ ans = await DiaryViewModel.updateDiaryLog(data)
|
|
|
|
|
+ console.log("日记-修改结果" + ans)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ data.noteTime = data.diaryDate + ':00'
|
|
|
|
|
+ ans = await RecodeViewModel.updateNote(data)
|
|
|
|
|
+ console.log("小记录-修改结果" + JSON.stringify(ans))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(ans) {
|
|
|
|
|
+ IBestToast.show({ message: '保存成功' })
|
|
|
|
|
+ yTRouter.routerBack()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ IBestToast.show({ message: '保存失败' })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 清空相册
|
|
|
|
|
+ */
|
|
|
|
|
+ clearPhoto() {
|
|
|
|
|
+ this.diaryData.imageUrls = []
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除图片
|
|
|
|
|
+ * @param index
|
|
|
|
|
+ */
|
|
|
|
|
+ delPhotoItem(index: number){
|
|
|
|
|
+ let temp = [...this.diaryData.imageUrls!]
|
|
|
|
|
+ temp?.splice(index, 1)
|
|
|
|
|
+ this.diaryData.imageUrls = temp
|
|
|
|
|
+ console.log("点击了删除" + JSON.stringify(this.diaryData.imageUrls))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 重写返回逻辑 - 拦截返回手势
|
|
|
|
|
+ * @returns
|
|
|
|
|
+ */
|
|
|
|
|
+ onRouterBack(): boolean {
|
|
|
|
|
+ if(!Variable.pageReadOnly) {
|
|
|
|
|
+ yTToast.openToast(wrapBuilder(DoubleConfirm), {
|
|
|
|
|
+ text: "是否确认退出编辑",
|
|
|
|
|
+ click: async () => {
|
|
|
|
|
+ yTToast.hide()
|
|
|
|
|
+ yTRouter.routerBack()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ yTRouter.routerBack()
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 路由参数解析
|
|
|
|
|
+ async getRouterParams(){
|
|
|
|
|
+ // 获取路由参数
|
|
|
|
|
+ const params = yTRouter.getParamByName("IncreaseDiaryPage").pop() as Record<string, boolean | number>;
|
|
|
|
|
+
|
|
|
|
|
+ // 获取参数
|
|
|
|
|
+ this.pageStatus = (params?.PageStatus ?? PageStatus.DIARY) as PageStatus
|
|
|
|
|
+
|
|
|
|
|
+ // 获取参数
|
|
|
|
|
+ let id = (params?.id ?? -1) as number;
|
|
|
|
|
+ if (id != -1) {
|
|
|
|
|
+ this.pageReadOnly = true
|
|
|
|
|
+ Variable.pageReadOnly = true
|
|
|
|
|
+ if(this.pageStatus == PageStatus.DIARY) {
|
|
|
|
|
+ this.diaryData = await DiaryViewModel.queryDiaryLogById(id)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.diaryData = await RecodeViewModel.queryNoteById(id)
|
|
|
|
|
+ this.diaryData.diaryDate = this.diaryData.noteTime
|
|
|
|
|
+ }
|
|
|
|
|
+ try{
|
|
|
|
|
+ let time = this.diaryData.diaryDate?.split(' ')?.[1]
|
|
|
|
|
+ let time1 = time?.split(':')
|
|
|
|
|
+ time1?.pop()
|
|
|
|
|
+ this.diaryData.diaryDate = this.diaryData.diaryDate?.split(' ')?.[0] + ' ' + time1?.join(':')
|
|
|
|
|
+ } catch (e){
|
|
|
|
|
+ console.log("时间解析错误")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async aboutToAppear(): Promise<void> {
|
|
|
|
|
+ this.diaryData.diaryDate = DateUtils.formatDateToCustomString(new Date(), true, false)
|
|
|
|
|
+ this.getRouterParams()
|
|
|
|
|
+
|
|
|
|
|
+ // TODO 在没有数据的时候 时间选择器的回显为 undefined
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ build() {
|
|
|
|
|
+ NavDestination() {
|
|
|
|
|
+ Column({ space: 5 }) {
|
|
|
|
|
+ // 标题区
|
|
|
|
|
+ Stack({alignContent: Alignment.Center}) {
|
|
|
|
|
+ Row(){
|
|
|
|
|
+ Image($r("app.media.close"))
|
|
|
|
|
+ .width(20)
|
|
|
|
|
+ .aspectRatio(1)
|
|
|
|
|
+ .onClick(this.onRouterBack)
|
|
|
|
|
+
|
|
|
|
|
+ Text(this.pageReadOnly ? "编辑" : "完成")
|
|
|
|
|
+ .fontSize(14)
|
|
|
|
|
+ .fontWeight(500)
|
|
|
|
|
+ .borderRadius(16)
|
|
|
|
|
+ .backgroundColor(Color.White)
|
|
|
|
|
+ .padding({top: 5.5, left: 14, right: 14, bottom: 5.5})
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.onComplete()
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .justifyContent(FlexAlign.SpaceBetween)
|
|
|
|
|
+
|
|
|
|
|
+ Text("创作")
|
|
|
|
|
+ .fontSize(20)
|
|
|
|
|
+ .fontWeight(700)
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .padding({ top: this.safeTop + 5, left: 20, right: 20, bottom: 22 })
|
|
|
|
|
+
|
|
|
|
|
+ // 内容区
|
|
|
|
|
+ Column({space: 5}) {
|
|
|
|
|
+ Stack({alignContent: Alignment.Bottom}){
|
|
|
|
|
+ // 主要内容
|
|
|
|
|
+ Column(){
|
|
|
|
|
+ // 日期选择
|
|
|
|
|
+ Row(){
|
|
|
|
|
+ Row({space: 8}){
|
|
|
|
|
+ Text(this.diaryData.diaryDate?.split(' ')[0])
|
|
|
|
|
+ .fontSize(16)
|
|
|
|
|
+ .fontWeight(600)
|
|
|
|
|
+
|
|
|
|
|
+ Image($r('app.media.Diary_DateOpen'))
|
|
|
|
|
+ .width(14)
|
|
|
|
|
+ .height(8)
|
|
|
|
|
+ }
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.showDatePicker = true
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 时间选择
|
|
|
|
|
+ Row({space: 8}){
|
|
|
|
|
+ if(this.pageStatus == PageStatus.RECODE) {
|
|
|
|
|
+ Text(this.diaryData.diaryDate?.split(' ')[1])
|
|
|
|
|
+ .fontSize(16)
|
|
|
|
|
+ .fontWeight(600)
|
|
|
|
|
+
|
|
|
|
|
+ Image($r('app.media.Diary_DateOpen'))
|
|
|
|
|
+ .width(14)
|
|
|
|
|
+ .height(8)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.showTimePicker = true
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .justifyContent(FlexAlign.SpaceBetween)
|
|
|
|
|
+ .padding({top: 16, bottom: 16}) // , left: 20, right: 20
|
|
|
|
|
+
|
|
|
|
|
+ // 标题栏
|
|
|
|
|
+ Row() {
|
|
|
|
|
+ TextInput({ text: $$this.diaryData.title, placeholder: "输入标题会更受欢迎!" })
|
|
|
|
|
+ .padding(0)
|
|
|
|
|
+ .fontSize(16)
|
|
|
|
|
+ .fontWeight(500)
|
|
|
|
|
+ .maxLength(20)
|
|
|
|
|
+ .height('100%')
|
|
|
|
|
+ .layoutWeight(1)
|
|
|
|
|
+ .borderRadius(0)
|
|
|
|
|
+ .placeholderColor("#BFBFBF")
|
|
|
|
|
+ .backgroundColor(Color.Transparent)
|
|
|
|
|
+ .caretColor('app.color.main_ac_color_dark')
|
|
|
|
|
+ .placeholderFont({ size: 16, weight: FontWeight.Bold })
|
|
|
|
|
+
|
|
|
|
|
+ Row(){
|
|
|
|
|
+ if(this.diaryData.title && !this.pageReadOnly){
|
|
|
|
|
+ Image($r('app.media.Diary_close'))
|
|
|
|
|
+ .width(24)
|
|
|
|
|
+ .height(24)
|
|
|
|
|
+ .borderRadius(12)
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.diaryData.title = ''
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ .width(24)
|
|
|
|
|
+ .margin({right: 15})
|
|
|
|
|
+
|
|
|
|
|
+ Text(`${20 - (this.diaryData.title ? this.diaryData.title.length : 0) }`)
|
|
|
|
|
+ .fontColor("#BFBFBF")
|
|
|
|
|
+ }
|
|
|
|
|
+ .height(50)
|
|
|
|
|
+ .border({
|
|
|
|
|
+ width: {
|
|
|
|
|
+ bottom: 0.1
|
|
|
|
|
+ },
|
|
|
|
|
+ color: 20 - (this.diaryData.title ? this.diaryData.title.length : 0) === 0 ? Color.Red : "#BFBFBF"
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 内容栏
|
|
|
|
|
+ List(){
|
|
|
|
|
+ ListItem(){
|
|
|
|
|
+ TextArea({ text: $$this.diaryData.content, placeholder: "记录此刻" })
|
|
|
|
|
+ .padding(0)
|
|
|
|
|
+ .fontSize(14)
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .height("100%")
|
|
|
|
|
+ .borderRadius(0)
|
|
|
|
|
+ .fontWeight(400)
|
|
|
|
|
+ .placeholderColor("#BFBFBF")
|
|
|
|
|
+ .placeholderFont({ size: 16 })
|
|
|
|
|
+ .backgroundColor(Color.Transparent)
|
|
|
|
|
+ .caretColor('app.color.main_ac_color_dark')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ .padding({top: 12})
|
|
|
|
|
+ .layoutWeight(1)
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+
|
|
|
|
|
+ Column({space: 32}){
|
|
|
|
|
+ // 图片显示器
|
|
|
|
|
+ Scroll(){
|
|
|
|
|
+ Row({space: 5}){
|
|
|
|
|
+ ForEach(this.diaryData.imageUrls, (item: string, index: number) => {
|
|
|
|
|
+ Stack({alignContent: Alignment.TopEnd}){
|
|
|
|
|
+ Image(item)
|
|
|
|
|
+ .width(100)
|
|
|
|
|
+ .height(108)
|
|
|
|
|
+ if(!this.pageReadOnly) {
|
|
|
|
|
+ Image($r('app.media.Diary_close'))
|
|
|
|
|
+ .width(24)
|
|
|
|
|
+ .aspectRatio(1)
|
|
|
|
|
+ .offset({
|
|
|
|
|
+ x: -2, y: -2
|
|
|
|
|
+ })
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.delPhotoItem(index)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ .height(108)
|
|
|
|
|
+ .scrollable(ScrollDirection.Horizontal)
|
|
|
|
|
+ .align(Alignment.TopStart)
|
|
|
|
|
+
|
|
|
|
|
+ // 图片选择器
|
|
|
|
|
+ Row(){
|
|
|
|
|
+ // 清空
|
|
|
|
|
+ Row(){
|
|
|
|
|
+ if(!this.pageReadOnly){
|
|
|
|
|
+ Text('清空')
|
|
|
|
|
+ .fontSize(18)
|
|
|
|
|
+ .fontWeight(400)
|
|
|
|
|
+ .fontColor('#979797')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ .borderRadius(20)
|
|
|
|
|
+ .backgroundColor('#F0F0F0')
|
|
|
|
|
+ .alignItems(VerticalAlign.Center)
|
|
|
|
|
+ .justifyContent(FlexAlign.Center)
|
|
|
|
|
+ .padding({ top: 6, right: 18, bottom: 6, left: 18})
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ // this.clearPhoto()
|
|
|
|
|
+ this.diaryData.content = ''
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 相册
|
|
|
|
|
+ Row({space: 5}){
|
|
|
|
|
+ Image($r('app.media.photoAlbum'))
|
|
|
|
|
+ .width(20)
|
|
|
|
|
+ .aspectRatio(1)
|
|
|
|
|
+
|
|
|
|
|
+ Text("相册")
|
|
|
|
|
+ .fontSize(18)
|
|
|
|
|
+ .fontWeight(500)
|
|
|
|
|
+ }
|
|
|
|
|
+ .borderRadius(18)
|
|
|
|
|
+ .linearGradient(this.linearInfo)
|
|
|
|
|
+ .padding({ top: 12, right: 16, bottom: 12, left: 16})
|
|
|
|
|
+ .onClick(()=>{
|
|
|
|
|
+ this.photoSelect()
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .alignItems(VerticalAlign.Center)
|
|
|
|
|
+ .justifyContent(FlexAlign.SpaceBetween)
|
|
|
|
|
+ }
|
|
|
|
|
+ .padding({bottom: 64})
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .height("100%")
|
|
|
|
|
+
|
|
|
|
|
+ // 当页面不可编辑时添加覆盖层
|
|
|
|
|
+ if(this.pageReadOnly) {
|
|
|
|
|
+ Row()
|
|
|
|
|
+ .width('100%')
|
|
|
|
|
+ .height('100%')
|
|
|
|
|
+ .backgroundColor(Color.Transparent) // 透明覆盖层
|
|
|
|
|
+ .onTouch((event: TouchEvent) => {
|
|
|
|
|
+ event.stopPropagation() // 阻止触摸事件
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 开启时间选择器
|
|
|
|
|
+ if(this.showTimePicker){
|
|
|
|
|
+ Column(){
|
|
|
|
|
+ DiaryTimePicker({
|
|
|
|
|
+ timeStr: (this.diaryData.diaryDate ?? DateUtils.formatDateToCustomString(new Date(), true)).split(' ')[1],
|
|
|
|
|
+ onConfirm: (time: string) => {
|
|
|
|
|
+ this.showTimePicker = false
|
|
|
|
|
+ console.log("选择的时间 " + time)
|
|
|
|
|
+ this.diaryData.diaryDate = this.diaryData.diaryDate?.split(' ')[0] + ' ' + time
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .height("100%")
|
|
|
|
|
+ .padding({ top: 53 })
|
|
|
|
|
+ .alignItems(HorizontalAlign.End)
|
|
|
|
|
+ .justifyContent(FlexAlign.Start)
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.showTimePicker = false
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 开启日期选择器
|
|
|
|
|
+ if(this.showDatePicker) {
|
|
|
|
|
+ Column(){
|
|
|
|
|
+ DiaryDatePicker({
|
|
|
|
|
+ selectedDate: new Date(this.diaryData.diaryDate ?? new Date().toISOString()),
|
|
|
|
|
+ selectDateBack: (date: Date) => {
|
|
|
|
|
+ this.showDatePicker = false
|
|
|
|
|
+ let result = DateUtils.formatDateToCustomString(date, false)
|
|
|
|
|
+ console.log("选择的日期" + result)
|
|
|
|
|
+ try {
|
|
|
|
|
+ let temp = this.diaryData.diaryDate?.split(' ')[1]
|
|
|
|
|
+ this.diaryData.diaryDate = result + ' ' + temp
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .width("80%")
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .height("100%")
|
|
|
|
|
+ .padding({ top: 53 })
|
|
|
|
|
+ .alignItems(HorizontalAlign.Start)
|
|
|
|
|
+ .justifyContent(FlexAlign.Start)
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.showDatePicker = false
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .height("100%")
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .layoutWeight(1)
|
|
|
|
|
+ .backgroundColor(Color.White)
|
|
|
|
|
+ .alignItems(HorizontalAlign.Start)
|
|
|
|
|
+ .justifyContent(FlexAlign.Start)
|
|
|
|
|
+ .padding({ left: 20, right: 20 })
|
|
|
|
|
+ .borderRadius({
|
|
|
|
|
+ topLeft: 28, topRight: 28
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .height("100%")
|
|
|
|
|
+ .linearGradient(this.linearInfo)
|
|
|
|
|
+ }
|
|
|
|
|
+ .hideTitleBar(true)
|
|
|
|
|
+ .onBackPressed(() => {
|
|
|
|
|
+ console.log("返回"+this.pageReadOnly)
|
|
|
|
|
+ return this.onRouterBack.bind(this)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@Builder
|
|
|
|
|
+function IncreaseDiaryBuilder() {
|
|
|
|
|
+ IncreaseDiaryPage()
|
|
|
|
|
+}
|