AboutPage.ets 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. import { systemShare } from '@kit.ShareKit'
  13. import { uniformTypeDescriptor } from '@kit.ArkData'
  14. @Preview
  15. // @Entry
  16. @Component
  17. export struct AboutPage{
  18. context = this.getUIContext().getHostContext() as common.UIAbilityContext
  19. /** 应用包名 */
  20. @State bundleName: string = ''
  21. @Consume mType: number
  22. @Consume isShowDrawer: boolean;
  23. @Consume offsetX: number;
  24. @State isDarkMode: boolean = false
  25. @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
  26. ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  27. /** 当前断点类型(如大屏/小屏) */
  28. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  29. @StorageProp('themeColor') themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
  30. onColorModeChange() {
  31. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  32. }
  33. @State verName:string = ''
  34. @State appName:string = ''
  35. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  36. // 组件生命周期
  37. aboutToAppear() {
  38. // Utility.disableFullScreen()
  39. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  40. this.verName = AppUtil.getVersionName()
  41. Utility.getAppName(getContext(this)).then((appName:string)=>{
  42. this.appName = appName
  43. })
  44. this.bundleName = AppUtil.getBundleName()
  45. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  46. AppStorage.setOrCreate('themeColor', themeColor);
  47. this.themeColor = themeColor;
  48. this.onColorModeChange()
  49. console.info('LifeCycleComponent aboutToAppear');
  50. }
  51. // 组件生命周期
  52. aboutToDisappear() {
  53. console.info('LifeCycleComponent aboutToDisappear');
  54. }
  55. // 工具函数:hex转hsl、hsl转hex、生成渐变色
  56. hexToHsl(hex: string): [number, number, number] {
  57. hex = hex.replace('#', '');
  58. let r = parseInt(hex.substring(0,2), 16) / 255;
  59. let g = parseInt(hex.substring(2,4), 16) / 255;
  60. let b = parseInt(hex.substring(4,6), 16) / 255;
  61. let max = Math.max(r, g, b), min = Math.min(r, g, b);
  62. let h = 0, s = 0, l = (max + min) / 2;
  63. if(max !== min){
  64. let d = max - min;
  65. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  66. switch(max){
  67. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  68. case g: h = (b - r) / d + 2; break;
  69. case b: h = (r - g) / d + 4; break;
  70. }
  71. h = h * 60;
  72. }
  73. return [h, s, l];
  74. }
  75. hslToHex(h: number, s: number, l: number): string {
  76. let c = (1 - Math.abs(2 * l - 1)) * s;
  77. let x = c * (1 - Math.abs((h / 60) % 2 - 1));
  78. let m = l - c/2;
  79. let r=0, g=0, b=0;
  80. if (0 <= h && h < 60) { r = c; g = x; b = 0; }
  81. else if (60 <= h && h < 120) { r = x; g = c; b = 0; }
  82. else if (120 <= h && h < 180) { r = 0; g = c; b = x; }
  83. else if (180 <= h && h < 240) { r = 0; g = x; b = c; }
  84. else if (240 <= h && h < 300) { r = x; g = 0; b = c; }
  85. else if (300 <= h && h < 360) { r = c; g = 0; b = x; }
  86. let toHex = (v: number) => Math.round((v + m) * 255).toString(16).padStart(2, '0');
  87. return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
  88. }
  89. getGradientColor(themeColor: string, offset: number = 40): string {
  90. let hsl = this.hexToHsl(themeColor);
  91. let h = hsl[0];
  92. let s = hsl[1];
  93. let l = hsl[2];
  94. h = (h + offset) % 360;
  95. return this.hslToHex(h, s, l);
  96. }
  97. build() {
  98. Column(){
  99. // 顶部安全区和自定义标题栏
  100. Column() {
  101. // 顶部安全区
  102. Blank()
  103. .height(this.topRectHeight)
  104. .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
  105. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  106. // 自定义标题栏(Stack实现绝对居中)
  107. Stack() {
  108. // 居中标题
  109. Text('关于我们')
  110. .fontSize(18)
  111. .fontColor(Color.White)
  112. .align(Alignment.Center)
  113. // 左右按钮
  114. Row() {
  115. Image($r('app.media.left_back_white'))
  116. .width(26)
  117. .height(26)
  118. .margin({ left: 12, right: 8 })
  119. .onClick(() => {
  120. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  121. // 动画闭包内控制Image组件的出现和消失
  122. // this.isShowDrawer = !this.isShowDrawer
  123. // this.offsetX = 0
  124. this.mType =0
  125. })
  126. })
  127. Blank().flexGrow(1)
  128. Blank().width(32)
  129. }
  130. .height(48)
  131. .width('100%')
  132. .alignItems(VerticalAlign.Center)
  133. }
  134. .height(48)
  135. .width('100%')
  136. .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
  137. }
  138. Scroll(){
  139. Column(){
  140. Image($r('app.media.icon'))
  141. .width(120)
  142. .height(120)
  143. .borderRadius('100%')
  144. .clip(true)
  145. Text(this.appName+'V:'+this.verName)
  146. .fontColor(this.isDarkMode ? Color.White : Color.Black)
  147. .fontWeight(480)
  148. .fontSize(17)
  149. .margin({top:20,bottom:10})
  150. Text(CommonConstants.ICP_NO)
  151. .fontColor(this.isDarkMode ? Color.White : Color.Black)
  152. .fontWeight(480)
  153. .decoration({ type: TextDecorationType.Underline, color: this.isDarkMode ? Color.White : Color.Black })
  154. .fontSize(13)
  155. .margin({top:10,bottom:10})
  156. .onClick(()=>{
  157. let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  158. context.openLink(CommonConstants.ICP_URL, {})
  159. })
  160. this.aboutItemView()
  161. }
  162. .justifyContent(FlexAlign.Start)
  163. .width('100%')
  164. }
  165. .layoutWeight(1)
  166. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  167. .animation({ duration: 380, curve: Curve.Ease,delay:50 }))
  168. .backgroundColor(this.isDarkMode?Color.Black:this.themeColor)
  169. .linearGradient(!this.isDarkMode ? {colors:[[this.themeColor, 0.0], [this.getGradientColor(this.themeColor, 50), 0.6]]} : undefined)
  170. }
  171. .layoutWeight(1)
  172. .width('100%')
  173. .height('100%')
  174. }
  175. @Builder
  176. aboutItemView(){
  177. Column() {
  178. //分享给朋友
  179. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  180. Row() {
  181. SymbolGlyph($r('sys.symbol.share'))
  182. .fontSize(22)
  183. .fontColor(['#06B4FD'])
  184. .alignSelf(ItemAlign.Center)
  185. .margin({ left: 28 })
  186. Text('分享给朋友')
  187. .margin({ left: 10, right: 20 })
  188. .fontSize(15)
  189. .layoutWeight(1)
  190. .fontColor($r('app.color.text_color'))
  191. .fontWeight(480)
  192. .id('text_update')
  193. Blank()
  194. Image($r('app.media.arrow_right'))
  195. .width(22)
  196. .height(22)
  197. .margin({ left: 20, right: 20 })
  198. .align(Alignment.Center)
  199. }
  200. }
  201. .backgroundColor(Color.Transparent)
  202. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.9 })
  203. .width('100%')
  204. .height(55)
  205. .onClick(async () => {
  206. gotoShare(this.context,this.appName,this.bundleName)
  207. })
  208. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  209. //用户协议
  210. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  211. Row() {
  212. Image($r('app.media.hm_persion'))
  213. .width(22)
  214. .height(22)
  215. .alignSelf(ItemAlign.Center)
  216. .margin({ left: 28 })
  217. Text('用户协议')
  218. .margin({ left: 10, right: 20 })
  219. .fontSize(15)
  220. .layoutWeight(1)
  221. .fontColor($r('app.color.text_color'))
  222. .fontWeight(480)
  223. .id('text_update')
  224. Blank()
  225. Image($r('app.media.arrow_right'))
  226. .width(22)
  227. .height(22)
  228. .margin({ left: 20, right: 20 })
  229. }
  230. }
  231. .backgroundColor(Color.Transparent)
  232. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.9 })
  233. .width('100%')
  234. .height(55)
  235. .onClick(() => {
  236. router.pushUrl({
  237. url: 'pages/WebIndex',
  238. params: { titleName: '用户协议', webUrl: CommonConstants.NEW_DUTY }
  239. });
  240. })
  241. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  242. //隐私政策
  243. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  244. Row() {
  245. Image($r('app.media.hm_version'))
  246. .width(22)
  247. .height(22)
  248. .alignSelf(ItemAlign.Center)
  249. .margin({ left: 28 })
  250. Text('隐私政策')
  251. .margin({ left: 10, right: 20 })
  252. .fontSize(15)
  253. .layoutWeight(1)
  254. .fontColor($r('app.color.text_color'))
  255. .fontWeight(480)
  256. .id('text_update')
  257. Blank()
  258. Image($r('app.media.arrow_right'))
  259. .width(22)
  260. .height(22)
  261. .margin({ left: 20, right: 20 })
  262. }
  263. }
  264. .backgroundColor(Color.Transparent)
  265. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.9 })
  266. .width('100%')
  267. .height(55)
  268. .onClick(() => {
  269. router.pushUrl({
  270. url: 'pages/WebIndex',
  271. params: { titleName: '隐私政策', webUrl: CommonConstants.NEW_YS_HW }
  272. });
  273. })
  274. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  275. //给个好评
  276. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  277. Row() {
  278. Image($r('app.media.hm_flower'))
  279. .width(22)
  280. .height(22)
  281. .alignSelf(ItemAlign.Center)
  282. .margin({ left: 28 })
  283. Text('给个好评')
  284. .margin({ left: 10, right: 20 })
  285. .fontSize(15)
  286. .layoutWeight(1)
  287. .fontColor($r('app.color.text_color'))
  288. .fontWeight(480)
  289. .id('text_update')
  290. Blank()
  291. Image($r('app.media.arrow_right'))
  292. .width(22)
  293. .height(22)
  294. .margin({ left: 20, right: 20 })
  295. }
  296. }
  297. .backgroundColor(Color.Transparent)
  298. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.9 })
  299. .width('100%')
  300. .height(55)
  301. .onClick(() => {
  302. Utility.gotoMarket(this.context, this.bundleName)
  303. })
  304. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  305. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  306. Row() {
  307. SymbolGlyph($r('sys.symbol.music'))
  308. .fontSize(22)
  309. .fontColor(['#06B4FD'])
  310. .alignSelf(ItemAlign.Center)
  311. .margin({ left: 28 })
  312. Text('音频标签')
  313. .margin({ left: 10, right: 20 })
  314. .fontSize(15)
  315. .layoutWeight(1)
  316. .fontColor($r('app.color.text_color'))
  317. .fontWeight(480)
  318. .id('text_update')
  319. Blank()
  320. Image($r('app.media.arrow_right'))
  321. .width(22)
  322. .height(22)
  323. .margin({ left: 20, right: 20 })
  324. }
  325. }
  326. .backgroundColor(Color.Transparent)
  327. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.9 })
  328. .width('100%')
  329. .height(55)
  330. .onClick(() => {
  331. Utility.gotoMarket(this.context, 'com.xgplayer.ttmusic.tags')
  332. })
  333. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  334. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  335. Row() {
  336. SymbolGlyph($r('sys.symbol.media_center'))
  337. .fontSize(22)
  338. .fontColor(['#06B4FD'])
  339. .alignSelf(ItemAlign.Center)
  340. .margin({ left: 28 })
  341. Text('视频播放器')
  342. .margin({ left: 10, right: 20 })
  343. .fontSize(15)
  344. .layoutWeight(1)
  345. .fontColor($r('app.color.text_color'))
  346. .fontWeight(480)
  347. .id('text_update')
  348. Blank()
  349. Image($r('app.media.arrow_right'))
  350. .width(22)
  351. .height(22)
  352. .margin({ left: 20, right: 20 })
  353. }
  354. }
  355. .backgroundColor(Color.Transparent)
  356. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.9 })
  357. .width('100%')
  358. .height(55)
  359. .onClick(() => {
  360. Utility.gotoMarket(this.context, 'com.kuaiyao.kdb.hm')
  361. })
  362. Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  363. //关于我们
  364. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  365. Row() {
  366. SymbolGlyph($r('sys.symbol.person_2'))
  367. .fontSize(22)
  368. .fontColor(['#06B4FD'])
  369. .alignSelf(ItemAlign.Center)
  370. .margin({ left: 28 })
  371. Text('粉丝Q群(用户反馈)')
  372. .margin({ left: 10, right: 20 })
  373. .fontSize(15)
  374. .layoutWeight(1)
  375. .fontColor($r('app.color.text_color'))
  376. .fontWeight(480)
  377. .id('text_update')
  378. Blank()
  379. Image($r('app.media.arrow_right'))
  380. .width(22)
  381. .height(22)
  382. .margin({ left: 20, right: 20 })
  383. }
  384. }
  385. .backgroundColor(Color.Transparent)
  386. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.9 })
  387. .width('100%')
  388. .height(55)
  389. .onClick(() => {
  390. ToastUtil.showToast('复制群号成功!')
  391. Utility.copyText('685109858')
  392. const qqUrl = `mqqapi://card/show_pslcard?src_type=internal&version=1&uin=${CommonConstants.QQ_GROUP}&card_type=group&source=external`;
  393. let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  394. context.openLink(qqUrl, {})
  395. })
  396. // Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
  397. }
  398. .backgroundColor($r('app.color.silvery'))
  399. .opacity(0.7)
  400. .margin({left:20,right:20,top:20,bottom:10})
  401. .borderRadius(30)
  402. }
  403. }
  404. export async function gotoShare(mContext: common.UIAbilityContext,appName:string, bundleName:string) {
  405. let shareData: systemShare.SharedData = new systemShare.SharedData({
  406. utd: uniformTypeDescriptor.UniformDataType.TEXT,
  407. content: 'https://appgallery.huawei.com/app/detail?id=' + bundleName,
  408. title: appName, // 不传title字段时,显示content
  409. description: '精心雕琢的无损音乐播放器',
  410. // thumbnail: new Uint8Array(buffer) // 推荐传入适合的缩略图 不传则显示默认text图标
  411. thumbnail: mContext.resourceManager.getMediaContentSync($r("app.media.icon_32"))// 获取小于32k大小的图标才可以
  412. });
  413. // 进行分享面板显示
  414. let controller: systemShare.ShareController = new systemShare.ShareController(shareData);
  415. controller.show(mContext, {
  416. selectionMode: systemShare.SelectionMode.SINGLE,
  417. previewMode: systemShare.SharePreviewMode.DETAIL,
  418. }).then(() => {
  419. console.info('ShareController show success.');
  420. }).catch((error: BusinessError) => {
  421. console.error(`ShareController show error. code: ${error.code}, message: ${error.message}`);
  422. });
  423. }