refactor(store): 将localStorage替换为uni存储API
feat(login): 添加微信登录功能并获取openId fix(env): 关闭生产环境console删除功能 style(me): 移除未使用的hover和active样式 refactor(token): 修改getToken返回测试值
This commit is contained in:
parent
75de18ccfc
commit
70bf8121b1
|
|
@ -1,7 +1,7 @@
|
|||
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
|
||||
NODE_ENV = 'production'
|
||||
# 是否去除console 和 debugger
|
||||
VITE_DELETE_CONSOLE = true
|
||||
VITE_DELETE_CONSOLE = false
|
||||
# 是否开启sourcemap
|
||||
VITE_SHOW_SOURCEMAP = false
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,13 @@ import {isPageTabbar} from "@/tabbar/store";
|
|||
|
||||
import {tabbarList} from "@/tabbar/config";
|
||||
import { useWxStore } from './pinia/stores/wx';
|
||||
import { mpCodeToOpenId } from './api/users';
|
||||
const redirectUrl = ref('')
|
||||
|
||||
const wxStore = useWxStore();
|
||||
|
||||
onLoad((options) => {
|
||||
console.log('login options: ', options)
|
||||
onLoad(async (options) => {
|
||||
console.log('login options: ', options);
|
||||
if (options.redirect) {
|
||||
redirectUrl.value = ensureDecodeURIComponent(options.redirect)
|
||||
}
|
||||
|
|
@ -28,7 +29,6 @@ onLaunch( (options) => {
|
|||
})
|
||||
|
||||
onMounted(async () => {
|
||||
await wxStore.fakeQyLogin()
|
||||
})
|
||||
|
||||
onShow((options) => {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { useCartStore } from '@/pinia/stores/cart'
|
|||
import { getShopListApi } from '@/api/shop'
|
||||
import type { ShopEntity } from '@/api/shop/types'
|
||||
import ProductContainer from './components/product-container.vue';
|
||||
import { mpCodeToOpenId } from '@/api/users'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
|
|
@ -25,6 +26,18 @@ const shopId = ref<number>(0)
|
|||
|
||||
// 页面加载
|
||||
onMounted(async () => {
|
||||
await wxStore.fakeQyLogin();
|
||||
uni.login({
|
||||
provider: 'weixin', //使用微信登录
|
||||
success: function (loginRes) {
|
||||
mpCodeToOpenId(loginRes.code).then((openId) => {
|
||||
console.log('openId:', openId)
|
||||
}).catch((e) => {
|
||||
console.error('mpCodeToOpenId error:', e)
|
||||
})
|
||||
},
|
||||
});
|
||||
|
||||
if (showShopList.value) {
|
||||
try {
|
||||
// 等待 handleWxCallback 完成
|
||||
|
|
|
|||
|
|
@ -378,14 +378,6 @@ onMounted(() => {
|
|||
transition: left 0.5s ease;
|
||||
}
|
||||
|
||||
&:hover::before {
|
||||
left: 100%;
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(2px);
|
||||
box-shadow: 0 2px 8px rgba(64, 158, 255, 0.4);
|
||||
}
|
||||
|
||||
wd-icon {
|
||||
position: relative;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { pinia } from "@/pinia"
|
||||
import { LoginData } from "@/api/ab98/types"
|
||||
import { defineStore } from "pinia"
|
||||
import { ref } from "vue"
|
||||
|
||||
// 本地存储键名常量
|
||||
const STORAGE_KEYS = {
|
||||
|
|
@ -20,24 +21,24 @@ const STORAGE_KEYS = {
|
|||
*/
|
||||
export const useAb98UserStore = defineStore("ab98User", () => {
|
||||
// 用户面部图像URL
|
||||
const storedFace = localStorage.getItem(STORAGE_KEYS.FACE)
|
||||
const storedFace = uni.getStorageSync(STORAGE_KEYS.FACE)
|
||||
const face_img = ref<string>(storedFace ? decodeURIComponent(storedFace) : '')
|
||||
// 用户性别(男/女)
|
||||
const storedSex = localStorage.getItem(STORAGE_KEYS.SEX)
|
||||
const storedSex = uni.getStorageSync(STORAGE_KEYS.SEX)
|
||||
const sex = ref<string>(storedSex ? decodeURIComponent(storedSex) : '')
|
||||
// 用户真实姓名
|
||||
const storedName = localStorage.getItem(STORAGE_KEYS.NAME)
|
||||
const storedName = uni.getStorageSync(STORAGE_KEYS.NAME)
|
||||
const name = ref<string>(storedName ? decodeURIComponent(storedName) : '')
|
||||
// AB98系统用户唯一标识
|
||||
const storedUserId = localStorage.getItem(STORAGE_KEYS.USERID)
|
||||
const storedUserId = uni.getStorageSync(STORAGE_KEYS.USERID)
|
||||
const userid = ref<string>(storedUserId ? decodeURIComponent(storedUserId) : "")
|
||||
// 是否已完成注册流程
|
||||
const registered = ref<boolean>(JSON.parse(localStorage.getItem(STORAGE_KEYS.REGISTERED) || "false"))
|
||||
const registered = ref<boolean>(JSON.parse(uni.getStorageSync(STORAGE_KEYS.REGISTERED) || "false"))
|
||||
// 用户绑定手机号
|
||||
const storedTel = localStorage.getItem(STORAGE_KEYS.TEL)
|
||||
const storedTel = uni.getStorageSync(STORAGE_KEYS.TEL)
|
||||
const tel = ref<string>(storedTel ? decodeURIComponent(storedTel) : "")
|
||||
// 用户认证令牌
|
||||
const storedToken = localStorage.getItem(STORAGE_KEYS.TOKEN)
|
||||
const storedToken = uni.getStorageSync(STORAGE_KEYS.TOKEN)
|
||||
const token = ref<string>(storedToken ? decodeURIComponent(storedToken) : "");
|
||||
|
||||
const tokenLogin = ref<string>("");
|
||||
|
|
@ -45,7 +46,7 @@ export const useAb98UserStore = defineStore("ab98User", () => {
|
|||
const loginCode = '1'; // 默认验证码
|
||||
// 用户登录状态
|
||||
const isLogin = ref<boolean>(false);
|
||||
const storedLoginCode = localStorage.getItem(STORAGE_KEYS.LOGIN_CODE);
|
||||
const storedLoginCode = uni.getStorageSync(STORAGE_KEYS.LOGIN_CODE);
|
||||
isLogin.value = tel.value && storedLoginCode === String(loginCode) ? true : false;
|
||||
|
||||
/**
|
||||
|
|
@ -54,18 +55,18 @@ export const useAb98UserStore = defineStore("ab98User", () => {
|
|||
*/
|
||||
const setUserInfo = (data: LoginData) => {
|
||||
face_img.value = data.face_img
|
||||
localStorage.setItem(STORAGE_KEYS.FACE, encodeURIComponent(data.face_img))
|
||||
uni.setStorageSync(STORAGE_KEYS.FACE, encodeURIComponent(data.face_img))
|
||||
sex.value = data.sex
|
||||
localStorage.setItem(STORAGE_KEYS.SEX, encodeURIComponent(data.sex))
|
||||
uni.setStorageSync(STORAGE_KEYS.SEX, encodeURIComponent(data.sex))
|
||||
name.value = data.name
|
||||
localStorage.setItem(STORAGE_KEYS.NAME, encodeURIComponent(data.name))
|
||||
uni.setStorageSync(STORAGE_KEYS.NAME, encodeURIComponent(data.name))
|
||||
userid.value = data.userid
|
||||
localStorage.setItem(STORAGE_KEYS.USERID, encodeURIComponent(data.userid))
|
||||
uni.setStorageSync(STORAGE_KEYS.USERID, encodeURIComponent(data.userid))
|
||||
registered.value = data.registered
|
||||
localStorage.setItem(STORAGE_KEYS.REGISTERED, JSON.stringify(data.registered))
|
||||
uni.setStorageSync(STORAGE_KEYS.REGISTERED, JSON.stringify(data.registered))
|
||||
tel.value = data.tel
|
||||
localStorage.setItem(STORAGE_KEYS.TEL, encodeURIComponent(data.tel))
|
||||
localStorage.setItem(STORAGE_KEYS.LOGIN_CODE, encodeURIComponent(loginCode))
|
||||
uni.setStorageSync(STORAGE_KEYS.TEL, encodeURIComponent(data.tel))
|
||||
uni.setStorageSync(STORAGE_KEYS.LOGIN_CODE, encodeURIComponent(loginCode))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -74,19 +75,19 @@ export const useAb98UserStore = defineStore("ab98User", () => {
|
|||
*/
|
||||
const clearUserInfo = () => {
|
||||
face_img.value = ""
|
||||
localStorage.removeItem(STORAGE_KEYS.FACE)
|
||||
uni.removeStorageSync(STORAGE_KEYS.FACE)
|
||||
sex.value = ""
|
||||
localStorage.removeItem(STORAGE_KEYS.SEX)
|
||||
uni.removeStorageSync(STORAGE_KEYS.SEX)
|
||||
name.value = ""
|
||||
localStorage.removeItem(STORAGE_KEYS.NAME)
|
||||
uni.removeStorageSync(STORAGE_KEYS.NAME)
|
||||
userid.value = ""
|
||||
localStorage.removeItem(STORAGE_KEYS.USERID)
|
||||
uni.removeStorageSync(STORAGE_KEYS.USERID)
|
||||
registered.value = false
|
||||
localStorage.removeItem(STORAGE_KEYS.REGISTERED)
|
||||
uni.removeStorageSync(STORAGE_KEYS.REGISTERED)
|
||||
tel.value = ""
|
||||
localStorage.removeItem(STORAGE_KEYS.TEL)
|
||||
localStorage.removeItem(STORAGE_KEYS.TOKEN)
|
||||
localStorage.removeItem(STORAGE_KEYS.LOGIN_CODE)
|
||||
uni.removeStorageSync(STORAGE_KEYS.TEL)
|
||||
uni.removeStorageSync(STORAGE_KEYS.TOKEN)
|
||||
uni.removeStorageSync(STORAGE_KEYS.LOGIN_CODE)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -94,12 +95,12 @@ export const useAb98UserStore = defineStore("ab98User", () => {
|
|||
* @param value - JWT格式的认证令牌
|
||||
*/
|
||||
const setToken = (value: string) => {
|
||||
localStorage.setItem(STORAGE_KEYS.TOKEN, encodeURIComponent(value))
|
||||
uni.setStorageSync(STORAGE_KEYS.TOKEN, encodeURIComponent(value))
|
||||
token.value = value
|
||||
}
|
||||
|
||||
const setTel = (value: string) => {
|
||||
localStorage.setItem(STORAGE_KEYS.TEL, btoa(value))
|
||||
uni.setStorageSync(STORAGE_KEYS.TEL, btoa(value))
|
||||
tel.value = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { TOKEN_CACHE_NAME,TOKEN_CACHE_NAME_UNIFY } from '@/config/setting';
|
|||
* 获取缓存的token
|
||||
*/
|
||||
export function getToken(): string | null {
|
||||
return null;
|
||||
return 'token';
|
||||
const token = uni.getStorageSync(TOKEN_CACHE_NAME)
|
||||
return token;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue