home.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. console.log('res',res)
  48. console.log('res.result',res.result)
  49. // uni.navigateTo({
  50. // url: '/pages/views/saoCode/saoCode?q=' + res.result
  51. // });
  52. uni.navigateTo({
  53. url: '/pages/views/saoCode/saoCode?q=' + encodeURIComponent(res.result)
  54. });
  55. }
  56. });
  57. },
  58. },
  59. onHide() {
  60. this.userType = 0;
  61. },
  62. onUnload() {
  63. this.userType = 0;
  64. }
  65. }
  66. </script>
  67. <style lang="stylus" scoped>
  68. #home {
  69. height: 100%;
  70. display: flex;
  71. flex-direction: column;
  72. .flex-box-page{
  73. flex:1;
  74. display: flex;
  75. flex-direction: column;
  76. }
  77. .scan_btn {
  78. z-index:10;
  79. position: fixed;
  80. bottom: 210rpx;
  81. right: 0rpx;
  82. width: 130rpx;
  83. height: 130rpx;
  84. }
  85. }
  86. </style>