1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <template>
- <view class="content">
- <view class="one">
- <image class="logo" :src="logoUrl||'/static/logo.png'" />
- </view>
- </view>
- </template>
- <script setup lang="ts">
- import {
- getCurrentInstance,
- computed,
- ref
- } from 'vue'
- // 请求接口
- const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
- const $app = getCurrentInstance()?.appContext.config.globalProperties.$app;
- const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
- // openid
- const openid = computed(() => {
- return uni.getStorageSync('openid');
- })
- // logo图片
- const logoUrl = ref('');
- // 用户信息
- const initUser = async () => {
- uni.login({
- success: async function (result) {
- if (!result.code) {
- uni.showToast({
- title: '登录失败请重进!',
- icon: 'fail',
- });
- return false;
- }
- if (!openid.value) {
- const res = await login(result.code)
- if (res) uni.setStorageSync('openid', res);
- }
- uni.redirectTo({
- url: '/pages/home/index'
- })
- }
- })
- };
- // 获取openid
- const login = async (js_code : string) => {
- const res = await $app('/wechat/api/login/app', 'GET', {
- js_code: js_code,
- config: $config.wx_projectkey
- })
- if (res.errcode === 0) return res.data.openid;
- else {
- uni.showToast({
- title: '登录失败请重进!',
- icon: 'fail',
- });
- return false;
- }
- };
- // config信息
- const searchConfig = async () => {
- const res = await $api('/system/matchconfig/findOne', 'GET', {});
- if (res.code === 200) {
- if (res.data) {
- logoUrl.value = res.data.logoUrl
- uni.setStorageSync('config', res.data);
- }
- } else {
- uni.showToast({
- title: res.msg || '',
- icon: 'error',
- });
- }
- };
- initUser();
- searchConfig();
- </script>
- <style lang="scss" scoped>
- .content {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 100vh;
- .one {
- text-align: center;
- margin: 50vw 0 0 0;
- .logo {
- width: 50vw;
- height: 50vw;
- border-radius: 90px;
- box-shadow: 0 0 5px #f1f1f1;
- }
- }
- }
- </style>
|