返回 Social Auto Upload
account.js
根目录 / sau_frontend / src / stores / account.js
1 import { defineStore } from 'pinia'
2 import { ref } from 'vue'
3
4 export const useAccountStore = defineStore('account', () => {
5 // 存储所有账号信息
6 const accounts = ref([])
7
8 // 平台类型映射
9 const platformTypes = {
10 1: '小红书',
11 2: '视频号',
12 3: '抖音',
13 4: '快手'
14 }
15
16 // 设置账号列表
17 const setAccounts = (accountsData) => {
18 // 转换后端返回的数据格式为前端使用的格式
19 accounts.value = accountsData.map(item => {
20 return {
21 id: item[0],
22 type: item[1],
23 filePath: item[2],
24 name: item[3],
25 status: item[4] === -1 ? '验证中' : (item[4] === 1 ? '正常' : '异常'),
26 platform: platformTypes[item[1]] || '未知'
27 }
28 })
29 }
30
31 // 添加账号
32 const addAccount = (account) => {
33 accounts.value.push(account)
34 }
35
36 // 更新账号
37 const updateAccount = (id, updatedAccount) => {
38 const index = accounts.value.findIndex(acc => acc.id === id)
39 if (index !== -1) {
40 accounts.value[index] = { ...accounts.value[index], ...updatedAccount }
41 }
42 }
43
44 // 删除账号
45 const deleteAccount = (id) => {
46 accounts.value = accounts.value.filter(acc => acc.id !== id)
47 }
48
49 // 根据平台获取账号
50 const getAccountsByPlatform = (platform) => {
51 return accounts.value.filter(acc => acc.platform === platform)
52 }
53
54 return {
55 accounts,
56 setAccounts,
57 addAccount,
58 updateAccount,
59 deleteAccount,
60 getAccountsByPlatform
61 }
62 })
62 lines JAVASCRIPT