wangcy 2 месяцев назад
Родитель
Сommit
41c601d4d4

+ 2 - 0
commons/basic/Index.ets

@@ -1,3 +1,5 @@
+export { BackgroundPageModifier } from './src/main/ets/styles/AttributeModifier'
+
 export { pushMessageUtil } from './src/main/ets/utils/NoticeUtil'
 
 export { yTPreferences } from './src/main/ets/utils/YTPreferencesUtil'

+ 1 - 0
commons/basic/src/main/ets/apis/YTRequest.ets

@@ -60,6 +60,7 @@ instance.interceptors.response.use((response: AxiosResponse) => {
     return Promise.reject(response.data);
   }
 
+
   return response.data.data;
 }, (error: AxiosError) => {
   YTLog.error(error)

+ 172 - 0
commons/basic/src/main/ets/constants/StyleConstants.ets

@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Style constants for all features.
+ */
+export default class StyleConstants {
+  /**
+   *  Login logo component height of the parent 30.
+   */
+  static readonly LOGIN_LOGO_HEIGHT: string = '30%';
+  /**
+   *  Login bottom component height of the parent 50.
+   */
+  static readonly LOGIN_CENTER_HEIGHT: string = '50%';
+  /**
+   *  Login bottom component height of the parent 50.
+   */
+  static readonly LOGIN_BOTTOM_HEIGHT: string = '20%';
+  /**
+   * The width or height of the component is spread across the parent component.
+   */
+  static readonly FULL_PARENT: string = '100%';
+  /**
+   * The width of button.
+   */
+  static readonly BUTTON_WIDTH: string = '90%';
+  /**
+   * Grid columns of the 4.
+   */
+  static readonly GRID_COLUMNS: string = '1fr 1fr 1fr 1fr';
+  /**
+   * Grid rows of two the 2.
+   */
+  static readonly GRID_ROWS: string = '1fr 1fr';
+  /**
+   * Home grid height of the parent 15.9.
+   */
+  static readonly HOME_GRID_HEIGHT: string = '15.9%';
+  /**
+   * Bar width lg of the parent 7.5.
+   */
+  static readonly BAR_WIDTH_LG: string = '7.5%';
+  /**
+   * Bar default height of the parent 7.2.
+   */
+  static readonly BAR_DEFAULT_HEIGHT: string = '7.2%';
+  /**
+   * Bar height lg of the parent 50.
+   */
+  static readonly BAR_HEIGHT_LG: string = '50%';
+  /**
+   * Component common width of the parent 95.
+   */
+  static readonly COMMON_WIDTH: string = '95%';
+  /**
+   * Input length of the account.
+   */
+  static readonly INPUT_ACCOUNT_LENGTH: number = 11;
+  /**
+   *  Input length of the password.
+   */
+  static readonly INPUT_PASSWORD_LENGTH: number = 20;
+  /**
+   *  Left padding of the input box.
+   */
+  static readonly INPUT_PADDING_LEFT: number = 12;
+  /**
+   *  Layout weight of number 1.
+   */
+  static readonly WEIGHT_ONE: number = 1;
+  /**
+   * Common Spacing of Components.
+   */
+  static readonly COMMON_SPACE: number = 12;
+  /**
+   * Logo margin bottom of the parent 50.
+   */
+  static readonly LOGO_MARGIN_BOTTOM: number = 50;
+  /**
+   * Item space of the 12.
+   */
+  static readonly ITEM_SPACE: number = 12;
+  /**
+   * Grid aspect ratio of the 1.32.
+   */
+  static readonly GRID_ASPECT_RATIO: number = 1.32;
+  /**
+   * Swiper count of the 1.
+   */
+  static readonly SWIPER_COUNT_ONE: number = 1;
+  /**
+   * Swiper count of the 2.
+   */
+  static readonly SWIPER_COUNT_TWO: number = 2;
+  /**
+   * Swiper count of the 3.
+   */
+  static readonly SWIPER_COUNT_THREE: number = 3;
+  /**
+   * List column of the 2.
+   */
+  static readonly LIST_COLUMN_TWO: number = 2;
+  /**
+   * List column of the 3.
+   */
+  static readonly LIST_COLUMN_THREE: number = 3;
+  /**
+   * List column of the 4.
+   */
+  static readonly LIST_COLUMN_FOUR: number = 4;
+  /**
+   * Image list of the 12.
+   */
+  static readonly IMAGE_LIST_SPACE: number = 12;
+  /**
+   * Grid row columns sm of the 4.
+   */
+  static readonly COLUMNS_SM: number = 4;
+  /**
+   * Grid row columns md of the 8.
+   */
+  static readonly COLUMNS_MD: number = 8;
+  /**
+   * Grid row columns lg of the 12.
+   */
+  static readonly COLUMNS_LG: number = 12;
+  /**
+   * Grid gutter of the 12.
+   */
+  static readonly GRID_GUTTER: number = 12;
+  /**
+   * Grid col span sm of the 4.
+   */
+  static readonly SPAN_SM: number = 4;
+  /**
+   * Grid col span md of the 6.
+   */
+  static readonly SPAN_MD: number = 6;
+  /**
+   * Grid col span lg of the 8.
+   */
+  static readonly SPAN_LG: number = 8;
+  /**
+   * Grid col offset md of the 1.
+   */
+  static readonly OFFSET_MD: number = 1;
+  /**
+   * Grid col offset lg of the 2.
+   */
+  static readonly OFFSET_LG: number = 2;
+  /**
+   * 沉浸式状态栏闪避高度
+   */
+  static readonly TOP_HEIGHT: number = Number(AppStorage.get('safeTop'))
+  /**
+   * 沉浸式导航栏闪避高度
+   */
+  static readonly BOTTOM_HEIGHT: number = Number(AppStorage.get('bottomTop'))
+}

+ 43 - 0
commons/basic/src/main/ets/styles/AttributeModifier.ets

@@ -0,0 +1,43 @@
+import StyleConstants from '../constants/StyleConstants'
+
+export class BackgroundPageModifier implements AttributeModifier<CommonAttribute> {
+  isNeedImage: boolean
+  isNeedPaddingTop: boolean
+  isNeedPaddingBottom: boolean
+
+  constructor(isNeedImage: boolean, isNeedPaddingTop: boolean = true, isNeedPaddingBottom: boolean = true) {
+    this.isNeedImage = isNeedImage
+    this.isNeedPaddingTop = isNeedPaddingTop
+    this.isNeedPaddingBottom = isNeedPaddingBottom
+  }
+
+  applyNormalAttribute(instance: CommonAttribute): void {
+    if (this.isNeedImage) {
+      instance
+        .height(StyleConstants.FULL_PARENT)
+        .width(StyleConstants.FULL_PARENT)
+        .backgroundColor($r("app.color.theme_bg_color"))
+        // .backgroundImage($r("app.media.bgPage"))
+        .backgroundImageSize({ width: '100%', height: '100%' })//backgroundImageSize((ImageSize.Cover))
+        .backgroundImagePosition(Alignment.Center)
+        .padding({
+          top: this.isNeedPaddingTop ? StyleConstants.TOP_HEIGHT : 0,
+          bottom: this.isNeedPaddingBottom ? StyleConstants.BOTTOM_HEIGHT : 0,
+          left: 10,
+          right: 10
+        })
+    } else {
+      instance
+        .height(StyleConstants.FULL_PARENT)
+        .width(StyleConstants.FULL_PARENT)
+        .backgroundColor($r("app.color.theme_bg_color"))
+        .padding({
+          top: this.isNeedPaddingTop ? StyleConstants.TOP_HEIGHT : 0,
+          bottom: this.isNeedPaddingBottom ? StyleConstants.BOTTOM_HEIGHT : 0,
+          left: 10,
+          right: 10
+        })
+    }
+  }
+}
+

+ 2 - 2
commons/basic/src/main/ets/utils/YTPhotoHelper.ets

@@ -76,10 +76,10 @@ export class YTPhotoHelper {
   }
 
   //从相册选择图片
-  selectImage(success: (fullPath: string) => void) {
+  selectImage(success: (fullPath: string) => void, maxNumber: number = 1) {
     const option = new photoAccessHelper.PhotoSelectOptions()
     option.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE
-    option.maxSelectNumber = 1
+    option.maxSelectNumber = maxNumber
     const picker = new photoAccessHelper.PhotoViewPicker()
     picker.select(option)
       .then(res => {

+ 4 - 0
commons/basic/src/main/resources/base/element/color.json

@@ -19,6 +19,10 @@
     {
       "name": "main_blank",
       "value": "#FF161718"
+    },
+    {
+      "name": "theme_bg_color",
+      "value": "#FF161718"
     }
   ]
 }

+ 6 - 1
features/feature/src/main/ets/view/MainView.ets

@@ -1,6 +1,11 @@
+import { BackgroundPageModifier } from 'basic';
+
 @Component
 export struct MainView {
   build() {
-    Text('1')
+    Column() {
+
+    }
+    .attributeModifier(new BackgroundPageModifier(true))
   }
 }

+ 2 - 1
products/entry/src/main/ets/pages/Index.ets

@@ -1,4 +1,4 @@
-import { BasicType, YTAvoid, yTRouter, yTToast, YTUserRequest } from 'basic';
+import { BackgroundPageModifier, BasicType, YTAvoid, yTRouter, yTToast, YTUserRequest } from 'basic';
 import { Mine } from 'user/src/main/ets/views/Mine';
 import { MainView, SecondView, ThirdView } from 'feature';
 
@@ -85,6 +85,7 @@ struct Index {
       .height('100%')
       .backgroundColor(Color.White)
 
+
     }
     .mode(NavigationMode.Stack)
     .hideToolBar(true)