SettingPage.ets 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import {
  2. BasicType,
  3. DiaLogCompControl,
  4. IBestToast,
  5. userInfo,
  6. UserInfo,
  7. YTAvoid,
  8. YTHeader,
  9. YTLog,
  10. YTPhotoHelper,
  11. yTRouter,
  12. YTUserRequest
  13. } from 'basic'
  14. @Builder
  15. function settingBuilder() {
  16. NavDestination() {
  17. SettingPage()
  18. }
  19. .hideTitleBar(true)
  20. }
  21. @Component
  22. struct SettingPage {
  23. @StorageProp(YTAvoid.SAFE_BOTTOM_KEY) private safeBottom: number = 0
  24. @StorageProp(UserInfo.KEY) private userInfo: UserInfo = userInfo
  25. @State private value: string = ''
  26. private yTPhotoHelper = new YTPhotoHelper()
  27. private reviseBuilderArr: Array<BasicType> = [
  28. {
  29. text: '我的昵称', src: '名称',
  30. click: () => {
  31. this.openReviseNameBuilder()
  32. }
  33. }, {
  34. text: '绑定手机号',
  35. message: this.userInfo.getPhoneNumber() ?? '',
  36. click: () => {
  37. // this.openChangeBuilder()
  38. }
  39. }
  40. ]
  41. private reviseBuilderArr1: Array<BasicType> = [
  42. { text: '宝贝头像', src: '头像',
  43. click: () => {
  44. this.openChangeBuilder()
  45. }
  46. }, {
  47. text: '宝贝昵称', src: '名称',
  48. click: () => {
  49. // this.openReviseNameBuilder()
  50. }
  51. }, {
  52. text: '性别',
  53. click: () => {
  54. // this.openReviseNameBuilder()
  55. }
  56. }, {
  57. text: '生日',
  58. click: () => {
  59. // this.openReviseNameBuilder()
  60. }
  61. },
  62. ]
  63. private options: BasicType[] = [
  64. {
  65. text: '拍照',
  66. click: async () => {
  67. try {
  68. const fullpath = await this.yTPhotoHelper.takePicture()
  69. yTRouter.router2DelPhotoPage({ src: fullpath, type: 'header' })
  70. } catch (e) {
  71. YTLog.warn(e)
  72. }
  73. }
  74. },
  75. {
  76. text: '从相册中选择',
  77. click: () => {
  78. this.yTPhotoHelper.selectImage(
  79. (fullPath) => {
  80. yTRouter.router2DelPhotoPage({ src: fullPath, type: 'header' })
  81. })
  82. }
  83. }
  84. ]
  85. // 打开头像修改弹窗
  86. openChangeBuilder() {
  87. yTRouter.router2BottomDialog({
  88. params: this.options
  89. }, (info: PopInfo) => {
  90. let ans = info.result as string
  91. if (ans == '拍照') {
  92. this.options?.[0]?.click?.()
  93. } else if(ans == '从相册中选择') {
  94. this.options?.[1]?.click?.()
  95. }
  96. })
  97. }
  98. // 打开名称修改弹窗
  99. openReviseNameBuilder() {
  100. let control = new DiaLogCompControl(this.getUIContext())
  101. yTRouter.router2CenterDialog({
  102. param: { text: this.userInfo.getName() ?? this.userInfo.getPhoneNumber() ?? this.userInfo.getId()?.toString() },
  103. control: control,
  104. builder: () => {
  105. this.ReviseName({ text: this.userInfo.getName() ?? this.userInfo.getPhoneNumber() ?? this.userInfo.getId()?.toString() }, control)
  106. }
  107. }, (info: PopInfo) => {
  108. let ans = info.result as string
  109. YTUserRequest.changeNickname(ans, () => {
  110. IBestToast.show({ message: '名称修改成功' })
  111. })
  112. })
  113. }
  114. build() {
  115. Column() {
  116. YTHeader({ defaultStyle: { title: '用户设置' }, bgc: Color.White })
  117. Column({space: 16}) {
  118. this.reviseBuilder(this.reviseBuilderArr)
  119. this.reviseBuilder(this.reviseBuilderArr1)
  120. // YTButton({
  121. // btContent: '注销用户',
  122. // btFontColor: '#991C1C1C',
  123. // btFontSize: 16,
  124. // btHeight: 48,
  125. // btBorderRadius: 40,
  126. // bgc: Color.White,
  127. // click: () => {
  128. // yTToast.doubleConfirm({
  129. // message: '注销后无法恢复,是否确定注销?', click: () => {
  130. // YTUserRequest.logout(() => {
  131. // yTToast.hide()
  132. // yTRouter.routerBack()
  133. // setTimeout(() => {
  134. // IBestToast.show('注销成功')
  135. // }, 50)
  136. // })
  137. //
  138. // }
  139. // })
  140. // }
  141. // })
  142. // YTButton({
  143. // btContent: '退出登录',
  144. // click: () => {
  145. // this.userInfo.logout()
  146. // yTRouter.routerBack()
  147. // IBestToast.show({ message: '退出登录成功' })
  148. // },
  149. // btFontSize: 16,
  150. // btHeight: 48,
  151. // btBorderRadius: 40,
  152. // })
  153. }
  154. .padding({ left: 16, right: 16, top: 22 })
  155. }
  156. .width('100%')
  157. .height('100%')
  158. .backgroundColor('#F7F9FA')
  159. .padding({ bottom: this.safeBottom })
  160. }
  161. @Builder
  162. reviseBuilder(params: Array<BasicType>) {
  163. Column(){
  164. ForEach(params, (item: BasicType, index) => {
  165. Row() {
  166. Text(item.text)
  167. .fontSize($r('[basic].float.page_text_font_size_12'))
  168. .fontColor('#FF1C1C1C')
  169. .fontWeight(500)
  170. .fontSize(16)
  171. Row() {
  172. if (item.src == '头像') {
  173. Image(this.userInfo.getHeadImg() ? this.userInfo.getHeadImg() : $r('app.media.default_img'))
  174. .height(32)
  175. .width(32)
  176. .borderRadius(99)
  177. } else if (item.src == '名称') {
  178. Text(this.userInfo.getName() ?? this.userInfo.getPhoneNumber() ?? this.userInfo.getId()?.toString())
  179. .fontSize(16)
  180. .fontColor('#E61C1C1C')
  181. } else {
  182. Text(item.message)
  183. .fontSize(16)
  184. .fontColor('#E61C1C1C')
  185. }
  186. Image($r('app.media.right_arrow'))
  187. .width(24)
  188. .width(24)
  189. }
  190. }
  191. .width('100%')
  192. .onClick(item.click)
  193. .justifyContent(FlexAlign.SpaceBetween)
  194. if(index != params.length - 1) {
  195. Divider().width('100%').height(1).backgroundColor('#FBFBFB')
  196. .margin({top: 15, bottom: 15})
  197. }
  198. })
  199. }
  200. .padding(15)
  201. .borderRadius(8)
  202. .backgroundColor(Color.White)
  203. }
  204. @Builder
  205. ReviseName(param: BasicType, control: DiaLogCompControl){
  206. Column(){
  207. Text('宝贝昵称')
  208. .fontSize(16)
  209. .fontWeight(600)
  210. .fontColor('#FF000000')
  211. TextInput({text: param.text})
  212. .padding(10)
  213. .borderRadius(7)
  214. .backgroundColor('#F5F7F5')
  215. .onChange((text) => {
  216. param.text = text
  217. })
  218. .margin({top: 17})
  219. Row({space: 42}){
  220. Text('取消')
  221. .borderRadius(22)
  222. .fontColor('#FF000000')
  223. .backgroundColor('#FFF5F7F5')
  224. .padding({top: 10, left: 36, right: 36, bottom: 10})
  225. .onClick(() => {
  226. control._onBackPress()
  227. })
  228. Text('保存')
  229. .borderRadius(22)
  230. .fontColor('#FF000000')
  231. .backgroundColor('#FFFECF2F')
  232. .padding({top: 10, left: 36, right: 36, bottom: 10})
  233. .onClick(() => {
  234. if (!param.text) {
  235. IBestToast.show({
  236. type: "warning",
  237. message: "昵称不能为空"
  238. })
  239. return
  240. }
  241. control._onBackPress(param.text)
  242. })
  243. }
  244. .margin({top: 12})
  245. }
  246. .width(312)
  247. .height(158)
  248. .borderRadius(12)
  249. .backgroundColor(Color.White)
  250. .alignItems(HorizontalAlign.Center)
  251. .padding({left: 32, right: 32, top: 16, bottom: 8})
  252. }
  253. }