当前位置: 首页 > news >正文

Fastadmin表单分组显示

这是一个接口分类和本站分类进行绑定的表单,把绑定结果写到了一个文件中。

页面效果如下图

     * 绑定情况渲染页面* @return string* @throws \think\Exception* @throws \think\db\exception\DataNotFoundException* @throws \think\db\exception\ModelNotFoundException* @throws \think\exception\DbException*/public function bindcats(){$get = $this->request->get();$api_info = $this->model->where('id',$get['id'])->find();$categorys = Custom::apiget($api_info,'category',[]);$file = APP_PATH . 'extra/catbind_'.$api_info['name'].'.php';$type ='';$binds = [];if(file_exists($file)){$binds = require($file);/*** 左边是api的id,右边是项目本地的分类id* return array (* 70 => '89',* 69 => '61',* 68 => '64',* 67 => '59'* );*/}foreach ($categorys as $key=>$value){$categorys[$key]['bind_id'] = isset($binds[$value['id']]) ? $binds[$value['id']] : '';}$lang_categorys = Custom::apiget($api_info,'lang',[]);$file = APP_PATH . 'extra/langbind_'.$api_info['name'].'.php';$type ='';$binds = [];if(file_exists($file)){$binds = require($file);/*** 左边是api的id,右边是项目本地的语言id* return array (* 70 => '89',* 69 => '61',* 68 => '64',* 67 => '59'* );*/}foreach ($lang_categorys as $key=>$value){$lang_categorys[$key]['bind_id'] = isset($binds[$value['id']]) ? $binds[$value['id']] : '';}//根据语言整理成分组foreach ($lang_categorys as $key=>$value){$child = [];foreach ($categorys as $k=>$v){if($v['language_mark'] == $value['mark']){$child[] = $v;unset($categorys[$k]);}}$lang_categorys[$key]['child'] = $child;unset($child);if($key == 0){$lang_categorys[$key]['active'] = 1;}else{$lang_categorys[$key]['active'] = 0;}}$this->view->assign('lang_categorys', $lang_categorys);$this->view->assign('apiname', $api_info['name']);return $this->view->fetch();}public function dobind(){if ($this->request->isPost()) {$this->token();$apiname = $this->request->post('apiname');$file = APP_PATH . 'extra/catbind_'.$apiname.'.php';$bind_data = $this->request->post("bind/a", [], 'trim');
//            dump($bind_data);die;if ($bind_data) {foreach($bind_data as $v){$k= trim($v['key']);if($v['val'])$data[$k]=$v['val'];}file_put_contents($file,'<?php' . "\n\nreturn " . var_export_short($data) . ";\n");$this->success();}$this->error();}}
<style type="text/css">/* 保持原有样式不变 */@media (max-width: 375px) {.edit-form tr td input {width: 100%;}.edit-form tr th:first-child, .edit-form tr td:first-child {width: 20%;}.edit-form tr th:nth-last-of-type(-n+2), .edit-form tr td:nth-last-of-type(-n+2) {display: none;}}.edit-form table > tbody > tr td a.btn-delcfg {visibility: hidden;}.edit-form table > tbody > tr:hover td a.btn-delcfg {visibility: visible;}.btn,.btn-danger,.btn-xs,.btn-trash{display: none !important;}
</style><form id="set-form" role="form" data-toggle="validator" method="POST" action="{:url('dobind')}">{:token()}<input name="apiname" type="hidden" value="{$apiname}"><div class="panel-heading"><!-- 标签页导航 --><ul class="nav nav-tabs" role="tablist">{foreach $lang_categorys as $key=>$vo}<li role="presentation" class="{$vo.active?'active':''}"><a href="#tab-{$vo.mark}" aria-controls="tab-{$vo.mark}" role="tab" data-toggle="tab">{:__($vo.name)}</a></li>{/foreach}</ul><!-- 标签页内容 --><div class="tab-content">{foreach $lang_categorys as $key=>$vo}<div role="tabpanel" class="tab-pane fade {if $vo.active}active in{/if}" id="tab-{$vo.mark}"><table class="table table-striped"><thead><tr><th>ID</th><th>名称</th><th>语言标识</th><th width="250">绑定分类</th></tr></thead><tbody>{foreach $vo.child as $index=>$item}<tr><td>{$item.id}</td><td>{$item.name}</td><td>{$item.language_mark}</td><td><div class="form-group"><input name="bind[{$item.id}][key]" type="hidden" value="{$item.id}">{empty name="$vo.bind_id"}<input name="bind[{$item.id}][val]" type="text" value="{$item.bind_id}" data-source="category/index?type=video" data-params='{"custom[type]":"video"}' class="form-control selectpage">{else /}<input name="bind[{$item.id}][val]" type="text" value="{$item.bind_id}" data-source="category/index?type=video" data-params='{"custom[type]":"video","custom[lang_id]":"{$vo.bind_id}"}' class="form-control selectpage">{/empty}</div></td></tr>{/foreach}</tbody></table></div>{/foreach}</div></div><div class="form-group layer-footer"><label class="control-label col-xs-12 col-sm-4"></label><div class="col-xs-12 col-sm-8"><button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button></div></div>
</form>

绑定后生成的文件

<?phpreturn array (70 => '89',69 => '61',68 => '64',67 => '59',66 => '65',65 => '64',64 => '89',33 => '61',43 => '62',42 => '89',41 => '58',
);

相关文章:

  • 【2025最新】Spring Boot + Spring AI 玩转智能应用开发
  • 1.1 Epson机器人常用指令1-Print函数、RobotInfo$
  • 实景VR展厅制作流程与众趣科技实景VR展厅应用
  • 将 Element UI 表格拖动功能提取为公共方法
  • Linux云计算训练营笔记day11(Linux CentOS7)
  • 智慧赋能光伏运维——无人机巡检+地面监控双链路覆盖,打造光伏电站管理新标杆
  • Ansible模块——主机名设置和用户/用户组管理
  • 牛客网NC209794:使徒袭来
  • 一周快讯 | 银发文娱旅游一周新鲜事
  • 【愚公系列】《Manus极简入门》048-自然探险之旅:“户外活动规划师”
  • 深入理解 SPI 通信中的时钟极性与相位(CPOL 与 CPHA)
  • ARP 原理总结
  • 全新的开源监控工具CheckCle
  • C++学习:六个月从基础到就业——C++20:范围(Ranges)进阶
  • Supermemory:让大模型拥有“长效记忆“
  • 开源AI大模型等“神秘组合”,如何颠覆零售业数字化转型?
  • 统计客户端使用情况,使用es存储数据,实现去重以及计数
  • java中的Servlet4.x详解
  • GitHub排名第一的开源ERP项目:Odoo生产计划与执行的功能概述
  • Git初始化本地已有项目,并推送到远端Git仓库完整操作指南
  • 交通运输局男子与两名女子办婚礼?官方通报:未登记结婚,开除该男子
  • 长沙至赣州高铁初步设计获批,可填补湘赣两省斜向交通空白
  • 张宇祥已任上海闵行区委常委、副区长
  • 黄仁勋:新一代计算平台GB300三季度上市,AI计算能力每十年提升100万倍
  • 《习近平新时代中国特色社会主义思想学习论丛》第十一辑至第十五辑出版发行
  • 倒计时1天:走进“中国荔乡”茂名,探寻农交文旅商融合发展新模式