<template>
  <div class="default-main ba-table-box" >
    <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
    <el-row>
      <el-col :span="24">
        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['refresh', 'add', 'edit', 'delete', 'unfold']" quick-search-placeholder="通过菜单标题模糊搜索"
          @action="baTable.onTableHeaderAction" />
        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" :pagination="false" @action="baTable.onTableAction" />

      </el-col>
    </el-row>

    <!-- 表单 -->
    <PopupForm />
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, provide } from 'vue'
import { sysMenu } from '/@/api/controllerUrls'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { defaultOptButtons } from '/@/components/table'

import { baTableApi } from '/@/api/common'
import baTableClass from '/@/utils/baTable'

const tableRef = ref()
const baTable = new baTableClass(
    new baTableApi(sysMenu),
    {
        expandAll: false,
        dblClickNotEditColumn: [undefined, 'keepalive', 'status'],
        column: [
            { type: 'selection', align: 'center' },
            { label: '标题', prop: 'title', align: 'left' },
            { label: '图标', prop: 'icon', align: 'center', width: '60', render: 'icon', default: 'el-icon-Minus' },
            { label: '名称', prop: 'name', align: 'center', 'show-overflow-tooltip': true },
            {
                label: '类型',
                prop: 'type',
                align: 'center',
                render: 'tag',
                custom: { menu: 'danger', menu_dir: 'success', button: 'info' },
                replaceValue: { menu: '菜单项', menu_dir: '菜单目录', button: '页面按钮' },
            },
            { label: '缓存', prop: 'keepalive', align: 'center', width: '80', render: 'switch' },
            { label: '状态', prop: 'status', align: 'center', width: '80', render: 'switch' },
            { label: '修改时间', prop: 'updateTime', align: 'center', width: '180', render: 'datetime' },
            {
                label: '操作',
                align: 'center',
                width: '130',
                render: 'buttons',
                buttons: defaultOptButtons(),
            },
        ],
        dragSortLimitField: 'pid',
    },
    {
        defaultItems: {
            type: 'menu',
            menuType: 'tab',
            extend: 'none',
            keepalive: '1',
            status: '1',
            icon: 'el-icon-Minus',
            pid: '0',
        },
    },
    {
        // 获得编辑数据后
        requestEdit: () => {
            if (baTable.form.items && !baTable.form.items.icon) baTable.form.items.icon = 'el-icon-Minus'
        },
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.dragSort()
    })
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'auth/menu',
})
</script>

<style scoped lang="scss"></style>
