From 43d2d02e8e9b9bbbd5cef155f7172827e12726c2 Mon Sep 17 00:00:00 2001 From: aiyvyang Date: Sat, 9 May 2026 15:36:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor(store):=20=E4=BC=98=E5=8C=96=20Pinia?= =?UTF-8?q?=20store=20=E5=AE=9A=E4=B9=89=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将所有 store 模块从旧版 defineStore({ id: 'xxx', ... }) 形式 改为新版 defineStore('xxx', { ... }) 形式,符合 Pinia 推荐的最佳实践。 涉及模块: - app.js - cart.js - modal.js - sys.js - user.js --- sheep/store/app.js | 3 +-- sheep/store/cart.js | 3 +-- sheep/store/modal.js | 3 +-- sheep/store/sys.js | 3 +-- sheep/store/user.js | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/sheep/store/app.js b/sheep/store/app.js index 262adde9..969738c8 100644 --- a/sheep/store/app.js +++ b/sheep/store/app.js @@ -8,8 +8,7 @@ import user from './user'; import sys from './sys'; import { baseUrl, h5Url } from '@/sheep/config'; -const app = defineStore({ - id: 'app', +const app = defineStore('app', { state: () => ({ paramsForTabbar: {}, // 为全局tabbar跳转传参用。原因是 tabbar 无法传参,只能通过全局状态传递 info: { diff --git a/sheep/store/cart.js b/sheep/store/cart.js index ab96a2bc..748fb554 100644 --- a/sheep/store/cart.js +++ b/sheep/store/cart.js @@ -1,8 +1,7 @@ import { defineStore } from 'pinia'; import CartApi from '@/sheep/api/trade/cart'; -const cart = defineStore({ - id: 'cart', +const cart = defineStore('cart', { state: () => ({ list: [], // 购物车列表(invalidList + validList) selectedIds: [], // 已选列表 diff --git a/sheep/store/modal.js b/sheep/store/modal.js index bde9e0a3..c1764386 100644 --- a/sheep/store/modal.js +++ b/sheep/store/modal.js @@ -1,7 +1,6 @@ import { defineStore } from 'pinia'; -const modal = defineStore({ - id: 'modal', +const modal = defineStore('modal', { state: () => ({ auth: '', // 授权弹框 accountLogin|smsLogin|resetPassword|changeMobile|changePassword|changeUsername share: false, // 分享弹框 diff --git a/sheep/store/sys.js b/sheep/store/sys.js index f7151e0a..915b8f88 100644 --- a/sheep/store/sys.js +++ b/sheep/store/sys.js @@ -1,8 +1,7 @@ import { defineStore } from 'pinia'; import app from './app'; -const sys = defineStore({ - id: 'sys', +const sys = defineStore('sys', { state: () => ({ theme: '', // 主题, mode: 'light', // 明亮模式、暗黑模式(暂未支持) diff --git a/sheep/store/user.js b/sheep/store/user.js index fceb584f..d2be5175 100644 --- a/sheep/store/user.js +++ b/sheep/store/user.js @@ -36,8 +36,7 @@ const defaultNumData = { }, }; -const user = defineStore({ - id: 'user', +const user = defineStore('user', { state: () => ({ userInfo: clone(defaultUserInfo), // 用户信息 userWallet: clone(defaultUserWallet), // 用户钱包信息