index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view>
  3. <web-view src="http://localhost:3200"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. }
  11. },
  12. onReady() {
  13. // let token=uni.getStorageSync("token")
  14. // let userId=uni.getStorageSync("userId")
  15. // if(userId || token){
  16. // window.addEventListener("message", function (e) {
  17. // console.log('client 2 获取到数据啦:', e)
  18. // uni.setStorageSync("token",e.data.token)
  19. // uni.setStorageSync("userId",e.data.userId)
  20. // })
  21. // window.addEventListener("unload", function () {
  22. // window.removeEventListener("message", function (e) {
  23. // console.log('client 2 获取到数据啦:', e)
  24. // uni.setStorageSync("token",e.data.token)
  25. // uni.setStorageSync("userId",e.data.userId)
  26. // })
  27. // })
  28. },
  29. onLoad() {
  30. window.addEventListener("message", function (e) {
  31. console.log('client 2 获取到数据啦:', e)
  32. uni.setStorageSync("token",e.data.token)
  33. uni.setStorageSync("userId",e.data.userId)
  34. })
  35. let token=uni.getStorageSync("token")
  36. let userId=uni.getStorageSync("userId")
  37. let url= "ws://192.168.0.205:9000/common/websocket/test/"+ userId +""
  38. console.log("url",url)
  39. uni.connectSocket({
  40. url: "ws://192.168.0.205:9000/common/websocket/test/"+ userId +"/"+ token +"",
  41. // header: {
  42. // 'content-type': 'application/json'
  43. // },
  44. // protocols: ['protocol1'],
  45. // method: 'GET'
  46. });
  47. uni.onSocketMessage(function (res) {
  48. console.log('收到服务器内容:' + res);
  49. });
  50. // uni.createPushMessage({
  51. // content: '这是一条推送消息', // 推送内容
  52. // title: '新消息', // 推送标题
  53. // icon: '', // 推送图标(可选)
  54. // badge: '', // 应用角标数(可选)
  55. // duration:0, // 推送持续时间(可选)
  56. // success: function (res) {
  57. // console.log('推送成功', res);
  58. // },
  59. // fail: function (err) {
  60. // console.log('推送失败', err);
  61. // }
  62. // });
  63. // let item=uni.getStorageSync("_token");
  64. // console.log("item",item)
  65. },
  66. // onLoad: function () {
  67. // uni.createPushMessage({
  68. // content: '这是一条推送消息', // 推送内容
  69. // title: '新消息', // 推送标题
  70. // icon: '', // 推送图标(可选)
  71. // badge: '', // 应用角标数(可选)
  72. // duration:0, // 推送持续时间(可选)
  73. // success: function (res) {
  74. // console.log('推送成功', res);
  75. // },
  76. // fail: function (err) {
  77. // console.log('推送失败', err);
  78. // }
  79. // });
  80. // },
  81. methods: {
  82. }
  83. }
  84. </script>
  85. <style>
  86. </style>