mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-11-13 04:18:55 +08:00
refactor: 四端完成 Options API → script setup + vuex → pinia 迁移
- buyer(95) / seller(169) / im(53) / manager(280) 共 597 个组件全部从 Options API 转换为 <script setup> - 四端 vuex 全部移除,状态管理统一迁移至 pinia 4(stores/ 目录) - util.js 等基础设施去除 vm 首参依赖;全局属性($Message/$filters 等)在 script 内改为具名导入 - 被外部 ref 访问的公共组件均已补齐 defineExpose(清单见各端 MIGRATION-VUE3.md) - 各端 eslint 启用 vue/component-api-style 防止新代码回退 Options API - 四端 yarn build 全部通过;迁移约定与注意事项已更新至各端 MIGRATION-VUE3.md
This commit is contained in:
162
seller/src/stores/app.js
Normal file
162
seller/src/stores/app.js
Normal file
@@ -0,0 +1,162 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { otherRouter } from "@/router/router";
|
||||
|
||||
// 原 vuex app 模块的 pinia 版本;mutation 全部转为同名 action
|
||||
// 例外:storeOpenedList mutation 与 state 同名,改名 updateOpenedList;
|
||||
// clearOtherTags 原接收组件实例 vm,改为直接接收当前路由名 currentName
|
||||
export const useAppStore = defineStore("app", {
|
||||
state: () => ({
|
||||
shipTemplates: "",
|
||||
regions: [],
|
||||
styleStore: "",
|
||||
loading: false,
|
||||
added: false,
|
||||
navList: [],
|
||||
currNav: "",
|
||||
currNavTitle: "",
|
||||
cachePage: [],
|
||||
lang: "",
|
||||
isFullScreen: false,
|
||||
openedSubmenuArr: [],
|
||||
menuTheme: "dark",
|
||||
themeColor: "",
|
||||
storeOpenedList: [
|
||||
{
|
||||
title: "首页",
|
||||
path: "",
|
||||
name: "home_index",
|
||||
},
|
||||
],
|
||||
currentPageName: "",
|
||||
currentPath: [
|
||||
{
|
||||
title: "首页",
|
||||
path: "",
|
||||
name: "home_index",
|
||||
},
|
||||
],
|
||||
menuList: [],
|
||||
routers: [otherRouter],
|
||||
tagsList: [...otherRouter.children],
|
||||
messageCount: 0,
|
||||
dontCache: ["test", "test"],
|
||||
refMenu: "",
|
||||
}),
|
||||
actions: {
|
||||
childrenMenu(v) {
|
||||
this.refMenu = v;
|
||||
},
|
||||
updateAppRouter(routes) {
|
||||
this.routers.push(...routes);
|
||||
},
|
||||
updateDefaultRouter() {},
|
||||
setLoading(v) {
|
||||
this.loading = v;
|
||||
},
|
||||
setAdded(v) {
|
||||
this.added = v;
|
||||
},
|
||||
setNavList(list) {
|
||||
this.navList = list;
|
||||
},
|
||||
setCurrNav(v) {
|
||||
this.currNav = v;
|
||||
},
|
||||
setCurrNavTitle(v) {
|
||||
this.currNavTitle = v;
|
||||
},
|
||||
setTagsList(list) {
|
||||
this.tagsList.push(...list);
|
||||
},
|
||||
updateMenulist(routes) {
|
||||
this.menuList = routes;
|
||||
},
|
||||
addOpenSubmenu(name) {
|
||||
if (name.length && this.openedSubmenuArr.indexOf(name) === -1) {
|
||||
this.openedSubmenuArr.push(name);
|
||||
}
|
||||
},
|
||||
closePage(name) {
|
||||
this.cachePage.forEach((item, index) => {
|
||||
if (item == name) {
|
||||
this.cachePage.splice(index, 1);
|
||||
}
|
||||
});
|
||||
localStorage.cachePage = JSON.stringify(this.cachePage);
|
||||
},
|
||||
initCachepage() {
|
||||
if (localStorage.cachePage) {
|
||||
this.cachePage = JSON.parse(localStorage.cachePage);
|
||||
}
|
||||
},
|
||||
removeTag(name) {
|
||||
this.storeOpenedList.map((item, index) => {
|
||||
if (item.name == name) {
|
||||
this.storeOpenedList.splice(index, 1);
|
||||
}
|
||||
});
|
||||
},
|
||||
updateOpenedList(get) {
|
||||
let openedPage = this.storeOpenedList[get.index];
|
||||
if (get.argu) openedPage.argu = get.argu;
|
||||
if (get.query) openedPage.query = get.query;
|
||||
this.storeOpenedList.splice(get.index, 1, openedPage);
|
||||
localStorage.storeOpenedList = JSON.stringify(this.storeOpenedList);
|
||||
},
|
||||
clearAllTags() {
|
||||
this.storeOpenedList.splice(1);
|
||||
this.cachePage.length = 0;
|
||||
localStorage.cachePage = "";
|
||||
localStorage.storeOpenedList = JSON.stringify(this.storeOpenedList);
|
||||
},
|
||||
clearOtherTags(currentName) {
|
||||
let currentIndex = 0;
|
||||
this.storeOpenedList.forEach((item, index) => {
|
||||
if (item.name == currentName) {
|
||||
currentIndex = index;
|
||||
}
|
||||
});
|
||||
if (currentIndex == 0) {
|
||||
this.storeOpenedList.splice(1);
|
||||
} else {
|
||||
this.storeOpenedList.splice(currentIndex + 1);
|
||||
this.storeOpenedList.splice(1, currentIndex - 1);
|
||||
}
|
||||
this.cachePage = this.cachePage.filter((item) => item == currentName);
|
||||
localStorage.cachePage = JSON.stringify(this.cachePage);
|
||||
localStorage.storeOpenedList = JSON.stringify(this.storeOpenedList);
|
||||
},
|
||||
setOpenedList() {
|
||||
this.storeOpenedList = localStorage.storeOpenedList
|
||||
? JSON.parse(localStorage.storeOpenedList)
|
||||
: [otherRouter.children[0]];
|
||||
},
|
||||
setCurrentPath(pathArr) {
|
||||
this.currentPath = pathArr;
|
||||
},
|
||||
setCurrentPageName(name) {
|
||||
this.currentPageName = name;
|
||||
},
|
||||
setAvatarPath(path) {
|
||||
localStorage.avatorImgPath = path;
|
||||
},
|
||||
switchLang(lang) {
|
||||
this.lang = lang;
|
||||
localStorage.lang = lang;
|
||||
},
|
||||
clearOpenedSubmenu() {
|
||||
this.openedSubmenuArr.length = 0;
|
||||
},
|
||||
setMessageCount(count) {
|
||||
this.messageCount = count;
|
||||
},
|
||||
increateTag(tagObj) {
|
||||
if (this.dontCache.indexOf(tagObj.name) < 0) {
|
||||
this.cachePage.push(tagObj.name);
|
||||
localStorage.cachePage = JSON.stringify(this.cachePage);
|
||||
}
|
||||
this.storeOpenedList.push(tagObj);
|
||||
localStorage.storeOpenedList = JSON.stringify(this.storeOpenedList);
|
||||
},
|
||||
},
|
||||
});
|
||||
26
seller/src/stores/dict.js
Normal file
26
seller/src/stores/dict.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
export const useDictStore = defineStore("dict", {
|
||||
state: () => ({
|
||||
// 经常需要读取的数据字典
|
||||
sex: [],
|
||||
messageType: [],
|
||||
priority: [],
|
||||
leaveType: [],
|
||||
}),
|
||||
actions: {
|
||||
// 设置值的改变方法
|
||||
setSex(list) {
|
||||
this.sex = list;
|
||||
},
|
||||
setMessageType(list) {
|
||||
this.messageType = list;
|
||||
},
|
||||
setPriority(list) {
|
||||
this.priority = list;
|
||||
},
|
||||
setLeaveType(list) {
|
||||
this.leaveType = list;
|
||||
},
|
||||
},
|
||||
});
|
||||
17
seller/src/stores/setting.js
Normal file
17
seller/src/stores/setting.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { defineStore } from "pinia";
|
||||
import config from "@/config/index";
|
||||
|
||||
const { setting } = config;
|
||||
|
||||
const localSetting = window.localStorage.getItem("setting");
|
||||
|
||||
export const useSettingStore = defineStore("setting", {
|
||||
state: () => ({
|
||||
setting: localSetting ? JSON.parse(localSetting) : setting,
|
||||
}),
|
||||
actions: {
|
||||
updateSetting(data) {
|
||||
this.setting = data;
|
||||
},
|
||||
},
|
||||
});
|
||||
25
seller/src/stores/user.js
Normal file
25
seller/src/stores/user.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { defineStore } from "pinia";
|
||||
import Cookies from "js-cookie";
|
||||
import { removeStore } from "@/libs/storage";
|
||||
|
||||
// 退出登录时需要清除的会话/店铺数据
|
||||
// 保留 uuid(设备标识)、setting(主题)、currNav、category(缓存)、saveLogin(记住登录状态)等无关键
|
||||
const LOGOUT_KEYS = [
|
||||
"accessToken",
|
||||
"refreshToken",
|
||||
"menuData",
|
||||
"seller_expiration_time",
|
||||
"sellersiteName",
|
||||
"sellerlogoImg",
|
||||
"sellerIconImg",
|
||||
];
|
||||
|
||||
export const useUserStore = defineStore("user", {
|
||||
actions: {
|
||||
logout() {
|
||||
Cookies.remove("userInfoSeller");
|
||||
// 精确清除会话相关键,不再 localStorage.clear() 误删无关数据
|
||||
LOGOUT_KEYS.forEach((key) => removeStore(key));
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user