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.

my.vue 7.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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('unboundwx')" 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.CLEAR_STORAGE()
  94. this.RELAUNCH_TO('/pages/login')
  95. },
  96. // #ifdef MP-ALIPAY || MP-WEIXIN
  97. // 小程序绑定方法,只会编译到小程序
  98. async userBind() {
  99. const type = this.PLATFORM
  100. const confirm = await this.CONFIRM(
  101. '绑定确认',
  102. `确定要将智慧校园账号与当前登录的${this.PLATFORM_TEXT}账号绑定吗?\n(绑定后可以使用一键登录功能)`,
  103. true
  104. )
  105. if (!confirm) {
  106. return
  107. }
  108. this.LOADING('绑定中…')
  109. const [codeErr, { code }] = await uni.login({ provider: type })
  110. if (codeErr || !code) {
  111. this.HIDE_LOADING()
  112. this.TOAST('获取用户授权码失败')
  113. return
  114. }
  115. const success = await this.HTTP_POST('learun/adms/user/openid_bind', { code, type }, '绑定失败')
  116. if (!success) {
  117. return
  118. }
  119. this.HIDE_LOADING()
  120. this.SET_GLOBAL('loginUser', Object.assign({}, this.currentUser, { miniProgram: true }))
  121. this.TOAST(`已成功绑定到当前的${this.PLATFORM_TEXT}账号`)
  122. },
  123. // 解绑小程序
  124. async userUnBind() {
  125. const confirm = await this.CONFIRM(
  126. '解绑确认',
  127. '确定要解除小程序账号绑定吗? (解绑将自动退出登录,需使用力软账号和密码再次登录)',
  128. true
  129. )
  130. if (!confirm) {
  131. return
  132. }
  133. const success = await this.HTTP_POST('learun/adms/user/openid_unbind', { type: this.PLATFORM }, '解除绑定失败')
  134. if (!success) {
  135. return
  136. }
  137. this.CLEAR_GLOBAL()
  138. this.RELAUNCH_TO('/pages/login')
  139. this.TOAST('已成功解除绑定')
  140. },
  141. // #endif
  142. // 跳转到
  143. goTo(urlPath) {
  144. this.NAV_TO(`/pages/my/${urlPath}`)
  145. },
  146. // 解绑微信
  147. unbound(){
  148. this.CONFIRM('提示', '确定要解绑微信账号?', true).then(res => {
  149. if (res) {
  150. this.LOADING('正在解绑…');
  151. this.HTTP_POST('learun/adms/user/unbundWeiXin', null, '解绑失败').then(success => {
  152. this.HIDE_LOADING();
  153. if (!success) {
  154. return
  155. }
  156. this.TOAST("解绑成功")
  157. setTimeout(()=>{
  158. this.CLEAR_GLOBAL()
  159. this.RELAUNCH_TO('/pages/login')
  160. },500)
  161. });
  162. }
  163. });
  164. },
  165. // 用户头像 url
  166. avatarSrc() {
  167. if (!this.currentUser) {
  168. return ''
  169. }
  170. return this.API + `/learun/adms/user/img?data=${this.currentUser.userId}`
  171. }
  172. },
  173. computed: {
  174. // 返回当前用户
  175. currentUser() {
  176. return this.GET_GLOBAL('loginUser')
  177. },
  178. // 获取组织结构 tag 的显示
  179. userTag() {
  180. if (!this.currentUser) {
  181. return ''
  182. }
  183. const { companyId, departmentId } = this.currentUser
  184. if (!companyId) {
  185. return `总集团公司`
  186. }
  187. const company = this.GET_GLOBAL('company')
  188. const dep = this.GET_GLOBAL('department')
  189. // const companyName = company[companyId].name
  190. // if (!dep) {
  191. // return companyName
  192. // }
  193. // return `${companyName} / ${dep[departmentId].name}`
  194. },
  195. // 头像圆形/方形显示参数
  196. roundAvatar() {
  197. return this.CONFIG('pageConfig.roundAvatar')
  198. },
  199. // 页面底部公司/版权显示
  200. copyRightDisplay() {
  201. const year = new Date().getFullYear()
  202. const company = this.CONFIG('company')
  203. return `Copyright © ${year} ${company}`
  204. },
  205. // #ifdef MP-ALIPAY || MP-WEIXIN
  206. // 是否显示小程序绑定按钮
  207. MPBind() {
  208. return this.CONFIG(`miniProgramAccount.${this.PLATFORM}`).includes('bind')
  209. },
  210. // 是否显示小程序解绑按钮
  211. MPUnbind() {
  212. return this.CONFIG(`miniProgramAccount.${this.PLATFORM}`).includes('unbind')
  213. }
  214. // #endif
  215. }
  216. }
  217. </script>
  218. <style lang="less" scoped>
  219. .mybanner {
  220. background: #0c86d8;
  221. height: 120px;
  222. padding: 25px 15px;
  223. display: flex;
  224. align-items: center;
  225. .avatarslot {
  226. .avatar {
  227. height: 60px;
  228. width: 60px;
  229. }
  230. }
  231. .info {
  232. padding-left: 20px;
  233. .username {
  234. margin-bottom: 5px;
  235. }
  236. }
  237. .badge {
  238. flex-grow: 1;
  239. display: flex;
  240. justify-content: flex-end;
  241. }
  242. }
  243. .footer {
  244. text-align: center;
  245. font-size: 14px;
  246. color: #ccc;
  247. margin-bottom: 10rpx;
  248. }
  249. </style>