App.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <script>
  2. import { up, down } from '@/api/monitor'
  3. export default {
  4. onLaunch: function () {
  5. console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
  6. console.log('App Launch')
  7. },
  8. onShow: function () {
  9. console.log('App Show')
  10. console.log(this.$fileBasUrl, 'appppp$fileBasUrl')
  11. if (wx.getStorageSync('token')) {
  12. up()
  13. }
  14. // this.connectSocket()
  15. // this.timer = setInterval(() => {
  16. // wx.request({
  17. // url: 'http://192.168.0.109:3000/heartbeat?userId=' + wx.getStorageSync('userId'),
  18. // })
  19. // }, 5000)
  20. // uni.hideTabBar()
  21. },
  22. onHide: function () {
  23. console.log('App Hide')
  24. if (wx.getStorageSync('token')) {
  25. down()
  26. }
  27. // close socket
  28. // wx.closeSocket()
  29. // clearInterval(this.timer)
  30. // wx.request({
  31. // url: 'http://192.168.0.109:3000/hide?userId=' + wx.getStorageSync('userId'),
  32. // })
  33. },
  34. globalData: {
  35. fileBasUrl: 'https://mall.rongtongh.cn/storage/img',
  36. hasLogin: false,
  37. inviteId: null,
  38. orderConfirmIds: [],
  39. selectAddrss: false,
  40. selectCoupon: false,
  41. },
  42. methods: {
  43. connectSocket() {
  44. function connect() {
  45. wx.connectSocket({
  46. url: 'ws://192.168.0.109:3000',
  47. })
  48. wx.onSocketOpen(function (res) {
  49. console.log('WebSocket连接已打开!')
  50. let user = {
  51. name: 'user123',
  52. }
  53. wx.sendSocketMessage({
  54. data: JSON.stringify(user),
  55. })
  56. })
  57. wx.onSocketClose(function (res) {
  58. console.log('WebSocket连接已关闭!')
  59. setTimeout(() => {
  60. console.log('re connect')
  61. // connect()
  62. }, 2000)
  63. })
  64. }
  65. connect()
  66. },
  67. },
  68. }
  69. </script>
  70. <style lang="scss">
  71. @import './uni_modules/jc-tailwind/index.scss';
  72. /*每个页面公共css */
  73. @import '@/uni_modules/uni-scss/index.scss';
  74. /* #ifndef APP-NVUE */
  75. @import '@/static/customicons.css';
  76. @import '@/static/style.scss';
  77. // 设置整个项目的背景色
  78. page {
  79. background-color: #f5f5f5;
  80. }
  81. /* #endif */
  82. .example-info {
  83. font-size: 14px;
  84. color: #333;
  85. padding: 10px;
  86. }
  87. </style>