congzc 1 year ago
parent
commit
c33d92466b
4 changed files with 95 additions and 5 deletions
  1. +1
    -1
      src/pages/uploadPhoto/uploadPhoto.vue
  2. +26
    -4
      src/store/index.js
  3. +58
    -0
      src/store/modules/userInfo copy.js
  4. +10
    -0
      src/store/modules/userInfo.js

+ 1
- 1
src/pages/uploadPhoto/uploadPhoto.vue View File

@@ -312,7 +312,7 @@ onLoad((options) => {
userInfoModulesPinia.openId = res2.data.openId;
if (res2.data.token) {
userInfoModulesPinia.token = res2.data.token;
uni.setStorageSync("token", userInfoModulesPinia.token);
// uni.setStorageSync("token", userInfoModulesPinia.token);
console.log(userInfoModulesPinia.openId, "获取openid");
// 获取头像和金币
const res3 = await findImageApi();


+ 26
- 4
src/store/index.js View File

@@ -1,10 +1,32 @@
// import { createPinia } 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 = 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 };

+ 58
- 0
src/store/modules/userInfo copy.js View File

@@ -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
// }
// },

);

+ 10
- 0
src/store/modules/userInfo.js View File

@@ -42,7 +42,17 @@ export const userInfoModules = defineStore("userInfoStore", () => {
// }
return { userInfo, openId, token, myAvatar, myGlod, platForm, hostSystem };
},
{
// persist: true
unistorage: true,
}
// persist: {
// storage: {
// // getItem: uni.getStorageSync,
// token: uni.getStorageSync,
// setItem: uni.setStorageSync
// }
// },
);

Loading…
Cancel
Save