You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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