index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view class="content">
  3. <image class="logo" :src="config?.logo[0]?.url||'/static/logo.jpg'"></image>
  4. </view>
  5. </template>
  6. <script setup lang="ts">
  7. import { inject, ref } from 'vue';
  8. //该依赖已内置不需要单独安装
  9. import { onLoad } from "@dcloudio/uni-app";
  10. // 请求接口
  11. const $api = inject('$api');
  12. const $app = inject('$app');
  13. const $config = inject('$config');
  14. // 基本信息
  15. const config = ref({ logo: [] });
  16. onLoad(async () => {
  17. await searchConfig();
  18. await search();
  19. })
  20. // config信息
  21. const searchConfig = async () => {
  22. let res = await $api(`config`, 'GET', {});
  23. if (res.errcode == 0) {
  24. config.value = res.data[0] || {}
  25. uni.setStorage({
  26. key: 'config',
  27. data: res.data[0] || {},
  28. })
  29. }
  30. };
  31. // 查询
  32. const search = async () => {
  33. uni.getStorage({
  34. key: 'openid',
  35. success: async function (res) {
  36. const user = await $api('token/openid', 'POST', {
  37. openid: res.data
  38. })
  39. if (user.errcode == '0' && user.data?._id) {
  40. uni.setStorage({
  41. key: "user",
  42. data: user.data
  43. })
  44. } else {
  45. uni.removeStorage({
  46. key: 'user',
  47. success: function (res) {
  48. console.log('success');
  49. }
  50. });
  51. }
  52. uni.reLaunch({
  53. url: `/pages/home/index`
  54. })
  55. },
  56. fail: function (err) {
  57. uni.login({
  58. success: async function (res) {
  59. if (res.code) {
  60. uni.reLaunch({
  61. url: `/pages/home/index`
  62. })
  63. const aee = await $app('/wechat/api/login/app', 'GET', {
  64. js_code: res.code,
  65. config: $config.wx_projectkey
  66. })
  67. if (aee.errcode == '0') {
  68. uni.setStorage({
  69. key: "openid",
  70. data: aee.data.openid
  71. })
  72. const user = await $api('token/openid', 'POST', {
  73. openid: aee.data.openid
  74. })
  75. if (user.errcode == '0' && user.data?._id) {
  76. uni.setStorage({
  77. key: "user",
  78. data: user.data
  79. })
  80. } else {
  81. uni.removeStorage({
  82. key: 'user',
  83. success: function (res) {
  84. console.log('success');
  85. }
  86. });
  87. }
  88. uni.reLaunch({
  89. url: `/pages/home/index`
  90. })
  91. } else {
  92. uni.showToast({
  93. title: aee.errmsg,
  94. icon: 'none'
  95. })
  96. }
  97. } else {
  98. uni.showToast({
  99. title: res.errMsg,
  100. icon: 'none'
  101. })
  102. }
  103. }
  104. });
  105. }
  106. })
  107. };
  108. </script>
  109. <style lang="scss" scoped>
  110. .content {
  111. display: flex;
  112. flex-direction: column;
  113. align-items: center;
  114. justify-content: center;
  115. width: 100vw;
  116. height: 100vh;
  117. .logo {
  118. width: 50vw;
  119. height: 50vw;
  120. border-radius: 90px;
  121. box-shadow: 0 0 5px #f1f1f1;
  122. }
  123. }
  124. </style>