Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

255 řádky
6.3 KiB

  1. <template>
  2. <view v-if="currentUser" id="my" class="page">
  3. <!-- 顶部用户名、头像 banner -->
  4. <view @click="goTo('info')" class="mybanner">
  5. <view class="avatarslot">
  6. <image
  7. :src="avatarSrc()"
  8. :style="{ borderRadius: roundAvatar ? '50%' : '3px' }"
  9. mode="aspectFill"
  10. class="avatar"
  11. ></image>
  12. </view>
  13. <view class="info">
  14. <view class="username text-xl text-white">{{ currentUser.realName }}</view>
  15. <view class="usertag">
  16. <l-tag color="green">{{ userTag }}</l-tag>
  17. </view>
  18. </view>
  19. <view class="badge text-white text-lg"><l-icon type="right" round /></view>
  20. </view>
  21. <!-- 用户信息菜单 -->
  22. <l-list border card>
  23. <l-list-item @click="goTo('contact')" arrow>
  24. <l-icon type="phone" color="blue" />
  25. 联系方式
  26. </l-list-item>
  27. <!-- <l-list-item @click="goTo('qrcode')" arrow>
  28. <l-icon type="qrcode" color="blue" />
  29. 我的二维码
  30. </l-list-item> -->
  31. <l-list-item @click="goTo('password')" arrow>
  32. <l-icon type="edit" color="blue" />
  33. 修改密码
  34. </l-list-item>
  35. </l-list>
  36. <!-- 关于菜单 -->
  37. <!-- <l-list border card>
  38. <l-list-item @click="goTo('learun')" arrow>
  39. <l-icon type="home" color="blue" />
  40. 关于泉江
  41. </l-list-item>
  42. <l-list-item @click="goTo('framework')" arrow>
  43. <l-icon type="info" color="blue" />
  44. 数字化智慧校园
  45. </l-list-item>
  46. </l-list> -->
  47. <view class="padding" style="padding-top: 0;">
  48. <!-- 小程序账号绑定/解除按钮 -->
  49. <!-- #ifdef MP-ALIPAY || MP-WEIXIN -->
  50. <l-button
  51. v-if="MPBind && !currentUser.miniProgram"
  52. @click="userBind"
  53. size="lg"
  54. line="blue"
  55. class="block margin-top"
  56. block
  57. >
  58. 绑定{{ PLATFORM_TEXT }}账号
  59. </l-button>
  60. <l-button
  61. v-if="MPUnbind && currentUser.miniProgram"
  62. @click="userUnBind"
  63. size="lg"
  64. line="red"
  65. class="block margin-top"
  66. block
  67. >
  68. 解绑{{ PLATFORM_TEXT }}账号
  69. </l-button>
  70. <!-- #endif -->
  71. <l-button @click="logout" size="lg" color="red" class="block margin-top" block>退出登录</l-button>
  72. </view>
  73. <view class="footer">{{ copyRightDisplay }}</view>
  74. </view>
  75. </template>
  76. <script>
  77. export default {
  78. methods: {
  79. // 点击「注销登录」按钮
  80. async logout() {
  81. if (!(await this.CONFIRM('注销确认', '确定要注销登录吗?', true))) {
  82. return
  83. }
  84. this.CLEAR_GLOBAL()
  85. this.RELAUNCH_TO('/pages/login')
  86. },
  87. // #ifdef MP-ALIPAY || MP-WEIXIN
  88. // 小程序绑定方法,只会编译到小程序
  89. async userBind() {
  90. const type = this.PLATFORM
  91. const confirm = await this.CONFIRM(
  92. '绑定确认',
  93. `确定要将智慧校园账号与当前登录的${this.PLATFORM_TEXT}账号绑定吗?\n(绑定后可以使用一键登录功能)`,
  94. true
  95. )
  96. if (!confirm) {
  97. return
  98. }
  99. this.LOADING('绑定中…')
  100. const [codeErr, { code }] = await uni.login({ provider: type })
  101. if (codeErr || !code) {
  102. this.HIDE_LOADING()
  103. this.TOAST('获取用户授权码失败')
  104. return
  105. }
  106. const success = await this.HTTP_POST('learun/adms/user/openid_bind', { code, type }, '绑定失败')
  107. if (!success) {
  108. return
  109. }
  110. this.HIDE_LOADING()
  111. this.SET_GLOBAL('loginUser', Object.assign({}, this.currentUser, { miniProgram: true }))
  112. this.TOAST(`已成功绑定到当前的${this.PLATFORM_TEXT}账号`)
  113. },
  114. // 解绑小程序
  115. async userUnBind() {
  116. const confirm = await this.CONFIRM(
  117. '解绑确认',
  118. '确定要解除小程序账号绑定吗? (解绑将自动退出登录,需使用力软账号和密码再次登录)',
  119. true
  120. )
  121. if (!confirm) {
  122. return
  123. }
  124. const success = await this.HTTP_POST('learun/adms/user/openid_unbind', { type: this.PLATFORM }, '解除绑定失败')
  125. if (!success) {
  126. return
  127. }
  128. this.CLEAR_GLOBAL()
  129. this.RELAUNCH_TO('/pages/login')
  130. this.TOAST('已成功解除绑定')
  131. },
  132. // #endif
  133. // 跳转到
  134. goTo(urlPath) {
  135. this.NAV_TO(`/pages/my/${urlPath}`)
  136. },
  137. // 用户头像 url
  138. avatarSrc() {
  139. if (!this.currentUser) {
  140. return ''
  141. }
  142. return this.API + `/user/img?data=${this.currentUser.userId}`
  143. }
  144. },
  145. computed: {
  146. // 返回当前用户
  147. currentUser() {
  148. return this.GET_GLOBAL('loginUser')
  149. },
  150. // 获取组织结构 tag 的显示
  151. userTag() {
  152. if (!this.currentUser) {
  153. return ''
  154. }
  155. const { companyId, departmentId } = this.currentUser
  156. if (!companyId) {
  157. return `总集团公司`
  158. }
  159. const company = this.GET_GLOBAL('company')
  160. const dep = this.GET_GLOBAL('department')
  161. // const companyName = company[companyId].name
  162. // if (!dep) {
  163. // return companyName
  164. // }
  165. // return `${companyName} / ${dep[departmentId].name}`
  166. },
  167. // 头像圆形/方形显示参数
  168. roundAvatar() {
  169. return this.CONFIG('pageConfig.roundAvatar')
  170. },
  171. // 页面底部公司/版权显示
  172. copyRightDisplay() {
  173. const year = new Date().getFullYear()
  174. const company = this.CONFIG('company')
  175. return `Copyright © ${year} ${company}`
  176. },
  177. // #ifdef MP-ALIPAY || MP-WEIXIN
  178. // 是否显示小程序绑定按钮
  179. MPBind() {
  180. return this.CONFIG(`miniProgramAccount.${this.PLATFORM}`).includes('bind')
  181. },
  182. // 是否显示小程序解绑按钮
  183. MPUnbind() {
  184. return this.CONFIG(`miniProgramAccount.${this.PLATFORM}`).includes('unbind')
  185. }
  186. // #endif
  187. }
  188. }
  189. </script>
  190. <style lang="less" scoped>
  191. .mybanner {
  192. background: #0c86d8;
  193. height: 120px;
  194. padding: 25px 15px;
  195. display: flex;
  196. align-items: center;
  197. .avatarslot {
  198. .avatar {
  199. height: 60px;
  200. width: 60px;
  201. }
  202. }
  203. .info {
  204. padding-left: 20px;
  205. .username {
  206. margin-bottom: 5px;
  207. }
  208. }
  209. .badge {
  210. flex-grow: 1;
  211. display: flex;
  212. justify-content: flex-end;
  213. }
  214. }
  215. .footer {
  216. text-align: center;
  217. font-size: 14px;
  218. color: #ccc;
  219. margin-bottom: 10rpx;
  220. }
  221. </style>