哈哈哈哈哈哈哈哈哈哈哈一天天 2025-02-21 14:35 采纳率: 74.2%
浏览 32

eltable type=selection禁用


<script lang="ts" setup>
import useVuelidate from '@vuelidate/core'
import { required } from '@/utils/vuelidate/vuelidate-rules'
import { em } from '@/utils/vuelidate/vuelidate-helper'
import { getCurrentInstance } from 'vue'
import { getCourseGroupItemList, bindCourseGroupItemList } from '@/api/course-setup'
import useDialogPluginComponent from '@/components/global-render/use-dialog-plugin-component'
const route = useRoute()
const props = defineProps<{
    row: TeacherListItem | undefined
    CertCourseOptions
    SchoolCourseOptions
    attributeList
}>()
const multipleTableRef = ref()
const { visible, onDialogHide, onDialogOK } = useDialogPluginComponent()
const tableData = ref([])
const attribute = ref()
const certCourseTypeId = ref()
/* const schoolCourseTypeId = ref() */
const certPlanId = ref(route.query.id)
const name = ref()
const id = ref(props.row.id)
async function execute() {
    try {
        const params = {
            id: id.value,
            certCourseTypeId: certCourseTypeId.value,
            certPlanId: certPlanId.value,
            attribute: attribute.value,
            name: name.value,
        }
        const { data } = await getCourseGroupItemList(params)
        tableData.value = data.data
        tableData.value.forEach((item) => {
            if (item.checkStatus === true && item.otherCourseCheckStatus === false) {
                multipleTableRef.value?.toggleRowSelection(item, true)
            }
        })
    } catch (error) {
        errorHandler(error)
    }
}
async function onOkClick() {
    try {
        const params = {
            certPlanCourseId: id.value,
            certPlanCourseVOList: selectable.value,
        }
        await bindCourseGroupItemList(params)
        ElMessage.success('保存成功')
        onDialogOK()
    } catch (error) {
        errorHandler(error, '保存失败')
    }
}
const selectable = ref<[]>([])

async function reset() {
    name.value = ''
    attribute.value = ''
    certCourseTypeId.value = ''
    execute()
}
const handleSelectionChange = (selection: []) => {
    selectable.value = selection
}
async function select(row, index) {
    if (row.checkStatus === true && row.otherCourseCheckStatus === true) {
        return false // 禁用
    } else {
        return true //不禁用
    }
}
execute()
</script>

<template>
    <ElDialog v-model="visible" width="800px" title="管理课程" center @closed="onDialogHide">
        <TableLayout>
            <template #filter>
                <ElForm class="flex" style="background-color: #f2f2f2; padding: 10px 0 0 10px; margin-bottom: 20px; height: 130px; display: flex; flex-wrap: wrap">
                    <ElFormItem>
                        <ElInput v-model="name" placeholder="请输入课程名称" />
                    </ElFormItem>
                    <ElFormItem>
                        <el-select v-model="attribute" placeholder="课程属性" style="width: 240px">
                            <el-option v-for="item in props.attributeList" :key="item.id" :label="item.name" :value="item.id" />
                        </el-select>
                    </ElFormItem>
                    <ElFormItem>
                        <el-select v-model="certCourseTypeId" placeholder="专业课程类别" style="width: 240px">
                            <el-option v-for="item in props.CertCourseOptions" :key="item.id" :label="item.name" :value="item.id" />
                        </el-select>
                    </ElFormItem>
                    <!--     <ElFormItem>
                        <el-select v-model="schoolCourseTypeId" placeholder="学校课程类别" style="width: 240px">
                            <el-option v-for="item in props.SchoolCourseOptions" :key="item.id" :label="item.name" :value="item.id" />
                        </el-select>
                    </ElFormItem> -->
                    <ElFormItem class="ml-4">
                        <ElButton type="primary" @click="execute()"> 搜索 </ElButton>
                        <ElButton type="primary" @click="reset()"> 重置 </ElButton>
                    </ElFormItem>
                </ElForm>
            </template>
            <template #table>
                <el-Table @select-all="handleSelectionChange" @selection-change="handleSelectionChange" :row-key="(row) => row.id" ref="multipleTableRef" v-loading="isLoading" :data="tableData" border>
                    <el-table-column type="selection" width="55" :reserve-selection="true" :selectable="select" />
                    <ElTableColumn label="课程名称" prop="name" />
                    <ElTableColumn label="课程代码" prop="code" />
                    <ElTableColumn label="适用学年" prop="path" />
                    <ElTableColumn label="专业认证类别" prop="certCourseTypeName" />
                    <ElTableColumn label="属性" prop="attributeName" />
                </el-Table>
            </template>
        </TableLayout>
        <div style="text-align: center; margin: 30px 0">
            <ElButton type="primary" @click="onOkClick()" style="border-radius: 20px; width: 200px; height: 40px"> 保存 </ElButton>
        </div>
    </ElDialog>
</template>

<style lang="scss" scoped>
.text-center {
    margin-top: 50px;
}
::v-deep .el-card {
    border: none !important;
}
</style>

eltable是在eldialog里面的,我设置了eltable的默认选中和type=selection的禁用,但是禁用不生效,也不是不生效,只是接口请求已发送,禁用状态就会消失,怎么禁用呢

  • 写回答

2条回答 默认 最新

  • 阿里嘎多学长 2025-02-21 14:35
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    解决方案

    你想禁用 el-tabletype="selection" 属性,这个属性是用来选择表格中的行的。

    可以使用 :disabled 属性来禁用 type="selection" 属性,例如:

    <el-table :data="tableData" :disabled="true">
      <el-table-column type="selection" width="55"></el-table-column>
      <!-- 其他列 -->
    </el-table>
    

    在上面的代码中,我们使用 :disabled="true" 属性来禁用整个表格的选择功能。

    如果你想禁用某一列的选择功能,可以使用 :selectable 属性,例如:

    <el-table :data="tableData">
      <el-table-column type="selection" width="55" :selectable="selectable"></el-table-column>
      <!-- 其他列 -->
    </el-table>
    
    <script>
    export default {
      setup() {
        const selectable = (row) => {
          // 在这里实现选择的逻辑
          return true; // 返回 true 表示可以选择,返回 false 表示不能选择
        }
      }
    }
    </script>
    

    在上面的代码中,我们使用 :selectable 属性来禁用某一列的选择功能,并在 selectable 函数中实现选择的逻辑。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月21日