index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="content">
  3. <image class="logo" :src="config?.logo[0]?.url||'/static/logo.png'"></image>
  4. </view>
  5. </template>
  6. <script setup lang="ts">
  7. import { getCurrentInstance, ref } from 'vue';
  8. //该依赖已内置不需要单独安装
  9. import { onLoad } from "@dcloudio/uni-app";
  10. // 请求接口
  11. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  12. const $app = getCurrentInstance()?.appContext.config.globalProperties.$app;
  13. const $config = getCurrentInstance()?.appContext.config.globalProperties.$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
  25. uni.setStorage({
  26. key: 'config',
  27. data: res.data,
  28. })
  29. }
  30. };
  31. // 查询
  32. const search = async () => {
  33. uni.getStorage({
  34. key: 'openid',
  35. success: function (res) {
  36. uni.reLaunch({
  37. url: `/pages/home/index`
  38. })
  39. },
  40. fail: function (err) {
  41. uni.login({
  42. success: async function (res) {
  43. if (res.code) {
  44. uni.reLaunch({
  45. url: `/pages/home/index`
  46. })
  47. const aee = await $app('/wechat/api/login/app', 'GET', {
  48. js_code: res.code,
  49. config: $config.wx_projectkey
  50. })
  51. if (aee.errcode == '0') {
  52. uni.setStorage({
  53. key: "openid",
  54. data: aee.data.openid
  55. })
  56. uni.reLaunch({
  57. url: `/pages/home/index`
  58. })
  59. } else {
  60. uni.showToast({
  61. title: aee.errmsg,
  62. icon: 'none'
  63. })
  64. }
  65. } else {
  66. uni.showToast({
  67. title: res.errMsg,
  68. icon: 'none'
  69. })
  70. }
  71. }
  72. });
  73. }
  74. })
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .content {
  79. display: flex;
  80. flex-direction: column;
  81. align-items: center;
  82. justify-content: center;
  83. width: 100vw;
  84. height: 100vh;
  85. .logo {
  86. width: 50vw;
  87. height: 50vw;
  88. border-radius: 90px;
  89. box-shadow: 0 0 5px #f1f1f1;
  90. }
  91. }
  92. </style>