From c3b677f5391164504ddec23cfaec635974e4f38a Mon Sep 17 00:00:00 2001 From: Edan's Win11 <961150665@qq.com> Date: Tue, 3 Jun 2025 21:27:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20pinia=20=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sau_frontend/src/assets/vue.svg | 1 + sau_frontend/src/components/helloworld.vue | 66 +++++++++++++++++++++ sau_frontend/src/stores/account.js | 63 ++++++++++++++++++++ sau_frontend/src/stores/app.js | 69 ++++++++++++++++++++++ sau_frontend/src/stores/index.js | 9 +++ sau_frontend/src/stores/user.js | 31 ++++++++++ 6 files changed, 239 insertions(+) create mode 100644 sau_frontend/src/assets/vue.svg create mode 100644 sau_frontend/src/components/helloworld.vue create mode 100644 sau_frontend/src/stores/account.js create mode 100644 sau_frontend/src/stores/app.js create mode 100644 sau_frontend/src/stores/index.js create mode 100644 sau_frontend/src/stores/user.js diff --git a/sau_frontend/src/assets/vue.svg b/sau_frontend/src/assets/vue.svg new file mode 100644 index 0000000..770e9d3 --- /dev/null +++ b/sau_frontend/src/assets/vue.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sau_frontend/src/components/helloworld.vue b/sau_frontend/src/components/helloworld.vue new file mode 100644 index 0000000..c3c53b4 --- /dev/null +++ b/sau_frontend/src/components/helloworld.vue @@ -0,0 +1,66 @@ + + + + + diff --git a/sau_frontend/src/stores/account.js b/sau_frontend/src/stores/account.js new file mode 100644 index 0000000..1c33d84 --- /dev/null +++ b/sau_frontend/src/stores/account.js @@ -0,0 +1,63 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +export const useAccountStore = defineStore('account', () => { + // 存储所有账号信息 + const accounts = ref([]) + + // 平台类型映射 + const platformTypes = { + 1: '小红书', + 2: '视频号', + 3: '抖音', + 4: '快手' + } + + // 设置账号列表 + const setAccounts = (accountsData) => { + // 转换后端返回的数据格式为前端使用的格式 + accounts.value = accountsData.map(item => { + return { + id: item[0], + type: item[1], + filePath: item[2], + name: item[3], + status: item[4] === 1 ? '正常' : '异常', + platform: platformTypes[item[1]] || '未知', + avatar: '/vite.svg' // 默认使用vite.svg作为头像 + } + }) + } + + // 添加账号 + const addAccount = (account) => { + accounts.value.push(account) + } + + // 更新账号 + const updateAccount = (id, updatedAccount) => { + const index = accounts.value.findIndex(acc => acc.id === id) + if (index !== -1) { + accounts.value[index] = { ...accounts.value[index], ...updatedAccount } + } + } + + // 删除账号 + const deleteAccount = (id) => { + accounts.value = accounts.value.filter(acc => acc.id !== id) + } + + // 根据平台获取账号 + const getAccountsByPlatform = (platform) => { + return accounts.value.filter(acc => acc.platform === platform) + } + + return { + accounts, + setAccounts, + addAccount, + updateAccount, + deleteAccount, + getAccountsByPlatform + } +}) \ No newline at end of file diff --git a/sau_frontend/src/stores/app.js b/sau_frontend/src/stores/app.js new file mode 100644 index 0000000..73054c6 --- /dev/null +++ b/sau_frontend/src/stores/app.js @@ -0,0 +1,69 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +export const useAppStore = defineStore('app', () => { + // 是否是第一次进入账号管理页面 + const isFirstTimeAccountManagement = ref(true) + + // 是否是第一次进入素材管理页面 + const isFirstTimeMaterialManagement = ref(true) + + // 账号管理页面刷新状态 + const isAccountRefreshing = ref(false) + + // 素材列表数据 + const materials = ref([]) + + // 设置账号管理页面已访问 + const setAccountManagementVisited = () => { + isFirstTimeAccountManagement.value = false + } + + // 设置素材管理页面已访问 + const setMaterialManagementVisited = () => { + isFirstTimeMaterialManagement.value = false + } + + // 重置所有访问状态(用于重新登录或刷新应用时) + const resetVisitStatus = () => { + isFirstTimeAccountManagement.value = true + isFirstTimeMaterialManagement.value = true + } + + // 更新素材列表 + const setMaterials = (materialList) => { + materials.value = materialList + } + + // 添加新素材 + const addMaterial = (material) => { + materials.value.push(material) + } + + // 删除素材 + const removeMaterial = (materialId) => { + const index = materials.value.findIndex(m => m.id === materialId) + if (index > -1) { + materials.value.splice(index, 1) + } + } + + // 设置账号管理页面刷新状态 + const setAccountRefreshing = (status) => { + isAccountRefreshing.value = status + } + + return { + isFirstTimeAccountManagement, + isFirstTimeMaterialManagement, + isAccountRefreshing, + materials, + setAccountManagementVisited, + setMaterialManagementVisited, + resetVisitStatus, + setMaterials, + addMaterial, + removeMaterial, + setAccountRefreshing + } +}) \ No newline at end of file diff --git a/sau_frontend/src/stores/index.js b/sau_frontend/src/stores/index.js new file mode 100644 index 0000000..f8841a1 --- /dev/null +++ b/sau_frontend/src/stores/index.js @@ -0,0 +1,9 @@ +import { createPinia } from 'pinia' +import { useUserStore } from './user' +import { useAccountStore } from './account' +import { useAppStore } from './app' + +const pinia = createPinia() + +export default pinia +export { useUserStore, useAccountStore, useAppStore } \ No newline at end of file diff --git a/sau_frontend/src/stores/user.js b/sau_frontend/src/stores/user.js new file mode 100644 index 0000000..d9e1604 --- /dev/null +++ b/sau_frontend/src/stores/user.js @@ -0,0 +1,31 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +export const useUserStore = defineStore('user', () => { + const userInfo = ref({ + name: '', + email: '' + }) + + const isLoggedIn = ref(false) + + const setUserInfo = (info) => { + userInfo.value = info + isLoggedIn.value = true + } + + const logout = () => { + userInfo.value = { + name: '', + email: '' + } + isLoggedIn.value = false + } + + return { + userInfo, + isLoggedIn, + setUserInfo, + logout + } +}) \ No newline at end of file