App.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <script>
  2. import wsRequest from '@/static/websocket.js'
  3. export default {
  4. onLaunch(e) {
  5. let that = this
  6. uni.login({
  7. success(data) {
  8. let code = data.code
  9. if (code) {
  10. that.$tm.request.post('card/login', {
  11. code
  12. }).then((res) => {
  13. uni.setStorageSync('token', res.data.token);
  14. that.$tm.request.get('user/read').then(res => {
  15. that.$tm.vx.commit('user/setUserInfo', res.data)
  16. uni.setStorageSync('card_id', res.data.card_id)
  17. // websocket开始
  18. let websocket = new wsRequest("wss://cardoa.platomix.net/chat",
  19. 5000)
  20. websocket.socketTask.onMessage(
  21. res => { //onMessage这个监听在封装的js中赋值给了socketTask对象
  22. let data = JSON.parse(res.data)
  23. if (data.type !== 'ping') {
  24. if (data.type == 'init') {
  25. that.$tm.request.post('chat/bind', {
  26. 'client_id': data.client_id
  27. })
  28. // uni.navigateTo({
  29. // url:"/pages/index/detail?card_id=7&isUser=1"
  30. // })
  31. } else if (data.type == 'system') {
  32. // uni.$emit('onSystem', data)
  33. that.$tm.vx.commit('num/setNum', data.data
  34. .chat_num)
  35. } else if (data.type == 'chat') {
  36. uni.$emit('onMessage', data)
  37. } else if (data.type == 'track') {
  38. that.$tm.vx.commit('track/setTrack', data.data)
  39. }
  40. }
  41. })
  42. })
  43. })
  44. }
  45. }
  46. });
  47. },
  48. onShow: function() {
  49. let that = this
  50. // #ifdef MP
  51. const updateManager = uni.getUpdateManager();
  52. updateManager.onCheckForUpdate(function(res) {});
  53. updateManager.onUpdateReady(function(res) {
  54. uni.showModal({
  55. title: '更新提示',
  56. content: '新版本已经准备好,确认重启应用?',
  57. showCancel: false,
  58. success(res) {
  59. if (res.confirm) {
  60. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  61. updateManager.applyUpdate();
  62. }
  63. }
  64. });
  65. });
  66. updateManager.onUpdateFailed(function(res) {
  67. // 新的版本下载失败
  68. uni.showModal({
  69. title: '更新提示',
  70. content: '新版本更新失败,确认重试',
  71. success(res) {
  72. if (res.confirm) {
  73. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  74. updateManager.applyUpdate();
  75. }
  76. }
  77. });
  78. });
  79. // #endif
  80. },
  81. onHide: function() {}
  82. }
  83. </script>
  84. <style lang="scss">
  85. /** 主题包 **/
  86. @import './static/theme.scss';
  87. .shadow-white-25 {
  88. box-shadow: 0 5rpx 10rpx rgba(0, 0, 0, 0.35) !important;
  89. }
  90. /* 弧形背景 */
  91. .pure_top {
  92. position: relative;
  93. width: 100%;
  94. text-align: center;
  95. }
  96. .pure_top::after {
  97. width: 100%;
  98. height: 200rpx;
  99. position: absolute;
  100. left: 0;
  101. top: 0;
  102. z-index: -1;
  103. content: '';
  104. border-radius: 0 0 10% 10%;
  105. background: rgba(59, 92, 240, 1) !important;
  106. }
  107. .cu-tabbar-height {
  108. padding: 0;
  109. // height: calc(100upx + env(safe-area-inset-bottom) / 2);
  110. padding-bottom: calc(env(safe-area-inset-bottom) / 2);
  111. }
  112. .visitor-items-userInfo {
  113. color: #7F8AA3;
  114. font-size: 30rpx;
  115. }
  116. </style>
  117. <style>
  118. /*每个页面公共css */
  119. @import "./tm-vuetify/mian.min.css";
  120. @import "@/static/main.css";
  121. /* 主题包 */
  122. @import "./tm-vuetify/scss/theme.css";
  123. @import "./tm-vuetify/scss/fonts/fontawesome_base64.css";
  124. </style>