| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- import { defineStore } from "pinia";
- import ls from "@/utils/store2";
- import { ref } from "vue";
- import { userToken } from "../composables/config";
- import crypt from "../composables/crypt";
- import useGlobalStore from "./use-global-store";
- export interface UserInfo {
- id?: string;
- name: string;
- email: string;
- phone: string;
- approveStatus?: number;
- }
- export interface AccountInfo {
- loginName: string;
- password: string;
- rememberPassword: boolean;
- }
- const STORAGE_KEY = "USER";
- const ACCOUNT_INFO_KEY = "ACCOUNT_INFO_KEY";
- const ID_TYPE_OPTIONS_KEY = "ID_TYPE_OPTIONS_KEY";
- const APP_VERSION = 'APP_VERSION'
- const PROBLEM_DETAILS_KEY = "PROBLEM_DETAILS_KEY";
- const LOGIN_OPTIONS_KEY = "LOGIN_OPTIONS_KEY";
- const PAYMENT_CHANNEL_KEY = "PAYMENT_CHANNEL_KEY";
- const CHANNEL_LIST_KEY = "CHANNEL_LIST_KEY";
- const useUserStore = defineStore("userStore", () => {
- const userInfo = ref<UserInfo | null>(null);
- const accountInfo = ref<AccountInfo | null>(null);
- const isLoggedIn = ref(false);
- const reasonsOptions = ref<any>(null);
- const loginOptions = ref<any>(null);
- const paymentChannel = ref<any>(null);
- const channelList = ref<any>(null);
- const appVersion = ref<any>(null);
- const problemDetails = ref<any>(null);
- const initChannel = () => {
- const encryptedInfo = ls.get(PAYMENT_CHANNEL_KEY);
- if (encryptedInfo) {
- const decryptedInfo = crypt.decrypt(encryptedInfo);
- if (decryptedInfo) {
- paymentChannel.value = JSON.parse(decryptedInfo);
- }
- }
- };
- const initChannelList = () => {
- const encryptedInfo = ls.get(CHANNEL_LIST_KEY);
- if (encryptedInfo) {
- const decryptedInfo = crypt.decrypt(encryptedInfo);
- if (decryptedInfo) {
- channelList.value = JSON.parse(decryptedInfo);
- }
- }
- };
- const initUserInfo = () => {
- const encryptedInfo = ls.get(STORAGE_KEY);
- if (encryptedInfo) {
- const decryptedInfo = crypt.decrypt(encryptedInfo);
- if (decryptedInfo) {
- userInfo.value = JSON.parse(decryptedInfo);
- isLoggedIn.value = true;
- }
- }
- };
- const initAppVersion = () => {
- const encryptedInfo = ls.get(APP_VERSION);
- if (encryptedInfo) {
- const decryptedInfo = crypt.decrypt(encryptedInfo);
- if (decryptedInfo) {
- appVersion.value = JSON.parse(decryptedInfo);
- }
- }
- };
- const initLoginOptions = () => {
- const encryptedInfo = ls.get(LOGIN_OPTIONS_KEY);
- if (encryptedInfo) {
- const decryptedInfo = crypt.decrypt(encryptedInfo);
- if (decryptedInfo) {
- loginOptions.value = JSON.parse(decryptedInfo);
- }
- }
- }
- const initProblemDetails = () => {
- const encryptedInfo = ls.get(PROBLEM_DETAILS_KEY);
- if (encryptedInfo) {
- const decryptedInfo = crypt.decrypt(encryptedInfo);
- if (decryptedInfo) {
- problemDetails.value = JSON.parse(decryptedInfo);
- }
- }
- };
- const initReasonsOptions = () => {
- const encryptedInfo = ls.get(ID_TYPE_OPTIONS_KEY);
- if (encryptedInfo) {
- const decryptedInfo = crypt.decrypt(encryptedInfo);
- if (decryptedInfo) {
- reasonsOptions.value = JSON.parse(decryptedInfo);
- }
- }
- };
- const initAccountInfo = () => {
- const encryptedInfo = ls.get(ACCOUNT_INFO_KEY);
- if (encryptedInfo) {
- const decryptedInfo = crypt.decrypt(encryptedInfo);
- if (decryptedInfo) {
- accountInfo.value = JSON.parse(decryptedInfo);
- }
- }
- };
- const saveUserInfo = (info: UserInfo) => {
- userInfo.value = info;
- isLoggedIn.value = true;
- const encryptedInfo = crypt.encrypt(JSON.stringify(info));
- ls.set(STORAGE_KEY, encryptedInfo);
- };
- const savePaymentChannel = (info: any) => {
- paymentChannel.value = info;
- const encryptedInfo = crypt.encrypt(JSON.stringify(info));
- ls.set(PAYMENT_CHANNEL_KEY, encryptedInfo);
- };
- const saveChannelList = (info: any) => {
- channelList.value = info;
- const encryptedInfo = crypt.encrypt(JSON.stringify(info));
- ls.set(CHANNEL_LIST_KEY, encryptedInfo);
- };
- const saveLoginOptions = (info: any) => {
- loginOptions.value = info;
- const encryptedInfo = crypt.encrypt(JSON.stringify(info));
- ls.set(LOGIN_OPTIONS_KEY, encryptedInfo);
- };
- const saveProblemDetails = (info: any) => {
- problemDetails.value = info;
- const encryptedInfo = crypt.encrypt(JSON.stringify(info));
- ls.set(PROBLEM_DETAILS_KEY, encryptedInfo);
- };
- const saveAppVersion = (info: any) => {
- appVersion.value = info;
- const encryptedInfo = crypt.encrypt(JSON.stringify(info));
- ls.set(APP_VERSION, encryptedInfo);
- };
- const saveReasonsOptions = (info: any) => {
- reasonsOptions.value = info;
- const encryptedInfo = crypt.encrypt(JSON.stringify(info));
- ls.set(ID_TYPE_OPTIONS_KEY, encryptedInfo);
- };
- const saveAccountInfo = (info: AccountInfo) => {
- accountInfo.value = info;
- const encryptedInfo = crypt.encrypt(JSON.stringify(info));
- ls.set(ACCOUNT_INFO_KEY, encryptedInfo);
- };
- const clearUserInfo = () => {
- userInfo.value = null;
- isLoggedIn.value = false;
- userToken.value = "";
- reasonsOptions.value = null;
- loginOptions.value = null;
- paymentChannel.value = null;
- channelList.value = null;
-
- ls.remove(STORAGE_KEY);
- ls.remove(PAYMENT_CHANNEL_KEY);
- ls.remove(CHANNEL_LIST_KEY);
- ls.remove(LOGIN_OPTIONS_KEY);
- ls.remove(PROBLEM_DETAILS_KEY);
- ls.remove(APP_VERSION);
- ls.remove(ID_TYPE_OPTIONS_KEY);
- ls.remove(ACCOUNT_INFO_KEY);
- const globalStore = useGlobalStore();
- globalStore.setMode("customer");
- };
- initReasonsOptions();
- initUserInfo();
- initAccountInfo();
- initAppVersion();
- initLoginOptions();
- initProblemDetails();
- initChannel();
- initChannelList();
- return {
- userInfo,
- accountInfo,
- isLoggedIn,
- reasonsOptions,
- loginOptions,
- appVersion,
- problemDetails,
- paymentChannel,
- channelList,
- savePaymentChannel,
- saveChannelList,
- saveProblemDetails,
- saveLoginOptions,
- saveAppVersion,
- saveReasonsOptions,
- saveUserInfo,
- saveAccountInfo,
- clearUserInfo,
- };
- });
- export default useUserStore;
|