manage.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="container">
  3. <view class="lists" v-if="login">
  4. <view class="cu-card case">
  5. <view class="cu-item">
  6. <view class="cu-list menu-avatar">
  7. <view class="cu-item">
  8. <view class="cu-avatar round" :style="[{'background-image': 'url(' + avatar + ')'}]">
  9. </view>
  10. <view class="content">
  11. <view>{{user.nickname || ''}}</view>
  12. <view>电话:{{user.mobile || ''}}</view>
  13. <view>部门:{{user.department || ''}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="cu-list menu sm-border card-menu">
  20. <view class="cu-item arrow" @click="callManage()">
  21. <view class="content">
  22. <text class="cuIcon-phone text-black"></text>
  23. <text class="text-black">联系管理员</text>
  24. </view>
  25. </view>
  26. <view class="cu-item arrow" @click="logout()">
  27. <view class="content">
  28. <text class="cuIcon-exit text-black"></text>
  29. <text class="text-black">退出登录</text>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <view v-else>
  35. <view class="empty nologin-content">
  36. <image src="../../static/nologin.png" mode="widthFix"></image>
  37. <view class="text-gray">请先登录账号</view>
  38. <button class="cu-btn block bg-black lg" @click="goLogin()">
  39. <text class="cuIcon-lock margin-right-xs"></text> 登录账号</button>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. var _self
  46. var isLogin
  47. export default {
  48. data() {
  49. return {
  50. login: false,
  51. user: {},
  52. avatar: '',
  53. managePhone: ''
  54. };
  55. },
  56. onShow() {
  57. if (!_self.login) {
  58. isLogin = !getApp().globalData.token ? false : true
  59. if (isLogin) {
  60. _self.login = isLogin
  61. _self.getStaffInfo()
  62. }
  63. }
  64. },
  65. onLoad(e) {
  66. _self = this
  67. isLogin = !getApp().globalData.token ? false : true
  68. _self.login = isLogin
  69. if (!isLogin) {
  70. wx.login({
  71. success(res) {
  72. if (res.code) {
  73. _self.goWeLogin(res.code)
  74. }
  75. }
  76. })
  77. } else {
  78. _self.getStaffInfo()
  79. }
  80. _self.getSystemInfo()
  81. },
  82. methods: {
  83. getSystemInfo() {
  84. _self.$api.getSystemInfo().then((res) => {
  85. _self.managePhone = res.data.manage_phone
  86. }).catch((err) => {
  87. })
  88. },
  89. getStaffInfo() {
  90. uni.showLoading({
  91. title: '加载中...'
  92. })
  93. _self.$api.getStaffInfo().then((res) => {
  94. uni.hideLoading()
  95. _self.user = res.data
  96. _self.avatar = res.data.avatar
  97. }).catch((err) => {
  98. uni.hideLoading()
  99. _self.tui.toast(err.msg)
  100. })
  101. },
  102. goWeLogin(code) {
  103. _self.$api.welogin({
  104. code
  105. }).then((res) => {
  106. getApp().globalData.token = res.data.token
  107. getApp().globalData.equipmentManage = res.data.equipment_manage
  108. uni.setStorageSync('equipment_token', res.data.token)
  109. uni.setStorageSync('equipment_openid', res.data.openid)
  110. uni.setStorageSync('equipment_manage', res.data.equipment_manage)
  111. _self.login = true
  112. _self.getStaffInfo()
  113. }).catch((err) => {
  114. })
  115. },
  116. goLogin() {
  117. uni.navigateTo({
  118. url: '/pages/login/login',
  119. events: {
  120. // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
  121. isLoginFromLogin: function(data) {
  122. if (data && data.isLogin) {
  123. _self.login = true
  124. _self.getStaffInfo()
  125. }
  126. }
  127. }
  128. })
  129. },
  130. logout() {
  131. uni.showModal({
  132. title: '提示',
  133. content: '是否确认要操作退出登录?',
  134. success: function(res) {
  135. if (res.confirm) {
  136. _self.doLogout()
  137. }
  138. }
  139. });
  140. },
  141. doLogout() {
  142. uni.showLoading({
  143. title: '退出中...'
  144. })
  145. _self.$api.logout().then((res) => {
  146. uni.hideLoading()
  147. _self.clearStorage()
  148. }).catch((err) => {
  149. uni.hideLoading()
  150. _self.clearStorage()
  151. // _self.tui.toast(err.msg)
  152. })
  153. },
  154. clearStorage() {
  155. try {
  156. _self.login = false
  157. getApp().globalData.token = ''
  158. getApp().globalData.equipmentManage = 0
  159. uni.setStorageSync('equipment_token', '')
  160. uni.setStorageSync('equipment_openid', '')
  161. uni.setStorageSync('equipment_manage', '')
  162. uni.$emit('loginStatusEvent', {
  163. isLogin: false
  164. })
  165. _self.tui.toast('退出登录成功')
  166. } catch (e) {
  167. _self.tui.toast('退出失败,请稍后再试')
  168. }
  169. },
  170. callManage() {
  171. let managePhone = _self.managePhone
  172. if (managePhone == '') {
  173. _self.tui.toast('暂无管理员联系方式')
  174. return;
  175. }
  176. uni.makePhoneCall({
  177. phoneNumber: managePhone
  178. })
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. .cu-card>.cu-item {
  185. margin: 20rpx;
  186. }
  187. .cu-list.menu-avatar>.cu-item {
  188. height: 250rpx;
  189. .cu-avatar {
  190. width: 150rpx;
  191. height: 150rpx;
  192. left: 40rpx;
  193. }
  194. .content {
  195. left: 240rpx;
  196. line-height: 2;
  197. >view:first-child {
  198. font-size: 40rpx;
  199. font-weight: bold;
  200. }
  201. }
  202. }
  203. .cu-list.menu-avatar>.cu-item:after {
  204. border: 0;
  205. }
  206. .cu-list.card-menu {
  207. margin: 0 20rpx 20rpx;
  208. border-radius: 10rpx;
  209. }
  210. .empty {
  211. display: flex;
  212. flex-direction: column;
  213. align-items: center;
  214. justify-content: center;
  215. margin-top: 20vh;
  216. text-align: center;
  217. image {
  218. width: 40%;
  219. }
  220. .cu-btn {
  221. margin-top: 220rpx;
  222. }
  223. }
  224. .nologin-content {
  225. height: 100vh;
  226. margin-top: 0;
  227. background-color: #FFFFFF;
  228. }
  229. </style>