app-user.tsx 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import { defineComponent } from 'vue';
import { useNamespace } from '@ibiz-template/vue-util';
import '@ibiz-template/theme/style/components/common/app-user/app-user.scss';

export const AppUser = defineComponent({
  name: 'AppUser',
  setup() {
    const ns = useNamespace('app-user');
    const { srfusername = '游客' } = ibiz.appData?.context || {};
    return { ns, srfusername };
  },
  methods: {
    async onClick() {
      const res = await ibiz.auth.v7logout();
      if (res.ok) {
        ibiz.message.success('登出成功');
        this.$router.push(
          `/login?ru=${encodeURIComponent(
            window.location.hash.replace('#/', '/'),
          )}`,
        );
      } else {
        ibiz.message.error('登出失败');
      }
    },
  },
  render() {
    return (
      <div class={this.ns.b()}>
30 31 32 33 34 35
        <i-dropdown
          class={[
            this.ns.b('avatar'),
            this.ns.is('disabled', ibiz.env.disableLogout),
          ]}
        >
36 37 38 39 40 41 42
          <span class={this.ns.b('avatar-wrapper')}>
            <i-avatar
              size='small'
              src='https://i.loli.net/2017/08/21/599a521472424.jpg'
            />
            <span class={this.ns.be('avatar', 'name')}>{this.srfusername}</span>
          </span>
43 44 45 46 47 48 49 50
          {ibiz.env.disableLogout ? null : (
            <i-dropdown-menu slot='list'>
              <i-dropdown-item>
                <i class='ivu-icon ivu-icon-ios-log-out'></i>
                <span on-click={this.onClick}>退出登录</span>
              </i-dropdown-item>
            </i-dropdown-menu>
          )}
51 52 53 54 55
        </i-dropdown>
      </div>
    );
  },
});