avue中 curd的列表配置

说明: avue-crud组件中添加查询条件或者新增的时候,条件为下拉框且接口在curd组件中配置

1. html代码

<template>
  <basic-container>
    <avue-crud
      :data="dataList"
      :option="option"
      @search-change="searchChange"
      ref="crud"
    >
      <!-- 按钮 -->
      <template slot-scope="scope" slot="menuLeft">
        <el-button v-has="'dev-system-add'" type="primary" plain icon="icon-piliangdaochu">导出</el-button>
        <el-button
          v-has="'ent_enterprise_add'"
          class="filter-item"
          type="primary"
          plain
          icon="el-icon-plus"
          @click="$refs.crud.rowAdd()"
        >新增</el-button>
        <el-button
          v-has="'sys_enterprise_batch_del'"
          class="filter-item"
          type="danger"
          plain
          icon="icon-shanchu"
        >批量删除</el-button>
      </template>
      <!-- 自定义列搜索 -->
      <!-- <template slot-scope="{disabled,size}" slot="parentGroupNameSearch">
        <avue-select v-model="parentGroupName" placeholder="所属分组" :dic="dic"></avue-select>
      </template>-->
      <!-- 弹窗 -->
      <template style="width:100%;" slot="administrationForm" slot-scope="{type,disabled}">
        <v-region style="width:100%;" type="group" :town="true" v-model="adcData" search></v-region>
      </template>
      <template style="width:100%;" slot="gisAddressForm" slot-scope="scope">
        <div style="display:flex;line-height:32px;height:32px;">
          <el-input
            style="line-height:32px;height:32px;margin-right:10px;"
            type="text"
            autocomplete="off"
            v-model="form.gisAddress"
            :disabled="scope.disabled"
            :readonly="true"
          />
          <el-button type="primary" :disabled="scope.disabled">{{form.gisAddress?'重新定位':'定位'}}</el-button>
        </div>
      </template>
      <!--  -->
      <template style="width:100%;" slot-scope="leaderForm" slot="textLabel">
        <span>联系人&nbsp;&nbsp;</span>
        <el-tooltip class="item" effect="dark" content="文字提示" placement="top-start">
          <i class="el-icon-warning"></i>
        </el-tooltip>
      </template>
      <!--  -->
    </avue-crud>
  </basic-container>
</template>
  
<script>
import { tableOption } from "@/const/crud/basic/familyOrg";
export default {
  data() {
    return {
      dic: [],
      adcData: {},
      form: {},
      dataList: [
        {
          name: "所属分组",
          project: "111",
          address: "北京",
          people: "小明",
          phone: 123456789,
          group: 1
        },
        {
          name: "所属分组",
          project: "111",
          address: "北京",
          people: "小明",
          phone: 123456789,
          group: 1
        },
        {
          name: "所属分组",
          project: "111",
          address: "北京",
          people: "小明",
          phone: 123456789,
          group: 1
        }
      ],
      option: tableOption
    };
  },
  methods: {
    updateHostManufacturerDic(systemCategoryId) {
      // 内置方法
      var column = this.findObject(this.option.column, "parentGroupName");
      // 默认值
      column.value = "-1";
      // 参数
      column.dicQuery = { nodeType: 2 };
      // URL
      column.dicUrl = `/org/web/sysOrgTree/orgTree`;
      // 更新
      this.$refs.crud.updateDic("parentGroupName");
    },
    searchChange(form, done) {
      console.log("from", form);
      done();
    }
  },
  mounted() {
    this.updateHostManufacturerDic();
  }
};
</script>

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

2. tableOption的配置文件

import { rule } from '@/util/validateRules'
export const tableOption = {
    addBtn: false,
    searchMenuSpan: 8,
    column: [
        {
            label: "家庭名称",
            prop: "name",
            span: 24,
            search: true,
            searchLabel: "",
            searchLabelWidth: 1,
            searchPlaceholder: "按家庭名称搜索",
            rules: [
                {
                    required: true,
                    message: "请输入家庭名称",
                    trigger: "blur"
                }
            ]
        },
        {
            label: "所属项目",
            prop: "projectName",
            span: 24,
            rules: [
                {
                    required: true,
                    message: "请输入所属项目",
                    trigger: "blur"
                }
            ]
        },

        {
            label: "家庭地址",
            prop: "address",
            span: 24,
            rules: [
                {
                    required: true,
                    message: "请输入家庭地址",
                    trigger: "blur"
                }
            ]
        },
        {
            label: "联系人",
            prop: "leader",
            span: 24,
            rules: [
                {
                    required: true,
                    message: "请输入联系人",
                    trigger: "blur"
                }
            ]
        },
        {
            label: "联系方式",
            prop: "leaderPhone",
            span: 24,
            rules: [
                {
                    required: true,
                    message: "请输入联系方式",
                    trigger: "blur"
                }
            ]
        },
        {
            label: "地图标注",
            prop: "gisAddress",
            span: 24,
            hide: true,
            rules: [
                {
                    required: true,
                    message: "请输入地图标注",
                    trigger: "blur"
                }
            ]
        },
        {
            label: "行政区划",
            prop: "administration",
            span: 24,
            hide: true,
            rules: [
                {
                    required: true,
                    message: "请输入行政区划",
                    trigger: "blur"
                }
            ]
        },
        {
            label: "所属分组",
            prop: "parentGroupName",
            span: 24,
            search: true,
            type: "select",
            searchRange: false,
            searchLabel: "",
            searchLabelWidth: 1,
            searchPlaceholder: "所属分组",
            // 请求方法(默认get)
            dicMethod:'get',
            // 下拉框值转换
            props: {
                label: 'name',
                value: 'parentId',
                // 如果有层级关系需要添加
                // res:'data.list'
            },
            // 验证
            rules: [
                {
                    required: true,
                    message: "请输入所属分组",
                    trigger: "blur"
                }
            ]
        }
    ]
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Avue 使用 `avue-dialog` 和 `avue-curd` 组件可以实现将 Dialog 和 CRUD 绑定起来。具体步骤如下: 1. 安装 `avue` 和 `avue-cli`: ```bash npm install avue avue-cli ``` 2. 在 `main.js` 引入 `avue` 和 `avue-cli`: ```javascript import Vue from 'vue' import App from './App.vue' import Avue from 'avue' import AvueCli from 'avue-cli' Vue.use(Avue) Vue.use(AvueCli) new Vue({ el: '#app', render: h => h(App) }) ``` 3. 在 `App.vue` 使用 `avue-dialog` 和 `avue-curd` 组件: ```vue <template> <div> <avue-dialog ref="dialog" :visible="dialogVisible" :title="dialogTitle" @confirm="handleConfirm"> <avue-curd ref="curd" :crud="crud" @search="handleSearch" @change="handleChange" @delete="handleDelete" /> </avue-dialog> <button @click="openDialog">打开 Dialog</button> </div> </template> <script> export default { data () { return { dialogVisible: false, dialogTitle: '编辑', crud: { api: '/api/user', columns: [ { label: 'ID', field: 'id' }, { label: '姓名', field: 'name', type: 'input', rules: [{ required: true, message: '请输入姓名' }] }, { label: '年龄', field: 'age', type: 'input', rules: [{ required: true, message: '请输入年龄' }] }, { label: '性别', field: 'gender', type: 'radio', options: [{ label: '男', value: '男' }, { label: '女', value: '女' }] } ] } } }, methods: { openDialog () { this.dialogVisible = true this.$refs.curd.search() }, handleSearch () { // 处理搜索逻辑 }, handleChange (data) { // 处理数据变化逻辑 }, handleDelete (data) { // 处理删除逻辑 }, handleConfirm () { const data = this.$refs.curd.getData() // 处理确认逻辑 } } } </script> ``` 在上述代码,`avue-dialog` 组件用于显示 Dialog,`avue-curd` 组件用于显示 CRUD 表格。`crud` 对象包含了 CRUD 表格的配置信息,包括 API 地址、列信息等。`handleSearch`、`handleChange` 和 `handleDelete` 方法分别处理搜索、数据变化和删除事件。`handleConfirm` 方法处理确认事件,将数据保存到数据库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值