home.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view id="home">
  3. <teacherHome class="flex-box-page" v-if="userType==1"></teacherHome>
  4. <pupilHome class="flex-box-page" v-if="userType==2"></pupilHome>
  5. <img class="scan_btn" @click.stop="saoCode" src="@/pages_safetyExamine/images/icon_xyxc_sm.png" />
  6. </view>
  7. </template>
  8. <script>
  9. import {
  10. teacherHome
  11. } from '@/pages/views/teacherPage/teacherHome'
  12. import {
  13. pupilHome
  14. } from '@/pages/views/pupilPage/pupilHome'
  15. export default {
  16. name: "home",
  17. components: {
  18. teacherHome,
  19. pupilHome,
  20. },
  21. data() {
  22. return {
  23. userType: 0,
  24. }
  25. },
  26. onLoad() {
  27. },
  28. onShow() {
  29. if (uni.getStorageSync('token') && uni.getStorageSync('userId') && uni.getStorageSync('userType')) {
  30. this.userType = uni.getStorageSync('userType')
  31. } else {
  32. uni.removeStorageSync('token');
  33. uni.removeStorageSync('userId');
  34. uni.removeStorageSync('userType');
  35. uni.redirectTo({
  36. url: '/pages/login/login',
  37. });
  38. }
  39. },
  40. methods: {
  41. /* 扫一扫*/
  42. saoCode() {
  43. let self = this;
  44. uni.scanCode({
  45. onlyFromCamera: true,
  46. success: function(res) {
  47. let list = res.result.split("?")[1].split("&");
  48. let codeData = {};
  49. list.forEach((item) => {
  50. codeData[item.split("=")[0]] = item.split("=")[1];
  51. })
  52. if(codeData.type == 1 || codeData.type == 5 || codeData.type == 7 ||
  53. codeData.type == 8 || codeData.type == 9 || codeData.type == 10 ||
  54. codeData.type == 11 || codeData.type == 12){
  55. uni.navigateTo({
  56. url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(res.result)
  57. });
  58. }else{
  59. uni.showToast({
  60. mask: true,
  61. icon: "none",
  62. position: "center",
  63. title: '请扫描正确的小程序二维码',
  64. duration: 2000
  65. });
  66. }
  67. }
  68. });
  69. },
  70. },
  71. onHide() {
  72. this.userType = 0;
  73. },
  74. onUnload() {
  75. this.userType = 0;
  76. }
  77. }
  78. </script>
  79. <style lang="stylus" scoped>
  80. #home {
  81. height: 100%;
  82. display: flex;
  83. flex-direction: column;
  84. .flex-box-page{
  85. flex:1;
  86. display: flex;
  87. flex-direction: column;
  88. }
  89. .scan_btn {
  90. z-index:10;
  91. position: fixed;
  92. bottom: 210rpx;
  93. right: 0rpx;
  94. width: 130rpx;
  95. height: 130rpx;
  96. }
  97. }
  98. </style>