|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- <template>
- <view v-if="currentUser" id="my" class="page">
- <!-- 顶部用户名、头像 banner -->
- <view @click="goTo('info')" class="mybanner">
- <view class="avatarslot">
- <image
- :src="avatarSrc()"
- :style="{ borderRadius: roundAvatar ? '50%' : '3px' }"
- mode="aspectFill"
- class="avatar"
- ></image>
- </view>
- <view class="info">
- <view class="username text-xl text-white">{{ currentUser.realName }}</view>
- <view class="usertag">
- <l-tag color="green">{{ userTag }}</l-tag>
- </view>
- </view>
- <view class="badge text-white text-lg"><l-icon type="right" round /></view>
- </view>
-
- <!-- 用户信息菜单 -->
- <l-list border card>
- <l-list-item @click="goTo('contact')" arrow>
- <l-icon type="phone" color="blue" />
- 联系方式
- </l-list-item>
- <!-- <l-list-item @click="goTo('qrcode')" arrow>
- <l-icon type="qrcode" color="blue" />
- 我的二维码
- </l-list-item> -->
- <l-list-item @click="goTo('password')" arrow>
- <l-icon type="edit" color="blue" />
- 修改密码
- </l-list-item>
- <l-list-item @click="unbound" arrow>
- <image src="@/static/unbound.png" mode="" style="color: #0081ff;width: 14px;height: 14px;margin: 0 10px 0 5px;"></image>
- 解绑微信
- </l-list-item>
- </l-list>
-
- <!-- 关于菜单 -->
- <!-- <l-list border card>
- <l-list-item @click="goTo('learun')" arrow>
- <l-icon type="home" color="blue" />
- 关于泉江
- </l-list-item>
- <l-list-item @click="goTo('framework')" arrow>
- <l-icon type="info" color="blue" />
- 数字化智慧校园
- </l-list-item>
- </l-list> -->
-
- <view class="padding" style="padding-top: 0;">
- <!-- 小程序账号绑定/解除按钮 -->
- <!-- #ifdef MP-ALIPAY || MP-WEIXIN -->
- <l-button
- v-if="MPBind && !currentUser.miniProgram"
- @click="userBind"
- size="lg"
- line="blue"
- class="block margin-top"
- block
- >
- 绑定{{ PLATFORM_TEXT }}账号
- </l-button>
- <l-button
- v-if="MPUnbind && currentUser.miniProgram"
- @click="userUnBind"
- size="lg"
- line="red"
- class="block margin-top"
- block
- >
- 解绑{{ PLATFORM_TEXT }}账号
- </l-button>
- <!-- #endif -->
-
- <l-button @click="logout" size="lg" color="red" class="block margin-top" block>退出登录</l-button>
- </view>
-
- <view class="footer">{{ copyRightDisplay }}</view>
- </view>
- </template>
-
- <script>
- export default {
- methods: {
- // 点击「注销登录」按钮
- async logout() {
- if (!(await this.CONFIRM('注销确认', '确定要注销登录吗?', true))) {
- return
- }
-
- this.CLEAR_GLOBAL()
- this.RELAUNCH_TO('/pages/login')
- },
-
- // #ifdef MP-ALIPAY || MP-WEIXIN
- // 小程序绑定方法,只会编译到小程序
- async userBind() {
- const type = this.PLATFORM
- const confirm = await this.CONFIRM(
- '绑定确认',
- `确定要将智慧校园账号与当前登录的${this.PLATFORM_TEXT}账号绑定吗?\n(绑定后可以使用一键登录功能)`,
- true
- )
- if (!confirm) {
- return
- }
-
- this.LOADING('绑定中…')
- const [codeErr, { code }] = await uni.login({ provider: type })
- if (codeErr || !code) {
- this.HIDE_LOADING()
- this.TOAST('获取用户授权码失败')
- return
- }
-
- const success = await this.HTTP_POST('learun/adms/user/openid_bind', { code, type }, '绑定失败')
- if (!success) {
- return
- }
-
- this.HIDE_LOADING()
- this.SET_GLOBAL('loginUser', Object.assign({}, this.currentUser, { miniProgram: true }))
- this.TOAST(`已成功绑定到当前的${this.PLATFORM_TEXT}账号`)
- },
-
- // 解绑小程序
- async userUnBind() {
- const confirm = await this.CONFIRM(
- '解绑确认',
- '确定要解除小程序账号绑定吗? (解绑将自动退出登录,需使用力软账号和密码再次登录)',
- true
- )
- if (!confirm) {
- return
- }
-
- const success = await this.HTTP_POST('learun/adms/user/openid_unbind', { type: this.PLATFORM }, '解除绑定失败')
- if (!success) {
- return
- }
-
- this.CLEAR_GLOBAL()
- this.RELAUNCH_TO('/pages/login')
- this.TOAST('已成功解除绑定')
- },
- // #endif
-
- // 跳转到
- goTo(urlPath) {
- this.NAV_TO(`/pages/my/${urlPath}`)
- },
-
- // 解绑微信
- unbound(){
- this.CONFIRM('提示', '确定要解绑微信账号?', true).then(res => {
- if (res) {
- this.LOADING('正在解绑…');
- this.HTTP_POST('learun/adms/user/unbundWeiXin', null, '解绑失败').then(success => {
- this.HIDE_LOADING();
- if (!success) {
- return
- }
- this.TOAST("解绑成功")
- setTimeout(()=>{
- this.CLEAR_GLOBAL()
- this.RELAUNCH_TO('/pages/login')
- },1000)
- });
- }
- });
- },
-
- // 用户头像 url
- avatarSrc() {
- if (!this.currentUser) {
- return ''
- }
-
- return this.API + `/learun/adms/user/img?data=${this.currentUser.userId}`
- }
- },
-
- computed: {
- // 返回当前用户
- currentUser() {
- return this.GET_GLOBAL('loginUser')
- },
-
- // 获取组织结构 tag 的显示
- userTag() {
- if (!this.currentUser) {
- return ''
- }
-
- const { companyId, departmentId } = this.currentUser
- if (!companyId) {
- return `总集团公司`
- }
-
- const company = this.GET_GLOBAL('company')
- const dep = this.GET_GLOBAL('department')
- // const companyName = company[companyId].name
- // if (!dep) {
- // return companyName
- // }
-
- // return `${companyName} / ${dep[departmentId].name}`
- },
-
- // 头像圆形/方形显示参数
- roundAvatar() {
- return this.CONFIG('pageConfig.roundAvatar')
- },
-
- // 页面底部公司/版权显示
- copyRightDisplay() {
- const year = new Date().getFullYear()
- const company = this.CONFIG('company')
-
- return `Copyright © ${year} ${company}`
- },
-
- // #ifdef MP-ALIPAY || MP-WEIXIN
- // 是否显示小程序绑定按钮
- MPBind() {
- return this.CONFIG(`miniProgramAccount.${this.PLATFORM}`).includes('bind')
- },
-
- // 是否显示小程序解绑按钮
- MPUnbind() {
- return this.CONFIG(`miniProgramAccount.${this.PLATFORM}`).includes('unbind')
- }
- // #endif
- }
- }
- </script>
-
- <style lang="less" scoped>
- .mybanner {
- background: #0c86d8;
- height: 120px;
- padding: 25px 15px;
- display: flex;
- align-items: center;
-
- .avatarslot {
- .avatar {
- height: 60px;
- width: 60px;
- }
- }
-
- .info {
- padding-left: 20px;
-
- .username {
- margin-bottom: 5px;
- }
- }
-
- .badge {
- flex-grow: 1;
- display: flex;
- justify-content: flex-end;
- }
- }
-
- .footer {
- text-align: center;
- font-size: 14px;
- color: #ccc;
- margin-bottom: 10rpx;
- }
- </style>
|