index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. // repairsUserInfo: {
  23. // routes: ['首页', '工单管理', '待处理池']
  24. // },
  25. // 用户路由
  26. userListInfo: {
  27. routes: ['报修', '我的报修'],
  28. btns: []
  29. },
  30. // 师傅路由
  31. workerListInfo: {
  32. routes: ['首页', '工单管理', '待处理池'],
  33. btns: ['协作', '接单', '转单', '报价', '维修完成']
  34. },
  35. // 后勤路由
  36. logisticsListInfo: {
  37. routes: ['首页', '工单管理', '待处理池', '通讯录'],
  38. btns: ['表格编辑', '延时', '派单', '审核', '分段器按钮']
  39. },
  40. // 管理者路由
  41. adminListInfo: {
  42. routes: ['首页', '工单管理', '待处理池', '通讯录'],
  43. btns: ['首页分段器', '表格编辑', '工单管理分段器', '延时', '派单', '审核', '接单', '报价', '维修完成']
  44. }
  45. }
  46. },
  47. mounted() {
  48. // this.hasUserInfo()
  49. uni.setStorageSync('currentIndexRepairs', 0)
  50. uni.showActionSheet({
  51. itemList: ['用户', '维修师傅', '管理员', '后勤'],
  52. success: (res) => {
  53. if (res.tapIndex == 0) {
  54. uni.setStorageSync('repairsUserInfo', this.userListInfo)
  55. } else if (res.tapIndex == 1) {
  56. uni.setStorageSync('repairsUserInfo', this.workerListInfo)
  57. } else if (res.tapIndex == 2) {
  58. uni.setStorageSync('repairsUserInfo', this.adminListInfo)
  59. } else if (res.tapIndex == 3) {
  60. uni.setStorageSync('repairsUserInfo', this.logisticsListInfo)
  61. }
  62. uni.reLaunch({
  63. url: '/pagesRepairs/box/box'
  64. })
  65. }
  66. })
  67. },
  68. methods: {
  69. // 检查是否存在用户信息
  70. hasUserInfo() {
  71. const repairsUserInfo = uni.getStorageSync('repairsUserInfo')
  72. console.log(repairsUserInfo)
  73. if (repairsUserInfo) {
  74. uni.reLaunch({
  75. url: '/pagesRepairs/box/box'
  76. })
  77. } else {
  78. console.log('重新授权')
  79. // uni.setStorageSync('repairsUserInfo', this.userListInfo)
  80. // uni.reLaunch({
  81. // url: '/pagesRepairs/box/box'
  82. // })
  83. this.showLogin = true
  84. this.visible = true
  85. }
  86. },
  87. // 授权成功回调
  88. loginSuccess(res) {
  89. console.log('成功')
  90. let wxcode = res.detail.wxcode
  91. console.log(wxcode)
  92. // 获取wxcode后请求登录
  93. this.login(wxcode)
  94. },
  95. // 授权失败回调
  96. loginFail() {
  97. // console.log("授权失败");
  98. uni.showModal({
  99. title: '提示',
  100. content: '授权:请先领取校园卡、并激活!',
  101. confirmText: '领取',
  102. success: (res) => {
  103. if (res.confirm) {
  104. uni.reLaunch({
  105. url: '/pages/qr_code/qr_code'
  106. })
  107. } else if (res.cancel) {
  108. uni.reLaunch({
  109. url: '/pagesClockIn/404/404'
  110. })
  111. }
  112. }
  113. })
  114. },
  115. // 授权取消回调
  116. loginCancel() {
  117. // console.log("取消");
  118. uni.showModal({
  119. title: '提示',
  120. content: '请先授权,否则无法使用该功能',
  121. confirmText: '授权',
  122. success: (res) => {
  123. if (res.confirm) {
  124. uni.reLaunch({
  125. url: '/pagesRepairs/index/index'
  126. })
  127. } else if (res.cancel) {
  128. uni.reLaunch({
  129. url: '/pagesClockIn/404/404'
  130. })
  131. }
  132. }
  133. })
  134. },
  135. // 用户登陆获取个人信息和token
  136. async login(wxcode) {
  137. const res = await this.$myRequest_repairs({
  138. url: '/repair/api/login/Openid',
  139. // header: {
  140. // 'content-type': 'application/json',
  141. // platform: 2,
  142. // 'Accept-Language': 'zh-CN,zh;q=0.9'
  143. // },
  144. data: {
  145. // redirect_uri: `mnp://${this.appid}`,
  146. wxcode
  147. }
  148. })
  149. console.log(res)
  150. // if (res.code == 200) {
  151. // uni.setStorageSync('token', res.data.token)
  152. // uni.reLaunch({
  153. // url: '/pagesRepairs/box/box'
  154. // })
  155. // } else {
  156. // uni.showToast({
  157. // title: res.message,
  158. // icon: 'none'
  159. // })
  160. // }
  161. }
  162. }
  163. }
  164. </script>
  165. <style lang="scss"></style>