AboutPage.ets 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. @Consume mType: number
  17. @Consume isShowDrawer: boolean;
  18. @Consume offsetX: number;
  19. @State isDarkMode: boolean = false
  20. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  21. ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  22. /** 当前断点类型(如大屏/小屏) */
  23. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  24. @StorageProp('themeColor') themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
  25. onColorModeChange() {
  26. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  27. }
  28. @State verName:string = ''
  29. @State appName:string = ''
  30. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  31. // 组件生命周期
  32. aboutToAppear() {
  33. // Utility.disableFullScreen()
  34. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  35. this.verName = AppUtil.getVersionName()
  36. Utility.getAppName(getContext(this)).then((appName:string)=>{
  37. this.appName = appName
  38. })
  39. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  40. AppStorage.setOrCreate('themeColor', themeColor);
  41. this.themeColor = themeColor;
  42. this.onColorModeChange()
  43. console.info('LifeCycleComponent aboutToAppear');
  44. }
  45. // 组件生命周期
  46. aboutToDisappear() {
  47. console.info('LifeCycleComponent aboutToDisappear');
  48. }
  49. // 工具函数:hex转hsl、hsl转hex、生成渐变色
  50. hexToHsl(hex: string): [number, number, number] {
  51. hex = hex.replace('#', '');
  52. let r = parseInt(hex.substring(0,2), 16) / 255;
  53. let g = parseInt(hex.substring(2,4), 16) / 255;
  54. let b = parseInt(hex.substring(4,6), 16) / 255;
  55. let max = Math.max(r, g, b), min = Math.min(r, g, b);
  56. let h = 0, s = 0, l = (max + min) / 2;
  57. if(max !== min){
  58. let d = max - min;
  59. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  60. switch(max){
  61. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  62. case g: h = (b - r) / d + 2; break;
  63. case b: h = (r - g) / d + 4; break;
  64. }
  65. h = h * 60;
  66. }
  67. return [h, s, l];
  68. }
  69. hslToHex(h: number, s: number, l: number): string {
  70. let c = (1 - Math.abs(2 * l - 1)) * s;
  71. let x = c * (1 - Math.abs((h / 60) % 2 - 1));
  72. let m = l - c/2;
  73. let r=0, g=0, b=0;
  74. if (0 <= h && h < 60) { r = c; g = x; b = 0; }
  75. else if (60 <= h && h < 120) { r = x; g = c; b = 0; }
  76. else if (120 <= h && h < 180) { r = 0; g = c; b = x; }
  77. else if (180 <= h && h < 240) { r = 0; g = x; b = c; }
  78. else if (240 <= h && h < 300) { r = x; g = 0; b = c; }
  79. else if (300 <= h && h < 360) { r = c; g = 0; b = x; }
  80. let toHex = (v: number) => Math.round((v + m) * 255).toString(16).padStart(2, '0');
  81. return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
  82. }
  83. getGradientColor(themeColor: string, offset: number = 40): string {
  84. let hsl = this.hexToHsl(themeColor);
  85. let h = hsl[0];
  86. let s = hsl[1];
  87. let l = hsl[2];
  88. h = (h + offset) % 360;
  89. return this.hslToHex(h, s, l);
  90. }
  91. build() {
  92. Column(){
  93. // 顶部安全区和自定义标题栏
  94. Column() {
  95. // 顶部安全区
  96. Blank()
  97. .height(this.topRectHeight)
  98. .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
  99. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  100. // 自定义标题栏(Stack实现绝对居中)
  101. Stack() {
  102. // 居中标题
  103. Text('关于我们')
  104. .fontSize(18)
  105. .fontColor(Color.White)
  106. .align(Alignment.Center)
  107. // 左右按钮
  108. Row() {
  109. Image($r('app.media.left_back_white'))
  110. .width(26)
  111. .height(26)
  112. .margin({ left: 12, right: 8 })
  113. .onClick(() => {
  114. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  115. // 动画闭包内控制Image组件的出现和消失
  116. // this.isShowDrawer = !this.isShowDrawer
  117. // this.offsetX = 0
  118. this.mType =0
  119. })
  120. })
  121. Blank().flexGrow(1)
  122. Blank().width(32)
  123. }
  124. .height(48)
  125. .width('100%')
  126. .alignItems(VerticalAlign.Center)
  127. }
  128. .height(48)
  129. .width('100%')
  130. .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
  131. }
  132. Scroll(){
  133. Column(){
  134. Image($r('app.media.icon'))
  135. .width(120)
  136. .height(120)
  137. .borderRadius('100%')
  138. .clip(true)
  139. Text(this.appName+'V:'+this.verName)
  140. .fontColor(this.isDarkMode ? Color.White : Color.Black)
  141. .fontWeight(480)
  142. .fontSize(17)
  143. .margin({top:20,bottom:10})
  144. Text(CommonConstants.ICP_NO)
  145. .fontColor(this.isDarkMode ? Color.White : Color.Black)
  146. .fontWeight(480)
  147. .decoration({ type: TextDecorationType.Underline, color: this.isDarkMode ? Color.White : Color.Black })
  148. .fontSize(17)
  149. .margin({top:10,bottom:10})
  150. .onClick(()=>{
  151. let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  152. context.openLink(CommonConstants.ICP_URL, {})
  153. })
  154. Button('用户协议', { type: ButtonType.Capsule, stateEffect: false })
  155. .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'25%':'60%')
  156. .height(55)
  157. .margin({top:10,bottom:10})
  158. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  159. .stateEffect(true)
  160. .backgroundColor(this.themeColor)
  161. .onClick(()=>{
  162. router.pushUrl({
  163. url: 'pages/WebIndex',
  164. params: { titleName: '用户协议', webUrl: CommonConstants.NEW_DUTY }
  165. });
  166. })
  167. Button('隐私政策', { type: ButtonType.Capsule, stateEffect: false })
  168. .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'25%':'60%')
  169. .height(55)
  170. .margin({top:10,bottom:10})
  171. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  172. .stateEffect(true)
  173. .backgroundColor(this.themeColor)
  174. .onClick(()=>{
  175. router.pushUrl({
  176. url: 'pages/WebIndex',
  177. params: { titleName: '隐私政策', webUrl: CommonConstants.NEW_YS_HW }
  178. });
  179. })
  180. Button('音频标签', { type: ButtonType.Capsule, stateEffect: false })
  181. .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'25%':'60%')
  182. .height(55)
  183. .margin({top:10,bottom:10})
  184. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  185. .stateEffect(true)
  186. .backgroundColor(this.themeColor)
  187. .onClick(()=>{
  188. Utility.gotoMarket(getContext(this) as common.UIAbilityContext, 'com.xgplayer.ttmusic.tags')
  189. })
  190. Button('视频播放器', { type: ButtonType.Capsule, stateEffect: false })
  191. .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'25%':'60%')
  192. .height(55)
  193. .margin({top:10,bottom:10})
  194. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  195. .stateEffect(true)
  196. .backgroundColor(this.themeColor)
  197. .onClick(()=>{
  198. Utility.gotoMarket(getContext(this) as common.UIAbilityContext, 'com.kuaiyao.kdb.hm')
  199. })
  200. Button('粉丝QQ群', { type: ButtonType.Capsule, stateEffect: false })
  201. .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'25%':'60%')
  202. .height(55)
  203. .margin({top:10,bottom:20})
  204. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  205. .stateEffect(true)
  206. .backgroundColor(this.themeColor)
  207. .onClick(()=>{
  208. ToastUtil.showToast('复制群号成功!')
  209. Utility.copyText('685109858')
  210. const qqUrl = `mqqapi://card/show_pslcard?src_type=internal&version=1&uin=${CommonConstants.QQ_GROUP}&card_type=group&source=external`;
  211. let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  212. context.openLink(qqUrl, {})
  213. })
  214. Button('用户反馈', { type: ButtonType.Capsule, stateEffect: false })
  215. .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'25%':'60%')
  216. .height(55)
  217. .stateEffect(true)
  218. .margin({bottom:20})
  219. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  220. .backgroundColor(this.themeColor)
  221. .onClick(()=>{
  222. AlertDialog.show({
  223. title:'发送邮件',
  224. message:'感谢你的支持,如果有什么不支持的格式不能播放请反馈给我们修复,谢谢!有建议和反馈的请邮件联系我们:'+CommonConstants.CONTACT_MAIL,
  225. autoCancel:true,
  226. alignment:DialogAlignment.Center,
  227. offset:{dx:0,dy:-20},
  228. confirm:{
  229. value:'确定',
  230. fontColor:Color.White,
  231. backgroundColor:$r('app.color.title_bar_bg'),
  232. action:()=>{
  233. ToastUtil.showToast('复制邮件地址成功!')
  234. Utility.copyText(CommonConstants.CONTACT_MAIL)
  235. }
  236. }
  237. })
  238. })
  239. }
  240. .justifyContent(FlexAlign.Start)
  241. .width('100%')
  242. }
  243. .layoutWeight(1)
  244. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  245. .animation({ duration: 380, curve: Curve.Ease,delay:50 }))
  246. .backgroundColor(this.isDarkMode?Color.Black:this.themeColor)
  247. .linearGradient(!this.isDarkMode ? {colors:[[this.themeColor, 0.0], [this.getGradientColor(this.themeColor, 40), 0.6]]} : undefined)
  248. }
  249. .layoutWeight(1)
  250. .width('100%')
  251. .height('100%')
  252. }
  253. }