| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { defineStore } from 'pinia'
- import { uniStorage } from '@/utils/uniStorage'
- export interface SettlementSignContext {
- signTraceId: string
- subjectLocation: string
- createdAt: number
- }
- interface SettlementSignState {
- context?: SettlementSignContext
- }
- const SIGN_CONTEXT_EXPIRE_TIME = 30 * 60 * 1000
- const createSignTraceId = (subjectLocation: string): string => {
- return `${Date.now()}_${subjectLocation}`
- }
- export const useSettlementSignStore = defineStore('settlementSign', {
- state: (): SettlementSignState => ({
- context: undefined,
- }),
- getters: {
- validContext(state): SettlementSignContext | undefined {
- if (!state.context?.subjectLocation) return undefined
- const isExpired = Date.now() - state.context.createdAt > SIGN_CONTEXT_EXPIRE_TIME
- if (isExpired) return undefined
- return state.context
- },
- pendingSubjectLocation(): string {
- return this.validContext?.subjectLocation || ''
- },
- },
- actions: {
- createContext(subjectLocation: string): SettlementSignContext {
- const context: SettlementSignContext = {
- signTraceId: createSignTraceId(subjectLocation),
- subjectLocation,
- createdAt: Date.now(),
- }
- this.context = context
- return context
- },
- clearContext(): void {
- this.context = undefined
- },
- },
- persist: {
- key: 'settlement-sign-store',
- storage: uniStorage,
- pick: ['context'],
- },
- })
|