Sfoglia il codice sorgente

fix:登录逻辑、文案、注销
1. 优化密码登录和验证码登录的逻辑冲突
2. 修改登录页面的文案(hello)
3. 修改日记详情页面中只读状态下页面的逻辑和组件的显示
4. 新增注销账号逻辑

YuJing 2 mesi fa
parent
commit
403ffdc397

+ 1 - 1
commons/basic/src/main/ets/apis/YTUserRequest.ets

@@ -209,7 +209,7 @@ export class YTUserRequest extends YTRequest {
 
   // 用户注销账号
   static logout() {
-    YTUserRequest.post<null, null>(YTUserUrl.LOGIN_OUT)
+    YTRequest.post<null, null>(YTUserUrl.LOGIN_OUT)
       .then(() => {
         IBestToast.show("注销成功")
         userInfo.logout()

+ 1 - 1
commons/basic/src/main/ets/constants/index.ets

@@ -96,5 +96,5 @@ export enum YTUserUrl {
   /**
    * @description 注销账号
    */
-  LOGIN_OUT = '/api/diaryApUser/member/logout'
+  LOGIN_OUT = '/diaryApUser/logout'
 }

+ 4 - 2
commons/basic/src/main/ets/models/LoginCollect.ets

@@ -9,7 +9,8 @@ export class LoginCollect {
   password?: string; // 密码(密码登录/注册/重置时使用)
   smsCode?: string; // 验证码(验证码登录/注册/重置时使用)
   confirmPassword?: string; // 确认密码(注册/重置时使用)
-  isAgreePrivacy: boolean = false; // 是否同意隐私政策
+  isAgreePrivacy: boolean = false; // 是否同意隐私政策\
+  isPassword: boolean = false; // 是否为密码登录
   private code?: string //华为登录code
   private operation: 'register' | 'reset' | 'login'; // 当前操作类型:注册/重置/登录
   private uuid?: string //验证码登录防伪标识
@@ -223,7 +224,8 @@ export class LoginCollect {
     }
 
     // 场景分支:密码登录 或 验证码登录
-    if (this.password) {
+    // 补充: 必须是在密码登录状态下才校验密码的合法性
+    if (this.isPassword && this.password) {
       // 密码登录:校验密码非空
       if (!this.password.trim()) {
 

+ 55 - 43
features/feature/src/main/ets/pages/IncreaseDiaryPage.ets

@@ -1,4 +1,4 @@
-import { IBestToast, YTAvoid, yTRouter, yTToast } from 'basic'
+import { IBestToast, YTAvoid, yTRouter, yTToast } from 'basic';
 import { photoAccessHelper } from '@kit.MediaLibraryKit';
 import { DiaryDatePicker } from '../components/DiaryDatePicker';
 import { DiaryData, PageStatus, Variable } from '../models';
@@ -8,8 +8,6 @@ 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';
 
 /**
  * 新增/编辑 日记
@@ -194,6 +192,13 @@ struct IncreaseDiaryPage {
     // 获取参数
     this.pageStatus = (params?.PageStatus ?? PageStatus.DIARY) as PageStatus
 
+    let date = (params?.nowDate ?? -1)as number
+
+    if(date != -1){
+      this.diaryData.diaryDate = DateUtils.formatDateToCustomString(new Date(date), true, false)
+      console.log("参数" + this.diaryData.diaryDate)
+    }
+
     // 获取参数
     let id = (params?.id ?? -1) as number;
     if (id != -1) {
@@ -219,8 +224,6 @@ struct IncreaseDiaryPage {
   async aboutToAppear(): Promise<void> {
     this.diaryData.diaryDate = DateUtils.formatDateToCustomString(new Date(), true, false)
     this.getRouterParams()
-
-    // TODO 在没有数据的时候 时间选择器的回显为 undefined
   }
 
   build() {
@@ -271,7 +274,9 @@ struct IncreaseDiaryPage {
                     .height(8)
                 }
                 .onClick(() => {
-                  this.showDatePicker = true
+                  if(!this.pageReadOnly){
+                    this.showDatePicker = true
+                  }
                 })
 
                 // 时间选择
@@ -287,7 +292,9 @@ struct IncreaseDiaryPage {
                   }
                 }
                 .onClick(() => {
-                  this.showTimePicker = true
+                  if(!this.pageReadOnly) {
+                    this.showTimePicker = true
+                  }
                 })
               }
               .width("100%")
@@ -296,18 +303,26 @@ struct IncreaseDiaryPage {
 
               // 标题栏
               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 })
+                if(!this.pageReadOnly) {
+                  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 })
+                } else {
+                  Text(this.diaryData.title)
+                    .fontSize(16)
+                    .fontWeight(500)
+                    .layoutWeight(1)
+                }
+
 
                 Row(){
                   if(this.diaryData.title && !this.pageReadOnly){
@@ -337,17 +352,24 @@ struct IncreaseDiaryPage {
               // 内容栏
               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')
+                  if(!this.pageReadOnly) {
+                    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')
+                  } else {
+                    Text(this.diaryData.content)
+                      .width("100%")
+                      .fontSize(14)
+                      .fontWeight(400)
+                  }
                 }
               }
               .padding({top: 12})
@@ -400,7 +422,6 @@ struct IncreaseDiaryPage {
                   .justifyContent(FlexAlign.Center)
                   .padding({ top: 6, right: 18, bottom: 6, left: 18})
                   .onClick(() => {
-                    // this.clearPhoto()
                     this.diaryData.content = ''
                   })
 
@@ -418,7 +439,9 @@ struct IncreaseDiaryPage {
                   .linearGradient(this.linearInfo)
                   .padding({ top: 12, right: 16, bottom: 12, left: 16})
                   .onClick(()=>{
-                    this.photoSelect()
+                    if(!this.pageReadOnly) {
+                      this.photoSelect()
+                    }
                   })
                 }
                 .width("100%")
@@ -430,17 +453,6 @@ struct IncreaseDiaryPage {
             .width("100%")
             .height("100%")
 
-            // 当页面不可编辑时添加覆盖层
-            if(this.pageReadOnly) {
-              Row()
-                .width('100%')
-                .height('100%')
-                .backgroundColor(Color.Transparent) // 透明覆盖层
-                .onTouch((event: TouchEvent) => {
-                  event.stopPropagation() // 阻止触摸事件
-                })
-            }
-
             // 开启时间选择器
             if(this.showTimePicker){
               Column(){

+ 19 - 2
features/feature/src/main/ets/utils/DateUtils.ets

@@ -25,6 +25,13 @@ function createDateInfo(date: Date): DateInfo {
 
 
 export class DateUtils {
+  /**
+   * 格式化日期对象为自定义字符串
+   * @param date 日期对象
+   * @param needTime 是否需要时间 ( 时、分、秒 )
+   * @param needSecond 是否需要秒
+   * @returns
+   */
   static formatDateToCustomString(date: Date, needTime: boolean = true, needSecond: boolean = true): string {
     // 转换为 YY-MM-DD HH:mm:ss 格式
     const year = date.getFullYear().toString();
@@ -38,12 +45,22 @@ export class DateUtils {
     return result;
   }
 
-  // 获取指定月份的天数
+  /**
+   * 获取指定月份的天数
+   * @param year 年
+   * @param month 月份
+   * @returns 当月的天数
+   */
   static getDaysInMonth(year: number, month: number): number {
     return new Date(year, month, 0).getDate();
   }
 
-  // 是否为同一天
+  /**
+   * 判断两个 Date 对象是否为同一天
+   * @param date1
+   * @param date2
+   * @returns
+   */
   static isSameDay(date1: Date, date2: Date): boolean {
     return (
       date1.getFullYear() === date2.getFullYear() &&

+ 9 - 1
features/feature/src/main/ets/view/RecodView.ets

@@ -77,9 +77,17 @@ export struct RecodView {
    * @param id
    */
   routerAddNote(id?: number) {
+    // 产品要求:
+    // 1. 日期需要和上一级页面选择的日期保持一致。
+    let date: string = this.Vm.getSelectedDate().split(' ')[0]
+    // 2. 时间需要和当前时间保持一致。
+    let time: string = DateUtils.formatDateToCustomString(new Date(), true, false).split(' ')[1]
+    let ans: string = date + ' ' + time
+
     yTRouter.pushPathByName("IncreaseDiaryPage", {
       'id': id,
-      'PageStatus': PageStatus.RECODE
+      'PageStatus': PageStatus.RECODE,
+      'nowDate': new Date(ans).getTime(),
     } as Record<string, boolean | number | string>);
   }
 

+ 1 - 1
features/user/src/main/ets/pages/LoginPage.ets

@@ -44,7 +44,7 @@ struct LoginPage {
             .borderRadius(12)
             .backgroundColor('#4DFFFFFF')
             .margin({ bottom: 24, right: 28, top: 20 })
-          Text('HELLLO,\n欢迎来到朝暮日记')
+          Text('HELLO,\n欢迎来到朝暮日记')
             .lineHeight(40)
             .fontSize(28)
             .fontWeight(600)

+ 0 - 3
features/user/src/main/ets/pages/SettingPage.ets

@@ -114,9 +114,6 @@ struct SettingPage {
             yTToast.doubleConfirm({
               text: '警告⚠', message: '确定要注销吗?\n注销后数据可能丢失无法恢复!',
               click: () => {
-                userInfo.logout()
-                yTToast.hide()
-                yTRouter.routerBack()
                 YTUserRequest.logout()
               },
             })

+ 4 - 5
features/user/src/main/ets/views/LoginView.ets

@@ -9,7 +9,6 @@ import { CodeInputType } from '../models'
 @Component
 export struct LoginView {
   @State private loginCollect: LoginCollect = new LoginCollect('login')
-  @State private isPassword: boolean = false
   private inputCaptchaType: CodeInputType = {
     txt: '验证码',
     placeHolder: '请输入验证码'
@@ -53,7 +52,7 @@ export struct LoginView {
           this.loginCollect.phonenumber = value
         }
       })
-      if (this.isPassword) {
+      if (this.loginCollect.isPassword) {
         LoginInput({
           item: this.inputPasswordType,
           inputData: this.loginCollect.password,
@@ -85,13 +84,13 @@ export struct LoginView {
       })
 
       Row() {
-        if (!this.isPassword) {
+        if (!this.loginCollect.isPassword) {
           Text('密码登录')
             .fontColor($r('[basic].color.main_blank'))
             .fontSize(12)
             .fontWeight(700)
             .onClick(() => {
-              this.isPassword = true
+              this.loginCollect.isPassword = true
             })
           Blank()
         } else {
@@ -100,7 +99,7 @@ export struct LoginView {
             .fontWeight(700)
             .fontSize(12)
             .onClick(() => {
-              this.isPassword = false
+              this.loginCollect.isPassword = false
             })
           Blank()
           Text('忘记密码?')