业务表单后端控制,减少APP发版

一般我们做开发时,都是根据产品的需求和UI的设计图,前端确定样式布局,后端确定接口返回格式,最粗暴的方法就是前端写成死的格式,后端只传动态改变的数据,但是我们都知道APP发版是需要时间的,IOS周期更长,所以我们有些文本,url等都是可以靠后端控制的,这是最基本的用法。其实还有更方便的用法,可以让后端控制表单格式,信息,排序等可控的属性,这样我们可以在app不发版的情况下调整顺序,更改必填项、默认值、内容,甚至可以添加或者删除输入项,方法很加单,就是向下面代码示例一样,将表单格式后端控制,传给前端即可。

​
<?php

$config = [
    'form' => [
        [
            'index' => 1,
            'type' => 'input',
            'title' => '商品名称',
            'unit' => '',
            'key' => 'special',
            'hint' => '请输入商品名称',
            'has_options' => false,
            'is_must' => false,
            'option' => [],
        ],
        [
            'index' => 2,
            'type' => 'input',
            'title' => '价格',
            'key' => 'price',
            'unit' => '元/斤',
            'hint' => '请输入今日价格',
            'has_options' => true,
            'is_must' => false,
            'option' => [],
        ],
        [
            'index' => 3,
            'type' => 'select',
            'title' => '价格浮动',
            'key' => 'price_change',
            'unit' => '',
            'hint' => '请选择价格浮动',
            'has_options' => true,
            'is_must' => true,
            'option' => [
                [
                    'text' => '偏高',
                    'value' => 'high',
                    'checked' => 1,  //如果没有默认选中,则都为0
                ],
                [
                    'text' => 'level',
                    'value' => 'normal',
                    'checked' => 0,
                ],
                [
                    'text' => '偏低',
                    'value' => 'low',
                    'checked' => 0,
                ],
            ],
        ],
        [
            'index' => 4,
            'type' => 'radio',
            'title' => '商品质量',
            'key' => 'quality',
            'unit' => '',
            'hint' => '请选择商品质量',
            'has_options' => true,
            'is_must' => true,
            'option' => [
                [
                    'text' => '优质',
                    'value' => 'good',
                    'checked' => 1,  //如果没有默认选中,则都为0
                ],
                [
                    'text' => '一般',
                    'value' => 'normal',
                    'checked' => 0,
                ],
                [
                    'text' => '差',
                    'value' => 'bad',
                    'checked' => 0,
                ],
            ],
        ],
        [
            'index' => 5,
            'type' => 'checkbox',
            'title' => '今日天气',
            'key' => 'weather',
            'unit' => '',
            'hint' => '请选择天气情况',
            'has_options' => true,
            'is_must' => true,
            'option' => [
                [
                    'text' => '晴',
                    'value' => 'sunny',
                    'checked' => 1,  //如果没有默认选中,则都为0
                ],
                [
                    'text' => '下雨',
                    'value' => 'rain',
                    'checked' => 0,
                ],
                [
                    'text' => '下雪',
                    'value' => 'snow',
                    'checked' => 0,
                ],
                [
                    'text' => '阴',
                    'value' => 'cloudy',
                    'checked' => 0,
                ],
            ],
        ],
        [
            'index' => 6,
            'type' => 'textarea',
            'title' => '更多分析',
            'key' => 'more_analysis',
            'unit' => '',
            'hint' => '再加入您独到的见解吧',
            'has_options' => true,
            'is_must' => false,
            'option' => [],
        ],
    ],
];

​
发布了226 篇原创文章 · 获赞 31 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/why444216978/article/details/104416814