Browse Source

初始化用户

st 2 months ago
parent
commit
773400bf14

+ 8 - 1
.eslintrc-auto-import.json

@@ -94,6 +94,13 @@
     "useTelegramBackButton": true,
     "useTelegramTheme": true,
     "formatAmount": true,
-    "formatAmountNoFloat": true
+    "formatAmountNoFloat": true,
+    "DirectiveBinding": true,
+    "MaybeRef": true,
+    "MaybeRefOrGetter": true,
+    "onWatcherCleanup": true,
+    "useId": true,
+    "useModel": true,
+    "useTemplateRef": true
   }
 }

+ 3 - 4
env/.env

@@ -7,13 +7,12 @@ VITE_WX_APPID = 'wxa2abb91f64032a2b'
 # h5部署网站的base,配置到 manifest.config.ts 里的 h5.router.base
 VITE_APP_PUBLIC_BASE=/tonmini/
 
-VITE_SERVER_BASEURL = 'https://guitarcoin.app/'
-#VITE_SERVER_BASEURL = 'https://mydomainnow.xyz/'
-VITE_UPLOAD_BASEURL = 'https://guitarcoin.app/api/upload/image'
+VITE_SERVER_BASEURL = 'http://xoyozi9walh9.xiaomiqiu.com/app'
+VITE_UPLOAD_BASEURL = 'https://guitarcoin.app/app/upload/image'
 
 # h5是否需要配置代理
 VITE_APP_PROXY=true
-VITE_APP_PROXY_PREFIX = '/api'
+VITE_APP_PROXY_PREFIX = '/app'
 
 VITE_TELEGRAM_BASEURL = 'https://guitarcoin.app'
 VITE_TELEGRAM_BOOTNAME = 'Guitarcoinapp_bot'

+ 1 - 1
src/env.d.ts

@@ -18,7 +18,7 @@ interface ImportMetaEnv {
   /** H5是否需要代理 */
   readonly VITE_APP_PROXY: 'true' | 'false'
   /** H5是否需要代理,需要的话有个前缀 */
-  readonly VITE_APP_PROXY_PREFIX: string // 一般是/api
+  readonly VITE_APP_PROXY_PREFIX: string // 一般是/app
   /** 上传图片地址 */
   readonly VITE_UPLOAD_BASEURL: string
   /** 是否清除console */

+ 1 - 1
src/hooks/useUpload.ts

@@ -55,7 +55,7 @@ function uploadFile<T>({ tempFilePath, formData, data, error, loading }) {
       title: 'loading...',
     })
   }
-  const url = import.meta.env.MODE === 'development' ? '/api/upload/image' : VITE_UPLOAD_BASEURL
+  const url = import.meta.env.MODE === 'development' ? '/app/upload/image' : VITE_UPLOAD_BASEURL
   uni.uploadFile({
     url,
     filePath: tempFilePath,

+ 1 - 1
src/locale/README.md

@@ -9,4 +9,4 @@
 ## 参考文档
 
 [uniapp 国际化开发指南](https://uniapp.dcloud.net.cn/tutorial/i18n.html)
-[uniapp 国际化-注意事项](https://uniapp.dcloud.net.cn/api/ui/locale.html#onlocalechange) 最下面的注意事项
+[uniapp 国际化-注意事项](https://uniapp.dcloud.net.cn/app/ui/locale.html#onlocalechange) 最下面的注意事项

+ 12 - 3
src/pages/index/index.vue

@@ -16,14 +16,23 @@
   </view>
 </template>
 <script setup lang="ts">
+import { useLaunchParams } from '@telegram-apps/sdk-vue'
 import lottie from 'lottie-web'
 import animationData from '@/static/Animation.json'
 import Dialog from '@/components/common/Dialog/index.vue'
-
-const containerRef = ref(null)
+import { useUserStore } from '@/store/user'
+import { getShareCode } from '@/service/team'
+const pl = useLaunchParams()
+const useStore = useUserStore()
 const show = ref(false)
 
-onShow(() => {
+const initUser = async (user: any, shareCode: string) => {
+  const data = await useStore.setUserInfo(user, shareCode)
+}
+
+onShow(async () => {
+  await initUser(pl.initData.user, uni.getStorageSync('shareCode') || '')
+  const { data } = await getShareCode()
   nextTick(() => {
     const query = uni.createSelectorQuery()
     query

+ 13 - 18
src/service/index/foo.ts

@@ -6,16 +6,11 @@ export interface IFooItem {
 }
 
 export interface UserT {
-  token: string
-  nickname: string
-  login_telegram: string
-  register_status: number
+  tokenValue: string
 }
 
 export interface LoginI {
   coin_address?: string
-  scene?: string
-  terminal?: string
   share_code?: string
   firstName: string
   id: string | number
@@ -92,56 +87,56 @@ export const postFooAPI = (name: string) => {
 }
 // 登录接口
 export const coinLoginApi = (data: LoginI) => {
-  return httpGet<UserT>('/api/login/coinLogin', data)
+  return httpGet<UserT>('/app/login/coinLogin', data)
 }
 
 // 获取当前登录用户金币数量
 export const getUserCoinApi = () => {
-  return httpGet<UserCenter>('/api/development/center')
+  return httpGet<UserCenter>('/app/development/center')
 }
 
 // 统计用户在线时长
 export const updateOnlineTime = (onlineTime: number) => {
-  return http.post<UserCenter>('/api/user/updateOnlineTime', { online_time: onlineTime })
+  return http.post<UserCenter>('/app/user/updateOnlineTime', { online_time: onlineTime })
 }
 // 设置金币
 export const updateClikckAddCoin = (goldCoin: number) => {
-  return http.post<any>('/api/user/clikckAddCoin', { gold_coin: goldCoin })
+  return http.post<any>('/app/user/clikckAddCoin', { gold_coin: goldCoin })
 }
 // 设置体力
 export const updateStamina = (stamina: number) => {
-  return http.post<any>('/api/user/updateStamina', { stamina })
+  return http.post<any>('/app/user/updateStamina', { stamina })
 }
 
 // 检查是否注册过
 export const coinLoginCheck = (id: number) => {
-  return http.get<LoginCheck>('/api/login/coinLoginCheck', { terminal: 3, id })
+  return http.get<LoginCheck>('/app/login/coinLoginCheck', { terminal: 3, id })
 }
 
 // 开始金币活动
 export const startCoinGame = (startTime: string) => {
-  return http.post<LoginCheck>('/api/user/startCoinGame', { start_time: startTime })
+  return http.post<LoginCheck>('/app/user/startCoinGame', { start_time: startTime })
 }
 
 // 获取当前金币数量改版
 export const getDevelopmentCenter = () => {
-  return http.get<JinbiT>('/api/development/center')
+  return http.get<JinbiT>('/app/development/center')
 }
 // 设置金币
 export const stageCoinAdd = () => {
-  return http.post<any>('/api/user/stageCoinAdd')
+  return http.post<any>('/app/user/stageCoinAdd')
 }
 
 // 获取推进器信息
 export const propellerAllTwo = () => {
-  return http.get<ProductionIncreaseInterface[]>('/api/propeller/propellerAllTwo')
+  return http.get<ProductionIncreaseInterface[]>('/app/propeller/propellerAllTwo')
 }
 // 升级推进器
 export const prepellerDeduction = (id: number) => {
-  return http.post<any>('/api/propeller/prepellerDeduction', { id })
+  return http.post<any>('/app/propeller/prepellerDeduction', { id })
 }
 
 // 存入当前语言 user/checkLanguage
 export const postCheckLang = (lang: string) => {
-  return http.post<any>('/api/user/checkLanguage', { lang })
+  return http.post<any>('/app/user/checkLanguage', { lang })
 }

+ 5 - 0
src/service/team/index.ts

@@ -0,0 +1,5 @@
+import { httpGet } from '@/utils/http'
+
+export const getShareCode = () => {
+  return httpGet<string>('/app/distribution/getShareCode')
+}

+ 2 - 13
src/store/user.ts

@@ -2,7 +2,6 @@ import { defineStore } from 'pinia'
 import { ref } from 'vue'
 import { coinLoginApi, UserT } from '@/service/index/foo'
 import type { IUserInfo } from '@/typings'
-import { getGroup } from '@/service/team'
 
 const initState = {
   nickname: '',
@@ -26,25 +25,15 @@ export const useUserStore = defineStore(
     const userInfo = ref<IUserInfo>({ ...initState })
 
     const setUserInfo = async (val: IUserInfo, shareCode: string) => {
-      val.scene = '1'
-      val.terminal = '3'
       val.age_limit = uni.getStorageSync('age') || ''
-      val.avatar = val.photoUrl
       userInfo.value = val
       userInfo.value.share_code = shareCode
       const { data } = await coinLoginApi(val)
-      userInfo.value.token = data.token
-      uni.setStorageSync('token', data.token)
+      userInfo.value.token = data.tokenValue
+      uni.setStorageSync('token', data.tokenValue)
       return new Promise<UserT>((resolve) => {
         resolve(data)
       })
-      // 团队
-      // const res = await getGroup()
-      // if (res.data) {
-      //   userInfo.value.userGroup = res.data.group_info
-      // } else {
-      //   userInfo.value.userGroup = null
-      // }
     }
     const shareCode = ref(uni.getStorageSync('shareCode') || '')
     const setShareCode = (val: string) => {

+ 9 - 88
src/types/auto-import.d.ts

@@ -61,6 +61,7 @@ declare global {
   const onUnload: typeof import('@dcloudio/uni-app')['onUnload']
   const onUnmounted: typeof import('vue')['onUnmounted']
   const onUpdated: typeof import('vue')['onUpdated']
+  const onWatcherCleanup: typeof import('vue')['onWatcherCleanup']
   const provide: typeof import('vue')['provide']
   const reactive: typeof import('vue')['reactive']
   const readonly: typeof import('vue')['readonly']
@@ -78,11 +79,14 @@ declare global {
   const useAttrs: typeof import('vue')['useAttrs']
   const useCssModule: typeof import('vue')['useCssModule']
   const useCssVars: typeof import('vue')['useCssVars']
+  const useId: typeof import('vue')['useId']
   const useImgPath: typeof import('../hooks/useImgPath')['useImgPath']
+  const useModel: typeof import('vue')['useModel']
   const useNavbarWeixin: (typeof import("../hooks/useNavbarWeixin"))["default"]
   const useRequest: typeof import('../hooks/useRequest')['default']
   const useSlots: typeof import('vue')['useSlots']
   const useTelegramBackButton: typeof import('../hooks/useTelegramBackButton')['useTelegramBackButton']
+  const useTemplateRef: typeof import('vue')['useTemplateRef']
   const useUpload: typeof import('../hooks/useUpload')['default']
   const useUpload2: typeof import("../hooks/useUpload2")["default"]
   const watch: typeof import('vue')['watch']
@@ -93,7 +97,7 @@ declare global {
 // for type re-export
 declare global {
   // @ts-ignore
-  export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
+  export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
   import('vue')
 }
 // for vue template auto import
@@ -157,6 +161,7 @@ declare module 'vue' {
     readonly onUnload: UnwrapRef<typeof import('@dcloudio/uni-app')['onUnload']>
     readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
     readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
+    readonly onWatcherCleanup: UnwrapRef<typeof import('vue')['onWatcherCleanup']>
     readonly provide: UnwrapRef<typeof import('vue')['provide']>
     readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
     readonly readonly: UnwrapRef<typeof import('vue')['readonly']>
@@ -174,97 +179,13 @@ declare module 'vue' {
     readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
     readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
     readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
+    readonly useId: UnwrapRef<typeof import('vue')['useId']>
     readonly useImgPath: UnwrapRef<typeof import('../hooks/useImgPath')['useImgPath']>
+    readonly useModel: UnwrapRef<typeof import('vue')['useModel']>
     readonly useRequest: UnwrapRef<typeof import('../hooks/useRequest')['default']>
     readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
     readonly useTelegramBackButton: UnwrapRef<typeof import('../hooks/useTelegramBackButton')['useTelegramBackButton']>
-    readonly useUpload: UnwrapRef<typeof import('../hooks/useUpload')['default']>
-    readonly watch: UnwrapRef<typeof import('vue')['watch']>
-    readonly watchEffect: UnwrapRef<typeof import('vue')['watchEffect']>
-    readonly watchPostEffect: UnwrapRef<typeof import('vue')['watchPostEffect']>
-    readonly watchSyncEffect: UnwrapRef<typeof import('vue')['watchSyncEffect']>
-  }
-}
-declare module '@vue/runtime-core' {
-  interface GlobalComponents {}
-  interface ComponentCustomProperties {
-    readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
-    readonly computed: UnwrapRef<typeof import('vue')['computed']>
-    readonly createApp: UnwrapRef<typeof import('vue')['createApp']>
-    readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
-    readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
-    readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
-    readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']>
-    readonly formatAmount: UnwrapRef<typeof import('../hooks/moneyProcessing')['formatAmount']>
-    readonly formatAmountNoFloat: UnwrapRef<typeof import('../hooks/moneyProcessing')['formatAmountNoFloat']>
-    readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
-    readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
-    readonly h: UnwrapRef<typeof import('vue')['h']>
-    readonly inject: UnwrapRef<typeof import('vue')['inject']>
-    readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
-    readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
-    readonly isReadonly: UnwrapRef<typeof import('vue')['isReadonly']>
-    readonly isRef: UnwrapRef<typeof import('vue')['isRef']>
-    readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
-    readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
-    readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
-    readonly onAddToFavorites: UnwrapRef<typeof import('@dcloudio/uni-app')['onAddToFavorites']>
-    readonly onBackPress: UnwrapRef<typeof import('@dcloudio/uni-app')['onBackPress']>
-    readonly onBeforeMount: UnwrapRef<typeof import('vue')['onBeforeMount']>
-    readonly onBeforeUnmount: UnwrapRef<typeof import('vue')['onBeforeUnmount']>
-    readonly onBeforeUpdate: UnwrapRef<typeof import('vue')['onBeforeUpdate']>
-    readonly onDeactivated: UnwrapRef<typeof import('vue')['onDeactivated']>
-    readonly onError: UnwrapRef<typeof import('@dcloudio/uni-app')['onError']>
-    readonly onErrorCaptured: UnwrapRef<typeof import('vue')['onErrorCaptured']>
-    readonly onHide: UnwrapRef<typeof import('@dcloudio/uni-app')['onHide']>
-    readonly onLaunch: UnwrapRef<typeof import('@dcloudio/uni-app')['onLaunch']>
-    readonly onLoad: UnwrapRef<typeof import('@dcloudio/uni-app')['onLoad']>
-    readonly onMounted: UnwrapRef<typeof import('vue')['onMounted']>
-    readonly onNavigationBarButtonTap: UnwrapRef<typeof import('@dcloudio/uni-app')['onNavigationBarButtonTap']>
-    readonly onNavigationBarSearchInputChanged: UnwrapRef<typeof import('@dcloudio/uni-app')['onNavigationBarSearchInputChanged']>
-    readonly onNavigationBarSearchInputClicked: UnwrapRef<typeof import('@dcloudio/uni-app')['onNavigationBarSearchInputClicked']>
-    readonly onNavigationBarSearchInputConfirmed: UnwrapRef<typeof import('@dcloudio/uni-app')['onNavigationBarSearchInputConfirmed']>
-    readonly onNavigationBarSearchInputFocusChanged: UnwrapRef<typeof import('@dcloudio/uni-app')['onNavigationBarSearchInputFocusChanged']>
-    readonly onPageNotFound: UnwrapRef<typeof import('@dcloudio/uni-app')['onPageNotFound']>
-    readonly onPageScroll: UnwrapRef<typeof import('@dcloudio/uni-app')['onPageScroll']>
-    readonly onPullDownRefresh: UnwrapRef<typeof import('@dcloudio/uni-app')['onPullDownRefresh']>
-    readonly onReachBottom: UnwrapRef<typeof import('@dcloudio/uni-app')['onReachBottom']>
-    readonly onReady: UnwrapRef<typeof import('@dcloudio/uni-app')['onReady']>
-    readonly onRenderTracked: UnwrapRef<typeof import('vue')['onRenderTracked']>
-    readonly onRenderTriggered: UnwrapRef<typeof import('vue')['onRenderTriggered']>
-    readonly onResize: UnwrapRef<typeof import('@dcloudio/uni-app')['onResize']>
-    readonly onScopeDispose: UnwrapRef<typeof import('vue')['onScopeDispose']>
-    readonly onServerPrefetch: UnwrapRef<typeof import('vue')['onServerPrefetch']>
-    readonly onShareAppMessage: UnwrapRef<typeof import('@dcloudio/uni-app')['onShareAppMessage']>
-    readonly onShareTimeline: UnwrapRef<typeof import('@dcloudio/uni-app')['onShareTimeline']>
-    readonly onShow: UnwrapRef<typeof import('@dcloudio/uni-app')['onShow']>
-    readonly onTabItemTap: UnwrapRef<typeof import('@dcloudio/uni-app')['onTabItemTap']>
-    readonly onThemeChange: UnwrapRef<typeof import('@dcloudio/uni-app')['onThemeChange']>
-    readonly onUnhandledRejection: UnwrapRef<typeof import('@dcloudio/uni-app')['onUnhandledRejection']>
-    readonly onUnload: UnwrapRef<typeof import('@dcloudio/uni-app')['onUnload']>
-    readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
-    readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
-    readonly provide: UnwrapRef<typeof import('vue')['provide']>
-    readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
-    readonly readonly: UnwrapRef<typeof import('vue')['readonly']>
-    readonly ref: UnwrapRef<typeof import('vue')['ref']>
-    readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
-    readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
-    readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']>
-    readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']>
-    readonly toRaw: UnwrapRef<typeof import('vue')['toRaw']>
-    readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
-    readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
-    readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
-    readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
-    readonly unref: UnwrapRef<typeof import('vue')['unref']>
-    readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
-    readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
-    readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
-    readonly useImgPath: UnwrapRef<typeof import('../hooks/useImgPath')['useImgPath']>
-    readonly useRequest: UnwrapRef<typeof import('../hooks/useRequest')['default']>
-    readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
-    readonly useTelegramBackButton: UnwrapRef<typeof import('../hooks/useTelegramBackButton')['useTelegramBackButton']>
+    readonly useTemplateRef: UnwrapRef<typeof import('vue')['useTemplateRef']>
     readonly useUpload: UnwrapRef<typeof import('../hooks/useUpload')['default']>
     readonly watch: UnwrapRef<typeof import('vue')['watch']>
     readonly watchEffect: UnwrapRef<typeof import('vue')['watchEffect']>

+ 1 - 1
src/utils/http.ts

@@ -9,7 +9,7 @@ export const http = <T>(options: CustomRequestOptions) => {
     uni.request({
       ...options,
       header: {
-        Token: uni.getStorageSync('token') || '',
+        Authorization: `Bearer ${uni.getStorageSync('token')}` || '',
         lang: uni.getStorageSync('lang') || 'en',
       },
       timeout: 50000,

+ 1 - 1
src/utils/solana.ts

@@ -13,7 +13,7 @@ export class SolanaService {
   public wallet = ref(null)
 
   constructor() {
-    this.connection = new Connection('https://api.devnet.solana.com', 'confirmed')
+    this.connection = new Connection('https://app.devnet.solana.com', 'confirmed')
   }
 
   async createWallet(): Promise<string> {