refactor(store): 优化 Pinia store 定义方式

将所有 store 模块从旧版 defineStore({ id: 'xxx', ... }) 形式
改为新版 defineStore('xxx', { ... }) 形式,符合 Pinia 推荐的最佳实践。

涉及模块:
  - app.js
  - cart.js
  - modal.js
  - sys.js
  - user.js
pull/178/head
aiyvyang 2026-05-09 15:36:10 +08:00
parent b6b0ca3dbd
commit 43d2d02e8e
5 changed files with 5 additions and 10 deletions

View File

@ -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: {

View File

@ -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: [], // 已选列表

View File

@ -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, // 分享弹框

View File

@ -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', // 明亮模式、暗黑模式(暂未支持)

View File

@ -36,8 +36,7 @@ const defaultNumData = {
},
};
const user = defineStore({
id: 'user',
const user = defineStore('user', {
state: () => ({
userInfo: clone(defaultUserInfo), // 用户信息
userWallet: clone(defaultUserWallet), // 用户钱包信息