index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <image class="logo" :src="logoUrl" mode=""></image>
  6. </view>
  7. </view>
  8. </mobile-frame>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. logoUrl: '',
  15. };
  16. },
  17. onLoad: async function() {
  18. const that = this;
  19. await that.searchConfig();
  20. await that.watchlogin();
  21. },
  22. methods: {
  23. watchlogin() {
  24. const that = this;
  25. if (that.$store.state.socketTask == null) {
  26. uni.getStorage({
  27. key: 'token',
  28. success: function(res) {
  29. let user = that.$jwt(res.data);
  30. if (user._id) {
  31. //当websocket收到后端发送的消息时,触发
  32. let config = that.$config.wsUrl;
  33. // 开启websocket
  34. that.$store.dispatch('websocketInit', config + `/${user._id}`);
  35. }
  36. }
  37. })
  38. }
  39. },
  40. // 查询基本设置
  41. async searchConfig() {
  42. const that = this;
  43. let res = await that.$api(`/config`, 'GET', {});
  44. if (res.errcode == '0') {
  45. uni.getStorage({
  46. key: 'token',
  47. success: async (res) => {
  48. let arr = await that.$api(`/user/cct`, 'POST');
  49. if (arr.errcode == '0') {
  50. uni.setStorage({
  51. key: 'token',
  52. data: arr.data,
  53. success: function() {}
  54. });
  55. }
  56. }
  57. })
  58. let config = res.data;
  59. that.$set(that, `logoUrl`, config.config.logo[0].url);
  60. uni.setStorage({
  61. key: 'config',
  62. data: config,
  63. success: function(res) {
  64. // 赋值默认值
  65. that.$config.share = {
  66. title: config.title,
  67. path: '/pages/index/index',
  68. imageUrl: config.config.share[0].url
  69. }
  70. let url = `/pages/home/index`; ///pagesHome/order/detail /pages/home/index
  71. uni.redirectTo({
  72. url
  73. })
  74. },
  75. fail: function(err) {
  76. console.log(err);
  77. }
  78. })
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. .main {
  86. display: flex;
  87. flex-direction: column;
  88. width: 100vw;
  89. height: 100vh;
  90. .one {
  91. text-align: center;
  92. margin: 40vw 0 0 0;
  93. .logo {
  94. width: 50vw;
  95. height: 50vw;
  96. border-radius: 90px;
  97. box-shadow: 0 0 5px #f1f1f1;
  98. }
  99. }
  100. }
  101. </style>