Files
aida_front/src/store/seller/index.ts
2026-06-03 17:33:13 +08:00

97 lines
2.2 KiB
TypeScript

import { Module } from 'vuex'
import { RootState } from '../index'
import i18n from "@/lang/index";
import { Https } from '@/tool/https'
import { ApplyStatus } from "./index.d"
import store from '../index'
interface DesignerInfo {
shopName: string,
avatar: string,
brandBanner: string,
ownerName: string,
email: string,
mobile: string,
socialLinks: string[] | string,
description: string,
}
interface Seller {
isSeller: boolean,
applyStatus: number | null,
designerInfo: DesignerInfo,
firstEnter: boolean,
}
const seller: Module<Seller, RootState> = {
namespaced: true,
state: {
isSeller: false,
firstEnter: false,
applyStatus: null,
designerInfo: {
shopName: "--",
avatar: null,
brandBanner: null,
ownerName: "--",
email: "--",
mobile: "--",
socialLinks: ["--"],
description: "--"
},
},
mutations: {
set_firstEnter(state: Seller, value: boolean) {
state.firstEnter = value
},
set_isSeller(state: Seller, value: boolean) {
state.isSeller = value
},
set_applyStatus(state: Seller, value: number) {
state.applyStatus = value
if (value == ApplyStatus.Approved) {
state.isSeller = true
}
},
set_designerInfo(state: Seller, value: DesignerInfo) {
state.designerInfo = {
...state.designerInfo,
...value,
}
if (typeof value.socialLinks === "string") {
state.designerInfo.socialLinks = JSON.parse(value.socialLinks)
} else if (Array.isArray(value.socialLinks)) {
state.designerInfo.socialLinks = value.socialLinks
}
},
clear_state(state: Seller) {
state.isSeller = false
state.applyStatus = null
state.designerInfo = {
shopName: "--",
avatar: "",
brandBanner: "",
ownerName: "--",
email: "--",
mobile: "--",
socialLinks: ["--"],
description: "--"
}
},
},
actions: {
get_isSeller({ commit }) {
Https.axiosGet(Https.httpUrls.checkSellerDesigner).then(rv => {
commit('set_isSeller', !!rv.hasQualification)
commit('set_firstEnter', !rv.firstEnter)
})
},
async get_designerInfo({ commit }) {
const rv = await Https.axiosGet(Https.httpUrls.getDesignerInfo)
commit('set_designerInfo', rv)
return rv
},
}
}
export default seller