SettingPage.ets 6.6 KB

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