Ext.js5(radio group布局能力)(38)

view

/**
 * This example demonstrates the flexible layout capabilities of the RadioGroup class.
 * It also shows that you can validate radios as a group - try submitting the form before
 * changing any values to see this.
 * 和37是平行的,只是现在用的是RadioGroup 类
 */
Ext.define('KitchenSink.view.form.RadioGroupForm', {
    extend: 'Ext.form.Panel',
    xtype: 'form-radiogroup',

    // This example shares its ViewController with Checkbox Group Form
    //这个例子用的是Checkbox Group Form(37)的试图控制器
    controller: 'form-checkboxgroup',


    title: 'Radio Group Example',
    frame: true,
    width: 650,
    bodyPadding: 10,

    fieldDefaults: {
        labelWidth: 120
    },

    items: [{
        /*====================================================================
         * Individual checkbox/radio examples
         *====================================================================*/

        // Using checkbox/radio groups will generally be more convenient and flexible than
        // using individual checkbox and radio controls, but this shows that you can
        // certainly do so if you only have a single control at a time.

        xtype: 'container',
        layout: 'hbox',
        margin: '0 0 10',
        items: [{
            xtype: 'fieldset',
            flex: 1,
            title: 'Individual Checkboxes',
            defaultType: 'checkbox', // each item will be a checkbox
            layout: 'anchor',
            defaults: {
                anchor: '100%',
                hideEmptyLabel: false
            },
            items: [{
                xtype: 'textfield',
                name: 'txt-test1',
                fieldLabel: 'Alignment Test'
            }, {
                fieldLabel: 'Favorite Animals',
                boxLabel: 'Dog',
                name: 'fav-animal-dog',
                inputValue: 'dog'
            }, {
                boxLabel: 'Cat',
                name: 'fav-animal-cat',
                inputValue: 'cat'
            }, {
                checked: true,
                boxLabel: 'Monkey',
                name: 'fav-animal-monkey',
                inputValue: 'monkey'
            }]
        }, {
            xtype: 'component',
            width: 10
        }, {
            xtype: 'fieldset',
            flex: 1,
            title: 'Individual Radios',
            defaultType: 'radio', // each item will be a radio button
            layout: 'anchor',
            defaults: {
                anchor: '100%',
                hideEmptyLabel: false
            },
            items: [{
                xtype: 'textfield',
                name: 'txt-test2',
                fieldLabel: 'Alignment Test'
            }, {
                checked: true,
                fieldLabel: 'Favorite Color',
                boxLabel: 'Red',
                name: 'fav-color',
                inputValue: 'red'
            }, {
                boxLabel: 'Blue',
                name: 'fav-color',
                inputValue: 'blue'
            }, {
                boxLabel: 'Green',
                name: 'fav-color',
                inputValue: 'green'
            }]
        }]
    }, {
        /*====================================================================
         * RadioGroup examples
         *====================================================================*/
        // NOTE: These radio examples use the exact same options as the checkbox ones
        // above, so the comments will not be repeated.  Please see comments above for
        // additional explanation on some config options.
        // 注意:大部分都是沿用的37的代码,只需要关注额外的注释。
        xtype: 'fieldset',
        title: 'Radio Groups',
        // in this section we use the form layout that will aggregate all of the fields
        // into a single table, rather than one table per field.
        //在这一节中,我们将所有的fields放在一个表中,不想一个filed一个表
        layout: 'anchor',
        collapsible: true,
        defaults: {
            anchor: '100%'
        },
        items: [{
            xtype: 'textfield',
            name: 'txt-test4',
            fieldLabel: 'Alignment Test'
        },{
            xtype: 'radiogroup',
            fieldLabel: 'Auto Layout',
            cls: 'x-check-group-alt',
            items: [
                {boxLabel: 'Item 1', name: 'rb-auto', inputValue: 1},
                {boxLabel: 'Item 2', name: 'rb-auto', inputValue: 2, checked: true},
                {boxLabel: 'Item 3', name: 'rb-auto', inputValue: 3},
                {boxLabel: 'Item 4', name: 'rb-auto', inputValue: 4},
                {boxLabel: 'Item 5', name: 'rb-auto', inputValue: 5}
            ]
        },{
            xtype: 'radiogroup',
            fieldLabel: 'Single Column',
            columns: 1,
            items: [
                {boxLabel: 'Item 1', name: 'rb-col', inputValue: 1},
                {boxLabel: 'Item 2', name: 'rb-col', inputValue: 2, checked: true},
                {boxLabel: 'Item 3', name: 'rb-col', inputValue: 3}
            ]
        },{
            xtype: 'radiogroup',
            fieldLabel: 'Multi-Column (horizontal)',
            cls: 'x-check-group-alt',
            columns: 3,
            items: [
                {boxLabel: 'Item 1', name: 'rb-horiz-1', inputValue: 1},
                {boxLabel: 'Item 2', name: 'rb-horiz-1', inputValue: 2, checked: true},
                {boxLabel: 'Item 3', name: 'rb-horiz-1', inputValue: 3},
                {boxLabel: 'Item 4', name: 'rb-horiz-2', inputValue: 4},
                {boxLabel: 'Item 5', name: 'rb-horiz-2', inputValue: 5}
            ]
        },{
            xtype: 'radiogroup',
            fieldLabel: 'Multi-Column (vertical)',
            columns: 3,
            vertical: true,
            items: [
                {boxLabel: 'Item 1', name: 'rb-vert', inputValue: 1},
                {boxLabel: 'Item 2', name: 'rb-vert', inputValue: 2, checked: true},
                {boxLabel: 'Item 3', name: 'rb-vert', inputValue: 3},
                {boxLabel: 'Item 4', name: 'rb-vert', inputValue: 4},
                {boxLabel: 'Item 5', name: 'rb-vert', inputValue: 5}
            ]
        },{
            xtype: 'radiogroup',
            fieldLabel: 'Multi-Column<br />(custom widths)',
            cls: 'x-check-group-alt',
            columns: [100, 100],
            vertical: true,
            items: [
                {boxLabel: 'Item 1', name: 'rb-custwidth', inputValue: 1},
                {boxLabel: 'Item 2', name: 'rb-custwidth', inputValue: 2, checked: true},
                {boxLabel: 'Item 3', name: 'rb-custwidth', inputValue: 3},
                {boxLabel: 'Item 4', name: 'rb-custwidth', inputValue: 4},
                {boxLabel: 'Item 5', name: 'rb-custwidth', inputValue: 5}
            ]
        },{
            xtype: 'radiogroup',
            fieldLabel: 'Custom Layout<br />(w/ validation)',
            allowBlank: false,
            msgTarget: 'side',
            autoFitErrors: false,
            anchor: '-18',
            layout: 'column',
            defaultType: 'container',
            items: [{
                columnWidth: .25,
                items: [
                    {xtype: 'component', html: 'Heading 1', cls:'x-form-check-group-label'},
                    {xtype: 'radiofield', boxLabel: 'Item 1', name: 'rb-cust', inputValue: 1},
                    {xtype: 'radiofield', boxLabel: 'Item 2', name: 'rb-cust', inputValue: 2}
                ]
            },{
                columnWidth: .4,
                items: [
                    {xtype: 'component', html: 'Heading 2', cls:'x-form-check-group-label'},
                    {xtype: 'radiofield', boxLabel: 'A long item just for fun', name: 'rb-cust', inputValue: 3}
                ]
            },{
                columnWidth: .25,
                items: [
                    {xtype: 'component', html: 'Heading 3', cls:'x-form-check-group-label'},
                    {xtype: 'radiofield', boxLabel: 'Item 4', name: 'rb-cust', inputValue: 4},
                    {xtype: 'radiofield', boxLabel: 'Item 5', name: 'rb-cust', inputValue: 5}
                ]
            }]
        }]
    }],

    buttons: [{
        text: 'Save',
        handler: 'onSaveFormClick'
    }, {
        text: 'Reset',
        handler: 'onResetFormClick'
    }]
});
<template> <div class="search-form-container"> <el-select v-model="selectedItem" filterable clearable placeholder="请搜索并选择菜单" @change="handleSelectChange" :filter-method="filterMenu" @clear="handleClear" @focus="handleFocus" remote :remote-method="remoteMethod" > <el-option v-for="item in filteredMenus" :key="item.funcId" :label="item.name" :value="item.menuUrl" /> </el-select> <el-form :model="formData" label-width="120px" class="form-container"> <el-form-item label="操作员编号"> <el-input v-model="formData.createOpId" disabled /> </el-form-item> <el-form-item label="操作员编码"> <el-input v-model="formData.createOpCode" disabled /> </el-form-item> <el-form-item label="菜单编号"> <el-input v-model="formData.funcId" disabled /> </el-form-item> <el-form-item label="系统来源"> <el-input v-model="formData.opSource" disabled /> </el-form-item> <el-form-item label="页面编码"> <el-input v-model="formData.pageCode" disabled /> </el-form-item> <el-form-item label="菜单名称"> <el-input v-model="formData.funcName" disabled /> </el-form-item> <el-form-item label="创建时间"> <el-date-picker v-model="formData.createDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间" disabled /> </el-form-item> <el-form-item label="生效时间"> <el-date-picker v-model="formData.effectiveDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择生效时间" /> </el-form-item> <el-form-item label="失效时间"> <el-date-picker v-model="formData.expireDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择失效时间" /> </el-form-item> <el-form-item label="是否可以评价"> <el-radio-group v-model="formData.enabled"> <el-radio :label="true">是</el-radio> <el-radio :label="false">否</el-radio> </el-radio-group> </el-form-item> <div class="form-actions"> <el-button @click="resetForm">重置</el-button> <el-button type="primary" @click="saveForm">保存</el-button> </div> </el-form> </div> </template> <script> import { MUTATION } from '../config/constant.js'; import WbStore from '../utils/wbstore'; import { Button, Input, Select, FormItem, RadioGroup, Radio, Form, DatePicker, Option, } from 'element-ui'; import PinyinMatch from 'pinyin-match'; export default { name: 'MenuConfiguration', components: { [Button.name]: Button, [Input.name]: Input, [Select.name]: Select, [FormItem.name]: FormItem, [RadioGroup.name]: RadioGroup, [Form.name]: Form, [DatePicker.name]: DatePicker, [Option.name]: Option, [Radio.name]: Radio, }, data() { return { allMenus: [], selectedItem: null, formData: { createOpId: '', //创建的操作员编号 createOpCode: '', //创建的操作员编码 ext_C: '', //优化举措 ext_B: '', //下载地址 ext_A: '', //详细内容 funcId: '', //菜单编号 opSource: '', //系统来源 pageCode: '', //页面编号 enabled: '', //是否可以评价 A:允许 C:不允许 funcName: '', //菜单名称 hallFuncBaseId: '', //菜单基础编号 expireDate: '', //失效时间 effectiveDate: '', //生效时间 createDate: '', //创建时间 }, filteredMenus: [], }; }, mounted() { let menu_ = WbStore.opsForHash.get(MUTATION.MENUS, 'menus') || {}; this.$store.commit(MUTATION.MENUS, menu_.kMenu); this.allMenus = Object.values(menu_.kMenu); }, methods: { handleFocus() { this.filteredMenus = []; }, handleClear() { this.filteredMenus = []; this.resetForm(); }, remoteMethod(query) { if (query !== '') { this.filterMenu(query); } else { this.filteredMenus = []; } }, filterMenu(query) { this.filteredMenus = this.allMenus.filter(item => { const nameMatch = item.name.includes(query); const pinyinMatch = PinyinMatch.match(item.name, query); return nameMatch || (pinyinMatch && pinyinMatch !== false); }); }, async handleSelectChange(pageCode) { if (!pageCode) { this.resetForm(); return; } console.log('e', this.selectedItem, pageCode); try { const result = await this.$http.post( 'GW_QRY_HOME_BUSIHOME_QRYHALLFUNCBASEINFO', { pageCode: pageCode }, ); console.log('返回result',result) this.formData = this.transformData(result); } catch (error) { console.error('获取菜单配置失败:', error); } }, transformData(rawData) { delete rawData.retCode; delete rawData.retMessage; return { ...rawData, opSource: rawData.opSource === '1' ? '业务大厅' : '网格通', enabled: rawData.upvoteState === 'A', expireDate: rawData.expireDate.replace('.0', ''), effectiveDate: rawData.effectiveDate.replace('.0', ''), createDate: rawData.createDate.replace('.0', ''), }; }, resetForm() { this.formData.effectiveDate = ''; this.formData.expireDate = ''; this.formData.enabled = ''; }, async saveForm() { if (!this.formData.pageCode) { this.$message.warning('请先选择菜单'); return; } try { console.log('传来的数据表单:', this.formData); let data = { ...this.formData, opSource: '1', upvoteState: this.formData.enabled ? 'A' : 'C' } delete data.enabled; console.log('保存的数据data:', data); await this.$http.post('GW_DEAL_HOME_BUSIHOME_SAVEBASEINFO', data); this.$message({ message: '保存成功', type: 'success', }); } catch (error) { this.$message({ message: '保存失败', type: 'warning', }); } }, }, }; </script> <style scoped> .search-form-container { max-width: 800px; margin: 20px auto; padding: 20px; border: 1px solid #ebeef5; border-radius: 4px; } .form-container { margin-top: 20px; } .form-actions { display: flex; justify-content: flex-end; margin-top: 20px; } </style> 以上述代码为基础,实现整个页面的样式优化,最好表单一行内三列,冒号对齐
最新发布
07-17
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值