index.vue 5.3 KB
<template>
  <view class="mine-container" :style="{height: `${windowHeight}px`}">
    <!-- 个人信息卡片 -->
    <view class="profile-card">
      <view class="profile-bg" />
      <view class="profile-header">
        <view class="flex align-center">
          <view class="cu-avatar xl round avatar-initial">
            <text class="avatar-text">{{ initialNameChar }}</text>
          </view>
          <view class="profile-text" @click="name ? handleToInfo() : handleToLogin()">
            <view class="name">{{ name || '点击登录' }}</view>
            <view class="muted omit1">{{ deptPathsText }}</view>
            <view class="muted omit1">{{ telephone }}</view>
          </view>
        </view>
      </view>
    </view>

    <!-- 菜单列表 -->
    <view class="menu-list">
      <view class="list-cell list-cell-arrow" @click="handleToPwd">
        <view class="menu-item-box">
          <view class="iconfont icon-password menu-icon"></view>
          <view>修改密码</view>
        </view>
      </view>
      <!-- <view class="list-cell list-cell-arrow" @click="handleClearCache">
        <view class="menu-item-box">
          <view class="iconfont icon-clean menu-icon"></view>
          <view>清除缓存</view>
        </view>
      </view> -->
      <view class="list-cell list-cell-arrow" @click="handleToSetting">
        <view class="menu-item-box">
          <view class="iconfont icon-setting menu-icon"></view>
          <view>设置</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="handleAbout">
        <view class="menu-item-box">
          <view class="iconfont icon-aixin menu-icon"></view>
          <view>关于我们</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import storage from '@/utils/storage'
  
  export default {
    data() {
      return {
		   globalConfig: getApp().globalData.config,
        name: '',
        username: '',
        version: getApp().globalData.config.appInfo.version,
        deptPathsText: '',
        telephone: '',
        initialNameChar: ''
      }
    },
    onShow() {
      // this.$store.dispatch('GetInfo');
      const color = getApp().globalData.config.themeColor
      uni.setNavigationBarColor({
        frontColor: '#ffffff',
        backgroundColor: color
      })
    },
    
    computed: {
  
      initialNameChar() {
        const n = (this.username || '').trim()
        return n ? n.charAt(0) : '登'
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
    created() {
      console.log('this.$store.state.user', this.$store.state.user)
       this.name = this.$store.state.user.name || '';
        this.username = this.$store.state.user.username || '',
        this.deptPathsText =this.$store.state.user.deptPaths.length ? this.$store.state.user.deptPaths.join(',') : '',
        this.telephone = this.$store.state.user.telephone
        const _username = (this.username || '').trim()
        this.initialNameChar = _username ? _username.charAt(0) : '登'
    },
    methods: {
      handleToPwd() {
        this.$tab.navigateTo('/pages/mine/pwd/index')
      },
      handleClearCache() {
        try {
          storage.clean()
          uni.clearStorage()
          this.$modal.showToast('缓存已清除')
        } catch (e) {
          this.$modal.showToast('清除失败')
        }
      },

      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },
      handleToSetting() {
        this.$tab.navigateTo('/pages/mine/setting/index')
      },
      handleToLogin() {
        this.$tab.reLaunch('/pages/login')
      },
      handleToAvatar() {
        this.$tab.navigateTo('/pages/mine/avatar/index')
      },
      handleAbout() {
        this.$tab.navigateTo('/pages/mine/about/index')
      },
    }
  }
</script>

<style scoped lang="scss">
  page {
    background: #F2F3FF;
  }

  .mine-container {
    width: 100%;
    height: 100%;
    .profile-card {
      position: relative;
      height: 284rpx;
      .profile-bg {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1;
        background: $theme-primary;
        height: 134rpx;
      }
      .profile-header {
        position: absolute;
        top: 50rpx;
        left: 50%;
        transform: translateX(-50%);
        z-index: 2;
        width: 686rpx;
        padding: 36rpx 36rpx 46rpx;
        border-radius: 16rpx;
        background: linear-gradient( 358deg, #FFFFFF 0%, #CBE2FD 100%);
      }

      .cu-avatar {
        margin-right: 26rpx;
        &.avatar-initial {
          background-color: #fbecc0;
          display: flex;
          align-items: center;
          justify-content: center;
        }
        .avatar-text {
          color: #666;
          font-weight: 600;
          font-size: 36rpx;
        }
      }

      .profile-text {
        display: flex;
        flex-direction: column;
        gap: 4rpx;
        .name { font-size: 18px; font-weight: 600; color: rgba(0,0,0,0.9); }
        .muted { font-size: 12px; color: rgba(0,0,0,0.5); }
      }
    }
    .menu-list {
      margin: 0 32rpx;
      .list-cell {
        padding: 32rpx 40rpx;
        color: rgba(0,0,0,0.9);
        font-size: 32rpx;
      }
      .menu-icon {
        color: rgba(0,0,0,0.9);
        font-size: 40rpx;
      }
    }
  }
</style>