最简树状表格添加顶级项目后不刷新


模块市场里的最简树状表格:
1.先添加一个最上层项目并保存
2.接着点添加,添加这个对话框里,上级这个下拉列表中没有前面添加的最上层项目
哪里需要修改一下,对话框显示时重新从读取这个下拉呢?

language 复制代码
<!-- 树状表格必看 -->
<!-- 1. 不需要分页,所以第19行实现了隐藏分页组件 -->
<!-- 2. 为了显示需要,通常将 `树状` 字段设置为第一个字段,并且该字段对齐方式为 `left`,请参考第42行 -->
<!-- 3. 请注意第13行,其中的 unfold 可以在表头增加一个 `展开/收缩` 树状表格的按钮 -->
<!-- 4. 本文件内,除以上注意事项外,树状表格与普通表格无差别 -->

index.vue:
<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 />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'unfold', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: t('examples.treetable.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性,直接加在Table标签上即可 -->
        <Table ref="tableRef" :pagination="false" />

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

cleanXss
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'

const tableRef = ref()
const { t } = useI18n()
const optButtons = defaultOptButtons(['edit', 'delete'])
const baTable = new baTableClass(new baTableApi('/admin/examples.Treetable/'), {
    column: [
        { type: 'selection', align: 'center', operator: false },
        { label: t('examples.treetable.name'), prop: 'name', operator: 'LIKE', align: 'left' },
        { label: t('Id'), prop: 'id', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query'), width: 70 },
        {
            label: t('Create time'),
            prop: 'create_time',
            align: 'center',
            render: 'datetime',
            sortable: 'custom',
            operator: 'RANGE',
            width: 160,
        },
        { label: t('Operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
    ],
    dblClickNotEditColumn: [undefined],
})

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()
})

defineOptions({
    name: 'examples/treetable',
})
cleanXss

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

popupForm.vue

language 复制代码
<!-- 树状表格必看 -->
<!-- 1. 29-40行的远程下拉组件用于选择上级,它只是一个普通的远程下拉,只是设置了额外的 isTree 属性 -->
<!-- 2. 76-89行的表单验证规则用于禁止上级为当前数据 -->
<!-- 3. 本文件内,除以上注意事项外,树状表格表单与普通表格的表单无差别 -->

<template>
    <!-- 对话框表单 -->
    <el-dialog class="ba-operate-dialog" :close-on-click-modal="false" :model-value="baTable.form.operate ? true : false" @close="baTable.toggleForm">
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                >
                    <FormItem
                        type="remoteSelect"
                        prop="pid"
                        :label="t('examples.treetable.pid')"
                        v-model="baTable.form.items!.pid"
                        :placeholder="t('Click select')"
                        :input-attr="{
                            params: { isTree: true },
                            field: 'name',
                            'remote-url': baTable.api.actionUrl.get('index'),
                        }"
                    />
                    <FormItem
                        :label="t('examples.treetable.name')"
                        type="string"
                        v-model="baTable.form.items!.name"
                        prop="name"
                        :input-attr="{ placeholder: t('Please input field', { field: t('examples.treetable.name') }) }"
                    />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

cleanXss
import { reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import type { ElForm, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'

const formRef = ref<InstanceType<typeof ElForm>>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    pid: [
        {
            validator: (rule: any, val: string, callback: Function) => {
                if (!val) {
                    return callback()
                }
                if (parseInt(val) == parseInt(baTable.form.items!.id)) {
                    return callback(new Error(t('auth.menu.The superior menu rule cannot be the rule itself')))
                }
                return callback()
            },
            trigger: 'blur',
        },
    ],
    name: [buildValidatorData({ name: 'required', title: t('examples.treetable.name') })],
})
cleanXss

<style scoped lang="scss"></style>
已采纳
九月枫似火
九月枫似火
这家伙很懒,什么也没写~
2小时前

自己搞定了,赋个初始值就会重新读取下拉列表了。

language 复制代码
const baTable = new baTableClass(
    new baTableApi('/admin/examples.Treetable/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('examples.treetable.name'), prop: 'name', operator: 'LIKE', align: 'left' },
            { label: t('Id'), prop: 'id', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query'), width: 70 },
            {
                label: t('Create time'),
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                sortable: 'custom',
                operator: 'RANGE',
                width: 160,
            },
            { label: t('Operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
        ],
        dblClickNotEditColumn: [undefined],
    },
    {
        defaultItems: { pid: '0' }, //这里赋值初值就OK
    }
)
0个回答默认排序 投票数排序
没有更多回答了~
请先登录
0
1
0
1