index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view>
  3. <view v-if="showLogin">
  4. <login :ocode="ocode" :appkey="appkey" scope="snsapi_userinfo" :visible="visible" @success="loginSuccess" @fail="loginFail" @cancel="loginCancel" />
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. // 获取用户信息
  13. ocode: '1015730314',
  14. // 商户appkey
  15. appkey: 'EE28EE2C93296F4E',
  16. // 是否授权可见
  17. visible: false,
  18. // 是否启动授权
  19. showLogin: false,
  20. // 获取用户信息
  21. appid: 'wxd6f090391d410534',
  22. // 用户路由
  23. userListInfo: {
  24. routes: ['报修', '我的报修'],
  25. btns: []
  26. },
  27. // 师傅路由
  28. workerListInfo: {
  29. routes: ['首页', '工单管理', '待处理池'],
  30. btns: ['协作', '接单', '转单', '报价', '维修完成']
  31. },
  32. // 后勤路由
  33. logisticsListInfo: {
  34. routes: ['首页', '工单管理', '待处理池', '通讯录'],
  35. btns: ['表格编辑', '延时', '派单', '审核', '分段器按钮']
  36. },
  37. // 管理者路由
  38. adminListInfo: {
  39. routes: ['首页', '工单管理', '待处理池', '通讯录'],
  40. btns: ['首页分段器', '表格编辑', '工单管理分段器', '延时', '派单', '审核', '接单', '报价', '维修完成']
  41. }
  42. }
  43. },
  44. mounted() {
  45. this.hasUserInfo()
  46. // uni.setStorageSync('currentIndexRepairs', 0)
  47. // uni.showActionSheet({
  48. // itemList: ['用户', '维修师傅', '管理员', '后勤'],
  49. // success: (res) => {
  50. // if (res.tapIndex == 0) {
  51. // uni.setStorageSync('repairsUserInfo', this.userListInfo)
  52. // } else if (res.tapIndex == 1) {
  53. // uni.setStorageSync('repairsUserInfo', this.workerListInfo)
  54. // } else if (res.tapIndex == 2) {
  55. // uni.setStorageSync('repairsUserInfo', this.adminListInfo)
  56. // } else if (res.tapIndex == 3) {
  57. // uni.setStorageSync('repairsUserInfo', this.logisticsListInfo)
  58. // }
  59. // uni.reLaunch({
  60. // url: '/pagesRepairs/box/box'
  61. // })
  62. // }
  63. // })
  64. },
  65. methods: {
  66. // 检查是否存在用户信息
  67. hasUserInfo() {
  68. const repairsUserInfo = uni.getStorageSync('repairsUserInfo')
  69. console.log(repairsUserInfo)
  70. if (repairsUserInfo) {
  71. uni.setStorageSync('currentIndexRepairs', 0)
  72. uni.reLaunch({
  73. url: '/pagesRepairs/box/box'
  74. })
  75. } else {
  76. console.log('重新授权')
  77. this.showLogin = true
  78. this.visible = true
  79. }
  80. },
  81. // 授权成功回调
  82. loginSuccess(res) {
  83. console.log('成功')
  84. let wxcode = res.detail.wxcode
  85. console.log(wxcode)
  86. // 获取wxcode后请求登录
  87. this.login(wxcode)
  88. },
  89. // 用户登陆获取个人信息
  90. async login(wxcode) {
  91. const res = await this.$myRequest_repairs({
  92. url: '/login/Openid',
  93. header: {},
  94. data: {
  95. wxcode
  96. }
  97. })
  98. console.log(res)
  99. if (res.code === '200') {
  100. uni.setStorageSync('repairsUserInfo', res.data)
  101. uni.setStorageSync('currentIndexRepairs', 0)
  102. uni.reLaunch({
  103. url: '/pagesRepairs/box/box'
  104. })
  105. }
  106. },
  107. // 授权失败回调
  108. loginFail() {
  109. // console.log("授权失败");
  110. uni.showModal({
  111. title: '提示',
  112. content: '授权:请先领取校园卡、并激活!',
  113. confirmText: '领取',
  114. success: (res) => {
  115. if (res.confirm) {
  116. uni.reLaunch({
  117. url: '/pages/qr_code/qr_code'
  118. })
  119. } else if (res.cancel) {
  120. uni.reLaunch({
  121. url: '/pagesClockIn/404/404'
  122. })
  123. }
  124. }
  125. })
  126. },
  127. // 授权取消回调
  128. loginCancel() {
  129. // console.log("取消");
  130. uni.showModal({
  131. title: '提示',
  132. content: '请先授权,否则无法使用该功能',
  133. confirmText: '授权',
  134. success: (res) => {
  135. if (res.confirm) {
  136. uni.reLaunch({
  137. url: '/pagesRepairs/index/index'
  138. })
  139. } else if (res.cancel) {
  140. uni.reLaunch({
  141. url: '/pagesClockIn/404/404'
  142. })
  143. }
  144. }
  145. })
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss"></style>