| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- import {
- BasicType,
- IBestToast,
- reviseImgHeaderBuilder,
- takePicture,
- Upload,
- UserInfo,
- YTAvoid,
- YtButton,
- YTHeader,
- YTLog,
- YTRequest,
- YTRouter,
- YTToast
- } from 'basic'
- @Builder
- function settingBuilder() {
- NavDestination() {
- SettingPage()
- }
- .hideTitleBar(true)
- }
- @Component
- struct SettingPage {
- @StorageProp(YTAvoid.SAFE_TOP_KEY) safeTop: number = 0
- @StorageProp(YTAvoid.SAFE_BOTTOM_KEY) safeBottom: number = 0
- @StorageProp(UserInfo.KEY) userInfo: UserInfo = UserInfo.getInstance()
- @State showReviseName: boolean = false
- @State showHeaderImgRevise: boolean = false
- @State value: string = ''
- reviseBuilderArr: Array<BasicType<undefined>> = [
- {
- text: '头像修改',
- src: '',
- click: () => {
- this.showHeaderImgRevise = true
- }
- },
- {
- text: '昵称修改',
- click: () => {
- this.showReviseName = true
- }
- }
- ]
- options: BasicType<undefined>[] = [
- {
- text: '拍照',
- click: async () => {
- try {
- const fullpath = await takePicture()
- this.showHeaderImgRevise = false
- YTRouter.router2DelPhotoPage({ src: fullpath, type: 'header' })
- } catch (e) {
- YTLog.warn(e)
- }
- }
- },
- {
- text: '从相册中选择',
- click: () => {
- Upload.selectImage(this.getUIContext().getHostContext()!, (fullPath) => {
- this.showHeaderImgRevise = false
- YTRouter.router2DelPhotoPage({ src: fullPath, type: 'image' })
- })
- }
- },
- {
- text: '取消',
- click: () => {
- this.showHeaderImgRevise = false
- }
- },
- ]
- build() {
- Column() {
- YTHeader({ title: '用户设置' })
- Column() {
- ForEach(this.reviseBuilderArr, (item: BasicType<undefined>, index) => {
- this.reviseBuilder(item)
- if (index < this.reviseBuilderArr.length - 1) {
- Column() {
- Text('')
- .height(1)
- .width('100%')
- .backgroundColor('#0A000000')
- }
- .padding({ left: 12, right: 8 })
- .bindSheet($$this.showHeaderImgRevise, this.changeBuilder, {
- height: 204,
- backgroundColor: Color.White,
- showClose: false
- })
- }
- })
- YtButton({
- btContent: '退出登录', click: () => {
- this.userInfo.logout()
- YTRouter.routerBack()
- IBestToast.show({ message: '退出登录成功' })
- }
- })
- .margin({ top: 426, bottom: 12 })
- YtButton({
- btContent: '注销用户',
- btFontColor: Color.Red,
- bgc: Color.White,
- click: () => {
- YTToast.getInstance().doubleConfirm({
- text: '警告⚠', message: '确定要注销吗?\n注销后数据可能丢失无法恢复!', click: () => {
- UserInfo.getInstance().logout()
- YTToast.getInstance().hide()
- YTRouter.routerBack()
- }
- })
- }
- })
- }
- .bindSheet($$this.showReviseName, this.reviseNameBuilder, {
- height: 275,
- showClose: false,
- backgroundColor: Color.White
- })
- .padding({
- top: 29,
- left: 16,
- right: 16,
- })
- }
- .padding({ top: this.safeTop, bottom: this.safeBottom })
- }
- @Builder
- reviseBuilder(item: BasicType<undefined>) {
- Row() {
- Text(item.text)
- .fontSize($r('[basic].float.page_text_font_size_12'))
- .fontColor('#80000000')
- Row() {
- if (typeof item.src == 'string') {
- Image(this.userInfo.getHeadImg() ? this.userInfo.getHeadImg() : $r('app.media.default_img'))
- .height(24)
- .width(24)
- .borderRadius(12)
- } else {
- Text(this.userInfo.getName() ?? this.userInfo.getPhoneNumber() ?? this.userInfo.getId()?.toString())
- .fontSize($r('[basic].float.page_text_font_size_12'))
- .fontColor('#CC000000')
- }
- Image($r('app.media.right_arrow'))
- .width(24)
- .width(24)
- }
- }
- .width('100%')
- .justifyContent(FlexAlign.SpaceBetween)
- .padding({ left: 12, right: 4 })
- .height(36)
- .onClick(item.click)
- }
- @Builder
- reviseNameBuilder() {
- Column() {
- Text('昵称')
- .width('100%')
- .height(36)
- .textAlign(TextAlign.Start)
- .fontSize(12)
- TextInput({ text: $$this.value, placeholder: '请输入昵称' })
- .borderRadius(4)
- .fontSize(12)
- .placeholderFont({ size: 12 })
- .placeholderColor('#14000000')
- .height(36)
- .width('100%')
- .backgroundColor(Color.White)
- .border({ width: 1, color: '#14000000' })
- .margin({ bottom: 25 })
- .onChange((value) => {
- if (value.length > 7) {
- this.value = value.slice(0, 7)
- IBestToast.show({ type: "warning", message: '用户名称最大为7位' })
- }
- })
- Row({ space: 32 }) {
- YtButton({
- btContent: '取消',
- btHeight: 25,
- btWidth: 78,
- btBorder: { width: 1, color: '#1A000000' },
- btPadding: {
- left: 26,
- right: 26,
- top: 4,
- bottom: 4
- },
- bgc: Color.White,
- btFontColor: $r('sys.color.mask_secondary'),
- click: () => {
- this.showReviseName = false
- this.value = ''
- }
- })
- YtButton({
- btContent: '完成',
- btHeight: 25,
- btWidth: 78,
- btPadding: {
- left: 26,
- right: 26,
- top: 4,
- bottom: 4
- },
- click: () => {
- if (!this.value) {
- IBestToast.show({
- type: "warning",
- message: "昵称不能为空"
- })
- return
- }
- YTRequest.changeNickname(this.value, () => {
- IBestToast.show({ message: '名称修改成功' })
- })
- //TODO 发送请求后关闭弹窗
- this.showReviseName = false
- }
- })
- }
- .justifyContent(FlexAlign.Center)
- .width('100%')
- }
- .padding({ left: 22, right: 22, top: 8 })
- }
- @Builder
- changeBuilder() {
- reviseImgHeaderBuilder(this.options)
- }
- }
|