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