App.vue 2.0 KB

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