| @@ -312,7 +312,7 @@ onLoad((options) => { | |||||
| userInfoModulesPinia.openId = res2.data.openId; | userInfoModulesPinia.openId = res2.data.openId; | ||||
| if (res2.data.token) { | if (res2.data.token) { | ||||
| userInfoModulesPinia.token = res2.data.token; | userInfoModulesPinia.token = res2.data.token; | ||||
| uni.setStorageSync("token", userInfoModulesPinia.token); | |||||
| // uni.setStorageSync("token", userInfoModulesPinia.token); | |||||
| console.log(userInfoModulesPinia.openId, "获取openid"); | console.log(userInfoModulesPinia.openId, "获取openid"); | ||||
| // 获取头像和金币 | // 获取头像和金币 | ||||
| const res3 = await findImageApi(); | const res3 = await findImageApi(); | ||||
| @@ -1,10 +1,32 @@ | |||||
| // import { createPinia } from 'pinia' | // import { createPinia } from 'pinia' | ||||
| import * as Pinia from 'pinia' | import * as Pinia from 'pinia' | ||||
| // import { createUnistorage } from 'pinia-plugin-unistorage' | |||||
| import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' | |||||
| import { createUnistorage } from 'pinia-plugin-unistorage' | |||||
| // import { createPersistedState } from 'pinia-plugin-persistedstate' | |||||
| // const store = createPinia(); | // const store = createPinia(); | ||||
| const store = Pinia.createPinia() | const store = Pinia.createPinia() | ||||
| // store.use(createUnistorage()) | |||||
| Pinia.use(piniaPluginPersistedstate) | |||||
| store.use(createUnistorage()) | |||||
| // store.use(createUnistorage( | |||||
| // { | |||||
| // storage: { | |||||
| // getItem: (key) => { | |||||
| // return uni.getStorageSync(key); | |||||
| // }, | |||||
| // setItem: (key, value) => { | |||||
| // uni.setStorageSync(key, value); | |||||
| // } | |||||
| // }, | |||||
| // } | |||||
| // )) | |||||
| // store.use(createPersistedState({ | |||||
| // storage: { | |||||
| // getItem: (key) => { | |||||
| // return uni.getStorageSync(key); | |||||
| // }, | |||||
| // setItem: (key, value) => { | |||||
| // uni.setStorageSync(key, value); | |||||
| // } | |||||
| // }, | |||||
| // })); | |||||
| export { store, Pinia }; | export { store, Pinia }; | ||||
| @@ -0,0 +1,58 @@ | |||||
| import { defineStore } from "pinia"; | |||||
| import { ref, reactive } from "vue"; | |||||
| // import { request } from "../../utils/request" | |||||
| /** | |||||
| * @description:用户信息持久化数据 | |||||
| */ | |||||
| export const userInfoModules = defineStore("userInfoStore", () => { | |||||
| // state | |||||
| const userInfo = ref(null) | |||||
| const openId = ref(null) | |||||
| const token = ref(null) | |||||
| const myAvatar = ref('') | |||||
| const myGlod = ref(0) | |||||
| /** | |||||
| * @description:依托平台:(web、mp-weixin、mp-toutiao) | |||||
| * @example 平台名:"web-H5",枚举值:1 | |||||
| * @example 平台名:"mp-weixin",枚举值:2 | |||||
| * @example 平台名:"mp-toutiao",枚举值:3 | |||||
| */ | |||||
| const platForm = ref(null) | |||||
| /** | |||||
| * @description:宿主系统:(windows、ios、android、mac、linux) | |||||
| * @example 系统名:windows,值:1 | |||||
| * @example 系统名:ios,值:2 | |||||
| * @example 系统名:android,值:3 | |||||
| * @example 系统名:mac,值:4 | |||||
| * @example 系统名:linux,值:5 | |||||
| */ | |||||
| const hostSystem = ref(null) | |||||
| // 登录获取用户信息 | |||||
| // async function getMyAvatar() { | |||||
| // } | |||||
| // 退出清除用户信息 | |||||
| // async function getMyGlod(params) { | |||||
| // } | |||||
| return { userInfo, openId, token, myAvatar, myGlod, platForm, hostSystem }; | |||||
| }, | |||||
| { | |||||
| // persist: true | |||||
| unistorage: true, | |||||
| } | |||||
| // persist: { | |||||
| // storage: { | |||||
| // // getItem: uni.getStorageSync, | |||||
| // token: uni.getStorageSync, | |||||
| // setItem: uni.setStorageSync | |||||
| // } | |||||
| // }, | |||||
| ); | |||||
| @@ -42,7 +42,17 @@ export const userInfoModules = defineStore("userInfoStore", () => { | |||||
| // } | // } | ||||
| return { userInfo, openId, token, myAvatar, myGlod, platForm, hostSystem }; | return { userInfo, openId, token, myAvatar, myGlod, platForm, hostSystem }; | ||||
| }, | }, | ||||
| { | { | ||||
| // persist: true | |||||
| unistorage: true, | unistorage: true, | ||||
| } | } | ||||
| // persist: { | |||||
| // storage: { | |||||
| // // getItem: uni.getStorageSync, | |||||
| // token: uni.getStorageSync, | |||||
| // setItem: uni.setStorageSync | |||||
| // } | |||||
| // }, | |||||
| ); | ); | ||||