index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <image class="logo" :src="logoUrl||'/static/logo.png'" />
  5. </view>
  6. </view>
  7. </template>
  8. <script setup lang="ts">
  9. import {
  10. getCurrentInstance,
  11. computed,
  12. ref
  13. } from 'vue'
  14. // 请求接口
  15. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  16. const $app = getCurrentInstance()?.appContext.config.globalProperties.$app;
  17. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  18. // openid
  19. const openid = computed(() => {
  20. return uni.getStorageSync('openid');
  21. })
  22. // logo图片
  23. const logoUrl = ref('');
  24. // 用户信息
  25. const initUser = async () => {
  26. uni.login({
  27. success: async function (result) {
  28. if (!result.code) {
  29. uni.showToast({
  30. title: '登录失败请重进!',
  31. icon: 'fail',
  32. });
  33. return false;
  34. }
  35. if (!openid.value) {
  36. const res = await login(result.code)
  37. if (res) uni.setStorageSync('openid', res);
  38. }
  39. uni.redirectTo({
  40. url: '/pages/home/index'
  41. })
  42. }
  43. })
  44. };
  45. // 获取openid
  46. const login = async (js_code : string) => {
  47. const res = await $app('/wechat/api/login/app', 'GET', {
  48. js_code: js_code,
  49. config: $config.wx_projectkey
  50. })
  51. if (res.errcode === 0) return res.data.openid;
  52. else {
  53. uni.showToast({
  54. title: '登录失败请重进!',
  55. icon: 'fail',
  56. });
  57. return false;
  58. }
  59. };
  60. // config信息
  61. const searchConfig = async () => {
  62. const res = await $api('/system/matchconfig/findOne', 'GET', {});
  63. if (res.code === 200) {
  64. if (res.data) {
  65. logoUrl.value = res.data.logoUrl
  66. uni.setStorageSync('config', res.data);
  67. }
  68. } else {
  69. uni.showToast({
  70. title: res.msg || '',
  71. icon: 'error',
  72. });
  73. }
  74. };
  75. initUser();
  76. searchConfig();
  77. </script>
  78. <style lang="scss" scoped>
  79. .content {
  80. display: flex;
  81. flex-direction: column;
  82. width: 100vw;
  83. height: 100vh;
  84. .one {
  85. text-align: center;
  86. margin: 50vw 0 0 0;
  87. .logo {
  88. width: 50vw;
  89. height: 50vw;
  90. border-radius: 90px;
  91. box-shadow: 0 0 5px #f1f1f1;
  92. }
  93. }
  94. }
  95. </style>