AboutPage.ets 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import TitleBar from '../view/TitleBar'
  2. import { router } from '@kit.ArkUI'
  3. import { CommonConstants } from '../common/constants/CommonConstants'
  4. import { AppUtil, DeviceUtil, DisplayUtil, ToastUtil } from '@pura/harmony-utils'
  5. import { Utility } from '../common/util/Utility'
  6. import { common, ConfigurationConstant } from '@kit.AbilityKit'
  7. import { BreakpointTypeEnum } from '../common/util/BreakpointSystem'
  8. import { resourceManager } from '@kit.LocalizationKit'
  9. import { PreferencesUtil } from '@pura/harmony-utils'
  10. import { hilog } from '@kit.PerformanceAnalysisKit'
  11. import { BusinessError } from '@kit.BasicServicesKit'
  12. @Preview
  13. @Entry
  14. @Component
  15. export struct AboutPage{
  16. @State isDarkMode: boolean = false
  17. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  18. ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  19. /** 当前断点类型(如大屏/小屏) */
  20. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  21. @StorageProp('themeColor') themeColor: string = '#FF4081';
  22. onColorModeChange() {
  23. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  24. }
  25. @State verName:string = ''
  26. @State appName:string = ''
  27. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  28. // 组件生命周期
  29. aboutToAppear() {
  30. // Utility.disableFullScreen()
  31. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  32. this.verName = AppUtil.getVersionName()
  33. Utility.getAppName(getContext(this)).then((appName:string)=>{
  34. this.appName = appName
  35. })
  36. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
  37. AppStorage.setOrCreate('themeColor', themeColor);
  38. this.themeColor = themeColor;
  39. this.onColorModeChange()
  40. console.info('LifeCycleComponent aboutToAppear');
  41. }
  42. // 组件生命周期
  43. aboutToDisappear() {
  44. console.info('LifeCycleComponent aboutToDisappear');
  45. }
  46. // 工具函数:hex转hsl、hsl转hex、生成渐变色
  47. hexToHsl(hex: string): [number, number, number] {
  48. hex = hex.replace('#', '');
  49. let r = parseInt(hex.substring(0,2), 16) / 255;
  50. let g = parseInt(hex.substring(2,4), 16) / 255;
  51. let b = parseInt(hex.substring(4,6), 16) / 255;
  52. let max = Math.max(r, g, b), min = Math.min(r, g, b);
  53. let h = 0, s = 0, l = (max + min) / 2;
  54. if(max !== min){
  55. let d = max - min;
  56. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  57. switch(max){
  58. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  59. case g: h = (b - r) / d + 2; break;
  60. case b: h = (r - g) / d + 4; break;
  61. }
  62. h = h * 60;
  63. }
  64. return [h, s, l];
  65. }
  66. hslToHex(h: number, s: number, l: number): string {
  67. let c = (1 - Math.abs(2 * l - 1)) * s;
  68. let x = c * (1 - Math.abs((h / 60) % 2 - 1));
  69. let m = l - c/2;
  70. let r=0, g=0, b=0;
  71. if (0 <= h && h < 60) { r = c; g = x; b = 0; }
  72. else if (60 <= h && h < 120) { r = x; g = c; b = 0; }
  73. else if (120 <= h && h < 180) { r = 0; g = c; b = x; }
  74. else if (180 <= h && h < 240) { r = 0; g = x; b = c; }
  75. else if (240 <= h && h < 300) { r = x; g = 0; b = c; }
  76. else if (300 <= h && h < 360) { r = c; g = 0; b = x; }
  77. let toHex = (v: number) => Math.round((v + m) * 255).toString(16).padStart(2, '0');
  78. return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
  79. }
  80. getGradientColor(themeColor: string, offset: number = 40): string {
  81. let hsl = this.hexToHsl(themeColor);
  82. let h = hsl[0];
  83. let s = hsl[1];
  84. let l = hsl[2];
  85. h = (h + offset) % 360;
  86. return this.hslToHex(h, s, l);
  87. }
  88. build() {
  89. Column(){
  90. // 顶部安全区和自定义标题栏
  91. Column() {
  92. // 顶部安全区
  93. Blank()
  94. .height(this.topRectHeight)
  95. .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
  96. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  97. // 自定义标题栏(Stack实现绝对居中)
  98. Stack() {
  99. // 居中标题
  100. Text('关于我们')
  101. .fontSize(18)
  102. .fontColor(Color.White)
  103. .align(Alignment.Center)
  104. // 左右按钮
  105. Row() {
  106. Image($r('app.media.left_back_white'))
  107. .width(24)
  108. .height(24)
  109. .margin({ left: 12, right: 8 })
  110. .onClick(() => {
  111. router.back();
  112. })
  113. Blank().flexGrow(1)
  114. Blank().width(32)
  115. }
  116. .height(48)
  117. .width('100%')
  118. .alignItems(VerticalAlign.Center)
  119. }
  120. .height(48)
  121. .width('100%')
  122. .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
  123. }
  124. Scroll(){
  125. Column(){
  126. Image($r('app.media.icon'))
  127. .width(150)
  128. .height(150)
  129. .borderRadius('100%')
  130. .clip(true)
  131. .margin({top:55})
  132. Text(this.appName+'V:'+this.verName)
  133. .fontColor(this.isDarkMode ? Color.White : Color.Black)
  134. .fontWeight(480)
  135. .fontSize(17)
  136. .margin({top:20,bottom:20})
  137. Text(CommonConstants.ICP_NO)
  138. .fontColor(this.isDarkMode ? Color.White : Color.Black)
  139. .fontWeight(480)
  140. .decoration({ type: TextDecorationType.Underline, color: this.isDarkMode ? Color.White : Color.Black })
  141. .fontSize(18)
  142. .margin({top:20,bottom:20})
  143. .onClick(()=>{
  144. // let want = {
  145. // action: "ohos.want.action.viewData",
  146. // uri: CommonConstants.ICP_URL
  147. // };
  148. let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  149. context.openLink(CommonConstants.ICP_URL, {})
  150. })
  151. Button('加入Q群:685109858', { type: ButtonType.Capsule, stateEffect: false })
  152. .width('60%')
  153. .height(55)
  154. .margin({top:50,bottom:20})
  155. // .visibility(Visibility.None)
  156. .stateEffect(true)
  157. .backgroundColor(this.themeColor)
  158. .stateStyles({
  159. pressed: { opacity: 0.6 }
  160. })
  161. .onClick(()=>{
  162. // ToastUtil.showToast('复制群号成功!')
  163. // Utility.copyText('685109858')
  164. const qqUrl = `mqqapi://card/show_pslcard?src_type=internal&version=1&uin=${CommonConstants.QQ_GROUP}&card_type=group&source=external`;
  165. let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  166. context.openLink(qqUrl, {})
  167. })
  168. Button('用户反馈', { type: ButtonType.Capsule, stateEffect: false })
  169. .width('60%')
  170. .height(55)
  171. .stateEffect(true)
  172. .margin({bottom:20})
  173. .backgroundColor(this.themeColor)
  174. .stateStyles({
  175. pressed: { opacity: 0.6 }
  176. })
  177. .onClick(()=>{
  178. AlertDialog.show({
  179. title:'发送邮件',
  180. message:'感谢你的支持,如果有什么不支持的格式不能播放请反馈给我们修复,谢谢!有建议和反馈的请邮件联系我们:'+CommonConstants.CONTACT_MAIL,
  181. autoCancel:true,
  182. alignment:DialogAlignment.Center,
  183. offset:{dx:0,dy:-20},
  184. confirm:{
  185. value:'确定',
  186. fontColor:Color.White,
  187. backgroundColor:$r('app.color.title_bar_bg'),
  188. action:()=>{
  189. ToastUtil.showToast('复制邮件地址成功!')
  190. Utility.copyText(CommonConstants.CONTACT_MAIL)
  191. }
  192. }
  193. })
  194. })
  195. }
  196. .height('100%')
  197. .width('100%')
  198. }
  199. .height(px2vp(DisplayUtil.getHeight()-AppUtil.getStatusBarHeight()-AppUtil.getNavigationIndicatorHeight()))
  200. .backgroundColor(this.isDarkMode?Color.Black:this.themeColor)
  201. .linearGradient(!this.isDarkMode ? {colors:[[this.themeColor, 0.0], [this.getGradientColor(this.themeColor, 40), 0.6]]} : undefined)
  202. }
  203. }
  204. }