import { shallowRef } from 'vue'
import { queryTableDefine } from '@/services/api/common'
import { defineStore } from '../store'
import { sessionData } from '../storage'

export const useTableColumnStore = defineStore(() => {
    const loading = shallowRef(false)
    const tableColumns = sessionData.getRef('tableColumns')

    // 获取表格列列表
    const getTableColumnList = async () => {
        try {
            if (tableColumns.value.length) {
                return Promise.resolve()
            }
            loading.value = true
            const res = await queryTableDefine({
                tableType: 2
            })
            tableColumns.value = res.data
        } finally {
            loading.value = false
        }
    }

    return {
        loading,
        tableColumns,
        getTableColumnList,
    }
})