SettingPage.ets 6.6 KB

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